diff --git a/usrStubs.c b/usrStubs.c index dc0cb66..ad88a7a 100644 --- a/usrStubs.c +++ b/usrStubs.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "config.h" #if defined(INCLUDE_IPFTPS) #include @@ -19,6 +20,9 @@ int usr_ipftps_authenticate_nopasswd(Ipftps_session *session, char *password) #endif +#define VXWORKS_POS (0x400000) +int lfsLowRawWrite(unsigned long offset, const char *buffer, int size); + int loadUserApp() { SEGMENT_ID seg; @@ -43,7 +47,8 @@ int loadUserApp() if (symFind(sysSymTbl, &symDesc) == OK) { appEntry = (void (*)(void))(symDesc.value); printf("AppEntry: %p\r\n", appEntry); - appEntry(); + taskSpawn ("tUserApp", 100, 0, 0x10000, + (FUNCPTR) appEntry,0,0,0,0,0,0,0,0,0,0); } } return 0; @@ -64,3 +69,52 @@ int mw(unsigned long addr, unsigned int val) return 0; } + +int updateVxWorks(const char *file, int pos) +{ + struct stat stbuf; + size_t size; + int fd, status; + unsigned char *ptr; + + if (stat(file, &stbuf) != OK) { + printf("Can't stat %s\r\n", file); + return ERROR; + } + + size = (stbuf.st_size + 0x10000 - 1) / 0x10000; + size *= 0x10000; + ptr = malloc(size); + if (ptr == NULL) { + printf("%s: out of memory\r\n", __FUNCTION__); + return ERROR; + } + + memset(ptr, 0xff, size); + + fd = open(file, O_RDONLY, 0); + if (fd < 0) { + printf("%s: can't open to read\r\n", __FUNCTION__); + free(ptr); + return ERROR; + } + printf("Reading: %d bytes\r\n", stbuf.st_size); + size = read(fd, ptr, stbuf.st_size); + close(fd); + + if (size != stbuf.st_size) { + printf("%s: read size mismatch %d != filesize %d\r\n", __FUNCTION__, size, stbuf.st_size); + free(ptr); + return ERROR; + } + size = (stbuf.st_size + 0x100 - 1) / 0x100; + size *= 0x100; + printf("Write to flash\r\n"); + if (pos <= 0) { + pos = VXWORKS_POS; + } + status = lfsLowRawWrite(pos, ptr, size); + free(ptr); + printf("%s\r\n", status == OK ? "Success" : "Failed"); + return status; +} diff --git a/vxbLfsLib.c b/vxbLfsLib.c index 63360d7..12c1291 100644 --- a/vxbLfsLib.c +++ b/vxbLfsLib.c @@ -561,40 +561,73 @@ void lfsDevRegister(void) (void)vxbDevRegister((struct vxbDevRegInfo *)&lfsDevDriver); } -STATUS lfsFormat(int unit) +LOCAL lfsDrvCtrl * getLfsLowHandle(int unit) { VXB_DEVICE_ID pDev; - lfsDrvCtrl *pDrvCtrl; - + lfsDrvCtrl *pDrvCtrl = NULL; + pDev = vxbInstByNameFind("lfs", unit); if (pDev == NULL) { printf("Can't find lfs%d\n", unit); - return ERROR; + return NULL; } pDrvCtrl = (lfsDrvCtrl *)pDev->pDrvCtrl; if (!pDrvCtrl->mtd) { printf("can't find spiFlash\n"); + return NULL; + } + + return pDrvCtrl; +} + +STATUS lfsFormat(int unit) +{ + lfsDrvCtrl *pDrvCtrl = getLfsLowHandle(unit); + + if (pDrvCtrl == NULL) { return ERROR; } + return lfs_format(&pDrvCtrl->fsh, &pDrvCtrl->lfsConfig); } STATUS lfsMount(int unit) { - VXB_DEVICE_ID pDev; - lfsDrvCtrl *pDrvCtrl; + lfsDrvCtrl *pDrvCtrl = getLfsLowHandle(unit); - pDev = vxbInstByNameFind("lfs", unit); - if (pDev == NULL) { - printf("Can't find lfs%d\n", unit); + if (pDrvCtrl == NULL) { return ERROR; } - pDrvCtrl = (lfsDrvCtrl *)pDev->pDrvCtrl; - if (!pDrvCtrl->mtd) { - printf("can't find spiFlash\n"); + return lfs_mount(&pDrvCtrl->fsh, &pDrvCtrl->lfsConfig); +} + +int lfsLowRawWrite(unsigned long offset, const char *buffer, int size) +{ + lfsDrvCtrl *pDrvCtrl = getLfsLowHandle(0); + int nblocks, block_size; + STATUS ok = OK; + if (pDrvCtrl == NULL) { return ERROR; } - return lfs_mount(&pDrvCtrl->fsh, &pDrvCtrl->lfsConfig); + + semTake(pDrvCtrl->lock, WAIT_FOREVER); + + block_size = pDrvCtrl->mtd->uEraseSize; + if (block_size <= 0) { + block_size = 0x10000; + } + nblocks = (size + block_size - 1) / block_size; + if (pDrvCtrl->mtd->flashOPs.blkErase) { + pDrvCtrl->mtd->flashOPs.blkErase(pDrvCtrl->mtd, offset, nblocks); + } + + if (pDrvCtrl->mtd->flashOPs.write) { + ok = pDrvCtrl->mtd->flashOPs.write(pDrvCtrl->mtd, offset, 1, size, &buffer, NULL); + } + semGive(pDrvCtrl->lock); + + return ok; } + diff --git a/vxbSm2130SpiDev.c b/vxbSm2130SpiDev.c index 8d71088..7fae06e 100644 --- a/vxbSm2130SpiDev.c +++ b/vxbSm2130SpiDev.c @@ -167,7 +167,6 @@ LOCAL SM2310_DEV_HANDLE *drv1553bOpen(SM2310_DEV_HANDLE *dev, const char *name, (void)semTake(pDrvCtrl->muteSem, WAIT_FOREVER); ++pDrvCtrl->refcount; (void)semGive(pDrvCtrl->muteSem); - printf("open: %p\n", dev); return dev; } @@ -178,8 +177,6 @@ LOCAL int drv1553bClose(SM2310_DEV_HANDLE *dev) (void)semTake(pDrvCtrl->muteSem, WAIT_FOREVER); --pDrvCtrl->refcount; (void)semGive(pDrvCtrl->muteSem); - - printf("close: %p\n", dev); return (OK); } @@ -189,8 +186,6 @@ LOCAL int drv1553bIoctl(SM2310_DEV_HANDLE *dev, int cmd, _Vx_ioctl_arg_t arg) SM2130_SPI_DEV *pDrvCtrl = dev->pDevCtrl; STATUS ret = OK; - printf("ioctl: %p\n", dev); - (void)semTake(pDrvCtrl->muteSem, WAIT_FOREVER); switch (cmd) { case FIOSELECT: @@ -202,10 +197,10 @@ LOCAL int drv1553bIoctl(SM2310_DEV_HANDLE *dev, int cmd, _Vx_ioctl_arg_t arg) case FIO_XFER: xfer = (SM2130_XFER *)(arg); switch (xfer->type) { - case FIO_XFER_TX: + case FIO_WR: pDrvCtrl->write(pDrvCtrl->pDev, xfer->reg, xfer->val); break; - case FIO_XFER_RX: + case FIO_RD: xfer->val = pDrvCtrl->read(pDrvCtrl->pDev, xfer->reg); break; default: @@ -214,9 +209,12 @@ LOCAL int drv1553bIoctl(SM2310_DEV_HANDLE *dev, int cmd, _Vx_ioctl_arg_t arg) } break; default: + printf("sm2130 unsupported ioctl: %d\r\n", cmd); + errnoSet(ENOTSUP); + ret = ERROR; break; } - (void)semGive(pDrvCtrl->muteSem); + semGive(pDrvCtrl->muteSem); return (ret); } /* }}} */ diff --git a/vxbSm2130SpiDev.h b/vxbSm2130SpiDev.h index 3561482..a44721f 100644 --- a/vxbSm2130SpiDev.h +++ b/vxbSm2130SpiDev.h @@ -5,8 +5,8 @@ #define SM2310_DEV_NAME "/sm2130" -#define FIO_XFER_TX (1) -#define FIO_XFER_RX (2) +#define FIO_WR (1) +#define FIO_RD (2) #define FIO_XFER (200)