Android OTA related tools (8) Use lpadd to add images to super.img


I always thought that no one would use the lpadd tool, just like I thought that no one would use lpmake to manually generate super.img.

However, some friends really use lpadd and lpmake to learn and understand super.img.

lpadd not found

By the way, lpmake and lpadd are really good tools for learning super.img. It would be better if there is another lpdelete/remove. Of course, these are very low-frequency or even rarely used gadgets, so that the bug in lpunpack mentioned in the previous article has not been fixed.

In fact, the commands introduced by lpmake in the README.md of the official code also have bugs.

The previous articles introduced lpdump, lpmake and lpunpack respectively. This article introduces lpadd.

This article introduces the use of this tool based on lpadd compiled and generated by android-13.0.0_r41, but it is also applicable to other Android versions starting from Android 11 ®).

"Android OTA Related Tools" series currently has a list of articles:

This article is original by Guyongqiangx (guyongqiangx). Please indicate the source when reprinting.

Article link: https://blog.csdn.net/guyongqiangx/article/details/132635213

1. Compilation of lpadd

The lpadd tool is a logical partition tool introduced after Android 11®. The source code is located system/extras/partition_toolsin the directory. lpadd will not be compiled by default.

Since lpadd only supports running on the host, if you need to compile lpadd, you need to add it to PRODUCT_HOST_PACKAGES:

PRODUCT_HOST_PACKAGES += lpadd

I use the Android reference device Panther to compile here, and modify it as follows:

android-13.0.0_r41$ repo diff device/google/pantah/device-panther.mk 
project device/google/pantah/
diff --git a/device-panther.mk b/device-panther.mk
index 3c61c6d..e9e2f6c 100644
--- a/device-panther.mk
+++ b/device-panther.mk
@@ -143,6 +143,8 @@ PRODUCT_PROPERTY_OVERRIDES += \
 PRODUCT_PACKAGES += \
        libspatialaudio
 
+PRODUCT_HOST_PACKAGES += lpadd 
+
 # Bluetooth hci_inject test tool
 PRODUCT_PACKAGES_DEBUG += \
     hci_inject

After making the above modifications, compile again.

In addition to this method, you can also use mmm directly in the root directory to compile the partition_tools module where lpadd is located:

android-13.0.0_r41$ mmm system/extras/partition_tools
android-13.0.0_r41$ which lpadd
/local/public/users/rocky/android-13.0.0_r41/out/host/linux-x86/bin/lpadd

After compiling Android out/host/linux-x86/bin/lpadd, it is output to. After the first compilation, you can reference it after setting the Android compilation environment through source and lunch operations.

For example:

$ source build/envsetup.sh 
$ lunch aosp_panther-userdebug
$ which lpadd 
/public/rocky/android-13.0.0_r41/out/host/linux-x86/bin/lpadd

Of course, you can also out/host/linux-x86/binadd it to the current directory and use:

$ echo $PATH
/home/rocky/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
$ export PATH=${
    
    PWD}/out/host/linux-x86/bin:$PATH
$ echo $PATH
/public/rocky/android-13.0.0_r41/out/host/linux-x86/bin:/home/rocky/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
$ which lpadd 
/public/rocky/android-13.0.0_r41/out/host/linux-x86/bin/lpadd

Both methods are similar, but I personally recommend the former.

2. Help information for lpadd

The help information provided by the lpadd tool:

android-13.0.0_r41$ lpadd -h
lpadd - command-line tool for adding partitions to a super.img

Usage:
 lpadd [options] SUPER PARTNAME PARTGROUP [IMAGE]

  SUPER                         Path to the super image. It can be sparsed or
                                unsparsed. If sparsed, it will be unsparsed
                                temporarily and re-sparsed over the original
                                file. This will consume extra space during the
                                execution of lpadd.
  PARTNAME                      Name of the partition to add.
  PARTGROUP                     Name of the partition group to use. If the
                                partition can be updated over OTA, the group
                                should match its updatable group.
  IMAGE                         If specified, the contents of the given image
                                will be added to the super image. If the image
                                is sparsed, it will be temporarily unsparsed.
                                If no image is specified, the partition will
                                be zero-sized.

Extra options:
  --readonly                    The partition should be mapped read-only.
  --replace                     The partition contents should be replaced with
                                the input image.

In addition to the help information above, the documentation included in the Android source code system/extras/partition_tools/README.mdalso contains some explanations of lpadd, as follows:

official document for lpadd

According to the official Android documentation, in my opinion the following key points are:

  • lpadd can be used to add partition image files to super.img, or to add partitions to super_empty.img. It is beneficial in various situations of separate or mixed compilation, such as radio.img and system.img compiled by different codes managed by different departments or companies, but both hope to be finally added to a super.img.
  • The added partition name PART_NAME must not exist yet.
  • Partition image files cannot be added to super_empty.img.
  • lpadd will consume a lot of TMPDIR space, so if the default TMPDIR does not have enough space, temporarily specify a location through the command line variable TMPDIR.

3. Usage of lpadd

3.1 Preparation

For the convenience of demonstration, I have manually generated 3 super device images named rocky, which are:

  • empty's super device image: rocky_empty.img
  • Super device image in raw format: rocky_raw.img
  • Super device image in sparse format: rocky_sparse.img

The size of the super device is 10G (10000M):

  • Contains 2 "guyognqiangx_a", "guyongqiangx_b" with a size of 4G (4000M) and the default "default" group group
  • Groups "guyognqiangx_a" and "guyongqiangx_b" contain "boot_a" and "boot_b" with a size of 20M respectively.
  • The default group "default" contains a "radio" group with a size of 100M

In addition, I android-13.0.0_r41conducted this experiment based on compiling Google's Panther device. If you download the code and compile Panther, please refer to the step-by-step article "How to download and compile Android source code?"

Because when making images in raw format and sparse format, the specified partition needs to be converted to sparse format first, so I converted radio.img and system.img into sradio.img and ssystem.img in sparse format:

$ img2simg out/target/product/panther/radio.img sradio.img 
$ img2simg out/target/product/panther/system.img ssystem.img 
$ ls -lh out/target/product/panther/{
    
    radio,system}.img {
    
    sradio,ssystem}.img
-rw-r--r-- 1 rocky users  77M Aug 16 00:29 out/target/product/panther/radio.img
-rw-r--r-- 1 rocky users 846M Aug 16 00:58 out/target/product/panther/system.img
-rw-r--r-- 1 rocky users  68M Sep  2 09:36 sradio.img
-rw-r--r-- 1 rocky users 843M Sep  2 09:36 ssystem.img
empty super device image

Does not contain any partition images

$ lpmake --device-size 10485760000 \
        --metadata-size 65536     \
        --metadata-slots 2        \
        -g guyongqiangx_a:4194304000 \
        -g guyongqiangx_b:4194304000 \
        -p "radio:readonly:104857600" \
        -p "boot_a:none:2197520:guyongqiangx_a" \
        -p "boot_b:none:2197520:guyongqiangx_b" \
        -o rocky_empty.img
Super device image in raw format

The "radio" partition in the "default" group uses the image "sradio.img"

$ lpmake --device-size 10485760000 \
       --metadata-size 65536     \
       --metadata-slots 2        \
       -g guyongqiangx_a:4194304000 \
       -g guyongqiangx_b:4194304000 \
       -p "radio:readonly:104857600" \
       -i "radio=sradio.img" \
       -p "boot_a:none:2197520:guyongqiangx_a" \
       -p "boot_b:none:2197520:guyongqiangx_b" \
       -o rocky_raw.img
Super device image in sparse format
  • The "radio" partition in the "default" group uses the image "sradio.img"
  • The "system_a" partition in the "guyongqiangx_a" group uses the image "ssystem.img"
  • Use "-S" to specify the output sparse format image
$ lpmake --device-size 10485760000 \
       --metadata-size 65536     \
       --metadata-slots 2        \
       -g guyongqiangx_a:4194304000 \
       -g guyongqiangx_b:4194304000 \
       -p "radio:readonly:104857600" \
       -i "radio=sradio.img" \
       -p "system_a:readonly:1048576000:guyongqiangx_a" \
       -i "system_a=ssystem.img" \
       -p "boot_a:none:2197520:guyongqiangx_a" \
       -p "boot_b:none:2197520:guyongqiangx_b" \
       -S -o rocky_sparse.img

After adding the partition images in the three formats, you can use lpdump to view the partition image status.

Subsequent operations mainly use the partition image rocky_raw.img in raw format.

3.1 lpadd partition operation example

Recommendation: After completing the following steps of lpmake and lpadd, it is recommended to use lpdump or lpunpack to check the results of lpadd to deepen your understanding of lpadd and super dynamic partition devices.

Add a new partition "vendor_a" and mirror to the "guyongqiangx_a" group of rocky_raw.img:

$ lpadd rocky_raw.img vendor_a guyongqiangx_a out/target/product/panther/vendor.img

Add the readonly partition "radio_a" in the "guyognqiangx_a" group

$ lpadd rocky_raw.img --readonly radio_a guyongqiangx_a

Based on the previous step, directly adding a mirror to the radio_a partition failed. You need to use the “–replace” option to add a partition mirror:

$ lpadd rocky_raw.img radio_a guyongqiangx_a out/target/product/panther/radio.img
[liblp]Attempting to create duplication partition with name: radio_a
Could not add partition: radio_a
$ lpadd rocky_raw.img --replace radio_a guyongqiangx_a out/target/product/panther/radio.img
Writing data for partition radio_a...
Done.

Because the default when using lpadd is to add a new partition to the super device, if the partition already exists and you need to update the partition image, you need to use the “–replace” option.

Replace the radio_a partition image from the original radio.img to bootloader.img:

$ lpadd rocky_raw.img --replace radio_a guyongqiangx_a out/target/product/panther/bootloader.img
Writing data for partition radio_a...
Done.

Directly adding partitions and mirrors to the empty super device will fail:

$ lpadd rocky_empty.img radio_a guyongqiangx_a out/target/product/panther/radio.img
Cannot add a partition image to an empty super file.

But you can add partitions to the empty super device:

$ lpadd rocky_empty.img radio_a guyongqiangx_a
Done.

For the management of logical partitions, it would be perfect to add an lpdelete or lpremove to remove the partition from the super device, because then the add, delete, modify, and check operations of the entire partition will be available, but it is a pity that it is not available~

4. Others

For more content about these articles related to Android OTA upgrade, please refer to "Introduction to Android OTA Upgrade Series Column Articles" .

If you have subscribed to the paid columns for dynamic partitioning and virtual partitioning, please be sure to add me on WeChat and note your subscription account number to join the "Dynamic Partitioning & Virtual Partitioning 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. This group is limited to column subscribers~

In addition, I have an Android OTA upgrade discussion group. There are now 400+ friends in it. They mainly discuss OTA upgrade topics for mobile phones, car machines, TVs, set-top boxes, tablets and other devices. If you are engaged in OTA upgrade work, welcome To join a group to communicate, please indicate "Android OTA Discussion Group" when adding me on WeChat. This group is only open to Android OTA developers~

In the background of the public account "Rocky Sees the World", reply "wx" to obtain your personal WeChat account.

Guess you like

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