admin 发表于 2022-9-26 17:14:08

高通 SC60 SDM450 自动匹配flash 容量大小补丁

问题:
      SC60智能通信模组,Android9.0系统,同时会采购1+8和2+16的配置,但是软件上面统一都只是显示8G的ROM,如何实现同一软件自动识别EMMC容量大小并正确显示?

解决方案:
      源码补丁见附件中(移远提供补丁):
diff --git a/device/qcom/msm8953_64/fstabs-4.9/fstab_AB_variant.qti b/device/qcom/msm8953_64/fstabs-4.9/fstab_AB_variant.qti
index f750e49..a0b24bf 100644
--- a/device/qcom/msm8953_64/fstabs-4.9/fstab_AB_variant.qti
+++ b/device/qcom/msm8953_64/fstabs-4.9/fstab_AB_variant.qti
@@ -34,7 +34,7 @@

#<src>                                    <mnt_point><type><mnt_flags and options>                     <fs_mgr_flags>
/dev/block/bootdevice/by-name/system      /            ext4    ro,barrier=1,discard                        wait,slotselect,avb
-/dev/block/bootdevice/by-name/userdata      /data      ext4    noatime,nosuid,nodev,barrier=1,noauto_da_alloc,discardwait,forceencrypt=footer,quota,reservedsize=128M
+/dev/block/bootdevice/by-name/userdata      /data      ext4    noatime,nosuid,nodev,barrier=1,noauto_da_alloc,discard,resize wait,forceencrypt=footer,quota,reservedsize=128M
/devices/platform/soc/7864900.sdhci/mmc_host*      /storage/sdcard1 vfatnosuid,nodev         wait,voldmanaged=sdcard1:auto,noemulatedsd,encryptable=footer
/devices/platform/soc/7000000.ssusb/7000000.dwc3/xhci-hcd.0.auto*/storage/usbotgvfatnosuid,nodevwait,voldmanaged=usbotg:auto
/devices/soc/7864900.sdhci/mmc_host*      /storage/sdcard1 vfatnosuid,nodev         wait,voldmanaged=sdcard1:auto,noemulatedsd,encryptable=footer
diff --git a/device/qcom/msm8953_64/fstabs-4.9/fstab_non_AB_variant.qti b/device/qcom/msm8953_64/fstabs-4.9/fstab_non_AB_variant.qti
index cef6107..740f9fe 100644
--- a/device/qcom/msm8953_64/fstabs-4.9/fstab_non_AB_variant.qti
+++ b/device/qcom/msm8953_64/fstabs-4.9/fstab_non_AB_variant.qti
@@ -34,7 +34,7 @@

#<src>                                    <mnt_point><type><mnt_flags and options>                     <fs_mgr_flags>
/dev/block/bootdevice/by-name/system      /            ext4    ro,barrier=1,discard                        wait,avb
-/dev/block/bootdevice/by-name/userdata      /data      ext4    noatime,nosuid,nodev,barrier=1,noauto_da_alloc,discardwait,forceencrypt=footer,quota,reservedsize=128M
+/dev/block/bootdevice/by-name/userdata      /data      ext4    noatime,nosuid,nodev,barrier=1,noauto_da_alloc,discard,resize wait,forceencrypt=footer,quota,reservedsize=128M
/devices/platform/soc/7864900.sdhci/mmc_host*      /storage/sdcard1 vfatnosuid,nodev         wait,voldmanaged=sdcard1:auto,noemulatedsd,encryptable=footer
/devices/platform/soc/7000000.ssusb/7000000.dwc3/xhci-hcd.0.auto*/storage/usbotgvfatnosuid,nodevwait,voldmanaged=usbotg:auto
/devices/soc/7864900.sdhci/mmc_host*      /storage/sdcard1 vfatnosuid,nodev         wait,voldmanaged=sdcard1:auto,noemulatedsd,encryptable=footer
diff --git a/system/core/fs_mgr/fs_mgr.cpp b/system/core/fs_mgr/fs_mgr.cpp
index 29f165f..e511c5e 100755
--- a/system/core/fs_mgr/fs_mgr.cpp
+++ b/system/core/fs_mgr/fs_mgr.cpp
@@ -61,6 +61,11 @@
#include "fs_mgr_priv.h"
#include "fs_mgr_priv_dm_ioctl.h"

+#ifdef FS_MGR_RESIZE_ENABLE
+#include "cryptfs.h"
+#define RESIZE2FS_BIN   "/system/bin/resize2fs"
+#endif
+
#define KEY_LOC_PROP   "ro.crypto.keyfile.userdata"
#define KEY_IN_FOOTER"footer"

@@ -416,6 +421,72 @@ static void tune_encrypt(const char* blk_device, const struct fstab_rec* rec,
   }
}

+#ifdef FS_MGR_RESIZE_ENABLE
+static void resize_fs(const std::string& blk_device, const std::string& fs_type,
+                      const std::string& key_loc) {
+    uint64_t device_sz;
+    uint64_t device_ss;
+    int status = 0;
+    int ret = 0;
+
+    android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(blk_device.c_str(), O_RDONLY | O_CLOEXEC)));
+
+    if (fd < 0) {
+      PERROR << "Failed to open '" << blk_device << "'";
+      return;
+    }
+
+    /* Cannot use BLKGETSIZE to get the number of sectors,
+    * because need to do device_sz -= CRYPT_FOOTER_OFFSET
+    */
+    if ((ioctl(fd, BLKGETSIZE64, &device_sz)) == -1) {
+      PERROR << "(BLKGETSIZE64) Can't get '" << blk_device << "' size";
+      return;
+    }
+
+    if ((ioctl(fd, BLKSSZGET, &device_ss)) == -1) {
+      PERROR << "(BLKSSZGET) Can't get '" << blk_device << "' size";
+      return;
+    }
+
+    /* Format the partition using the calculated length */
+    if (!strcmp(key_loc.c_str(), KEY_IN_FOOTER))
+      device_sz -= CRYPT_FOOTER_OFFSET;
+
+    if (is_extfs(fs_type)) {
+      if (access(RESIZE2FS_BIN, X_OK)) {
+            LINFO << "Not running " << RESIZE2FS_BIN << " on " << blk_device
+            << " (executable not in system image)";
+      } else {
+            std::string size_kb_str(android::base::StringPrintf("%" PRIu64 "K", device_sz / 1024));
+
+            LINFO << "Running " << RESIZE2FS_BIN << " on " << blk_device;
+
+            /* extX cmd */
+            const char *resize2fs_argv[] = {
+                RESIZE2FS_BIN,
+                "-f",
+                blk_device.c_str(),
+                size_kb_str.c_str()
+            };
+
+            ret = android_fork_execvp_ext(ARRAY_SIZE(resize2fs_argv),
+                const_cast<char **>(resize2fs_argv),
+                &status, true, LOG_KLOG,
+                false, NULL, NULL, 0);
+
+            if (ret < 0) {
+                /* No need to check for error in fork, we can't really handle it now */
+                LERROR << "Failed trying to run " << RESIZE2FS_BIN;
+                return;
+            }
+      }
+    }
+}
+#endif
+
+
+
//
// Prepare the filesystem on the given block device to be mounted.
//
@@ -452,6 +523,14 @@ static int prepare_fs_for_mount(const char* blk_device, const struct fstab_rec*
         check_fs(blk_device, rec->fs_type, rec->mount_point, &fs_stat);
   }

+#ifdef FS_MGR_RESIZE_ENABLE
+    if ((rec->flags & MF_RESIZE) && !strcmp(blk_device, rec->blk_device)) {
+      resize_fs(blk_device, rec->fs_type, rec->key_loc);
+      check_fs(blk_device, rec->fs_type, rec->mount_point, &fs_stat);
+    }
+      LERROR << "admin Enter addprepare_fs_for_mount FS_MGR_RESIZE_ENABLE" << fs_stat;
+#endif
+
   if (is_extfs(rec->fs_type) && (rec->fs_mgr_flags & (MF_RESERVEDSIZE | MF_FILEENCRYPTION))) {
         struct ext4_super_block sb;

diff --git a/system/core/fs_mgr/fs_mgr_fstab.cpp b/system/core/fs_mgr/fs_mgr_fstab.cpp
old mode 100644
new mode 100755
index cc1fc93..d70600c
--- a/system/core/fs_mgr/fs_mgr_fstab.cpp
+++ b/system/core/fs_mgr/fs_mgr_fstab.cpp
@@ -73,6 +73,9 @@ static struct flag_list mount_flags[] = {
   { "private",    MS_PRIVATE },
   { "slave",      MS_SLAVE },
   { "shared",   MS_SHARED },
+#ifdef FS_MGR_RESIZE_ENABLE
+      {"resize", MF_RESIZE},
+#endif
   { "defaults",   0 },
   { 0,            0 },
};
diff --git a/system/core/fs_mgr/fs_mgr_priv.h b/system/core/fs_mgr/fs_mgr_priv.h
old mode 100644
new mode 100755
index c1cc3be..2150c60
--- a/system/core/fs_mgr/fs_mgr_priv.h
+++ b/system/core/fs_mgr/fs_mgr_priv.h
@@ -33,6 +33,11 @@
*/
#define FS_MGR_CHECK(x) CHECK(x) << "in libfs_mgr "

+#define FS_MGR_RESIZE_ENABLE
+#ifdef FS_MGR_RESIZE_ENABLE
+#define MF_RESIZE         0x10000000
+#endif
+
#define FS_MGR_TAG ""

// Logs a message to kernel
diff --git a/system/sepolicy/prebuilts/api/26.0/private/file_contexts b/system/sepolicy/prebuilts/api/26.0/private/file_contexts
index 4485b95..dd6985f 100644
--- a/system/sepolicy/prebuilts/api/26.0/private/file_contexts
+++ b/system/sepolicy/prebuilts/api/26.0/private/file_contexts
@@ -537,3 +537,4 @@
/mnt/user(/.*)?             u:object_r:mnt_user_file:s0
/mnt/runtime(/.*)?          u:object_r:storage_file:s0
/storage(/.*)?            u:object_r:storage_file:s0
+/system/bin/resize2fs      u:object_r:fsck_exec:s0
diff --git a/system/sepolicy/prebuilts/api/27.0/private/file_contexts b/system/sepolicy/prebuilts/api/27.0/private/file_contexts
index 5369758..2f04e4c 100644
--- a/system/sepolicy/prebuilts/api/27.0/private/file_contexts
+++ b/system/sepolicy/prebuilts/api/27.0/private/file_contexts
@@ -468,3 +468,4 @@
/mnt/user(/.*)?             u:object_r:mnt_user_file:s0
/mnt/runtime(/.*)?          u:object_r:storage_file:s0
/storage(/.*)?            u:object_r:storage_file:s0
+/system/bin/resize2fs      u:object_r:fsck_exec:s0
diff --git a/system/sepolicy/prebuilts/api/28.0/private/file_contexts b/system/sepolicy/prebuilts/api/28.0/private/file_contexts
index 32eb3f1..6329d5c 100644
--- a/system/sepolicy/prebuilts/api/28.0/private/file_contexts
+++ b/system/sepolicy/prebuilts/api/28.0/private/file_contexts
@@ -541,3 +541,4 @@
#############################
# mount point for read-write vendor partitions
/mnt/vendor(/.*)?          u:object_r:mnt_vendor_file:s0
+/system/bin/resize2fs      u:object_r:fsck_exec:s0




页: [1]
查看完整版本: 高通 SC60 SDM450 自动匹配flash 容量大小补丁