Darin Petkov | 51a83db | 2010-05-26 15:37:25 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 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 |
| 5 | # found in the LICENSE file. |
| 6 | |
| 7 | # This script prints the hardware class (e.g., the hardware |
| 8 | # qualification ID) of this device, or "unknown" if it can't determine |
| 9 | # the hardware class. |
| 10 | |
Darin Petkov | 1c2b4c8 | 2010-06-30 10:30:27 -0700 | [diff] [blame] | 11 | # TODO(petkov): If the hardware qualification ID is not available on |
| 12 | # the systems, the script uses alternative ways to identify different |
| 13 | # system classes (e.g., the WiFi adapter PCI vendor and device |
| 14 | # IDs). Switch the script to use only real hardware qualification ID |
| 15 | # when that becomes available on all systems. |
| 16 | |
| 17 | HARDWARE_CLASS= |
| 18 | readonly HWID_PATH=/sys/bus/platform/devices/chromeos_acpi/HWID |
Darin Petkov | 51a83db | 2010-05-26 15:37:25 -0700 | [diff] [blame] | 19 | |
| 20 | # Appends a new component ID to the hardware class. Separates IDs with |
| 21 | # dashes. |
| 22 | append_class() { |
Darin Petkov | 1c2b4c8 | 2010-06-30 10:30:27 -0700 | [diff] [blame] | 23 | [ -n "$1" ] || return |
Darin Petkov | 51a83db | 2010-05-26 15:37:25 -0700 | [diff] [blame] | 24 | [ -n "$HARDWARE_CLASS" ] && HARDWARE_CLASS="${HARDWARE_CLASS}-" |
| 25 | HARDWARE_CLASS="${HARDWARE_CLASS}$1" |
| 26 | } |
| 27 | |
Darin Petkov | 1c2b4c8 | 2010-06-30 10:30:27 -0700 | [diff] [blame] | 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 | |
Darin Petkov | 51a83db | 2010-05-26 15:37:25 -0700 | [diff] [blame] | 36 | # Adds the CPU family, model and stepping info, if available, to the |
| 37 | # class. |
| 38 | cpu() { |
| 39 | [ -r /proc/cpuinfo ] || return |
Darin Petkov | 1c2b4c8 | 2010-06-30 10:30:27 -0700 | [diff] [blame] | 40 | local family |
| 41 | family=$(grep -m1 '^cpu family' /proc/cpuinfo \ |
| 42 | | sed 's/cpu family\s\+:\s\+\([0-9]\+\)$/\1/') |
| 43 | local model |
| 44 | model=$(grep -m1 '^model' /proc/cpuinfo \ |
| 45 | | sed 's/model\s\+:\s\+\([0-9]\+\)$/\1/') |
| 46 | local 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" |
Darin Petkov | 51a83db | 2010-05-26 15:37:25 -0700 | [diff] [blame] | 51 | fi |
| 52 | } |
| 53 | |
| 54 | # Adds the wlan0 PCI vendor and device ID, if available, to the class. |
| 55 | wlan() { |
Darin Petkov | 1c2b4c8 | 2010-06-30 10:30:27 -0700 | [diff] [blame] | 56 | local dev=/sys/class/net/wlan0/device |
| 57 | if [ -r $dev/vendor ] && [ -r $dev/device ]; then |
| 58 | local id |
| 59 | id=$(paste -d ':' $dev/vendor $dev/device | sed s/0x//g) |
| 60 | append_class "wlan0/$id" |
Darin Petkov | 51a83db | 2010-05-26 15:37:25 -0700 | [diff] [blame] | 61 | fi |
| 62 | } |
| 63 | |
Darin Petkov | 1c2b4c8 | 2010-06-30 10:30:27 -0700 | [diff] [blame] | 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 |
Darin Petkov | 51a83db | 2010-05-26 15:37:25 -0700 | [diff] [blame] | 72 | |
Darin Petkov | 1c2b4c8 | 2010-06-30 10:30:27 -0700 | [diff] [blame] | 73 | echo $HARDWARE_CLASS |
| 74 | } |
Darin Petkov | 51a83db | 2010-05-26 15:37:25 -0700 | [diff] [blame] | 75 | |
Darin Petkov | 1c2b4c8 | 2010-06-30 10:30:27 -0700 | [diff] [blame] | 76 | main $@ |