适用于Android内核boot.img生成流程

适用于Android内核boot.img生成流程

  • 作者:吴思含(Witheart)
  • 更新时间:20241205

1. 内核编译

  1. 执行以下脚本编译内核源码:

    bash 复制代码
    ./make.sh
  2. 编译完成后,在内核源码目录下生成以下文件:

    • boot.img:包含内核镜像 Image 和 second(实际上是 resource.img)。
    • resource.img:资源镜像。

    注意:

    • 此时生成的 boot.img 缺少 ramdisk.img。
    • 此时的 resource.img 不完整,缺少电量显示图片等资源。

2. 生成完整的 boot.img

2.1 补充 resource.img 的内容
  1. 进入 u-boot 目录:

    bash 复制代码
    cd ../u-boot/
  2. 使用 u-boot 目录下的打包工具重新打包 resource.img:

    bash 复制代码
    ./scripts/pack_resource.sh ../kernel/resource.img

    脚本功能:

    • 解包指定的 resource.img。
    • 将 <uboot>/tools/images/ 目录下的所有 .bmp 图片资源,和原有资源一起重新打包为一个新的 resource.img。
  3. 将打包完成的 resource.img 复制回内核源码目录:

    bash 复制代码
    cp resource.img ../kernel/

2.2 生成完整的 boot.img
  1. 返回 Android SDK 顶层目录:

    bash 复制代码
    cd ../
  2. 执行以下命令生成完整的 boot.img:

    bash 复制代码
    make bootimage -j16

    命令说明:

    • 生成过程中会自动创建 ramdisk.img。
    • 将 ramdisk.img、内核镜像 Image、内核 DTB 文件,以及重新打包的 resource.img 一起打包成完整的 boot.img。
  3. 生成的完整 boot.img 输出路径:

    复制代码
    <SDK>/out/target/product/<产品名称>/boot.img

    说明: 该 boot.img 是最终要烧录到开发板 boot 分区的文件。


总结

  • boot.img 的生成涉及两个重要步骤:
    1. 补充完善 resource.img。
    2. 生成完整的 boot.img。
  • 最终生成的 boot.img 包含以下内容:
    • 内核镜像 Image。
    • 内核设备树 DTB 文件。
    • 初始根文件系统镜像 ramdisk.img。
    • 资源镜像 resource.img。
相关推荐
booboosui7 小时前
编号没变,消息还是来了:Mac 端通知读取漏第二条的原因
android
雨白1 天前
单例设计模式:从 Java/Kotlin 实现到 Android 实战
android
hai_android1 天前
一行 asLiveData,背后是一座生命周期的桥
android·java·kotlin
阿杰m1 天前
Android源码第二十三章:Telephony、RIL 与 IMS——来电怎么到应用?
android
booboosui1 天前
没人认领 .md:安卓把报告交给了音乐播放器打开
android
用户60709759149061 天前
AOSP 14 OTA 升级指导(四):update_engine 内部机制——Action 流水线与写盘
android
恋猫de小郭1 天前
Jetpack Compose 1.13 发布,憋了这么久终有交代了
android·前端·flutter
JMchen1231 天前
【Android 性能优化实战 60 讲】12 异步 Inflate 实战与痛击:源码拆解原生瓶颈,手写增强版布局预加载框架
android·性能优化·实战·启动优化·异步inflate·x2c
好的佩奇2 天前
蓝牙之设备角色与连接
android·flutter·蓝牙
雨白2 天前
Android 消息机制剖析:从 Handler 投递到 Looper 循环的全链路
android