HOWTO: Unpack, Edit, and Re-Pack Boot Images

RK3576-Android15-Android16-免root 方案-客户免root方案实现su 相关操作 最近自己在做开机动画相关需求时候,涉及到一个权限问题。对于App 测和adb 命令侧一定要su 情况下才能够进行相关操作。有的时候甚至需要才能操作。这里暂不分析为什么这么改,有兴趣自行分析这个拿来直接用,对开发调试 释放权限,针对客户友好开发非常好。 阅读详情

From: http://android-dls.com/wiki/index.php?title=HOWTO:_Unpack%2C_Edit%2C_and_Re-Pack_Boot_Images

 

Several people have already figured out the details on their own, but I have gotten requests to do a more comprehensive tutorial on how the boot and recovery images are structured, and how you can edit them.

 

Background

Your phone has several devices which hold different parts of the filesystem:

#cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00040000 00020000 "misc"
mtd1: 00500000 00020000 "recovery"
mtd2: 00280000 00020000 "boot"
mtd3: 04380000 00020000 "system"
mtd4: 04380000 00020000 "cache"
mtd5: 04ac0000 00020000 "userdata"

In this tutorial, we will deal with "recovery" and "boot". "system" holds everything that gets mounted in your system/ directory, and userdata/ is everything that shows up in data/ (this is all the apps you've installed, your preferences, etc).

The recovery and boot partitions are at /dev/mtd/mtd1 and /dev/mtd/mtd2, and before you do anything else you should back these up:

# cat /dev/mtd/mtd1 > /sdcard/mtd1.img
# cat /dev/mtd/mtd2 > /sdcard/mtd2.img

The other thing you should do is put your favorite update.zip file into the root directory of your sd card so that if you screw up your boot partition you can boot into recovery mode and re-apply the update. You probably want one of the pre-rooted recovery images found elsewhere on the forums.

There is also another important file you should know about. in /system/recovery.img there is a full copy of everything that is loaded on mtd1. This file is automatically flashed onto mtd1 every time you shut down. That means two things: 1. Any changes you make directly to /dev/mtd/mtd1 get blown away on reboot and 2. If you want to change /dev/mtd/mtd1 you're probably better off just sticking the image in /system/recovery.img and rebooting. When creating your own custom update.zip files (especially when adapting the stock images), you can get tripped up if you forget to replace /system/recovery.img and it ends up overwriting /dev/mtd/mtd1 unbeknownst to you. Watch out.

Structure of boot and recovery images

The boot and recovery images are not proper filesystems. Instead, they are a custom android format consisting of a 2k header, followed by a gzipped kernel, followed by a ramdisk, followed by a second stage loader (optional, we have not seen these in the wild yet). This structure is outlined in mkbootimg.h :

+-----------------+ 
| boot header     | 1 page
+-----------------+
| kernel          | n pages  
+-----------------+
| ramdisk         | m pages  
+-----------------+
| second stage    | o pages
+-----------------+

n = (kernel_size + page_size - 1) / page_size
m = (ramdisk_size + page_size - 1) / page_size
o = (second_size + page_size - 1) / page_size

0. all entities are page_size aligned in flash
1. kernel and ramdisk are required (size != 0)
2. second is optional (second_size == 0 -> no second)

A ramdisk is basically a small filesystem containing the core files needed to initialize the system. It includes the critical init process, as well as init.rc, which is where you can set many system-wide properties. If you really want to know more about it, here is the documentation . Here's a list of files on a typical ramdisk:

./init.trout.rc
./default.prop
./proc
./dev
./init.rc
./init
./sys
./init.goldfish.rc
./sbin
./sbin/adbd
./system
./data

The recovery image typically has a few extra files, which constitute the recovery binary and supporting files (the application that gets run if you hold down home+power when rebooting). These files are:

./res
./res/images
./res/images/progress_bar_empty_left_round.bmp
./res/images/icon_firmware_install.bmp
./res/images/indeterminate3.bmp
./res/images/progress_bar_fill.bmp
./res/images/progress_bar_left_round.bmp
./res/images/icon_error.bmp
./res/images/indeterminate1.bmp
./res/images/progress_bar_empty_right_round.bmp
./res/images/icon_firmware_error.bmp
./res/images/progress_bar_right_round.bmp
./res/images/indeterminate4.bmp
./res/images/indeterminate5.bmp
./res/images/indeterminate6.bmp
./res/images/progress_bar_empty.bmp
./res/images/indeterminate2.bmp
./res/images/icon_unpacking.bmp
./res/images/icon_installing.bmp
./sbin/recovery

Unpacking, Editing, and Re-Packing the images

Note: below I give you the details for unpacking and repacking manually, but I created two perl scripts that do most of this for you (unpack-bootimg.pl , repack-bootimg.pl ).

If you are good with a hex editor, you can open up any of these images and strip off the first 2k of data. Then, look for a bunch of zeroes followed by the hex 1F 8B (which is the magic number of a gzip file). Copy everything from the first line of the file, through the zeroes, and stopping at the 1F 8B. That is the kernel. Everything from the 1F 8B through the end is the ramdisk. You could save each of these files separately. In order to see the contents of the ramdisk, you need to un-gzip it and then un-cpio it. You could use a command like this (ideally after creating a new directory and cd'ing into it):

gunzip -c ../your-ramdisk-file | cpio -i

That will place all of the files from the ramdisk in your working directory. You can now edit them.

In order to re-create the ramdisk, you need to re-cpio them and re-gzip those files, with a command like the following (remember, cpio will include everything in the current working directory, so you probably want to remove any other cruft you might have in there):

find . | cpio -o -H newc | gzip > ../newramdisk.cpio.gz

The final step is to combine the kernel and your new ramdisk into the full image, using the mkbootimg program (which you should download and compile from the git repository):

mkbootimg --cmdline 'no_console_suspend=1 console=null' --kernel your-kernel-file --ramdisk newramdisk.cpio.gz -o mynewimage.img

Now, there's a lot of hassle in pulling apart files in hex editors and remembering all of these commands, so I wrote unpack and repack perl scripts for you. Hooray.

Alternative Method

Download split_bootimg.zip . This Zip file contains one Perl file, split_bootimg.pl, which reads the boot.img header (according to the bootimg.h of the Android source code ) to extract the kernel and ramdisk. The script also outputs the kernel command line and board name (if specified).

(Note: Do not use a boot.img image extracted directly from /dev/mtd/mtd2 . This image may become corrupted during the read process.)

The following example uses the boot.img from the full TC4-RC28 update:

% ./split_bootimg.pl boot.img 
Page size: 2048 (0x00000800)
Kernel size: 1388548 (0x00153004)
Ramdisk size: 141518 (0x000228ce)
Second size: 0 (0x00000000)
Board name: 
Command line: no_console_suspend=1
Writing boot.img-kernel ... complete.
Writing boot.img-ramdisk.gz ... complete.

Extract the ramdisk.

% mkdir ramdisk
% cd ramdisk
% gzip -dc ../boot.img-ramdisk.gz | cpio -i
% cd ..

Make any changes necessary (e.g., set ro.secure=0 in default.prop ).

Recreate the cpio archive using the mkbootfs binary produced from building the Android source code (The cpio utility in OS X does not recognize the newc format, therefore mkbootfs is the best option for OS X users).

% mkbootfs ./ramdisk | gzip > ramdisk-new.gz

Recreate the image file using the mkbootimg binary produced from building the Android source code.

% mkbootimg --cmdline 'no_console_suspend=1 console=null' --kernel boot.img-kernel --ramdisk ramdisk-new.gz -o boot-new.img

(Note: the console=null command line option was introduced in the TC4-RC30 boot images to remove the root shell (TODO: add link))

Flashing your new image back onto the phone

You will probably only ever be flashing boot images directly to the phone, given the fact that /system/recovery.img automatically flashes the recovery device for you (as noted above). If you have created a new recovery image, just stick it in /system/recovery.img and reboot. If you are flashing a boot image, stick it on your phone via adb (a tool included in the Android SDK ):

adb push ./mynewimage.img /sdcard

Then, open a shell to your phone via 'adb shell', get root , and do the following two commands to flash your new boot image:

# cat /dev/zero > /dev/mtd/mtd2
   write: No space left on device [this is ok, you can ignore]
# flash_image boot /sdcard/mynewimage.img

Reboot.

If your phone starts all the way up, congratulations. If not, you did something wrong and you'll need to boot into recovery mode and apply your update.zip file (reboot while holding down home+power, when you get the recovery screen press alt+L and then alt+S).

Something fun to do with your new found power

If you place a file titled initlogo.rle in the root directory of your boot image, the phone will display this image upon boot (after the "G1" image and before the Android animation). In order to create this file, you need to create a 320x480 image in Photoshop or Gimp and save it as a "raw image" file. You then need to compress that image with the program to565. More details on that here .

 

This is not the same thing as applying an update.zip

You will see other places on the forums that describe how to create customized update.zip files, as well as update.zip files that people are sharing. For example, there is a recent update.zip which is a modified version of rc30 (with the anti-root aspects disabled). The update.zip files include new boot images, recovery images, and typically replacements for the entire system/ directory as well as other updates. If you are creating a custom boot or recovery image, it is typically a good idea to start with the image distributed with the most recent update you have applied (flashing an image from an older release could have unintended consequences).


Questions?

 

RK3576-Android16-实现开机动画自定义-动态替换bootanimation.zip 开机动画本身分三个不分:uboot 、 kernel 、 Android 三个部分开机动画。我们这里只讲Android层的开机动画,开机动画本身打包到镜像里面去,现在需求就是可以动态替换开机动画实现开机动画自定义、客户可控的功能。平台是RK3576 Android16 方案这里核心是其它根据个人需求,无关紧要代码在Android16 平台上,动态替换开机动画的一次尝试折腾了固化的只读分区,暂未成功,但是自己的方案data 分区也是一个尝试,可以完美解决实际需求。 阅读详情

相关推荐

FREERTOS+LWIP+IAP实现TCP、HTTP、网页访问并固件升级、更新配置 (三)lwip实现httpd服务并在web访问

在前两篇文章中配置freeRTOS和,并实现了TCP、UDP的通信协议,现在终于轮到重头戏lwip的httpd服务,LWIP官方例程中是有很多自带的网页的,但是远远不够满足实际项目的使用需求,因此我也是踩了很多坑,从前端网页制作,到网络通信的实现,到后端数据处理,从头开始学起,也是学习到了很多没接触过的东西,本章将搭建LWIP的HTTP服务使得浏览器可以访问WEB。

wangjiaheng0716的博客 2971

【转】HOWTO: Unpack, Edit, and Re-Pack Boot Images

<br />Several people have already figured out the details on their own, but I have gotten requests to do a more comprehensive tutorial on how the boot and recovery images are structured, and how you can edit them. Contents[hide]1Background2Structure of boo

lovescorpio的专栏 749

如何用谷歌插件Apollo.io高效开发客户?手把手教你避开常见坑点

本文详细介绍了如何利用谷歌插件Apollo.io高效开发外贸客户,包括核心功能解析、免费额度最大化利用策略、多插件协同技巧以及常见陷阱规避方法。通过Apollo.io的智能匹配算法和庞大数据库,外贸从业者可以精准锁定目标客户,提升开发效率。

banana的博客 899

Android: How to Unpack, Edit, and Re-Pack Boot Images

http://android-dls.com/wiki/index.php?title=HOWTO:_Unpack%2C_Edit%2C_and_Re-Pack_Boot_Images HOWTO: Unpack, Edit, and Re-Pack Boot Images Several people have already figured out the details on t

Lanttor的技术博文 1389

LAMMPS实操系列(四): 高熵合金FCC-CoCrCuFeNi的退火模拟

我们对FCC-CoCrCuFeNi的退火模拟思路主要是,首先将材料以均匀的速率用100 ps从300 K升温至1000 K,然后在1000 K的温度下平衡100 ps,随后以均匀的速率用100 ps从1000 K降温至300 K,随后通过共轭梯度下降法做静力学结构优化得到退火后的结构。由于FCC-CoCrCuFeNi高熵合金被认为是潜在的工程结构材料[1],接下来我们将对退火前后的结构进行压缩模拟,对比退火前后FCC-CoCrCuFeNi高熵合金的力学性能变化,敬请各位读者关注我们的更新。

Ceshigo_CD的博客 4843

55、宇宙微波背景辐射望远镜及其光学系统解析

本文详细解析了宇宙微波背景辐射(CMB)望远镜及其光学系统的设计与优化。内容涵盖折射与反射光学系统的特性、旁瓣控制技术、气球与地面观测系统的对比、探测器阵列的发展、光学系统设计流程以及不同观测场景下的光学系统选择。同时,文章展望了CMB望远镜光学系统的未来发展趋势,包括技术创新、多频段观测、国际合作与大型项目等。通过系统性的分析与对比,为CMB研究提供了全面的技术支持与理论基础。

f9g0h的博客 149

MySQL 分片集群的备份别堆本地盘:用 Vitess 把备份落进 RustFS

Vitess 把 MySQL 拆成很多分片,一个分片跑在一台 tablet 上。备份要是还落在每台 tablet 自己的本地盘里,分片一多就散成一地,真要恢复的时候还得挨个去找哪台机器存了哪份。更现实的麻烦是本地盘一旦坏掉,那份备份跟着就没了,分片越密,单点越稠。Vitess 自带一套 S3 兼容的备份存储实现,能把每个分片的备份直接写进对象存储。用 RustFS 当这个 S3 后端,所有分片的…

分布式存储与RustFS的博客 910

通过分子模板构建随机分布在溶液中的纳米颗粒(一)

通过分子模板构建随机分布在溶液中的纳米颗粒 要实现的目标: 1、可以循环建立多个水分子溶液的模型; 2、针对不同水分子数,自动创建文件夹; 3、运行完毕将所有结果自动存储在对应文件夹里; 分子模板的具体教程请见我的博客: https://blog.csdn.net/qq_43689832/article/details/104443175 1、首先,我们先建立纳米颗粒的分子模板,命名为p_30.txt: 包括两种原子类型。具体格式如下: # LAMMPS molecule file makin.

Rockyoung 2651

CRMEB Pro 秒杀库存:高并发下的扣减写法

秒杀二开别只改活动价。三处要一起减,且必须在创单事务里。

weixin_39475803的博客 215

CANoe中如何仿真报文的CRC和Counter,告诉你三种方法皆可实现

CANoe中如何仿真报文的CRC和Counter

蚂蚁小兵 5293

模型训练篇 | 手把手教你使用ResNet训练自己数据集和推理,ResNet50通用物体分类识别,含完整代码和数据集,全网最详细教程

手把手教你使用ResNet训练自己数据集和推理,ResNet50通用物体分类识别,含完整代码和数据集,全网最详细教程。本篇文章将带你学习 ResNet50 模型构建、ResNet50训练自己数据集、数据集处理、推理和验证、模型剪枝与模型改进等。 本篇教程适配各种分类识别任务,可以说是一个通用的教程,只需修改自己的数据集即可完成自己领域的任务和系统实现。

在职AI算法工程师,擅长计算机视觉,YOLO目标检测、分割等,擅长web、pyqt界面可视化,好内容持续更新中,来这里跟大家一起学习,共同进步 757

MySQL 备份恢复(日志管理和备份)

MySQL日志用于排错、性能分析及数据恢复。主要日志包括错误日志(记录启动、关闭及运行错误)、通用查询日志(记录客户端所有操作)。通过配置文件my.cnf可指定日志路径,如log_error = error.log。使用SHOW VARIABLES LIKE 'log_error'查看错误日志位置。通用查询日志需开启general_log = ON并指定文件路径。日志对故障排查和数据恢复至关重要。

Y_P_W的博客 207

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

Android的APK 集成到 AOSP 源码的方法和流程介绍

1. 目录# 3. device.mk 中添加# 4. 编译编译完成后,APK 就会出现在下,烧录镜像后系统自带该应用。

ZZXTIANMING的博客 271

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

RK3588边缘计算:YOLOv8 使用Android NDK部署_笔记1

RKNN Model Zoo基于 RKNPU SDK 工具链开发, 提供了目前主流算法的部署例程. 例程包含导出RKNN模型, 使用 Python API, CAPI 推理 RKNN 模型的流程.支持RK3562RK3566RK3568RK3576RK3588RV1126B平台。部分支持RV1103RV1106支持RV1109RV1126RK1808平台。1、rknn_model_zoo官网地址。

m0_60657960的博客 198

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

Android 玩机进阶:刀盾环境 ROOT 工具箱(ADB隐藏/免授权)与 Zygisk / Vector / HMA-OSS 配置教程

本文基于「刀盾环境 App」实拍,详解刷入内核后配置ROOT工具箱(含深度隐藏调试、ADB免弹授权等6大功能)及模块中心六大入口,手把手演示通过Zygisk+Vector+HMA-OSS在线安装与激活全流程,四步完成双模块部署,重启后三界面核验确保生效,助力高效实现系统级定制与风控规避。

专注安卓前沿科技 214

MySQL 基本查询(下)

注意:8.0 的窗口函数在 5.7 中没有直接等价写法,通常要用自连接或用户变量模拟,迁移成本较高,需单独评估。注意:下面所涉及到的SQL代码都是兼容5.7版本,其字符集和校验规则是兼容5.7和8.0的写法。是原子操作,新旧表在一条语句内完成替换,避免“先删后插”中途失败导致数据不一致。CRUD 的操作对象是表,所以先给出完整、可直接执行的建表脚本。聚合,是为了满足 5.7/8.0 默认开启的。案例:删除表中的重复记录,重复数据只保留一份。作用:对查询到的结果进行列值更新。的查询结果直接插入到目标表中。

qq_73640809的博客 225

侧载 APK 后台服务起不来排查:Android 14 foregroundServiceType 与前台服务类型权限

有一类闪退很有迷惑性:应用能装、能打开、主界面一切正常,但只要点「开始录音」「后台同步」「开启导航」「投屏」「连接手表」,立刻闪退或者功能静默失效。卸载重装、清缓存、换下载源都没用。看日志才会发现,崩的不是界面代码,而是系统把一次前台服务(Foreground Service,简称 FGS)启动拦下来了。这个问题在侧载 APK 上格外高发,原因有三个:一是侧载包的常常比商店版旧,或者被改包者动过;二是 Android 14 起系统对 FGS 的类型声明与权限做了强校验,改包时删掉一行就会直接崩;

qq362196705的专栏 145
上一篇: RFC 1180 - TCP/IP tutorial 学习笔记
下一篇: ramfs, rootfs &amp; initramfs
CodeJoker
博客等级 码龄18年 50粉丝 37原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址