blob: 0250bda9aef67e870eb2486387c2c8112638c9e1 [file] [log] [blame]
Willy Tu4dd03ca2021-08-06 09:37:35 -07001FILESEXTRAPATHS:prepend:gbmc := "${THISDIR}/${PN}:"
William A. Kennington III97b47e02021-07-15 16:23:01 -07002
Tom Tung4d433a42022-03-31 15:16:41 +08003SRC_URI:append:gbmc = " \
William A. Kennington III38028f52023-10-18 16:07:34 -07004 file://gbmc_eth_config.json \
5 file://gbmc_eth_access.json \
Tom Tung4d433a42022-03-31 15:16:41 +08006"
William A. Kennington III97b47e02021-07-15 16:23:01 -07007
Willy Tu4dd03ca2021-08-06 09:37:35 -07008DEPENDS:append:gbmc = " jq-native"
William A. Kennington III97b47e02021-07-15 16:23:01 -07009
10GBMCBR_IPMI_CHANNEL ?= "11"
11
Willy Tu1da83062022-04-07 23:48:56 -070012ENTITY_MAPPING ?= "default"
13
William A. Kennington III38028f52023-10-18 16:07:34 -070014gbmc_add_channel() {
15 local chan="$1"
16 local intf="$2"
17
18 jq --slurpfile ecfg ${WORKDIR}/gbmc_eth_config.json --arg CHAN "$chan" --arg INTF "$intf" \
19 '. + {$CHAN: ($ecfg[0] + {"name": $INTF})}' $config_json >${WORKDIR}/tmp-config.json
20 mv ${WORKDIR}/tmp-config.json $config_json
21
22 jq --slurpfile ecfg ${WORKDIR}/gbmc_eth_access.json --arg CHAN "$chan" \
23 '. + {$CHAN: $ecfg[0]}' $access_json >${WORKDIR}/tmp-access.json
24 mv ${WORKDIR}/tmp-access.json $access_json
25}
26
William A. Kennington III97b47e02021-07-15 16:23:01 -070027# Replace a channel in config.json to add gbmcbr reporting
Willy Tu4dd03ca2021-08-06 09:37:35 -070028do_install:append:gbmc() {
Tom Tung4d433a42022-03-31 15:16:41 +080029 config_json=${D}${datadir}/ipmi-providers/channel_config.json
William A. Kennington III38028f52023-10-18 16:07:34 -070030 access_json=${D}${datadir}/ipmi-providers/channel_access.json
31
Tom Tung4d433a42022-03-31 15:16:41 +080032 overlapping="$(jq '."${GBMCBR_IPMI_CHANNEL}" | .is_valid and .name != "gbmcbr"' $config_json)"
William A. Kennington III97b47e02021-07-15 16:23:01 -070033 if [ "$overlapping" != "false" ]; then
34 echo "gBMC channel config overlaps on ${GBMCBR_IPMI_CHANNEL}" >&2
Tom Tung4d433a42022-03-31 15:16:41 +080035 cat $config_json
William A. Kennington III97b47e02021-07-15 16:23:01 -070036 exit 1
37 fi
Tom Tung4d433a42022-03-31 15:16:41 +080038 overlapping="$(jq '."${GBMCBR_IPMI_CHANNEL}" | .access_mode and .access_mode != "always_available"' $access_json)"
39 if [ "$overlapping" != "false" ]; then
40 echo "gBMC channel access overlaps on ${GBMCBR_IPMI_CHANNEL}" >&2
41 cat $access_json
42 exit 1
43 fi
William A. Kennington III38028f52023-10-18 16:07:34 -070044 gbmc_add_channel ${GBMCBR_IPMI_CHANNEL} gbmcbr
Willy Tuc93f10b2022-03-28 11:18:53 -070045
46 # Set entity-map.json to empty json for gBMC by default.
47 # Each system will override it if needed.
Willy Tu1da83062022-04-07 23:48:56 -070048 if [[ "${ENTITY_MAPPING}" != "default" ]]; then
49 echo "[]" > ${D}${datadir}/ipmi-providers/entity-map.json
50 fi
William A. Kennington III97b47e02021-07-15 16:23:01 -070051}
Willy Tu2dc424c2022-06-09 13:21:39 -070052
53python do_gbmc_version () {
54 import json
55
56 if d.getVar('GBMC_VERSION') is None:
57 return
58
59 version = d.getVar('GBMC_VERSION').split('.')
60 major = min(int(version[0]), 0x7F) & 0x7F
61 minor = min(int(version[1]), 99)
62 minor = int(minor / 10) * 16 + minor % 10;
63 point = int(version[2])
64 subpoint = int(version[3])
65
66 dir = d.getVar('D') + d.getVar('datadir') + '/ipmi-providers'
67 path = os.path.join(dir, 'dev_id.json')
68
69 dev_id = {}
70
71 # Open existing dev_id and override the fields not needed for version.
72 with open(path, 'r') as f:
73 dev_id = json.load(f)
74 dev_id["firmware_revision"] = {
75 "major": major,
76 "minor": minor
77 }
78 dev_id["aux"] = subpoint << 16 | (0xFFFF & point)
79
80 with open(path, 'w') as f:
81 json.dump(dev_id, f, sort_keys=True, indent=4)
82}
83
84addtask gbmc_version after do_install before do_package