From c21d3d8a6765387cd1e2afa02383fca4a6d4c3c8 Mon Sep 17 00:00:00 2001 From: Corvus Corax Date: Sat, 8 Nov 2014 12:59:16 +0100 Subject: [PATCH] uncrustification! --- flight/pios/common/pios_logfs.c | 92 ++-- flight/pios/common/pios_trace.c | 8 +- flight/pios/inc/pios_stdio.h | 114 ++--- flight/pios/inc/pios_trace.h | 67 +-- .../posix/libraries/yaffs2/yaffs_nor_drv.c | 416 +++++++++--------- .../posix/libraries/yaffs2/yaffs_nor_drv.h | 2 - .../posix/libraries/yaffs2/yaffs_osglue.c | 134 +++--- .../pios/posix/libraries/yaffs2/yaffscfg2k.c | 138 +++--- flight/pios/posix/libraries/yaffs2/ynorsim.c | 213 ++++----- flight/pios/posix/libraries/yaffs2/ynorsim.h | 2 +- 10 files changed, 595 insertions(+), 591 deletions(-) diff --git a/flight/pios/common/pios_logfs.c b/flight/pios/common/pios_logfs.c index 0d126dab8..842847ac5 100644 --- a/flight/pios/common/pios_logfs.c +++ b/flight/pios/common/pios_logfs.c @@ -55,7 +55,7 @@ static void getObjectPathAndName(uintptr_t fs_id, uint32_t obj_id, uint16_t obj_ #define DEVICENAME_LEN 8 static void getDeviceName(uintptr_t fs_id, char *devicename) { - snprintf((char *)devicename, DEVICENAME_LEN, "/dev%01u", (unsigned) fs_id); + snprintf((char *)devicename, DEVICENAME_LEN, "/dev%01u", (unsigned)fs_id); } /** @@ -69,31 +69,29 @@ static void getLogfsPath(uintptr_t fs_id, char *devicename) snprintf((char *)devicename, LOGFSPATH_LEN, "/dev%01u/logfs", (unsigned)fs_id); } -//Simplistic API takes the fs_id and maps to a path /dev0 eg. not really necessary +// Simplistic API takes the fs_id and maps to a path /dev0 eg. not really necessary // but allows reuse existing API plus new API in parallel without too much conflict int32_t PIOS_FLASHFS_Logfs_Destroy( - __attribute__((unused)) uintptr_t fs_id) + __attribute__((unused)) uintptr_t fs_id) { - pios_DIR *dp; + pios_DIR *dp; struct pios_dirent *ep; char path[LOGFSPATH_LEN]; + getLogfsPath(fs_id, path); pios_trace(PIOS_TRACE_TEST, "PIOS_FLASHFS_Logfs_Destroy"); - dp = pios_opendir (path); - if (dp != NULL) - { - while ((ep = pios_readdir(dp))) { - pios_unlink (ep->d_name); - } - (void) pios_closedir (dp); - } - else - { - pios_trace(PIOS_TRACE_ERROR, "Couldn't open the directory %s.", path); + dp = pios_opendir(path); + if (dp != NULL) { + while ((ep = pios_readdir(dp))) { + pios_unlink(ep->d_name); + } + (void)pios_closedir(dp); + } else { + pios_trace(PIOS_TRACE_ERROR, "Couldn't open the directory %s.", path); } return 0; } @@ -122,11 +120,11 @@ int32_t PIOS_FLASHFS_Logfs_Destroy( * @retval -7 if writing the new object to the filesystem failed */ int32_t PIOS_FLASHFS_ObjSave( - __attribute__((unused)) uintptr_t fs_id, - uint32_t obj_id, - uint16_t obj_inst_id, - uint8_t *obj_data, - uint16_t obj_size) + __attribute__((unused)) uintptr_t fs_id, + uint32_t obj_id, + uint16_t obj_inst_id, + uint8_t *obj_data, + uint16_t obj_size) { int fd; char filename[OBJECTPATHNAME_LEN]; @@ -142,9 +140,8 @@ int32_t PIOS_FLASHFS_ObjSave( pios_trace(PIOS_TRACE_TEST, "pios_open (%s) retval=%d.", filename, fd); if (fd < 0) { - pios_trace(PIOS_TRACE_ERROR, "Couldn't open %s", filename); - } - else { + pios_trace(PIOS_TRACE_ERROR, "Couldn't open %s", filename); + } else { // Append object bytes_written = pios_write(fd, obj_data, obj_size); pios_trace(PIOS_TRACE_TEST, "pios_write bytes_written=%d obj_size=%d", bytes_written, obj_size); @@ -175,11 +172,11 @@ int32_t PIOS_FLASHFS_ObjSave( * @retval -5 if reading the object data from flash fails */ int32_t PIOS_FLASHFS_ObjLoad( - __attribute__((unused)) uintptr_t fs_id, - uint32_t obj_id, - uint16_t obj_inst_id, - uint8_t *obj_data, - uint16_t obj_size) + __attribute__((unused)) uintptr_t fs_id, + uint32_t obj_id, + uint16_t obj_inst_id, + uint8_t *obj_data, + uint16_t obj_size) { int fd; char filename[OBJECTPATHNAME_LEN]; @@ -190,24 +187,24 @@ int32_t PIOS_FLASHFS_ObjLoad( // Get filename getObjectPathAndName(fs_id, obj_id, obj_inst_id, filename); - fd = pios_open(filename,O_RDONLY, S_IREAD | S_IWRITE); + fd = pios_open(filename, O_RDONLY, S_IREAD | S_IWRITE); pios_trace(PIOS_TRACE_TEST, "pios_open (%s) retval=%d.", filename, fd); if (fd < 0) { - pios_trace(PIOS_TRACE_ERROR, "Couldn't open %s", filename); - } - else { + pios_trace(PIOS_TRACE_ERROR, "Couldn't open %s", filename); + } else { // Load object - bytes_read = pios_read(fd, (void *)obj_data, (uint32_t)obj_size); + bytes_read = pios_read(fd, (void *)obj_data, (uint32_t)obj_size); pios_trace(PIOS_TRACE_TEST, "pios_read (%d) expected=%d.", obj_size, bytes_read); // Done, close file and unlock pios_close(fd); } - if (bytes_read != obj_size) + if (bytes_read != obj_size) { return -1; + } return 0; } @@ -223,12 +220,13 @@ int32_t PIOS_FLASHFS_ObjLoad( * @retval -3 if failed to delete the object from the filesystem */ int32_t PIOS_FLASHFS_ObjDelete( - __attribute__((unused)) uintptr_t fs_id, - uint32_t obj_id, - uint16_t obj_inst_id) + __attribute__((unused)) uintptr_t fs_id, + uint32_t obj_id, + uint16_t obj_inst_id) { char filename[OBJECTPATHNAME_LEN]; int retval; + pios_trace(PIOS_TRACE_TEST, "PIOS_FLASHFS_ObjDelete"); // Get filename @@ -236,7 +234,7 @@ int32_t PIOS_FLASHFS_ObjDelete( // Delete file retval = pios_unlink((char *)filename); - pios_trace(PIOS_TRACE_TEST, "pios_unlink(%s) retval=%d" , filename, retval); + pios_trace(PIOS_TRACE_TEST, "pios_unlink(%s) retval=%d", filename, retval); return 0; } @@ -252,9 +250,10 @@ int32_t PIOS_FLASHFS_ObjDelete( * @retval -5 if failed to mount arena 0 */ int32_t PIOS_FLASHFS_Format( - __attribute__((unused)) uintptr_t fs_id) + __attribute__((unused)) uintptr_t fs_id) { int retval; + pios_trace(PIOS_TRACE_TEST, "PIOS_FLASHFS_Format"); // Convert fs_id into device name @@ -262,12 +261,12 @@ int32_t PIOS_FLASHFS_Format( getDeviceName(fs_id, devicename); retval = pios_format(devicename, - TRUE, // unmount flag - TRUE, // force unmount flag - TRUE); // remount + TRUE, // unmount flag + TRUE, // force unmount flag + TRUE); // remount pios_trace(PIOS_TRACE_TEST, "pios_format (%s) retval=%d.", devicename, retval); - return retval; + return retval; } /** @@ -277,17 +276,18 @@ int32_t PIOS_FLASHFS_Format( * @retval -1 if fs_id is not a valid filesystem instance */ int32_t PIOS_FLASHFS_GetStats( - __attribute__((unused)) uintptr_t fs_id, - __attribute__((unused)) struct PIOS_FLASHFS_Stats *stats) + __attribute__((unused)) uintptr_t fs_id, + __attribute__((unused)) struct PIOS_FLASHFS_Stats *stats) { // pios_trace(PIOS_TRACE_TEST, "PIOS_FLASHFS_GetStats"); // Convert fs_id into device name char devicename[DEVICENAME_LEN]; + getDeviceName(fs_id, devicename); // Get yaffs statistics for that device - stats->num_free_slots = yaffs_freespace(devicename); + stats->num_free_slots = yaffs_freespace(devicename); stats->num_active_slots = yaffs_totalspace(devicename) - stats->num_free_slots; // Return device usage statistics diff --git a/flight/pios/common/pios_trace.c b/flight/pios/common/pios_trace.c index a311b7ad0..cb1aa91ae 100644 --- a/flight/pios/common/pios_trace.c +++ b/flight/pios/common/pios_trace.c @@ -26,7 +26,6 @@ */ - #include "pios_trace.h" unsigned pios_trace_mask = 0; @@ -34,12 +33,11 @@ unsigned pios_trace_mask = 0; unsigned pios_set_trace(unsigned tm) { - pios_trace_mask = tm; - return pios_trace_mask; + pios_trace_mask = tm; + return pios_trace_mask; } unsigned pios_get_trace(void) { - return pios_trace_mask; + return pios_trace_mask; } - diff --git a/flight/pios/inc/pios_stdio.h b/flight/pios/inc/pios_stdio.h index 15501acec..79d4fd9a4 100644 --- a/flight/pios/inc/pios_stdio.h +++ b/flight/pios/inc/pios_stdio.h @@ -29,65 +29,65 @@ #include "yaffsfs.h" -#define pios_open(path, oflag, mode) yaffs_open(path, oflag, mode) -#define pios_close(fd) yaffs_close(fd) -#define pios_fsync(fd) yaffs_fsync(fd) -#define pios_flush(fd) yaffs_flush(fd) -#define pios_read(fd, buf, nbyte) yaffs_read(fd, buf, nbyte) -#define pios_write(fd, buf, nbyte) yaffs_write(fd, buf, nbyte) -#define pios_fdatasync(fd) yaffs_fdatasync(fd) -#define pios_access(path, amode) yaffs_access(path, amode) -#define pios_dup(fd) yaffs_dup(fd) -#define pios_pread(fd, buf, nbyte, offset) yaffs_pread(fd, buf, nbyte, offset) -#define pios_pwrite(fd, buf, nbyte, offset) yaffs_pwrite(fd, buf, nbyte, offset) -#define pios_lseek(fd, offset, whence) yaffs_lseek(fd, offset, whence) -#define pios_truncate(path, new_size) yaffs_truncate(path, new_size) -#define pios_ftruncate(fd, new_size) yaffs_ftruncate(fd, new_size) -#define pios_unlink(path) yaffs_unlink(path) -#define pios_rename(oldPath, newPath) yaffs_rename(oldPath, newPath) -#define pios_stat(path, buf) yaffs_stat(path, buf) -#define pios_lstat(path, buf) yaffs_lstat(path, buf) -#define pios_fstat(fd, buf) yaffs_fstat(fd, buf) -#define pios_utime(path, buf) yaffs_utime(path, buf) -#define pios_futime(fd, buf) yaffs_futime(fd, buf) -#define pios_setxattr(path, name, data, size, flags) yaffs_setxattr(path, name, data, size, flags) -#define pios_lsetxattr(path, name, data, size, flags) yaffs_lsetxattr(path, name, data, size, flags) -#define pios_fsetxattr(fd, name, data, size, flags) yaffs_fsetxattr(path, name, data, size, flags) +#define pios_open(path, oflag, mode) yaffs_open(path, oflag, mode) +#define pios_close(fd) yaffs_close(fd) +#define pios_fsync(fd) yaffs_fsync(fd) +#define pios_flush(fd) yaffs_flush(fd) +#define pios_read(fd, buf, nbyte) yaffs_read(fd, buf, nbyte) +#define pios_write(fd, buf, nbyte) yaffs_write(fd, buf, nbyte) +#define pios_fdatasync(fd) yaffs_fdatasync(fd) +#define pios_access(path, amode) yaffs_access(path, amode) +#define pios_dup(fd) yaffs_dup(fd) +#define pios_pread(fd, buf, nbyte, offset) yaffs_pread(fd, buf, nbyte, offset) +#define pios_pwrite(fd, buf, nbyte, offset) yaffs_pwrite(fd, buf, nbyte, offset) +#define pios_lseek(fd, offset, whence) yaffs_lseek(fd, offset, whence) +#define pios_truncate(path, new_size) yaffs_truncate(path, new_size) +#define pios_ftruncate(fd, new_size) yaffs_ftruncate(fd, new_size) +#define pios_unlink(path) yaffs_unlink(path) +#define pios_rename(oldPath, newPath) yaffs_rename(oldPath, newPath) +#define pios_stat(path, buf) yaffs_stat(path, buf) +#define pios_lstat(path, buf) yaffs_lstat(path, buf) +#define pios_fstat(fd, buf) yaffs_fstat(fd, buf) +#define pios_utime(path, buf) yaffs_utime(path, buf) +#define pios_futime(fd, buf) yaffs_futime(fd, buf) +#define pios_setxattr(path, name, data, size, flags) yaffs_setxattr(path, name, data, size, flags) +#define pios_lsetxattr(path, name, data, size, flags) yaffs_lsetxattr(path, name, data, size, flags) +#define pios_fsetxattr(fd, name, data, size, flags) yaffs_fsetxattr(path, name, data, size, flags) -#define pios_getxattr(path, name, data, size) yaffs_getxattr(path, name, data, size) -#define pios_lgetxattr(path, name, data, size) yaffs_lgetxattr(path, name, data, size) -#define pios_fgetxattr(fd, name, data, size) yaffs_fgetxattr(fd, name, data, size) -#define pios_removexattr(path, name) yaffs_removexattr(path, name) -#define pios_lremoveattr(path, name) yaffs_lremovexattr(path, name) -#define pios_fremovexattr(fd, name) yaffs_fremovexattr(fd, name) -#define pios_listxattr(path, list, size) yaffs_listxattr(path, list, size) -#define pios_llistxattr(path, list,size) yaffs_llistxattr(path, list, size) -#define pios_flistxattr(fd, list, size) yaffs_flistxattr(fd, list, size) -#define pios_chmod(path, mode) yaffs_chmod(path, mode) -#define pios_fchmod(fd, mode) yaffs_fchmod(fd, mode) -#define pios_mkdir(path, mode) yaffs_mkdir(path, mode) -#define pios_rmdir(path) yaffs_rmdir(path) -#define pios_opendir(dirname) yaffs_opendir(dirname) -#define pios_readdir(dirp) yaffs_readdir(dirp) -#define pios_rewinddir(dirp) yaffs_rewinddir(dirp) -#define pios_closedir(dirp) yaffs_closedir(dirp) -#define pios_mount(path) yaffs_mount(path) -#define pios_mount2(path, read_only) yaffs_mount2(path, read_only) -#define pios_mount3(path, read_only, skip_checkpt) yaffs_mount3(path, read_only, skip_checkpt) -#define pios_umount(path) yaffs_unmount(path) -#define pios_umount2(path, force) yaffs_unmount2(path, force) -#define pios_remount(path, force, read_only) yaffs_remount(path, force,read_only) -#define pios_format(path, unmount_flag, force_unmount_flag, remount_flag) yaffs_format(path, unmount_flag, force_unmount_flag, remount_flag) -#define pios_sync(path) yaffs_sync(path) -#define pios_symlink(oldpath, newpath) yaffs_symlink(oldpath, newpath) -#define pios_readlink(path, buf, bufsize) yaffs_readlink(path, buf, bufsiz) -#define pios_link(oldpath, newpath) yaffs_link(oldpath, newpath) -#define pios_mknod(pathname, mode, dev) yaffs_mknod(pathname, mode, dev) -#define pios_freespace(path) yaffs_freespace(path) -#define pios_totalspace(path) yaffs_totalspace(path) +#define pios_getxattr(path, name, data, size) yaffs_getxattr(path, name, data, size) +#define pios_lgetxattr(path, name, data, size) yaffs_lgetxattr(path, name, data, size) +#define pios_fgetxattr(fd, name, data, size) yaffs_fgetxattr(fd, name, data, size) +#define pios_removexattr(path, name) yaffs_removexattr(path, name) +#define pios_lremoveattr(path, name) yaffs_lremovexattr(path, name) +#define pios_fremovexattr(fd, name) yaffs_fremovexattr(fd, name) +#define pios_listxattr(path, list, size) yaffs_listxattr(path, list, size) +#define pios_llistxattr(path, list, size) yaffs_llistxattr(path, list, size) +#define pios_flistxattr(fd, list, size) yaffs_flistxattr(fd, list, size) +#define pios_chmod(path, mode) yaffs_chmod(path, mode) +#define pios_fchmod(fd, mode) yaffs_fchmod(fd, mode) +#define pios_mkdir(path, mode) yaffs_mkdir(path, mode) +#define pios_rmdir(path) yaffs_rmdir(path) +#define pios_opendir(dirname) yaffs_opendir(dirname) +#define pios_readdir(dirp) yaffs_readdir(dirp) +#define pios_rewinddir(dirp) yaffs_rewinddir(dirp) +#define pios_closedir(dirp) yaffs_closedir(dirp) +#define pios_mount(path) yaffs_mount(path) +#define pios_mount2(path, read_only) yaffs_mount2(path, read_only) +#define pios_mount3(path, read_only, skip_checkpt) yaffs_mount3(path, read_only, skip_checkpt) +#define pios_umount(path) yaffs_unmount(path) +#define pios_umount2(path, force) yaffs_unmount2(path, force) +#define pios_remount(path, force, read_only) yaffs_remount(path, force, read_only) +#define pios_format(path, unmount_flag, force_unmount_flag, remount_flag) yaffs_format(path, unmount_flag, force_unmount_flag, remount_flag) +#define pios_sync(path) yaffs_sync(path) +#define pios_symlink(oldpath, newpath) yaffs_symlink(oldpath, newpath) +#define pios_readlink(path, buf, bufsize) yaffs_readlink(path, buf, bufsiz) +#define pios_link(oldpath, newpath) yaffs_link(oldpath, newpath) +#define pios_mknod(pathname, mode, dev) yaffs_mknod(pathname, mode, dev) +#define pios_freespace(path) yaffs_freespace(path) +#define pios_totalspace(path) yaffs_totalspace(path) -#define pios_DIR yaffs_DIR -#define pios_dirent yaffs_dirent +#define pios_DIR yaffs_DIR +#define pios_dirent yaffs_dirent #endif /* PIOS_STDIO_H */ diff --git a/flight/pios/inc/pios_trace.h b/flight/pios/inc/pios_trace.h index 28fbd3d97..959c6e17a 100644 --- a/flight/pios/inc/pios_trace.h +++ b/flight/pios/inc/pios_trace.h @@ -34,45 +34,46 @@ extern unsigned int pios_trace_mask; * The flags masked in PIOS_TRACE_ALWAYS are always traced. */ -#define PIOS_TRACE_OS 0x00000002 -#define PIOS_TRACE_ALLOCATE 0x00000004 -#define PIOS_TRACE_TEST 0x00000008 -#define PIOS_TRACE_BAD_BLOCKS 0x00000010 -#define PIOS_TRACE_ERASE 0x00000020 -#define PIOS_TRACE_GC 0x00000040 -#define PIOS_TRACE_WRITE 0x00000080 -#define PIOS_TRACE_TRACING 0x00000100 -#define PIOS_TRACE_DELETION 0x00000200 -#define PIOS_TRACE_BUFFERS 0x00000400 -#define PIOS_TRACE_NANDACCESS 0x00000800 -#define PIOS_TRACE_GC_DETAIL 0x00001000 -#define PIOS_TRACE_SCAN_DEBUG 0x00002000 -#define PIOS_TRACE_MTD 0x00004000 -#define PIOS_TRACE_CHECKPOINT 0x00008000 +#define PIOS_TRACE_OS 0x00000002 +#define PIOS_TRACE_ALLOCATE 0x00000004 +#define PIOS_TRACE_TEST 0x00000008 +#define PIOS_TRACE_BAD_BLOCKS 0x00000010 +#define PIOS_TRACE_ERASE 0x00000020 +#define PIOS_TRACE_GC 0x00000040 +#define PIOS_TRACE_WRITE 0x00000080 +#define PIOS_TRACE_TRACING 0x00000100 +#define PIOS_TRACE_DELETION 0x00000200 +#define PIOS_TRACE_BUFFERS 0x00000400 +#define PIOS_TRACE_NANDACCESS 0x00000800 +#define PIOS_TRACE_GC_DETAIL 0x00001000 +#define PIOS_TRACE_SCAN_DEBUG 0x00002000 +#define PIOS_TRACE_MTD 0x00004000 +#define PIOS_TRACE_CHECKPOINT 0x00008000 -#define PIOS_TRACE_VERIFY 0x00010000 -#define PIOS_TRACE_VERIFY_NAND 0x00020000 -#define PIOS_TRACE_VERIFY_FULL 0x00040000 -#define PIOS_TRACE_VERIFY_ALL 0x000f0000 +#define PIOS_TRACE_VERIFY 0x00010000 +#define PIOS_TRACE_VERIFY_NAND 0x00020000 +#define PIOS_TRACE_VERIFY_FULL 0x00040000 +#define PIOS_TRACE_VERIFY_ALL 0x000f0000 -#define PIOS_TRACE_SYNC 0x00100000 -#define PIOS_TRACE_BACKGROUND 0x00200000 -#define PIOS_TRACE_LOCK 0x00400000 -#define PIOS_TRACE_MOUNT 0x00800000 - -#define PIOS_TRACE_ERROR 0x40000000 -#define PIOS_TRACE_BUG 0x80000000 -#define PIOS_TRACE_ALWAYS 0xf0000000 +#define PIOS_TRACE_SYNC 0x00100000 +#define PIOS_TRACE_BACKGROUND 0x00200000 +#define PIOS_TRACE_LOCK 0x00400000 +#define PIOS_TRACE_MOUNT 0x00800000 +#define PIOS_TRACE_ERROR 0x40000000 +#define PIOS_TRACE_BUG 0x80000000 +#define PIOS_TRACE_ALWAYS 0xf0000000 #ifdef PIOS_TRACE -#define pios_trace(msk, fmt, ...) do { \ - if (pios_trace_mask & (msk)) \ - printf("pios_trace: " fmt "\n", ##__VA_ARGS__); \ -} while (0) +#define pios_trace(msk, fmt, ...) \ + do { \ + if (pios_trace_mask & (msk)) { \ + printf("pios_trace: " fmt "\n",##__VA_ARGS__); } \ + } \ + while (0) #else -#define pios_trace(msk, fmt, ...) +#define pios_trace(msk, fmt, ...) #endif /* Trace control functions */ @@ -80,4 +81,4 @@ unsigned pios_set_trace(unsigned tm); unsigned pios_get_trace(void); -#endif +#endif // ifndef PIOS_TRACE_H diff --git a/flight/pios/posix/libraries/yaffs2/yaffs_nor_drv.c b/flight/pios/posix/libraries/yaffs2/yaffs_nor_drv.c index 7ac108aa2..7c9989a3b 100644 --- a/flight/pios/posix/libraries/yaffs2/yaffs_nor_drv.c +++ b/flight/pios/posix/libraries/yaffs2/yaffs_nor_drv.c @@ -31,22 +31,22 @@ #include "yaffs_guts.h" /* Tunable data */ -#define DATA_BYTES_PER_CHUNK 512 -#define SPARE_BYTES_PER_CHUNK 16 -#define BLOCK_SIZE_IN_BYTES (128*1024) -#define BYTES_IN_DEVICE (4*1024*1024) +#define DATA_BYTES_PER_CHUNK 512 +#define SPARE_BYTES_PER_CHUNK 16 +#define BLOCK_SIZE_IN_BYTES (128 * 1024) +#define BYTES_IN_DEVICE (4 * 1024 * 1024) -#define BYTES_PER_CHUNK (DATA_BYTES_PER_CHUNK + SPARE_BYTES_PER_CHUNK) -#define SPARE_AREA_OFFSET DATA_BYTES_PER_CHUNK -#define CHUNKS_PER_BLOCK (BLOCK_SIZE_IN_BYTES/BYTES_PER_CHUNK) +#define BYTES_PER_CHUNK (DATA_BYTES_PER_CHUNK + SPARE_BYTES_PER_CHUNK) +#define SPARE_AREA_OFFSET DATA_BYTES_PER_CHUNK +#define CHUNKS_PER_BLOCK (BLOCK_SIZE_IN_BYTES / BYTES_PER_CHUNK) -#define BLOCKS_IN_DEVICE (BYTES_IN_DEVICE/BLOCK_SIZE_IN_BYTES) +#define BLOCKS_IN_DEVICE (BYTES_IN_DEVICE / BLOCK_SIZE_IN_BYTES) -#define YNOR_PREMARKER (0xF6) -#define YNOR_POSTMARKER (0xF0) +#define YNOR_PREMARKER (0xF6) +#define YNOR_POSTMARKER (0xF0) -#define FORMAT_OFFSET (CHUNKS_PER_BLOCK * BYTES_PER_CHUNK) -#define FORMAT_VALUE 0x1234 +#define FORMAT_OFFSET (CHUNKS_PER_BLOCK * BYTES_PER_CHUNK) +#define FORMAT_VALUE 0x1234 #if 1 @@ -55,293 +55,295 @@ static struct nor_sim *nor_sim; -#define nor_drv_FlashInit() do {nor_sim = ynorsim_initialise("emfile-nor", BLOCKS_IN_DEVICE, BLOCK_SIZE_IN_BYTES); } while(0) -#define nor_drv_FlashDeinit() ynorsim_shutdown(nor_sim) -#define nor_drv_FlashWrite32(addr,buf,nwords) ynorsim_wr32(nor_sim,addr,buf,nwords) -#define nor_drv_FlashRead32(addr,buf,nwords) ynorsim_rd32(nor_sim,addr,buf,nwords) -#define nor_drv_FlashEraseBlock(addr) ynorsim_erase(nor_sim,addr) -#define DEVICE_BASE ynorsim_get_base(nor_sim) +#define nor_drv_FlashInit() \ + do { nor_sim = ynorsim_initialise("emfile-nor", BLOCKS_IN_DEVICE, BLOCK_SIZE_IN_BYTES); } \ + while (0) +#define nor_drv_FlashDeinit() ynorsim_shutdown(nor_sim) +#define nor_drv_FlashWrite32(addr, buf, nwords) ynorsim_wr32(nor_sim, addr, buf, nwords) +#define nor_drv_FlashRead32(addr, buf, nwords) ynorsim_rd32(nor_sim, addr, buf, nwords) +#define nor_drv_FlashEraseBlock(addr) ynorsim_erase(nor_sim, addr) +#define DEVICE_BASE ynorsim_get_base(nor_sim) #else /* Compile this to hook up to read hardware */ #include "../blob/yflashrw.h" -#define nor_drv_FlashInit() do{} while(0) -#define nor_drv_FlashDeinit() do {} while(0) -#define nor_drv_FlashWrite32(addr,buf,nwords) Y_FlashWrite(addr,buf,nwords) -#define nor_drv_FlashRead32(addr,buf,nwords) Y_FlashRead(addr,buf,nwords) -#define nor_drv_FlashEraseBlock(addr) Y_FlashErase(addr,BLOCK_SIZE_IN_BYTES) -#define DEVICE_BASE (32 * 1024 * 1024) -#endif +#define nor_drv_FlashInit() \ + do {} \ + while (0) +#define nor_drv_FlashDeinit() \ + do {} \ + while (0) +#define nor_drv_FlashWrite32(addr, buf, nwords) Y_FlashWrite(addr, buf, nwords) +#define nor_drv_FlashRead32(addr, buf, nwords) Y_FlashRead(addr, buf, nwords) +#define nor_drv_FlashEraseBlock(addr) Y_FlashErase(addr, BLOCK_SIZE_IN_BYTES) +#define DEVICE_BASE (32 * 1024 * 1024) +#endif /* if 1 */ static u32 *Block2Addr(struct yaffs_dev *dev, int blockNumber) { - u8 *addr; + u8 *addr; - dev=dev; + dev = dev; - addr = (u8*)DEVICE_BASE; - addr += blockNumber * BLOCK_SIZE_IN_BYTES; + addr = (u8 *)DEVICE_BASE; + addr += blockNumber * BLOCK_SIZE_IN_BYTES; - return (u32 *) addr; + return (u32 *)addr; } static u32 *Block2FormatAddr(struct yaffs_dev *dev, int blockNumber) { - u8 *addr; + u8 *addr; - addr = (u8*) Block2Addr(dev,blockNumber); - addr += FORMAT_OFFSET; + addr = (u8 *)Block2Addr(dev, blockNumber); + addr += FORMAT_OFFSET; - return (u32 *)addr; + return (u32 *)addr; } static u32 *Chunk2DataAddr(struct yaffs_dev *dev, int chunk_id) { - unsigned block; - unsigned chunkInBlock; - u8 *addr; + unsigned block; + unsigned chunkInBlock; + u8 *addr; - block = chunk_id/dev->param.chunks_per_block; - chunkInBlock = chunk_id % dev->param.chunks_per_block; + block = chunk_id / dev->param.chunks_per_block; + chunkInBlock = chunk_id % dev->param.chunks_per_block; - addr = (u8*) Block2Addr(dev,block); - addr += chunkInBlock * BYTES_PER_CHUNK; + addr = (u8 *)Block2Addr(dev, block); + addr += chunkInBlock * BYTES_PER_CHUNK; - return (u32 *)addr; + return (u32 *)addr; } static u32 *Chunk2SpareAddr(struct yaffs_dev *dev, int chunk_id) { - u8 *addr; + u8 *addr; - addr = (u8*) Chunk2DataAddr(dev, chunk_id); - addr += SPARE_AREA_OFFSET; - return (u32 *)addr; + addr = (u8 *)Chunk2DataAddr(dev, chunk_id); + addr += SPARE_AREA_OFFSET; + return (u32 *)addr; } -static void nor_drv_AndBytes(u8*target, const u8 *src, int nbytes) +static void nor_drv_AndBytes(u8 *target, const u8 *src, int nbytes) { - while(nbytes > 0){ - *target &= *src; - target++; - src++; - nbytes--; - } + while (nbytes > 0) { + *target &= *src; + target++; + src++; + nbytes--; + } } -static int nor_drv_WriteChunkToNAND(struct yaffs_dev *dev,int nand_chunk, - const u8 *data, int data_len, - const u8 *oob, int oob_len) +static int nor_drv_WriteChunkToNAND(struct yaffs_dev *dev, int nand_chunk, + const u8 *data, int data_len, + const u8 *oob, int oob_len) { - u32 *dataAddr = Chunk2DataAddr(dev,nand_chunk); - u32 *spareAddr = Chunk2SpareAddr(dev,nand_chunk); + u32 *dataAddr = Chunk2DataAddr(dev, nand_chunk); + u32 *spareAddr = Chunk2SpareAddr(dev, nand_chunk); - struct yaffs_spare *spare = (struct yaffs_spare *)oob; - struct yaffs_spare tmpSpare; + struct yaffs_spare *spare = (struct yaffs_spare *)oob; + struct yaffs_spare tmpSpare; - (void) oob_len; + (void)oob_len; - /* We should only be getting called for one of 3 reasons: - * Writing a chunk: data and spare will not be NULL - * Writing a deletion marker: data will be NULL, spare not NULL - * Writing a bad block marker: data will be NULL, spare not NULL + /* We should only be getting called for one of 3 reasons: + * Writing a chunk: data and spare will not be NULL + * Writing a deletion marker: data will be NULL, spare not NULL + * Writing a bad block marker: data will be NULL, spare not NULL + */ + + if (sizeof(struct yaffs_spare) != SPARE_BYTES_PER_CHUNK) { + BUG(); + } + + if (data && oob) { + if (spare->page_status != 0xff) { + BUG(); + } + /* Write a pre-marker */ + memset(&tmpSpare, 0xff, sizeof(tmpSpare)); + tmpSpare.page_status = YNOR_PREMARKER; + nor_drv_FlashWrite32(spareAddr, (u32 *)&tmpSpare, sizeof(struct yaffs_spare) / sizeof(u32)); + + /* Write the data */ + nor_drv_FlashWrite32(dataAddr, (u32 *)data, data_len / sizeof(u32)); + + memcpy(&tmpSpare, spare, sizeof(struct yaffs_spare)); + + /* Write the real tags, but override the premarker*/ + tmpSpare.page_status = YNOR_PREMARKER; + nor_drv_FlashWrite32(spareAddr, (u32 *)&tmpSpare, sizeof(struct yaffs_spare) / sizeof(u32)); + + /* Write a post-marker */ + tmpSpare.page_status = YNOR_POSTMARKER; + nor_drv_FlashWrite32(spareAddr, (u32 *)&tmpSpare, sizeof(tmpSpare) / sizeof(u32)); + } else if (spare) { + /* This has to be a read-modify-write operation to handle NOR-ness */ + + nor_drv_FlashRead32(spareAddr, (u32 *)&tmpSpare, sizeof(struct yaffs_spare) / sizeof(u32)); + + nor_drv_AndBytes((u8 *)&tmpSpare, (u8 *)spare, sizeof(struct yaffs_spare)); + + nor_drv_FlashWrite32(spareAddr, (u32 *)&tmpSpare, sizeof(struct yaffs_spare) / sizeof(u32)); + } else { + BUG(); + } + + return YAFFS_OK; +} + +static int nor_drv_ReadChunkFromNAND(struct yaffs_dev *dev, int nand_chunk, + u8 *data, int data_len, + u8 *oob, int oob_len, + enum yaffs_ecc_result *ecc_result) +{ + struct yaffs_spare *spare = (struct yaffs_spare *)oob; + + u32 *dataAddr = Chunk2DataAddr(dev, nand_chunk); + u32 *spareAddr = Chunk2SpareAddr(dev, nand_chunk); + + if (data) { + nor_drv_FlashRead32(dataAddr, (u32 *)data, dev->param.total_bytes_per_chunk / sizeof(u32)); + } + + if (oob) { + nor_drv_FlashRead32(spareAddr, (u32 *)spare, oob_len / sizeof(u32)); + + /* If the page status is YNOR_POSTMARKER then it was written properly + * so change that to 0xFF so that the rest of yaffs is happy. */ + if (spare->page_status == YNOR_POSTMARKER) { + spare->page_status = 0xff; + } else if (spare->page_status != 0xff && + (spare->page_status | YNOR_PREMARKER) != 0xff) { + spare->page_status = YNOR_PREMARKER; + } + } - if(sizeof(struct yaffs_spare) != SPARE_BYTES_PER_CHUNK) - BUG(); - - if(data && oob) { - if(spare->page_status != 0xff) - BUG(); - /* Write a pre-marker */ - memset(&tmpSpare,0xff,sizeof(tmpSpare)); - tmpSpare.page_status = YNOR_PREMARKER; - nor_drv_FlashWrite32(spareAddr,(u32 *)&tmpSpare,sizeof(struct yaffs_spare)/sizeof(u32)); - - /* Write the data */ - nor_drv_FlashWrite32(dataAddr,(u32 *)data, data_len/ sizeof(u32)); - - memcpy(&tmpSpare,spare,sizeof(struct yaffs_spare)); - - /* Write the real tags, but override the premarker*/ - tmpSpare.page_status = YNOR_PREMARKER; - nor_drv_FlashWrite32(spareAddr,(u32 *)&tmpSpare,sizeof(struct yaffs_spare)/sizeof(u32)); - - /* Write a post-marker */ - tmpSpare.page_status = YNOR_POSTMARKER; - nor_drv_FlashWrite32(spareAddr,(u32 *)&tmpSpare,sizeof(tmpSpare)/sizeof(u32)); - - } else if(spare){ - /* This has to be a read-modify-write operation to handle NOR-ness */ - - nor_drv_FlashRead32(spareAddr,(u32 *)&tmpSpare,sizeof(struct yaffs_spare)/sizeof(u32)); - - nor_drv_AndBytes((u8 *)&tmpSpare,(u8 *)spare,sizeof(struct yaffs_spare)); - - nor_drv_FlashWrite32(spareAddr,(u32 *)&tmpSpare,sizeof(struct yaffs_spare)/sizeof(u32)); - } else { - BUG(); - } - - return YAFFS_OK; -} - -static int nor_drv_ReadChunkFromNAND(struct yaffs_dev *dev,int nand_chunk, - u8 *data, int data_len, - u8 *oob, int oob_len, - enum yaffs_ecc_result *ecc_result) -{ - struct yaffs_spare *spare = (struct yaffs_spare *)oob; - - u32 *dataAddr = Chunk2DataAddr(dev,nand_chunk); - u32 *spareAddr = Chunk2SpareAddr(dev,nand_chunk); - - if (data) { - nor_drv_FlashRead32(dataAddr,(u32 *)data,dev->param.total_bytes_per_chunk / sizeof(u32)); - } - - if (oob) { - nor_drv_FlashRead32(spareAddr,(u32 *)spare, oob_len/ sizeof(u32)); - - /* If the page status is YNOR_POSTMARKER then it was written properly - * so change that to 0xFF so that the rest of yaffs is happy. - */ - if(spare->page_status == YNOR_POSTMARKER) - spare->page_status = 0xff; - else if(spare->page_status != 0xff && - (spare->page_status | YNOR_PREMARKER) != 0xff) - spare->page_status = YNOR_PREMARKER; - } - - if(ecc_result) - *ecc_result = YAFFS_ECC_RESULT_NO_ERROR; - - return YAFFS_OK; + if (ecc_result) { + *ecc_result = YAFFS_ECC_RESULT_NO_ERROR; + } + return YAFFS_OK; } static int nor_drv_FormatBlock(struct yaffs_dev *dev, int blockNumber) { - u32 *blockAddr = Block2Addr(dev,blockNumber); - u32 *formatAddr = Block2FormatAddr(dev,blockNumber); - u32 formatValue = FORMAT_VALUE; + u32 *blockAddr = Block2Addr(dev, blockNumber); + u32 *formatAddr = Block2FormatAddr(dev, blockNumber); + u32 formatValue = FORMAT_VALUE; - nor_drv_FlashEraseBlock(blockAddr); - nor_drv_FlashWrite32(formatAddr,&formatValue,1); + nor_drv_FlashEraseBlock(blockAddr); + nor_drv_FlashWrite32(formatAddr, &formatValue, 1); - return YAFFS_OK; + return YAFFS_OK; } static int nor_drv_UnformatBlock(struct yaffs_dev *dev, int blockNumber) { - u32 *formatAddr = Block2FormatAddr(dev,blockNumber); - u32 formatValue = 0; + u32 *formatAddr = Block2FormatAddr(dev, blockNumber); + u32 formatValue = 0; - nor_drv_FlashWrite32(formatAddr,&formatValue,1); + nor_drv_FlashWrite32(formatAddr, &formatValue, 1); - return YAFFS_OK; + return YAFFS_OK; } static int nor_drv_IsBlockFormatted(struct yaffs_dev *dev, int blockNumber) { - u32 *formatAddr = Block2FormatAddr(dev,blockNumber); - u32 formatValue; + u32 *formatAddr = Block2FormatAddr(dev, blockNumber); + u32 formatValue; - nor_drv_FlashRead32(formatAddr,&formatValue,1); + nor_drv_FlashRead32(formatAddr, &formatValue, 1); - return (formatValue == FORMAT_VALUE); + return formatValue == FORMAT_VALUE; } static int nor_drv_EraseBlockInNAND(struct yaffs_dev *dev, int blockNumber) { - - if(blockNumber < 0 || blockNumber >= BLOCKS_IN_DEVICE) - { - yaffs_trace(YAFFS_TRACE_ALWAYS, - "Attempt to erase non-existant block %d\n", - blockNumber); - return YAFFS_FAIL; - } - else - { - nor_drv_UnformatBlock(dev,blockNumber); - nor_drv_FormatBlock(dev,blockNumber); - return YAFFS_OK; - } - + if (blockNumber < 0 || blockNumber >= BLOCKS_IN_DEVICE) { + yaffs_trace(YAFFS_TRACE_ALWAYS, + "Attempt to erase non-existant block %d\n", + blockNumber); + return YAFFS_FAIL; + } else { + nor_drv_UnformatBlock(dev, blockNumber); + nor_drv_FormatBlock(dev, blockNumber); + return YAFFS_OK; + } } static int nor_drv_InitialiseNAND(struct yaffs_dev *dev) { - int i; + int i; - nor_drv_FlashInit(); - /* Go through the blocks formatting them if they are not formatted */ - for(i = dev->param.start_block; i <= dev->param.end_block; i++){ - if(!nor_drv_IsBlockFormatted(dev,i)){ - nor_drv_FormatBlock(dev,i); - } - } - return YAFFS_OK; + nor_drv_FlashInit(); + /* Go through the blocks formatting them if they are not formatted */ + for (i = dev->param.start_block; i <= dev->param.end_block; i++) { + if (!nor_drv_IsBlockFormatted(dev, i)) { + nor_drv_FormatBlock(dev, i); + } + } + return YAFFS_OK; } static int nor_drv_Deinitialise_flash_fn(struct yaffs_dev *dev) { - dev=dev; + dev = dev; - nor_drv_FlashDeinit(); + nor_drv_FlashDeinit(); - return YAFFS_OK; + return YAFFS_OK; } struct yaffs_dev *yaffs_nor_install_drv(const char *name) { - - struct yaffs_dev *dev = malloc(sizeof(struct yaffs_dev)); - char *name_copy = strdup(name); - struct yaffs_param *param; - struct yaffs_driver *drv; + struct yaffs_dev *dev = malloc(sizeof(struct yaffs_dev)); + char *name_copy = strdup(name); + struct yaffs_param *param; + struct yaffs_driver *drv; - if(!dev || !name_copy) { - free(name_copy); - free(dev); - return NULL; - } + if (!dev || !name_copy) { + free(name_copy); + free(dev); + return NULL; + } - param = &dev->param; - drv = &dev->drv; + param = &dev->param; + drv = &dev->drv; - memset(dev, 0, sizeof(*dev)); + memset(dev, 0, sizeof(*dev)); - param->name = name_copy; + param->name = name_copy; - param->total_bytes_per_chunk = DATA_BYTES_PER_CHUNK; - param->chunks_per_block = CHUNKS_PER_BLOCK; - param->n_reserved_blocks = 2; - param->start_block = 0; // Can use block 0 - param->end_block = BLOCKS_IN_DEVICE - 1; // Last block - param->use_nand_ecc = 0; // use YAFFS's ECC - param->disable_soft_del = 1; + param->total_bytes_per_chunk = DATA_BYTES_PER_CHUNK; + param->chunks_per_block = CHUNKS_PER_BLOCK; + param->n_reserved_blocks = 2; + param->start_block = 0; // Can use block 0 + param->end_block = BLOCKS_IN_DEVICE - 1; // Last block + param->use_nand_ecc = 0; // use YAFFS's ECC + param->disable_soft_del = 1; - drv->drv_write_chunk_fn = nor_drv_WriteChunkToNAND; - drv->drv_read_chunk_fn = nor_drv_ReadChunkFromNAND; - drv->drv_erase_fn = nor_drv_EraseBlockInNAND; - drv->drv_initialise_fn = nor_drv_InitialiseNAND; - drv->drv_deinitialise_fn = nor_drv_Deinitialise_flash_fn; + drv->drv_write_chunk_fn = nor_drv_WriteChunkToNAND; + drv->drv_read_chunk_fn = nor_drv_ReadChunkFromNAND; + drv->drv_erase_fn = nor_drv_EraseBlockInNAND; + drv->drv_initialise_fn = nor_drv_InitialiseNAND; + drv->drv_deinitialise_fn = nor_drv_Deinitialise_flash_fn; - param->n_caches = 10; - param->disable_soft_del = 1; + param->n_caches = 10; + param->disable_soft_del = 1; - dev->driver_context = (void *) nor_sim; + dev->driver_context = (void *)nor_sim; - yaffs_add_device(dev); + yaffs_add_device(dev); - return NULL; + return NULL; } diff --git a/flight/pios/posix/libraries/yaffs2/yaffs_nor_drv.h b/flight/pios/posix/libraries/yaffs2/yaffs_nor_drv.h index f85622330..38695dfb3 100644 --- a/flight/pios/posix/libraries/yaffs2/yaffs_nor_drv.h +++ b/flight/pios/posix/libraries/yaffs2/yaffs_nor_drv.h @@ -21,5 +21,3 @@ struct yaffs_dev; struct yaffs_dev *yaffs_nor_install_drv(const char *name); #endif - - diff --git a/flight/pios/posix/libraries/yaffs2/yaffs_osglue.c b/flight/pios/posix/libraries/yaffs2/yaffs_osglue.c index ab4106a36..1127066dc 100644 --- a/flight/pios/posix/libraries/yaffs2/yaffs_osglue.c +++ b/flight/pios/posix/libraries/yaffs2/yaffs_osglue.c @@ -37,15 +37,15 @@ static int yaffsfs_lastError; void yaffsfs_SetError(int err) { - //Do whatever to set error - yaffsfs_lastError = err; - errno = err; - pios_trace(PIOS_TRACE_ERROR, "yaffsfs_SetError(%d) %s", err, yaffs_error_to_str(err) ); + // Do whatever to set error + yaffsfs_lastError = err; + errno = err; + pios_trace(PIOS_TRACE_ERROR, "yaffsfs_SetError(%d) %s", err, yaffs_error_to_str(err)); } int yaffsfs_GetLastError(void) { - return yaffsfs_lastError; + return yaffsfs_lastError; } /* @@ -57,9 +57,10 @@ int yaffsfs_GetLastError(void) */ int yaffsfs_CheckMemRegion(const void *addr, size_t size, int write_request) { - if(!addr) - return -1; - return 0; + if (!addr) { + return -1; + } + return 0; } /* @@ -80,71 +81,70 @@ static pthread_t bc_gc_thread; void yaffsfs_Lock(void) { - pthread_mutex_lock( &mutex1 ); + pthread_mutex_lock(&mutex1); } void yaffsfs_Unlock(void) { - pthread_mutex_unlock( &mutex1 ); + pthread_mutex_unlock(&mutex1); } static void *bg_gc_func(void *dummy) { - struct yaffs_dev *dev; - int urgent = 0; - int result; - int next_urgent; + struct yaffs_dev *dev; + int urgent = 0; + int result; + int next_urgent; - /* Sleep for a bit to allow start up */ - sleep(2); + /* Sleep for a bit to allow start up */ + sleep(2); - while (1) { - /* Iterate through devices, do bg gc updating ungency */ - yaffs_dev_rewind(); - next_urgent = 0; + while (1) { + /* Iterate through devices, do bg gc updating ungency */ + yaffs_dev_rewind(); + next_urgent = 0; - while ((dev = yaffs_next_dev()) != NULL) { - result = yaffs_do_background_gc_reldev(dev, urgent); - if (result > 0) - next_urgent = 1; - } + while ((dev = yaffs_next_dev()) != NULL) { + result = yaffs_do_background_gc_reldev(dev, urgent); + if (result > 0) { + next_urgent = 1; + } + } - urgent = next_urgent; + urgent = next_urgent; - if (next_urgent) - sleep(1); - else - sleep(5); - } + if (next_urgent) { + sleep(1); + } else { + sleep(5); + } + } - /* Don't ever return. */ - return NULL; + /* Don't ever return. */ + return NULL; } void yaffsfs_LockInit(void) { - /* Initialise lock */ - pthread_mutex_init(&mutex1, NULL); + /* Initialise lock */ + pthread_mutex_init(&mutex1, NULL); - /* Sneak in starting a background gc thread too */ - // pthread_create(&bc_gc_thread, NULL, bg_gc_func, NULL); + /* Sneak in starting a background gc thread too */ + // pthread_create(&bc_gc_thread, NULL, bg_gc_func, NULL); } -#else +#else /* if 1 */ void yaffsfs_Lock(void) -{ -} +{} void yaffsfs_Unlock(void) -{ -} +{} void yaffsfs_LockInit(void) -{ -} -#endif +{} +#endif /* if 1 */ /* * yaffsfs_CurrentTime() retrns a 32-bit timestamp. @@ -154,7 +154,7 @@ void yaffsfs_LockInit(void) u32 yaffsfs_CurrentTime(void) { - return time(NULL); + return time(NULL); } @@ -167,41 +167,45 @@ u32 yaffsfs_CurrentTime(void) #ifdef CONFIG_YAFFS_TEST_MALLOC -static int yaffs_kill_alloc = 0; +static int yaffs_kill_alloc = 0; static size_t total_malloced = 0; -static size_t malloc_limit = 0 & 6000000; +static size_t malloc_limit = 0 & 6000000; void *yaffsfs_malloc(size_t size) { - void * this; - if(yaffs_kill_alloc) - return NULL; - if(malloc_limit && malloc_limit <(total_malloced + size) ) - return NULL; + void *this; - this = malloc(size); - if(this) - total_malloced += size; - return this; + if (yaffs_kill_alloc) { + return NULL; + } + if (malloc_limit && malloc_limit < (total_malloced + size)) { + return NULL; + } + + this = malloc(size); + if (this) { + total_malloced += size; + } + return this; } -#else +#else /* ifdef CONFIG_YAFFS_TEST_MALLOC */ void *yaffsfs_malloc(size_t size) { - return malloc(size); + return malloc(size); } -#endif +#endif /* ifdef CONFIG_YAFFS_TEST_MALLOC */ void yaffsfs_free(void *ptr) { - free(ptr); + free(ptr); } void yaffsfs_OSInitialisation(void) { - yaffsfs_LockInit(); + yaffsfs_LockInit(); } /* @@ -211,7 +215,7 @@ void yaffsfs_OSInitialisation(void) void yaffs_bug_fn(const char *file_name, int line_no) { - printf("yaffs bug detected %s:%d\n", - file_name, line_no); - assert(0); + printf("yaffs bug detected %s:%d\n", + file_name, line_no); + assert(0); } diff --git a/flight/pios/posix/libraries/yaffs2/yaffscfg2k.c b/flight/pios/posix/libraries/yaffs2/yaffscfg2k.c index b6f08e75e..31a055225 100644 --- a/flight/pios/posix/libraries/yaffs2/yaffscfg2k.c +++ b/flight/pios/posix/libraries/yaffs2/yaffscfg2k.c @@ -41,14 +41,14 @@ unsigned yaffs_trace_mask = 0; - //YAFFS_TRACE_ERROR | - //YAFFS_TRACE_BUG | - //YAFFS_TRACE_ALWAYS | - //0; +// YAFFS_TRACE_ERROR | +// YAFFS_TRACE_BUG | +// YAFFS_TRACE_ALWAYS | +// 0; int random_seed; int simulate_power_failure = 0; -static unsigned int pios_flash_device_count=0; +static unsigned int pios_flash_device_count = 0; /* Configure the devices that will be used */ @@ -58,96 +58,95 @@ static unsigned int pios_flash_device_count=0; // called first before device device driver setup so need to change int yaffs_start_up(void) { - static int start_up_called = 0; + static int start_up_called = 0; - if(start_up_called) - return 0; - start_up_called = 1; + if (start_up_called) { + return 0; + } + start_up_called = 1; - /* Call the OS initialisation (eg. set up lock semaphore */ - yaffsfs_OSInitialisation(); + /* Call the OS initialisation (eg. set up lock semaphore */ + yaffsfs_OSInitialisation(); - return 0; + return 0; } - -void yaffsSigHandler ( int sig) +void yaffsSigHandler(int sig) { char devicename[8]; int fs_id; - pios_trace(PIOS_TRACE_TEST, "yaffsSigHandler sig=%d", sig); - switch (sig) - { - case SIGQUIT: - case SIGTERM: - case SIGKILL: - case SIGINT: + pios_trace(PIOS_TRACE_TEST, "yaffsSigHandler sig=%d", sig); + switch (sig) { + case SIGQUIT: + case SIGTERM: + case SIGKILL: + case SIGINT: - for (fs_id =0; fs_id < pios_flash_device_count; fs_id++) - { - snprintf(devicename,6, "/dev%01u", (unsigned) fs_id); - - pios_umount((const char *)devicename); - - } - pios_flash_device_count=0; - exit(1); - break; - default: - break; + for (fs_id = 0; fs_id < pios_flash_device_count; fs_id++) { + snprintf(devicename, 6, "/dev%01u", (unsigned)fs_id); + pios_umount((const char *)devicename); } + pios_flash_device_count = 0; + exit(1); + break; + default: + break; + } } -static void yaffsSigSetup -( -void (*sighandler)(int sig) -) +static void yaffsSigSetup( + void (*sighandler)(int sig)) { - //sigset_t block_sigusr; + // sigset_t block_sigusr; struct sigaction sa; sigemptyset(&sa.sa_mask); - sa.sa_flags = 0; + sa.sa_flags = 0; sa.sa_handler = sighandler; - if (sigaction(SIGQUIT, &sa, NULL)) return; + if (sigaction(SIGQUIT, &sa, NULL)) { + return; + } sigemptyset(&sa.sa_mask); - sa.sa_flags = 0; + sa.sa_flags = 0; sa.sa_handler = sighandler; - if (sigaction(SIGINT , &sa, NULL)) return; + if (sigaction(SIGINT, &sa, NULL)) { + return; + } sigemptyset(&sa.sa_mask); - sa.sa_flags = 0; + sa.sa_flags = 0; sa.sa_handler = sighandler; - if (sigaction(SIGTERM, &sa, NULL)) return; + if (sigaction(SIGTERM, &sa, NULL)) { + return; + } sigemptyset(&sa.sa_mask); - sa.sa_flags = 0; + sa.sa_flags = 0; sa.sa_handler = sighandler; - if (sigaction(SIGKILL, &sa, NULL)) return; - - return; + if (sigaction(SIGKILL, &sa, NULL)) { + return; + } } - - /** * @brief Initialize the flash object setting FS. Each call creates a yaffs device * @return 0 if success, -1 if failure */ int32_t PIOS_FLASHFS_Logfs_Init( - __attribute__((unused)) uintptr_t *fs_id, // return identifier for fs device - __attribute__((unused)) const struct flashfs_logfs_cfg *cfg, //optional - if flash - __attribute__((unused)) const struct pios_flash_driver *driver, //optional - if flash - __attribute__((unused)) uintptr_t flash_id) //optional - if flash + __attribute__((unused)) uintptr_t *fs_id, // return identifier for fs device + __attribute__((unused)) const struct flashfs_logfs_cfg *cfg, // optional - if flash + __attribute__((unused)) const struct pios_flash_driver *driver, // optional - if flash + __attribute__((unused)) uintptr_t flash_id) // optional - if flash { int retval; + pios_trace(PIOS_TRACE_TEST, "PIOS_FLASHFS_Logfs_Init"); char devicename[8]; char logfs_path[12]; @@ -161,34 +160,33 @@ int32_t PIOS_FLASHFS_Logfs_Init( *fs_id = pios_flash_device_count; pios_flash_device_count++; - snprintf(devicename,6, "/dev%01u", (unsigned) *fs_id); + snprintf(devicename, 6, "/dev%01u", (unsigned)*fs_id); - // Simposix implementation uses a ram nor simulation which can be installed + // Simposix implementation uses a ram nor simulation which can be installed // as multiple instances - yaffs_nor_install_drv(devicename); + yaffs_nor_install_drv(devicename); - sigset_t sigset; - sigemptyset(&sigset); - yaffsSigSetup(yaffsSigHandler); + sigset_t sigset; + sigemptyset(&sigset); + yaffsSigSetup(yaffsSigHandler); - // Attempt to mount the device + // Attempt to mount the device retval = pios_mount(devicename); if (retval < 0) { pios_trace(PIOS_TRACE_ERROR, "Couldn't mount %s", devicename); - } - else { - - //Create a "logfs" directory on each yaffs device for use by the - // pios_logfs API. - snprintf(logfs_path, 12, "%s/%s", devicename, PIOS_LOGFS_DIR); + } else { + // Create a "logfs" directory on each yaffs device for use by the + // pios_logfs API. + snprintf(logfs_path, 12, "%s/%s", devicename, PIOS_LOGFS_DIR); // Create the logfs directory if it does not already exist - retval = pios_mkdir(logfs_path, O_CREAT); - if (retval < 0) pios_trace(PIOS_TRACE_ERROR, "Couldn't mkdir %s", logfs_path); + retval = pios_mkdir(logfs_path, O_CREAT); + if (retval < 0) { + pios_trace(PIOS_TRACE_ERROR, "Couldn't mkdir %s", logfs_path); + } } return retval; } - diff --git a/flight/pios/posix/libraries/yaffs2/ynorsim.c b/flight/pios/posix/libraries/yaffs2/ynorsim.c index 654fdc773..378a07324 100644 --- a/flight/pios/posix/libraries/yaffs2/ynorsim.c +++ b/flight/pios/posix/libraries/yaffs2/ynorsim.c @@ -21,42 +21,42 @@ #include "pios_trace.h" -#define YNORSIM_FNAME "emfile-nor" +#define YNORSIM_FNAME "emfile-nor" /* Set YNORSIM_BIT_CHANGES to a a value from 1..30 to - *simulate bit flipping as the programming happens. + * simulate bit flipping as the programming happens. * A low value results in faster simulation with less chance of encountering a partially programmed * word. */ -//#define YNORSIM_BIT_CHANGES 15 -#define YNORSIM_BIT_CHANGES 2 +// #define YNORSIM_BIT_CHANGES 15 +#define YNORSIM_BIT_CHANGES 2 #if 0 /* Simulate 32MB of flash in 256k byte blocks. * This stuff is x32. */ -#define YNORSIM_BLOCK_SIZE_U32 (256*1024/4) -#define YNORSIM_DEV_SIZE_U32 (32*1024 * 1024/4) +#define YNORSIM_BLOCK_SIZE_U32 (256 * 1024 / 4) +#define YNORSIM_DEV_SIZE_U32 (32 * 1024 * 1024 / 4) #else /* Simulate 8MB of flash in 256k byte blocks. * This stuff is x32. */ -#define YNORSIM_BLOCK_SIZE_U32 (256*1024/4) -#define YNORSIM_DEV_SIZE_U32 (8*1024 * 1024/4) +#define YNORSIM_BLOCK_SIZE_U32 (256 * 1024 / 4) +#define YNORSIM_DEV_SIZE_U32 (8 * 1024 * 1024 / 4) #endif struct nor_sim { - int n_blocks; - int block_size_bytes; - int file_size; - u32 *word; - int initialised; - char *fname; - int remaining_ops; - int nops_so_far; + int n_blocks; + int block_size_bytes; + int file_size; + u32 *word; + int initialised; + char *fname; + int remaining_ops; + int nops_so_far; }; int ops_multiplier = 500; @@ -65,146 +65,149 @@ extern int simulate_power_failure; static void NorError(struct nor_sim *sim) { - printf("Nor error on device %s\n", sim->fname); - while (1) { - } + printf("Nor error on device %s\n", sim->fname); + while (1) {} } static void ynorsim_save_image(struct nor_sim *sim) { - int h; - pios_trace(PIOS_TRACE_TEST, "ynorsim_save_image"); - h = open(sim->fname, O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE); - write(h, sim->word, sim->file_size); - close(h); + int h; + + pios_trace(PIOS_TRACE_TEST, "ynorsim_save_image"); + h = open(sim->fname, O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE); + write(h, sim->word, sim->file_size); + close(h); } static void ynorsim_restore_image(struct nor_sim *sim) { - int h; - pios_trace(PIOS_TRACE_TEST, "ynorsim_restore_image"); - h = open(sim->fname, O_RDONLY, S_IREAD | S_IWRITE); - memset(sim->word, 0xFF, sim->file_size); - read(h, sim->word, sim->file_size); - close(h); + int h; + + pios_trace(PIOS_TRACE_TEST, "ynorsim_restore_image"); + h = open(sim->fname, O_RDONLY, S_IREAD | S_IWRITE); + memset(sim->word, 0xFF, sim->file_size); + read(h, sim->word, sim->file_size); + close(h); } static void ynorsim_power_fail(struct nor_sim *sim) { - ynorsim_save_image(sim); - exit(1); + ynorsim_save_image(sim); + exit(1); } static void ynorsim_maybe_power_fail(struct nor_sim *sim) { - sim->nops_so_far++; - sim->remaining_ops--; - if (simulate_power_failure && sim->remaining_ops < 1) { - printf("Simulated power failure after %d operations\n", - sim->nops_so_far); - ynorsim_power_fail(sim); - } + sim->nops_so_far++; + sim->remaining_ops--; + if (simulate_power_failure && sim->remaining_ops < 1) { + printf("Simulated power failure after %d operations\n", + sim->nops_so_far); + ynorsim_power_fail(sim); + } } static void ynorsim_ready(struct nor_sim *sim) { - if (sim->initialised) - return; - srand(random_seed); - sim->remaining_ops = 1000000000; - sim->remaining_ops = - (rand() % 10000) * ops_multiplier * YNORSIM_BIT_CHANGES; - ynorsim_restore_image(sim); - sim->initialised = 1; + if (sim->initialised) { + return; + } + srand(random_seed); + sim->remaining_ops = 1000000000; + sim->remaining_ops = + (rand() % 10000) * ops_multiplier * YNORSIM_BIT_CHANGES; + ynorsim_restore_image(sim); + sim->initialised = 1; } /* Public functions. */ -void ynorsim_rd32(struct nor_sim *sim, u32 * addr, u32 * buf, int nwords) +void ynorsim_rd32(struct nor_sim *sim, u32 *addr, u32 *buf, int nwords) { - sim = sim; - while (nwords > 0) { - *buf = *addr; - buf++; - addr++; - nwords--; - } + sim = sim; + while (nwords > 0) { + *buf = *addr; + buf++; + addr++; + nwords--; + } } -void ynorsim_wr_one_word32(struct nor_sim *sim, u32 * addr, u32 val) +void ynorsim_wr_one_word32(struct nor_sim *sim, u32 *addr, u32 val) { - u32 tmp; - u32 m; - int i; + u32 tmp; + u32 m; + int i; - tmp = *addr; - if (val & ~tmp) { - /* Fail due to trying to change a zero into a 1 */ - printf("attempt to set a zero to one (%x)->(%x)\n", tmp, val); - NorError(sim); - } + tmp = *addr; + if (val & ~tmp) { + /* Fail due to trying to change a zero into a 1 */ + printf("attempt to set a zero to one (%x)->(%x)\n", tmp, val); + NorError(sim); + } - for (i = 0; i < YNORSIM_BIT_CHANGES; i++) { - m = 1 << (rand() & 31); - if (!(m & val)) { - tmp &= ~m; - *addr = tmp; - ynorsim_maybe_power_fail(sim); - } + for (i = 0; i < YNORSIM_BIT_CHANGES; i++) { + m = 1 << (rand() & 31); + if (!(m & val)) { + tmp &= ~m; + *addr = tmp; + ynorsim_maybe_power_fail(sim); + } + } - } - - *addr = tmp & val; - ynorsim_maybe_power_fail(sim); + *addr = tmp & val; + ynorsim_maybe_power_fail(sim); } -void ynorsim_wr32(struct nor_sim *sim, u32 * addr, u32 * buf, int nwords) +void ynorsim_wr32(struct nor_sim *sim, u32 *addr, u32 *buf, int nwords) { - while (nwords > 0) { - ynorsim_wr_one_word32(sim, addr, *buf); - addr++; - buf++; - nwords--; - } + while (nwords > 0) { + ynorsim_wr_one_word32(sim, addr, *buf); + addr++; + buf++; + nwords--; + } } -void ynorsim_erase(struct nor_sim *sim, u32 * addr) +void ynorsim_erase(struct nor_sim *sim, u32 *addr) { - /* Todo... bit flipping */ - pios_trace(PIOS_TRACE_TEST, "ynorsim_erase"); - memset(addr, 0xFF, sim->block_size_bytes); + /* Todo... bit flipping */ + pios_trace(PIOS_TRACE_TEST, "ynorsim_erase"); + memset(addr, 0xFF, sim->block_size_bytes); } struct nor_sim *ynorsim_initialise(char *name, int n_blocks, - int block_size_bytes) + int block_size_bytes) { - struct nor_sim *sim; + struct nor_sim *sim; - sim = malloc(sizeof(*sim)); - if (!sim) - return NULL; + sim = malloc(sizeof(*sim)); + if (!sim) { + return NULL; + } - memset(sim, 0, sizeof(*sim)); - sim->n_blocks = n_blocks; - sim->block_size_bytes = block_size_bytes; - sim->file_size = n_blocks * block_size_bytes; - sim->word = malloc(sim->file_size); - sim->fname = strdup(name); + memset(sim, 0, sizeof(*sim)); + sim->n_blocks = n_blocks; + sim->block_size_bytes = block_size_bytes; + sim->file_size = n_blocks * block_size_bytes; + sim->word = malloc(sim->file_size); + sim->fname = strdup(name); - if(!sim->word) - return NULL; + if (!sim->word) { + return NULL; + } - ynorsim_ready(sim); - return sim; + ynorsim_ready(sim); + return sim; } void ynorsim_shutdown(struct nor_sim *sim) { - ynorsim_save_image(sim); - sim->initialised = 0; + ynorsim_save_image(sim); + sim->initialised = 0; } u32 *ynorsim_get_base(struct nor_sim *sim) { - return sim->word; + return sim->word; } diff --git a/flight/pios/posix/libraries/yaffs2/ynorsim.h b/flight/pios/posix/libraries/yaffs2/ynorsim.h index a51617ec3..1fdaee919 100644 --- a/flight/pios/posix/libraries/yaffs2/ynorsim.h +++ b/flight/pios/posix/libraries/yaffs2/ynorsim.h @@ -25,6 +25,6 @@ void ynorsim_wr32(struct nor_sim *sim, u32 *addr, u32 *data, int nwords); void ynorsim_erase(struct nor_sim *sim, u32 *addr); void ynorsim_shutdown(struct nor_sim *sim); struct nor_sim *ynorsim_initialise(char *name, int n_blocks, int block_size_bytes); -u32 * ynorsim_get_base(struct nor_sim *sim); +u32 *ynorsim_get_base(struct nor_sim *sim); #endif