blob: d490c08745385fe82cee61919c388da472987772 [file] [log] [blame]
Adriana Kobylakb96c7502021-08-06 16:25:30 +00001FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
Tom Joseph6c09f7a2018-09-24 07:34:14 -05002
3# Calculate the auxiliary firmware revision to be updated in the dev_id.json
4# file. It is calculated from the VERSION_ID field which currently has two
5# formats. The revision field is 4 bytes, the first two bytes represent the
6# count of commits from the tagging and next two bytes represent the version.
7# Both fields are represented in BCD encoded format, so 9999 is the maximum
8# value both fields can take. With the format "v2.1-216-ga78ace8", Petitboot
9# would display the firmware revision as "Firmware version: 2.01.02160000",
10# "0216" is count and the revision is "0000". With the format
11# "ibm-v2.0-10-r41-0-gd0c319e" Petitboot would display the firmware revision
12# as "Firmware version: 2.00.00100041", "0010" is count and the revision
13# is "0041".
14inherit image_version
15
16unset do_patch[noexec]
17do_patch[depends] = "os-release:do_populate_sysroot"
18
Adriana Kobylakb96c7502021-08-06 16:25:30 +000019python do_patch:ibm-ac-server() {
Tom Joseph6c09f7a2018-09-24 07:34:14 -050020 import json
21 import re
22 from shutil import copyfile
23 version_id = do_get_version(d)
24
Adriana Kobylak49054bc2021-01-14 15:37:48 -060025 # count from the commit version, minimum of one digit
Tom Joseph6c09f7a2018-09-24 07:34:14 -050026 count = re.findall("-(\d{1,4})-", version_id)
Adriana Kobylak49054bc2021-01-14 15:37:48 -060027 if count:
28 commit = count[0]
29 else:
30 commit = "0"
Tom Joseph6c09f7a2018-09-24 07:34:14 -050031
32 release = re.findall("-r(\d{1,4})", version_id)
33 if release:
Adriana Kobylak49054bc2021-01-14 15:37:48 -060034 auxVer = commit + "{0:0>4}".format(release[0])
Tom Joseph6c09f7a2018-09-24 07:34:14 -050035 else:
Adriana Kobylak49054bc2021-01-14 15:37:48 -060036 auxVer = commit + "0000"
Tom Joseph6c09f7a2018-09-24 07:34:14 -050037
38 workdir = d.getVar('WORKDIR', True)
39 file = os.path.join(workdir, 'dev_id.json')
40
41 # Update dev_id.json with the auxiliary firmware revision
42 with open(file, "r+") as jsonFile:
43 data = json.load(jsonFile)
44 jsonFile.seek(0)
45 jsonFile.truncate()
46 data["aux"] = int(auxVer, 16)
47 json.dump(data, jsonFile)
48}