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