summaryrefslogtreecommitdiff
path: root/meta-google/recipes-phosphor/ipmi/phosphor-ipmi-config.bbappend
blob: 121562af930ba80b6c81e22af35560d2990ef54c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
FILESEXTRAPATHS:prepend:gbmc := "${THISDIR}/${PN}:"

SRC_URI:append:gbmc = " \
  file://gbmc_eth_config.json \
  file://gbmc_eth_access.json \
"

DEPENDS:append:gbmc = " jq-native"

GBMCBR_IPMI_CHANNEL ?= "11"
GBMC_NCSI_IPMI_CHANNEL ??= "1"

ENTITY_MAPPING ?= "default"

gbmc_add_channel() {
  local chan="$1"
  local intf="$2"

  jq --slurpfile ecfg ${WORKDIR}/gbmc_eth_config.json --arg CHAN "$chan" --arg INTF "$intf" \
    '. + {$CHAN: ($ecfg[0] + {"name": $INTF})}' $config_json >${WORKDIR}/tmp-config.json
  mv ${WORKDIR}/tmp-config.json $config_json

  jq --slurpfile ecfg ${WORKDIR}/gbmc_eth_access.json --arg CHAN "$chan" \
    '. + {$CHAN: $ecfg[0]}' $access_json >${WORKDIR}/tmp-access.json
  mv ${WORKDIR}/tmp-access.json $access_json
}

# Replace a channel in config.json to add gbmcbr reporting
do_install:append:gbmc() {
  config_json=${D}${datadir}/ipmi-providers/channel_config.json
  access_json=${D}${datadir}/ipmi-providers/channel_access.json

  overlapping="$(jq '."${GBMCBR_IPMI_CHANNEL}" | .is_valid and .name != "gbmcbr"' $config_json)"
  if [ "$overlapping" != "false" ]; then
    echo "gBMC channel config overlaps on ${GBMCBR_IPMI_CHANNEL}" >&2
    cat $config_json
    exit 1
  fi
  overlapping="$(jq '."${GBMCBR_IPMI_CHANNEL}" | .access_mode and .access_mode != "always_available"' $access_json)"
  if [ "$overlapping" != "false" ]; then
    echo "gBMC channel access overlaps on ${GBMCBR_IPMI_CHANNEL}" >&2
    cat $access_json
    exit 1
  fi
  gbmc_add_channel ${GBMCBR_IPMI_CHANNEL} gbmcbr
  if [ -n "${GBMC_NCSI_IF_NAME}" ]; then
    gbmc_add_channel ${GBMC_NCSI_IPMI_CHANNEL} ${GBMC_NCSI_IF_NAME}
  fi

  # Set entity-map.json to empty json for gBMC by default.
  # Each system will override it if needed.
  if [[ "${ENTITY_MAPPING}" != "default" ]]; then
    echo "[]" > ${D}${datadir}/ipmi-providers/entity-map.json
  fi
}

python do_gbmc_version () {
  import json

  if d.getVar('GBMC_VERSION') is None:
    return

  version = d.getVar('GBMC_VERSION').split('.')
  major = min(int(version[0]), 0x7F) & 0x7F
  minor = min(int(version[1]), 99)
  minor = int(minor / 10) * 16 + minor % 10;
  point = int(version[2])
  subpoint = int(version[3])

  dir = d.getVar('D') + d.getVar('datadir') + '/ipmi-providers'
  path = os.path.join(dir, 'dev_id.json')

  dev_id = {}

  # Open existing dev_id and override the fields not needed for version.
  with open(path, 'r') as f:
    dev_id = json.load(f)
    dev_id["firmware_revision"] = {
      "major": major,
      "minor": minor
    }
    dev_id["aux"] =  subpoint << 16 | (0xFFFF & point)

  with open(path, 'w') as f:
    json.dump(dev_id, f, sort_keys=True, indent=4)
}

addtask gbmc_version after do_install before do_package