blob: 121562af930ba80b6c81e22af35560d2990ef54c [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 III97b47e02021-07-15 16:23:01 -070012
Willy Tu1da83062022-04-07 23:48:56 -070013ENTITY_MAPPING ?= "default"
14
William A. Kennington III38028f52023-10-18 16:07:34 -070015gbmc_add_channel() {
16 local chan="$1"
17 local intf="$2"
18
19 jq --slurpfile ecfg ${WORKDIR}/gbmc_eth_config.json --arg CHAN "$chan" --arg INTF "$intf" \
20 '. + {$CHAN: ($ecfg[0] + {"name": $INTF})}' $config_json >${WORKDIR}/tmp-config.json
21 mv ${WORKDIR}/tmp-config.json $config_json
22
23 jq --slurpfile ecfg ${WORKDIR}/gbmc_eth_access.json --arg CHAN "$chan" \
24 '. + {$CHAN: $ecfg[0]}' $access_json >${WORKDIR}/tmp-access.json
25 mv ${WORKDIR}/tmp-access.json $access_json
26}
27
William A. Kennington III97b47e02021-07-15 16:23:01 -070028# Replace a channel in config.json to add gbmcbr reporting
Willy Tu4dd03ca2021-08-06 09:37:35 -070029do_install:append:gbmc() {
Tom Tung4d433a42022-03-31 15:16:41 +080030 config_json=${D}${datadir}/ipmi-providers/channel_config.json
William A. Kennington III38028f52023-10-18 16:07:34 -070031 access_json=${D}${datadir}/ipmi-providers/channel_access.json
32
Tom Tung4d433a42022-03-31 15:16:41 +080033 overlapping="$(jq '."${GBMCBR_IPMI_CHANNEL}" | .is_valid and .name != "gbmcbr"' $config_json)"
William A. Kennington III97b47e02021-07-15 16:23:01 -070034 if [ "$overlapping" != "false" ]; then
35 echo "gBMC channel config overlaps on ${GBMCBR_IPMI_CHANNEL}" >&2
Tom Tung4d433a42022-03-31 15:16:41 +080036 cat $config_json
William A. Kennington III97b47e02021-07-15 16:23:01 -070037 exit 1
38 fi
Tom Tung4d433a42022-03-31 15:16:41 +080039 overlapping="$(jq '."${GBMCBR_IPMI_CHANNEL}" | .access_mode and .access_mode != "always_available"' $access_json)"
40 if [ "$overlapping" != "false" ]; then
41 echo "gBMC channel access overlaps on ${GBMCBR_IPMI_CHANNEL}" >&2
42 cat $access_json
43 exit 1
44 fi
William A. Kennington III38028f52023-10-18 16:07:34 -070045 gbmc_add_channel ${GBMCBR_IPMI_CHANNEL} gbmcbr
William A. Kennington IIIbff90312023-10-18 16:09:29 -070046 if [ -n "${GBMC_NCSI_IF_NAME}" ]; then
William A. Kennington IIIcfcec1f2023-10-18 16:11:40 -070047 gbmc_add_channel ${GBMC_NCSI_IPMI_CHANNEL} ${GBMC_NCSI_IF_NAME}
William A. Kennington IIIbff90312023-10-18 16:09:29 -070048 fi
Willy Tuc93f10b2022-03-28 11:18:53 -070049
50 # Set entity-map.json to empty json for gBMC by default.
51 # Each system will override it if needed.
Willy Tu1da83062022-04-07 23:48:56 -070052 if [[ "${ENTITY_MAPPING}" != "default" ]]; then
53 echo "[]" > ${D}${datadir}/ipmi-providers/entity-map.json
54 fi
William A. Kennington III97b47e02021-07-15 16:23:01 -070055}
Willy Tu2dc424c2022-06-09 13:21:39 -070056
57python do_gbmc_version () {
58 import json
59
60 if d.getVar('GBMC_VERSION') is None:
61 return
62
63 version = d.getVar('GBMC_VERSION').split('.')
64 major = min(int(version[0]), 0x7F) & 0x7F
65 minor = min(int(version[1]), 99)
66 minor = int(minor / 10) * 16 + minor % 10;
67 point = int(version[2])
68 subpoint = int(version[3])
69
70 dir = d.getVar('D') + d.getVar('datadir') + '/ipmi-providers'
71 path = os.path.join(dir, 'dev_id.json')
72
73 dev_id = {}
74
75 # Open existing dev_id and override the fields not needed for version.
76 with open(path, 'r') as f:
77 dev_id = json.load(f)
78 dev_id["firmware_revision"] = {
79 "major": major,
80 "minor": minor
81 }
82 dev_id["aux"] = subpoint << 16 | (0xFFFF & point)
83
84 with open(path, 'w') as f:
85 json.dump(dev_id, f, sort_keys=True, indent=4)
86}
87
88addtask gbmc_version after do_install before do_package