Willy Tu | 4dd03ca | 2021-08-06 09:37:35 -0700 | [diff] [blame] | 1 | FILESEXTRAPATHS:prepend:gbmc := "${THISDIR}/${PN}:" |
William A. Kennington III | 97b47e0 | 2021-07-15 16:23:01 -0700 | [diff] [blame] | 2 | |
Tom Tung | 4d433a4 | 2022-03-31 15:16:41 +0800 | [diff] [blame] | 3 | SRC_URI:append:gbmc = " \ |
William A. Kennington III | 38028f5 | 2023-10-18 16:07:34 -0700 | [diff] [blame] | 4 | file://gbmc_eth_config.json \ |
| 5 | file://gbmc_eth_access.json \ |
Tom Tung | 4d433a4 | 2022-03-31 15:16:41 +0800 | [diff] [blame] | 6 | " |
William A. Kennington III | 97b47e0 | 2021-07-15 16:23:01 -0700 | [diff] [blame] | 7 | |
Willy Tu | 4dd03ca | 2021-08-06 09:37:35 -0700 | [diff] [blame] | 8 | DEPENDS:append:gbmc = " jq-native" |
William A. Kennington III | 97b47e0 | 2021-07-15 16:23:01 -0700 | [diff] [blame] | 9 | |
| 10 | GBMCBR_IPMI_CHANNEL ?= "11" |
| 11 | |
Willy Tu | 1da8306 | 2022-04-07 23:48:56 -0700 | [diff] [blame] | 12 | ENTITY_MAPPING ?= "default" |
| 13 | |
William A. Kennington III | 38028f5 | 2023-10-18 16:07:34 -0700 | [diff] [blame] | 14 | gbmc_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 III | 97b47e0 | 2021-07-15 16:23:01 -0700 | [diff] [blame] | 27 | # Replace a channel in config.json to add gbmcbr reporting |
Willy Tu | 4dd03ca | 2021-08-06 09:37:35 -0700 | [diff] [blame] | 28 | do_install:append:gbmc() { |
Tom Tung | 4d433a4 | 2022-03-31 15:16:41 +0800 | [diff] [blame] | 29 | config_json=${D}${datadir}/ipmi-providers/channel_config.json |
William A. Kennington III | 38028f5 | 2023-10-18 16:07:34 -0700 | [diff] [blame] | 30 | access_json=${D}${datadir}/ipmi-providers/channel_access.json |
| 31 | |
Tom Tung | 4d433a4 | 2022-03-31 15:16:41 +0800 | [diff] [blame] | 32 | overlapping="$(jq '."${GBMCBR_IPMI_CHANNEL}" | .is_valid and .name != "gbmcbr"' $config_json)" |
William A. Kennington III | 97b47e0 | 2021-07-15 16:23:01 -0700 | [diff] [blame] | 33 | if [ "$overlapping" != "false" ]; then |
| 34 | echo "gBMC channel config overlaps on ${GBMCBR_IPMI_CHANNEL}" >&2 |
Tom Tung | 4d433a4 | 2022-03-31 15:16:41 +0800 | [diff] [blame] | 35 | cat $config_json |
William A. Kennington III | 97b47e0 | 2021-07-15 16:23:01 -0700 | [diff] [blame] | 36 | exit 1 |
| 37 | fi |
Tom Tung | 4d433a4 | 2022-03-31 15:16:41 +0800 | [diff] [blame] | 38 | 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 III | 38028f5 | 2023-10-18 16:07:34 -0700 | [diff] [blame] | 44 | gbmc_add_channel ${GBMCBR_IPMI_CHANNEL} gbmcbr |
William A. Kennington III | bff9031 | 2023-10-18 16:09:29 -0700 | [diff] [blame^] | 45 | if [ -n "${GBMC_NCSI_IF_NAME}" ]; then |
| 46 | gbmc_add_channel 1 ${GBMC_NCSI_IF_NAME} |
| 47 | fi |
Willy Tu | c93f10b | 2022-03-28 11:18:53 -0700 | [diff] [blame] | 48 | |
| 49 | # Set entity-map.json to empty json for gBMC by default. |
| 50 | # Each system will override it if needed. |
Willy Tu | 1da8306 | 2022-04-07 23:48:56 -0700 | [diff] [blame] | 51 | if [[ "${ENTITY_MAPPING}" != "default" ]]; then |
| 52 | echo "[]" > ${D}${datadir}/ipmi-providers/entity-map.json |
| 53 | fi |
William A. Kennington III | 97b47e0 | 2021-07-15 16:23:01 -0700 | [diff] [blame] | 54 | } |
Willy Tu | 2dc424c | 2022-06-09 13:21:39 -0700 | [diff] [blame] | 55 | |
| 56 | python 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 | |
| 87 | addtask gbmc_version after do_install before do_package |