| #!/bin/sh |
| |
| # Copyright 2016 The ChromiumOS Authors |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| set -e |
| |
| # Determines the device serial number. On Chrome OS hardware, it's stored in VPD |
| # and can be read from there. |
| # |
| # For all other hardware, try to find a unique serial number from various |
| # sources. 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 |
| serial_number() { |
| local serial_number |
| |
| if crossystem "mainfw_type?nonchrome"; then |
| # 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}" |
| else |
| # On Chrome OS hardware, read from VPD. |
| vpd_get_value serial_number |
| fi |
| } |
| |
| # shellcheck disable=SC2154 |
| true > "${MACHINE_INFO}" |
| chmod 0644 "${MACHINE_INFO}" |
| |
| # Generate the key-value pairs we need, and capture and log errors. |
| MACHINE_INFO_ERR=$( { |
| # If we have the Flex ID tool, output a Flex ID, or a serial number if not. |
| if command -v flex_id_tool >/dev/null; then |
| echo "flex_id=\"$(flex_id_tool --type=id)\"" |
| else |
| echo "serial_number=\"$(serial_number)\"" |
| fi |
| |
| # 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)\"" |
| } 2>&1 >> "${MACHINE_INFO}" ) |
| if [ -n "${MACHINE_INFO_ERR}" ]; then |
| logger -t write-machine-info "${MACHINE_INFO_ERR}" |
| fi |