Android OTA related tools (3) A/B system bootctl tool


The previous two articles:

Introduce snapshotctl and dmctl, the most commonly used tools for debugging dynamic partition and virtual A/B partition, respectively. This article introduces bootctl (boot control), a tool specially used to set the BootControl HAL interface.

The most commonly used place for this tool is to check the slot status of the A/B system and switch systems under the command line of the Android system.

I first introduced the basic usage in "Android A/B System OTA Analysis (3) Communication between the main system and bootloader" , and this article introduces this tool in detail.

This article is original by Rocky Watching the World (guyongqiangx), please indicate the source for reprinting.
Article link: https://guyongqiangx.blog.csdn.net/article/details/129310109

This article is based on the Android version: android-11.0.0_r21, but subsequent versions are similar

Online code: http://aospxref.com/android-11.0.0_r21/

1. Compilation of bootctl

By default, bootctl will not be compiled into the system, you need to add bootctl to PRODUCT_PACKAGESthe variable .

If you don't know how to add it, execute the grep command in the device directory to see how google's reference device is added.

For example, on crosshatch devices on Android 11, bootctl is included PRODUCT_PACKAGES_DEBUGas follows:

http://aospxref.com/android-11.0.0_r21/raw/device/google/crosshatch/device.mk

# The following modules are included in debuggable builds only.
PRODUCT_PACKAGES_DEBUG += \
    bootctl \
    update_engine_client

Since it is here PRODUCT_PACKAGES_DEBUG, bootctl is only included in userdebug builds.

If you want to include bootctl in other versions, it is recommended to add bootctl PRODUCT_PACKAGESto .

2. Help information of bootctl

The commands of bootctl are relatively intuitive, and you can basically see the name and meaning:

console:/ # bootctl -h                                                                                                                                                                                                                                          
bootctl - command-line wrapper for the boot HAL.

Usage:
  bootctl COMMAND

Commands:
  hal-info                       - Show info about boot_control HAL used.
  get-number-slots               - Prints number of slots.
  get-current-slot               - Prints currently running SLOT.
  mark-boot-successful           - Mark current slot as GOOD.
  set-active-boot-slot SLOT      - On next boot, load and execute SLOT.
  set-slot-as-unbootable SLOT    - Mark SLOT as invalid.
  is-slot-bootable SLOT          - Returns 0 only if SLOT is bootable.
  is-slot-marked-successful SLOT - Returns 0 only if SLOT is marked GOOD.
  get-suffix SLOT                - Prints suffix for SLOT.
  set-snapshot-merge-status STAT - Sets whether a snapshot-merge of any dynamic
                                   partition is in progress. Valid STAT values
                                   are: none, unknown, snapshotted, merging,
                                   or cancelled.
  get-snapshot-merge-status      - Prints the current snapshot-merge status.

SLOT parameter is the zero-based slot-number.

Two new commands have been added on Android 11:

  • set-snapshot-merge-status STAT
  • get-snapshot-merge-status

These two commands are specially used to set and view the snapshot status of the virtual A/B partition.

For specific information about the BootControl HAL interface, please refer to the following two articles:

The previous article analyzed the code implementation of BootControl, and the latter article analyzed the changes of the system on the BootControl interface in order to support the virtual A/B partition.

3. Usage of bootctl

Below are some typical uses of the bootctl command on a device.

1. thing-info

Hal-info command to view the HAL information of the current IBootControl interface:

  • Execute the hal-info command on the Android 7.1 system
console:/ # bootctl hal-info
HAL name:            boot control hal for bcm platform
HAL author:          Broadcom
HAL module version:  0.1
  • Execute the hal-info command on Android 11
console:/ # bootctl hal-info
HAL Version: [email protected]::IBootControl

2. get-number-slots

get-number-slots is used to print the number of slots in the current system, and the A/B system generally has two.

console:/ # bootctl get-number-slots
2

3. get-current-slot

get-current-slot is used to print the current system running slot (slot):

console:/ # bootctl get-current-slot
1

The A/B system generally consists of two slots, 0 and 1, and the system here runs on slot 1.

4. mark-boot-successful

mark-boot-successful Mark the currently running system as successfully booted

console:/ # bootctl mark-boot-successful 

5. set-active-boot-slot

set-active-boot-slot Set the slot for the next boot of the system,

console:/ # bootctl get-current-slot                                           
1

This shows that the current system is running on slot 1 (B slot), run:

console:/ # bootctl set-active-boot-slot 0

Another slot 0 (A slot) will be set for the next boot.

Equivalent to executing commands through fastboot:

fastboot set_active a

6. set-slot-as-unbootable

set-slot-as-unbootable marks the corresponding slot as unbootable.

The following command marks slot 0 (A slot) as invalid and unbootable:

console:/ # bootctl set-slot-as-unbootable 0

7. is-slot-bootable

is-slot-bootable command to check whether the specified slot can be started

When the specified slot can be started, it returns 0, which is displayed on the console as the command exited normally.

When the specified slot cannot be started, it will be displayed as an abnormal exit of the command on the console.

console:/ # bootctl is-slot-bootable 1
console:/ # bootctl is-slot-bootable 0                                         
70|console:/ # 

In the above command, slot 1 can start normally (command ends normally), but slot 0 cannot start (command exits abnormally)

8. is-slot-marked-successful

is-slot-marked-successful returns whether the corresponding slot is marked as successfully started

Returns 0 when the specified slot is marked as successfully started, which is displayed on the console as the command exited normally.

When the specified slot is not marked as successfully started, it will be displayed on the console as the command exiting abnormally.

console:/ # bootctl is-slot-marked-successful 1
console:/ # 
console:/ # bootctl is-slot-marked-successful 0
70|console:/ # 

The execution results here show that slot 1 has been marked as successfully started, and slot 0 has not been marked as successfully started.

9. get-suffix

get-suffix returns the suffix of the specified slot

console:/ # bootctl get-suffix 0
_a
console:/ # bootctl get-suffix 1
_b

Here it shows that the suffixes of the two slots of the system are _aand _b.

10. set-snapshot-merge-status

set-snapshot-merge-status Set the current merge status of the system, applicable after Android 11.

Valid values ​​for the operation are: none, unknown, snapshotted, merging, and canceled.

console:/ # bootctl get-snapshot-merge-status 
none
console:/ # bootctl set-snapshot-merge-status unknown
console:/ # bootctl get-snapshot-merge-status                                  
unknown
console:/ # bootctl set-snapshot-merge-status cancelled                        
console:/ # bootctl get-snapshot-merge-status 
cancelled
console:/ # bootctl set-snapshot-merge-status active                           
bootctl - command-line wrapper for the boot HAL.

Usage:
  bootctl COMMAND

Commands:
  hal-info                       - Show info about boot_control HAL used.
  get-number-slots               - Prints number of slots.
  get-current-slot               - Prints currently running SLOT.
  mark-boot-successful           - Mark current slot as GOOD.
  set-active-boot-slot SLOT      - On next boot, load and execute SLOT.
  set-slot-as-unbootable SLOT    - Mark SLOT as invalid.
  is-slot-bootable SLOT          - Returns 0 only if SLOT is bootable.
  is-slot-marked-successful SLOT - Returns 0 only if SLOT is marked GOOD.
  get-suffix SLOT                - Prints suffix for SLOT.
  set-snapshot-merge-status STAT - Sets whether a snapshot-merge of any dynamic
                                   partition is in progress. Valid STAT values
                                   are: none, unknown, snapshotted, merging,
                                   or cancelled.
  get-snapshot-merge-status      - Prints the current snapshot-merge status.

SLOT parameter is the zero-based slot-number.
64|console:/ # 

In the last operation above, an attempt to set the merge status to an invalid value of active failed.

11. get-snapshot-merge-status

get-snapshot-merge-status Get the merge status of the current system, applicable after Android 11.

console:/ # bootctl get-snapshot-merge-status 
none

4. Thinking questions

The HAL interface defined by IBootContol is implemented and used in several places.

  1. The Android main system implements the IBootControl interface, and provides services to the upper layer through the BootControl Service, including the Update Engine and the bootctl tool here.

  2. The corresponding structure of IBootControl is implemented in the bootloader, which is used to operate the data stored in the external device (flash, eMMC) by IBootControl in the bootloader (usually the misc partition)

    Some slot-related operations of the fastboot tool also work through the IBootControl interface implemented by the bootloader.

Now comes the question, do you know the fastboot command corresponding to the bootctl tool command?

5. Other

So far, I have written about Android OTA upgrade related topics including:

  • Basic introduction: "Android A/B System" series
  • Core module: "Android Update Engine Analysis" series
  • Dynamic Partitions: "Android Dynamic Partitions" series
  • Virtual A/B: "Android Virtual A/B Partition" series
  • Upgrade tools: "Android OTA related tools" series

For more information on these articles about Android OTA upgrades, please refer to "Introduction to Android OTA Upgrade Series Column Articles" .

If you have already subscribed to the dynamic partition and virtual partition paid column, please be sure to add me on WeChat, note the subscription account, and pull you into the "Dynamic Partition & Virtual Partition Column VIP Q&A Group". I will answer your questions about A/B systems, dynamic partitions, virtual partitions, various OTA upgrades and signatures at a convenient time.

In addition, I have an Android OTA upgrade discussion group, which now has 400+ friends, mainly discussing OTA upgrade topics for various devices such as mobile phones, car machines, TVs, set-top boxes, and tablets. If you are engaged in OTA upgrade work, welcome Join the group to communicate together, please indicate "Android OTA Discussion Group" when adding me on WeChat. This group is limited to Android OTA developers~

Reply "wx" in the backstage of the official account "Rocky Watching the World" to get personal WeChat.

Guess you like

Origin blog.csdn.net/guyongqiangx/article/details/129310109