add "flasher flash_vbmeta" command (!1885)

Flashes device vbmeta partition (can be overriden with
"flash_fastboot_partition_vbmeta" setting in deviceinfo)
with custom vbmeta.img which has verity flag disabled,
so device can boot postmarketOS with no problems.
This commit is contained in:
Alexey Min 2020-03-04 02:51:25 +03:00 committed by Oliver Smith
parent 45f5ace1c2
commit e6da56d9b0
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
5 changed files with 42 additions and 2 deletions

View File

@ -273,6 +273,7 @@ deviceinfo_attributes = [
"flash_heimdall_partition_system",
"flash_fastboot_partition_kernel",
"flash_fastboot_partition_system",
"flash_fastboot_partition_vbmeta",
"generate_legacy_uboot_initfs",
"kernel_cmdline",
"generate_bootimg",
@ -351,13 +352,21 @@ uuu specific: $UUU_SCRIPT
"""
flashers = {
"fastboot": {
"depends": ["android-tools"],
"depends": ["android-tools", "avbtool"],
"actions": {
"list_devices": [["fastboot", "devices", "-l"]],
"flash_rootfs": [["fastboot", "flash", "$PARTITION_SYSTEM",
"$IMAGE"]],
"flash_kernel": [["fastboot", "flash", "$PARTITION_KERNEL",
"$BOOT/boot.img-$FLAVOR"]],
"flash_vbmeta": [
# Generate vbmeta image with "disable verification" flag
["avbtool", "make_vbmeta_image", "--flags", "2",
"--padding_size", "$FLASH_PAGESIZE",
"--output", "/vbmeta.img"],
["fastboot", "flash", "$PARTITION_VBMETA", "/vbmeta.img"],
["rm", "-f", "/vbmeta.img"]
],
"boot": [["fastboot", "--cmdline", "$KERNEL_CMDLINE",
"boot", "$BOOT/boot.img-$FLAVOR"]],
},

View File

@ -70,6 +70,11 @@ def rootfs(args):
pmb.flasher.run(args, "flash_rootfs")
def flash_vbmeta(args):
logging.info("(native) flash vbmeta.img with verity disabled flag")
pmb.flasher.run(args, "flash_vbmeta")
def list_devices(args):
pmb.flasher.run(args, "list_devices")
@ -115,6 +120,8 @@ def frontend(args):
kernel(args)
if action == "flash_rootfs":
rootfs(args)
if action == "flash_vbmeta":
flash_vbmeta(args)
if action == "list_flavors":
list_flavors(args)
if action == "list_devices":

View File

@ -32,6 +32,15 @@ def run(args, action, flavor=None):
# Variable setup
vars = pmb.flasher.variables(args, flavor, method)
# vbmeta flasher requires vbmeta partition to be explicitly specified
if action == "flash_vbmeta" and not vars["$PARTITION_VBMETA"]:
raise RuntimeError("Your device does not have 'vbmeta' partition"
" specified; set"
" 'deviceinfo_flash_fastboot_partition_vbmeta'"
" in deviceinfo file. See also:"
" <https://wiki.postmarketos.org/wiki/"
"Deviceinfo_reference>")
# Run the commands of each action
for command in cfg["actions"][action]:
# Variable replacement

View File

@ -7,17 +7,21 @@ def variables(args, flavor, method):
if "cmdline" in args and args.cmdline:
_cmdline = args.cmdline
flash_pagesize = args.deviceinfo['flash_pagesize']
if method.startswith("fastboot"):
_partition_kernel = args.deviceinfo["flash_fastboot_partition_kernel"] or "boot"
_partition_system = args.deviceinfo["flash_fastboot_partition_system"] or "system"
_partition_vbmeta = args.deviceinfo["flash_fastboot_partition_vbmeta"] or None
else:
_partition_kernel = args.deviceinfo["flash_heimdall_partition_kernel"] or "KERNEL"
_partition_system = args.deviceinfo["flash_heimdall_partition_system"] or "SYSTEM"
if "partition" in args and args.partition:
# Only one of two operations is done at same time so it doesn't matter sharing the arg
# Only one of operations is done at same time so it doesn't matter sharing the arg
_partition_kernel = args.partition
_partition_system = args.partition
_partition_vbmeta = args.partition
vars = {
"$BOOT": "/mnt/rootfs_" + args.device + "/boot",
@ -29,6 +33,8 @@ def variables(args, flavor, method):
"$PARTITION_KERNEL": _partition_kernel,
"$PARTITION_INITFS": args.deviceinfo["flash_heimdall_partition_initfs"] or "RECOVERY",
"$PARTITION_SYSTEM": _partition_system,
"$PARTITION_VBMETA": _partition_vbmeta,
"$FLASH_PAGESIZE": flash_pagesize,
"$RECOVERY_ZIP": "/mnt/buildroot_" + args.deviceinfo["arch"] +
"/var/lib/postmarketos-android-recovery-installer"
"/pmos-" + args.device + ".zip",

View File

@ -70,6 +70,15 @@ def arguments_flasher(subparser):
" 'userdata' on Android may have more"
" space)")
# Flash vbmeta
flash_vbmeta = sub.add_parser("flash_vbmeta",
help="generate and flash AVB 2.0 image with disable"
" verification flag set to a partition on the"
" device (typically called vbmeta)")
flash_vbmeta.add_argument("--partition", default=None,
help="partition to flash the vbmeta to (defaults"
" to deviceinfo_flash_*_partition_vbmeta")
# Actions without extra arguments
sub.add_parser("sideload", help="sideload recovery zip")
sub.add_parser("list_flavors", help="list installed kernel flavors" +