Use the HWID from the firmware as the hardware class, if available.
BUG=3089
TEST=gmerge'd on device, ran with and without an hwid file.
Review URL: http://codereview.chromium.org/2824039
diff --git a/metrics/hardware_class b/metrics/hardware_class
index c99db9b..9136076 100755
--- a/metrics/hardware_class
+++ b/metrics/hardware_class
@@ -8,49 +8,69 @@
# qualification ID) of this device, or "unknown" if it can't determine
# the hardware class.
-# TODO(petkov): The hardware qualification ID is not available on
-# systems yet, so the script uses alternative ways to identify
-# different system classes (e.g., the WiFi adapter PCI vendor and
-# device IDs). Switch the script to use real hardware qualification ID
-# when that becomes available.
+# TODO(petkov): If the hardware qualification ID is not available on
+# the systems, the script uses alternative ways to identify different
+# system classes (e.g., the WiFi adapter PCI vendor and device
+# IDs). Switch the script to use only real hardware qualification ID
+# when that becomes available on all systems.
+
+HARDWARE_CLASS=
+readonly HWID_PATH=/sys/bus/platform/devices/chromeos_acpi/HWID
# Appends a new component ID to the hardware class. Separates IDs with
# dashes.
append_class() {
+ [ -n "$1" ] || return
[ -n "$HARDWARE_CLASS" ] && HARDWARE_CLASS="${HARDWARE_CLASS}-"
HARDWARE_CLASS="${HARDWARE_CLASS}$1"
}
+hwid() {
+ [ -r "$HWID_PATH" ] || return
+ local acpihwid
+ acpihwid=$(cat "$HWID_PATH")
+ [ -n "$acpihwid" ] || return
+ append_class "$acpihwid"
+}
+
# Adds the CPU family, model and stepping info, if available, to the
# class.
cpu() {
[ -r /proc/cpuinfo ] || return
- FAMILY=`grep -m1 '^cpu family' /proc/cpuinfo \
- | sed 's/cpu family\s\+:\s\+\([0-9]\+\)$/\1/'`
- MODEL=`grep -m1 '^model' /proc/cpuinfo \
- | sed 's/model\s\+:\s\+\([0-9]\+\)$/\1/'`
- STEPPING=`grep -m1 '^stepping' /proc/cpuinfo \
- | sed 's/stepping\s\+:\s\+\([0-9]\+\)$/\1/'`
- if [ -n "$FAMILY" ] && [ -n "$MODEL" ] && [ -n "$STEPPING" ]; then
- append_class "cpu/$FAMILY:$MODEL:$STEPPING"
+ local family
+ family=$(grep -m1 '^cpu family' /proc/cpuinfo \
+ | sed 's/cpu family\s\+:\s\+\([0-9]\+\)$/\1/')
+ local model
+ model=$(grep -m1 '^model' /proc/cpuinfo \
+ | sed 's/model\s\+:\s\+\([0-9]\+\)$/\1/')
+ local stepping
+ stepping=$(grep -m1 '^stepping' /proc/cpuinfo \
+ | sed 's/stepping\s\+:\s\+\([0-9]\+\)$/\1/')
+ if [ -n "$family" ] && [ -n "$model" ] && [ -n "$stepping" ]; then
+ append_class "cpu/$family:$model:$stepping"
fi
}
# Adds the wlan0 PCI vendor and device ID, if available, to the class.
wlan() {
- WLAN_DEV=/sys/class/net/wlan0/device
- if [ -r $WLAN_DEV/vendor ] && [ -r $WLAN_DEV/device ]; then
- WLAN_ID=`paste -d ':' $WLAN_DEV/vendor $WLAN_DEV/device | sed s/0x//g`
- append_class "wlan0/$WLAN_ID"
+ local dev=/sys/class/net/wlan0/device
+ if [ -r $dev/vendor ] && [ -r $dev/device ]; then
+ local id
+ id=$(paste -d ':' $dev/vendor $dev/device | sed s/0x//g)
+ append_class "wlan0/$id"
fi
}
+main() {
+ hwid
+ # If the HWID is not available, use system component IDs.
+ if [ -z "$HARDWARE_CLASS" ]; then
+ cpu
+ wlan
+ [ -z "$HARDWARE_CLASS" ] && HARDWARE_CLASS=unknown
+ fi
-HARDWARE_CLASS=
+ echo $HARDWARE_CLASS
+}
-cpu
-wlan
-
-[ -z "$HARDWARE_CLASS" ] && HARDWARE_CLASS=unknown
-
-echo $HARDWARE_CLASS
+main $@