From 2e2b14205f4b81c7483ab42d62f144487097e9a4 Mon Sep 17 00:00:00 2001 From: chenjing Date: Thu, 24 Jun 2021 15:03:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20userfs=E5=88=86=E5=8C=BA=E7=9A=84?= =?UTF-8?q?=E8=B5=B7=E5=A7=8B=E5=9C=B0=E5=9D=80=E4=B8=8E=E5=A4=A7=E5=B0=8F?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E9=80=9A=E8=BF=87bootargs=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在内核解析bootargs参数时,加入对userAddr与userSize两个字段的解析。 1、如果bootargs中配置了userAddr与userSize,则使用配置值划分storage分区。 2、如果bootargs中未配置这两个字段,则storage分区默认紧接在rootfs分区后。 close #I3XNEY Signed-off-by: chenjing Change-Id: Iba63ccd7fc3f7efc1d726c4b38beee5df1d64122 --- kernel/common/los_rootfs.c | 42 ++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/kernel/common/los_rootfs.c b/kernel/common/los_rootfs.c index f11e2912..22992753 100644 --- a/kernel/common/los_rootfs.c +++ b/kernel/common/los_rootfs.c @@ -106,7 +106,7 @@ struct disk_divide_info *StorageBlockGetEmmc(void); struct block_operations *StorageBlockGetMmcOps(void); char *StorageBlockGetEmmcNodeName(void *block); -STATIC const CHAR *AddEmmcRootfsPart(INT32 rootAddr, INT32 rootSize) +STATIC const CHAR *AddEmmcRootfsPart(INT32 rootAddr, INT32 rootSize, INT32 userAddr, INT32 userSize) { INT32 ret; @@ -123,8 +123,8 @@ STATIC const CHAR *AddEmmcRootfsPart(INT32 rootAddr, INT32 rootSize) PRINT_ERR("Failed to add mmc root partition!\n"); return NULL; } else { - UINT64 storageStartCnt = (rootAddr + rootSize) / EMMC_SEC_SIZE; - UINT64 storageSizeCnt = STORAGE_SIZE / EMMC_SEC_SIZE; + UINT64 storageStartCnt = userAddr / EMMC_SEC_SIZE; + UINT64 storageSizeCnt = userSize / EMMC_SEC_SIZE; UINT64 userdataStartCnt = storageStartCnt + storageSizeCnt; UINT64 userdataSizeCnt = g_emmcDisk->sector_count - userdataStartCnt; ret = add_mmc_partition(emmc, storageStartCnt, storageSizeCnt); @@ -150,7 +150,7 @@ STATIC const CHAR *AddEmmcRootfsPart(INT32 rootAddr, INT32 rootSize) } #endif -STATIC const CHAR *GetDevName(const CHAR *rootType, INT32 rootAddr, INT32 rootSize) +STATIC const CHAR *GetDevName(const CHAR *rootType, INT32 rootAddr, INT32 rootSize, INT32 userAddr, INT32 userSize) { const CHAR *rootDev = NULL; @@ -162,7 +162,7 @@ STATIC const CHAR *GetDevName(const CHAR *rootType, INT32 rootAddr, INT32 rootSi PRINT_ERR("Failed to add spinor/spinand root partition!\n"); } else { rootDev = FLASH_DEV_NAME; - ret = add_mtd_partition(FLASH_TYPE, (rootAddr + rootSize), STORAGE_SIZE, SECOND_MTD_PART_NUM); + ret = add_mtd_partition(FLASH_TYPE, userAddr, userSize, SECOND_MTD_PART_NUM); if (ret != LOS_OK) { PRINT_ERR("Failed to add spinor/spinand storage partition!\n"); } @@ -189,7 +189,7 @@ STATIC const CHAR *GetDevName(const CHAR *rootType, INT32 rootAddr, INT32 rootSi #ifdef LOSCFG_STORAGE_EMMC if (strcmp(rootType, "emmc") == 0) { - rootDev = AddEmmcRootfsPart(rootAddr, rootSize); + rootDev = AddEmmcRootfsPart(rootAddr, rootSize, userAddr, userSize); } else #endif @@ -341,12 +341,14 @@ ERROUT: return LOS_NOK; } -STATIC INT32 MatchRootInfo(CHAR *p, CHAR **rootType, CHAR **fsType, INT32 *rootAddr, INT32 *rootSize) +STATIC INT32 MatchRootInfo(CHAR *p, CHAR **rootType, CHAR **fsType, INT32 *rootAddr, INT32 *rootSize, INT32 *userAddr, INT32 *userSize) { const CHAR *rootName = "root="; const CHAR *fsName = "fstype="; const CHAR *rootAddrName = "rootaddr="; const CHAR *rootSizeName = "rootsize="; + const CHAR *userAddrName = "useraddr="; + const CHAR *userSizeName = "usersize="; if ((*rootType == NULL) && (strncmp(p, rootName, strlen(rootName)) == 0)) { *rootType = strdup(p + strlen(rootName)); @@ -378,10 +380,24 @@ STATIC INT32 MatchRootInfo(CHAR *p, CHAR **rootType, CHAR **fsType, INT32 *rootA } } + if (*userAddr < 0) { + if (MatchRootPos(p, userAddrName, userAddr) != LOS_OK) { + return LOS_NOK; + } else if (*userAddr >= 0) { + return LOS_OK; + } + } + + if (*userSize < 0) { + if (MatchRootPos(p, userSizeName, userSize) != LOS_OK) { + return LOS_NOK; + } + } + return LOS_OK; } -STATIC INT32 GetRootType(CHAR **rootType, CHAR **fsType, INT32 *rootAddr, INT32 *rootSize) +STATIC INT32 GetRootType(CHAR **rootType, CHAR **fsType, INT32 *rootAddr, INT32 *rootSize, INT32 *userAddr, INT32 *userSize) { CHAR *args = NULL; CHAR *p = NULL; @@ -396,7 +412,7 @@ STATIC INT32 GetRootType(CHAR **rootType, CHAR **fsType, INT32 *rootAddr, INT32 #endif p = strsep(&args, " "); while (p != NULL) { - if (MatchRootInfo(p, rootType, fsType, rootAddr, rootSize) != LOS_OK) { + if (MatchRootInfo(p, rootType, fsType, rootAddr, rootSize, userAddr, userSize) != LOS_OK) { goto ERROUT; } p = strsep(&args, " "); @@ -528,6 +544,8 @@ INT32 OsMountRootfs(VOID) INT32 err; INT32 rootAddr = -1; INT32 rootSize = -1; + INT32 userAddr = -1; + INT32 userSize = -1; CHAR *rootType = NULL; CHAR *fsType = NULL; const CHAR *rootDev = NULL; @@ -538,15 +556,17 @@ INT32 OsMountRootfs(VOID) rootAddr = ROOTFS_FLASH_ADDR; rootSize = ROOTFS_FLASH_SIZE; #else - ret = GetRootType(&rootType, &fsType, &rootAddr, &rootSize); + ret = GetRootType(&rootType, &fsType, &rootAddr, &rootSize, &userAddr, &userSize); if (ret != LOS_OK) { return ret; } rootAddr = (rootAddr >= 0) ? rootAddr : ROOTFS_FLASH_ADDR; rootSize = (rootSize >= 0) ? rootSize : ROOTFS_FLASH_SIZE; #endif + userAddr = (userAddr >= 0) ? userAddr : rootAddr + rootSize; + userSize = (userSize >= 0) ? userSize : STORAGE_SIZE; - rootDev = GetDevName(rootType, rootAddr, rootSize); + rootDev = GetDevName(rootType, rootAddr, rootSize, userAddr, userSize); if (rootDev != NULL) { ret = OsMountRootfsAndUserfs(rootDev, fsType); if (ret != LOS_OK) { -- GitLab