美文网首页
编译&刷机

编译&刷机

作者: MelanDawn | 来源:发表于2022-01-22 17:16 被阅读0次

说明:以下所有编译命令均在源码根目录执行操作

一、加载编译环境

source build/envsetup.sh

二、编译

2.1 编译完整Android

Android 全编译的完整操作命令有两种:

  1. 第一种:
source build/envsetup.sh
lunch
<input number>【在编号列表中选择合适的产品编号】
make -j 32

1.1 第二种:

source build/envsetup.sh
lunch <product_name_type> 【以pixel5为例,它的产品名称是 aosp_redfin-userdebug】
make -j 32

2.2 编译 image

make systemimage
make systemextimage

2.3 编译模块

具体请通过帮助命令查询:

  • m help
  • hmm

2.4 使用 Ninja 编译模块

alias ninja=./prebuilts/build-tools/linux-x86/bin/ninja
ninja -f out/combined-<XXX>.ninja <module_name>

for example (Bluetooth.apk on pixel5):

alias ninja=./prebuilts/build-tools/linux-x86/bin/ninja
ninja -f out/combined-aosp_redfin.ninja Bluetooth

三、解锁设备

  1. 打开开发者模式
  2. 进入开发者模式首页,打开“OEM解锁”开关
  3. 命令行执行 adb reboot bootloader
  4. 设备重启至屏幕显示内容之后,执行 fastboot flashing unlock
  5. 通过音量加、减按键,选择 unlock 选项;再通过电源按键确定选择,手机自行重启
  6. 执行 adb disable-verity
  7. 执行 adb reboot ,设备重启
  8. 执行 adb root
  9. 执行 adb remount

执行 1-5 后,设备即可执行全刷;
再执行 6-9 后,设备即可执行模块的更新(后文的刷模块)。

四、刷机(烧录)

4.0 前提条件

以 pixel5 为例:

  1. 将 pixel5 通过线连接到电脑;
  2. 打开手机的开发者模式;
  3. 启动 USB 调试模式。

4.1 全刷

  1. 生成刷机文件 images.zip
zip images.zip out/target/product/redfin/*.img out/target/product/redfin/android-info.txt 
  1. 刷机命令
    需要在image所在的路径执行
fastboot flash bootloader bootloader.img
fastboot reboot-bootloader
fastboot flash radio radio.img
fastboot reboot-bootloader
fastboot -w update images.zip

4.2 刷 image

4.2.1 刷 image 的模式

4.2.1.1 bootloader 模式

进入方式:

xxx reboot bootloader

例如:

adb reboot bootloader

fastboot reboot bootloader
4.2.1.2 fastbootd 模式

进入方式:

xxx reboot fastboot

例如:

adb reboot bootloader

fastboot reboot fastboot

4.2.2 刷 image 举例

由于存在两种刷机模式,因此首先需要明确该 img 需要在哪个模式下进行烧录,然后执行烧录命令。

  1. 例如烧录 bootloader.img (bootloader):
adb reboot bootloader
fastboot flash bootloader bootloader.img
  1. 例如烧录 system.img (fastbootd)
adb reboot fastboot
fastboot flash system system.img

4.3 刷 模块(so、jar、apk 等)

4.3.1 刷模块 举例

  1. 刷 设置应用(以 pixel5 redfin 为例)
adb push out\target\product\redfin\system_ext\priv-app\Settings\Settings.apk  system_ext/priv-app/Settings/
4.3.2 刷模块的脚本 举例
  1. init.bat(进入源码根目录的脚本)
Y:
cd pixel5
  1. remount.bat(挂载设备的脚本)
adb root
adb remount
  1. push_settings_apk.bat(push 目标产物的脚本)
call remount.bat
call init.bat

adb push out\target\product\redfin\system_ext\priv-app\Settings\Settings.apk  system_ext/priv-app/Settings/

五、刷机 Log

5.1 全刷(注意:中途进入 fastbootd 模式)

执行的命令

adb reboot bootloader
fastboot flash bootloader bootloader.img
fastboot reboot-bootloader
fastboot flash radio radio.img
fastboot reboot-bootloader
fastboot -w update images.zip

由于中途进入了fastbootd模式,因此需要注意:
哪些 image 在bootloader模式下刷;
哪些 image 在fastbootd模式下刷。

注意:执行该命令之前,处在 bootloader 模式

PS E:\device\pixel\localimg> fastboot -w update images.zip
\--------------------------------------------
Bootloader Version...: r3-0.3-6776358
Baseband Version.....: g7250-00016-200826-B-6790987
Serial Number........: 0C111FDD4001NF
--------------------------------------------
extracting android-info.txt (0 MB) to RAM...
Checking 'product'                                 OKAY [  0.066s]
Setting current slot to 'a'                        OKAY [  0.079s]
extracting boot.img (96 MB) to disk... took 0.258s
archive does not contain 'boot.sig'
Sending 'boot_a' (98304 KB)                        OKAY [  2.434s]
Writing 'boot_a'                                   OKAY [  0.505s]
extracting dtbo.img (16 MB) to disk... took 0.031s
archive does not contain 'dtbo.sig'
Sending 'dtbo_a' (16384 KB)                        OKAY [  0.492s]
Writing 'dtbo_a'                                   OKAY [  0.175s]
archive does not contain 'dt.img'
archive does not contain 'recovery.img'
extracting vbmeta.img (0 MB) to disk... took 0.001s
archive does not contain 'vbmeta.sig'
Sending 'vbmeta_a' (8 KB)                          OKAY [  0.137s]
Writing 'vbmeta_a'                                 OKAY [  0.070s]
extracting vbmeta_system.img (0 MB) to disk... took 0.000s
archive does not contain 'vbmeta_system.sig'
Sending 'vbmeta_system_a' (4 KB)                   OKAY [  0.137s]
Writing 'vbmeta_system_a'                          OKAY [  0.076s]
extracting vendor_boot.img (96 MB) to disk... took 0.192s
archive does not contain 'vendor_boot.sig'
Sending 'vendor_boot_a' (98304 KB)                 OKAY [  2.441s]
Writing 'vendor_boot_a'                            OKAY [  0.366s]
extracting super_empty.img (0 MB) to disk... took 0.000s


Rebooting into fastboot                            OKAY [  0.062s]
< waiting for any device >
Sending 'super' (4 KB)                             OKAY [  0.001s]
Updating super partition                           OKAY [  0.008s]
Resizing 'product_a'                               OKAY [  0.005s]
Resizing 'system_a'                                OKAY [  0.006s]
Resizing 'system_ext_a'                            OKAY [  0.005s]
Resizing 'system_b'                                OKAY [  0.006s]
Resizing 'vendor_a'                                OKAY [  0.005s]
Resizing 'vendor_b'                                OKAY [  0.004s]
archive does not contain 'boot_other.img'
archive does not contain 'odm.img'
archive does not contain 'odm_dlkm.img'
extracting product.img (228 MB) to disk... took 1.100s
archive does not contain 'product.sig'
Resizing 'product_a'                               OKAY [  0.005s]
Sending 'product_a' (233900 KB)                    OKAY [  5.923s]
Writing 'product_a'                                OKAY [  2.001s]
extracting system.img (837 MB) to disk... took 3.565s
archive does not contain 'system.sig'
Resizing 'system_a'                                OKAY [  0.007s]
Sending sparse 'system_a' 1/4 (262140 KB)          OKAY [  6.754s]
Writing 'system_a'                                 OKAY [  0.911s]
Sending sparse 'system_a' 2/4 (262140 KB)          OKAY [  6.727s]
Writing 'system_a'                                 OKAY [  1.012s]
Sending sparse 'system_a' 3/4 (262140 KB)          OKAY [  6.686s]
Writing 'system_a'                                 OKAY [  0.992s]
Sending sparse 'system_a' 4/4 (70804 KB)           OKAY [  1.805s]
Writing 'system_a'                                 OKAY [  0.296s]
extracting system_ext.img (117 MB) to disk... took 0.450s
archive does not contain 'system_ext.sig'
Resizing 'system_ext_a'                            OKAY [  0.006s]
Sending 'system_ext_a' (120496 KB)                 OKAY [  3.043s]
Writing 'system_ext_a'                             OKAY [  0.478s]
extracting system_other.img (23 MB) to disk... took 0.111s
archive does not contain 'system.sig'
Resizing 'system_b'                                OKAY [  0.006s]
Sending 'system_b' (23836 KB)                      OKAY [  0.609s]
Writing 'system_b'                                 OKAY [  0.147s]
extracting vendor.img (673 MB) to disk... took 2.744s
archive does not contain 'vendor.sig'
Resizing 'vendor_a'                                OKAY [  0.006s]
Sending sparse 'vendor_a' 1/3 (262140 KB)          OKAY [  6.794s]
Writing 'vendor_a'                                 OKAY [  0.924s]
Sending sparse 'vendor_a' 2/3 (262140 KB)          OKAY [  6.702s]
Writing 'vendor_a'                                 OKAY [  0.999s]
Sending sparse 'vendor_a' 3/3 (165656 KB)          OKAY [  4.250s]
Writing 'vendor_a'                                 OKAY [  0.631s]
archive does not contain 'vendor_dlkm.img'
archive does not contain 'vendor_other.img'
Erasing 'userdata'                                 OKAY [  7.315s]
Erase successful, but not automatically formatting.
File system type raw not supported.
Erasing 'metadata'                                 OKAY [  0.013s]
Erase successful, but not automatically formatting.
File system type raw not supported.
Rebooting                                          OKAY [  0.001s]
Finished. Total time: 100.540s

六、分区与镜像

Android分区介绍 by Goole
引导加载程序(bootloader)示例流程

镜像文件名 用途
recovery.img
bootloader.img 供应商专有的镜像,可包含多个bootloader,负责在设备上启动内核。
\color{red}{物理分区}
boot.img 其中包含 kernel 镜像和 ramdisk 镜像
dtb.img Device Tree Blob image
dtbo.img Device Tree Blob overlay image
vbmeta.img Verified Boot
Android Verified Boot (AVB)是 Verified Boot 的一种具体实现。
\color{red}{动态分区} 动态分区适用于用户空间分区,从用户空间分区独立出来的分区如果不属于用户空间分区,那么也不属于动态分区
odm.img
product.img
system.img
system_ext.img
vendor.img
super.img 动态分区镜像的集合,但具体包含了哪些镜像可根据配置查询。

以 db845c 为例:
device/linaro/dragonboard/BoardConfigCommon.mk
BOARD_BUILD_SUPER_IMAGE_BY_DEFAULT := true
BOARD_SUPER_PARTITION_GROUPS := db_dynamic_partitions
BOARD_DB_DYNAMIC_PARTITIONS_PARTITION_LIST := system vendor system_ext product
该开发板的 super.img 包含了 system、system_ext、product、vendor 四个镜像
radio.img
ramdisk.img
userdata.img

相关文章

网友评论

      本文标题:编译&刷机

      本文链接:https://www.haomeiwen.com/subject/oevqlltx.html