[高通SDM450][Android9.0]同一套代码兼容不同的emmc

文章目录

    • 开发平台基本信息
    • 问题描述
    • 解决方法
      • 1. 如何计算userdata分区大小
      • 2. 兼容不同规格的emmc
      • 3.MTP模式显示异常

开发平台基本信息

芯片: SDM450
版本: Android 9.0
kernel: msm-4.9

问题描述

一款设备,经常会出现搭配不同内存的情况,比如2+16跟4+64,是智能硬件比较经常使用的两种规格,在之前新增并挂载custom分区里有讲到,BoardConfig.mk里面userdata分区的大小就是根据计算得出来的,而不同的内存,userdata分区大小肯定是不同的,如果在4+64G的模块上,用16G的userdata分区大小,那系统设置显示的内存大小也只有16G,并且在MTP模式下,电脑显示设备内存是占满的16G,无法使用。

解决方法

从问题描述可以总结为以下三点:

  1. 如果计算userdata分区大小
  2. 不同规格的emmc,如何做兼容
  3. MTP模式下异常问题

1. 如何计算userdata分区大小

  1. ls -l /dev/block/bootdevice/by-name/ 找到userdata 对应的块设备
    [高通SDM450][Android9.0]同一套代码兼容不同的emmc_第1张图片

  2. cat /proc/partitions 找到上面的块设备
    [高通SDM450][Android9.0]同一套代码兼容不同的emmc_第2张图片

  3. 将上面找到的块设备大小填写到device/qcom/msm8953_64/BoardConfig.mk 的 BOARD_USERDATAIMAGE_PARTITION_SIZE := 9614892032 = 94264071024 - 361024*1024(预留36M空间)字段。

2. 兼容不同规格的emmc

diff --git a/system/core/fs_mgr/fs_mgr.c b/system/core/fs_mgr/fs_mgr.c
index 7a7296d..e3cf798 100755
--- a/system/core/fs_mgr/fs_mgr.c
+++ b/system/core/fs_mgr/fs_mgr.c
@@ -56,6 +56,7 @@
 #define E2FSCK_BIN      "/system/bin/e2fsck"
 #define F2FS_FSCK_BIN  "/system/bin/fsck.f2fs"
 #define MKSWAP_BIN      "/system/bin/mkswap"
+#define RESIZE2FS_BIN   "/system/bin/resize2fs"
 
 #define FSCK_LOG_FILE   "/dev/fscklogs/log"
 
@@ -163,6 +164,20 @@ static void check_fs(char *blk_device, char *fs_type, char *target)
                 ERROR("Failed trying to run %s\n", E2FSCK_BIN);
             }
         }
+	#ifndef FS_MGR_RESIZE_DISABLED
+    if (!strcmp(target, "/data")) {
+	char* resize2fs_argv[] = {RESIZE2FS_BIN, "-f", blk_device};
+		INFO("Running %s -a %s\n", RESIZE2FS_BIN, blk_device);
+        ret = android_fork_execvp_ext(ARRAY_SIZE(resize2fs_argv), resize2fs_argv,
+                                        &status, true, LOG_KLOG | LOG_FILE,
+                                        true, FSCK_LOG_FILE, NULL, 0);
+
+        if (ret < 0) {
+            /* No need to check for error in fork, we can't really handle it now */
+            ERROR("Failed trying to run %s\n",RESIZE2FS_BIN);
+        }
+    }
+#endif	
     } else if (!strcmp(fs_type, "f2fs")) {
             char *f2fs_fsck_argv[] = {
                     F2FS_FSCK_BIN,
@@ -332,11 +347,12 @@ static int mount_with_alternatives(struct fstab *fstab, int start_idx, int *end_
                      fstab->recs[i].mount_point, i, fstab->recs[i].fs_type, fstab->recs[*attempted_idx].fs_type);
                 continue;
             }
-
-            if (fstab->recs[i].fs_mgr_flags & MF_CHECK) {
+            if ((!strcmp(fstab->recs[i].mount_point, "/data"))||(fstab->recs[i].fs_mgr_flags & MF_CHECK)){
+            //if (fstab->recs[i].fs_mgr_flags & MF_CHECK) {
                 check_fs(fstab->recs[i].blk_device, fstab->recs[i].fs_type,
                          fstab->recs[i].mount_point);
             }
+
             if (!__mount(fstab->recs[i].blk_device, fstab->recs[i].mount_point, &fstab->recs[i])) {
                 *attempted_idx = i;
                 mounted = 1;
diff --git a/system/sepolicy/init.te b/system/sepolicy/init.te
index 9bc78d1..8548fbb 100644
--- a/system/sepolicy/init.te
+++ b/system/sepolicy/init.te
@@ -7,7 +7,8 @@ type init_exec, exec_type, file_type;
 
 # /dev/__null__ node created by init.
 allow init tmpfs:chr_file create_file_perms;
-
+allow init system_file:file execute_no_trans;
+allow init userdata_block_device:blk_file  rw_file_perms;
 #
 # init direct restorecon calls.
 #
@@ -25,7 +26,7 @@ allow init self:capability sys_resource;
 allow init tmpfs:file unlink;
 
 # Access pty created for fsck.
-allow init devpts:chr_file { read write open };
+allow init devpts:chr_file { ioctl read write open };
 
 # Create /dev/fscklogs files.
 allow init fscklogs:file create_file_perms;
@@ -304,7 +305,7 @@ neverallow init shell_data_file:lnk_file read;
 neverallow init app_data_file:lnk_file read;
 
 # init should never execute a program without changing to another domain.
-neverallow init { file_type fs_type }:file execute_no_trans;
+#neverallow init { file_type fs_type  }:file execute_no_trans;
 
 # Init never adds or uses services via service_manager.
 neverallow init service_manager_type:service_manager { add find };
diff --git a/device/qcom/msm8953_64/BoardConfig.mk b/device/qcom/msm8953_64/BoardConfig.mk
index 83ca655..cc7e5aa 100755
--- a/device/qcom/msm8953_64/BoardConfig.mk
+++ b/device/qcom/msm8953_64/BoardConfig.mk
@@ -51,7 +51,7 @@ TARGET_USERIMAGES_USE_EXT4 := true
 BOARD_BOOTIMAGE_PARTITION_SIZE := 0x04000000
 BOARD_RECOVERYIMAGE_PARTITION_SIZE := 0x04000000
 BOARD_SYSTEMIMAGE_PARTITION_SIZE := 3221225472
-BOARD_USERDATAIMAGE_PARTITION_SIZE := 9999220736
+BOARD_USERDATAIMAGE_PARTITION_SIZE := 1024220736
 BOARD_CACHEIMAGE_PARTITION_SIZE := 268435456
 BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE := ext4
 BOARD_PERSISTIMAGE_PARTITION_SIZE := 33554432

3.MTP模式显示异常

diff --git a/frameworks/av/media/mtp/Android.bp b/media/mtp/Android.bp
old mode 100644
new mode 100755
index 2cf9b82..196ede5
--- a/frameworks/av/media/mtp/Android.bp
+++ b/frameworks/av/media/mtp/Android.bp
@@ -51,6 +51,7 @@ cc_library_shared {
         "libbase",
         "liblog",
         "libusbhost",
+               "libcutils"
     ],
 }
 
diff --git a/frameworks/av/media/mtp/MtpStorage.cpp b/media/mtp/MtpStorage.cpp
index 557b665..5c51594 100755
--- a/frameworks/av/media/mtp/MtpStorage.cpp
+++ b/frameworks/av/media/mtp/MtpStorage.cpp
@@ -28,6 +28,8 @@
 #include <string.h>
 #include <stdio.h>
 #include <limits.h>
+#include <cutils/atomic.h>
+#include <cutils/properties.h> 
 
 namespace android {
 
@@ -66,8 +68,16 @@ uint64_t MtpStorage::getMaxCapacity() {
         if (statfs(getPath(), &stat))
             return -1;
         mMaxCapacity = (uint64_t)stat.f_blocks * (uint64_t)stat.f_bsize;
-    }  
-    return 16*gbSpace;
+    }
+       char value[PROPERTY_VALUE_MAX];
+       int largemtp = 0;
+       // 通过属性控制,MTP显示的大小是16G还是64G
+       property_get("persist.custom.large.mtp", value, "0");
+       largemtp = atoi(value); 
+       if (largemtp == 0){
+               return 16*gbSpace;
+       }else{
+               return 64*gbSpace;
+       }
 }
 
 uint64_t MtpStorage::getFreeSpace() {

你可能感兴趣的:(Android9.0,framework,Android9.0,emmc,MTP,flash)