搜索

451

主题

663

帖子

5297

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
5297
QQ
发表于 2022-9-26 17:14:08 1843 浏览 0 回复

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

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

解决方案:
      源码补丁见附件中(移远提供补丁):
  1. 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
  2. index f750e49..a0b24bf 100644
  3. --- a/device/qcom/msm8953_64/fstabs-4.9/fstab_AB_variant.qti
  4. +++ b/device/qcom/msm8953_64/fstabs-4.9/fstab_AB_variant.qti
  5. @@ -34,7 +34,7 @@

  6. #<src>                                      <mnt_point>  <type>  <mnt_flags and options>                     <fs_mgr_flags>
  7. /dev/block/bootdevice/by-name/system        /            ext4    ro,barrier=1,discard                        wait,slotselect,avb
  8. -/dev/block/bootdevice/by-name/userdata      /data        ext4    noatime,nosuid,nodev,barrier=1,noauto_da_alloc,discard  wait,forceencrypt=footer,quota,reservedsize=128M
  9. +/dev/block/bootdevice/by-name/userdata      /data        ext4    noatime,nosuid,nodev,barrier=1,noauto_da_alloc,discard,resize wait,forceencrypt=footer,quota,reservedsize=128M
  10. /devices/platform/soc/7864900.sdhci/mmc_host*        /storage/sdcard1 vfat  nosuid,nodev         wait,voldmanaged=sdcard1:auto,noemulatedsd,encryptable=footer
  11. /devices/platform/soc/7000000.ssusb/7000000.dwc3/xhci-hcd.0.auto*  /storage/usbotg  vfat  nosuid,nodev  wait,voldmanaged=usbotg:auto
  12. /devices/soc/7864900.sdhci/mmc_host*        /storage/sdcard1 vfat  nosuid,nodev         wait,voldmanaged=sdcard1:auto,noemulatedsd,encryptable=footer
  13. 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
  14. index cef6107..740f9fe 100644
  15. --- a/device/qcom/msm8953_64/fstabs-4.9/fstab_non_AB_variant.qti
  16. +++ b/device/qcom/msm8953_64/fstabs-4.9/fstab_non_AB_variant.qti
  17. @@ -34,7 +34,7 @@

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

  32. +#ifdef FS_MGR_RESIZE_ENABLE
  33. +#include "cryptfs.h"
  34. +#define RESIZE2FS_BIN   "/system/bin/resize2fs"
  35. +#endif
  36. +
  37. #define KEY_LOC_PROP   "ro.crypto.keyfile.userdata"
  38. #define KEY_IN_FOOTER  "footer"

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

  42. +#ifdef FS_MGR_RESIZE_ENABLE
  43. +static void resize_fs(const std::string& blk_device, const std::string& fs_type,
  44. +                      const std::string& key_loc) {
  45. +    uint64_t device_sz;
  46. +    uint64_t device_ss;
  47. +    int status = 0;
  48. +    int ret = 0;
  49. +
  50. +    android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(blk_device.c_str(), O_RDONLY | O_CLOEXEC)));
  51. +
  52. +    if (fd < 0) {
  53. +        PERROR << "Failed to open '" << blk_device << "'";
  54. +        return;
  55. +    }
  56. +
  57. +    /* Cannot use BLKGETSIZE to get the number of sectors,
  58. +    * because need to do device_sz -= CRYPT_FOOTER_OFFSET
  59. +    */
  60. +    if ((ioctl(fd, BLKGETSIZE64, &device_sz)) == -1) {
  61. +        PERROR << "(BLKGETSIZE64) Can't get '" << blk_device << "' size";
  62. +        return;
  63. +    }
  64. +
  65. +    if ((ioctl(fd, BLKSSZGET, &device_ss)) == -1) {
  66. +        PERROR << "(BLKSSZGET) Can't get '" << blk_device << "' size";
  67. +        return;
  68. +    }
  69. +
  70. +    /* Format the partition using the calculated length */
  71. +    if (!strcmp(key_loc.c_str(), KEY_IN_FOOTER))
  72. +        device_sz -= CRYPT_FOOTER_OFFSET;
  73. +
  74. +    if (is_extfs(fs_type)) {
  75. +        if (access(RESIZE2FS_BIN, X_OK)) {
  76. +            LINFO << "Not running " << RESIZE2FS_BIN << " on " << blk_device
  77. +            << " (executable not in system image)";
  78. +        } else {
  79. +            std::string size_kb_str(android::base::StringPrintf("%" PRIu64 "K", device_sz / 1024));
  80. +
  81. +            LINFO << "Running " << RESIZE2FS_BIN << " on " << blk_device;
  82. +
  83. +            /* extX cmd */
  84. +            const char *resize2fs_argv[] = {
  85. +                RESIZE2FS_BIN,
  86. +                "-f",
  87. +                blk_device.c_str(),
  88. +                size_kb_str.c_str()
  89. +            };
  90. +
  91. +            ret = android_fork_execvp_ext(ARRAY_SIZE(resize2fs_argv),
  92. +                const_cast<char **>(resize2fs_argv),
  93. +                &status, true, LOG_KLOG,
  94. +                false, NULL, NULL, 0);
  95. +
  96. +            if (ret < 0) {
  97. +                /* No need to check for error in fork, we can't really handle it now */
  98. +                LERROR << "Failed trying to run " << RESIZE2FS_BIN;
  99. +                return;
  100. +            }
  101. +        }
  102. +    }
  103. +}
  104. +#endif
  105. +
  106. +
  107. +
  108. //
  109. // Prepare the filesystem on the given block device to be mounted.
  110. //
  111. @@ -452,6 +523,14 @@ static int prepare_fs_for_mount(const char* blk_device, const struct fstab_rec*
  112.          check_fs(blk_device, rec->fs_type, rec->mount_point, &fs_stat);
  113.      }

  114. +#ifdef FS_MGR_RESIZE_ENABLE
  115. +    if ((rec->flags & MF_RESIZE) && !strcmp(blk_device, rec->blk_device)) {
  116. +        resize_fs(blk_device, rec->fs_type, rec->key_loc);
  117. +        check_fs(blk_device, rec->fs_type, rec->mount_point, &fs_stat);
  118. +    }
  119. +        LERROR << "admin Enter add  prepare_fs_for_mount FS_MGR_RESIZE_ENABLE" << fs_stat;
  120. +#endif
  121. +
  122.      if (is_extfs(rec->fs_type) && (rec->fs_mgr_flags & (MF_RESERVEDSIZE | MF_FILEENCRYPTION))) {
  123.          struct ext4_super_block sb;

  124. diff --git a/system/core/fs_mgr/fs_mgr_fstab.cpp b/system/core/fs_mgr/fs_mgr_fstab.cpp
  125. old mode 100644
  126. new mode 100755
  127. index cc1fc93..d70600c
  128. --- a/system/core/fs_mgr/fs_mgr_fstab.cpp
  129. +++ b/system/core/fs_mgr/fs_mgr_fstab.cpp
  130. @@ -73,6 +73,9 @@ static struct flag_list mount_flags[] = {
  131.      { "private",    MS_PRIVATE },
  132.      { "slave",      MS_SLAVE },
  133.      { "shared",     MS_SHARED },
  134. +#ifdef FS_MGR_RESIZE_ENABLE
  135. +        {"resize", MF_RESIZE},
  136. +#endif
  137.      { "defaults",   0 },
  138.      { 0,            0 },
  139. };
  140. diff --git a/system/core/fs_mgr/fs_mgr_priv.h b/system/core/fs_mgr/fs_mgr_priv.h
  141. old mode 100644
  142. new mode 100755
  143. index c1cc3be..2150c60
  144. --- a/system/core/fs_mgr/fs_mgr_priv.h
  145. +++ b/system/core/fs_mgr/fs_mgr_priv.h
  146. @@ -33,6 +33,11 @@
  147.   */
  148. #define FS_MGR_CHECK(x) CHECK(x) << "in libfs_mgr "

  149. +#define FS_MGR_RESIZE_ENABLE
  150. +#ifdef FS_MGR_RESIZE_ENABLE
  151. +#define MF_RESIZE         0x10000000
  152. +#endif
  153. +
  154. #define FS_MGR_TAG "[libfs_mgr]"

  155. // Logs a message to kernel
  156. diff --git a/system/sepolicy/prebuilts/api/26.0/private/file_contexts b/system/sepolicy/prebuilts/api/26.0/private/file_contexts
  157. index 4485b95..dd6985f 100644
  158. --- a/system/sepolicy/prebuilts/api/26.0/private/file_contexts
  159. +++ b/system/sepolicy/prebuilts/api/26.0/private/file_contexts
  160. @@ -537,3 +537,4 @@
  161. /mnt/user(/.*)?             u:object_r:mnt_user_file:s0
  162. /mnt/runtime(/.*)?          u:object_r:storage_file:s0
  163. /storage(/.*)?              u:object_r:storage_file:s0
  164. +/system/bin/resize2fs      u:object_r:fsck_exec:s0
  165. diff --git a/system/sepolicy/prebuilts/api/27.0/private/file_contexts b/system/sepolicy/prebuilts/api/27.0/private/file_contexts
  166. index 5369758..2f04e4c 100644
  167. --- a/system/sepolicy/prebuilts/api/27.0/private/file_contexts
  168. +++ b/system/sepolicy/prebuilts/api/27.0/private/file_contexts
  169. @@ -468,3 +468,4 @@
  170. /mnt/user(/.*)?             u:object_r:mnt_user_file:s0
  171. /mnt/runtime(/.*)?          u:object_r:storage_file:s0
  172. /storage(/.*)?              u:object_r:storage_file:s0
  173. +/system/bin/resize2fs      u:object_r:fsck_exec:s0
  174. diff --git a/system/sepolicy/prebuilts/api/28.0/private/file_contexts b/system/sepolicy/prebuilts/api/28.0/private/file_contexts
  175. index 32eb3f1..6329d5c 100644
  176. --- a/system/sepolicy/prebuilts/api/28.0/private/file_contexts
  177. +++ b/system/sepolicy/prebuilts/api/28.0/private/file_contexts
  178. @@ -541,3 +541,4 @@
  179. #############################
  180. # mount point for read-write vendor partitions
  181. /mnt/vendor(/.*)?          u:object_r:mnt_vendor_file:s0
  182. +/system/bin/resize2fs      u:object_r:fsck_exec:s0
复制代码




本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
手机微信同号:13682654092
回复

使用道具 举报

返回列表
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则


登录或注册
快速回复 返回顶部 返回列表