blob: 1afe115502269804469cc1f61959be70757e9251 [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
William A. Kennington IIIbff90312023-10-18 16:09:29 -070045 if [ -n "${GBMC_NCSI_IF_NAME}" ]; then
46 gbmc_add_channel 1 ${GBMC_NCSI_IF_NAME}
47 fi
Willy Tuc93f10b2022-03-28 11:18:53 -070048
49 # Set entity-map.json to empty json for gBMC by default.
50 # Each system will override it if needed.
Willy Tu1da83062022-04-07 23:48:56 -070051 if [[ "${ENTITY_MAPPING}" != "default" ]]; then
52 echo "[]" > ${D}${datadir}/ipmi-providers/entity-map.json
53 fi
William A. Kennington III97b47e02021-07-15 16:23:01 -070054}
Willy Tu2dc424c2022-06-09 13:21:39 -070055
56python do_gbmc_version () {
57 import json
58
59 if d.getVar('GBMC_VERSION') is None:
60 return
61
62 version = d.getVar('GBMC_VERSION').split('.')
63 major = min(int(version[0]), 0x7F) & 0x7F
64 minor = min(int(version[1]), 99)
65 minor = int(minor / 10) * 16 + minor % 10;
66 point = int(version[2])
67 subpoint = int(version[3])
68
69 dir = d.getVar('D') + d.getVar('datadir') + '/ipmi-providers'
70 path = os.path.join(dir, 'dev_id.json')
71
72 dev_id = {}
73
74 # Open existing dev_id and override the fields not needed for version.
75 with open(path, 'r') as f:
76 dev_id = json.load(f)
77 dev_id["firmware_revision"] = {
78 "major": major,
79 "minor": minor
80 }
81 dev_id["aux"] = subpoint << 16 | (0xFFFF & point)
82
83 with open(path, 'w') as f:
84 json.dump(dev_id, f, sort_keys=True, indent=4)
85}
86
87addtask gbmc_version after do_install before do_package