blob: 71826959e22d77eee3263e6160638da956a8aa6e [file] [log] [blame]
George Liudd6464e2021-08-07 10:09:52 +08001FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
John Wang0641c482019-06-27 10:50:24 +08002
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
19python do_patch() {
20 import json
21 import re
22 from shutil import copyfile
23 version_id = do_get_version(d)
24
25 # count from the commit version
26 count = re.findall("-(\d{1,4})-", version_id)
27
George Liuc2f79e42020-09-08 13:39:16 +080028 if not count:
29 return
30
John Wang0641c482019-06-27 10:50:24 +080031 release = re.findall("-r(\d{1,4})", version_id)
32 if release:
33 auxVer = count[0] + "{0:0>4}".format(release[0])
34 else:
35 auxVer = count[0] + "0000"
36
37 workdir = d.getVar('WORKDIR', True)
38 file = os.path.join(workdir, 'dev_id.json')
39
40 # Update dev_id.json with the auxiliary firmware revision
41 with open(file, "r+") as jsonFile:
42 data = json.load(jsonFile)
43 jsonFile.seek(0)
44 jsonFile.truncate()
45 data["aux"] = int(auxVer, 16)
46 json.dump(data, jsonFile)
47}