10d163575Sopenharmony_ci/* 20d163575Sopenharmony_ci * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. 30d163575Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. 40d163575Sopenharmony_ci * 50d163575Sopenharmony_ci * Redistribution and use in source and binary forms, with or without modification, 60d163575Sopenharmony_ci * are permitted provided that the following conditions are met: 70d163575Sopenharmony_ci * 80d163575Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright notice, this list of 90d163575Sopenharmony_ci * conditions and the following disclaimer. 100d163575Sopenharmony_ci * 110d163575Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright notice, this list 120d163575Sopenharmony_ci * of conditions and the following disclaimer in the documentation and/or other materials 130d163575Sopenharmony_ci * provided with the distribution. 140d163575Sopenharmony_ci * 150d163575Sopenharmony_ci * 3. Neither the name of the copyright holder nor the names of its contributors may be used 160d163575Sopenharmony_ci * to endorse or promote products derived from this software without specific prior written 170d163575Sopenharmony_ci * permission. 180d163575Sopenharmony_ci * 190d163575Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 200d163575Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 210d163575Sopenharmony_ci * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 220d163575Sopenharmony_ci * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 230d163575Sopenharmony_ci * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 240d163575Sopenharmony_ci * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 250d163575Sopenharmony_ci * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 260d163575Sopenharmony_ci * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 270d163575Sopenharmony_ci * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 280d163575Sopenharmony_ci * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 290d163575Sopenharmony_ci * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 300d163575Sopenharmony_ci */ 310d163575Sopenharmony_ci 320d163575Sopenharmony_ci#include "los_rootfs.h" 330d163575Sopenharmony_ci#include "los_bootargs.h" 340d163575Sopenharmony_ci#include "los_base.h" 350d163575Sopenharmony_ci#include "string.h" 360d163575Sopenharmony_ci#include "sys/mount.h" 370d163575Sopenharmony_ci#include "sys/stat.h" 380d163575Sopenharmony_ci#include "sys/types.h" 390d163575Sopenharmony_ci 400d163575Sopenharmony_ci#if defined(LOSCFG_STORAGE_SPINOR) || defined(LOSCFG_STORAGE_SPINAND) 410d163575Sopenharmony_ci#include "mtd_list.h" 420d163575Sopenharmony_ci#include "mtd_partition.h" 430d163575Sopenharmony_ci#endif 440d163575Sopenharmony_ci 450d163575Sopenharmony_ci#ifdef LOSCFG_STORAGE_EMMC 460d163575Sopenharmony_ci#include "disk.h" 470d163575Sopenharmony_ci#include "ff.h" 480d163575Sopenharmony_ci#endif 490d163575Sopenharmony_ci 500d163575Sopenharmony_ci 510d163575Sopenharmony_ci#ifdef LOSCFG_STORAGE_EMMC 520d163575Sopenharmony_cistruct disk_divide_info *StorageBlockGetEmmc(void); 530d163575Sopenharmony_cistruct block_operations *StorageBlockGetMmcOps(void); 540d163575Sopenharmony_cichar *StorageBlockGetEmmcNodeName(void *block); 550d163575Sopenharmony_ci 560d163575Sopenharmony_ciSTATIC INT32 AddEmmcParts(INT32 rootAddr, INT32 rootSize, INT32 userAddr, INT32 userSize) 570d163575Sopenharmony_ci{ 580d163575Sopenharmony_ci INT32 ret; 590d163575Sopenharmony_ci 600d163575Sopenharmony_ci los_disk *emmcDisk = los_get_mmcdisk_bytype(EMMC); 610d163575Sopenharmony_ci if (emmcDisk == NULL) { 620d163575Sopenharmony_ci PRINT_ERR("Get EMMC disk failed!\n"); 630d163575Sopenharmony_ci return LOS_NOK; 640d163575Sopenharmony_ci } 650d163575Sopenharmony_ci 660d163575Sopenharmony_ci void *block = ((struct drv_data *)emmcDisk->dev->data)->priv; 670d163575Sopenharmony_ci const char *node_name = StorageBlockGetEmmcNodeName(block); 680d163575Sopenharmony_ci if (los_disk_deinit(emmcDisk->disk_id) != ENOERR) { 690d163575Sopenharmony_ci PRINT_ERR("Failed to deinit emmc disk!\n"); 700d163575Sopenharmony_ci return LOS_NOK; 710d163575Sopenharmony_ci } 720d163575Sopenharmony_ci 730d163575Sopenharmony_ci struct disk_divide_info *emmc = StorageBlockGetEmmc(); 740d163575Sopenharmony_ci ret = add_mmc_partition(emmc, rootAddr / EMMC_SEC_SIZE, rootSize / EMMC_SEC_SIZE); 750d163575Sopenharmony_ci if (ret != LOS_OK) { 760d163575Sopenharmony_ci PRINT_ERR("Failed to add mmc root partition!\n"); 770d163575Sopenharmony_ci return LOS_NOK; 780d163575Sopenharmony_ci } 790d163575Sopenharmony_ci 800d163575Sopenharmony_ci#ifdef LOSCFG_PLATFORM_PATCHFS 810d163575Sopenharmony_ci UINT64 patchStartCnt = userAddr / EMMC_SEC_SIZE; 820d163575Sopenharmony_ci UINT64 patchSizeCnt = PATCH_SIZE / EMMC_SEC_SIZE; 830d163575Sopenharmony_ci ret = add_mmc_partition(emmc, patchStartCnt, patchSizeCnt); 840d163575Sopenharmony_ci if (ret != LOS_OK) { 850d163575Sopenharmony_ci PRINT_ERR("Failed to add mmc patch partition!\n"); 860d163575Sopenharmony_ci return LOS_NOK; 870d163575Sopenharmony_ci } 880d163575Sopenharmony_ci userAddr += PATCH_SIZE; 890d163575Sopenharmony_ci#endif 900d163575Sopenharmony_ci 910d163575Sopenharmony_ci UINT64 storageStartCnt = userAddr / EMMC_SEC_SIZE; 920d163575Sopenharmony_ci UINT64 storageSizeCnt = userSize / EMMC_SEC_SIZE; 930d163575Sopenharmony_ci UINT64 userdataStartCnt = storageStartCnt + storageSizeCnt; 940d163575Sopenharmony_ci UINT64 userdataSizeCnt = emmcDisk->sector_count - userdataStartCnt; 950d163575Sopenharmony_ci ret = add_mmc_partition(emmc, storageStartCnt, storageSizeCnt); 960d163575Sopenharmony_ci if (ret != LOS_OK) { 970d163575Sopenharmony_ci PRINT_ERR("Failed to add mmc storage partition!\n"); 980d163575Sopenharmony_ci return LOS_NOK; 990d163575Sopenharmony_ci } 1000d163575Sopenharmony_ci 1010d163575Sopenharmony_ci ret = add_mmc_partition(emmc, userdataStartCnt, userdataSizeCnt); 1020d163575Sopenharmony_ci if (ret != LOS_OK) { 1030d163575Sopenharmony_ci PRINT_ERR("Failed to add mmc userdata partition!\n"); 1040d163575Sopenharmony_ci return LOS_NOK; 1050d163575Sopenharmony_ci } 1060d163575Sopenharmony_ci 1070d163575Sopenharmony_ci LOS_Msleep(10); /* 100, sleep time. waiting for device identification */ 1080d163575Sopenharmony_ci 1090d163575Sopenharmony_ci INT32 diskId = los_alloc_diskid_byname(node_name); 1100d163575Sopenharmony_ci if (diskId < 0) { 1110d163575Sopenharmony_ci PRINT_ERR("Failed to alloc disk %s!\n", node_name); 1120d163575Sopenharmony_ci return LOS_NOK; 1130d163575Sopenharmony_ci } 1140d163575Sopenharmony_ci 1150d163575Sopenharmony_ci if (los_disk_init(node_name, StorageBlockGetMmcOps(), block, diskId, emmc) != ENOERR) { 1160d163575Sopenharmony_ci PRINT_ERR("Failed to init emmc disk!\n"); 1170d163575Sopenharmony_ci return LOS_NOK; 1180d163575Sopenharmony_ci } 1190d163575Sopenharmony_ci 1200d163575Sopenharmony_ci return LOS_OK; 1210d163575Sopenharmony_ci} 1220d163575Sopenharmony_ci#endif 1230d163575Sopenharmony_ci 1240d163575Sopenharmony_ci 1250d163575Sopenharmony_ciSTATIC INT32 AddPartitions(CHAR *dev, UINT64 rootAddr, UINT64 rootSize, UINT64 userAddr, UINT64 userSize) 1260d163575Sopenharmony_ci{ 1270d163575Sopenharmony_ci#if defined(LOSCFG_STORAGE_SPINOR) || defined(LOSCFG_STORAGE_SPINAND) 1280d163575Sopenharmony_ci INT32 ret; 1290d163575Sopenharmony_ci INT32 blk0 = 0; 1300d163575Sopenharmony_ci INT32 blk2 = 2; 1310d163575Sopenharmony_ci if (strcmp(dev, "flash") == 0 || strcmp(dev, FLASH_TYPE) == 0) { 1320d163575Sopenharmony_ci ret = add_mtd_partition(FLASH_TYPE, rootAddr, rootSize, blk0); 1330d163575Sopenharmony_ci if (ret != LOS_OK) { 1340d163575Sopenharmony_ci PRINT_ERR("Failed to add mtd root partition!\n"); 1350d163575Sopenharmony_ci return LOS_NOK; 1360d163575Sopenharmony_ci } 1370d163575Sopenharmony_ci 1380d163575Sopenharmony_ci ret = add_mtd_partition(FLASH_TYPE, userAddr, userSize, blk2); 1390d163575Sopenharmony_ci if (ret != LOS_OK) { 1400d163575Sopenharmony_ci PRINT_ERR("Failed to add mtd storage partition!\n"); 1410d163575Sopenharmony_ci return LOS_NOK; 1420d163575Sopenharmony_ci } 1430d163575Sopenharmony_ci 1440d163575Sopenharmony_ci return LOS_OK; 1450d163575Sopenharmony_ci } 1460d163575Sopenharmony_ci#endif 1470d163575Sopenharmony_ci 1480d163575Sopenharmony_ci#ifdef LOSCFG_STORAGE_EMMC 1490d163575Sopenharmony_ci if (strcmp(dev, "emmc") == 0) { 1500d163575Sopenharmony_ci return AddEmmcParts(rootAddr, rootSize, userAddr, userSize); 1510d163575Sopenharmony_ci } 1520d163575Sopenharmony_ci#endif 1530d163575Sopenharmony_ci 1540d163575Sopenharmony_ci PRINT_ERR("Unsupport dev type: %s\n", dev); 1550d163575Sopenharmony_ci return LOS_NOK; 1560d163575Sopenharmony_ci} 1570d163575Sopenharmony_ci 1580d163575Sopenharmony_ci 1590d163575Sopenharmony_ciSTATIC INT32 ParseRootArgs(CHAR **dev, CHAR **fstype, UINT64 *rootAddr, UINT64 *rootSize, UINT32 *mountFlags) 1600d163575Sopenharmony_ci{ 1610d163575Sopenharmony_ci INT32 ret; 1620d163575Sopenharmony_ci CHAR *rootAddrStr = NULL; 1630d163575Sopenharmony_ci CHAR *rootSizeStr = NULL; 1640d163575Sopenharmony_ci CHAR *rwTag = NULL; 1650d163575Sopenharmony_ci 1660d163575Sopenharmony_ci ret = LOS_GetArgValue("root", dev); 1670d163575Sopenharmony_ci if (ret != LOS_OK) { 1680d163575Sopenharmony_ci PRINT_ERR("Cannot find root!"); 1690d163575Sopenharmony_ci return ret; 1700d163575Sopenharmony_ci } 1710d163575Sopenharmony_ci 1720d163575Sopenharmony_ci ret = LOS_GetArgValue("fstype", fstype); 1730d163575Sopenharmony_ci if (ret != LOS_OK) { 1740d163575Sopenharmony_ci PRINT_ERR("Cannot find fstype!"); 1750d163575Sopenharmony_ci return ret; 1760d163575Sopenharmony_ci } 1770d163575Sopenharmony_ci 1780d163575Sopenharmony_ci ret = LOS_GetArgValue("rootaddr", &rootAddrStr); 1790d163575Sopenharmony_ci if (ret != LOS_OK) { 1800d163575Sopenharmony_ci *rootAddr = ROOTFS_ADDR; 1810d163575Sopenharmony_ci } else { 1820d163575Sopenharmony_ci *rootAddr = LOS_SizeStrToNum(rootAddrStr); 1830d163575Sopenharmony_ci } 1840d163575Sopenharmony_ci 1850d163575Sopenharmony_ci ret = LOS_GetArgValue("rootsize", &rootSizeStr); 1860d163575Sopenharmony_ci if (ret != LOS_OK) { 1870d163575Sopenharmony_ci *rootSize = ROOTFS_SIZE; 1880d163575Sopenharmony_ci } else { 1890d163575Sopenharmony_ci *rootSize = LOS_SizeStrToNum(rootSizeStr); 1900d163575Sopenharmony_ci } 1910d163575Sopenharmony_ci 1920d163575Sopenharmony_ci ret = LOS_GetArgValue("ro", &rwTag); 1930d163575Sopenharmony_ci if (ret == LOS_OK) { 1940d163575Sopenharmony_ci *mountFlags = MS_RDONLY; 1950d163575Sopenharmony_ci } else { 1960d163575Sopenharmony_ci *mountFlags = 0; 1970d163575Sopenharmony_ci } 1980d163575Sopenharmony_ci 1990d163575Sopenharmony_ci return LOS_OK; 2000d163575Sopenharmony_ci} 2010d163575Sopenharmony_ci 2020d163575Sopenharmony_ciSTATIC INT32 ParseUserArgs(UINT64 rootAddr, UINT64 rootSize, UINT64 *userAddr, UINT64 *userSize) 2030d163575Sopenharmony_ci{ 2040d163575Sopenharmony_ci INT32 ret; 2050d163575Sopenharmony_ci CHAR *userAddrStr = NULL; 2060d163575Sopenharmony_ci CHAR *userSizeStr = NULL; 2070d163575Sopenharmony_ci 2080d163575Sopenharmony_ci ret = LOS_GetArgValue("useraddr", &userAddrStr); 2090d163575Sopenharmony_ci if (ret != LOS_OK) { 2100d163575Sopenharmony_ci *userAddr = rootAddr + rootSize; 2110d163575Sopenharmony_ci } else { 2120d163575Sopenharmony_ci *userAddr = LOS_SizeStrToNum(userAddrStr); 2130d163575Sopenharmony_ci } 2140d163575Sopenharmony_ci 2150d163575Sopenharmony_ci ret = LOS_GetArgValue("usersize", &userSizeStr); 2160d163575Sopenharmony_ci if (ret != LOS_OK) { 2170d163575Sopenharmony_ci *userSize = USERFS_SIZE; 2180d163575Sopenharmony_ci } else { 2190d163575Sopenharmony_ci *userSize = LOS_SizeStrToNum(userSizeStr); 2200d163575Sopenharmony_ci } 2210d163575Sopenharmony_ci 2220d163575Sopenharmony_ci return LOS_OK; 2230d163575Sopenharmony_ci} 2240d163575Sopenharmony_ci 2250d163575Sopenharmony_ciSTATIC INT32 MountPartitions(CHAR *fsType, UINT32 mountFlags) 2260d163575Sopenharmony_ci{ 2270d163575Sopenharmony_ci INT32 ret; 2280d163575Sopenharmony_ci INT32 err; 2290d163575Sopenharmony_ci 2300d163575Sopenharmony_ci /* Mount rootfs */ 2310d163575Sopenharmony_ci ret = mount(ROOT_DEV_NAME, ROOT_DIR_NAME, fsType, mountFlags, NULL); 2320d163575Sopenharmony_ci if (ret != LOS_OK) { 2330d163575Sopenharmony_ci err = get_errno(); 2340d163575Sopenharmony_ci PRINT_ERR("Failed to mount %s, rootDev %s, errno %d: %s\n", ROOT_DIR_NAME, ROOT_DEV_NAME, err, strerror(err)); 2350d163575Sopenharmony_ci return ret; 2360d163575Sopenharmony_ci } 2370d163575Sopenharmony_ci 2380d163575Sopenharmony_ci#ifdef LOSCFG_STORAGE_EMMC 2390d163575Sopenharmony_ci#ifdef LOSCFG_PLATFORM_PATCHFS 2400d163575Sopenharmony_ci /* Mount patch */ 2410d163575Sopenharmony_ci ret = mkdir(PATCH_DIR_NAME, DEFAULT_MOUNT_DIR_MODE); 2420d163575Sopenharmony_ci if ((ret != LOS_OK) && ((err = get_errno()) != EEXIST)) { 2430d163575Sopenharmony_ci PRINT_ERR("Failed to mkdir %s, errno %d: %s\n", PATCH_DIR_NAME, err, strerror(err)); 2440d163575Sopenharmony_ci return ret; 2450d163575Sopenharmony_ci } 2460d163575Sopenharmony_ci 2470d163575Sopenharmony_ci ret = mount(PATCH_DEV_NAME, PATCH_DIR_NAME, fsType, 0, DEFAULT_MOUNT_DATA); 2480d163575Sopenharmony_ci if ((ret != LOS_OK) && ((err = get_errno()) == ENOTSUP)) { 2490d163575Sopenharmony_ci ret = format(PATCH_DEV_NAME, 0, FM_FAT32); 2500d163575Sopenharmony_ci if (ret != LOS_OK) { 2510d163575Sopenharmony_ci PRINT_ERR("Failed to format %s\n", PATCH_DEV_NAME); 2520d163575Sopenharmony_ci return ret; 2530d163575Sopenharmony_ci } 2540d163575Sopenharmony_ci 2550d163575Sopenharmony_ci ret = mount(PATCH_DEV_NAME, PATCH_DIR_NAME, fsType, 0, DEFAULT_MOUNT_DATA); 2560d163575Sopenharmony_ci if (ret != LOS_OK) { 2570d163575Sopenharmony_ci err = get_errno(); 2580d163575Sopenharmony_ci } 2590d163575Sopenharmony_ci } 2600d163575Sopenharmony_ci if (ret != LOS_OK) { 2610d163575Sopenharmony_ci PRINT_ERR("Failed to mount %s, errno %d: %s\n", PATCH_DIR_NAME, err, strerror(err)); 2620d163575Sopenharmony_ci return ret; 2630d163575Sopenharmony_ci } 2640d163575Sopenharmony_ci#endif 2650d163575Sopenharmony_ci#endif 2660d163575Sopenharmony_ci 2670d163575Sopenharmony_ci /* Mount userfs */ 2680d163575Sopenharmony_ci ret = mkdir(STORAGE_DIR_NAME, DEFAULT_MOUNT_DIR_MODE); 2690d163575Sopenharmony_ci if ((ret != LOS_OK) && ((err = get_errno()) != EEXIST)) { 2700d163575Sopenharmony_ci PRINT_ERR("Failed to mkdir %s, errno %d: %s\n", STORAGE_DIR_NAME, err, strerror(err)); 2710d163575Sopenharmony_ci return ret; 2720d163575Sopenharmony_ci } 2730d163575Sopenharmony_ci 2740d163575Sopenharmony_ci ret = mount(USER_DEV_NAME, STORAGE_DIR_NAME, fsType, 0, DEFAULT_MOUNT_DATA); 2750d163575Sopenharmony_ci if (ret != LOS_OK) { 2760d163575Sopenharmony_ci err = get_errno(); 2770d163575Sopenharmony_ci PRINT_ERR("Failed to mount %s, errno %d: %s\n", STORAGE_DIR_NAME, err, strerror(err)); 2780d163575Sopenharmony_ci return ret; 2790d163575Sopenharmony_ci } 2800d163575Sopenharmony_ci 2810d163575Sopenharmony_ci#ifdef LOSCFG_STORAGE_EMMC 2820d163575Sopenharmony_ci /* Mount userdata */ 2830d163575Sopenharmony_ci ret = mkdir(USERDATA_DIR_NAME, DEFAULT_MOUNT_DIR_MODE); 2840d163575Sopenharmony_ci if ((ret != LOS_OK) && ((err = get_errno()) != EEXIST)) { 2850d163575Sopenharmony_ci PRINT_ERR("Failed to mkdir %s, errno %d: %s\n", USERDATA_DIR_NAME, err, strerror(err)); 2860d163575Sopenharmony_ci return ret; 2870d163575Sopenharmony_ci } 2880d163575Sopenharmony_ci 2890d163575Sopenharmony_ci ret = mount(USERDATA_DEV_NAME, USERDATA_DIR_NAME, fsType, 0, DEFAULT_MOUNT_DATA); 2900d163575Sopenharmony_ci if ((ret != LOS_OK) && ((err = get_errno()) == ENOTSUP)) { 2910d163575Sopenharmony_ci ret = format(USERDATA_DEV_NAME, 0, FM_FAT32); 2920d163575Sopenharmony_ci if (ret != LOS_OK) { 2930d163575Sopenharmony_ci PRINT_ERR("Failed to format %s\n", USERDATA_DEV_NAME); 2940d163575Sopenharmony_ci return ret; 2950d163575Sopenharmony_ci } 2960d163575Sopenharmony_ci 2970d163575Sopenharmony_ci ret = mount(USERDATA_DEV_NAME, USERDATA_DIR_NAME, fsType, 0, DEFAULT_MOUNT_DATA); 2980d163575Sopenharmony_ci if (ret != LOS_OK) { 2990d163575Sopenharmony_ci err = get_errno(); 3000d163575Sopenharmony_ci } 3010d163575Sopenharmony_ci } 3020d163575Sopenharmony_ci if (ret != LOS_OK) { 3030d163575Sopenharmony_ci PRINT_ERR("Failed to mount %s, errno %d: %s\n", USERDATA_DIR_NAME, err, strerror(err)); 3040d163575Sopenharmony_ci return ret; 3050d163575Sopenharmony_ci } 3060d163575Sopenharmony_ci#endif 3070d163575Sopenharmony_ci return LOS_OK; 3080d163575Sopenharmony_ci} 3090d163575Sopenharmony_ci 3100d163575Sopenharmony_ciSTATIC INT32 CheckValidation(UINT64 rootAddr, UINT64 rootSize, UINT64 userAddr, UINT64 userSize) 3110d163575Sopenharmony_ci{ 3120d163575Sopenharmony_ci UINT64 alignSize = LOS_GetAlignsize(); 3130d163575Sopenharmony_ci if (alignSize == 0) { 3140d163575Sopenharmony_ci return LOS_OK; 3150d163575Sopenharmony_ci } 3160d163575Sopenharmony_ci 3170d163575Sopenharmony_ci if ((rootAddr & (alignSize - 1)) || (rootSize & (alignSize - 1)) || 3180d163575Sopenharmony_ci (userAddr & (alignSize - 1)) || (userSize & (alignSize - 1))) { 3190d163575Sopenharmony_ci PRINT_ERR("The address or size value should be 0x%llx aligned!\n", alignSize); 3200d163575Sopenharmony_ci return LOS_NOK; 3210d163575Sopenharmony_ci } 3220d163575Sopenharmony_ci 3230d163575Sopenharmony_ci return LOS_OK; 3240d163575Sopenharmony_ci} 3250d163575Sopenharmony_ci 3260d163575Sopenharmony_ciINT32 OsMountRootfs() 3270d163575Sopenharmony_ci{ 3280d163575Sopenharmony_ci INT32 ret; 3290d163575Sopenharmony_ci CHAR *dev = NULL; 3300d163575Sopenharmony_ci CHAR *fstype = NULL; 3310d163575Sopenharmony_ci UINT64 rootAddr; 3320d163575Sopenharmony_ci UINT64 rootSize; 3330d163575Sopenharmony_ci UINT64 userAddr; 3340d163575Sopenharmony_ci UINT64 userSize; 3350d163575Sopenharmony_ci UINT32 mountFlags; 3360d163575Sopenharmony_ci 3370d163575Sopenharmony_ci ret = ParseRootArgs(&dev, &fstype, &rootAddr, &rootSize, &mountFlags); 3380d163575Sopenharmony_ci if (ret != LOS_OK) { 3390d163575Sopenharmony_ci return ret; 3400d163575Sopenharmony_ci } 3410d163575Sopenharmony_ci 3420d163575Sopenharmony_ci ret = ParseUserArgs(rootAddr, rootSize, &userAddr, &userSize); 3430d163575Sopenharmony_ci if (ret != LOS_OK) { 3440d163575Sopenharmony_ci return ret; 3450d163575Sopenharmony_ci } 3460d163575Sopenharmony_ci 3470d163575Sopenharmony_ci ret = CheckValidation(rootAddr, rootSize, userAddr, userSize); 3480d163575Sopenharmony_ci if (ret != LOS_OK) { 3490d163575Sopenharmony_ci return ret; 3500d163575Sopenharmony_ci } 3510d163575Sopenharmony_ci 3520d163575Sopenharmony_ci ret = AddPartitions(dev, rootAddr, rootSize, userAddr, userSize); 3530d163575Sopenharmony_ci if (ret != LOS_OK) { 3540d163575Sopenharmony_ci return ret; 3550d163575Sopenharmony_ci } 3560d163575Sopenharmony_ci 3570d163575Sopenharmony_ci ret = MountPartitions(fstype, mountFlags); 3580d163575Sopenharmony_ci if (ret != LOS_OK) { 3590d163575Sopenharmony_ci return ret; 3600d163575Sopenharmony_ci } 3610d163575Sopenharmony_ci 3620d163575Sopenharmony_ci return LOS_OK; 3630d163575Sopenharmony_ci} 364