android R ext4 image打包脚本介绍

一、Android R打包指令使用介绍

(1)mkuserimg_mke2fs

#./mkuserimg_mke2fs --help
usage: mkuserimg_mke2fs [-h] [--android_sparse] [--journal_size JOURNAL_SIZE]
                        [--timestamp TIMESTAMP] [--fs_config FS_CONFIG]
                        [--product_out PRODUCT_OUT]
                        [--block_list_file BLOCK_LIST_FILE]
                        [--base_alloc_file_in BASE_ALLOC_FILE_IN]
                        [--base_alloc_file_out BASE_ALLOC_FILE_OUT]
                        [--label LABEL] [--inodes INODES]
                        [--inode_size INODE_SIZE]
                        [--reserved_percent RESERVED_PERCENT]
                        [--flash_erase_block_size FLASH_ERASE_BLOCK_SIZE]
                        [--flash_logical_block_size FLASH_LOGICAL_BLOCK_SIZE]
                        [--mke2fs_uuid MKE2FS_UUID]
                        [--mke2fs_hash_seed MKE2FS_HASH_SEED]
                        [--share_dup_blocks]
                        src_dir output_file {ext2,ext4} mount_point fs_size
                        [file_contexts]

positional arguments:
  src_dir               The source directory for user image.
  output_file           The path of the output image file.
  {ext2,ext4}           Variant of the extended filesystem.
  mount_point           The mount point for user image.
  fs_size               Size of the file system.
  file_contexts         The selinux file context.

optional arguments:
  -h, --help            show this help message and exit
  --android_sparse, -s  Outputs an android sparse image (mke2fs).
  --journal_size JOURNAL_SIZE, -j JOURNAL_SIZE
                        Journal size (mke2fs).
  --timestamp TIMESTAMP, -T TIMESTAMP
                        Fake timetamp for the output image.
  --fs_config FS_CONFIG, -C FS_CONFIG
                        Path to the fs config file (e2fsdroid).
  --product_out PRODUCT_OUT, -D PRODUCT_OUT
                        Path to the directory with device specific fs config
                        files (e2fsdroid).
  --block_list_file BLOCK_LIST_FILE, -B BLOCK_LIST_FILE
                        Path to the block list file (e2fsdroid).
  --base_alloc_file_in BASE_ALLOC_FILE_IN, -d BASE_ALLOC_FILE_IN
                        Path to the input base fs file (e2fsdroid).
  --base_alloc_file_out BASE_ALLOC_FILE_OUT, -A BASE_ALLOC_FILE_OUT
                        Path to the output base fs file (e2fsdroid).
  --label LABEL, -L LABEL
                        The mount point (mke2fs).
  --inodes INODES, -i INODES
                        The extfs inodes count (mke2fs).
  --inode_size INODE_SIZE, -I INODE_SIZE
                        The extfs inode size (mke2fs).
  --reserved_percent RESERVED_PERCENT, -M RESERVED_PERCENT
                        The reserved blocks percentage (mke2fs).
  --flash_erase_block_size FLASH_ERASE_BLOCK_SIZE, -e FLASH_ERASE_BLOCK_SIZE
                        The flash erase block size (mke2fs).
  --flash_logical_block_size FLASH_LOGICAL_BLOCK_SIZE, -o FLASH_LOGICAL_BLOCK_SIZE
                        The flash logical block size (mke2fs).
  --mke2fs_uuid MKE2FS_UUID, -U MKE2FS_UUID
                        The mke2fs uuid (mke2fs) .
  --mke2fs_hash_seed MKE2FS_HASH_SEED, -S MKE2FS_HASH_SEED
                        The mke2fs hash seed (mke2fs).
  --share_dup_blocks, -c
                        ext4 share dup blocks (e2fsdroid).

(2)mke2fs

#./mke2fs
Usage: mke2fs [-c|-l filename] [-b block-size] [-C cluster-size]
        [-i bytes-per-inode] [-I inode-size] [-J journal-options]
        [-G flex-group-size] [-N number-of-inodes] [-d root-directory]
        [-m reserved-blocks-percentage] [-o creator-os]
        [-g blocks-per-group] [-L volume-label] [-M last-mounted-directory]
        [-O feature[,...]] [-r fs-revision] [-E extended-option[,...]]
        [-t fs-type] [-T usage-type ] [-U UUID] [-e errors_behavior][-z undo_file]
        [-jnqvDFSV] device [blocks-count]

(3)mke2fs使用举例

./mke2fs -L lcfg_L -M /lcfg -E android_sparse -t ext4 -b 4096 lcfg_new.img 4096

参数解释:
-L lcfg_L  指定文件系统lable

-M /lcfg   指定文件系统挂载点,新的android系统可能必须指定,否则可能不开机

-E android_sparse  使用android稀疏文件系统

-t ext4 指定文件系统类型

-b 4096 指定block size为4K

lcfg_new.img 打包后的文件名

最后的4096为文件系统占用多少个block,即大小为4096个block,16MB

-d 指定打包的路径,不指定则打包一个空文件系统

./mke2fs -d ../mnt/ -L lcfg_L -M /lcfg -E android_sparse -t ext4 -b 4096 lcfg_new.img 4096

0x460地址的53EF对应ext4文件系统,0x4A0地址存储的lable name,0x4B0地址存储的挂载点名字。

(5)mkuserimg_mke2fs使用举例

#./mkuserimg_mke2fs -s -L lcfg_L ../mnt/ lcfg_new.img ext4 lcfg 16777216
10:48:38 mkuserimg_mke2fs.py INFO: Env: {'MKE2FS_CONFIG': '/tmp/tmpIS3W7w'}
10:48:38 mkuserimg_mke2fs.py INFO: Running: mke2fs -L lcfg_L -M /lcfg -E android_sparse -t ext4 -b 4096 lcfg_new.img 4096
mke2fs 1.45.5 (07-Jan-2020)
lcfg_new.img: Unimplemented ext2 library function while setting up superblock

10:48:38 mkuserimg_mke2fs.py ERROR: Failed to run mke2fs: mke2fs 1.45.5 (07-Jan-2020)
lcfg_new.img: Unimplemented ext2 library function while setting up superblock

发现使用这个脚本打包会报Unimplemented ext2 library function while setting up superblock的错误,查询网上信息均不能解决此问题。android编译log里执行是没有报错的,暂时原因未知。由此脚本输出log可以确认实际调用的还是mke2fs这个命令。

以下是android编译log这个命令的调用输出:

mkuserimg_mke2fs -s /data/aosp/out/soong/.temp/tmpB5DBG3 /data/aosp/out/target/product/${product}/obj/PACKAGING/target_files_intermediates/${product}_-target_files-eng.${username}/IMAGES/system.img ext4 / 1561997312 -j 0 -T 1230768000 -C /data/aosp/out/soong/.temp/merged_fs_configiM8m_z.txt -B /data/aosp/out/target/product/${product}/obj/PACKAGING/target_files_intermediates/${product}-target_files-eng.${username}/IMAGES/system.map -L / -i 4287 -M 0 -U 2735b6e1-a757-5a14-9bef-47754fd50ded -S 700f0123-0f4b-5b89-9162-47d96902e561 --inode_size 256 /data/aosp/out/target/product/${product}/obj/PACKAGING/target_files_intermediates/${product}-target_files-eng.${username}/META/file_contexts.bin


输出:

mke2fs -O ^has_journal -L / -N 4287 -I 256 -M / -m 0 -U 2735b6e1-a757-5a14-9bef-47754fd50ded -E android_sparse,hash_seed=700f0123-0f4b-5b89-9162-47d96902e561 -t ext4 -b 4096 /data/aosp/out/target/product/${product}/obj/PACKAGING/target_files_intermediates/${product}-target_files-eng.${username}/IMAGES/system.img 381347



mkuserimg_mke2fs -s /data/aosp/out/target/product/${product}/obj/PACKAGING/target_files_intermediates/${product}-target_files-eng.${username}/ODM /data/aosp/out/target/product/${product}/obj/PACKAGING/target_files_intermediates/${product}-target_files-eng.${username}/IMAGES/odm.img ext4 odm 659456 -j 0 -T 1230768000 -C /data/aosp/out/target/product/${product}/obj/PACKAGING/target_files_intermediates/se1000_car-target_files-eng.${username}/META/odm_filesystem_config.txt -B /data/aosp/out/target/product/${product}/obj/PACKAGING/target_files_intermediates/${product}-target_files-eng.${username}/IMAGES/odm.map -L odm -i 24 -M 0 -U 2953e192-e67a-51ec-ba5b-d87b876e96be -S 8547b481-be54-5451-857b-c04843da04c8 --inode_size 256 /data/aosp/out/target/product/${product}/obj/PACKAGING/target_files_intermediates/${product}-target_files-eng.jiongjionglv/META/file_contexts.bin

输出:
mke2fs -O ^has_journal -L odm -N 25 -I 256 -M /odm -m 0 -U 2953e192-e67a-51ec-ba5b-d87b876e96be -E android_sparse,hash_seed=8547b481-be54-5451-857b-c04843da04c8 -t ext4 -b 4096 /data/aosp/out/target/product/${product}/obj/PACKAGING/target_files_intermediates/${product}-target_files-eng.${username}/IMAGES/odm.img 4243

(6)mkf2fsuserimg.sh 使用介绍

此脚本是用来制作f2fs格式image,比如userdata.img

./mkf2fsuserimg.sh -h
in mkf2fsuserimg.sh PATH=/usr/local/mongodb/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
Usage:
mkf2fsuserimg.sh OUTPUT_FILE SIZE
         [-S] [-C FS_CONFIG] [-f SRC_DIR] [-D PRODUCT_OUT]
         [-s FILE_CONTEXTS] [-t MOUNT_POINT] [-T TIMESTAMP]
         [-L LABEL] [--prjquota] [--casefold]

mkf2fsuserimg.sh /data/aosp/out/target/product/${product}/obj/PACKAGING/target_files_intermediates/${product}-target_files-eng.${username}/IMAGES/userdata.img 34359738368 -S -f /data/aosp/out/soong/.temp/tmpbJAfR1 -s /data/aosp/out/target/product/${product}/obj/PACKAGING/target_files_intermediates/${product}-target_files-eng.${username}/META/file_contexts.bin -t data -T 1230768000 -L data --prjquota --casefold

make_f2fs -g android -S 34359738368 -l data -O project_quota,extra_attr -O casefold -C utf8 /data/aosp/out/target/product/${product}/obj/PACKAGING/target_files_intermediates/${product}-target_files-eng.${username}/IMAGES/userdata.img

Android R 文件系统制作工具下载:https://download.csdn.net/download/u013463707/89550435

platform-tool下载地址:https://dl.google.com/android/repository/platform-tools-latest-windows.zip

https://dl.google.com/android/repository/platform-tools-latest-linux.zip

部分历史版本下载:https://gitee.com/awake558/platform-tools/tree/master

下载链接:https://dl.google.com/android/repository/platform-tools_r[版本] -[系统] .zip

版本:platform-tools的版本名称(26.0.0,33.0.0...)

系统:Windwos→windows,Mac→darwin,linux→linux

例如:https://dl.google.com/android/repository/platform-tools_r26.0.0-windows.zip

部分历史版本无法下载,版本信息参考:https://developer.android.com/studio/releases/platform-tools

参考链接:

https://blog.csdn.net/qq_45683435/article/details/104070216/

修改system.img的文件的权限和属性:使用make.ext4fs的方法_system.ext4.win-CSDN博客