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" |
William A. Kennington III | cfcec1f | 2023-10-18 16:11:40 -0700 | [diff] [blame] | 11 | GBMC_NCSI_IPMI_CHANNEL ??= "1" |
Tom Tung | 40c8d14 | 2024-01-16 11:12:58 +0800 | [diff] [blame] | 12 | GBMC_NCSI_IPMI_CHANNEL:npcm8xx ??= "2" |
William A. Kennington III | 54ae5fd | 2023-10-18 16:12:42 -0700 | [diff] [blame] | 13 | # Only used for extra channels, GBMCBR and NCSI are autopopulated |
| 14 | # Format looks like "<channel>|<intf> <channel2>|<intf2>", Ex. "2|eth0 3|back" |
| 15 | GBMC_IPMI_CHANNEL_MAP ??= "" |
William A. Kennington III | 97b47e0 | 2021-07-15 16:23:01 -0700 | [diff] [blame] | 16 | |
Willy Tu | 1da8306 | 2022-04-07 23:48:56 -0700 | [diff] [blame] | 17 | ENTITY_MAPPING ?= "default" |
| 18 | |
William A. Kennington III | 38028f5 | 2023-10-18 16:07:34 -0700 | [diff] [blame] | 19 | gbmc_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 III | 97b47e0 | 2021-07-15 16:23:01 -0700 | [diff] [blame] | 32 | # Replace a channel in config.json to add gbmcbr reporting |
Willy Tu | 4dd03ca | 2021-08-06 09:37:35 -0700 | [diff] [blame] | 33 | do_install:append:gbmc() { |
Tom Tung | 4d433a4 | 2022-03-31 15:16:41 +0800 | [diff] [blame] | 34 | config_json=${D}${datadir}/ipmi-providers/channel_config.json |
William A. Kennington III | 38028f5 | 2023-10-18 16:07:34 -0700 | [diff] [blame] | 35 | access_json=${D}${datadir}/ipmi-providers/channel_access.json |
| 36 | |
Tom Tung | 4d433a4 | 2022-03-31 15:16:41 +0800 | [diff] [blame] | 37 | 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] | 38 | if [ "$overlapping" != "false" ]; then |
| 39 | echo "gBMC channel config overlaps on ${GBMCBR_IPMI_CHANNEL}" >&2 |
Tom Tung | 4d433a4 | 2022-03-31 15:16:41 +0800 | [diff] [blame] | 40 | cat $config_json |
William A. Kennington III | 97b47e0 | 2021-07-15 16:23:01 -0700 | [diff] [blame] | 41 | exit 1 |
| 42 | fi |
Tom Tung | 4d433a4 | 2022-03-31 15:16:41 +0800 | [diff] [blame] | 43 | 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 III | 38028f5 | 2023-10-18 16:07:34 -0700 | [diff] [blame] | 49 | gbmc_add_channel ${GBMCBR_IPMI_CHANNEL} gbmcbr |
William A. Kennington III | bff9031 | 2023-10-18 16:09:29 -0700 | [diff] [blame] | 50 | if [ -n "${GBMC_NCSI_IF_NAME}" ]; then |
William A. Kennington III | cfcec1f | 2023-10-18 16:11:40 -0700 | [diff] [blame] | 51 | gbmc_add_channel ${GBMC_NCSI_IPMI_CHANNEL} ${GBMC_NCSI_IF_NAME} |
William A. Kennington III | bff9031 | 2023-10-18 16:09:29 -0700 | [diff] [blame] | 52 | fi |
William A. Kennington III | 54ae5fd | 2023-10-18 16:12:42 -0700 | [diff] [blame] | 53 | 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 Tu | c93f10b | 2022-03-28 11:18:53 -0700 | [diff] [blame] | 62 | |
| 63 | # Set entity-map.json to empty json for gBMC by default. |
| 64 | # Each system will override it if needed. |
Willy Tu | 1da8306 | 2022-04-07 23:48:56 -0700 | [diff] [blame] | 65 | if [[ "${ENTITY_MAPPING}" != "default" ]]; then |
| 66 | echo "[]" > ${D}${datadir}/ipmi-providers/entity-map.json |
| 67 | fi |
William A. Kennington III | 97b47e0 | 2021-07-15 16:23:01 -0700 | [diff] [blame] | 68 | } |
Willy Tu | 2dc424c | 2022-06-09 13:21:39 -0700 | [diff] [blame] | 69 | |
| 70 | python 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 Fair | 5da95ea | 2024-03-29 18:09:17 +0000 | [diff] [blame] | 97 | dev_id["manuf_id"] = 11129 |
| 98 | dev_id["prod_id"] = 14426 |
| 99 | |
Willy Tu | 2dc424c | 2022-06-09 13:21:39 -0700 | [diff] [blame] | 100 | with open(path, 'w') as f: |
| 101 | json.dump(dev_id, f, sort_keys=True, indent=4) |
| 102 | } |
| 103 | |
| 104 | addtask gbmc_version after do_install before do_package |