blob: 04b447615ab1c19bc95ebd764d235c0cab5d5a74 [file] [log] [blame]
Tim Leecbb46b92020-06-18 09:28:26 +08001#!/bin/bash
2
3string=''
4pmbus_read() {
5 data=$(i2cget -f -y $1 $2 $3 i $4)
6
7 if [[ -z "$data" ]]; then
8 echo "i2c$1 device $2 command $3 error" >&2
9 exit 1
10 fi
11
12 arry=$(echo ${data} | sed -e "s/$4\: //" | sed -e "s/\0x00//g" | sed -e "s/\0xff//g" | sed -e "s/\0x7f//g" | sed -e "s/\0x0f//g" | sed -e "s/\0x14//g")
13
14 string=''
15 for d in ${arry}
16 do
17 hex=$(echo $d | sed -e "s/0\x//")
18 string+=$(echo -e "\x${hex}");
19 done
20}
21
22update_inventory() {
23 INVENTORY_SERVICE='xyz.openbmc_project.Inventory.Manager'
24 INVENTORY_OBJECT='/xyz/openbmc_project/inventory'
25 INVENTORY_PATH='xyz.openbmc_project.Inventory.Manager'
26 OBJECT_PATH="/system/chassis/motherboard/powersupply$1"
27 busctl call \
28 ${INVENTORY_SERVICE} \
29 ${INVENTORY_OBJECT} \
30 ${INVENTORY_PATH} \
31 Notify a{oa{sa{sv}}} 1 \
32 ${OBJECT_PATH} 1 $2 $3 \
33 $4 $5 $6
34}
35
36if [ $# -eq 0 ]; then
37 echo 'No PSU device is given' >&2
38 exit 1
39fi
40
41input=$(echo $1 | tr "-" " ")
42arr=(${input// / });
43
44
45pmbus_read ${arr[1]} ${arr[2]} 0x99 11
46update_inventory ${arr[0]} "xyz.openbmc_project.Inventory.Decorator.Asset" 1 "Manufacturer" "s" $string
47
48pmbus_read ${arr[1]} ${arr[2]} 0x9a 11
49update_inventory ${arr[0]} "xyz.openbmc_project.Inventory.Decorator.Asset" 1 "Model" "s" $string
50
51pmbus_read ${arr[1]} ${arr[2]} 0xad 21
52update_inventory ${arr[0]} "xyz.openbmc_project.Inventory.Decorator.Asset" 1 "PartNumber" "s" $string
53
54pmbus_read ${arr[1]} ${arr[2]} 0x9e 18
55update_inventory ${arr[0]} "xyz.openbmc_project.Inventory.Decorator.Asset" 1 "SerialNumber" "s" $string
56
57update_inventory ${arr[0]} "xyz.openbmc_project.Inventory.Decorator.Cacheable" 1 "Cached" "b" "true"
58update_inventory ${arr[0]} "xyz.openbmc_project.Inventory.Decorator.Replaceable" 1 "FieldReplaceable" "b" "true"
59update_inventory ${arr[0]} "xyz.openbmc_project.Inventory.Item" 1 "Present" "b" "true"
60update_inventory ${arr[0]} "xyz.openbmc_project.Inventory.Item" 1 "PrettyName" "s" "powersupply${arr[0]}"
61update_inventory ${arr[0]} "xyz.openbmc_project.Inventory.Item.PowerSupply" 0