aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnand Balagopalakrishnan2020-08-11 16:33:06 -0500
committerDave Gerlach2020-08-14 12:11:07 -0500
commita8d5f684d000788a8e4e700c20bf7455110faf36 (patch)
tree92c074f85a9a19edd260071c6c2f24e04bf58c2f
parentbbc59bcc2d004ffa9ea7ff53532f85caf888ee99 (diff)
downloadk3-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--Makefile3
-rwxr-xr-xscripts/sysfw_boardcfg_blob_creator.py105
2 files changed, 108 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 9ca6646ec..7ef72b49c 100644
--- a/Makefile
+++ b/Makefile
@@ -109,6 +109,7 @@ SOC_BIN_NAMES += $(SOURCES:%.c=%.bin)
109 109
110ITB ?= $(binroot)/sysfw-$(SOC)-$(CONFIG).itb 110ITB ?= $(binroot)/sysfw-$(SOC)-$(CONFIG).itb
111ITS ?= $(soc_objroot)/$(basename $(notdir $(ITB))).its 111ITS ?= $(soc_objroot)/$(basename $(notdir $(ITB))).its
112COMBINED_BRDCFG ?= $(soc_objroot)/combined-cfg.bin
112 113
113vpath %.itb $(soc_objroot) 114vpath %.itb $(soc_objroot)
114vpath %.bin $(soc_objroot) 115vpath %.bin $(soc_objroot)
@@ -172,6 +173,8 @@ sysfw.itb: $(ITB)
172 173
173soc_objs: $(SOC_OBJS) 174soc_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
2import argparse
3import logging
4import os
5import struct
6import tempfile
7from shutil import copyfileobj
8from shutil import rmtree
9
10BOARDCFG = 0xB
11BOARDCFG_SEC = 0xD
12BOARDCFG_PM = 0xE
13BOARDCFG_RM = 0xC
14BOARDCFG_NUM_ELEMS = 4
15
16class 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
66def 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
92pp = argparse.ArgumentParser(add_help=False)
93pp.add_argument('-l', '--log-level', type=str, default="INFO", choices=["INFO", "DEBUG"])
94pp.add_argument('--sw-rev', type=int, default=0)
95pp.add_argument('-o', '--output-file', type=argparse.FileType('wb'), default="./sysfw-data.bin")
96pp.add_argument('-d', '--devgrp', type=int, default=0)
97pp.add_argument('-b', '--boardcfg', type=argparse.FileType('rb'))
98pp.add_argument('-s', '--boardcfg-sec', type=argparse.FileType('rb'))
99pp.add_argument('-p', '--boardcfg-pm', type=argparse.FileType('rb'))
100pp.add_argument('-r', '--boardcfg-rm', type=argparse.FileType('rb'))
101
102args = pp.parse_args()
103logging.getLogger().setLevel(args.log_level)
104logging.debug(args)
105create_sysfw_blob(args)