Tim Lee | cbb46b9 | 2020-06-18 09:28:26 +0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | string='' |
| 4 | pmbus_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 | |
| 22 | update_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 | |
| 36 | if [ $# -eq 0 ]; then |
| 37 | echo 'No PSU device is given' >&2 |
| 38 | exit 1 |
| 39 | fi |
| 40 | |
| 41 | input=$(echo $1 | tr "-" " ") |
| 42 | arr=(${input// / }); |
| 43 | |
| 44 | |
| 45 | pmbus_read ${arr[1]} ${arr[2]} 0x99 11 |
| 46 | update_inventory ${arr[0]} "xyz.openbmc_project.Inventory.Decorator.Asset" 1 "Manufacturer" "s" $string |
| 47 | |
| 48 | pmbus_read ${arr[1]} ${arr[2]} 0x9a 11 |
| 49 | update_inventory ${arr[0]} "xyz.openbmc_project.Inventory.Decorator.Asset" 1 "Model" "s" $string |
| 50 | |
| 51 | pmbus_read ${arr[1]} ${arr[2]} 0xad 21 |
| 52 | update_inventory ${arr[0]} "xyz.openbmc_project.Inventory.Decorator.Asset" 1 "PartNumber" "s" $string |
| 53 | |
| 54 | pmbus_read ${arr[1]} ${arr[2]} 0x9e 18 |
| 55 | update_inventory ${arr[0]} "xyz.openbmc_project.Inventory.Decorator.Asset" 1 "SerialNumber" "s" $string |
| 56 | |
| 57 | update_inventory ${arr[0]} "xyz.openbmc_project.Inventory.Decorator.Cacheable" 1 "Cached" "b" "true" |
| 58 | update_inventory ${arr[0]} "xyz.openbmc_project.Inventory.Decorator.Replaceable" 1 "FieldReplaceable" "b" "true" |
| 59 | update_inventory ${arr[0]} "xyz.openbmc_project.Inventory.Item" 1 "Present" "b" "true" |
| 60 | update_inventory ${arr[0]} "xyz.openbmc_project.Inventory.Item" 1 "PrettyName" "s" "powersupply${arr[0]}" |
| 61 | update_inventory ${arr[0]} "xyz.openbmc_project.Inventory.Item.PowerSupply" 0 |