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 = " \ |
| 4 | file://gbmc_bridge_config.json \ |
| 5 | file://gbmc_bridge_access.json \ |
| 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 | 97b47e0 | 2021-07-15 16:23:01 -0700 | [diff] [blame] | 14 | # Replace a channel in config.json to add gbmcbr reporting |
Willy Tu | 4dd03ca | 2021-08-06 09:37:35 -0700 | [diff] [blame] | 15 | do_install:append:gbmc() { |
Tom Tung | 4d433a4 | 2022-03-31 15:16:41 +0800 | [diff] [blame] | 16 | config_json=${D}${datadir}/ipmi-providers/channel_config.json |
| 17 | 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] | 18 | if [ "$overlapping" != "false" ]; then |
| 19 | echo "gBMC channel config overlaps on ${GBMCBR_IPMI_CHANNEL}" >&2 |
Tom Tung | 4d433a4 | 2022-03-31 15:16:41 +0800 | [diff] [blame] | 20 | cat $config_json |
William A. Kennington III | 97b47e0 | 2021-07-15 16:23:01 -0700 | [diff] [blame] | 21 | exit 1 |
| 22 | fi |
Tom Tung | 4d433a4 | 2022-03-31 15:16:41 +0800 | [diff] [blame] | 23 | jq --slurpfile brcfg ${WORKDIR}/gbmc_bridge_config.json \ |
| 24 | '. + {"${GBMCBR_IPMI_CHANNEL}": $brcfg[0]}' $config_json >${WORKDIR}/tmp |
| 25 | mv ${WORKDIR}/tmp $config_json |
| 26 | |
| 27 | access_json=${D}${datadir}/ipmi-providers/channel_access.json |
| 28 | overlapping="$(jq '."${GBMCBR_IPMI_CHANNEL}" | .access_mode and .access_mode != "always_available"' $access_json)" |
| 29 | if [ "$overlapping" != "false" ]; then |
| 30 | echo "gBMC channel access overlaps on ${GBMCBR_IPMI_CHANNEL}" >&2 |
| 31 | cat $access_json |
| 32 | exit 1 |
| 33 | fi |
| 34 | jq --slurpfile brcfg ${WORKDIR}/gbmc_bridge_access.json \ |
| 35 | '. + {"${GBMCBR_IPMI_CHANNEL}": $brcfg[0]}' $access_json >${WORKDIR}/tmp |
| 36 | mv ${WORKDIR}/tmp $access_json |
Willy Tu | c93f10b | 2022-03-28 11:18:53 -0700 | [diff] [blame] | 37 | |
| 38 | # Set entity-map.json to empty json for gBMC by default. |
| 39 | # Each system will override it if needed. |
Willy Tu | 1da8306 | 2022-04-07 23:48:56 -0700 | [diff] [blame] | 40 | if [[ "${ENTITY_MAPPING}" != "default" ]]; then |
| 41 | echo "[]" > ${D}${datadir}/ipmi-providers/entity-map.json |
| 42 | fi |
William A. Kennington III | 97b47e0 | 2021-07-15 16:23:01 -0700 | [diff] [blame] | 43 | } |
Willy Tu | 2dc424c | 2022-06-09 13:21:39 -0700 | [diff] [blame] | 44 | |
| 45 | python do_gbmc_version () { |
| 46 | import json |
| 47 | |
| 48 | if d.getVar('GBMC_VERSION') is None: |
| 49 | return |
| 50 | |
| 51 | version = d.getVar('GBMC_VERSION').split('.') |
| 52 | major = min(int(version[0]), 0x7F) & 0x7F |
| 53 | minor = min(int(version[1]), 99) |
| 54 | minor = int(minor / 10) * 16 + minor % 10; |
| 55 | point = int(version[2]) |
| 56 | subpoint = int(version[3]) |
| 57 | |
| 58 | dir = d.getVar('D') + d.getVar('datadir') + '/ipmi-providers' |
| 59 | path = os.path.join(dir, 'dev_id.json') |
| 60 | |
| 61 | dev_id = {} |
| 62 | |
| 63 | # Open existing dev_id and override the fields not needed for version. |
| 64 | with open(path, 'r') as f: |
| 65 | dev_id = json.load(f) |
| 66 | dev_id["firmware_revision"] = { |
| 67 | "major": major, |
| 68 | "minor": minor |
| 69 | } |
| 70 | dev_id["aux"] = subpoint << 16 | (0xFFFF & point) |
| 71 | |
| 72 | with open(path, 'w') as f: |
| 73 | json.dump(dev_id, f, sort_keys=True, indent=4) |
| 74 | } |
| 75 | |
| 76 | addtask gbmc_version after do_install before do_package |