2011-04-29 20:59:40 +00:00
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2011-04-29 23:50:38 +00:00
|
|
|
#include <sys/mount.h>
|
|
|
|
|
2011-04-29 20:59:40 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
2011-04-29 23:50:38 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
2011-05-04 21:59:23 +00:00
|
|
|
#include <dirent.h>
|
2011-04-29 23:50:38 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <crc32.h>
|
2011-05-04 21:59:23 +00:00
|
|
|
#include <debug.h>
|
2011-04-29 20:59:40 +00:00
|
|
|
|
|
|
|
#include <nuttx/mtd.h>
|
2011-10-31 13:16:08 +00:00
|
|
|
#include <nuttx/ioctl.h>
|
2011-04-29 20:59:40 +00:00
|
|
|
#include <nuttx/nxffs.h>
|
|
|
|
|
2011-10-31 13:16:08 +00:00
|
|
|
#if CONFIG_RAMMTD_BLOCKSIZE != 32
|
|
|
|
# error "SetCONFIG_RAMMTD_BLOCKSIZE to 32"
|
2011-05-05 20:01:43 +00:00
|
|
|
#endif
|
2011-05-01 14:48:27 +00:00
|
|
|
|
2011-10-31 13:16:08 +00:00
|
|
|
static int8_t random_data[1068];
|
|
|
|
//static int8_t mtd_ram[4096]; <-- Not enough space for two file copies
|
|
|
|
static int8_t mtd_ram[4096];
|
2011-05-01 14:48:27 +00:00
|
|
|
|
2011-10-31 13:16:08 +00:00
|
|
|
static int brake_nxffs(void)
|
2011-05-01 14:48:27 +00:00
|
|
|
{
|
2011-10-31 13:16:08 +00:00
|
|
|
FAR struct mtd_dev_s * mtd_dev;
|
|
|
|
int ret,i;
|
|
|
|
FILE *config;
|
|
|
|
int32_t size;
|
2011-05-01 14:48:27 +00:00
|
|
|
|
2011-10-31 13:16:08 +00:00
|
|
|
mtd_dev = rammtd_initialize(mtd_ram, sizeof(mtd_ram));
|
|
|
|
if (mtd_dev == NULL)
|
2011-05-01 14:48:27 +00:00
|
|
|
{
|
2011-10-31 13:16:08 +00:00
|
|
|
vdbg("RAM MTD of init failed");
|
2011-05-01 14:48:27 +00:00
|
|
|
}
|
|
|
|
|
2011-10-31 13:16:08 +00:00
|
|
|
ret = nxffs_initialize(mtd_dev);
|
|
|
|
if (ret < 0)
|
2011-05-04 21:59:23 +00:00
|
|
|
{
|
2011-10-31 13:16:08 +00:00
|
|
|
vdbg("ERROR: NXFFS initialization failed: %d\n", -ret);
|
|
|
|
vdbg("errasing it and trying again\n");
|
|
|
|
mtd_dev->ioctl(mtd_dev,MTDIOC_BULKERASE,0);
|
|
|
|
ret = nxffs_initialize(mtd_dev);
|
|
|
|
if(ret <0) return -1; // broke good
|
2011-05-04 21:59:23 +00:00
|
|
|
}
|
|
|
|
|
2011-10-31 13:16:08 +00:00
|
|
|
ret = mount(NULL, "/mnt/nxffs", "nxffs", 0, NULL);
|
|
|
|
if (ret < 0)
|
2011-05-04 21:59:23 +00:00
|
|
|
{
|
2011-10-31 13:16:08 +00:00
|
|
|
dbg("ERROR: Failed to mount the NXFFS volume: %d\n", errno);
|
|
|
|
dbg("%s\n\r",strerror(errno));
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = 0; i<10; i++)
|
|
|
|
{
|
|
|
|
config = fopen("/mnt/nxffs/config","w");
|
|
|
|
ret = fwrite(random_data,sizeof(random_data),1,config);
|
|
|
|
fclose(config);
|
|
|
|
if (ret == 1)
|
|
|
|
dbg("wrote all the data\r\n");
|
|
|
|
else{
|
|
|
|
dbg("ERROR! did not write all the data\r\n");
|
|
|
|
sleep(1);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
config = fopen("/mnt/nxffs/config","r");
|
|
|
|
size = fread(random_data,sizeof(random_data),1,config);
|
|
|
|
if (size == 1)
|
|
|
|
dbg("read the right amount of data\n\r");
|
|
|
|
else{
|
|
|
|
dbg("ERROR! did not read the right amount of data\n\r");
|
|
|
|
sleep(1);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
fclose(config);
|
2011-05-04 21:59:23 +00:00
|
|
|
}
|
2011-10-31 13:16:08 +00:00
|
|
|
return 0;
|
2011-05-04 21:59:23 +00:00
|
|
|
}
|
|
|
|
|
2011-04-29 20:59:40 +00:00
|
|
|
int user_start(int argc, char *argv[])
|
|
|
|
{
|
2011-10-31 13:16:08 +00:00
|
|
|
return brake_nxffs();
|
2011-04-29 20:59:40 +00:00
|
|
|
}
|
|
|
|
|