blob: 91360766677d555acb12716346f4570fb79a0a0d [file] [log] [blame]
Darin Petkov51a83db2010-05-26 15:37:25 -07001#!/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 Petkov1c2b4c82010-06-30 10:30:27 -070011# 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
17HARDWARE_CLASS=
18readonly HWID_PATH=/sys/bus/platform/devices/chromeos_acpi/HWID
Darin Petkov51a83db2010-05-26 15:37:25 -070019
20# Appends a new component ID to the hardware class. Separates IDs with
21# dashes.
22append_class() {
Darin Petkov1c2b4c82010-06-30 10:30:27 -070023 [ -n "$1" ] || return
Darin Petkov51a83db2010-05-26 15:37:25 -070024 [ -n "$HARDWARE_CLASS" ] && HARDWARE_CLASS="${HARDWARE_CLASS}-"
25 HARDWARE_CLASS="${HARDWARE_CLASS}$1"
26}
27
Darin Petkov1c2b4c82010-06-30 10:30:27 -070028hwid() {
29 [ -r "$HWID_PATH" ] || return
30 local acpihwid
31 acpihwid=$(cat "$HWID_PATH")
32 [ -n "$acpihwid" ] || return
33 append_class "$acpihwid"
34}
35
Darin Petkov51a83db2010-05-26 15:37:25 -070036# Adds the CPU family, model and stepping info, if available, to the
37# class.
38cpu() {
39 [ -r /proc/cpuinfo ] || return
Darin Petkov1c2b4c82010-06-30 10:30:27 -070040 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 Petkov51a83db2010-05-26 15:37:25 -070051 fi
52}
53
54# Adds the wlan0 PCI vendor and device ID, if available, to the class.
55wlan() {
Darin Petkov1c2b4c82010-06-30 10:30:27 -070056 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 Petkov51a83db2010-05-26 15:37:25 -070061 fi
62}
63
Darin Petkov1c2b4c82010-06-30 10:30:27 -070064main() {
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 Petkov51a83db2010-05-26 15:37:25 -070072
Darin Petkov1c2b4c82010-06-30 10:30:27 -070073 echo $HARDWARE_CLASS
74}
Darin Petkov51a83db2010-05-26 15:37:25 -070075
Darin Petkov1c2b4c82010-06-30 10:30:27 -070076main $@