feat: add liteos patch ability

Signed-off-by: jason_gitee <yangjie140@huawei.com>
This commit is contained in:
jason_gitee 2021-08-28 08:02:50 +00:00 committed by Gitee
parent aa5b2c7641
commit 98ca8441fe
8 changed files with 82 additions and 15 deletions

View File

@ -110,7 +110,10 @@ kernel_module(module_name) {
"$LITEOSTOPDIR/fs/vfs/vnode_hash.c", "$LITEOSTOPDIR/fs/vfs/vnode_hash.c",
] ]
include_dirs = [ "$LITEOSTOPDIR/syscall" ] include_dirs = [
"$LITEOSTOPDIR/syscall",
"$LITEOSTOPDIR/fs/zpfs/include",
]
public_configs = [ ":public" ] public_configs = [ ":public" ]
} }

View File

@ -101,6 +101,7 @@ LOCAL_INCLUDE := \
-I $(LITEOSTOPDIR)/drivers/mtd/multi_partition/include\ -I $(LITEOSTOPDIR)/drivers/mtd/multi_partition/include\
-I $(LITEOSTOPDIR)/fs/vfs/include/operation\ -I $(LITEOSTOPDIR)/fs/vfs/include/operation\
-I $(LITEOSTOPDIR)/syscall\ -I $(LITEOSTOPDIR)/syscall\
-I $(LITEOSTOPDIR)/fs/zpfs/include
ifeq ($(LOSCFG_FS_FAT), y) ifeq ($(LOSCFG_FS_FAT), y)
LOCAL_INCLUDE += -I $(LITEOSTHIRDPARTY)/FatFs/source LOCAL_INCLUDE += -I $(LITEOSTHIRDPARTY)/FatFs/source

View File

@ -159,6 +159,7 @@ int VnodeDevInit(void);
int VnodeAlloc(struct VnodeOps *vop, struct Vnode **vnode); int VnodeAlloc(struct VnodeOps *vop, struct Vnode **vnode);
int VnodeFree(struct Vnode *vnode); int VnodeFree(struct Vnode *vnode);
int VnodeLookup(const char *path, struct Vnode **vnode, uint32_t flags); int VnodeLookup(const char *path, struct Vnode **vnode, uint32_t flags);
int VnodeLookupAt(const char *path, struct Vnode **vnode, uint32_t flags, struct Vnode *orgVnode);
int VnodeHold(void); int VnodeHold(void);
int VnodeDrop(void); int VnodeDrop(void);
void VnodeRefDec(struct Vnode *vnode); void VnodeRefDec(struct Vnode *vnode);

View File

@ -360,14 +360,21 @@ STEP_FINISH:
return ret; return ret;
} }
int VnodeLookup(const char *path, struct Vnode **result, uint32_t flags) int VnodeLookupAt(const char *path, struct Vnode **result, uint32_t flags, struct Vnode *orgVnode)
{ {
int ret;
struct Vnode *startVnode = NULL; struct Vnode *startVnode = NULL;
char *normalizedPath = NULL; char *normalizedPath = NULL;
int ret = PreProcess(path, &startVnode, &normalizedPath); if (orgVnode != NULL) {
if (ret != LOS_OK) { startVnode = orgVnode;
goto OUT_FREE_PATH; normalizedPath = strdup(path);
} else {
ret = PreProcess(path, &startVnode, &normalizedPath);
if (ret != LOS_OK) {
PRINT_ERR("[VFS]lookup failed, invalid path err = %d\n", ret);
goto OUT_FREE_PATH;
}
} }
if (normalizedPath[0] == '/' && normalizedPath[1] == '\0') { if (normalizedPath[0] == '/' && normalizedPath[1] == '\0') {
@ -404,6 +411,11 @@ OUT_FREE_PATH:
return ret; return ret;
} }
int VnodeLookup(const char *path, struct Vnode **vnode, uint32_t flags)
{
return VnodeLookupAt(path, vnode, flags, NULL);
}
static void ChangeRootInternal(struct Vnode *rootOld, char *dirname) static void ChangeRootInternal(struct Vnode *rootOld, char *dirname)
{ {
int ret; int ret;

View File

@ -33,7 +33,9 @@ module_switch = defined(LOSCFG_FS_ZPFS)
module_name = get_path_info(rebase_path("."), "name") module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) { kernel_module(module_name) {
sources = [ sources = [
"vfs_zpfs.c", "src/vfs_zpfs.c",
"zpfs.c", "src/zpfs.c",
] ]
include_dirs = [ "include" ]
} }

View File

@ -31,14 +31,10 @@ include $(LITEOSTOPDIR)/config.mk
MODULE_NAME := $(notdir $(shell pwd)) MODULE_NAME := $(notdir $(shell pwd))
LOCAL_SRCS := $(wildcard *.c) LOCAL_SRCS := $(wildcard src/*.c)
LOCAL_INCLUDE = \ LOCAL_INCLUDE := \
-I $(LITEOSTOPDIR)/fs/include \ -I $(LITEOSTOPDIR)/fs/zpfs/include
-I $(LITEOSTOPDIR)/fs/zpfs \
-I $(LITEOSTOPDIR)/../../third_party/NuttX/liteos/fs/include\
-I $(LITEOSTOPDIR)/../../third_party/NuttX/liteos/fs/include/inode
LOCAL_FLAGS := $(LITEOS_GCOV_OPTS) LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
include $(MODULE) include $(MODULE)

View File

@ -81,6 +81,17 @@ STATIC INT32 AddEmmcParts(INT32 rootAddr, INT32 rootSize, INT32 userAddr, INT32
return LOS_NOK; return LOS_NOK;
} }
#ifdef LOSCFG_PLATFORM_PATCHFS
UINT64 patchStartCnt = userAddr / EMMC_SEC_SIZE;
UINT64 patchSizeCnt = PATCH_SIZE / EMMC_SEC_SIZE;
ret = add_mmc_partition(emmc, patchStartCnt, patchSizeCnt);
if (ret != LOS_OK) {
PRINT_ERR("Failed to add mmc patch partition!\n");
return LOS_NOK;
}
userAddr += PATCH_SIZE;
#endif
UINT64 storageStartCnt = userAddr / EMMC_SEC_SIZE; UINT64 storageStartCnt = userAddr / EMMC_SEC_SIZE;
UINT64 storageSizeCnt = userSize / EMMC_SEC_SIZE; UINT64 storageSizeCnt = userSize / EMMC_SEC_SIZE;
UINT64 userdataStartCnt = storageStartCnt + storageSizeCnt; UINT64 userdataStartCnt = storageStartCnt + storageSizeCnt;
@ -235,6 +246,35 @@ STATIC INT32 MountPartitions(CHAR *fsType, UINT32 mountFlags)
return ret; return ret;
} }
#ifdef LOSCFG_STORAGE_EMMC
#ifdef LOSCFG_PLATFORM_PATCHFS
/* Mount patch */
ret = mkdir(PATCH_DIR_NAME, DEFAULT_MOUNT_DIR_MODE);
if ((ret != LOS_OK) && ((err = get_errno()) != EEXIST)) {
PRINT_ERR("Failed to mkdir %s, errno %d: %s\n", PATCH_DIR_NAME, err, strerror(err));
return ret;
}
ret = mount(PATCH_DEV_NAME, PATCH_DIR_NAME, fsType, 0, DEFAULT_MOUNT_DATA);
if ((ret != LOS_OK) && ((err = get_errno()) == ENOTSUP)) {
ret = format(PATCH_DEV_NAME, 0, FM_FAT32);
if (ret != LOS_OK) {
PRINT_ERR("Failed to format %s\n", PATCH_DEV_NAME);
return ret;
}
ret = mount(PATCH_DEV_NAME, PATCH_DIR_NAME, fsType, 0, DEFAULT_MOUNT_DATA);
if (ret != LOS_OK) {
err = get_errno();
}
}
if (ret != LOS_OK) {
PRINT_ERR("Failed to mount %s, errno %d: %s\n", PATCH_DIR_NAME, err, strerror(err));
return ret;
}
#endif
#endif
/* Mount userfs */ /* Mount userfs */
ret = mkdir(STORAGE_DIR_NAME, DEFAULT_MOUNT_DIR_MODE); ret = mkdir(STORAGE_DIR_NAME, DEFAULT_MOUNT_DIR_MODE);
if ((ret != LOS_OK) && ((err = get_errno()) != EEXIST)) { if ((ret != LOS_OK) && ((err = get_errno()) != EEXIST)) {

View File

@ -38,6 +38,9 @@
#define STORAGE_DIR_NAME "/storage" #define STORAGE_DIR_NAME "/storage"
#ifdef LOSCFG_STORAGE_EMMC #ifdef LOSCFG_STORAGE_EMMC
#define USERDATA_DIR_NAME "/userdata" #define USERDATA_DIR_NAME "/userdata"
#ifdef LOSCFG_PLATFORM_PATCHFS
#define PATCH_DIR_NAME "/patch"
#endif
#endif #endif
#define DEFAULT_MOUNT_DIR_MODE 0755 #define DEFAULT_MOUNT_DIR_MODE 0755
#define DEFAULT_MOUNT_DATA NULL #define DEFAULT_MOUNT_DATA NULL
@ -64,11 +67,20 @@
#define USERFS_SIZE (CFIFLASH_CAPACITY - ROOTFS_ADDR - ROOTFS_SIZE) #define USERFS_SIZE (CFIFLASH_CAPACITY - ROOTFS_ADDR - ROOTFS_SIZE)
#elif defined (LOSCFG_STORAGE_EMMC) #elif defined (LOSCFG_STORAGE_EMMC)
#define ROOT_DEV_NAME "/dev/mmcblk0p0" #define ROOT_DEV_NAME "/dev/mmcblk0p0"
#ifdef LOSCFG_PLATFORM_PATCHFS
#define PATCH_DEV_NAME "/dev/mmcblk0p1"
#define USER_DEV_NAME "/dev/mmcblk0p2"
#define USERDATA_DEV_NAME "/dev/mmcblk0p3"
#else
#define USER_DEV_NAME "/dev/mmcblk0p1" #define USER_DEV_NAME "/dev/mmcblk0p1"
#define USERDATA_DEV_NAME "/dev/mmcblk0p2" #define USERDATA_DEV_NAME "/dev/mmcblk0p2"
#endif
#define ROOTFS_ADDR 0xA00000 #define ROOTFS_ADDR 0xA00000
#define ROOTFS_SIZE 0x1400000 #define ROOTFS_SIZE 0x1400000
#define USERFS_SIZE 0x3200000 #define USERFS_SIZE 0x3200000
#ifdef LOSCFG_PLATFORM_PATCHFS
#define PATCH_SIZE 0x200000
#endif
#ifdef DEFAULT_MOUNT_DIR_MODE #ifdef DEFAULT_MOUNT_DIR_MODE
#undef DEFAULT_MOUNT_DIR_MODE #undef DEFAULT_MOUNT_DIR_MODE
#endif #endif