1. 程式人生 > >除錯Android之system.img的來回切換。

除錯Android之system.img的來回切換。

同事讀啟動log資訊,認為是系統掛載出問題了,在網上搜了一寫,對system.img的處理。

從一篇網文開始

step1

sdat2img.py <transfer_list> <system_new_file> <system_ext4>

- <transfer_list> = input, system.transfer.list from rom zip
- <system_new_file> = input, system.new.dat from rom zip
- <system_ext4> = output ext4 raw image file

and a quick example:

sdat2img.py system.transfer.list system.new.dat system.img

by running this command you will get as output the file my_new_system.img which is the raw ext4 image.

但第一步當時並不會做,因為兩個inout檔案沒見到過,直到第四步昨晚發現竟然是一個迴圈步驟,此時搜了其他命令生成了raw的檔案

/home/sun/rk3288work/RK3288_7.1_181121/out/host/linux-x86/bin/simg2img system.img system_raw.img

生成了system_raw.img

Step 2 - Decompress EXT4 (raw image) -> OUTPUT folder -> Compress EXT4 (raw image)
 

Now we need to mount or ext4 raw image into an output folder so we can see apks/jars etc.
To do this we need to type this command:

sudo mount -t ext4 -o loop system.img output/

As you can see there is a new folder called output which we can edit/modify/delete your files (not able to? see here)

Now we need to compress it back to a raw ext4 image, to do this we need the make_ext4fs binary. Make sure you have the file_contexts file (taken from the Rom zip) inside the make_ext4fs path. Then type this (got issues? see here)

./make_ext4fs -T 0 -S file_contexts -l 1073741824 -a system system_new.img output/

You will get the new raw ext4 image called 'system_new.img' ready for the next step.

這一步吧第一步生成的檔案掛載後,又用make_ext4fs打包了output資料夾下掛載的系統

做的步驟

[email protected]:/home/sun/rk3288work/RK3288_7.1_181121/rockdev/Image-rk3288# mkdir output

[email protected]:/home/sun/rk3288work/RK3288_7.1_181121/rockdev/Image-rk3288# cd output/

[email protected]:/home/sun/rk3288work/RK3288_7.1_181121/rockdev/Image-rk3288# mount -t ext4 -o loop ../system_raw.img ./

[email protected]:/home/sun/rk3288work/RK3288_7.1_181121/rockdev/Image-rk3288# ../../out/host/linux-x86/bin/make_ext4fs -T 0 -S ../../out/target/product/rk3288/root/file_contexts.bin -l 2048M -a system system_2th.img output/

Step 3 - Converting = EXT4 (raw image) -> IMG (sparse image)
 

Now we need to convert the ext4 raw image into a sparse image. For this you need img2simg binary you can find here (thx to @A.S._id). 
The usage is simple:

img2simg <raw_image_file> <sparse_image_file>

Pretty self-explanatory, the output will be a new sparse image (.img).

做了這種操作

這個操作的img2simg命令不能用,搜了一下發現SDK中有原始碼,需要編譯執行變異的過程是

在SDK的根目錄下執行

source build/envsetup.sh

lunch  

選要變異的版本,我是14

make img2simg_host

之後這個命令就可用了

[email protected]:/home/sun/rk3288work/RK3288_7.1_181121/rockdev/Image-rk3288# ../../out/host/linux-x86/bin/img2simg system_2th.img system_3th.img

接下來做第四步

Step 4 - Converting = IMG (sparse image) -> DAT (sparse data)
 

Now we need the img2sdat binary, the usage is very simple (make sure you have python 2.7+ installed):

./img2sdat.py <system_img>

- <system_img> = name of input sparse image file (from step 3)

As you can see the output is composed by system.transfer.list, (system.patch.dat) & system.new.dat, ready to be replaced inside your Rom zip.

第四步找不到命令,就看到文章下邊有那個命令的Python程式碼

DOWNLOADs
sdat2img.py 
github.com
make_ext4fs
mega.co.nz
img2sdat.py
github.com

接下來就進去把命令克隆下來 

點選進入img2sdat.py
github.com  這個連結下,最好和之前編譯原始檔的資料夾目錄一致,比如~/rk3288work/RK3288_7.1_181121/system/core/libdata$  我在core/下新建了樂意libdata資料夾然後克隆了兩個命令文字

[email protected]:~/rk3288work/RK3288_7.1_181121/system/core/libdata$ git clone https://github.com/xpirt/img2sdat.git

[email protected]:~/rk3288work/RK3288_7.1_181121/system/core/libdata$ git clone https://github.com/xpirt/sdat2img.git

然後就直接運行了該目錄下的第四步的命令

[email protected]:/home/sun/rk3288work/RK3288_7.1_181121/rockdev/Image-rk3288# ../../system/core/libdata/img2sdat/img2sdat.py system_3th.img

生成了3個檔案

-rw-r--r--   1 root root  61K 12月 29 15:57 system.transfer.list
-rw-r--r--   1 root root    0 12月 29 15:57 system.patch.dat

-rw-r--r--   1 root root 518M 12月 29 15:57 system.new.dat

至此四步做完了,然後忽然發現還有返回的命令,就做了一下操作,做完後,發現就是第一步的操作,發現這是格式的轉換過程。

[email protected]:/home/sun/rk3288work/RK3288_7.1_181121/rockdev/Image-rk3288# ../../system/core/libdata/sdat2img/sdat2img.py system.transfer.list system.new.dat system_5th.img