1. Preparation tools
Under linux system:
1. Install tool software
sudo apt install android-sdk-libsparse-utils
2. Download make_ext4fs
make_ext4fs, system.img packaging tool under Linux-Android document resources-CSDN download
3. Basic knowledge (optional whether to read or not, go to the next step if not)
Both system.img and vendor.img exist in two formats: raw and sparse. When executed under Linux: file system.img
① One is raw ext4 image , which is often called raw image . Use file to observe it: It is characterized by a complete ext4 partition image (including many all-zero invalid padding areas), which can be mounted directly using mount , so it is relatively large. (Generally around 1G). file view
$ file system.img
system.img:Linux rev 1.0 ext4 filesystem data, UUID=da594c53-9beb-f85c-85c5-cedf76546f7a, volume name "system" (extents) (large files)
② The other is sparse ext4 image , which is often referred to as simg
, which is a very ordinary dat file. Since it describes raw ext4 sparsely, the size is relatively small (there is no invalid padding area with all zeros, generally between 300 and 500M). file view:
$ file system.img
system.img: Android sparse image, version: 1.0, Total of 393216 4096-byte output blocks in 40 input chunks.
Android itself provides source code tools to convert between the two. The source code is located at :
system/core/libsparse/simg2img.c // Convert sparse image to raw image;
system/core/libsparse/img2simg.c // Convert raw image converted to sparse image;
2. Unpack system.img
//解包
$ sudo simg2img system.img system.img.ext4
//创建一个目录
$ sudo mkdir sysmain
//将解包的ext4文件挂载到sysmain
$ sudo mount -o loop system.img.ext4 sysmain
Next you can cd to sysmain and modify the image content! ! !
3. system.img packaging
You can choose any one of the following methods
Method ①:
sudo ./make_ext4fs -l 1456M -s -a system systest.img sysmain
If the execution error " error: ext4_allocate_best_fit_partial: failed to allocate 2260 blocks, out... " is reported, please increase the size after appeal -l (but not too large, otherwise you may need to modify the flashing configuration, such as mtk's scatter.txt document!)
The image systest.img that comes out has been modified and can be renamed to system.img. If the device does not have safe boot, it will start successfully!
Method ②:
$ sudo umount sysmain
$ sudo img2simg system.img.ext4 systest.img
Finish! Method ② is also applicable to the modification of userdata.img! ! Effective in personal testing
similar to vendor.img
-----------
ps 1: For mtk, the flash tool is SP_Flash_Tool
ps 2: Secure boot only performs signature verification on read-only partitions
------------------------------------------------------------------
boot.img packaging and unpacking
You need to download the tool first:
https://download.csdn.net/download/ab6326795/87364050?spm=1001.2014.3001.5501
Instructions for use:
1. Use AIK to repack boot.img.
Copy the boot.img in the flash package to the AIK-Linux directory, execute ./unpackimg.sh to unpack, delete the ./split_img/boot.img-zImage file, and then Copy the Image.gz-dtb file to the ./split_img directory and rename it to boot.img-zImage.
Execute ./repackimg.sh to generate the image-new.img file, which is the boot.img file that we can flash.
2. If AIK encounters "unrecognized format. error!" or "ramdisk" problems,
then use mb. This thing seems to require MINGW. I couldn't run it in cmd, but it ran successfully in MINGW! !
unpack:
./mb.exe unpack /d/WPSSoftware/test/boot.img
repack:
./mb.exe repack /d/WPSSoftware/test/boot.img