diff options
author | Anand Balagopalakrishnan | 2020-08-11 16:33:06 -0500 |
---|---|---|
committer | Dave Gerlach | 2020-08-14 12:11:07 -0500 |
commit | a8d5f684d000788a8e4e700c20bf7455110faf36 (patch) | |
tree | 92c074f85a9a19edd260071c6c2f24e04bf58c2f | |
parent | bbc59bcc2d004ffa9ea7ff53532f85caf888ee99 (diff) | |
download | k3-image-gen-a8d5f684d000788a8e4e700c20bf7455110faf36.tar.gz k3-image-gen-a8d5f684d000788a8e4e700c20bf7455110faf36.tar.xz k3-image-gen-a8d5f684d000788a8e4e700c20bf7455110faf36.zip |
scripts: sysfw_boardcfg_blob_creator: Add support for combining board configurations files
The sysfw data in the new Combined ROM image format should be a single
file containing all the four board configurations. Add support for
combining all the four board configurations.
Signed-off-by: Anand Balagopalakrishnan <anandb@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
-rw-r--r-- | Makefile | 3 | ||||
-rwxr-xr-x | scripts/sysfw_boardcfg_blob_creator.py | 105 |
2 files changed, 108 insertions, 0 deletions
@@ -109,6 +109,7 @@ SOC_BIN_NAMES += $(SOURCES:%.c=%.bin) | |||
109 | 109 | ||
110 | ITB ?= $(binroot)/sysfw-$(SOC)-$(CONFIG).itb | 110 | ITB ?= $(binroot)/sysfw-$(SOC)-$(CONFIG).itb |
111 | ITS ?= $(soc_objroot)/$(basename $(notdir $(ITB))).its | 111 | ITS ?= $(soc_objroot)/$(basename $(notdir $(ITB))).its |
112 | COMBINED_BRDCFG ?= $(soc_objroot)/combined-cfg.bin | ||
112 | 113 | ||
113 | vpath %.itb $(soc_objroot) | 114 | vpath %.itb $(soc_objroot) |
114 | vpath %.bin $(soc_objroot) | 115 | vpath %.bin $(soc_objroot) |
@@ -172,6 +173,8 @@ sysfw.itb: $(ITB) | |||
172 | 173 | ||
173 | soc_objs: $(SOC_OBJS) | 174 | soc_objs: $(SOC_OBJS) |
174 | 175 | ||
176 | $(COMBINED_BRDCFG): $(SOC_BINS) | ||
177 | python3 ./scripts/sysfw_boardcfg_blob_creator.py -b $(soc_objroot)/board-cfg.bin -s $(soc_objroot)/sec-cfg.bin -p $(soc_objroot)/pm-cfg.bin -r $(soc_objroot)/rm-cfg.bin -o $@ | ||
175 | 178 | ||
176 | $(soc_objroot)/%.o: %.c | 179 | $(soc_objroot)/%.o: %.c |
177 | $(CROSS_COMPILE)gcc $(CFLAGS) -c -o $@-pre-validated $< | 180 | $(CROSS_COMPILE)gcc $(CFLAGS) -c -o $@-pre-validated $< |
diff --git a/scripts/sysfw_boardcfg_blob_creator.py b/scripts/sysfw_boardcfg_blob_creator.py new file mode 100755 index 000000000..1f2fdc094 --- /dev/null +++ b/scripts/sysfw_boardcfg_blob_creator.py | |||
@@ -0,0 +1,105 @@ | |||
1 | #!/usr/bin/env python3 | ||
2 | import argparse | ||
3 | import logging | ||
4 | import os | ||
5 | import struct | ||
6 | import tempfile | ||
7 | from shutil import copyfileobj | ||
8 | from shutil import rmtree | ||
9 | |||
10 | BOARDCFG = 0xB | ||
11 | BOARDCFG_SEC = 0xD | ||
12 | BOARDCFG_PM = 0xE | ||
13 | BOARDCFG_RM = 0xC | ||
14 | BOARDCFG_NUM_ELEMS = 4 | ||
15 | |||
16 | class BoardCfgDesc(): | ||
17 | """Get board config descriptor for a given file """ | ||
18 | |||
19 | fmt = '<HHHBB' | ||
20 | index = 0 | ||
21 | offset = 0 | ||
22 | |||
23 | def __init__(self, outfile, devgrp, | ||
24 | sw_rev = 0, | ||
25 | num_elems = BOARDCFG_NUM_ELEMS): | ||
26 | self.devgrp = devgrp | ||
27 | try: | ||
28 | self.fh = open(outfile, 'wb') | ||
29 | bytes = self.fh.write(struct.pack('<BB', num_elems, sw_rev)) | ||
30 | self.offset += bytes | ||
31 | self.offset += 4 * struct.calcsize(self.fmt) | ||
32 | self.tmpdir = tempfile.mkdtemp() | ||
33 | descfile = os.path.join(self.tmpdir, "desc") | ||
34 | bcfgfile = os.path.join(self.tmpdir, "bcfg") | ||
35 | self.desc_fh = open(descfile, "wb+") | ||
36 | self.bcfg_fh = open(bcfgfile, "wb+") | ||
37 | except: | ||
38 | raise Exception("File Error") | ||
39 | |||
40 | def add_boardcfg(self, bcfgtype, bcfgfile): | ||
41 | with open(bcfgfile, 'rb') as bfh: | ||
42 | bcfg = bfh.read() | ||
43 | size = len(bcfg) | ||
44 | desc = struct.pack(self.fmt, bcfgtype, self.offset, size, self.devgrp, 0) | ||
45 | self.desc_fh.write(desc) | ||
46 | self.bcfg_fh.write(bcfg) | ||
47 | logging.debug("Packing boardcfg data of size [%d bytes] from file %s", size, bcfgfile) | ||
48 | self.offset += size | ||
49 | self.index += 1 | ||
50 | |||
51 | def finalize(self): | ||
52 | try: | ||
53 | self.desc_fh.seek(0) | ||
54 | self.bcfg_fh.seek(0) | ||
55 | copyfileobj(self.desc_fh, self.fh) | ||
56 | copyfileobj(self.bcfg_fh, self.fh) | ||
57 | except: | ||
58 | logging.error("**** Error in finalizing boardcfg file ****") | ||
59 | raise Exception("File Error") | ||
60 | finally: | ||
61 | self.fh.close() | ||
62 | self.desc_fh.close() | ||
63 | self.bcfg_fh.close() | ||
64 | rmtree(self.tmpdir) | ||
65 | |||
66 | def create_sysfw_blob(args): | ||
67 | """Create a SYSFW data blob to be used as a component in combined image """ | ||
68 | |||
69 | if args.boardcfg is None or args.boardcfg_sec is None or args.boardcfg_pm is None or args.boardcfg_rm is None: | ||
70 | logging.error("**** All 4 boardcfg binaries need to be provided ****") | ||
71 | raise Exception("Insufficient arguments") | ||
72 | |||
73 | logging.info("#### Creating SYSFW data blob - %s ####", args.output_file.name) | ||
74 | logging.info("#### SW Rev = %d", args.sw_rev) | ||
75 | logging.info("#### Device Group = %d", args.devgrp) | ||
76 | logging.info("#### Board config binary - %s", args.boardcfg.name) | ||
77 | logging.info("#### Board config security binary - %s", args.boardcfg_sec.name) | ||
78 | logging.info("#### Board config PM binary - %s", args.boardcfg_pm.name) | ||
79 | logging.info("#### Board config RM binary - %s", args.boardcfg_rm.name) | ||
80 | |||
81 | blob = BoardCfgDesc(args.output_file.name, args.devgrp, args.sw_rev) | ||
82 | blob.add_boardcfg(BOARDCFG, args.boardcfg.name) | ||
83 | blob.add_boardcfg(BOARDCFG_SEC, args.boardcfg_sec.name) | ||
84 | blob.add_boardcfg(BOARDCFG_PM, args.boardcfg_pm.name) | ||
85 | blob.add_boardcfg(BOARDCFG_RM, args.boardcfg_rm.name) | ||
86 | |||
87 | blob.finalize() | ||
88 | |||
89 | # options -> device, sw_rev, boardcfg, security boardcfg, pm boardcfg, rm boardcfg, output file | ||
90 | |||
91 | # parser for mandatory arguments | ||
92 | pp = argparse.ArgumentParser(add_help=False) | ||
93 | pp.add_argument('-l', '--log-level', type=str, default="INFO", choices=["INFO", "DEBUG"]) | ||
94 | pp.add_argument('--sw-rev', type=int, default=0) | ||
95 | pp.add_argument('-o', '--output-file', type=argparse.FileType('wb'), default="./sysfw-data.bin") | ||
96 | pp.add_argument('-d', '--devgrp', type=int, default=0) | ||
97 | pp.add_argument('-b', '--boardcfg', type=argparse.FileType('rb')) | ||
98 | pp.add_argument('-s', '--boardcfg-sec', type=argparse.FileType('rb')) | ||
99 | pp.add_argument('-p', '--boardcfg-pm', type=argparse.FileType('rb')) | ||
100 | pp.add_argument('-r', '--boardcfg-rm', type=argparse.FileType('rb')) | ||
101 | |||
102 | args = pp.parse_args() | ||
103 | logging.getLogger().setLevel(args.log_level) | ||
104 | logging.debug(args) | ||
105 | create_sysfw_blob(args) | ||