Skip to content

Commit

Permalink
lib: add dtbutils library module
Browse files Browse the repository at this point in the history
with a function for concatenating DTBOs onto DTBs.

Signed-off-by: Matt Madison <[email protected]>
  • Loading branch information
madisongh committed Apr 9, 2023
1 parent b28462f commit 802f7d9
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/oe4t/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

BBIMPORTS = ["dtbutils"]
49 changes: 49 additions & 0 deletions lib/oe4t/dtbutils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
def concat_dtb_overlays(dtbfile, overlays, outfile, d):
"""
Produce an output DTB file that has zero or more
overlay DTBs concatenated to it, for processing by
NVIDIA's OverlayManager UEFI driver.
Source DTB and overlay files can reside either under
${EXTERNAL_KERNEL_DEVICETREE} or in ${DEPLOY_DIR_IMAGE}.
dtbfile: Main DTB file
overlays: space-separated list of zero or more DTBO files
outfile: name of output file
d: recipe context
"""
import os
import bb.utils

def find_file_under(fname, rootdir):
for dirname, _, f in os.walk(rootdir):
if fname in f:
return os.path.join(dirname, fname)
return None

def locate_dtb_files(dtbnames):
result = []
extern_root = d.getVar('EXTERNAL_KERNEL_DEVICETREE')
imgdeploydir = d.getVar('DEPLOY_DIR_IMAGE')
for dtb in dtbnames:
if os.path.isabs(dtb):
result.append(dtb)
continue
if extern_root:
dtbpath = find_file_under(dtb, extern_root)
if dtbpath:
result.append(dtbpath)
continue
result.append(os.path.join(imgdeploydir, dtb))
return result

infiles = locate_dtb_files([dtbfile] + overlays.split())
bb.note("Creating concatenated device tree: ", outfile)
with open(outfile, "wb") as outf:
for infile in infiles:
# the overlay manager expects all DTBOs to start
# on a 4K page boundary
outf.write(bytearray(int((outf.tell() + 4095) / 4096) * 4096))
bb.note(" Adding: ", infile)
with open(infile, "rb") as inf:
outf.write(inf.read())

0 comments on commit 802f7d9

Please sign in to comment.