Add support for packing multiple vendor ramdisks in vendor_boot
Add support for partitioning the vendor_boot kernel modules into
multiple vendor ramdisk fragments. The partition granularity is kernel
module directory. This mechanism builds upon the existing
BOARD_KERNEL_MODULE_DIRS mechanism. For example, say we have three
kernel module directories:
BOARD_KERNEL_MODULE_DIRS := foo bar baz
We can then define a vendor ramdisk fragment:
BOARD_MKBOOTIMG_ARGS += --header_version 4
BOARD_VENDOR_RAMDISK_FRAGMENTS := dlkm_foobar
And let said ramdisk to contain the DLKM directories "foo" and "bar":
BOARD_VENDOR_RAMDISK_FRAGMENT.dlkm_foobar.KERNEL_MODULE_DIRS := foo bar
BOARD_VENDOR_RAMDISK_FRAGMENT.dlkm_foobar.MKBOOTIMG_ARGS := <mkbootimg args>
The built vendor_boot image would contain two ramdisks.
The first one being the "default" ramdisk, which contains DLKM directory
"baz" and the rest of the files that get's installed to
$(TARGET_VENDOR_RAMDISK_OUT).
The second one is the "dlkm_foobar" ramdisk, which contains the two DLKM
directories.
Design doc: go/vendor-boot-v4
Bug: 162864255
Test: Modify BoardConfig.mk to have a product build v4 vendor_boot
Test: Use unpack_bootimg to verify the vendor_boot image
Test: Teach a bootloader how to handle v4 boot image, flash boot &
vendor_boot and boot device
Change-Id: Ibb1bbd7ebe36430c55ec6c4818c1d3888a319089
diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py
index bae0b20..0172add 100644
--- a/tools/releasetools/common.py
+++ b/tools/releasetools/common.py
@@ -1660,6 +1660,24 @@
cmd.extend(["--vendor_ramdisk", ramdisk_img.name])
cmd.extend(["--vendor_boot", img.name])
+ ramdisk_fragment_imgs = []
+ fn = os.path.join(sourcedir, "vendor_ramdisk_fragments")
+ if os.access(fn, os.F_OK):
+ ramdisk_fragments = shlex.split(open(fn).read().rstrip("\n"))
+ for ramdisk_fragment in ramdisk_fragments:
+ fn = os.path.join(sourcedir, "RAMDISK_FRAGMENTS", ramdisk_fragment, "mkbootimg_args")
+ cmd.extend(shlex.split(open(fn).read().rstrip("\n")))
+ fn = os.path.join(sourcedir, "RAMDISK_FRAGMENTS", ramdisk_fragment, "prebuilt_ramdisk")
+ # Use prebuilt image if found, else create ramdisk from supplied files.
+ if os.access(fn, os.F_OK):
+ ramdisk_fragment_pathname = fn
+ else:
+ ramdisk_fragment_root = os.path.join(sourcedir, "RAMDISK_FRAGMENTS", ramdisk_fragment)
+ ramdisk_fragment_img = _MakeRamdisk(ramdisk_fragment_root, lz4_ramdisks=use_lz4)
+ ramdisk_fragment_imgs.append(ramdisk_fragment_img)
+ ramdisk_fragment_pathname = ramdisk_fragment_img.name
+ cmd.extend(["--vendor_ramdisk_fragment", ramdisk_fragment_pathname])
+
RunAndCheckOutput(cmd)
# AVB: if enabled, calculate and add hash.
@@ -1677,6 +1695,8 @@
img.seek(os.SEEK_SET, 0)
data = img.read()
+ for f in ramdisk_fragment_imgs:
+ f.close()
ramdisk_img.close()
img.close()