高通平台上新增一个分区

        客户有个需求,需要增加一个100m大小的分区,用来存放客户预置的资料,并且不能被恢复出厂设置删除。针对这个需求,客户的资料肯定不能放在原有的分区里面,新增的分区,也不能挂载到原有的分区目录下,否则恢复出厂设置时,一定会被清空。这么看来,就只能在系统根目录下,新建个文件夹,并将客户分区,挂载到这个根目录上才行。因为我们用的是android9.0,在这套代码上,会有很多的权限限制,如果没有配置对,会导致各种问题,现记录如下。

1.)在device\qcom\msm8953_64\BoardConfig.mk里做如下修改

BOARD_USERDATAIMAGE_PARTITION_SIZE := 9719880090 #9824737690 对应的,要从userdata上减100m
BOARD_PERSISTIMAGE_PARTITION_SIZE := 33554432
BOARD_PERSISTIMAGE_FILE_SYSTEM_TYPE := ext4
BOARD_OEMIMAGE_PARTITION_SIZE := 268435456
BOARD_UNRECOVERABLEIMAGE_PARTITION_SIZE := 104857600 #单位为字节,换算下来就是100m

 

2.)device\qcom\msm8953_64\non_hlos\SDM450.LA.3.2.1\common\config\partition.xml

   <partition label="unrecoverable" size_in_kb="102400" type="0eadd5c1-2049-4873-8b86-0e559dfcb8c7" bootable="false" readonly=" false" filename="unrecoverable.img" sparse="true"/>
  //这里的userdata也要对应的减少100m
    <partition label="userdata" size_in_kb="2555648" type="1B81E7E6-F50D-419B-A739-2AEEF8DA3335" bootable="false" readonly="false" filename="userdata.img" sparse="true"/>

顺便说一句,在这个文件里,有一个GROW_LAST_PARTITION_TO_FILL_DISK这样的标签,当它设为true的时候,表示系统前面分剩下的空间,全部自动分到userdata.img里去。设了这个标签后的表现就是,当有些同学各分区的大小没有计算准确时,比如在16g的板子上,system.img、modem.img等除userdata.img外的所有的分区一共占了5g,理论上userdata.img就还剩9g,但是如果某个同学在这两个配置文件里,计算有误,将userdata.img的大小写成了6g,那么就还有3g给浪费了。这时下载完后第一次开机时,userdata.img分区的大小,是下载时从这些分区表里读出来的6g,还有3g空间不见了。但是如果这时恢复出厂设置的话,系统检测到GROW_LAST_PARTITION_TO_FILL_DISK这个标签为true后,会自动将剩下的3g空间也给补到userdata上。所以建议大家,这个标签都要设为true.

3.)\device\qcom\msm8953_64\fstabs-4.9\fstab_non_AB_variant.qti

  在最后增加一行:/dev/block/bootdevice/by-name/unrecoverable    /unrecoverable    ext4     defaults   defaults

4.)device\qcom\msm8953_64\msm8953_64.mk里增加一行

PRODUCT_COPY_FILES += device/qcom/msm8953_64/res/unrecoverable.img:$(PRODUCT_OUT)/unrecoverable.img

5.)device\qcom\msm8953_64\non_hlos\SDM450.LA.3.2.1\contents.xml里增加下面代码

	<download_file minimized="true" fastboot="true">
        <file_name>unrecoverable.img</file_name>
        <file_path>LINUX/android/out/target/product/msm8953_64/</file_path>
    </download_file>

6.)system\core\rootdir\Android.mk,在这里内置分区对应的目录

LOCAL_POST_INSTALL_CMD += ; mkdir -p $(TARGET_ROOT_OUT)/unrecoverable

这里非常重要,在android9.0上,selinux对系统权限限制越来越严格了,不能像之前那样,在init.rc或init.target.rc等初始化脚本里进行系统根目录的mkdir操作。也就是说,在android.9.0上,不能在系统根目录上创建文件夹了。如果要在系统根目录创建文件夹,有两个方法,一是关闭selinux,二是要将系统根目录的文件夹,像内置app那样,在编译时就给内置进去。

7.)device\qcom\sepolicy\vendor\common\file.te

type unrecoverable_data_file, file_type;//创建文件节点

8.)device\qcom\sepolicy\vendor\common\file_contexts

/unrecoverable(/.*)?        u:object_r:unrecoverable_data_file:s0//创建文件节点

9.)device\qcom\sepolicy\vendor\common\device.te

type unrecoverable_block_device,dev_type; //创建设备节点

10.)device\qcom\sepolicy\vendor\msm8953\file_contexts

/dev/block/bootdevice/by-name/unrecoverable                               u:object_r:unrecoverable_block_device:s0//创建设备节点

11.)device\qcom\sepolicy\vendor\common\adbd.te增加adb访问权限

allow adbd unrecoverable_data_file:dir { search open read write add_name create getattr setattr };
allow adbd unrecoverable_data_file:file { open read create write getattr setattr};

12.)device\qcom\sepolicy\vendor\common\init.te增加init进程的对分区设备文件的操作权限

allow init unrecoverable_block_device:blk_file rw_file_perms;
allow init unrecoverable_block_device:blk_file relabelto;

13.)device\qcom\sepolicy\vendor\common\platform_app.te

allow platform_app unrecoverable_data_file:dir { search open read write add_name create getattr setattr };
allow platform_app unrecoverable_data_file:file { open read create write getattr setattr};

14.)device\qcom\sepolicy\vendor\common\recovery.te

allow recovery unrecoverable_block_device:blk_file *;

15.)device\qcom\sepolicy\vendor\common\system_app.te

allow system_app unrecoverable_data_file:dir { search open read write add_name create getattr setattr };
allow system_app unrecoverable_data_file:file { open read create write getattr setattr};

16.)device\qcom\sepolicy\vendor\common\system_server.te

allow system_server unrecoverable_data_file:dir { search open read write add_name create getattr setattr };
allow system_server unrecoverable_data_file:file { open read create write getattr setattr};

17.)device\qcom\sepolicy\vendor\common\vold.te

allow vold unrecoverable_data_file:dir r_dir_perms;
allow vold unrecoverable_block_device:blk_file rw_file_perms;
allow vold unrecoverable_block_device:blk_file create_file_perms;
allow vold unrecoverable_data_file:dir { read getattr open ioctl };

18.)device\qcom\sepolicy\vendor\common\shell.te

r_dir_file(shell, unrecoverable_data_file)
allow shell unrecoverable_data_file:dir { search open read write add_name create getattr setattr };
allow shell unrecoverable_data_file:file { open read create write getattr setattr};

19.)device\qcom\msm8953_64\init.target.rc

    chown root root /unrecoverable
    chmod 0777 /unrecoverable
    restorecon_recursive /unrecoverable

其中,如果不做第18、19步的话,会导在user版本上,插上usb后,进入adb shell时,看不到新增加的分区。

20.)将制作好的.img文件,放到device\qcom\msm8953_64\res这个目录下。

以下是一个简单的高通8295芯片的分区代码,其中包含了一些物理分区的信息,用于控制设备的分区行为。这个代码使用了GPT分区表,其中包含了一些基本的分区,如boot、recovery、system、userdata等等。此外,代码中还包含了一些附加分区,如cache、persist、misc等等。请注意,这只是一个简单的示例,实际的分区代码可能会更复杂和详细。 ``` #define SECTOR_SIZE 512 #define PARTITION_TABLE_SIZE 34 * SECTOR_SIZE struct partition_entry { uint8_t partition_guid[16]; uint64_t starting_lba; uint64_t ending_lba; uint64_t attributes; uint16_t partition_name[36]; }; struct partition_table { uint64_t signature; uint32_t revision; uint32_t header_size; uint32_t crc32; uint32_t reserved; uint64_t current_lba; uint64_t backup_lba; uint64_t first_usable_lba; uint64_t last_usable_lba; uint8_t disk_guid[16]; uint64_t partition_entry_lba; uint32_t num_partition_entries; uint32_t sizeof_partition_entry; uint32_t partition_entry_array_crc32; struct partition_entry partition_entries[128]; }; int main() { struct partition_table gpt = {0}; gpt.signature = 0x5452415020494645ULL; gpt.revision = 0x00010000; gpt.header_size = 92; gpt.current_lba = 1; gpt.backup_lba = 65535; gpt.first_usable_lba = 34; gpt.last_usable_lba = 65502; memcpy(gpt.disk_guid, "\x8f\x00\x00\x00\x00\x00\x10\x00\x80\x00\x00\xaa\x00\x38\x9b\x71", 16); gpt.partition_entry_lba = 2; gpt.num_partition_entries = 128; gpt.sizeof_partition_entry = 128; // boot partition struct partition_entry boot = {0}; memcpy(boot.partition_guid, "\x40\x0c\x52\x6a\x8d\x4e\x4f\x5d\x84\x65\x5a\x3e\x3f\xbd\x6c\x3f", 16); boot.starting_lba = 34; boot.ending_lba = 1601; boot.attributes = 0; memcpy(boot.partition_name, L"boot", 8 * sizeof(wchar_t)); gpt.partition_entries[0] = boot; // recovery partition struct partition_entry recovery = {0}; memcpy(recovery.partition_guid, "\x9e\x6d\xc5\x8e\x3b\x3d\x4a\x4b\x9f\x6a\x92\x9d\x8b\xfa\x8a\x13", 16); recovery.starting_lba = 1602; recovery.ending_lba = 3137; recovery.attributes = 0; memcpy(recovery.partition_name, L"recovery", 16 * sizeof(wchar_t)); gpt.partition_entries[1] = recovery; // system partition struct partition_entry system = {0}; memcpy(system.partition_guid, "\x7a\x26\x8c\x2e\x5d\x91\x4c\x45\xa1\x4b\x7e\x69\xb6\x6f\x1f\x9f", 16); system.starting_lba = 3138; system.ending_lba = 44289; system.attributes = 0; memcpy(system.partition_name, L"system", 12 * sizeof(wchar_t)); gpt.partition_entries[2] = system; // userdata partition struct partition_entry userdata = {0}; memcpy(userdata.partition_guid, "\xc5\x9a\x34\xd2\x64\x4d\x4c\x4d\x80\x0b\x67\xc0\x5c\x1b\xf3\x96", 16); userdata.starting_lba = 44290; userdata.ending_lba = 65502; userdata.attributes = 0; memcpy(userdata.partition_name, L"userdata", 14 * sizeof(wchar_t)); gpt.partition_entries[3] = userdata; // cache partition struct partition_entry cache = {0}; memcpy(cache.partition_guid, "\xbf\x0a\x1b\x2e\xd2\x1d\x4c\x4f\xa6\xdb\x2a\xef\x43\x7c\xdf\x3b", 16); cache.starting_lba = 3138; cache.ending_lba = 3377; cache.attributes = 0; memcpy(cache.partition_name, L"cache", 10 * sizeof(wchar_t)); gpt.partition_entries[4] = cache; // persist partition struct partition_entry persist = {0}; memcpy(persist.partition_guid, "\x6d\x55\x8e\xea\x6f\x36\x4c\x4d\xbb\x1c\x95\x7d\x5c\x5b\x12\x45", 16); persist.starting_lba = 3378; persist.ending_lba = 3649; persist.attributes = 0; memcpy(persist.partition_name, L"persist", 12 * sizeof(wchar_t)); gpt.partition_entries[5] = persist; // misc partition struct partition_entry misc = {0}; memcpy(misc.partition_guid, "\x5d\x07\x7d\x41\x6c\x77\x4e\x4f\xa9\x5e\x9c\x7d\x5c\x5b\x12\x45", 16); misc.starting_lba = 3650; misc.ending_lba = 3777; misc.attributes = 0; memcpy(misc.partition_name, L"misc", 8 * sizeof(wchar_t)); gpt.partition_entries[6] = misc; // write partition table to disk FILE* fp = fopen("/dev/block/mmcblk0", "wb"); fwrite(&gpt, 1, PARTITION_TABLE_SIZE, fp); fclose(fp); return 0; } ```
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值