|
|
@ -1,3 +1,4 @@ |
|
|
|
/* vim: set ts=4 sw=4 et fdm=marker: */ |
|
|
|
#include <vxWorks.h> |
|
|
|
#include <stdio.h> |
|
|
|
#include <string.h> |
|
|
@ -7,12 +8,508 @@ |
|
|
|
#include <taskLib.h> |
|
|
|
#include <sysLib.h> |
|
|
|
#include <tickLib.h> |
|
|
|
#include <iosLib.h> |
|
|
|
#include <hwif/vxbus/vxBus.h> |
|
|
|
#include <hwif/vxbus/hwConf.h> |
|
|
|
#include <hwif/vxbus/vxbPlbLib.h> |
|
|
|
#include <hwif/util/hwMemLib.h> |
|
|
|
#include <hwif/util/vxbParamSys.h> |
|
|
|
|
|
|
|
#include <hwif/vxbus/vxbSpiLib.h> |
|
|
|
#include "vxbSp25SpiFlash.h" |
|
|
|
#include <../h/flash/vxbFlash.h> |
|
|
|
#include <../h/flash/vxbFlashCommon.h> |
|
|
|
#include <usrLib.h> |
|
|
|
|
|
|
|
#if !defined(__DCC__) |
|
|
|
#define LFS_THREADSAFE 1 |
|
|
|
#include "lfs/lfs.c" |
|
|
|
#include "lfs/lfs_util.c" |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
typedef struct __lfs_drv_ctrl lfsDrvCtrl; |
|
|
|
typedef struct lfs_ios_drv lfsIosDrv; |
|
|
|
|
|
|
|
struct __lfs_file_descr { |
|
|
|
union { |
|
|
|
lfs_file_t file; |
|
|
|
lfs_dir_t dir; |
|
|
|
} u; |
|
|
|
BOOL isDir; |
|
|
|
lfsDrvCtrl *ctrl; |
|
|
|
}; |
|
|
|
|
|
|
|
typedef struct __lfs_file_descr LFS_FILE_DESC; |
|
|
|
|
|
|
|
struct lfs_ios_drv { |
|
|
|
DEV_HDR devHdr; |
|
|
|
lfsDrvCtrl *pDrvCtrl; |
|
|
|
}; |
|
|
|
|
|
|
|
struct __lfs_drv_ctrl { |
|
|
|
VXB_DEVICE_ID pDev; |
|
|
|
/* per-driver info */ |
|
|
|
void *pDrvCtrl; |
|
|
|
const char *mountPoint; |
|
|
|
|
|
|
|
const char *flashDrvName; |
|
|
|
int flashUnit; |
|
|
|
|
|
|
|
UINT32 flashOffset; |
|
|
|
UINT32 flashSize; |
|
|
|
UINT32 pageSize; |
|
|
|
|
|
|
|
UINT32 blkNum; |
|
|
|
|
|
|
|
int lfsDrvNum; |
|
|
|
|
|
|
|
lfsIosDrv lfsDrv; |
|
|
|
FLASH_CHIP_ID mtd; |
|
|
|
|
|
|
|
struct lfs_config lfsConfig; |
|
|
|
|
|
|
|
SEM_ID lock; |
|
|
|
lfs_t fsh; |
|
|
|
}; |
|
|
|
|
|
|
|
/* {{{ lfsDevFuncs */ |
|
|
|
LOCAL void lfsDevInstInit(VXB_DEVICE_ID pDev) |
|
|
|
{ |
|
|
|
lfsDrvCtrl *drv; |
|
|
|
struct hcfDevice *pHcf; |
|
|
|
|
|
|
|
drv = (lfsDrvCtrl *)hwMemAlloc(sizeof(*drv)); |
|
|
|
if (drv == NULL) { |
|
|
|
return; |
|
|
|
} |
|
|
|
drv->pDrvCtrl = pDev; |
|
|
|
pDev->pDrvCtrl = drv; |
|
|
|
|
|
|
|
drv->mtd = NULL; |
|
|
|
|
|
|
|
pHcf = (struct hcfDevice *)hcfDeviceGet(pDev); |
|
|
|
if (pHcf == NULL) { |
|
|
|
#ifndef _VXBUS_BASIC_HWMEMLIB |
|
|
|
hwMemFree((char *)drv); |
|
|
|
#endif /* _VXBUS_BASIC_HWMEMLIB */ |
|
|
|
pDev->pDrvCtrl = NULL; |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (devResourceGet(pHcf, "flashName", HCF_RES_STRING, (void *)&drv->flashDrvName) != OK) { |
|
|
|
goto err; |
|
|
|
} |
|
|
|
|
|
|
|
if (devResourceGet(pHcf, "flashUnit", HCF_RES_INT, (void *)&drv->flashUnit) != OK) { |
|
|
|
drv->flashUnit = 0; |
|
|
|
} |
|
|
|
|
|
|
|
if (devResourceGet(pHcf, "flashOffset", HCF_RES_INT, (void *)&drv->flashOffset) != OK) { |
|
|
|
drv->flashOffset = 0; |
|
|
|
} |
|
|
|
|
|
|
|
if (devResourceGet(pHcf, "flashSize", HCF_RES_INT, (void *)&drv->flashSize) != OK) { |
|
|
|
drv->flashSize = 0; |
|
|
|
} |
|
|
|
|
|
|
|
if (devResourceGet(pHcf, "pageSize", HCF_RES_INT, (void *)&drv->pageSize) != OK) { |
|
|
|
drv->pageSize = 256; |
|
|
|
} |
|
|
|
|
|
|
|
if (devResourceGet(pHcf, "mountPoint", HCF_RES_STRING, (void *)&drv->mountPoint) != OK) { |
|
|
|
drv->mountPoint = "/lfs0"; |
|
|
|
} |
|
|
|
|
|
|
|
vxbNextUnitGet(pDev); |
|
|
|
return; |
|
|
|
err: |
|
|
|
#ifndef _VXBUS_BASIC_HWMEMLIB |
|
|
|
hwMemFree((char *)drv); |
|
|
|
#endif /* _VXBUS_BASIC_HWMEMLIB */ |
|
|
|
pDev->pDrvCtrl = NULL; |
|
|
|
} |
|
|
|
|
|
|
|
LOCAL void lfsDevInstInit2(VXB_DEVICE_ID pDev) |
|
|
|
{ |
|
|
|
lfsDrvCtrl *pDrvCtrl = (lfsDrvCtrl *)pDev->pDrvCtrl; |
|
|
|
|
|
|
|
pDrvCtrl->lock = semBCreate(SEM_Q_FIFO, SEM_FULL); |
|
|
|
} |
|
|
|
|
|
|
|
/* {{{ lfs handler */ |
|
|
|
LOCAL LFS_FILE_DESC *lfsFuncOpen(lfsIosDrv *dev, const char *name, int flags, int mode) |
|
|
|
{ |
|
|
|
int err; |
|
|
|
LFS_FILE_DESC *ptr; |
|
|
|
|
|
|
|
if (S_ISDIR(mode)) { |
|
|
|
printf("is dir not support\r\n"); |
|
|
|
return (LFS_FILE_DESC *)(ERROR); |
|
|
|
} |
|
|
|
|
|
|
|
printf("mode: %x, flags: %x, name=%p, %c(%s)\r\n", mode, flags, name, name); |
|
|
|
|
|
|
|
ptr = calloc(1, sizeof *ptr); |
|
|
|
if (!ptr) { |
|
|
|
goto end; |
|
|
|
} |
|
|
|
|
|
|
|
ptr->ctrl = dev->pDrvCtrl; |
|
|
|
|
|
|
|
if (name == NULL || name[0] == '\0') { |
|
|
|
err = lfs_dir_open(&ptr->ctrl->fsh, &ptr->u.dir, "."); |
|
|
|
printf("dir_open: %d\r\n", err); |
|
|
|
if (err != LFS_ERR_OK) { |
|
|
|
free(ptr); |
|
|
|
goto end; |
|
|
|
} |
|
|
|
printf("open: %p\r\n", ptr); |
|
|
|
ptr->isDir = 1; |
|
|
|
return ptr; |
|
|
|
} |
|
|
|
|
|
|
|
printf("open: %s\r\n", name); |
|
|
|
|
|
|
|
if (lfs_file_open(&ptr->ctrl->fsh, &ptr->u.file, name, LFS_O_RDWR) == LFS_ERR_OK) { |
|
|
|
return ptr; |
|
|
|
} else { |
|
|
|
free(ptr); |
|
|
|
} |
|
|
|
end: |
|
|
|
return (LFS_FILE_DESC *)(ERROR); |
|
|
|
} |
|
|
|
|
|
|
|
LOCAL int lfsFuncClose(LFS_FILE_DESC *pfd) |
|
|
|
{ |
|
|
|
lfsDrvCtrl *pDrvCtrl = pfd->ctrl; |
|
|
|
|
|
|
|
printf("close: %p\r\n", pfd); |
|
|
|
|
|
|
|
if (pfd->isDir) { |
|
|
|
lfs_dir_close(&pDrvCtrl->fsh, &pfd->u.dir); |
|
|
|
} else { |
|
|
|
lfs_file_close(&pDrvCtrl->fsh, &pfd->u.file); |
|
|
|
} |
|
|
|
free(pfd); |
|
|
|
|
|
|
|
return OK; |
|
|
|
} |
|
|
|
|
|
|
|
LOCAL int lfsFuncIoctl(LFS_FILE_DESC *pfd, int cmd, _Vx_ioctl_arg_t arg) |
|
|
|
{ |
|
|
|
struct stat *stbuf; |
|
|
|
lfsDrvCtrl *pDrvCtrl = pfd->ctrl; |
|
|
|
|
|
|
|
printf("ioctl: %d\r\n", cmd); |
|
|
|
switch (cmd) { |
|
|
|
case FIOFSTATGET: |
|
|
|
stbuf = (struct stat *)(arg); |
|
|
|
stbuf->st_dev = (u_long)&pDrvCtrl->lfsDrv.devHdr; |
|
|
|
stbuf->st_nlink = 1; |
|
|
|
stbuf->st_attrib = 0; |
|
|
|
if (pfd->isDir) { |
|
|
|
stbuf->st_mode = S_IRWXU | S_IRWXG | S_IRWXO | S_IFDIR; |
|
|
|
stbuf->st_size = pDrvCtrl->pageSize; |
|
|
|
stbuf->st_blocks = 1; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
return (OK); |
|
|
|
} |
|
|
|
|
|
|
|
LOCAL ssize_t lfsFuncRead(LFS_FILE_DESC *pfd, char *buffer, size_t maxbytes) |
|
|
|
{ |
|
|
|
lfsDrvCtrl *pDrvCtrl = pfd->ctrl; |
|
|
|
|
|
|
|
printf("read: %p\r\n", pfd); |
|
|
|
if (pfd->isDir) { |
|
|
|
printf("read dir\r\n"); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
return lfs_file_read(&pDrvCtrl->fsh, &pfd->u.file, buffer, maxbytes); |
|
|
|
} |
|
|
|
|
|
|
|
LOCAL ssize_t lfsFuncWrite(LFS_FILE_DESC *pfd, char *buffer, size_t nbytes) |
|
|
|
{ |
|
|
|
lfsDrvCtrl *pDrvCtrl = pfd->ctrl; |
|
|
|
|
|
|
|
printf("write: %p\r\n", pfd); |
|
|
|
if (pfd->isDir) { |
|
|
|
printf("write dir\r\n"); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
return lfs_file_write(&pDrvCtrl->fsh, &pfd->u.file, buffer, nbytes); |
|
|
|
} |
|
|
|
|
|
|
|
LOCAL STATUS lfsFuncRemove(LFS_FILE_DESC *pfd, char *pPath) |
|
|
|
{ |
|
|
|
lfsDrvCtrl *pDrvCtrl = pfd->ctrl; |
|
|
|
|
|
|
|
printf("remove: %s\r\n", pPath); |
|
|
|
lfs_remove(&pDrvCtrl->fsh, pPath); |
|
|
|
|
|
|
|
return OK; |
|
|
|
} |
|
|
|
/* }}} */ |
|
|
|
|
|
|
|
/* {{{ lfs flash operations */ |
|
|
|
LOCAL int lfsFlashRead(const struct lfs_config *cfg, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size) |
|
|
|
{ |
|
|
|
UINT32 pos; |
|
|
|
lfsDrvCtrl *pDrvCtrl = cfg->context; |
|
|
|
UINT8 *buffers[2] = {buffer, NULL}; |
|
|
|
|
|
|
|
pos = pDrvCtrl->flashOffset + block * cfg->block_size + off; |
|
|
|
|
|
|
|
printf("%s: block: %lu, off: %lu, size: %lu, pos: 0x%lx\n", __FUNCTION__, block, off, size, pos); |
|
|
|
|
|
|
|
if (pDrvCtrl->mtd->flashOPs.read(pDrvCtrl->mtd, pos, 1, size, buffers, NULL) == OK) { |
|
|
|
return LFS_ERR_OK; |
|
|
|
} |
|
|
|
return LFS_ERR_IO; |
|
|
|
} |
|
|
|
|
|
|
|
LOCAL int lfsFlashProg(const struct lfs_config *cfg, lfs_block_t block, lfs_off_t off, const void *buffer, |
|
|
|
lfs_size_t size) |
|
|
|
{ |
|
|
|
STATUS r; |
|
|
|
UINT32 pos; |
|
|
|
lfsDrvCtrl *pDrvCtrl = cfg->context; |
|
|
|
UINT8 *buffers[2] = {(void *)buffer, NULL}; |
|
|
|
|
|
|
|
pos = pDrvCtrl->flashOffset + block * cfg->block_size + off; |
|
|
|
|
|
|
|
printf("%s: block: %lu, off: %lu, size: %lu, pos: 0x%lx\n", __FUNCTION__, block, off, size, pos); |
|
|
|
|
|
|
|
r = pDrvCtrl->mtd->flashOPs.write(pDrvCtrl->mtd, pos, 1, size, buffers, NULL); |
|
|
|
printf("prog done: %d\r\n", r); |
|
|
|
|
|
|
|
return r == OK ? LFS_ERR_OK : LFS_ERR_IO; |
|
|
|
} |
|
|
|
|
|
|
|
LOCAL int lfsFlashErase(const struct lfs_config *cfg, lfs_block_t block) |
|
|
|
{ |
|
|
|
UINT32 pos; |
|
|
|
lfsDrvCtrl *pDrvCtrl = cfg->context; |
|
|
|
|
|
|
|
printf("%s: block: %lu\n", __FUNCTION__, block); |
|
|
|
pos = pDrvCtrl->flashOffset + block * cfg->block_size; |
|
|
|
if (pDrvCtrl->mtd->flashOPs.blkErase(pDrvCtrl->mtd, pos, 1) == OK) { |
|
|
|
return LFS_ERR_OK; |
|
|
|
} |
|
|
|
return LFS_ERR_IO; |
|
|
|
} |
|
|
|
|
|
|
|
LOCAL int lfsFlashSync(const struct lfs_config *c) |
|
|
|
{ |
|
|
|
return LFS_ERR_OK; |
|
|
|
} |
|
|
|
|
|
|
|
#ifdef LFS_THREADSAFE |
|
|
|
|
|
|
|
LOCAL int lfsFlashLock(const struct lfs_config *cfg) |
|
|
|
{ |
|
|
|
lfsDrvCtrl *pDrvCtrl = cfg->context; |
|
|
|
|
|
|
|
semTake(pDrvCtrl->lock, WAIT_FOREVER); |
|
|
|
|
|
|
|
return LFS_ERR_OK; |
|
|
|
} |
|
|
|
|
|
|
|
LOCAL int lfsFlashUnlock(const struct lfs_config *cfg) |
|
|
|
{ |
|
|
|
lfsDrvCtrl *pDrvCtrl = cfg->context; |
|
|
|
|
|
|
|
semGive(pDrvCtrl->lock); |
|
|
|
|
|
|
|
return LFS_ERR_OK; |
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
LOCAL void lfsCfgInit(lfsDrvCtrl *drv, FLASH_CHIP_ID flash) |
|
|
|
{ |
|
|
|
int buffer_size = flash->uPageSize > 0 ? flash->uPageSize : drv->pageSize; |
|
|
|
|
|
|
|
memset(&drv->lfsConfig, 0, sizeof drv->lfsConfig); |
|
|
|
|
|
|
|
drv->lfsConfig.context = drv; |
|
|
|
drv->lfsConfig.read = lfsFlashRead; |
|
|
|
drv->lfsConfig.prog = lfsFlashProg; |
|
|
|
drv->lfsConfig.erase = lfsFlashErase; |
|
|
|
drv->lfsConfig.sync = lfsFlashSync; |
|
|
|
|
|
|
|
drv->lfsConfig.read_size = buffer_size; |
|
|
|
drv->lfsConfig.prog_size = buffer_size; |
|
|
|
|
|
|
|
drv->lfsConfig.block_size = flash->uEraseSize; |
|
|
|
drv->lfsConfig.block_count = drv->blkNum; |
|
|
|
|
|
|
|
drv->lfsConfig.cache_size = buffer_size; |
|
|
|
drv->lfsConfig.lookahead_size = flash->uEraseSize / 8; |
|
|
|
|
|
|
|
drv->lfsConfig.block_cycles = 100; |
|
|
|
#ifdef LFS_THREADSAFE |
|
|
|
drv->lfsConfig.lock = lfsFlashLock; |
|
|
|
drv->lfsConfig.unlock = lfsFlashUnlock; |
|
|
|
#endif |
|
|
|
} |
|
|
|
/* }}} */ |
|
|
|
|
|
|
|
LOCAL void lfsDevInstConnect(VXB_DEVICE_ID pDev) |
|
|
|
{ |
|
|
|
lfsDrvCtrl *pDrvCtrl; |
|
|
|
VXB_DEVICE_ID pFlashDev; |
|
|
|
FLASH_CHIP_ID (*flashChipInfoGet)(VXB_DEVICE_ID pDev, UINT32 chipId); |
|
|
|
|
|
|
|
pDrvCtrl = (lfsDrvCtrl *)pDev->pDrvCtrl; |
|
|
|
|
|
|
|
pFlashDev = vxbInstByNameFind((char *)pDrvCtrl->flashDrvName, pDrvCtrl->flashUnit); |
|
|
|
if (!pFlashDev) { |
|
|
|
return; |
|
|
|
} |
|
|
|
semTake(pDrvCtrl->lock, WAIT_FOREVER); |
|
|
|
flashChipInfoGet = (void *)vxbDevMethodGet(pFlashDev, DEVMETHOD_CALL(vxbFlashChipInfoGet)); |
|
|
|
pDrvCtrl->mtd = flashChipInfoGet(pFlashDev, 0); |
|
|
|
if (pDrvCtrl->mtd) { |
|
|
|
if (pDrvCtrl->flashSize <= 0) { |
|
|
|
pDrvCtrl->flashSize = pDrvCtrl->mtd->uChipSize - pDrvCtrl->flashOffset; |
|
|
|
} |
|
|
|
pDrvCtrl->blkNum = pDrvCtrl->flashSize / pDrvCtrl->mtd->uEraseSize; |
|
|
|
|
|
|
|
/* clang-format off */ |
|
|
|
pDrvCtrl->lfsDrvNum = iosDrvInstall( |
|
|
|
(DRV_CREATE_PTR) lfsFuncOpen, |
|
|
|
(DRV_REMOVE_PTR) lfsFuncRemove, |
|
|
|
(DRV_OPEN_PTR) lfsFuncOpen, |
|
|
|
(DRV_CLOSE_PTR) lfsFuncClose, |
|
|
|
(DRV_READ_PTR) lfsFuncRead, |
|
|
|
(DRV_WRITE_PTR) lfsFuncWrite, |
|
|
|
(DRV_IOCTL_PTR) lfsFuncIoctl |
|
|
|
); |
|
|
|
/* clang-format on */ |
|
|
|
if (pDrvCtrl->lfsDrvNum > 0) { |
|
|
|
if (iosDevAdd(&pDrvCtrl->lfsDrv.devHdr, pDrvCtrl->mountPoint, pDrvCtrl->lfsDrvNum) == OK) { |
|
|
|
pDrvCtrl->lfsDrv.pDrvCtrl = pDrvCtrl; |
|
|
|
lfsCfgInit(pDrvCtrl, pDrvCtrl->mtd); |
|
|
|
} else { |
|
|
|
pDrvCtrl->mtd = NULL; |
|
|
|
} |
|
|
|
} else { |
|
|
|
pDrvCtrl->mtd = NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
semGive(pDrvCtrl->lock); |
|
|
|
if (pDrvCtrl->mtd) |
|
|
|
lfs_mount(&pDrvCtrl->fsh, &pDrvCtrl->lfsConfig); |
|
|
|
} |
|
|
|
|
|
|
|
LOCAL struct drvBusFuncs lfsDevFuncs = { |
|
|
|
lfsDevInstInit, /* devInstanceInit */ |
|
|
|
lfsDevInstInit2, /* devInstanceInit2 */ |
|
|
|
lfsDevInstConnect /* devConnect */ |
|
|
|
}; |
|
|
|
/* }}} */ |
|
|
|
|
|
|
|
/* {{{ lfsMethods */ |
|
|
|
LOCAL void lfsDevShow(VXB_DEVICE_ID pDev, int verbose) |
|
|
|
{ |
|
|
|
lfsDrvCtrl *pDrvCtrl = (lfsDrvCtrl *)pDev->pDrvCtrl; |
|
|
|
printf(" %s unit %d on %s @ 0x%08x", pDev->pName, pDev->unitNumber, vxbBusTypeString(pDev->busID), pDev); |
|
|
|
printf(" with busInfo %p\n", pDev->u.pSubordinateBus); |
|
|
|
|
|
|
|
if (verbose) { |
|
|
|
printf(" mountPoint: %s\n", pDrvCtrl->mountPoint); |
|
|
|
printf(" flashName: %s\n", pDrvCtrl->flashDrvName); |
|
|
|
printf(" mtd: %p\n", pDrvCtrl->mtd); |
|
|
|
printf(" read_size: %d\n", pDrvCtrl->lfsConfig.read_size); |
|
|
|
printf(" prog_size: %d\n", pDrvCtrl->lfsConfig.prog_size); |
|
|
|
printf(" block_size: %d\n", pDrvCtrl->lfsConfig.block_size); |
|
|
|
if (pDrvCtrl->mtd) { |
|
|
|
printf(" flashChip: %s\n", pDrvCtrl->mtd->chipName); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
LOCAL STATUS lfsDevInstUnlink(VXB_DEVICE_ID pDev, void *unused) |
|
|
|
{ |
|
|
|
lfsDrvCtrl *pDrvCtrl = (lfsDrvCtrl *)pDev->pDrvCtrl; |
|
|
|
|
|
|
|
/* Check for vaild parameter */ |
|
|
|
VXB_ASSERT_NONNULL_V(pDev); |
|
|
|
|
|
|
|
#ifndef _VXBUS_BASIC_HWMEMLIB |
|
|
|
hwMemFree((char *)pDrvCtrl); |
|
|
|
#endif /* _VXBUS_BASIC_HWMEMLIB */ |
|
|
|
pDev->pDrvCtrl = NULL; |
|
|
|
|
|
|
|
return OK; |
|
|
|
} |
|
|
|
/* }}} */ |
|
|
|
|
|
|
|
/* Publish the methods for the resources controlled with this file */ |
|
|
|
/* clang-format off */ |
|
|
|
LOCAL struct vxbDeviceMethod lfsDevMethods[] = { |
|
|
|
DEVMETHOD(busDevShow , lfsDevShow), |
|
|
|
DEVMETHOD(vxbDrvUnlink, lfsDevInstUnlink), |
|
|
|
{ 0, 0 } |
|
|
|
}; |
|
|
|
|
|
|
|
LOCAL struct vxbSpiRegister lfsDevDriver = { |
|
|
|
{ |
|
|
|
NULL, /* pNext */ |
|
|
|
VXB_DEVID_DEVICE, /* devID */ |
|
|
|
VXB_BUSID_PLB, /* busID */ |
|
|
|
VXBUS_VERSION_5, /* vxbVersion */ |
|
|
|
"lfs", /* drvName */ |
|
|
|
&lfsDevFuncs, /* pDrvBusFuncs */ |
|
|
|
lfsDevMethods, /* pMethods */ |
|
|
|
NULL, /* devProbe */ |
|
|
|
NULL, /* pParamDefaults */ |
|
|
|
}, |
|
|
|
}; |
|
|
|
/* clang-format on */ |
|
|
|
|
|
|
|
void lfsDevRegister(void) |
|
|
|
{ |
|
|
|
(void)vxbDevRegister((struct vxbDevRegInfo *)&lfsDevDriver); |
|
|
|
} |
|
|
|
|
|
|
|
STATUS lfsFormat(int unit) |
|
|
|
{ |
|
|
|
VXB_DEVICE_ID pDev; |
|
|
|
lfsDrvCtrl *pDrvCtrl; |
|
|
|
|
|
|
|
pDev = vxbInstByNameFind("lfs", unit); |
|
|
|
if (pDev == NULL) { |
|
|
|
printf("Can't find lfs%d\n", unit); |
|
|
|
return ERROR; |
|
|
|
} |
|
|
|
|
|
|
|
pDrvCtrl = (lfsDrvCtrl *)pDev->pDrvCtrl; |
|
|
|
if (!pDrvCtrl->mtd) { |
|
|
|
printf("mtd is null\n"); |
|
|
|
return ERROR; |
|
|
|
} |
|
|
|
return lfs_format(&pDrvCtrl->fsh, &pDrvCtrl->lfsConfig); |
|
|
|
} |
|
|
|
|
|
|
|
STATUS lfsMount(int unit) |
|
|
|
{ |
|
|
|
VXB_DEVICE_ID pDev; |
|
|
|
lfsDrvCtrl *pDrvCtrl; |
|
|
|
|
|
|
|
pDev = vxbInstByNameFind("lfs", unit); |
|
|
|
if (pDev == NULL) { |
|
|
|
printf("Can't find lfs%d\n", unit); |
|
|
|
return ERROR; |
|
|
|
} |
|
|
|
|
|
|
|
pDrvCtrl = (lfsDrvCtrl *)pDev->pDrvCtrl; |
|
|
|
if (!pDrvCtrl->mtd) { |
|
|
|
printf("mtd is null\n"); |
|
|
|
return ERROR; |
|
|
|
} |
|
|
|
return lfs_mount(&pDrvCtrl->fsh, &pDrvCtrl->lfsConfig); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|