[PATCH rtems6 - v2 00/16] Overwork flashdev
From: Bernd Moessner Hi, here`s the revised patch set. Patches 1-5 have not been disputed and are therefore untouched. I only added the issue reference to the comment line. I`ve choosen to not rename "min. write block size" and "region". In addition to that I kept the "region" mechanics i.e. having only set and unset. Calling set two times still updates the current region. Nevertheless there is a lot of refactoring wrt. aligning IOCTL and function names / making their names a bit more descriptive by adding "GET/get" where appropriate. Apart from that: * Some bugfixes like the wrong address computation when returing from read / write (happened only in case a region is set) * As Kinsey recommended I`ve added the information on the erase block size to the page info instead of creating a new IOCTL. * The region create and update command now check if the region is aligned to the erase block size. * The write function checks if address / length are aligned to min. write block size (if it is !=0) We still need Aaron for review, but the API change is much smaller in this patch set compared to the previous one. Therefore, I hope we can resolve this issue soon. Regards Bernd Bernd Moessner (16): flashdev.h: Add missing C++ include guards flashdev: Unify IOCTL macro names flashdev: Align IOCTL function and macro names flashdev: Align IOCTL and shell function names flashdev: Add missing default case flashdev.c: return error in case neither read nor write buffer was provided flashdev: fix wrong offset assignment flashdev: add function to deregister and update test case flashdev: Refactor RTEMS_FLASHDEV_IOCTL_GET_WRITE_BLOCK_SIZE flashdev testsuite: Allow testsuite to set the min. write block size flashdev testsuite: allow page size and count to be set from testcase flashdev: Add erase info to page info flashdev: erase function must take erase size and alignment into account flashdev: create region only if it is aligned to erase size flashdev: Refactor IOCTL defines into enum flashdev: disallow writes that do not match alignment / req. length cpukit/dev/flash/flashdev.c | 196 + cpukit/include/dev/flash/flashdev.h | 88 -- cpukit/libmisc/shell/main_flashdev.c | 83 +++--- testsuites/libtests/flashdev01/init.c | 269 +- .../libtests/flashdev01/test_flashdev.c | 161 --- .../libtests/flashdev01/test_flashdev.h | 9 +- 6 files changed, 580 insertions(+), 226 deletions(-) -- 2.34.1 ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
[PATCH rtems6 - v2 01/16] flashdev.h: Add missing C++ include guards
From: Bernd Moessner Updates #4981 --- cpukit/include/dev/flash/flashdev.h | 9 + 1 file changed, 9 insertions(+) diff --git a/cpukit/include/dev/flash/flashdev.h b/cpukit/include/dev/flash/flashdev.h index d1dc08a5c4..6759357206 100644 --- a/cpukit/include/dev/flash/flashdev.h +++ b/cpukit/include/dev/flash/flashdev.h @@ -39,6 +39,11 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + + typedef struct rtems_flashdev rtems_flashdev; /** @@ -454,6 +459,10 @@ void rtems_flashdev_destroy_and_free( rtems_flashdev *flash ); +#ifdef __cplusplus +} +#endif + /** @} */ #endif /* _DEV_FLASHDEV_H */ -- 2.34.1 ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
[PATCH rtems6 - v2 02/16] flashdev: Unify IOCTL macro names
From: Bernd Moessner Updates #4981 --- cpukit/dev/flash/flashdev.c | 16 cpukit/include/dev/flash/flashdev.h | 16 cpukit/libmisc/shell/main_flashdev.c | 12 ++-- testsuites/libtests/flashdev01/init.c | 16 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/cpukit/dev/flash/flashdev.c b/cpukit/dev/flash/flashdev.c index be85593201..40666290e0 100644 --- a/cpukit/dev/flash/flashdev.c +++ b/cpukit/dev/flash/flashdev.c @@ -362,32 +362,32 @@ static int rtems_flashdev_ioctl( rtems_flashdev_release( flash ); err = 0; break; -case RTEMS_FLASHDEV_IOCTL_JEDEC_ID: +case RTEMS_FLASHDEV_IOCTL_GET_JEDEC_ID: *( (uint32_t *) arg ) = rtems_flashdev_ioctl_jedec_id( flash ); err = 0; break; case RTEMS_FLASHDEV_IOCTL_ERASE: err = rtems_flashdev_ioctl_erase( flash, iop, arg ); break; -case RTEMS_FLASHDEV_IOCTL_REGION_SET: +case RTEMS_FLASHDEV_IOCTL_SET_REGION: err = rtems_flashdev_ioctl_set_region( flash, iop, arg ); break; -case RTEMS_FLASHDEV_IOCTL_REGION_UNSET: +case RTEMS_FLASHDEV_IOCTL_UNSET_REGION: err = rtems_flashdev_ioctl_clear_region( flash, iop ); break; -case RTEMS_FLASHDEV_IOCTL_TYPE: +case RTEMS_FLASHDEV_IOCTL_GET_TYPE: err = rtems_flashdev_ioctl_flash_type( flash, arg ); break; -case RTEMS_FLASHDEV_IOCTL_PAGEINFO_BY_OFFSET: +case RTEMS_FLASHDEV_IOCTL_GET_PAGEINFO_BY_OFFSET: err = rtems_flashdev_ioctl_pageinfo_offset( flash, arg ); break; -case RTEMS_FLASHDEV_IOCTL_PAGEINFO_BY_INDEX: +case RTEMS_FLASHDEV_IOCTL_GET_PAGEINFO_BY_INDEX: err = rtems_flashdev_ioctl_pageinfo_index( flash, arg ); break; -case RTEMS_FLASHDEV_IOCTL_PAGE_COUNT: +case RTEMS_FLASHDEV_IOCTL_GET_PAGE_COUNT: err = rtems_flashdev_ioctl_page_count( flash, arg ); break; -case RTEMS_FLASHDEV_IOCTL_WRITE_BLOCK_SIZE: +case RTEMS_FLASHDEV_IOCTL_GET_WRITE_BLOCK_SIZE: err = rtems_flashdev_ioctl_write_block_size( flash, arg ); break; } diff --git a/cpukit/include/dev/flash/flashdev.h b/cpukit/include/dev/flash/flashdev.h index 6759357206..59028a8cba 100644 --- a/cpukit/include/dev/flash/flashdev.h +++ b/cpukit/include/dev/flash/flashdev.h @@ -77,7 +77,7 @@ typedef struct rtems_flashdev rtems_flashdev; * @param[out] jedec_id Pointer to uint32_t in which the JEDEC ID is * returned in. */ -#define RTEMS_FLASHDEV_IOCTL_JEDEC_ID 2 +#define RTEMS_FLASHDEV_IOCTL_GET_JEDEC_ID 2 /** * @brief Erases flash device. * @@ -94,20 +94,20 @@ typedef struct rtems_flashdev rtems_flashdev; * @param[in] region Pointer to rtems_flashdev_region struct containing * base and length of defined region. */ -#define RTEMS_FLASHDEV_IOCTL_REGION_SET 4 +#define RTEMS_FLASHDEV_IOCTL_SET_REGION 4 /** * @brief Removes the set region on the file descriptor. * * This command has no argument. */ -#define RTEMS_FLASHDEV_IOCTL_REGION_UNSET 5 +#define RTEMS_FLASHDEV_IOCTL_UNSET_REGION 5 /** * @brief Returns the type of flash device (e.g. NOR or NAND). * * @param[out] flash_type Pointer to integer which is set to the flash * type macro value. */ -#define RTEMS_FLASHDEV_IOCTL_TYPE 6 +#define RTEMS_FLASHDEV_IOCTL_GET_TYPE 6 /** * @brief Get the size and address of flash page at given offset @@ -118,7 +118,7 @@ typedef struct rtems_flashdev rtems_flashdev; * @param[in,out] rtems_flashdev_ioctl_page_info arg Pointer to struct * with offset and space for return values. */ -#define RTEMS_FLASHDEV_IOCTL_PAGEINFO_BY_OFFSET 7 +#define RTEMS_FLASHDEV_IOCTL_GET_PAGEINFO_BY_OFFSET 7 /** * @brief Get the size and address of nth flash page where n is index passed in. @@ -128,21 +128,21 @@ typedef struct rtems_flashdev rtems_flashdev; * @param[in,out] rtems_flashdev_ioctl_page_info arg Pointer to struct * with index and space for return values. */ -#define RTEMS_FLASHDEV_IOCTL_PAGEINFO_BY_INDEX 8 +#define RTEMS_FLASHDEV_IOCTL_GET_PAGEINFO_BY_INDEX 8 /** * @brief Get the number of pages in flash device. * * @param[out] count Integer containing the number of pages. */ -#define RTEMS_FLASHDEV_IOCTL_PAGE_COUNT 9 +#define RTEMS_FLASHDEV_IOCTL_GET_PAGE_COUNT 9 /** * @brief Get the minimum write size supported by the driver. * * @param[out] count Integer containing the minimum write size. */ -#define RTEMS_FLASHDEV_IOCTL_WRITE_BLOCK_SIZE 10 +#define RTEMS_FLASHDEV_IOCTL_GET_WRITE_BLOCK_SIZE 10 /** * @brief The maximum number of region limited file descriptors diff --git a/cpukit/libmisc/shell/main_flashdev.c b/cpukit/libmisc/shell/main_flashdev.c index ca2454b33c..969b0687d2 100644 --- a/cpukit/libmisc/shell/main_flashdev.c +++ b/cpukit/libmisc/shell/main_flashdev.c @@ -385,7 +385,7 @@ int flashdev_shell_type( char *dev_path ) /* Get type */ status = flashdev_shell_ioctl_value( dev_path, -RTEMS_FLASHDEV_IO
[PATCH rtems6 - v2 03/16] flashdev: Align IOCTL function and macro
From: Bernd Moessner Updates #4981 --- cpukit/dev/flash/flashdev.c | 72 +-- cpukit/include/dev/flash/flashdev.h | 12 ++-- .../libtests/flashdev01/test_flashdev.c | 36 +- 3 files changed, 60 insertions(+), 60 deletions(-) diff --git a/cpukit/dev/flash/flashdev.c b/cpukit/dev/flash/flashdev.c index 40666290e0..27edead968 100644 --- a/cpukit/dev/flash/flashdev.c +++ b/cpukit/dev/flash/flashdev.c @@ -99,31 +99,31 @@ static int rtems_flashdev_ioctl_clear_region( rtems_libio_t *iop ); -static uint32_t rtems_flashdev_ioctl_jedec_id( +static uint32_t rtems_flashdev_ioctl_get_jedec_id( rtems_flashdev *flash ); -static uint32_t rtems_flashdev_ioctl_flash_type( +static uint32_t rtems_flashdev_ioctl_get_flash_type( rtems_flashdev *flash, void *arg ); -static int rtems_flashdev_ioctl_pageinfo_offset( +static int rtems_flashdev_ioctl_get_pageinfo_offset( rtems_flashdev *flash, void *arg ); -static int rtems_flashdev_ioctl_pageinfo_index( +static int rtems_flashdev_ioctl_get_pageinfo_index( rtems_flashdev *flash, void *arg ); -static int rtems_flashdev_ioctl_page_count( +static int rtems_flashdev_ioctl_get_page_count( rtems_flashdev *flash, void *arg ); -static int rtems_flashdev_ioctl_write_block_size( +static int rtems_flashdev_ioctl_get_write_block_size( rtems_flashdev *flash, void *arg ); @@ -363,7 +363,7 @@ static int rtems_flashdev_ioctl( err = 0; break; case RTEMS_FLASHDEV_IOCTL_GET_JEDEC_ID: - *( (uint32_t *) arg ) = rtems_flashdev_ioctl_jedec_id( flash ); + *( (uint32_t *) arg ) = rtems_flashdev_ioctl_get_jedec_id( flash ); err = 0; break; case RTEMS_FLASHDEV_IOCTL_ERASE: @@ -376,19 +376,19 @@ static int rtems_flashdev_ioctl( err = rtems_flashdev_ioctl_clear_region( flash, iop ); break; case RTEMS_FLASHDEV_IOCTL_GET_TYPE: - err = rtems_flashdev_ioctl_flash_type( flash, arg ); + err = rtems_flashdev_ioctl_get_flash_type( flash, arg ); break; case RTEMS_FLASHDEV_IOCTL_GET_PAGEINFO_BY_OFFSET: - err = rtems_flashdev_ioctl_pageinfo_offset( flash, arg ); + err = rtems_flashdev_ioctl_get_pageinfo_offset( flash, arg ); break; case RTEMS_FLASHDEV_IOCTL_GET_PAGEINFO_BY_INDEX: - err = rtems_flashdev_ioctl_pageinfo_index( flash, arg ); + err = rtems_flashdev_ioctl_get_pageinfo_index( flash, arg ); break; case RTEMS_FLASHDEV_IOCTL_GET_PAGE_COUNT: - err = rtems_flashdev_ioctl_page_count( flash, arg ); + err = rtems_flashdev_ioctl_get_page_count( flash, arg ); break; case RTEMS_FLASHDEV_IOCTL_GET_WRITE_BLOCK_SIZE: - err = rtems_flashdev_ioctl_write_block_size( flash, arg ); + err = rtems_flashdev_ioctl_get_write_block_size( flash, arg ); break; } @@ -493,12 +493,12 @@ static int rtems_flashdev_do_init( flash->read = NULL; flash->write = NULL; flash->erase = NULL; - flash->jedec_id = NULL; - flash->flash_type = NULL; - flash->page_info_by_offset = NULL; - flash->page_info_by_index = NULL; - flash->page_count = NULL; - flash->write_block_size = NULL; + flash->get_jedec_id = NULL; + flash->get_flash_type = NULL; + flash->get_page_info_by_offset = NULL; + flash->get_page_info_by_index = NULL; + flash->get_page_count = NULL; + flash->get_write_block_size = NULL; flash->region_table = NULL; return 0; } @@ -768,29 +768,29 @@ static size_t rtems_flashdev_get_region_size( return table->regions[ rtems_flashdev_get_region_index( iop ) ].size; } -static uint32_t rtems_flashdev_ioctl_jedec_id( rtems_flashdev *flash ) +static uint32_t rtems_flashdev_ioctl_get_jedec_id( rtems_flashdev *flash ) { - if ( flash->jedec_id == NULL ) { + if ( flash->get_jedec_id == NULL ) { return 0; } else { -return ( *flash->jedec_id )( flash ); +return ( *flash->get_jedec_id )( flash ); } } -static uint32_t rtems_flashdev_ioctl_flash_type( +static uint32_t rtems_flashdev_ioctl_get_flash_type( rtems_flashdev *flash, void *arg ) { rtems_flashdev_flash_type *type = (rtems_flashdev_flash_type*)arg; - if ( flash->flash_type == NULL ) { + if ( flash->get_flash_type == NULL ) { return 0; } else { -return ( *flash->flash_type )( flash, type ); +return ( *flash->get_flash_type )( flash, type ); } } -static int rtems_flashdev_ioctl_pageinfo_offset( +static int rtems_flashdev_ioctl_get_pageinfo_offset( rtems_flashdev *flash, void *arg ) @@ -800,18 +800,18 @@ static int rtems_flashdev_ioctl_pageinfo_offset( if ( arg == NULL ) { rtems_set_errno_and_return_minus_one( EINVAL ); } - if ( flash->page_info_by_offset == NULL ) { + if ( flash->get_page_info_by_offset == NULL ) { return 0; } else { page_info = (rtems_flashdev_ioctl_page_info *) arg; -return ( *flash->page_info_by_offset )( flash, +return ( *flash->get_page_info_by_offset )( flash,
[PATCH rtems6 - v2 07/16] flashdev: fix wrong offset assignment
From: Bernd Moessner When the region feature is active, flashdev assumes that a relative address is provided. It computes the abs. address and carries out the read / write. However, in this case it must not assign the abs. address to iop->offset. The relative address is required here to allow newlib to correctly read/write the next junk of data. Updates #4981 --- cpukit/dev/flash/flashdev.c | 10 -- 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/cpukit/dev/flash/flashdev.c b/cpukit/dev/flash/flashdev.c index 7bc13ed70a..b908e87023 100644 --- a/cpukit/dev/flash/flashdev.c +++ b/cpukit/dev/flash/flashdev.c @@ -145,8 +145,7 @@ static int rtems_flashdev_get_abs_addr( static int rtems_flashdev_update_and_return( rtems_libio_t *iop, int status, - size_t count, - off_t new_offset + size_t count ); static uint32_t rtems_flashdev_find_unallocated_region( @@ -339,7 +338,7 @@ static int rtems_flashdev_read_write( rtems_flashdev_release( flash ); /* Update offset and return */ - return rtems_flashdev_update_and_return( iop, status, count, addr + count ); + return rtems_flashdev_update_and_return( iop, status, count ); } static int rtems_flashdev_ioctl( @@ -599,13 +598,12 @@ static int rtems_flashdev_get_abs_addr( static int rtems_flashdev_update_and_return( rtems_libio_t *iop, int status, - size_t count, - off_t new_offset + size_t count ) { /* Update offset and return */ if ( status == 0 ) { -iop->offset = new_offset; +iop->offset += count; return count; } else { rtems_set_errno_and_return_minus_one( status ); -- 2.34.1 ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
[PATCH rtems6 - v2 04/16] flashdev: Align IOCTL and shell function
From: Bernd Moessner Updates #4981 --- cpukit/libmisc/shell/main_flashdev.c | 36 ++-- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/cpukit/libmisc/shell/main_flashdev.c b/cpukit/libmisc/shell/main_flashdev.c index 969b0687d2..516c77ae27 100644 --- a/cpukit/libmisc/shell/main_flashdev.c +++ b/cpukit/libmisc/shell/main_flashdev.c @@ -35,12 +35,12 @@ static int flashdev_shell_read(char *dev_path, int argc, char *argv[]); static int flashdev_shell_write(char *dev_path, int argc, char *argv[]); static int flashdev_shell_erase(char *dev_path, int argc, char *argv[]); -static int flashdev_shell_type(char *dev_path); -static int flashdev_shell_jedecid(char *dev_path); -static int flashdev_shell_page_off(char *dev_path, int argc, char *argv[]); -static int flashdev_shell_page_idx(char *dev_path, int argc, char *argv[]); -static int flashdev_shell_pg_count(char *dev_path); -static int flashdev_shell_wb_size(char *dev_path); +static int flashdev_shell_get_type(char *dev_path); +static int flashdev_shell_get_jedec_id(char *dev_path); +static int flashdev_shell_get_page_by_off(char *dev_path, int argc, char *argv[]); +static int flashdev_shell_get_page_by_idx(char *dev_path, int argc, char *argv[]); +static int flashdev_shell_get_pg_count(char *dev_path); +static int flashdev_shell_get_wb_size(char *dev_path); static int flashdev_shell_ioctl_value( char *dev_path, @@ -99,22 +99,22 @@ static int rtems_flashdev_shell_main( int argc, char *argv[] ) { return flashdev_shell_erase(dev_path, argc, &argv[i]); case ('t'): /* Flash Type */ -return flashdev_shell_type(dev_path); +return flashdev_shell_get_type(dev_path); case ('d'): /* JEDEC Id */ -return flashdev_shell_jedecid(dev_path); +return flashdev_shell_get_jedec_id(dev_path); case ('o'): /* Page info by offset */ -return flashdev_shell_page_off(dev_path, argc, &argv[i]); +return flashdev_shell_get_page_by_off(dev_path, argc, &argv[i]); case ('i'): /* Page info by index */ -return flashdev_shell_page_idx(dev_path, argc, &argv[i]); +return flashdev_shell_get_page_by_idx(dev_path, argc, &argv[i]); case ('p'): /* Page count */ -return flashdev_shell_pg_count(dev_path); +return flashdev_shell_get_pg_count(dev_path); case ('b'): /* Write block size */ -return flashdev_shell_wb_size(dev_path); +return flashdev_shell_get_wb_size(dev_path); case ('h'): default: /* Help */ @@ -377,7 +377,7 @@ int flashdev_shell_erase( return 0; } -int flashdev_shell_type( char *dev_path ) +int flashdev_shell_get_type( char *dev_path ) { int type; int status; @@ -409,7 +409,7 @@ int flashdev_shell_type( char *dev_path ) return 0; } -int flashdev_shell_jedecid( char *dev_path ) { +int flashdev_shell_get_jedec_id( char *dev_path ) { uint32_t ret; int status; @@ -430,7 +430,7 @@ int flashdev_shell_jedecid( char *dev_path ) { return 0; } -static int flashdev_shell_page_off( +static int flashdev_shell_get_page_by_off( char *dev_path, int argc, char *argv[] @@ -444,7 +444,7 @@ static int flashdev_shell_page_off( ); } -static int flashdev_shell_page_idx( +static int flashdev_shell_get_page_by_idx( char *dev_path, int argc, char *argv[] @@ -458,7 +458,7 @@ static int flashdev_shell_page_idx( ); } -static int flashdev_shell_pg_count( char *dev_path ) +static int flashdev_shell_get_pg_count( char *dev_path ) { uint32_t ret; int status; @@ -480,7 +480,7 @@ static int flashdev_shell_pg_count( char *dev_path ) return 0; } -static int flashdev_shell_wb_size( char *dev_path ) +static int flashdev_shell_get_wb_size( char *dev_path ) { size_t ret; int status; -- 2.34.1 ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
[PATCH rtems6 - v2 06/16] flashdev.c: return error in case neither
From: Bernd Moessner Updates #4981 --- cpukit/dev/flash/flashdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpukit/dev/flash/flashdev.c b/cpukit/dev/flash/flashdev.c index 8bd3d11246..7bc13ed70a 100644 --- a/cpukit/dev/flash/flashdev.c +++ b/cpukit/dev/flash/flashdev.c @@ -320,7 +320,7 @@ static int rtems_flashdev_read_write( int status; if ( read_buff == NULL && write_buff == NULL ) { -return 0; +rtems_set_errno_and_return_minus_one( EINVAL ); } /* Get flash address */ -- 2.34.1 ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
[PATCH rtems6 - v2 08/16] flashdev: add function to deregister
From: Bernd Moessner In addition to that update the test case Updates #4981 --- cpukit/dev/flash/flashdev.c | 12 ++ cpukit/include/dev/flash/flashdev.h | 14 +++ testsuites/libtests/flashdev01/init.c | 15 ++-- .../libtests/flashdev01/test_flashdev.c | 24 +++ .../libtests/flashdev01/test_flashdev.h | 2 ++ 5 files changed, 65 insertions(+), 2 deletions(-) diff --git a/cpukit/dev/flash/flashdev.c b/cpukit/dev/flash/flashdev.c index b908e87023..37d42955eb 100644 --- a/cpukit/dev/flash/flashdev.c +++ b/cpukit/dev/flash/flashdev.c @@ -484,6 +484,18 @@ int rtems_flashdev_register( return rv; } +int rtems_flashdev_deregister( + const char *flash_path +) +{ + rtems_filesystem_eval_path_context_t ctx; + int eval_flags = RTEMS_FS_FOLLOW_LINK; + const rtems_filesystem_location_info_t *currentloc = +rtems_filesystem_eval_path_start( &ctx , flash_path, eval_flags ); + + return IMFS_rmnod(NULL, currentloc); +} + static int rtems_flashdev_do_init( rtems_flashdev *flash, void ( *destroy )( rtems_flashdev *flash ) diff --git a/cpukit/include/dev/flash/flashdev.h b/cpukit/include/dev/flash/flashdev.h index 6244d38e3a..51e0486148 100644 --- a/cpukit/include/dev/flash/flashdev.h +++ b/cpukit/include/dev/flash/flashdev.h @@ -441,6 +441,20 @@ int rtems_flashdev_register( const char *flash_path ); +/** + * @brief Deregister the flash device. + * + * This function removes the node allocated for the flash device. + * + * @param[in] flash_path The path to the flash device file. + * + * @retval 0 Successful operation. + * @retval non-zero Failed operation. + */ +int rtems_flashdev_deregister( + const char *flash_path +); + /** * @brief Destroys the flash device. * diff --git a/testsuites/libtests/flashdev01/init.c b/testsuites/libtests/flashdev01/init.c index 30af3f33c1..48cb033c04 100644 --- a/testsuites/libtests/flashdev01/init.c +++ b/testsuites/libtests/flashdev01/init.c @@ -60,17 +60,18 @@ static void run_test(void) { int page_count; int type; size_t wb_size; + const char flash_path[] = "/dev/flashdev0"; /* Initalize the flash device driver and flashdev */ flash = test_flashdev_init(); rtems_test_assert(flash != NULL); /* Register the flashdev as a device */ - status = rtems_flashdev_register(flash, "dev/flashdev0"); + status = rtems_flashdev_register(flash, flash_path); rtems_test_assert(!status); /* Open the flashdev */ - file = fopen("dev/flashdev0", "r+"); + file = fopen(flash_path, "r+"); rtems_test_assert(file != NULL); fd = fileno(file); @@ -159,6 +160,16 @@ static void run_test(void) { fseek(file, 0x400, SEEK_SET); fgets(buff, 11, file); rtems_test_assert(strncmp(buff, "HELLO WORLD", 11)); + + /* Close the file handle */ + status = fclose(file); + rtems_test_assert(!status); + + /* Deregister path */ + status = rtems_flashdev_deregister(flash_path); + rtems_test_assert(!status); + + test_flashdev_deinit(flash); } static void Init(rtems_task_argument arg) diff --git a/testsuites/libtests/flashdev01/test_flashdev.c b/testsuites/libtests/flashdev01/test_flashdev.c index d97f5d8145..9e257863b1 100644 --- a/testsuites/libtests/flashdev01/test_flashdev.c +++ b/testsuites/libtests/flashdev01/test_flashdev.c @@ -273,3 +273,27 @@ rtems_flashdev* test_flashdev_init(void) return flash; } + +/* Free Flashdev and underlying driver. */ +void test_flashdev_deinit( + rtems_flashdev* flash +) +{ + if (NULL != flash) + { +if (NULL != flash->driver) +{ + free(flash->region_table); +} +if (NULL != flash->driver) +{ + test_flashdev* flash_driver = (test_flashdev*) flash->driver; + if (NULL != flash_driver->data) + { +free( flash_driver->data); + } + free(flash->driver); +} +rtems_flashdev_destroy_and_free(flash); + } +} diff --git a/testsuites/libtests/flashdev01/test_flashdev.h b/testsuites/libtests/flashdev01/test_flashdev.h index 8b03959c42..894c5d3747 100644 --- a/testsuites/libtests/flashdev01/test_flashdev.h +++ b/testsuites/libtests/flashdev01/test_flashdev.h @@ -32,4 +32,6 @@ rtems_flashdev* test_flashdev_init(void); +void test_flashdev_deinit(rtems_flashdev* flash); + #endif /* __TEST_FLASHDEV_H */ -- 2.34.1 ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
[PATCH rtems6 - v2 09/16] flashdev: Refactor macro name
From: Bernd Moessner The major change in this patch is that it refactors RTEMS_FLASHDEV_IOCTL_GET_WRITE_BLOCK_SIZE to become RTEMS_FLASHDEV_IOCTL_GET_MIN_WRITE_BLOCK_SIZE. Apart from that this patch fixes comments and aligns function names. There is no change in the behaviour of the code introduced by this patch. Updates #4981 --- cpukit/dev/flash/flashdev.c | 26 +- cpukit/include/dev/flash/flashdev.h | 15 +++--- cpukit/libmisc/shell/main_flashdev.c | 47 +++ testsuites/libtests/flashdev01/init.c | 9 ++-- .../libtests/flashdev01/test_flashdev.c | 30 ++-- 5 files changed, 68 insertions(+), 59 deletions(-) diff --git a/cpukit/dev/flash/flashdev.c b/cpukit/dev/flash/flashdev.c index 37d42955eb..50915312a0 100644 --- a/cpukit/dev/flash/flashdev.c +++ b/cpukit/dev/flash/flashdev.c @@ -108,12 +108,12 @@ static uint32_t rtems_flashdev_ioctl_get_flash_type( void *arg ); -static int rtems_flashdev_ioctl_get_pageinfo_offset( +static int rtems_flashdev_ioctl_get_pageinfo_by_offset( rtems_flashdev *flash, void *arg ); -static int rtems_flashdev_ioctl_get_pageinfo_index( +static int rtems_flashdev_ioctl_get_pageinfo_by_index( rtems_flashdev *flash, void *arg ); @@ -123,7 +123,7 @@ static int rtems_flashdev_ioctl_get_page_count( void *arg ); -static int rtems_flashdev_ioctl_get_write_block_size( +static int rtems_flashdev_ioctl_get_min_write_block_size( rtems_flashdev *flash, void *arg ); @@ -378,16 +378,16 @@ static int rtems_flashdev_ioctl( err = rtems_flashdev_ioctl_get_flash_type( flash, arg ); break; case RTEMS_FLASHDEV_IOCTL_GET_PAGEINFO_BY_OFFSET: - err = rtems_flashdev_ioctl_get_pageinfo_offset( flash, arg ); + err = rtems_flashdev_ioctl_get_pageinfo_by_offset( flash, arg ); break; case RTEMS_FLASHDEV_IOCTL_GET_PAGEINFO_BY_INDEX: - err = rtems_flashdev_ioctl_get_pageinfo_index( flash, arg ); + err = rtems_flashdev_ioctl_get_pageinfo_by_index( flash, arg ); break; case RTEMS_FLASHDEV_IOCTL_GET_PAGE_COUNT: err = rtems_flashdev_ioctl_get_page_count( flash, arg ); break; -case RTEMS_FLASHDEV_IOCTL_GET_WRITE_BLOCK_SIZE: - err = rtems_flashdev_ioctl_get_write_block_size( flash, arg ); +case RTEMS_FLASHDEV_IOCTL_GET_MIN_WRITE_BLOCK_SIZE: + err = rtems_flashdev_ioctl_get_min_write_block_size( flash, arg ); break; default: err = EINVAL; @@ -511,7 +511,7 @@ static int rtems_flashdev_do_init( flash->get_page_info_by_offset = NULL; flash->get_page_info_by_index = NULL; flash->get_page_count = NULL; - flash->get_write_block_size = NULL; + flash->get_min_write_block_size = NULL; flash->region_table = NULL; return 0; } @@ -802,7 +802,7 @@ static uint32_t rtems_flashdev_ioctl_get_flash_type( } } -static int rtems_flashdev_ioctl_get_pageinfo_offset( +static int rtems_flashdev_ioctl_get_pageinfo_by_offset( rtems_flashdev *flash, void *arg ) @@ -823,7 +823,7 @@ static int rtems_flashdev_ioctl_get_pageinfo_offset( } } -static int rtems_flashdev_ioctl_get_pageinfo_index( rtems_flashdev *flash, +static int rtems_flashdev_ioctl_get_pageinfo_by_index( rtems_flashdev *flash, void *arg ) { rtems_flashdev_ioctl_page_info *page_info; @@ -854,7 +854,7 @@ static int rtems_flashdev_ioctl_get_page_count( rtems_flashdev *flash, void *arg } } -static int rtems_flashdev_ioctl_get_write_block_size( +static int rtems_flashdev_ioctl_get_min_write_block_size( rtems_flashdev *flash, void *arg ) @@ -862,10 +862,10 @@ static int rtems_flashdev_ioctl_get_write_block_size( if ( arg == NULL ) { rtems_set_errno_and_return_minus_one( EINVAL ); } - if ( flash->get_write_block_size == NULL ) { + if ( flash->get_min_write_block_size == NULL ) { return 0; } else { -return ( *flash->get_write_block_size )( flash, ( (size_t *) arg ) ); +return ( *flash->get_min_write_block_size )( flash, ( (size_t *) arg ) ); } } diff --git a/cpukit/include/dev/flash/flashdev.h b/cpukit/include/dev/flash/flashdev.h index 51e0486148..6ce00c4ead 100644 --- a/cpukit/include/dev/flash/flashdev.h +++ b/cpukit/include/dev/flash/flashdev.h @@ -138,11 +138,11 @@ typedef struct rtems_flashdev rtems_flashdev; #define RTEMS_FLASHDEV_IOCTL_GET_PAGE_COUNT 9 /** - * @brief Get the minimum write size supported by the driver. + * @brief Get the minimum write block size supported by the driver. * - * @param[out] count Integer containing the minimum write size. + * @param[out] count Integer containing the minimum write block size. */ -#define RTEMS_FLASHDEV_IOCTL_GET_WRITE_BLOCK_SIZE 10 +#define RTEMS_FLASHDEV_IOCTL_GET_MIN_WRITE_BLOCK_SIZE 10 /** * @brief The maximum number of region limited file descriptors @@ -351,17 +351,18 @@ struct rtems_flashdev { ); /** - * @brief Call to device driver to re
[PATCH rtems6 - v2 10/16] flashdev: extend testsuite
From: Bernd Moessner Allow testsuite to set the min. write block size Updates #4981 --- testsuites/libtests/flashdev01/init.c | 191 +++--- .../libtests/flashdev01/test_flashdev.c | 13 +- .../libtests/flashdev01/test_flashdev.h | 2 +- 3 files changed, 133 insertions(+), 73 deletions(-) diff --git a/testsuites/libtests/flashdev01/init.c b/testsuites/libtests/flashdev01/init.c index dead939212..7745f43e36 100644 --- a/testsuites/libtests/flashdev01/init.c +++ b/testsuites/libtests/flashdev01/init.c @@ -42,6 +42,7 @@ #define MIN_WRTIE_BLOCK_SIZE 1 const char rtems_test_name[] = "FLASHDEV 1"; +const char test_string[] = "My test string!"; static void run_test(void); @@ -59,11 +60,116 @@ static void run_test(void) { uint32_t jedec; int page_count; int type; - size_t min_write_block_size; + size_t bytes_read; + size_t min_write_write_block_size_in[] = {1,8,16}; + size_t min_write_write_block_size_out; const char flash_path[] = "/dev/flashdev0"; + for ( int loop = 0; loop <= 2; loop++) + { +/* Initalize the flash device driver and flashdev */ +flash = test_flashdev_init(min_write_write_block_size_in[loop]); +rtems_test_assert(flash != NULL); + +/* Register the flashdev as a device */ +status = rtems_flashdev_register(flash, flash_path); +rtems_test_assert(!status); + +/* Open the flashdev */ +file = fopen(flash_path, "r+"); +rtems_test_assert(file != NULL); + +/* Adjust the file buffering */ +status = setvbuf(file, NULL, _IOFBF, min_write_write_block_size_in[loop]); +rtems_test_assert(!status); + +fd = fileno(file); + +/* Read data from flash */ +read_data = fgets(buff, TEST_DATA_SIZE, file); +rtems_test_assert(read_data != NULL); + +/* Fseek to start of flash and read again */ +status = fseek(file, 0x0, SEEK_SET); +rtems_test_assert(!status); +bytes_read = fread(buff, 1, TEST_DATA_SIZE, file); +rtems_test_assert(bytes_read == TEST_DATA_SIZE); + +/* Fseek to start of flash */ +status = fseek(file, 0x0, SEEK_SET); +rtems_test_assert(!status); + +/* Write the test name to the flash */ +status = fwrite(test_string, 1, sizeof(test_string), file); +rtems_test_assert(status == sizeof(test_string)); + +/* Fseek to start of flash and read again */ +status = fseek(file, 0x0, SEEK_SET); +rtems_test_assert(!status); +fgets(buff, TEST_DATA_SIZE, file); +rtems_test_assert(!strncmp(buff, test_string, sizeof(test_string))); + +/* Test Erasing */ +e_args.offset = 0x0; +e_args.size = PAGE_SIZE; +status = ioctl(fd, RTEMS_FLASHDEV_IOCTL_ERASE, &e_args); +rtems_test_assert(!status); + +fseek(file, 0x0, SEEK_SET); +fgets(buff, TEST_DATA_SIZE, file); +rtems_test_assert(buff[0] == 0); + +/* Test getting JEDEC ID */ +status = ioctl(fd, RTEMS_FLASHDEV_IOCTL_GET_JEDEC_ID, &jedec); +rtems_test_assert(!status); +rtems_test_assert(jedec == 0x00ABCDEF); + +/* Test getting flash type */ +status = ioctl(fd, RTEMS_FLASHDEV_IOCTL_GET_TYPE, &type); +rtems_test_assert(!status); +rtems_test_assert(type == RTEMS_FLASHDEV_NOR); + +/* Test getting page info from offset */ +pg_info.location = PAGE_SIZE + PAGE_SIZE/2; + +status = ioctl(fd, RTEMS_FLASHDEV_IOCTL_GET_PAGEINFO_BY_OFFSET, &pg_info); +rtems_test_assert(!status); +rtems_test_assert(pg_info.page_info.offset == PAGE_SIZE); +rtems_test_assert(pg_info.page_info.size == PAGE_SIZE); + +/* Test getting page info from index */ +pg_info.location = 2; +status = ioctl(fd, RTEMS_FLASHDEV_IOCTL_GET_PAGEINFO_BY_INDEX, &pg_info); +rtems_test_assert(!status); +rtems_test_assert(pg_info.page_info.offset == 2*PAGE_SIZE); +rtems_test_assert(pg_info.page_info.size == PAGE_SIZE); + +/* Test getting page count */ +status = ioctl(fd, RTEMS_FLASHDEV_IOCTL_GET_PAGE_COUNT, &page_count); +rtems_test_assert(!status); +rtems_test_assert(page_count == PAGE_COUNT); + +/* Test getting min write size */ +status = ioctl(fd, RTEMS_FLASHDEV_IOCTL_GET_MIN_WRITE_BLOCK_SIZE, +&min_write_write_block_size_out); +rtems_test_assert(!status); +rtems_test_assert(0 == memcmp(&min_write_write_block_size_out, + &min_write_write_block_size_in[loop], + sizeof(size_t))); + +/* Close the file handle */ +status = fclose(file); +rtems_test_assert(!status); + +/* Deregister path */ +status = rtems_flashdev_deregister(flash_path); +rtems_test_assert(!status); + +test_flashdev_deinit(flash); + } + /* Initalize the flash device driver and flashdev */ - flash = test_flashdev_init(); + flash = test_flashdev_init(min_write_write_block_size_in[1]); rtems_test_assert(flash != NULL); /* Register the flashdev as a device */ @@ -72,72 +178,12 @@ static void run_test(void) { /* Open the flash
[PATCH rtems6 - v2 11/16] flashdev: extend testsuite
From: Bernd Moessner Updates #4981 --- testsuites/libtests/flashdev01/init.c | 8 +++- .../libtests/flashdev01/test_flashdev.c | 41 --- .../libtests/flashdev01/test_flashdev.h | 6 ++- 3 files changed, 38 insertions(+), 17 deletions(-) diff --git a/testsuites/libtests/flashdev01/init.c b/testsuites/libtests/flashdev01/init.c index 7745f43e36..8fe1d083f3 100644 --- a/testsuites/libtests/flashdev01/init.c +++ b/testsuites/libtests/flashdev01/init.c @@ -68,7 +68,9 @@ static void run_test(void) { for ( int loop = 0; loop <= 2; loop++) { /* Initalize the flash device driver and flashdev */ -flash = test_flashdev_init(min_write_write_block_size_in[loop]); +flash = test_flashdev_init( PAGE_COUNT, +PAGE_SIZE, +min_write_write_block_size_in[loop]); rtems_test_assert(flash != NULL); /* Register the flashdev as a device */ @@ -169,7 +171,9 @@ static void run_test(void) { } /* Initalize the flash device driver and flashdev */ - flash = test_flashdev_init(min_write_write_block_size_in[1]); + flash = test_flashdev_init( PAGE_COUNT, + PAGE_SIZE, + min_write_write_block_size_in[1]); rtems_test_assert(flash != NULL); /* Register the flashdev as a device */ diff --git a/testsuites/libtests/flashdev01/test_flashdev.c b/testsuites/libtests/flashdev01/test_flashdev.c index acc02e04f6..d7f8a2fe67 100644 --- a/testsuites/libtests/flashdev01/test_flashdev.c +++ b/testsuites/libtests/flashdev01/test_flashdev.c @@ -30,14 +30,14 @@ #include -#define TEST_DATA_SIZE (PAGE_SIZE * PAGE_COUNT) -#define PAGE_COUNT 16 -#define PAGE_SIZE 128 #define MAX_NUM_REGIONS 48 #define BITALLOC_SIZE 32 #define NUM_BITALLOC ((MAX_NUM_REGIONS + BITALLOC_SIZE - 1) / BITALLOC_SIZE) size_t g_min_write_block_size = 0; +size_t g_page_count = 0; +size_t g_page_size = 0; +size_t g_test_data_size = 0; /** * This flash device driver is for testing flashdev @@ -111,8 +111,8 @@ int test_flashdev_get_page_by_offset( size_t *page_size ) { - *page_offset = search_offset - (search_offset%PAGE_SIZE); - *page_size = PAGE_SIZE; + *page_offset = search_offset - (search_offset%g_page_size); + *page_size = g_page_size; return 0; } @@ -124,8 +124,8 @@ int test_flashdev_get_page_by_index( size_t *page_size ) { - *page_offset = search_index * PAGE_SIZE; - *page_size = PAGE_SIZE; + *page_offset = search_index * g_page_size; + *page_size = g_page_size; return 0; } @@ -135,7 +135,7 @@ int test_flashdev_get_page_count( int *page_count ) { - *page_count = PAGE_COUNT; + *page_count = g_page_count; return 0; } @@ -181,7 +181,7 @@ int test_flashdev_read( { test_flashdev* driver = flash->driver; - if (offset + count > TEST_DATA_SIZE) { + if (offset + count > g_test_data_size) { rtems_set_errno_and_return_minus_one( EINVAL ); } @@ -200,7 +200,7 @@ int test_flashdev_write( { test_flashdev* driver = flash->driver; - if (offset + count > TEST_DATA_SIZE) { + if (offset + count > g_test_data_size) { rtems_set_errno_and_return_minus_one( EINVAL ); } @@ -218,11 +218,11 @@ int test_flashdev_erase( { test_flashdev* driver = flash->driver; - if (offset + count > TEST_DATA_SIZE) { + if (offset + count > g_test_data_size) { rtems_set_errno_and_return_minus_one( EINVAL ); } - if (offset%PAGE_SIZE || count%PAGE_SIZE) { + if (offset%g_page_size || count%g_page_size) { rtems_set_errno_and_return_minus_one( EINVAL ); } @@ -231,13 +231,26 @@ int test_flashdev_erase( } /* Initialize Flashdev and underlying driver. */ -rtems_flashdev* test_flashdev_init(size_t min_write_block_size) +rtems_flashdev* test_flashdev_init( + size_t page_count, + size_t page_size, + size_t min_write_block_size + ) { + if (0 == page_count) { +return NULL; + } + if (0 == page_size) { +return NULL; + } if (0 == min_write_block_size) { return NULL; } + g_page_count = page_count; + g_page_size = page_size; g_min_write_block_size = min_write_block_size; + g_test_data_size = g_page_size * g_page_count; rtems_flashdev *flash = rtems_flashdev_alloc_and_init(sizeof(rtems_flashdev)); @@ -252,7 +265,7 @@ rtems_flashdev* test_flashdev_init(size_t min_write_block_size) return NULL; } - flash_driver->data = calloc(1, TEST_DATA_SIZE); + flash_driver->data = calloc(1, g_test_data_size); if (flash_driver->data == NULL) { free(flash_driver); rtems_flashdev_destroy_and_free(flash); diff --git a/testsuites/libtests/flashdev01/test_flashdev.h b/testsuites/libtests/flashdev01/test_flashdev.h index 568efcee34..ca2838ecd2 100644 --- a/testsuites/libtests/flashdev01/test_flashdev.h +++ b/testsuites/libtests/flashdev01/test_flashdev.h @@ -30,7 +30,11 @@ #include -rtems_flashdev* test_flashdev_init(size_t min_write_block_size); +rtems_flash
[PATCH rtems6 - v2 12/16] flashdev: Add erase info to page info
From: Bernd Moessner Updates #4981 --- cpukit/dev/flash/flashdev.c | 8 ++- cpukit/include/dev/flash/flashdev.h | 18 ++- cpukit/libmisc/shell/main_flashdev.c | 18 --- testsuites/libtests/flashdev01/init.c | 18 ++- .../libtests/flashdev01/test_flashdev.c | 49 ++- .../libtests/flashdev01/test_flashdev.h | 1 + 6 files changed, 90 insertions(+), 22 deletions(-) diff --git a/cpukit/dev/flash/flashdev.c b/cpukit/dev/flash/flashdev.c index 50915312a0..e10daace99 100644 --- a/cpukit/dev/flash/flashdev.c +++ b/cpukit/dev/flash/flashdev.c @@ -819,7 +819,9 @@ static int rtems_flashdev_ioctl_get_pageinfo_by_offset( return ( *flash->get_page_info_by_offset )( flash, page_info->location, &page_info->page_info.offset, - &page_info->page_info.size ); + &page_info->page_info.size, + &page_info->erase_info.offset, + &page_info->erase_info.size ); } } @@ -838,7 +840,9 @@ static int rtems_flashdev_ioctl_get_pageinfo_by_index( rtems_flashdev *flash, return ( *flash->get_page_info_by_index )( flash, page_info->location, &page_info->page_info.offset, - &page_info->page_info.size ); + &page_info->page_info.size, + &page_info->erase_info.offset, + &page_info->erase_info.size ); } } diff --git a/cpukit/include/dev/flash/flashdev.h b/cpukit/include/dev/flash/flashdev.h index 6ce00c4ead..ac21f883e8 100644 --- a/cpukit/include/dev/flash/flashdev.h +++ b/cpukit/include/dev/flash/flashdev.h @@ -214,6 +214,12 @@ typedef struct rtems_flashdev_ioctl_page_info { * base offset and size of page. */ rtems_flashdev_region page_info; + + /** + * @brief Erase information returned about the page. Including the + * base offset and size of the erase block. + */ + rtems_flashdev_region erase_info; } rtems_flashdev_ioctl_page_info; /** @@ -306,6 +312,8 @@ struct rtems_flashdev { * returned. * @param[out] page_offset The offset of the start of the page * @param[out] page_size The size of the page + * @param[out] erase_offset The offset of the start of the erase block + * @param[out] erase_size The erase block size * * @retval 0 Success. * @retval non-zero Failed. @@ -314,7 +322,9 @@ struct rtems_flashdev { rtems_flashdev *flash, off_t search_offset, off_t *page_offset, -size_t *page_size +size_t *page_size, +off_t *erase_offset, +size_t *erase_size ); /** @@ -325,6 +335,8 @@ struct rtems_flashdev { * @param[in] search_index The index of the page which info is to be returned. * @param[out] page_offset The offset of the start of the page * @param[out] page_size The size of the page + * @param[out] erase_offset The offset of the start of the erase block + * @param[out] erase_size The erase block size * * @retval 0 Success. * @retval non-zero Failed. @@ -333,7 +345,9 @@ struct rtems_flashdev { rtems_flashdev *flashdev, off_t search_index, off_t *page_offset, -size_t *page_size +size_t *page_size, +off_t *erase_offset, +size_t *erase_size ); /** diff --git a/cpukit/libmisc/shell/main_flashdev.c b/cpukit/libmisc/shell/main_flashdev.c index 8443d8f71d..54cdf78103 100644 --- a/cpukit/libmisc/shell/main_flashdev.c +++ b/cpukit/libmisc/shell/main_flashdev.c @@ -37,11 +37,11 @@ static int flashdev_shell_write(char *dev_path, int argc, char *argv[]); static int flashdev_shell_erase(char *dev_path, int argc, char *argv[]); static int flashdev_shell_get_type(char *dev_path); static int flashdev_shell_get_jedec_id(char *dev_path); -static int flashdev_shell_get_page_by_off( +static int flashdev_shell_get_page_info_by_offset( char *dev_path, int argc, char *argv[] ); -static int flashdev_shell_get_page_by_idx( +static int flashdev_shell_get_page_info_by_index( char *dev_path, int argc, char *argv[] @@ -112,10 +112,10 @@ static int rtems_flashdev_shell_main( int argc, char *argv[] ) { return flashdev_shell_get_jedec_id(dev_path); case ('o'): /* Get page info by offset */ -return flashdev_shell_get_page_by_off(dev_path, argc, &argv[i]); +return flashdev_shell_get_page_info_by_offset(dev_path, argc, &argv[i]); case ('i'): /* Get page info by index */ -return flashdev_shell_get_page_by_idx(dev_path, argc, &argv[i]); +return flashdev_shell_get_page_info_by_index(dev_path, argc, &argv[i]); case ('p'):
[PATCH rtems6 - v2 13/16] flashdev: fix erase function
From: Bernd Moessner Erase function must take erase size and alignment into account Updates #4981 --- cpukit/dev/flash/flashdev.c | 49 ++- testsuites/libtests/flashdev01/init.c | 18 +- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/cpukit/dev/flash/flashdev.c b/cpukit/dev/flash/flashdev.c index e10daace99..d18d14b2f8 100644 --- a/cpukit/dev/flash/flashdev.c +++ b/cpukit/dev/flash/flashdev.c @@ -60,6 +60,12 @@ static int rtems_flashdev_read_write( size_t count ); +static int rtems_check_erase_valid( + rtems_flashdev* flash, + off_t offset, + size_t count +); + static int rtems_flashdev_ioctl_erase( rtems_flashdev *flash, rtems_libio_t *iop, @@ -341,6 +347,41 @@ static int rtems_flashdev_read_write( return rtems_flashdev_update_and_return( iop, status, count ); } +static int rtems_check_erase_valid( + rtems_flashdev* flash, + off_t offset, + size_t count +) +{ + rtems_flashdev_ioctl_page_info page_info; + page_info.location = offset; + off_t offset_max = offset + count; + + while(page_info.location < offset_max) + { +( *flash->get_page_info_by_offset )( flash, + page_info.location, + &page_info.page_info.offset, + &page_info.page_info.size, + &page_info.erase_info.offset, + &page_info.erase_info.size ); + +if (page_info.erase_info.offset != page_info.location) +{ + rtems_set_errno_and_return_minus_one( EINVAL ); +} + +page_info.location += page_info.erase_info.size; + } + + if (offset_max != page_info.location) + { +rtems_set_errno_and_return_minus_one( EINVAL ); + } + + return 0; +} + static int rtems_flashdev_ioctl( rtems_libio_t *iop, ioctl_command_t command, @@ -643,8 +684,14 @@ static int rtems_flashdev_ioctl_erase( if ( status < 0 ) { return status; } + status = rtems_check_erase_valid( flash, new_offset, erase_args_1->size ); + if ( status < 0 ) { +return status; + } - /* Erase flash */ + /* Erase flash, not fragmented as the driver might want to use even + * a different erase size for speed + */ status = ( *flash->erase )( flash, new_offset, erase_args_1->size ); return status; } diff --git a/testsuites/libtests/flashdev01/init.c b/testsuites/libtests/flashdev01/init.c index 84e2c7859d..fd3bda769e 100644 --- a/testsuites/libtests/flashdev01/init.c +++ b/testsuites/libtests/flashdev01/init.c @@ -112,10 +112,26 @@ static void run_test(void) { fgets(buff, TEST_DATA_SIZE, file); rtems_test_assert(!strncmp(buff, test_string, sizeof(test_string))); -/* Test Erasing */ +/* Test Erasing - this one must fail */ e_args.offset = 0x0; e_args.size = PAGE_SIZE; status = ioctl(fd, RTEMS_FLASHDEV_IOCTL_ERASE, &e_args); +rtems_test_assert(status); + +/* Test Erasing - this one must fail */ +e_args.offset = 0x1; +e_args.size = ERASE_BLOCK_SIZE; +status = ioctl(fd, RTEMS_FLASHDEV_IOCTL_ERASE, &e_args); +rtems_test_assert(status); + +/* Test Erasing - this one must pass */ +e_args.offset = 0x0; +status = ioctl(fd, RTEMS_FLASHDEV_IOCTL_ERASE, &e_args); +rtems_test_assert(!status); + +/* Test Erasing - this one must pass */ +e_args.size = 2*ERASE_BLOCK_SIZE; +status = ioctl(fd, RTEMS_FLASHDEV_IOCTL_ERASE, &e_args); rtems_test_assert(!status); fseek(file, 0x0, SEEK_SET); -- 2.34.1 ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
[PATCH rtems6 - v2 14/16] flashdev: revise region creation
From: Bernd Moessner Create / update region only if it is aligned to erase size Updates #4981 --- cpukit/dev/flash/flashdev.c | 14 ++ testsuites/libtests/flashdev01/init.c | 12 2 files changed, 26 insertions(+) diff --git a/cpukit/dev/flash/flashdev.c b/cpukit/dev/flash/flashdev.c index d18d14b2f8..8aa4380ab7 100644 --- a/cpukit/dev/flash/flashdev.c +++ b/cpukit/dev/flash/flashdev.c @@ -738,6 +738,13 @@ static int rtems_flashdev_ioctl_create_region( int i; rtems_flashdev_region_table *table = flash->region_table; + /* Region is only valid if it can be erased */ + i = rtems_check_erase_valid(flash, region_in->offset, region_in->size); + if(i < 0) + { +return i; + } + /* Find unallocated region slot */ i = rtems_flashdev_find_unallocated_region(flash->region_table); if (i == RTEMS_FLASHDEV_REGION_ALLOC_FULL) { @@ -764,6 +771,13 @@ static int rtems_flashdev_ioctl_update_region( uint32_t region_index = rtems_flashdev_get_region_index( iop ); rtems_flashdev_region_table *table = flash->region_table; + /* Region is only valid if it can be erased */ + int i = rtems_check_erase_valid(flash, region_in->offset, region_in->size); + if(i < 0) + { +return i; + } + /** * If region index is larger then maximum region index or region * index at given index is undefined return an error. diff --git a/testsuites/libtests/flashdev01/init.c b/testsuites/libtests/flashdev01/init.c index fd3bda769e..5755708525 100644 --- a/testsuites/libtests/flashdev01/init.c +++ b/testsuites/libtests/flashdev01/init.c @@ -221,6 +221,18 @@ static void run_test(void) { fd = fileno(file); + /* Test Regions - this one must fail */ + region.offset = 0x401; + region.size = 0x200; + status = ioctl(fd, RTEMS_FLASHDEV_IOCTL_SET_REGION, ®ion); + rtems_test_assert(status); + + /* Test Regions - this one must fail */ + region.offset = 0x400; + region.size = 0xFF; + status = ioctl(fd, RTEMS_FLASHDEV_IOCTL_SET_REGION, ®ion); + rtems_test_assert(status); + /* Test Regions */ region.offset = 0x400; region.size = 0x200; -- 2.34.1 ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
[PATCH rtems6 - v2 15/16] flashdev: Refactor IOCTL defines into enum
From: Bernd Moessner Updates #4981 --- cpukit/include/dev/flash/flashdev.h | 24 +--- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/cpukit/include/dev/flash/flashdev.h b/cpukit/include/dev/flash/flashdev.h index ac21f883e8..d59f5e92e5 100644 --- a/cpukit/include/dev/flash/flashdev.h +++ b/cpukit/include/dev/flash/flashdev.h @@ -58,18 +58,19 @@ typedef struct rtems_flashdev rtems_flashdev; /* IOCTL Calls */ +typedef enum { /** * @brief Obtains the flash device. * * This command has no argument. */ -#define RTEMS_FLASHDEV_IOCTL_OBTAIN 0 +RTEMS_FLASHDEV_IOCTL_OBTAIN, /** * @brief Releases the flash device. * * This command has no argument. */ -#define RTEMS_FLASHDEV_IOCTL_RELEASE 1 +RTEMS_FLASHDEV_IOCTL_RELEASE, /** * @brief Returns the JEDEC ID of the flash device. This IOCTL call * is informational only. @@ -77,14 +78,14 @@ typedef struct rtems_flashdev rtems_flashdev; * @param[out] jedec_id Pointer to uint32_t in which the JEDEC ID is * returned in. */ -#define RTEMS_FLASHDEV_IOCTL_GET_JEDEC_ID 2 +RTEMS_FLASHDEV_IOCTL_GET_JEDEC_ID, /** * @brief Erases flash device. * * @param[in] erase_args Pointer to rtems_flashdev_region struct * containing offset and size of erase to be performed. */ -#define RTEMS_FLASHDEV_IOCTL_ERASE 3 +RTEMS_FLASHDEV_IOCTL_ERASE, /** * @brief Set a region that limits read, write and erase calls to within it. * Regions are file descriptor specific and limited to a single region per @@ -94,20 +95,20 @@ typedef struct rtems_flashdev rtems_flashdev; * @param[in] region Pointer to rtems_flashdev_region struct containing * base and length of defined region. */ -#define RTEMS_FLASHDEV_IOCTL_SET_REGION 4 +RTEMS_FLASHDEV_IOCTL_SET_REGION, /** * @brief Removes the set region on the file descriptor. * * This command has no argument. */ -#define RTEMS_FLASHDEV_IOCTL_UNSET_REGION 5 +RTEMS_FLASHDEV_IOCTL_UNSET_REGION, /** * @brief Returns the type of flash device (e.g. NOR or NAND). * * @param[out] flash_type Pointer to integer which is set to the flash * type macro value. */ -#define RTEMS_FLASHDEV_IOCTL_GET_TYPE 6 +RTEMS_FLASHDEV_IOCTL_GET_TYPE, /** * @brief Get the size and address of flash page at given offset @@ -118,7 +119,7 @@ typedef struct rtems_flashdev rtems_flashdev; * @param[in,out] rtems_flashdev_ioctl_page_info arg Pointer to struct * with offset and space for return values. */ -#define RTEMS_FLASHDEV_IOCTL_GET_PAGEINFO_BY_OFFSET 7 +RTEMS_FLASHDEV_IOCTL_GET_PAGEINFO_BY_OFFSET, /** * @brief Get the size and address of nth flash page where n is index passed in. @@ -128,21 +129,22 @@ typedef struct rtems_flashdev rtems_flashdev; * @param[in,out] rtems_flashdev_ioctl_page_info arg Pointer to struct * with index and space for return values. */ -#define RTEMS_FLASHDEV_IOCTL_GET_PAGEINFO_BY_INDEX 8 +RTEMS_FLASHDEV_IOCTL_GET_PAGEINFO_BY_INDEX, /** * @brief Get the number of pages in flash device. * * @param[out] count Integer containing the number of pages. */ -#define RTEMS_FLASHDEV_IOCTL_GET_PAGE_COUNT 9 +RTEMS_FLASHDEV_IOCTL_GET_PAGE_COUNT, /** * @brief Get the minimum write block size supported by the driver. * * @param[out] count Integer containing the minimum write block size. */ -#define RTEMS_FLASHDEV_IOCTL_GET_MIN_WRITE_BLOCK_SIZE 10 +RTEMS_FLASHDEV_IOCTL_GET_MIN_WRITE_BLOCK_SIZE, +} rtems_flashdev_ioctl_token; /** * @brief The maximum number of region limited file descriptors -- 2.34.1 ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
[PATCH rtems6 - v2 16/16] flashdev: restrict flash writes
From: Bernd Moessner Disallow writes that do not match alignment / req. length This feature applies if the min write block size is != 0. Closes #4981 --- cpukit/dev/flash/flashdev.c | 11 +++ testsuites/libtests/flashdev01/init.c | 24 +++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/cpukit/dev/flash/flashdev.c b/cpukit/dev/flash/flashdev.c index 8aa4380ab7..9e319321be 100644 --- a/cpukit/dev/flash/flashdev.c +++ b/cpukit/dev/flash/flashdev.c @@ -323,6 +323,7 @@ static int rtems_flashdev_read_write( rtems_flashdev *flash = IMFS_generic_get_context_by_iop( iop ); off_t addr; int status; + size_t min_write_block_size = 0; if ( read_buff == NULL && write_buff == NULL ) { rtems_set_errno_and_return_minus_one( EINVAL ); @@ -339,6 +340,16 @@ static int rtems_flashdev_read_write( if ( read_buff != NULL ) { status = ( *flash->read )( flash, addr, count, read_buff ); } else if ( write_buff != NULL ) { +/* Make sure we have aligned writes in min. write block size is set */ +( *flash->get_min_write_block_size )( flash, &min_write_block_size ); +if (min_write_block_size) +{ + if((addr % min_write_block_size) || (count % min_write_block_size) ) + { +rtems_flashdev_release( flash ); +rtems_set_errno_and_return_minus_one( EINVAL ); + } +} status = ( *flash->write )( flash, addr, count, write_buff ); } rtems_flashdev_release( flash ); diff --git a/testsuites/libtests/flashdev01/init.c b/testsuites/libtests/flashdev01/init.c index 5755708525..ebbbfe 100644 --- a/testsuites/libtests/flashdev01/init.c +++ b/testsuites/libtests/flashdev01/init.c @@ -215,11 +215,33 @@ static void run_test(void) { /* Open the flashdev */ file = fopen(flash_path, "r+"); + fd = fileno(file); + + /* Write the test name to the flash - actually to newlib s buffer */ + status = fwrite(test_string, 1, sizeof(test_string)-1, file); + /* False positive, rtems_flashdev_read_write was not called. String is still + * in buffer. + */ + rtems_test_assert(status == sizeof(test_string)-1); + /* Flush will call rtems_flashdev_read_write and we see that things fail */ + status = fflush(file); + rtems_test_assert(status); + /* Adjust the file buffering */ status = setvbuf(file, NULL, _IOFBF, min_write_write_block_size_in[1]); rtems_test_assert(!status); - fd = fileno(file); + fseek(file, 0x0, SEEK_SET); + + /* Write the test name to the flash - actually to newlib s buffer */ + status = fwrite(test_string, 1, sizeof(test_string)-1, file); + /* False positive, rtems_flashdev_read_write was not called. String is still + * in buffer. + */ + rtems_test_assert(status == sizeof(test_string)-1); + /* Flush will call rtems_flashdev_read_write and we see that things fail */ + status = fflush(file); + rtems_test_assert(status); /* Test Regions - this one must fail */ region.offset = 0x401; -- 2.34.1 ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
[PATCH rtems6 - v2 05/16] flashdev: Add missing default case
From: Bernd Moessner Updates #4981 --- cpukit/dev/flash/flashdev.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cpukit/dev/flash/flashdev.c b/cpukit/dev/flash/flashdev.c index 27edead968..8bd3d11246 100644 --- a/cpukit/dev/flash/flashdev.c +++ b/cpukit/dev/flash/flashdev.c @@ -390,6 +390,8 @@ static int rtems_flashdev_ioctl( case RTEMS_FLASHDEV_IOCTL_GET_WRITE_BLOCK_SIZE: err = rtems_flashdev_ioctl_get_write_block_size( flash, arg ); break; +default: + err = EINVAL; } rtems_flashdev_release( flash ); -- 2.34.1 ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
[PATCH rtems6 0/1] Fix comment in xparameters.h
From: Bernd Moessner See patch Bernd Moessner (1): xparameters.h: fix typo in comment bsps/include/xil/xparameters.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.34.1 ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
[PATCH rtems6 1/1] xparameters.h: fix typo in comment
From: Bernd Moessner --- bsps/include/xil/xparameters.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bsps/include/xil/xparameters.h b/bsps/include/xil/xparameters.h index b665810643..9d4d95eacb 100644 --- a/bsps/include/xil/xparameters.h +++ b/bsps/include/xil/xparameters.h @@ -41,4 +41,4 @@ extern "C" { } #endif -#endif /* XIL_PRINTF_H */ +#endif /* XPARAMETERS_H */ -- 2.34.1 ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel