Skip to content

Commit 661f9b4

Browse files
committed
Update the code for flashing additional partitions and improve the layout a bit
1 parent 5d34157 commit 661f9b4

5 files changed

Lines changed: 121 additions & 113 deletions

File tree

doc/how_to_contribute_your_own_installation_configurations.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Every config file should have `metadata` with the following fields:
1616
- `device_code`: str; The official device code.
1717
- `supported_device_codes`: List[str]; A list of supported device codes for the config. The config will be loaded based on this field.
1818
- `twrp-link`: [OPTIONAL] str; name of the corresponding twrp page.
19+
- `additional_steps` : [OPTIONAL] List[str]; A list of additional steps. Can be `dtbo`, `vbmeta`, `vendor_boot` or `super_empty`.
1920

2021
In addition to these metadata, every config can have optional `requirements`. If these are set, the user is asked to check if they are meet.
2122
- `android`: [OPTIONAL] int|str; Android version to install prior to installing a custom ROM.
@@ -32,7 +33,7 @@ Every step in the config file corresponds to one view in the application. These
3233
- `img`: [OPTIONAL] Display an image on the left pane of the step view. Images are loaded from `openandroidinstaller/assets/imgs/`.
3334
- `content`: str; The content text displayed alongside the action of the step. Used to inform the user about what's going on. For consistency and better readability the text should be moved into the next line using `>`.
3435
- `link`: [OPTIONAL] Link to use for the link button if type is `link_button_with_confirm`.
35-
- `command`: [ONLY for call_button* steps] str; The command to run. One of `adb_reboot`, `adb_reboot_bootloader`, `adb_reboot_download`, `adb_sideload`, `adb_twrp_wipe_and_install`, `adb_twrp_copy_partitions`, `fastboot_boot_recovery`, `fastboot_unlock_with_code`, `fastboot_unlock`, `fastboot_oem_unlock`, `fastboot_get_unlock_data`, `fastboot_reboot`, `heimdall_flash_recovery`.
36+
- `command`: [ONLY for call_button* steps] str; The command to run. One of `adb_reboot`, `adb_reboot_bootloader`, `adb_reboot_download`, `adb_sideload`, `adb_twrp_wipe_and_install`, `adb_twrp_copy_partitions`, `fastboot_boot_recovery`, `fastboot_flash_additional_partitions`, `fastboot_unlock_with_code`, `fastboot_unlock`, `fastboot_unlock_critical`, `fastboot_oem_unlock`, `fastboot_get_unlock_data`, `fastboot_reboot`, `heimdall_flash_recovery`.
3637
- `allow_skip`: [OPTIONAL] boolean; If a skip button should be displayed to allow skipping this step. Can be useful when the bootloader is already unlocked.
3738

3839
**Please try to retain this order of these fields in your config to ensure consistency.**

openandroidinstaller/tooling.py

Lines changed: 50 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ def fastboot_boot_recovery(
416416

417417

418418
def fastboot_flash_boot(bin_path: Path, recovery: str) -> TerminalResponse:
419-
"""Temporarily, flash custom recovery with fastboot to boot partition."""
419+
"""Flash custom recovery with fastboot to boot partition."""
420420
logger.info("Flash custom recovery with fastboot.")
421421
for line in run_command(
422422
"fastboot flash boot", target=f"{recovery}", bin_path=bin_path
@@ -440,6 +440,54 @@ def fastboot_flash_boot(bin_path: Path, recovery: str) -> TerminalResponse:
440440
yield True
441441

442442

443+
@add_logging("Flash additional partitions with fastboot")
444+
def fastboot_flash_additional_partitions(
445+
bin_path: Path, dtbo: Optional[str], vbmeta: Optional[str], super_empty: Optional[str], is_ab: bool = True
446+
) -> TerminalResponse:
447+
"""Flash additional partitions (dtbo, vbmeta, super_empty) with fastboot."""
448+
logger.info("Flash additional partitions with fastboot.")
449+
if dtbo:
450+
logger.info("dtbo selected. Flashing dtbo partition.")
451+
for line in run_command(
452+
"fastboot flash dtbo ", target=f"{dtbo}", bin_path=bin_path
453+
):
454+
yield line
455+
if not is_ab:
456+
if (type(line) == bool) and not line:
457+
logger.error("Flashing dtbo failed.")
458+
yield False
459+
else:
460+
yield True
461+
else:
462+
yield True
463+
464+
if vbmeta:
465+
logger.info("vbmeta selected. Flashing vbmeta partition.")
466+
for line in run_command(
467+
"fastboot flash vbmeta ", target=f"{vbmeta}", bin_path=bin_path
468+
):
469+
yield line
470+
if not is_ab:
471+
if (type(line) == bool) and not line:
472+
logger.error("Flashing vbmeta failed.")
473+
yield False
474+
else:
475+
yield True
476+
477+
if super_empty:
478+
logger.info("super_empty selected. Wiping super partition.")
479+
for line in run_command(
480+
"fastboot wipe-super ", target=f"{super_empty}", bin_path=bin_path
481+
):
482+
yield line
483+
if not is_ab:
484+
if (type(line) == bool) and not line:
485+
logger.error("Wiping super failed.")
486+
yield False
487+
else:
488+
yield True
489+
490+
443491
def heimdall_wait_for_download_available(bin_path: Path) -> bool:
444492
"""Use heimdall detect to wait for download mode to become available on the device."""
445493
logger.info("Wait for download mode to become available.")
@@ -496,55 +544,4 @@ def search_device(platform: str, bin_path: Path) -> Optional[str]:
496544
return device_code
497545
except CalledProcessError:
498546
logger.error("Failed to detect a device.")
499-
return None
500-
501-
502-
@add_logging("Flash additional partitions with fastboot")
503-
def fastboot_flash_additional_partitions(
504-
bin_path: Path, dtbo: str, vbmeta: str, super_empty: str, is_ab: bool = True
505-
) -> TerminalResponse:
506-
"""Flash additional partitions (dtbo, vbmeta, super_empty) with fastboot."""
507-
if dtbo:
508-
for line in run_command(
509-
"fastboot flash dtbo ", target=f"{dtbo}", bin_path=bin_path
510-
):
511-
yield line
512-
if not is_ab:
513-
if (type(line) == bool) and not line:
514-
logger.error("Flashing dtbo failed.")
515-
yield False
516-
else:
517-
yield True
518-
else:
519-
logger.info("No dtbo selected. Skipping")
520-
yield True
521-
522-
if vbmeta:
523-
for line in run_command(
524-
"fastboot flash vbmeta ", target=f"{vbmeta}", bin_path=bin_path
525-
):
526-
yield line
527-
if not is_ab:
528-
if (type(line) == bool) and not line:
529-
logger.error("Flashing vbmeta failed.")
530-
yield False
531-
else:
532-
yield True
533-
else:
534-
logger.info("No vbmeta selected. Skipping")
535-
yield True
536-
537-
if super_empty:
538-
for line in run_command(
539-
"fastboot wipe-super ", target=f"{super_empty}", bin_path=bin_path
540-
):
541-
yield line
542-
if not is_ab:
543-
if (type(line) == bool) and not line:
544-
logger.error("Wiping super failed.")
545-
yield False
546-
else:
547-
yield True
548-
else:
549-
logger.info("No super_empty selected. Skipping")
550-
yield True
547+
return None

openandroidinstaller/utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ def image_works_with_device(supported_device_codes: List[str], image_path: str)
6161

6262

6363
def image_sdk_level(image_path: str) -> int:
64-
"""
65-
Determine Android version of the selected image.
66-
Android 13 : 33
64+
"""Determine Android version of the selected image.
65+
66+
Example:
67+
Android 13: 33
6768
"""
6869
with zipfile.ZipFile(image_path) as image_zip:
6970
with image_zip.open(

0 commit comments

Comments
 (0)