Skip to content

Commit 873c283

Browse files
sjg20nathanchance
authored andcommitted
scripts/make_fit: Move dtb processing into a function
Since build_fit() is getting quite long, move the dtb processing into a separate function. Change the double quotes in the write() call to single, to match the rest of the script. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Nicolas Schier <nsc@kernel.org> Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Reviewed-by: Chen-Yu Tsai <wenst@chromium.org> Link: https://patch.msgid.link/20260106162738.2605574-4-sjg@chromium.org Signed-off-by: Nathan Chancellor <nathan@kernel.org>
1 parent 26428e7 commit 873c283

1 file changed

Lines changed: 44 additions & 23 deletions

File tree

scripts/make_fit.py

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,47 @@ def process_dtb(fname, args):
277277

278278
return (model, compat, files)
279279

280+
281+
def _process_dtbs(args, fsw, entries, fdts):
282+
"""Process all DTB files and add them to the FIT
283+
284+
Args:
285+
args: Program arguments
286+
fsw: FIT writer object
287+
entries: List to append entries to
288+
fdts: Dictionary of processed DTBs
289+
290+
Returns:
291+
tuple:
292+
Number of files processed
293+
Total size of files processed
294+
"""
295+
seq = 0
296+
size = 0
297+
for fname in args.dtbs:
298+
# Ignore non-DTB (*.dtb) files
299+
if os.path.splitext(fname)[1] != '.dtb':
300+
continue
301+
302+
try:
303+
(model, compat, files) = process_dtb(fname, args)
304+
except Exception as e:
305+
sys.stderr.write(f'Error processing {fname}:\n')
306+
raise e
307+
308+
for fn in files:
309+
if fn not in fdts:
310+
seq += 1
311+
size += os.path.getsize(fn)
312+
output_dtb(fsw, seq, fn, args.arch, args.compress)
313+
fdts[fn] = seq
314+
315+
files_seq = [fdts[fn] for fn in files]
316+
entries.append([model, compat, files_seq])
317+
318+
return seq, size
319+
320+
280321
def build_fit(args):
281322
"""Build the FIT from the provided files and arguments
282323
@@ -289,7 +330,6 @@ def build_fit(args):
289330
int: Number of configurations generated
290331
size: Total uncompressed size of data
291332
"""
292-
seq = 0
293333
size = 0
294334
fsw = libfdt.FdtSw()
295335
setup_fit(fsw, args.name)
@@ -310,34 +350,15 @@ def build_fit(args):
310350
size += len(data)
311351
write_ramdisk(fsw, data, args)
312352

313-
for fname in args.dtbs:
314-
# Ignore non-DTB (*.dtb) files
315-
if os.path.splitext(fname)[1] != '.dtb':
316-
continue
317-
318-
try:
319-
(model, compat, files) = process_dtb(fname, args)
320-
except Exception as e:
321-
sys.stderr.write(f"Error processing {fname}:\n")
322-
raise e
323-
324-
for fn in files:
325-
if fn not in fdts:
326-
seq += 1
327-
size += os.path.getsize(fn)
328-
output_dtb(fsw, seq, fn, args.arch, args.compress)
329-
fdts[fn] = seq
330-
331-
files_seq = [fdts[fn] for fn in files]
332-
333-
entries.append([model, compat, files_seq])
353+
count, fdt_size = _process_dtbs(args, fsw, entries, fdts)
354+
size += fdt_size
334355

335356
finish_fit(fsw, entries, bool(args.ramdisk))
336357

337358
# Include the kernel itself in the returned file count
338359
fdt = fsw.as_fdt()
339360
fdt.pack()
340-
return fdt.as_bytearray(), seq + 1 + bool(args.ramdisk), size
361+
return fdt.as_bytearray(), count + 1 + bool(args.ramdisk), size
341362

342363

343364
def run_make_fit():

0 commit comments

Comments
 (0)