blob: f3a9b4a75da9395d87b5d233102548552bf0fe46 [file] [log] [blame]
#!/bin/sh
# Copyright 2016 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
set -e
# Try to find a unique source for non-official devices. We might expand this a
# bit more based on feedback from Chromium OS derivatives. We don't currently
# guarantee the exact format of this either.
#
# These are example SMBIOS fields available:
# bios_date bios_vendor bios_version
# board_asset_tag board_name board_serial board_vendor board_version
# chassis_asset_tag chassis_serial chassis_type chassis_vendor chassis_version
# product_name product_serial product_uuid product_version
chromiumos_serial_number() {
local serial_number
# Try the SMBIOS product serial if available.
local smbios_pserial="/sys/devices/virtual/dmi/id/product_serial"
if [ -r "${smbios_pserial}" ]; then
serial_number="$(cat "${smbios_pserial}" 2>/dev/null)" || :
fi
if [ -z "${serial_number}" ]; then
# Try the SMBIOS UUID if available. QEMU can set this via -uuid.
local smbios_puuid="/sys/devices/virtual/dmi/id/product_uuid"
if [ -r "${smbios_puuid}" ]; then
serial_number="$(cat "${smbios_puuid}" 2>/dev/null)" || :
fi
fi
# If we couldn't find one, just use current timestamp as some sort of noise.
if [ -z "${serial_number}" ]; then
serial_number="$(date -u +%s)"
fi
# All non-Chrome OS devices get a "nonchrome" prefix.
echo "nonchrome-${serial_number}"
}
# As of Chrome OS 58, we dump VPD information unconditionally, so it is always
# available on the login screen, even after OOBE (see crbug.com/216422). Note
# that the machine-info.conf upstart config file takes care of deleting the
# $MACHINE_INFO file before a user session starts.
touch "${MACHINE_INFO}"
chmod 0644 "${MACHINE_INFO}"
if crossystem "mainfw_type?nonchrome"; then
echo "serial_number=\"$(chromiumos_serial_number)\""
else
# Dump full information in the VPD, including the serial number.
dump_vpd_log --full --stdout
# Dynamic information.
echo "customization_id=\"$(cros_config /ui help-content-id)\""
echo "rlz_brand_code=\"$(cros_config / brand-code)\""
echo "wpsw_cur=\"$(crossystem wpsw_cur)\""
fi >> "${MACHINE_INFO}"