From e6626d25547e2de83acb722ded829b887be53e57 Mon Sep 17 00:00:00 2001 From: wangchen <253227059@qq.com> Date: Thu, 21 Jul 2022 07:19:36 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=80=82=E9=85=8Dliteos-m=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=B3=BB=E7=BB=9F=E6=9C=80=E6=96=B0=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=20=E3=80=90=E8=83=8C=E6=99=AF=E3=80=91=E9=80=82=E9=85=8Dliteos?= =?UTF-8?q?-m=E6=96=87=E4=BB=B6=E7=B3=BB=E7=BB=9F=E6=9C=80=E6=96=B0?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【修改方案】 1, device目录删除对lfs的直接依赖 2, 完善lfs的初始化流程 【影响】 对现有的产品编译不会有影响。 re #I5HOQ2 Signed-off-by: wangchen --- .../board/driver/flash/ram_virt_flash.c | 18 +++--- .../board/driver/flash/ram_virt_flash.h | 2 + arm_mps2_an386/liteos_m/board/fs/BUILD.gn | 1 - arm_mps2_an386/liteos_m/board/fs/fs_init.c | 50 +++++++++------ .../liteos_m/board/fs/fs_lowlevel.c | 61 ------------------- .../liteos_m/board/fs/fs_lowlevel.h | 56 ----------------- 6 files changed, 45 insertions(+), 143 deletions(-) delete mode 100644 arm_mps2_an386/liteos_m/board/fs/fs_lowlevel.c delete mode 100644 arm_mps2_an386/liteos_m/board/fs/fs_lowlevel.h diff --git a/arm_mps2_an386/liteos_m/board/driver/flash/ram_virt_flash.c b/arm_mps2_an386/liteos_m/board/driver/flash/ram_virt_flash.c index 3061995..c831079 100644 --- a/arm_mps2_an386/liteos_m/board/driver/flash/ram_virt_flash.c +++ b/arm_mps2_an386/liteos_m/board/driver/flash/ram_virt_flash.c @@ -50,12 +50,16 @@ HalLogicPartition g_halPartitions[] = { }, }; +HalLogicPartition *getPartitionInfo(VOID) +{ + return g_halPartitions; +} + INT32 virt_flash_erase(HalPartition pdrv, UINT32 offSet, UINT32 size) { - UINT32 startAddr; + UINT32 startAddr = offSet; UINT32 partitionEnd; - startAddr = g_halPartitions[pdrv].partitionStartAddr + offSet; partitionEnd = g_halPartitions[pdrv].partitionStartAddr + g_halPartitions[pdrv].partitionLength; if (startAddr >= partitionEnd) { printf("flash over erase, 0x%x, 0x%x\r\n", startAddr, partitionEnd); @@ -75,10 +79,9 @@ INT32 virt_flash_erase(HalPartition pdrv, UINT32 offSet, UINT32 size) INT32 virt_flash_write(HalPartition pdrv, UINT32 *offSet, const VOID *buf, UINT32 bufLen) { - UINT32 startAddr; + UINT32 startAddr = *offSet; UINT32 partitionEnd; - startAddr = g_halPartitions[pdrv].partitionStartAddr + *offSet; partitionEnd = g_halPartitions[pdrv].partitionStartAddr + g_halPartitions[pdrv].partitionLength; if (startAddr >= partitionEnd) { printf("flash over write, 0x%x, 0x%x\r\n", startAddr, partitionEnd); @@ -98,10 +101,9 @@ INT32 virt_flash_write(HalPartition pdrv, UINT32 *offSet, const VOID *buf, UINT3 INT32 virt_flash_erase_write(HalPartition pdrv, UINT32 *offSet, const VOID *buf, UINT32 bufLen) { - UINT32 startAddr; + UINT32 startAddr = *offSet; UINT32 partitionEnd; - startAddr = g_halPartitions[pdrv].partitionStartAddr + *offSet; partitionEnd = g_halPartitions[pdrv].partitionStartAddr + g_halPartitions[pdrv].partitionLength; if (startAddr >= partitionEnd) { printf("flash over e&w, 0x%x, 0x%x\r\n", startAddr, partitionEnd); @@ -121,9 +123,9 @@ INT32 virt_flash_erase_write(HalPartition pdrv, UINT32 *offSet, const VOID *buf, INT32 virt_flash_read(HalPartition pdrv, UINT32 *offSet, VOID *buf, UINT32 bufLen) { - UINT32 startAddr; + UINT32 startAddr = *offSet; UINT32 partitionEnd; - startAddr = g_halPartitions[pdrv].partitionStartAddr + *offSet; + partitionEnd = g_halPartitions[pdrv].partitionStartAddr + g_halPartitions[pdrv].partitionLength; if (startAddr >= partitionEnd) { printf("flash over read, 0x%x, 0x%x\r\n", startAddr, partitionEnd); diff --git a/arm_mps2_an386/liteos_m/board/driver/flash/ram_virt_flash.h b/arm_mps2_an386/liteos_m/board/driver/flash/ram_virt_flash.h index aee94f4..3f323d7 100644 --- a/arm_mps2_an386/liteos_m/board/driver/flash/ram_virt_flash.h +++ b/arm_mps2_an386/liteos_m/board/driver/flash/ram_virt_flash.h @@ -49,6 +49,8 @@ typedef struct { UINT32 partitionOptions; } HalLogicPartition; + +HalLogicPartition *getPartitionInfo(VOID); INT32 virt_flash_erase(HalPartition in_partition, UINT32 off_set, UINT32 size); INT32 virt_flash_write(HalPartition in_partition, UINT32 *off_set, const VOID *in_buf, UINT32 in_buf_len); INT32 virt_flash_erase_write(HalPartition in_partition, UINT32 *off_set, const VOID *in_buf, UINT32 in_buf_len); diff --git a/arm_mps2_an386/liteos_m/board/fs/BUILD.gn b/arm_mps2_an386/liteos_m/board/fs/BUILD.gn index 36795fb..c6dde2f 100644 --- a/arm_mps2_an386/liteos_m/board/fs/BUILD.gn +++ b/arm_mps2_an386/liteos_m/board/fs/BUILD.gn @@ -38,7 +38,6 @@ static_library("fs_adapter") { sources = [ "ff_gen_drv.c", "fs_init.c", - "fs_lowlevel.c", ] public_configs = [ ":fs_adapter_config" ] diff --git a/arm_mps2_an386/liteos_m/board/fs/fs_init.c b/arm_mps2_an386/liteos_m/board/fs/fs_init.c index 7b21fcd..9211b9e 100644 --- a/arm_mps2_an386/liteos_m/board/fs/fs_init.c +++ b/arm_mps2_an386/liteos_m/board/fs/fs_init.c @@ -30,46 +30,62 @@ #include "los_config.h" #include "ram_virt_flash.h" +#include "los_fs.h" #if (LOSCFG_SUPPORT_LITTLEFS == 1) #include "fs_lowlevel.h" struct fs_cfg { CHAR *mount_point; - struct lfs_config lfs_cfg; + struct PartitionCfg partCfg; }; -STATIC struct fs_cfg fs[LOSCFG_LFS_MAX_MOUNT_SIZE] = {0}; - INT32 LfsLowLevelInit() { INT32 ret; + struct fs_cfg fs[LOSCFG_LFS_MAX_MOUNT_SIZE] = {0}; + HalLogicPartition *halPartitionsInfo = getPartitionInfo(); + + INT32 lengthArray = halPartitionsInfo[FLASH_PARTITION_DATA0].partitionLength; + INT32 addrArray = halPartitionsInfo[FLASH_PARTITION_DATA0].partitionStartAddr; + ret = LOS_DiskPartition("flash0", "littlefs", &lengthArray, &addrArray, 1); + printf("%s: DiskPartition %s\n", __func__, (ret == 0) ? "succeed" : "failed"); + if (ret != 0) { + return -1; + } fs[0].mount_point = "/littlefs"; - fs[0].lfs_cfg.block_size = 4096; /* 4096, lfs block size */ - fs[0].lfs_cfg.block_count = 2048; /* 2048, lfs block count */ - fs[0].lfs_cfg.context = FLASH_PARTITION_DATA0; - fs[0].lfs_cfg.read = littlefs_block_read; - fs[0].lfs_cfg.prog = littlefs_block_write; - fs[0].lfs_cfg.erase = littlefs_block_erase; - fs[0].lfs_cfg.sync = littlefs_block_sync; + fs[0].partCfg.partNo = FLASH_PARTITION_DATA0; + fs[0].partCfg.blockSize = 4096; /* 4096, lfs block size */ + fs[0].partCfg.blockCount = 2048; /* 2048, lfs block count */ + fs[0].partCfg.readFunc = virt_flash_read; + fs[0].partCfg.writeFunc = virt_flash_write; + fs[0].partCfg.eraseFunc = virt_flash_erase; - fs[0].lfs_cfg.read_size = 256; /* 256, lfs read size */ - fs[0].lfs_cfg.prog_size = 256; /* 256, lfs prog size */ - fs[0].lfs_cfg.cache_size = 256; /* 256, lfs cache size */ - fs[0].lfs_cfg.lookahead_size = 16; /* 16, lfs lookahead size */ - fs[0].lfs_cfg.block_cycles = 1000; /* 1000, lfs block cycles */ + fs[0].partCfg.readSize = 256; /* 256, lfs read size */ + fs[0].partCfg.writeSize = 256; /* 256, lfs prog size */ + fs[0].partCfg.cacheSize = 256; /* 256, lfs cache size */ + fs[0].partCfg.lookaheadSize = 16; /* 16, lfs lookahead size */ + fs[0].partCfg.blockCycles = 1000; /* 1000, lfs block cycles */ - ret = mount(NULL, fs[0].mount_point, "littlefs", 0, &fs[0].lfs_cfg); + ret = LOS_PartitionFormat("flash0", "littlefs", &fs[0].partCfg); + printf("%s: PartitionFormat %s\n", __func__, (ret == 0) ? "succeed" : "failed"); + if (ret != 0) { + return -1; + } + + ret = mount(NULL, fs[0].mount_point, "littlefs", 0, &fs[0].partCfg); printf("%s: mount fs on '%s' %s\n", __func__, fs[0].mount_point, (ret == 0) ? "succeed" : "failed"); if (ret != 0) { return -1; } - ret = mkdir(fs[0].mount_point); + + ret = mkdir(fs[0].mount_point, 0777); /* 0777, set dir permissions */ printf("%s: mkdir '%s' %s\n", __func__, fs[0].mount_point, (ret == 0) ? "succeed" : "failed"); if (ret != 0) { return -1; } + return 0; } #endif diff --git a/arm_mps2_an386/liteos_m/board/fs/fs_lowlevel.c b/arm_mps2_an386/liteos_m/board/fs/fs_lowlevel.c deleted file mode 100644 index 51f0f6d..0000000 --- a/arm_mps2_an386/liteos_m/board/fs/fs_lowlevel.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used - * to endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -#include "ram_virt_flash.h" - -#if (LOSCFG_SUPPORT_LITTLEFS == 1) -#include "fs_lowlevel.h" - -INT32 littlefs_block_read(const struct lfs_config *c, lfs_block_t block, - lfs_off_t off, VOID *dst, lfs_size_t size) -{ - UINT32 addr = c->block_size * block + off; - return virt_flash_read((HalPartition)c->context, &addr, dst, size); -} - -INT32 littlefs_block_write(const struct lfs_config *c, lfs_block_t block, - lfs_off_t off, const VOID *dst, lfs_size_t size) -{ - UINT32 addr = c->block_size * block + off; - return virt_flash_write((HalPartition)c->context, &addr, dst, size); -} - -INT32 littlefs_block_erase(const struct lfs_config *c, lfs_block_t block) -{ - UINT32 addr = c->block_size * block; - return virt_flash_erase((HalPartition)c->context, addr, c->block_size); -} - -INT32 littlefs_block_sync(const struct lfs_config *c) -{ - return 0; -} -#endif diff --git a/arm_mps2_an386/liteos_m/board/fs/fs_lowlevel.h b/arm_mps2_an386/liteos_m/board/fs/fs_lowlevel.h deleted file mode 100644 index 7448973..0000000 --- a/arm_mps2_an386/liteos_m/board/fs/fs_lowlevel.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used - * to endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __FS_LOWLEVEL_H__ -#define __FS_LOWLEVEL_H__ - -#include "los_config.h" - -#if (LOSCFG_SUPPORT_LITTLEFS == 1) -#include "lfs.h" -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -#if (LOSCFG_SUPPORT_LITTLEFS == 1) -INT32 littlefs_block_read(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, VOID *dst, lfs_size_t size); -INT32 littlefs_block_write(const struct lfs_config *c, lfs_block_t block, - lfs_off_t off, const VOID *dst, lfs_size_t size); -INT32 littlefs_block_erase(const struct lfs_config *c, lfs_block_t block); -INT32 littlefs_block_sync(const struct lfs_config *c); -#endif - -#ifdef __cplusplus -} -#endif - -#endif -- Gitee