Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(458)

Side by Side Diff: hardware_class

Issue 2824039: Use the HWID from the firmware as the hardware class, if available. (Closed) Base URL: ssh://git@chromiumos-git/metrics.git
Patch Set: Fix HWID path. Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/bin/sh 1 #!/bin/sh
2 2
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 # This script prints the hardware class (e.g., the hardware 7 # This script prints the hardware class (e.g., the hardware
8 # qualification ID) of this device, or "unknown" if it can't determine 8 # qualification ID) of this device, or "unknown" if it can't determine
9 # the hardware class. 9 # the hardware class.
10 10
11 # TODO(petkov): The hardware qualification ID is not available on 11 # TODO(petkov): If the hardware qualification ID is not available on
12 # systems yet, so the script uses alternative ways to identify 12 # the systems, the script uses alternative ways to identify different
13 # different system classes (e.g., the WiFi adapter PCI vendor and 13 # system classes (e.g., the WiFi adapter PCI vendor and device
14 # device IDs). Switch the script to use real hardware qualification ID 14 # IDs). Switch the script to use only real hardware qualification ID
15 # when that becomes available. 15 # when that becomes available on all systems.
16
17 HARDWARE_CLASS=
18 readonly HWID_PATH=/sys/bus/platform/devices/chromeos_acpi/HWID
16 19
17 # Appends a new component ID to the hardware class. Separates IDs with 20 # Appends a new component ID to the hardware class. Separates IDs with
18 # dashes. 21 # dashes.
19 append_class() { 22 append_class() {
23 [ -n "$1" ] || return
20 [ -n "$HARDWARE_CLASS" ] && HARDWARE_CLASS="${HARDWARE_CLASS}-" 24 [ -n "$HARDWARE_CLASS" ] && HARDWARE_CLASS="${HARDWARE_CLASS}-"
21 HARDWARE_CLASS="${HARDWARE_CLASS}$1" 25 HARDWARE_CLASS="${HARDWARE_CLASS}$1"
22 } 26 }
23 27
28 hwid() {
29 [ -r "$HWID_PATH" ] || return
30 local acpihwid
31 acpihwid=$(cat "$HWID_PATH")
32 [ -n "$acpihwid" ] || return
33 append_class "$acpihwid"
34 }
35
24 # Adds the CPU family, model and stepping info, if available, to the 36 # Adds the CPU family, model and stepping info, if available, to the
25 # class. 37 # class.
26 cpu() { 38 cpu() {
27 [ -r /proc/cpuinfo ] || return 39 [ -r /proc/cpuinfo ] || return
28 FAMILY=`grep -m1 '^cpu family' /proc/cpuinfo \ 40 local family
29 | sed 's/cpu family\s\+:\s\+\([0-9]\+\)$/\1/'` 41 family=$(grep -m1 '^cpu family' /proc/cpuinfo \
30 MODEL=`grep -m1 '^model' /proc/cpuinfo \ 42 | sed 's/cpu family\s\+:\s\+\([0-9]\+\)$/\1/')
31 | sed 's/model\s\+:\s\+\([0-9]\+\)$/\1/'` 43 local model
32 STEPPING=`grep -m1 '^stepping' /proc/cpuinfo \ 44 model=$(grep -m1 '^model' /proc/cpuinfo \
33 | sed 's/stepping\s\+:\s\+\([0-9]\+\)$/\1/'` 45 | sed 's/model\s\+:\s\+\([0-9]\+\)$/\1/')
34 if [ -n "$FAMILY" ] && [ -n "$MODEL" ] && [ -n "$STEPPING" ]; then 46 local stepping
35 append_class "cpu/$FAMILY:$MODEL:$STEPPING" 47 stepping=$(grep -m1 '^stepping' /proc/cpuinfo \
48 | sed 's/stepping\s\+:\s\+\([0-9]\+\)$/\1/')
49 if [ -n "$family" ] && [ -n "$model" ] && [ -n "$stepping" ]; then
50 append_class "cpu/$family:$model:$stepping"
36 fi 51 fi
37 } 52 }
38 53
39 # Adds the wlan0 PCI vendor and device ID, if available, to the class. 54 # Adds the wlan0 PCI vendor and device ID, if available, to the class.
40 wlan() { 55 wlan() {
41 WLAN_DEV=/sys/class/net/wlan0/device 56 local dev=/sys/class/net/wlan0/device
42 if [ -r $WLAN_DEV/vendor ] && [ -r $WLAN_DEV/device ]; then 57 if [ -r $dev/vendor ] && [ -r $dev/device ]; then
43 WLAN_ID=`paste -d ':' $WLAN_DEV/vendor $WLAN_DEV/device | sed s/0x//g` 58 local id
44 append_class "wlan0/$WLAN_ID" 59 id=$(paste -d ':' $dev/vendor $dev/device | sed s/0x//g)
60 append_class "wlan0/$id"
45 fi 61 fi
46 } 62 }
47 63
64 main() {
65 hwid
66 # If the HWID is not available, use system component IDs.
67 if [ -z "$HARDWARE_CLASS" ]; then
68 cpu
69 wlan
70 [ -z "$HARDWARE_CLASS" ] && HARDWARE_CLASS=unknown
71 fi
48 72
49 HARDWARE_CLASS= 73 echo $HARDWARE_CLASS
74 }
50 75
51 cpu 76 main $@
52 wlan
53
54 [ -z "$HARDWARE_CLASS" ] && HARDWARE_CLASS=unknown
55
56 echo $HARDWARE_CLASS
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698