blob: 782ebe36ef9cda7edb2cc731a12b10bc68df9f5a [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"
William A. Kennington IIIcfcec1f2023-10-18 16:11:40 -070011GBMC_NCSI_IPMI_CHANNEL ??= "1"
William A. Kennington III54ae5fd2023-10-18 16:12:42 -070012# Only used for extra channels, GBMCBR and NCSI are autopopulated
13# Format looks like "<channel>|<intf> <channel2>|<intf2>", Ex. "2|eth0 3|back"
14GBMC_IPMI_CHANNEL_MAP ??= ""
William A. Kennington III97b47e02021-07-15 16:23:01 -070015
Willy Tu1da83062022-04-07 23:48:56 -070016ENTITY_MAPPING ?= "default"
17
William A. Kennington III38028f52023-10-18 16:07:34 -070018gbmc_add_channel() {
19 local chan="$1"
20 local intf="$2"
21
22 jq --slurpfile ecfg ${WORKDIR}/gbmc_eth_config.json --arg CHAN "$chan" --arg INTF "$intf" \
23 '. + {$CHAN: ($ecfg[0] + {"name": $INTF})}' $config_json >${WORKDIR}/tmp-config.json
24 mv ${WORKDIR}/tmp-config.json $config_json
25
26 jq --slurpfile ecfg ${WORKDIR}/gbmc_eth_access.json --arg CHAN "$chan" \
27 '. + {$CHAN: $ecfg[0]}' $access_json >${WORKDIR}/tmp-access.json
28 mv ${WORKDIR}/tmp-access.json $access_json
29}
30
William A. Kennington III97b47e02021-07-15 16:23:01 -070031# Replace a channel in config.json to add gbmcbr reporting
Willy Tu4dd03ca2021-08-06 09:37:35 -070032do_install:append:gbmc() {
Tom Tung4d433a42022-03-31 15:16:41 +080033 config_json=${D}${datadir}/ipmi-providers/channel_config.json
William A. Kennington III38028f52023-10-18 16:07:34 -070034 access_json=${D}${datadir}/ipmi-providers/channel_access.json
35
Tom Tung4d433a42022-03-31 15:16:41 +080036 overlapping="$(jq '."${GBMCBR_IPMI_CHANNEL}" | .is_valid and .name != "gbmcbr"' $config_json)"
William A. Kennington III97b47e02021-07-15 16:23:01 -070037 if [ "$overlapping" != "false" ]; then
38 echo "gBMC channel config overlaps on ${GBMCBR_IPMI_CHANNEL}" >&2
Tom Tung4d433a42022-03-31 15:16:41 +080039 cat $config_json
William A. Kennington III97b47e02021-07-15 16:23:01 -070040 exit 1
41 fi
Tom Tung4d433a42022-03-31 15:16:41 +080042 overlapping="$(jq '."${GBMCBR_IPMI_CHANNEL}" | .access_mode and .access_mode != "always_available"' $access_json)"
43 if [ "$overlapping" != "false" ]; then
44 echo "gBMC channel access overlaps on ${GBMCBR_IPMI_CHANNEL}" >&2
45 cat $access_json
46 exit 1
47 fi
William A. Kennington III38028f52023-10-18 16:07:34 -070048 gbmc_add_channel ${GBMCBR_IPMI_CHANNEL} gbmcbr
William A. Kennington IIIbff90312023-10-18 16:09:29 -070049 if [ -n "${GBMC_NCSI_IF_NAME}" ]; then
William A. Kennington IIIcfcec1f2023-10-18 16:11:40 -070050 gbmc_add_channel ${GBMC_NCSI_IPMI_CHANNEL} ${GBMC_NCSI_IF_NAME}
William A. Kennington IIIbff90312023-10-18 16:09:29 -070051 fi
William A. Kennington III54ae5fd2023-10-18 16:12:42 -070052 map="${GBMC_IPMI_CHANNEL_MAP}"
53 # Split the map over the space separated entries
54 for entry in $map; do
55 OLDIFS="$IFS"
56 # Split the entry over the `|` separator
57 IFS='|'
58 gbmc_add_channel $entry
59 IFS="$OLDIFS"
60 done
Willy Tuc93f10b2022-03-28 11:18:53 -070061
62 # Set entity-map.json to empty json for gBMC by default.
63 # Each system will override it if needed.
Willy Tu1da83062022-04-07 23:48:56 -070064 if [[ "${ENTITY_MAPPING}" != "default" ]]; then
65 echo "[]" > ${D}${datadir}/ipmi-providers/entity-map.json
66 fi
William A. Kennington III97b47e02021-07-15 16:23:01 -070067}
Willy Tu2dc424c2022-06-09 13:21:39 -070068
69python do_gbmc_version () {
70 import json
71
72 if d.getVar('GBMC_VERSION') is None:
73 return
74
75 version = d.getVar('GBMC_VERSION').split('.')
76 major = min(int(version[0]), 0x7F) & 0x7F
77 minor = min(int(version[1]), 99)
78 minor = int(minor / 10) * 16 + minor % 10;
79 point = int(version[2])
80 subpoint = int(version[3])
81
82 dir = d.getVar('D') + d.getVar('datadir') + '/ipmi-providers'
83 path = os.path.join(dir, 'dev_id.json')
84
85 dev_id = {}
86
87 # Open existing dev_id and override the fields not needed for version.
88 with open(path, 'r') as f:
89 dev_id = json.load(f)
90 dev_id["firmware_revision"] = {
91 "major": major,
92 "minor": minor
93 }
94 dev_id["aux"] = subpoint << 16 | (0xFFFF & point)
95
96 with open(path, 'w') as f:
97 json.dump(dev_id, f, sort_keys=True, indent=4)
98}
99
100addtask gbmc_version after do_install before do_package