xref: /openbmc/openbmc/meta-ibm/recipes-phosphor/ipmi/phosphor-ipmi-config.bbappend (revision 91a1cec28e08f949b120fe8885e87ef256ca4d93)
1b96c7504SAdriana KobylakFILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
2e1615142SBrad Bishop
3e1615142SBrad Bishop# Calculate the auxiliary firmware revision to be updated in the dev_id.json
4e1615142SBrad Bishop# file. It is calculated from the VERSION_ID field which currently has two
5e1615142SBrad Bishop# formats. The revision field is 4 bytes, the first two bytes represent the
6e1615142SBrad Bishop# count of commits from the tagging and next two bytes represent the version.
7e1615142SBrad Bishop# Both fields are represented in BCD encoded format, so 9999 is the maximum
8e1615142SBrad Bishop# value both fields can take. With the format "v2.1-216-ga78ace8", Petitboot
9e1615142SBrad Bishop# would display the firmware revision as "Firmware version: 2.01.02160000",
10e1615142SBrad Bishop# "0216" is count and the revision is "0000". With the format
11e1615142SBrad Bishop# "ibm-v2.0-10-r41-0-gd0c319e" Petitboot would display the firmware revision
12e1615142SBrad Bishop# as "Firmware version: 2.00.00100041", "0010" is count and the revision
13e1615142SBrad Bishop# is "0041".
14e1615142SBrad Bishopinherit image_version
15e1615142SBrad Bishop
16e1615142SBrad Bishopunset do_patch[noexec]
17e1615142SBrad Bishopdo_patch[depends] = "os-release:do_populate_sysroot"
18e1615142SBrad Bishop
19b96c7504SAdriana Kobylakpython do_patch:ibm-ac-server() {
20e1615142SBrad Bishop    import json
21e1615142SBrad Bishop    import re
22e1615142SBrad Bishop    from shutil import copyfile
23e1615142SBrad Bishop    version_id = do_get_version(d)
24e1615142SBrad Bishop
2549054bcbSAdriana Kobylak    # count from the commit version, minimum of one digit
26e1615142SBrad Bishop    count = re.findall("-(\d{1,4})-", version_id)
2749054bcbSAdriana Kobylak    if count:
2849054bcbSAdriana Kobylak        commit = count[0]
2949054bcbSAdriana Kobylak    else:
3049054bcbSAdriana Kobylak        commit = "0"
31e1615142SBrad Bishop
32e1615142SBrad Bishop    release = re.findall("-r(\d{1,4})", version_id)
33e1615142SBrad Bishop    if release:
3449054bcbSAdriana Kobylak        auxVer = commit + "{0:0>4}".format(release[0])
35e1615142SBrad Bishop    else:
3649054bcbSAdriana Kobylak        auxVer = commit + "0000"
37e1615142SBrad Bishop
38*91a1cec2SAndrew Geissler    unpackdir = d.getVar('UNPACKDIR', True)
39*91a1cec2SAndrew Geissler    file = os.path.join(unpackdir, 'dev_id.json')
40e1615142SBrad Bishop
41e1615142SBrad Bishop    # Update dev_id.json with the auxiliary firmware revision
42e1615142SBrad Bishop    with open(file, "r+") as jsonFile:
43e1615142SBrad Bishop        data = json.load(jsonFile)
44e1615142SBrad Bishop        jsonFile.seek(0)
45e1615142SBrad Bishop        jsonFile.truncate()
46e1615142SBrad Bishop        data["aux"] = int(auxVer, 16)
47e1615142SBrad Bishop        json.dump(data, jsonFile)
48e1615142SBrad Bishop}
49