blob: 3256e834a3a69559562f737e42210c1bc271c52f [file] [log] [blame]
John Wang0641c482019-06-27 10:50:24 +08001FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
2
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
28 release = re.findall("-r(\d{1,4})", version_id)
29 if release:
30 auxVer = count[0] + "{0:0>4}".format(release[0])
31 else:
32 auxVer = count[0] + "0000"
33
34 workdir = d.getVar('WORKDIR', True)
35 file = os.path.join(workdir, 'dev_id.json')
36
37 # Update dev_id.json with the auxiliary firmware revision
38 with open(file, "r+") as jsonFile:
39 data = json.load(jsonFile)
40 jsonFile.seek(0)
41 jsonFile.truncate()
42 data["aux"] = int(auxVer, 16)
43 json.dump(data, jsonFile)
44}