当前位置:   article > 正文

[高通MSM8909][Android7.1]新增并挂载custom分区_android custom分区

android custom分区

开发平台基本信息

芯片: 高通MSM8909
版本: Android 7.1
kernel: msm-3.18

问题描述

作为一个智能硬件定制设备厂商,往往会有一个产品供应给不同客户的情况;那如果一个客户提供一个固件的话,对于系统人员的工作量会很大;所以,比较好的解决方案就是在系统中将各个客户的定制需求都实现,然后,在系统中新创建一个分区用户存放客户定制的信息,系统通过加载分区内的配置文件,对应加载客户定制的功能。
Android原生其实就有这么一个分区,oem分区,默认就会挂载这个分区。所以,我们可以参考一下,创建一个custom分区,用来存放一些定制信息。

解决方法

1.调整分区大小

新建的custom分区,其实是从userdata分区里面划分出来,所以,要从userdata分区大小中减去分出来的custom分区,我这边新建的custom分区是200M,对应mk文件的大小就是:20010241024=209715200。具体修改如下:

--- a/device/qcom/msm8909/BoardConfig.mk
+++ b/device/qcom/msm8909/BoardConfig.mk
@@ -103,10 +103,11 @@ BOARD_BOOTIMAGE_PARTITION_SIZE := 0x02000000
 BOARD_RECOVERYIMAGE_PARTITION_SIZE := 0x02000000
 BOARD_SYSTEMIMAGE_PARTITION_SIZE := 1288491008
 #BOARD_USERDATAIMAGE_PARTITION_SIZE := 4990155776 #5191482368 #1659305984
-BOARD_USERDATAIMAGE_PARTITION_SIZE := 4860132352 #4989991936 #(4811759-65536)*1024  #3918852608  #4990155776-160*1024*1024 #5191482368 #1659305984 #4990155776-160*1024
+BOARD_USERDATAIMAGE_PARTITION_SIZE := 4650417152 #4989991936 #(4811759-65536)*1024  #3918852608  #4990155776-160*1024*1024 #5191482368 #1659305984 #4990155776-160*1024
 BOARD_CACHEIMAGE_PARTITION_SIZE := 268435456
 BOARD_PERSISTIMAGE_PARTITION_SIZE := 33554432
 BOARD_OEMIMAGE_PARTITION_SIZE := 268435456
+BOARD_CUSTOM_PARTITION_SIZE := 209715200
 BOARD_FLASH_BLOCK_SIZE := 131072 # (BOARD_KERNEL_PAGESIZE * 64)

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

2.挂载分区并给分区权限

挂载分区在fstab里面加也行,在rc文件里面,按照oem分区的那种方式挂载也行;授权的话,也可以在init.rc里面加,都差不多,只不过是先挂载跟后挂载的区别而已。

diff --git a/device/qcom/msm8909/fstab.qcom b/device/qcom/msm8909/fstab.qcom
index 873b580..512250a 100755
--- a/device/qcom/msm8909/fstab.qcom
+++ b/device/qcom/msm8909/fstab.qcom
@@ -14,3 +14,4 @@
 
 #mount one u disk without usb hub
 /devices/platform/msm_hsusb_host/usb1/1-1/*            /storage/usbotg         vfat    nosuid,nodev    wait,voldmanaged=usbotg:auto,noemulatedsd
+/dev/block/bootdevice/by-name/custom       /custom    ext4    nosuid,nodev  wait
\ No newline at end of file
diff --git a/device/qcom/msm8909/init.target.rc b/device/qcom/msm8909/init.target.rc
index 480acff..f75acf5 100755
--- a/device/qcom/msm8909/init.target.rc
+++ b/device/qcom/msm8909/init.target.rc
@@ -51,6 +51,10 @@ on fs
     mkdir /persist/data 0700 system system
     restorecon_recursive /persist
 
+       chown root system /custom
+    chmod 0777 /custom
+    restorecon_recursive /custom
+
     wait /dev/block/bootdevice/by-name/modem
     mount vfat /dev/block/bootdevice/by-name/modem /firmware ro context=u:object_r:firmware_file:s0,shortname=lower,uid=1000,gid=1000,dmask=227,fmask=337
     #write /sys/kernel/boot_adsp/boot 1

diff --git a/system/core/rootdir/Android.mk b/system/core/rootdir/Android.mk
old mode 100644
new mode 100755
index 7d0c87d..c022151
--- a/system/core/rootdir/Android.mk
+++ b/system/core/rootdir/Android.mk
@@ -149,6 +149,9 @@ ifeq ($(AB_OTA_UPDATER),true)
   LOCAL_POST_INSTALL_CMD += ; mkdir -p $(TARGET_ROOT_OUT)/postinstall
 endif
 
+#custom
+LOCAL_POST_INSTALL_CMD += ; mkdir -p $(TARGET_ROOT_OUT)/custom
+


  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41

3.修改烧录的xml

这一步非常关键,一定要用当前系统使用的prebuilt包去修改制作,不然的话,会出现一直卡在开机动画的情况。如果卡在开机动画,可以通过adb shell,看看新增的分区是否已经挂载上了,如果是,那大概率就是挂载的分区大小跟分区表对不上。修改方法,就是修改prebuilt包中的partition.xml,同样的,将userdata分区大小减去custom分区大小,然后再重新生成patch0.xml跟rawprogram0.xml,然后将新生成的两个文件替换打包脚本里面的文件即可。

	<partition label="userdata" size_in_kb="1832960" type="1B81E7E6-F50D-419B-A739-2AEEF8DA3335" bootable="false" readonly="false" filename="userdata.img" sparse="true"/>
	<partition label="custom" size_in_kb="204800" type="1B81E7E6-F50D-419B-A739-2AEEF8DA3336" bootable="false" readonly="false" filename="custom.img" sparse="false"/>
  • 1
  • 2

注:prebuilt包一般是芯片供应商提供的。partition.xml里面分区大小的单位是kb,所以custom分区就是:200*1024=204800。custom分区里面的type我是直接复制oem分区的,关系不是很大。

4.更新后的分区表

通过步骤3生成新的分区表xml,这边是我新生成的分区表差异,可以参考一下,一般只改变patch0.xml跟rawprogram0.xml

diff --git a/prebuilt/images/patch0.xml b/prebuilt/images/patch0.xml
index dede4b2..9ddb187 100755
--- a/prebuilt/images/patch0.xml
+++ b/prebuilt/images/patch0.xml
@@ -3,10 +3,10 @@
   <!--NOTE: This is an ** Autogenerated file **-->
   <!--NOTE: Patching is in little endian format, i.e. 0xAABBCCDD will look like DD CC BB AA in the file or on disk-->
   <!--NOTE: This file is used by Trace32 - So make sure to add decimals, i.e. 0x10-10=0, *but* 0x10-10.=6.-->
-  <patch SECTOR_SIZE_IN_BYTES="512" byte_offset="40" filename="gpt_main0.bin" physical_partition_number="0" size_in_bytes="8" start_sector="10" value="NUM_DISK_SECTORS-34." what="Update last partition 33 'us
erdata' with actual size in Primary Header."/>
-  <patch SECTOR_SIZE_IN_BYTES="512" byte_offset="40" filename="DISK" physical_partition_number="0" size_in_bytes="8" start_sector="10" value="NUM_DISK_SECTORS-34." what="Update last partition 33 'userdata' w
ith actual size in Primary Header."/>
-  <patch SECTOR_SIZE_IN_BYTES="512" byte_offset="40" filename="gpt_backup0.bin" physical_partition_number="0" size_in_bytes="8" start_sector="8" value="NUM_DISK_SECTORS-34." what="Update last partition 33 'u
serdata' with actual size in Backup Header."/>
-  <patch SECTOR_SIZE_IN_BYTES="512" byte_offset="40" filename="DISK" physical_partition_number="0" size_in_bytes="8" start_sector="NUM_DISK_SECTORS-25." value="NUM_DISK_SECTORS-34." what="Update last partiti
on 33 'userdata' with actual size in Backup Header."/>
+  <patch SECTOR_SIZE_IN_BYTES="512" byte_offset="168" filename="gpt_main0.bin" physical_partition_number="0" size_in_bytes="8" start_sector="10" value="NUM_DISK_SECTORS-34." what="Update last partition 34 'p
rivdata' with actual size in Primary Header."/>^M
+  <patch SECTOR_SIZE_IN_BYTES="512" byte_offset="168" filename="DISK" physical_partition_number="0" size_in_bytes="8" start_sector="10" value="NUM_DISK_SECTORS-34." what="Update last partition 34 'privdata' 
with actual size in Primary Header."/>^M
+  <patch SECTOR_SIZE_IN_BYTES="512" byte_offset="168" filename="gpt_backup0.bin" physical_partition_number="0" size_in_bytes="8" start_sector="8" value="NUM_DISK_SECTORS-34." what="Update last partition 34 '
privdata' with actual size in Backup Header."/>^M
+  <patch SECTOR_SIZE_IN_BYTES="512" byte_offset="168" filename="DISK" physical_partition_number="0" size_in_bytes="8" start_sector="NUM_DISK_SECTORS-25." value="NUM_DISK_SECTORS-34." what="Update last partit
ion 34 'privdata' with actual size in Backup Header."/>^M
   <patch SECTOR_SIZE_IN_BYTES="512" byte_offset="48" filename="gpt_main0.bin" physical_partition_number="0" size_in_bytes="8" start_sector="1" value="NUM_DISK_SECTORS-34." what="Update Primary Header with La
stUseableLBA."/>
   <patch SECTOR_SIZE_IN_BYTES="512" byte_offset="48" filename="DISK" physical_partition_number="0" size_in_bytes="8" start_sector="1" value="NUM_DISK_SECTORS-34." what="Update Primary Header with LastUseable
LBA."/>
   <patch SECTOR_SIZE_IN_BYTES="512" byte_offset="48" filename="gpt_backup0.bin" physical_partition_number="0" size_in_bytes="8" start_sector="32" value="NUM_DISK_SECTORS-34." what="Update Backup Header with 
LastUseableLBA."/>
diff --git a/prebuilt/rawprogram_full.xml b/prebuilt/rawprogram_full.xml
index e860ada..f3787b6 100755
--- a/prebuilt/rawprogram_full.xml
+++ b/prebuilt/rawprogram_full.xml
@@ -23,18 +23,19 @@
   <program SECTOR_SIZE_IN_BYTES="512" file_sector_offset="0" filename="" label="reserve4" num_partition_sectors="32768" physical_partition_number="0" size_in_KB="16384.0" sparse="false" start_byte_hex="0xa15
00000L" start_sector="5285888"/>
-  <program SECTOR_SIZE_IN_BYTES="512" file_sector_offset="0" filename="userdata.img" label="userdata" num_partition_sectors="0" physical_partition_number="0" size_in_KB="0" sparse="true" start_byte_hex="0xa2
500000L" start_sector="5318656"/>
+  <program SECTOR_SIZE_IN_BYTES="512" file_sector_offset="0" filename="userdata.img" label="userdata" num_partition_sectors="9082846" physical_partition_number="0" size_in_KB="4541423.0" sparse="true" start_
byte_hex="0xa2500000L" start_sector="5318656"/>^M
+  <program SECTOR_SIZE_IN_BYTES="512" file_sector_offset="0" filename="custom.img" label="custom" num_partition_sectors="0" physical_partition_number="0" size_in_KB="0" sparse="false" start_byte_hex="0x1
b77fbc00L" start_sector="14401502"/>^M
   <program SECTOR_SIZE_IN_BYTES="512" file_sector_offset="0" filename="gpt_main0.bin" label="PrimaryGPT" num_partition_sectors="34" physical_partition_number="0" size_in_KB="17.0" sparse="false" start_byte_h
ex="0x0" start_sector="0"/>
   <program SECTOR_SIZE_IN_BYTES="512" file_sector_offset="0" filename="gpt_backup0.bin" label="BackupGPT" num_partition_sectors="33" physical_partition_number="0" size_in_KB="16.5" sparse="false" start_byte_
hex="(512*NUM_DISK_SECTORS)-16896." start_sector="NUM_DISK_SECTORS-33."/>
 </data>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/445155
推荐阅读
相关标签
  

闽ICP备14008679号