我们经常需要查看内核编译的产物---boot.img里面的内容,那该如何查看呢?方法如下,本文采用倒叙法来写。
boot.img解压产物效果:
~/snap/Android_boot_image_editor/build/unzip_boot$ ls -l
total 44580
-rw-rw-r-- 1 ubuntu20 ubuntu20 3472 JAN 1 20:14 boot.avb.json
-rw-rw-r-- 1 ubuntu20 ubuntu20 973 JAN 1 20:14 boot.json
-rw-rw-r-- 1 ubuntu20 ubuntu20 167923 JAN 1 20:14 dtb
-rw-rw-r-- 1 ubuntu20 ubuntu20 15787699 JAN 1 20:14 kernel
-rw-rw-r-- 1 ubuntu20 ubuntu20 164024 JAN 1 20:14 kernel_configs.txt
-rw-rw-r-- 1 ubuntu20 ubuntu20 8 JAN 1 20:14 kernel_version.txt
-rw-rw-r-- 1 ubuntu20 ubuntu20 20813312 JAN 1 20:14 ramdisk.img
-rw-rw-r-- 1 ubuntu20 ubuntu20 37173 JAN 1 20:14 ramdisk.img_filelist.txt
-rw-rw-r-- 1 ubuntu20 ubuntu20 8647450 JAN 1 20:14 ramdisk.img.gz
drwxrwxr-x 27 ubuntu20 ubuntu20 4096 JAN 1 20:14 root
一、环境准备
1.1 boot解压工具下载
git clone https://github.com/zbx911/Android_boot_image_editor.git
1.2 Linux环境变量安装
sudo apt install git device-tree-compiler lz4 xz-utils zlib1g-dev openjdk-17-jdk gcc g++ python3 python-is-python3 p7zip-full android-sdk-libsparse-utils erofs-utils
1.3 gradle下载安装
主要是配置gradle的url,否则会报各种异常错误。
配置gradle:(路径)Android_boot_image_editor/gradle/wrapper/gradle-wrapper.properties
gradle/wrapper/gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-8.7-rc-3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
二、boot解压过程
执行: ./gradlew unpackDownloading https://mirrors.cloud.tencent.com/gradle/gradle-8.7-rc-3-bin.zip
............10%.............20%.............30%.............40%............50%.............60%.............70%.............80%.............90%............100%Welcome to Gradle 8.7-rc-3!Here are the highlights of this release:- Compiling and testing with Java 22- Cacheable Groovy script compilation- New methods in lazy collection propertiesFor more details see https://docs.gradle.org/8.7-rc-3/release-notes.htmlStarting a Gradle Daemon (subsequent builds will be faster)> Task :helper:compileKotlin
w: file:///home/ubuntu20/snap/Android_boot_image_editor/helper/src/main/kotlin/cfig/helper/CryptoHelper.kt:123:25 The value 'true' assigned to 'var bSuccess: Boolean defined in cfig.helper.CryptoHelper.KeyBox.Companion.parse4' is never used
w: file:///home/ubuntu20/snap/Android_boot_image_editor/helper/src/main/kotlin/cfig/helper/CryptoHelper.kt:127:29 The value 'false' assigned to 'var bSuccess: Boolean defined in cfig.helper.CryptoHelper.KeyBox.Companion.parse4' is never used
w: file:///home/ubuntu20/snap/Android_boot_image_editor/helper/src/main/kotlin/cfig/helper/CryptoHelper.kt:132:29 The value 'false' assigned to 'var bSuccess: Boolean defined in cfig.helper.CryptoHelper.KeyBox.Companion.parse4' is never used
w: file:///home/ubuntu20/snap/Android_boot_image_editor/helper/src/main/kotlin/cfig/helper/CryptoHelper.kt:502:43 Variable 'obj' initializer is redundant
w: file:///home/ubuntu20/snap/Android_boot_image_editor/helper/src/main/kotlin/cfig/helper/CryptoHelper.kt:521:29 Variable 'obj' is never used
w: file:///home/ubuntu20/snap/Android_boot_image_editor/helper/src/main/kotlin/cfig/helper/CryptoHelper.kt:533:47 Variable 'obj' initializer is redundant
w: file:///home/ubuntu20/snap/Android_boot_image_editor/helper/src/main/kotlin/cfig/helper/Launcher.kt:83:19 Variable 'cmd' is never used
w: file:///home/ubuntu20/snap/Android_boot_image_editor/helper/src/main/kotlin/cfig/helper/ZipHelper.kt:120:37 'getter for nextZipEntry: ZipArchiveEntry!' is deprecated. Deprecated in Java
w: file:///home/ubuntu20/snap/Android_boot_image_editor/helper/src/main/kotlin/cfig/helper/ZipHelper.kt:162:13 'constructor ZipFile(String!)' is deprecated. Deprecated in Java
w: file:///home/ubuntu20/snap/Android_boot_image_editor/helper/src/main/kotlin/cfig/helper/ZipHelper.kt:179:13 'constructor ZipFile(String!)' is deprecated. Deprecated in Java20:14:05.264 [main] INFO rom.fdt.DTC - no more FDT header
20:14:05.267 [main] WARN rom.fdt.DTC - Successfully parsed 0 FDT headers from build/unzip_boot/dtb, remainder: 187923 bytes
20:14:05.268 [main] INFO cfig.bootimg.v2.BootV2 - dtb sz = 0
20:14:05.272 [main] INFO avb.AVBInfo - parseFrom(FILE:boot.img) ...
20:14:05.287 [main] INFO avb.AVBInfo - FILE:boot.img: Glance(footer=Footer(versionMajor=1, versionMinor=0, originalImageSize=24606720, vbMetaOffset=24608768, vbMetaSize=1664), vbMetaOffset=24608768).footer
20:14:05.371 [main] INFO avb.AVBInfo - VBMeta: boot.img -> build/unzip_boot/boot.avb.json
20:14:05.552 [main] INFO cfig.Avb - signed with release key
20:14:05.613 [main] INFO cfig.bootimg.v2.BootV2 - Unpack Summary of boot.img
┌───────────────────────────────────────┬──────────────────────────────────────┐
│What │Where │
└───────────────────────────────────────┴──────────────────────────────────────┘
┌───────────────────────────────────────┬──────────────────────────────────────┐
│image info │build/unzip_boot/boot.json │
├───────────────────────────────────────┼──────────────────────────────────────┤
│AVB info [verified] │build/unzip_boot/boot.avb.json │
│\-- signing key │private release key │
├───────────────────────────────────────┼──────────────────────────────────────┤
│kernel │build/unzip_boot/kernel │
│\-- version [4.9] │build/unzip_boot/kernel_version.txt │
│\-- config │build/unzip_boot/kernel_configs.txt │
├───────────────────────────────────────┼──────────────────────────────────────┤
│ramdisk │build/unzip_boot/ramdisk.img.gz │
│\-- extracted ramdisk rootfs │build/unzip_boot/root │
├───────────────────────────────────────┼──────────────────────────────────────┤
│dtb │build/unzip_boot/dtb │
└───────────────────────────────────────┴──────────────────────────────────────┘
20:14:05.677 [main] WARN cfig.packable.PackableLauncher - 'unpack' sequence completed
三、boot.img打包
./gradlew pack