Browse Source

littlefs add autoFormat option

Signed-off-by: surenyi <surenyi82@163.com>
master
surenyi 2 weeks ago
parent
commit
aacfc315a6
  1. 2
      config.h
  2. 6
      hwconf.c
  3. 4
      lfs/lfs.c
  4. 20
      vxbLfsLib.c
  5. 1
      vxbSp25SpiFlash.c

2
config.h

@ -181,7 +181,7 @@ extern "C" {
/* Flash memory configuration */
#define SPI_FLASH_DEVICE_NAME "spiFlash_SM25QU256E"
#define SPI_FLASH_DEVICE_NAME "spiFlash_sp25probe"
#define SZ_32M (0x02000000)
#define SZ_64K (0x00010000)
#define SPI_FLASH_SIZE (SZ_32M)

6
hwconf.c

@ -241,7 +241,7 @@ struct hcfResource ftCanDev2Resources[] = {
struct vxbSpiDevInfo qspiDevTbl[] = {
/* name cs width freq mode */
#ifdef DRV_SPIFLASH_SP25
{ SPI_FLASH_DEVICE_NAME, 0, 8, 30000000, 1},
{ SPI_FLASH_DEVICE_NAME, 0, 8, 18000000, 1},
#endif
};
@ -253,7 +253,6 @@ struct hcfResource qspiResources[] = {
{ "addrMode", HCF_RES_INT, { (void *)(QSPI_ADDR_SEL_4) } },
{ "spiDev", HCF_RES_ADDR, { (void *)&qspiDevTbl[0]} },
{ "spiDevNum", HCF_RES_INT, { (void *)NELEMENTS(qspiDevTbl)}},
};
# define qspiNum NELEMENTS(qspiResources)
#endif /* DRV_FTQSPI */
@ -520,6 +519,7 @@ struct hcfResource lfsResources[] = {
{ "flashName" , HCF_RES_STRING, {(void *)TFFS_PART0_FLASH_NAME}},
{ "flashOffset", HCF_RES_INT, {(void *)(TFFS_PART0_FLASH_BOOT_SIZE)}},
{ "flashSize" , HCF_RES_INT, {(void *)((TFFS_PART0_FLASH_SIZE) - (TFFS_PART0_FLASH_BOOT_SIZE))}},
{ "autoFormat", HCF_RES_INT, {(void *)(1)}},
};
#define lfsResNum NELEMENTS(lfsResources)
#endif
@ -538,8 +538,6 @@ const struct hcfDevice hcfDeviceList[] = {
#endif /* DRV_ARM_GIC */
{ "primeCellSioDev", 0, VXB_BUSID_PLB, 0, primeCellSioDev0Num , primeCellSioDev0Resources },
{ "primeCellSioDev", 1, VXB_BUSID_PLB, 0, primeCellSioDev1Num , primeCellSioDev1Resources },
/* { "primeCellSioDev", 2, VXB_BUSID_PLB, 0, primeCellSioDev2Num , primeCellSioDev2Resources }, */ /* 1553B SPI */
/* { "primeCellSioDev", 3, VXB_BUSID_PLB, 0, primeCellSioDev3Num , primeCellSioDev3Resources }, */
#ifdef DRV_VXBEND_FTGMAC
{ "gmac", 0, VXB_BUSID_PLB, 0, gmac0Num, gmac0Resources},

4
lfs/lfs.c

@ -4577,7 +4577,7 @@ static int lfs_mount_(lfs_t *lfs, const struct lfs_config *cfg) {
}
// scan directory blocks for superblock and any global updates
lfs_mdir_t dir = {0};
lfs_mdir_t dir = {{0}, 0};
dir.tail[0] = 0;
dir.tail[1] = 1;
lfs_block_t tortoise[2] = {LFS_BLOCK_NULL, LFS_BLOCK_NULL};
@ -5374,7 +5374,7 @@ static int lfs_fs_gc_(lfs_t *lfs) {
if (lfs->cfg->compact_thresh
< lfs->cfg->block_size - lfs->cfg->prog_size) {
// iterate over all mdirs
lfs_mdir_t mdir = {0};
lfs_mdir_t mdir = {{0}, 0};
mdir.tail[0] = 0;
mdir.tail[1] = 1;
while (!lfs_pair_isnull(mdir.tail)) {

20
vxbLfsLib.c

@ -51,8 +51,11 @@ struct __lfs_drv_ctrl {
VXB_DEVICE_ID pDev;
/* per-driver info */
void *pDrvCtrl;
char name[16];
const char *mountPoint;
BOOL autoFormat;
const char *flashDrvName;
int flashUnit;
@ -117,8 +120,13 @@ LOCAL void lfsDevInstInit(VXB_DEVICE_ID pDev)
drv->pageSize = 256;
}
if (devResourceGet(pHcf, "autoFormat", HCF_RES_INT, (void *)&drv->autoFormat) != OK) {
drv->autoFormat = 0;
}
if (devResourceGet(pHcf, "mountPoint", HCF_RES_STRING, (void *)&drv->mountPoint) != OK) {
drv->mountPoint = "/lfs0";
snprintf(drv->name, sizeof drv->name, "/lfs%d", pDev->unitNumber);
drv->mountPoint = drv->name;
}
vxbNextUnitGet(pDev);
@ -490,9 +498,15 @@ LOCAL void lfsDevInstConnect(VXB_DEVICE_ID pDev)
}
}
semGive(pDrvCtrl->lock);
if (pDrvCtrl->mtd)
if (pDrvCtrl->mtd) {
int ret;
ret = lfs_mount(&pDrvCtrl->fsh, &pDrvCtrl->lfsConfig);
if ((ret != LFS_ERR_OK) && pDrvCtrl->autoFormat) {
lfs_format(&pDrvCtrl->fsh, &pDrvCtrl->lfsConfig);
lfs_mount(&pDrvCtrl->fsh, &pDrvCtrl->lfsConfig);
}
}
}
LOCAL struct drvBusFuncs lfsDevFuncs = {
lfsDevInstInit, /* devInstanceInit */
@ -628,7 +642,7 @@ int lfsLowRawWrite(unsigned long offset, const char *buffer, int size)
}
if (pDrvCtrl->mtd->flashOPs.write) {
ok = pDrvCtrl->mtd->flashOPs.write(pDrvCtrl->mtd, offset, 1, size, &buffer, NULL);
ok = pDrvCtrl->mtd->flashOPs.write(pDrvCtrl->mtd, offset, 1, size, (UINT8 **)&buffer, NULL);
}
semGive(pDrvCtrl->lock);

1
vxbSp25SpiFlash.c

@ -323,6 +323,7 @@ LOCAL const struct spiFlash_info spiFlashList[] =
{ "sp25probe", 0, 0, 0, 0, 0, 0, 0},
/* KM02 use this flash */
{ "SM25QU256E", 0x20, 0x7019, 0, 256, 64 * 1024, 512, JEDECID_NO_EXT},
{ "GD25LQ256" , 0xc8, 0x6019, 0, 256, 64 * 1024, 512, JEDECID_NO_EXT},
/* SPANSION S25FLXX serials */

Loading…
Cancel
Save