Android 10 新建test分区--------以高通平台为例
记录下近期新建分区相关的学习内容
1. 新建test分区修改代码路径
1、amss/commom/config/ufs/external/partition.xml //修改分区表
2、amss/common/contents.xml //属性配置
3、android/device/qcom/kona/fstab.qcom //文件系统
4、android/device/qcom/kona/BoardConfig.mk //底板配置:分区表大小
5、android/system/core/rootdir/Android.mk //打包镜像
6、android/system/sepolicy/prebuilts/api/29.0/private/file_contexts //android 10对应29,可通过命令查看,后文会详细说明
7、android/system/sepolicy/private/file_contexts //6、7两者要对应
8、android/device/qcom/common/generate_extra_images.mk //生成镜像文件
9、amss/commom/build/app/gen_buildflavor.cmm //AA--AB,未修改 默认为AB
2. 具体修改
1、amss/commom/config/ufs/external/partition.xml //修改分区表
<partition label="test" size_in_kb="16384" type=" xxx" bootable="false" readonly="false" filename="test.img" sparse="true"/>
//"xxx"是UUID,地位类似于身份证,可以在任意目录下输入uuidgen获得
amss/common/build/ufs/patch0.xml
amss/common/build/ufs/rawprogram0.xml
这两个路径下的内容会因为partition.xml的修改而变化,但是我在新建分区的时候也手动进行了下列的修改,这地方没太搞明白,不知道没改行不行
amss/common/build/ufs/patch0.xml:
-<patch SECTOR_SIZE_IN_BYTES="4096" byte_offset="1832" filename="gpt_main0.bin" physical_partition_number="0" size_in_bytes="8" start_sector="2" value="NUM_DISK_SECTORS-6." what="Updata last partition 15 'userdata' with actual size in Primary Header."/>
-<patch SECTOR_SIZE_IN_BYTES="4096" byte_offset="1832" filename="DISK" physical_partition_number="0" size_in_bytes="8" start_sector="2" value="NUM_DISK_SECTORS-6." what="Updata last partition 15 'userdata' with actual size in Primary Header."/>
-<patch SECTOR_SIZE_IN_BYTES="4096" byte_offset="1832" filename="gpt_backup.bin" physical_partition_number="0" size_in_bytes="8" start_sector="0" value="NUM_DISK_SECTORS-6." what="Updata last partition 15 'userdata' with actual size in Backup Header."/>
-<patch SECTOR_SIZE_IN_BYTES="4096" byte_offset="1832" filename="DISK" physical_partition_number="0" size_in_bytes="8" start_sector="NUM_DISK_SECTORS-5" value="NUM_DISK_SECTORS-6." what="Updata last partition 15 'userdata' with actual size in Backup Header."/>
+<patch SECTOR_SIZE_IN_BYTES="4096" byte_offset="1960" filename="gpt_main0.bin" physical_partition_number="0" size_in_bytes="8" start_sector="2" value="NUM_DISK_SECTORS-6." what="Updata last partition 16 'userdata' with actual size in Primary Header."/>
+<patch SECTOR_SIZE_IN_BYTES="4096" byte_offset="1960" filename="DISK" physical_partition_number="0" size_in_bytes="8" start_sector="2" value="NUM_DISK_SECTORS-6." what="Updata last partition 16 'userdata' with actual size in Primary Header."/>
+<patch SECTOR_SIZE_IN_BYTES="4096" byte_offset="1960" filename="gpt_backup.bin" physical_partition_number="0" size_in_bytes="8" start_sector="0" value="NUM_DISK_SECTORS-6." what="Updata last partition 16 'userdata' with actual size in Backup Header."/>
+<patch SECTOR_SIZE_IN_BYTES="4096" byte_offset="1960" filename="DISK" physical_partition_number="0" size_in_bytes="8" start_sector="NUM_DISK_SECTORS-5" value="NUM_DISK_SECTORS-6." what="Updata last partition 16 'userdata' with actual size in Backup Header."/>
amss/common/build/ufs/rawprogram0.xml:
-<program SECTOR_SIZE_IN_bytes="4096" file_sector_offset="0" filename="" label="vm-system_a" num_partition_sector="32768" partofsingleimage="false" physical_partition_number="0" readbackverify="false" size_in_KB="131072.0" sparse="false" start_byte_hex="0x30fa28000" start_sector="3209768"/>
-<program SECTOR_SIZE_IN_bytes="4096" file_sector_offset="0" filename="" label="vm-system_b" num_partition_sector="32768" partofsingleimage="false" physical_partition_number="0" readbackverify="false" size_in_KB="131072.0" sparse="false" start_byte_hex="0x317a28000" start_sector="3242536"/>
-<program SECTOR_SIZE_IN_bytes="4096" file_sector_offset="0" filename="" label="rawdump" num_partition_sector="32768" partofsingleimage="false" physical_partition_number="0" readbackverify="false" size_in_KB="131072.0" sparse="false" start_byte_hex="0x31fa28000" start_sector="3275304"/>
-<program SECTOR_SIZE_IN_bytes="4096" file_sector_offset="0" filename="userdata.img" label="userdata" num_partition_sector="0" partofsingleimage="false" physical_partition_number="0" readbackverify="false" size_in_KB="0" sparse="true" start_byte_hex="0x327a28000" start_sector="3308072"/>
+<program SECTOR_SIZE_IN_bytes="4096" file_sector_offset="0" filename="test.img" label="test" num_partition_sector="4096" partofsingleimage="false" physical_partition_number="0" readbackverify="false" size_in_KB="131072.0" sparse="false" start_byte_hex="0x30fa28000" start_sector="3209768"/>
+<program SECTOR_SIZE_IN_bytes="4096" file_sector_offset="0" filename="" label="vm-system_a" num_partition_sector="32768" partofsingleimage="false" physical_partition_number="0" readbackverify="false" size_in_KB="131072.0" sparse="false" start_byte_hex="0x310a28000" start_sector="3213864"/>
+<program SECTOR_SIZE_IN_bytes="4096" file_sector_offset="0" filename="" label="vm-system_b" num_partition_sector="32768" partofsingleimage="false" physical_partition_number="0" readbackverify="false" size_in_KB="131072.0" sparse="false" start_byte_hex="0x318a28000" start_sector="3246632"/>
+<program SECTOR_SIZE_IN_bytes="4096" file_sector_offset="0" filename="" label="rawdump" num_partition_sector="32768" partofsingleimage="false" physical_partition_number="0" readbackverify="false" size_in_KB="131072.0" sparse="false" start_byte_hex="0x320a28000" start_sector="3279400"/>
+<program SECTOR_SIZE_IN_bytes="4096" file_sector_offset="0" filename=userdata.img" label="userdata" num_partition_sector="0" partofsingleimage="false" physical_partition_number="0" readbackverify="false" size_in_KB="0" sparse="true" start_byte_hex="0x328a28000" start_sector="3312168"/>
2、amss/common/contents.xml //属性配置
<download_file sparse_image_path="true" minimized="true" fastboot="true">
<file_name>test.img</file_name>
<file_path>out/target/product/kona/</file_path> //生成test.img镜像路径
</download_file>
3、android/device/qcom/kona/fstab.qcom //文件系统
/dev/block/by_name/test /test /ext4 noatime,nosuid,nodev,discard wait
fstab相关参数说明:http://blog.csdn.net/weixin_43025343/article/details/123640480
4、android/device/qcom/kona/BoardConfig.mk //底板配置:分区表大小
BOARD_TESTIMAGE_PARTITION_SIZE := 16384
BOARD_TESTIMAGE_FILE_SYSTEM_TYPE := ext4
5、android/system/core/rootdir/Android.mk //打包镜像
For /test partition
LOCAL_POST_INSTALL_CMD += ; mkdir -P $(TARGET_BOOT_OUT)/test
6、android/system/sepolicy/prebuilts/api/29.0/private/file_contexts //android 10对应29,可通过命令查看,后文会详细说明
/test u:object_r:system_data_file:s0
7、android/system/sepolicy/private/file_contexts //6、7两者要对应
/test u:object_r:system_data_file:s0
查询当前Android版本:
方式1:代码编译过,通过find -name bulid.prop查找,在目录android/out/dist下,通过vim搜索命令可得 /version.sdk=29,version.release=10
方式2:代码未编译,在目录android/bulild/core/version_defaults.mk
PLATFORM_SDK_VERSION := 29
方式3:代码下到板子里通过adb命令获取版本信息:
add shell
getprop | prep -rn version
//获取版本信息
adb root
adb shell cat sys/class/power_supply/battery/capacity
//顺便记下通过adb命令查看电池容量
说明:全部的编译产物都位于/out目录下 build生成的镜像文件:system.img;ramdisk.img;userdata.img位于/out/target/product/目录下
7、android/system/sepolicy/private/file_contexts //6、7两者要对应
/test u:object_r:system_data_file:s0
8、amss/device/qcom/common/generate_extra_images.mk //生成镜像文件
ifneq ($(strip $(BOARD_TESTIMG_PARTITION_SIZE)),)
TARGET_OUT_METADATA := $(PRODUCT_OUT)/test
INSTALLED_METADATAIMAGE_TARGET := $(PRODUCT_OUT)/test.img
define build-testimage-target
$(call pretty,"Target testdata fs image: $(INSTALLED_METADATAIMAGE_TARGET)")
@mkdir -p $(TARGET_OUT_METADATA)
$(hide)PATH=$(HOST_OUT_EXECUTABLES):$${PATH} $(MKEXUSEIMG) -s $(TARGET_OUT_METADATA) $@ ext4 test $(BOARD_TESTDATAIMAGE_PARTITION_SIZE)
$(hide) chmod a+r $@
endef
$(INSTALLED_METADATAIMAGE_TARGET): $(MKEXTUSERIMG) $(MAKE_EXT4FS)
->$(build-metadataimage-target)
ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_METADATAIMAGE_TARGET)
ALL_MODULES $(LOCAL_MODULE).INSTALLED += $(INSTALLED_METADATAIMAGE_TARGET)
droidcore: $(INSTALLED_MATADATAIMAGE_TARGET)
.PHONY: metadataimage
metadataimage: $(INSTALLED_METADATAIMAGE_TARGET)
endif
3. 查看新建分区挂载与逻辑梳理
3.1 查看新建分区挂载
adb root
adb shell
df -h //如果看到test分区说明test分区新建并挂载成功
3.2 逻辑梳理
(1)分区表改完后需要将修改的分区表刷入,有两种刷入方式:
(a)fastboot刷机跟新分区表需要刷amss/common/build/ufs/gpt_both0、botth1…等文件
(b)qfil刷机跟新分区表需要刷amss/common/build/ufs/rawprogram0.xml、1.xml…等文件
说明:关于fastboot和qfile刷机。fastboot一般较为通用,Google官方提供,qfil为高通提供
qfil刷机不能刷大包,刷一些大分区如userdata等需要拆包(partition.xml中sparse="true",
表示拆包),qfil默认刷A分区可以修改成AB分区都刷
(2)编译生成test.img----out目录下
(3)刷机包----需要把test.img复制到一个路径下用于刷机
(4)刷机脚本
(5)启动挂载
(6)分区添加内容、相应的权限
总结: BSP需要沉淀----继续学习