<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p><br>
</p>
<div class="moz-cite-prefix">On 04.01.2024 20:05, Kinsey Moore
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAPycBojKKBgwmGmYVyxkWNWB=L_r24TAg8dALnWjvTObfd9a+A@mail.gmail.com">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<div dir="ltr">
<div class="gmail_quote">
<div class="gmail_attr">A few comments inline.<br>
</div>
<div dir="ltr" class="gmail_attr"><br>
</div>
<div dir="ltr" class="gmail_attr">On Thu, Jan 4, 2024 at
12:35 PM <<a href="mailto:berndmoessner80@gmail.com"
moz-do-not-send="true" class="moz-txt-link-freetext">berndmoessner80@gmail.com</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote"
style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">From:
Bernd Moessner <<a
href="mailto:berndmoessner80@gmail.com" target="_blank"
moz-do-not-send="true" class="moz-txt-link-freetext">berndmoessner80@gmail.com</a>><br>
<br>
---<br>
cpukit/dev/flash/flashdev.c | 71 ++++--<br>
cpukit/include/dev/flash/flashdev.h | 22 +-<br>
cpukit/libmisc/shell/main_flashdev.c | 26 +--<br>
testsuites/libtests/flashdev01/init.c | 204
++++++++++++------<br>
.../libtests/flashdev01/test_flashdev.c | 54 +++--<br>
.../libtests/flashdev01/test_flashdev.h | 4 +-<br>
6 files changed, 264 insertions(+), 117 deletions(-)<br>
<br>
diff --git a/cpukit/dev/flash/flashdev.c
b/cpukit/dev/flash/flashdev.c<br>
index 0020e8d2c1..f50d2235a1 100644<br>
--- a/cpukit/dev/flash/flashdev.c<br>
+++ b/cpukit/dev/flash/flashdev.c<br>
@@ -124,7 +124,7 @@ static int
rtems_flashdev_ioctl_get_page_count(<br>
void *arg<br>
);<br>
<br>
-static int rtems_flashdev_ioctl_get_write_block_size(<br>
+static int rtems_flashdev_ioctl_get_min_write_size(<br>
</blockquote>
<div><br>
</div>
<div>I'm not sure I agree with this renaming. As I understood
it, it is actually the write block size which implies all
writes must be a multiple of the write block size versus
minimum write size implying that writes must only be larger
than (or equal to) the provided size. The NOR chips that
support ECC when writing in 16-byte chunks would disable ECC
for partial writes of a 16-byte block performed primarily on
adjacent blocks. I should probably check that there is a
write alignment guarantee in flashdev.</div>
<div> </div>
</div>
</div>
</blockquote>
<br>
<p>No matter on what we agree we, we should document our expectation
how a flash memory is organized.</p>
<p>The memory organization on page 12 in<br>
</p>
<p><a class="moz-txt-link-freetext"
href="https://www.macronix.com/Lists/Datasheet/Attachments/8745/MX25L51245G,%203V,%20512Mb,%20v1.7.pdf">https://www.macronix.com/Lists/Datasheet/Attachments/8745/MX25L51245G,%203V,%20512Mb,%20v1.7.pdf</a></p>
<p>is, from my point of view, the most traditional view on a flash.
Perhaps it is problem of me, but when someone speaks of "block"
wrt. to flash memories I immediately assume it is a multiple of
sections.<br>
</p>
<p> However, I know flashes like the S25FL512S which has the ECC
feature you've mentioned. This special device has "16 Byte
Programming Blocks" with an ECC feature. However, does this lead
"min_write_block_size" or "min_ecc_block_size"? There are other
reasons than ECC for which a driver might want to report back min
write size and aligned writes. Calling it simply "min_write_size"
gives us both, it does not get confused with a block size and it
can report back a size / alignment information. Perhaps, we could
add an IOCTL to allow / forbid aligned writes.</p>
<p><br>
</p>
<blockquote type="cite"
cite="mid:CAPycBojKKBgwmGmYVyxkWNWB=L_r24TAg8dALnWjvTObfd9a+A@mail.gmail.com">
<div dir="ltr">
<div class="gmail_quote">
<blockquote class="gmail_quote"
style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
rtems_flashdev *flash,<br>
void *arg<br>
);<br>
@@ -146,8 +146,7 @@ static int rtems_flashdev_get_abs_addr(<br>
static int rtems_flashdev_update_and_return(<br>
rtems_libio_t *iop,<br>
int status,<br>
- size_t count,<br>
- off_t new_offset<br>
+ size_t count<br>
);<br>
<br>
static uint32_t rtems_flashdev_find_unallocated_region(<br>
@@ -225,13 +224,20 @@ static const
rtems_filesystem_file_handlers_r rtems_flashdev_handler = {<br>
.poll_h = rtems_filesystem_default_poll,<br>
.readv_h = rtems_filesystem_default_readv,<br>
.writev_h = rtems_filesystem_default_writev };<br>
-<br>
+/*<br>
static const IMFS_node_control<br>
rtems_flashdev_node_control = IMFS_GENERIC_INITIALIZER(<br>
&rtems_flashdev_handler,<br>
IMFS_node_initialize_generic,<br>
rtems_flashdev_node_destroy<br>
);<br>
+*/<br>
</blockquote>
<div><br>
</div>
<div>The above definition should be removed instead of
commented out.</div>
<div> <br>
</div>
</div>
</div>
</blockquote>
I`ll keep Aarons implementation. <br>
<blockquote type="cite"
cite="mid:CAPycBojKKBgwmGmYVyxkWNWB=L_r24TAg8dALnWjvTObfd9a+A@mail.gmail.com">
<div dir="ltr">
<div class="gmail_quote">
<blockquote class="gmail_quote"
style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+static const IMFS_node_control rtems_flashdev_node_control
= {<br>
+ .handlers = &rtems_flashdev_handler,<br>
+ .node_initialize = IMFS_node_initialize_generic,<br>
+ .node_remove = IMFS_node_remove_default,<br>
+ .node_destroy = rtems_flashdev_node_destroy<br>
+};<br>
<br>
static void rtems_flashdev_node_destroy(<br>
IMFS_jnode_t *node<br>
@@ -321,7 +327,7 @@ static int rtems_flashdev_read_write(<br>
int status;<br>
<br>
if ( read_buff == NULL && write_buff == NULL ) {<br>
- return 0;<br>
+ return EINVAL;<br>
}<br>
<br>
/* Get flash address */<br>
@@ -335,12 +341,35 @@ static int rtems_flashdev_read_write(<br>
if ( read_buff != NULL ) {<br>
status = ( *flash->read )( flash, addr, count,
read_buff );<br>
} else if ( write_buff != NULL ) {<br>
+ size_t min_write_size = 0;<br>
+ status = (flash)->get_min_write_size(flash,
&min_write_size);<br>
+<br>
+ if ( status < 0 ) {<br>
+ return status;<br>
+ }<br>
+<br>
+ if (0 == min_write_size )<br>
+ {<br>
+ rtems_set_errno_and_return_minus_one( EIO );<br>
+ }<br>
+ else<br>
+ {<br>
+ if (count % min_write_size)<br>
+ {<br>
+ rtems_set_errno_and_return_minus_one( EINVAL );<br>
+ }<br>
+ if (addr % min_write_size)<br>
+ {<br>
+ rtems_set_errno_and_return_minus_one( EFAULT );<br>
+ }<br>
+ }<br>
+<br>
status = ( *flash->write )( flash, addr, count,
write_buff );<br>
}<br>
rtems_flashdev_release( flash );<br>
<br>
/* Update offset and return */<br>
- return rtems_flashdev_update_and_return( iop, status,
count, addr + count );<br>
+ return rtems_flashdev_update_and_return( iop, status,
count );<br>
}<br>
<br>
static int rtems_flashdev_ioctl(<br>
@@ -388,8 +417,8 @@ static int rtems_flashdev_ioctl(<br>
case RTEMS_FLASHDEV_IOCTL_GET_PAGE_COUNT:<br>
err = rtems_flashdev_ioctl_get_page_count( flash, arg
);<br>
break;<br>
- case RTEMS_FLASHDEV_IOCTL_GET_WRITE_BLOCK_SIZE:<br>
- err = rtems_flashdev_ioctl_get_write_block_size(
flash, arg );<br>
+ case RTEMS_FLASHDEV_IOCTL_GET_MIN_WRITE_SIZE:<br>
+ err = rtems_flashdev_ioctl_get_min_write_size( flash,
arg );<br>
break;<br>
default:<br>
err = EINVAL;<br>
@@ -486,6 +515,18 @@ int rtems_flashdev_register(<br>
return rv;<br>
}<br>
<br>
+int rtems_flashdev_deregister(<br>
+ const char *flash_path<br>
+)<br>
+{<br>
+ rtems_filesystem_eval_path_context_t ctx;<br>
+ int eval_flags = RTEMS_FS_FOLLOW_LINK;<br>
+ const rtems_filesystem_location_info_t *currentloc =<br>
+ rtems_filesystem_eval_path_start( &ctx ,
flash_path, eval_flags );<br>
+<br>
+ return IMFS_rmnod(NULL, currentloc);<br>
+}<br>
+<br>
static int rtems_flashdev_do_init(<br>
rtems_flashdev *flash,<br>
void ( *destroy )( rtems_flashdev *flash )<br>
@@ -503,7 +544,7 @@ static int rtems_flashdev_do_init(<br>
flash->get_page_info_by_offset = NULL;<br>
flash->get_page_info_by_index = NULL;<br>
flash->get_page_count = NULL;<br>
- flash->get_write_block_size = NULL;<br>
+ flash->get_min_write_size = NULL;<br>
flash->region_table = NULL;<br>
return 0;<br>
}<br>
@@ -520,7 +561,6 @@ void rtems_flashdev_destroy_and_free(
rtems_flashdev *flash )<br>
}<br>
rtems_recursive_mutex_destroy( &( flash->mutex )
);<br>
free( flash );<br>
- flash = NULL;<br>
</blockquote>
<div><br>
</div>
<div>Unrelated change?<br>
</div>
<div> </div>
</div>
</div>
</blockquote>
<p>Ouch, yes</p>
<p><br>
</p>
<blockquote type="cite"
cite="mid:CAPycBojKKBgwmGmYVyxkWNWB=L_r24TAg8dALnWjvTObfd9a+A@mail.gmail.com">
<div dir="ltr">
<div class="gmail_quote">
<blockquote class="gmail_quote"
style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
return;<br>
}<br>
<br>
@@ -602,13 +642,12 @@ static int
rtems_flashdev_get_abs_addr(<br>
static int rtems_flashdev_update_and_return(<br>
rtems_libio_t *iop,<br>
int status,<br>
- size_t count,<br>
- off_t new_offset<br>
+ size_t count<br>
)<br>
{<br>
/* Update offset and return */<br>
if ( status == 0 ) {<br>
- iop->offset = new_offset;<br>
+ iop->offset += count;<br>
return count;<br>
} else {<br>
rtems_set_errno_and_return_minus_one( status );<br>
@@ -847,7 +886,7 @@ static int
rtems_flashdev_ioctl_get_page_count( rtems_flashdev *flash,
void *arg<br>
}<br>
}<br>
<br>
-static int rtems_flashdev_ioctl_get_write_block_size(<br>
+static int rtems_flashdev_ioctl_get_min_write_size(<br>
rtems_flashdev *flash,<br>
void *arg<br>
)<br>
@@ -855,10 +894,10 @@ static int
rtems_flashdev_ioctl_get_write_block_size(<br>
if ( arg == NULL ) {<br>
rtems_set_errno_and_return_minus_one( EINVAL );<br>
}<br>
- if ( flash->get_write_block_size == NULL ) {<br>
+ if ( flash->get_min_write_size == NULL ) {<br>
return 0;<br>
} else {<br>
- return ( *flash->get_write_block_size )( flash, (
(size_t *) arg ) );<br>
+ return ( *flash->get_min_write_size )( flash, (
(size_t *) arg ) );<br>
}<br>
}<br>
<br>
diff --git a/cpukit/include/dev/flash/flashdev.h
b/cpukit/include/dev/flash/flashdev.h<br>
index 6244d38e3a..f6973df2a3 100644<br>
--- a/cpukit/include/dev/flash/flashdev.h<br>
+++ b/cpukit/include/dev/flash/flashdev.h<br>
@@ -142,7 +142,7 @@ typedef struct rtems_flashdev
rtems_flashdev;<br>
*<br>
* @param[out] count Integer containing the minimum write
size.<br>
*/<br>
-#define RTEMS_FLASHDEV_IOCTL_GET_WRITE_BLOCK_SIZE 10<br>
+#define RTEMS_FLASHDEV_IOCTL_GET_MIN_WRITE_SIZE 10<br>
<br>
/**<br>
* @brief The maximum number of region limited file
descriptors<br>
@@ -354,14 +354,14 @@ struct rtems_flashdev {<br>
* @brief Call to device driver to return the minimum
write size of the<br>
* flash device.<br>
*<br>
- * @param[out] write_block_size The minimum write size of
the flash device.<br>
+ * @param[out] min_write_size The minimum write size of
the flash device.<br>
*<br>
* @retval 0 Success.<br>
* @retval non-zero Failed.<br>
*/<br>
- int ( *get_write_block_size )(<br>
+ int ( *get_min_write_size )(<br>
rtems_flashdev *flashdev,<br>
- size_t *write_block_size<br>
+ size_t *min_write_size<br>
);<br>
<br>
/**<br>
@@ -441,6 +441,20 @@ int rtems_flashdev_register(<br>
const char *flash_path<br>
);<br>
<br>
+/**<br>
+ * @brief Deregister the flash device.<br>
+ *<br>
+ * This function removes the node allocated for the flash
device.<br>
+ *<br>
+ * @param[in] flash_path The path to the flash device file.<br>
+ *<br>
+ * @retval 0 Successful operation.<br>
+ * @retval non-zero Failed operation.<br>
+ */<br>
+int rtems_flashdev_deregister(<br>
+ const char *flash_path<br>
+);<br>
+<br>
/**<br>
* @brief Destroys the flash device.<br>
*<br>
diff --git a/cpukit/libmisc/shell/main_flashdev.c
b/cpukit/libmisc/shell/main_flashdev.c<br>
index 516c77ae27..5851adfeef 100644<br>
--- a/cpukit/libmisc/shell/main_flashdev.c<br>
+++ b/cpukit/libmisc/shell/main_flashdev.c<br>
@@ -40,7 +40,7 @@ static int
flashdev_shell_get_jedec_id(char *dev_path);<br>
static int flashdev_shell_get_page_by_off(char *dev_path,
int argc, char *argv[]);<br>
static int flashdev_shell_get_page_by_idx(char *dev_path,
int argc, char *argv[]);<br>
static int flashdev_shell_get_pg_count(char *dev_path);<br>
-static int flashdev_shell_get_wb_size(char *dev_path);<br>
+static int flashdev_shell_get_min_write_size(char
*dev_path);<br>
<br>
static int flashdev_shell_ioctl_value(<br>
char *dev_path,<br>
@@ -67,7 +67,7 @@ static const char
rtems_flashdev_shell_usage [] =<br>
" -o <address> Print the page
information of page at address\n"<br>
" -i <index> Print the page
information of page at index\n"<br>
" -p Print the number of pages\n"<br>
- " -b Print the write block size\n"<br>
+ " -b Print the min. write size\n"<br>
" -h Print this help\n";<br>
<br>
<br>
@@ -98,23 +98,23 @@ static int rtems_flashdev_shell_main(
int argc, char *argv[] ) {<br>
/* Erase */<br>
return flashdev_shell_erase(dev_path, argc,
&argv[i]);<br>
case ('t'):<br>
- /* Flash Type */<br>
+ /* Get flash Type */<br>
return flashdev_shell_get_type(dev_path);<br>
case ('d'):<br>
- /* JEDEC Id */<br>
+ /* Get JEDEC Id */<br>
return flashdev_shell_get_jedec_id(dev_path);<br>
case ('o'):<br>
- /* Page info by offset */<br>
+ /* Get page info by offset */<br>
return flashdev_shell_get_page_by_off(dev_path,
argc, &argv[i]);<br>
case ('i'):<br>
- /* Page info by index */<br>
+ /* Get page info by index */<br>
return flashdev_shell_get_page_by_idx(dev_path,
argc, &argv[i]);<br>
case ('p'):<br>
- /* Page count */<br>
+ /* Get page count */<br>
return flashdev_shell_get_pg_count(dev_path);<br>
case ('b'):<br>
- /* Write block size */<br>
- return flashdev_shell_get_wb_size(dev_path);<br>
+ /* Get min write size */<br>
+ return flashdev_shell_get_min_write_size(dev_path);<br>
case ('h'):<br>
default:<br>
/* Help */<br>
@@ -480,7 +480,7 @@ static int flashdev_shell_get_pg_count(
char *dev_path )<br>
return 0;<br>
}<br>
<br>
-static int flashdev_shell_get_wb_size( char *dev_path )<br>
+static int flashdev_shell_get_min_write_size( char
*dev_path )<br>
{<br>
size_t ret;<br>
int status;<br>
@@ -488,16 +488,16 @@ static int flashdev_shell_get_wb_size(
char *dev_path )<br>
/* Get Write Block Size */<br>
status = flashdev_shell_ioctl_value(<br>
dev_path,<br>
- RTEMS_FLASHDEV_IOCTL_GET_WRITE_BLOCK_SIZE,<br>
+ RTEMS_FLASHDEV_IOCTL_GET_MIN_WRITE_SIZE,<br>
&ret<br>
);<br>
<br>
/* Print Write Block Size */<br>
if (status) {<br>
- printf("Failed to get write block size\n");<br>
+ printf("Failed to get min write size\n");<br>
return status;<br>
} else {<br>
- printf("Write block size: 0x%zx\n", ret);<br>
+ printf("Min. Write size: 0x%zx\n", ret);<br>
}<br>
return 0;<br>
}<br>
diff --git a/testsuites/libtests/flashdev01/init.c
b/testsuites/libtests/flashdev01/init.c<br>
index 30af3f33c1..dc174daa62 100644<br>
--- a/testsuites/libtests/flashdev01/init.c<br>
+++ b/testsuites/libtests/flashdev01/init.c<br>
@@ -34,14 +34,15 @@<br>
#include <fcntl.h><br>
#include <sys/ioctl.h><br>
<br>
-#define TEST_NAME_LENGTH 10<br>
+<br>
<br>
#define TEST_DATA_SIZE (PAGE_SIZE * PAGE_COUNT)<br>
#define PAGE_COUNT 16<br>
#define PAGE_SIZE 128<br>
-#define WB_SIZE 1<br>
+#define MIN_WRITE_SIZE 1<br>
<br>
const char rtems_test_name[] = "FLASHDEV 1";<br>
+const char test_string[] = "My test string!";<br>
<br>
static void run_test(void);<br>
<br>
@@ -53,89 +54,134 @@ static void run_test(void) {<br>
rtems_flashdev* flash;<br>
int status;<br>
char* read_data;<br>
+ size_t bytes_read;<br>
rtems_flashdev_region e_args;<br>
rtems_flashdev_ioctl_page_info pg_info;<br>
rtems_flashdev_region region;<br>
uint32_t jedec;<br>
int page_count;<br>
int type;<br>
- size_t wb_size;<br>
+ size_t min_write_size_in[] = {1,8,16};<br>
+ size_t min_write_size_out;<br>
+ const char flash_path[] = "/dev/flashdev0";<br>
+<br>
+ for ( int loop = 0; loop <= 2; loop++)<br>
+ {<br>
+ /* Initalize the flash device driver and flashdev */<br>
+ flash = test_flashdev_init(min_write_size_in[loop]);<br>
+ rtems_test_assert(flash != NULL);<br>
+<br>
+ /* Register the flashdev as a device */<br>
+ status = rtems_flashdev_register(flash, flash_path);<br>
+ rtems_test_assert(!status);<br>
+<br>
+ /* Open the flashdev */<br>
+ file = fopen(flash_path, "r+");<br>
+ rtems_test_assert(file != NULL);<br>
+<br>
+ /* Adjust the file buffering */<br>
+ status = setvbuf(file, NULL, _IOFBF,
min_write_size_in[loop]);<br>
+ rtems_test_assert(!status);<br>
+<br>
+ fd = fileno(file);<br>
+<br>
+ /* Read data from flash */<br>
+ read_data = fgets(buff, TEST_DATA_SIZE, file);<br>
+ rtems_test_assert(read_data != NULL);<br>
+<br>
+ /* Fseek to start of flash and read again */<br>
+ status = fseek(file, 0x0, SEEK_SET);<br>
+ rtems_test_assert(!status);<br>
+ bytes_read = fread(buff, 1, TEST_DATA_SIZE, file);<br>
+ rtems_test_assert(bytes_read == TEST_DATA_SIZE);<br>
+<br>
+ /* Fseek to start of flash */<br>
+ status = fseek(file, 0x0, SEEK_SET);<br>
+ rtems_test_assert(!status);<br>
+<br>
+ /* Write the test name to the flash */<br>
+ status = fwrite(test_string, 1, sizeof(test_string),
file);<br>
+ rtems_test_assert(status == sizeof(test_string));<br>
+<br>
+ /* Fseek to start of flash and read again */<br>
+ status = fseek(file, 0x0, SEEK_SET);<br>
+ rtems_test_assert(!status);<br>
+ fgets(buff, TEST_DATA_SIZE, file);<br>
+ rtems_test_assert(!strncmp(buff, test_string,
sizeof(test_string)));<br>
+<br>
+ /* Test Erasing */<br>
+ e_args.offset = 0x0;<br>
+ e_args.size = PAGE_SIZE;<br>
+ status = ioctl(fd, RTEMS_FLASHDEV_IOCTL_ERASE,
&e_args);<br>
+ rtems_test_assert(!status);<br>
+<br>
+ fseek(file, 0x0, SEEK_SET);<br>
+ fgets(buff, TEST_DATA_SIZE, file);<br>
+ rtems_test_assert(buff[0] == 0);<br>
+<br>
+ /* Test getting JEDEC ID */<br>
+ status = ioctl(fd, RTEMS_FLASHDEV_IOCTL_GET_JEDEC_ID,
&jedec);<br>
+ rtems_test_assert(!status);<br>
+ rtems_test_assert(jedec == 0x00ABCDEF);<br>
+<br>
+ /* Test getting flash type */<br>
+ status = ioctl(fd, RTEMS_FLASHDEV_IOCTL_GET_TYPE,
&type);<br>
+ rtems_test_assert(!status);<br>
+ rtems_test_assert(type == RTEMS_FLASHDEV_NOR);<br>
+<br>
+ /* Test getting page info from offset */<br>
+ pg_info.location = PAGE_SIZE + PAGE_SIZE/2;<br>
+<br>
+ status = ioctl(fd,
RTEMS_FLASHDEV_IOCTL_GET_PAGEINFO_BY_OFFSET, &pg_info);<br>
+ rtems_test_assert(!status);<br>
+ rtems_test_assert(pg_info.page_info.offset ==
PAGE_SIZE);<br>
+ rtems_test_assert(pg_info.page_info.size == PAGE_SIZE);<br>
+<br>
+ /* Test getting page info from index */<br>
+ pg_info.location = 2;<br>
+ status = ioctl(fd,
RTEMS_FLASHDEV_IOCTL_GET_PAGEINFO_BY_INDEX, &pg_info);<br>
+ rtems_test_assert(!status);<br>
+ rtems_test_assert(pg_info.page_info.offset ==
2*PAGE_SIZE);<br>
+ rtems_test_assert(pg_info.page_info.size == PAGE_SIZE);<br>
+<br>
+ /* Test getting page count */<br>
+ status = ioctl(fd, RTEMS_FLASHDEV_IOCTL_GET_PAGE_COUNT,
&page_count);<br>
+ rtems_test_assert(!status);<br>
+ rtems_test_assert(page_count == PAGE_COUNT);<br>
+<br>
+ /* Test getting min write size */<br>
+ status = ioctl(fd,
RTEMS_FLASHDEV_IOCTL_GET_MIN_WRITE_SIZE,
&min_write_size_out);<br>
+ rtems_test_assert(!status);<br>
+ rtems_test_assert(0 == memcmp(&min_write_size_out,
&min_write_size_in[loop] , sizeof(size_t)));<br>
+<br>
+ /* Close the file handle */<br>
+ status = fclose(file);<br>
+ rtems_test_assert(!status);<br>
+<br>
+ /* Deregister path */<br>
+ status = rtems_flashdev_deregister(flash_path);<br>
+ rtems_test_assert(!status);<br>
+<br>
+ test_flashdev_deinit(flash);<br>
+ }<br>
<br>
/* Initalize the flash device driver and flashdev */<br>
- flash = test_flashdev_init();<br>
+ flash = test_flashdev_init(min_write_size_in[1]);<br>
rtems_test_assert(flash != NULL);<br>
<br>
/* Register the flashdev as a device */<br>
- status = rtems_flashdev_register(flash, "dev/flashdev0");<br>
+ status = rtems_flashdev_register(flash, flash_path);<br>
rtems_test_assert(!status);<br>
<br>
/* Open the flashdev */<br>
- file = fopen("dev/flashdev0", "r+");<br>
+ file = fopen(flash_path, "r+");<br>
rtems_test_assert(file != NULL);<br>
- fd = fileno(file);<br>
-<br>
- /* Read data from flash */<br>
- read_data = fgets(buff, TEST_DATA_SIZE, file);<br>
- rtems_test_assert(read_data != NULL);<br>
-<br>
- /* Fseek to start of flash */<br>
- status = fseek(file, 0x0, SEEK_SET);<br>
- rtems_test_assert(!status);<br>
-<br>
- /* Write the test name to the flash */<br>
- status = fwrite(rtems_test_name, TEST_NAME_LENGTH, 1,
file);<br>
- rtems_test_assert(status == 1);<br>
-<br>
- /* Fseek to start of flash and read again */<br>
- status = fseek(file, 0x0, SEEK_SET);<br>
- rtems_test_assert(!status);<br>
- fgets(buff, TEST_DATA_SIZE, file);<br>
- rtems_test_assert(!strncmp(buff, rtems_test_name,
TEST_NAME_LENGTH));<br>
<br>
- /* Test Erasing */<br>
- e_args.offset = 0x0;<br>
- e_args.size = PAGE_SIZE;<br>
- status = ioctl(fd, RTEMS_FLASHDEV_IOCTL_ERASE,
&e_args);<br>
+ /* Adjust the file buffering */<br>
+ status = setvbuf(file, NULL, _IOFBF,
min_write_size_in[1]);<br>
rtems_test_assert(!status);<br>
<br>
- fseek(file, 0x0, SEEK_SET);<br>
- fgets(buff, TEST_DATA_SIZE, file);<br>
- rtems_test_assert(buff[0] == 0);<br>
-<br>
- /* Test getting JEDEC ID */<br>
- status = ioctl(fd, RTEMS_FLASHDEV_IOCTL_GET_JEDEC_ID,
&jedec);<br>
- rtems_test_assert(!status);<br>
- rtems_test_assert(jedec == 0x00ABCDEF);<br>
-<br>
- /* Test getting flash type */<br>
- status = ioctl(fd, RTEMS_FLASHDEV_IOCTL_GET_TYPE,
&type);<br>
- rtems_test_assert(!status);<br>
- rtems_test_assert(type == RTEMS_FLASHDEV_NOR);<br>
-<br>
- /* Test getting page info from offset */<br>
- pg_info.location = PAGE_SIZE + PAGE_SIZE/2;<br>
-<br>
- status = ioctl(fd,
RTEMS_FLASHDEV_IOCTL_GET_PAGEINFO_BY_OFFSET, &pg_info);<br>
- rtems_test_assert(!status);<br>
- rtems_test_assert(pg_info.page_info.offset == PAGE_SIZE);<br>
- rtems_test_assert(pg_info.page_info.size == PAGE_SIZE);<br>
-<br>
- /* Test getting page info from index */<br>
- pg_info.location = 2;<br>
- status = ioctl(fd,
RTEMS_FLASHDEV_IOCTL_GET_PAGEINFO_BY_INDEX, &pg_info);<br>
- rtems_test_assert(!status);<br>
- rtems_test_assert(pg_info.page_info.offset ==
2*PAGE_SIZE);<br>
- rtems_test_assert(pg_info.page_info.size == PAGE_SIZE);<br>
-<br>
- /* Test getting page count */<br>
- status = ioctl(fd, RTEMS_FLASHDEV_IOCTL_GET_PAGE_COUNT,
&page_count);<br>
- rtems_test_assert(!status);<br>
- rtems_test_assert(page_count == PAGE_COUNT);<br>
-<br>
- /* Test getting write block size */<br>
- status = ioctl(fd,
RTEMS_FLASHDEV_IOCTL_GET_WRITE_BLOCK_SIZE, &wb_size);<br>
- rtems_test_assert(!status);<br>
- rtems_test_assert(wb_size == WB_SIZE);<br>
+ fd = fileno(file);<br>
<br>
/* Test Regions */<br>
region.offset = 0x400;<br>
@@ -143,10 +189,16 @@ static void run_test(void) {<br>
status = ioctl(fd, RTEMS_FLASHDEV_IOCTL_SET_REGION,
®ion);<br>
rtems_test_assert(!status);<br>
<br>
+ /* Test read within then region */<br>
+ status = fseek(file, 0x0, SEEK_SET);<br>
+ rtems_test_assert(!status);<br>
+ bytes_read = fread(buff, 1, 0x200, file);<br>
+ rtems_test_assert(bytes_read == 0x200);<br>
+<br>
/* Test read to larger then region */<br>
fseek(file, 0x0, SEEK_SET);<br>
read_data = fgets(buff, 2048, file);<br>
- rtems_test_assert(read_data == NULL);<br>
+ rtems_test_assert(buff[0] == 0);<br>
<br>
/* Test fseek outside of region */<br>
status = fseek(file, 0x201, SEEK_SET);<br>
@@ -154,11 +206,21 @@ static void run_test(void) {<br>
<br>
/* Write to base unset region and check the writes
location */<br>
fseek(file, 0x0, SEEK_SET);<br>
- fwrite("HELLO WORLD", 11, 1, file);<br>
+ fwrite("HELLO WORLD!!!!!", 1, 16, file);<br>
ioctl(fd, RTEMS_FLASHDEV_IOCTL_UNSET_REGION, NULL);<br>
fseek(file, 0x400, SEEK_SET);<br>
- fgets(buff, 11, file);<br>
- rtems_test_assert(strncmp(buff, "HELLO WORLD", 11));<br>
+ fgets(buff, 16, file);<br>
+ rtems_test_assert(strncmp(buff, "HELLO WORLD!!!!!", 16));<br>
+<br>
+ /* Close the file handle */<br>
+ status = fclose(file);<br>
+ rtems_test_assert(!status);<br>
+<br>
+ /* Deregister path */<br>
+ status = rtems_flashdev_deregister(flash_path);<br>
+ rtems_test_assert(!status);<br>
+<br>
+ test_flashdev_deinit(flash);<br>
}<br>
<br>
static void Init(rtems_task_argument arg)<br>
diff --git a/testsuites/libtests/flashdev01/test_flashdev.c
b/testsuites/libtests/flashdev01/test_flashdev.c<br>
index d97f5d8145..0022210668 100644<br>
--- a/testsuites/libtests/flashdev01/test_flashdev.c<br>
+++ b/testsuites/libtests/flashdev01/test_flashdev.c<br>
@@ -33,11 +33,12 @@<br>
#define TEST_DATA_SIZE (PAGE_SIZE * PAGE_COUNT)<br>
#define PAGE_COUNT 16<br>
#define PAGE_SIZE 128<br>
-#define WB_SIZE 1<br>
#define MAX_NUM_REGIONS 48<br>
#define BITALLOC_SIZE 32<br>
#define NUM_BITALLOC ((MAX_NUM_REGIONS + BITALLOC_SIZE - 1)
/ BITALLOC_SIZE)<br>
<br>
+static size_t g_min_write_size = 0;<br>
+<br>
/**<br>
* This flash device driver is for testing flashdev<br>
* API calls.<br>
@@ -68,9 +69,9 @@ int test_flashdev_get_page_count(<br>
int *page_count<br>
);<br>
<br>
-int test_flashdev_get_wb_size(<br>
+int test_flashdev_get_min_write_size(<br>
rtems_flashdev *flash,<br>
- size_t *write_block_size<br>
+ size_t *min_write_size<br>
);<br>
<br>
uint32_t test_flashdev_get_jedec_id(<br>
@@ -102,7 +103,7 @@ int test_flashdev_erase(<br>
size_t count<br>
);<br>
<br>
-/* Find page info by offset handler */<br>
+/* Get page info by offset handler */<br>
int test_flashdev_get_page_by_off(<br>
rtems_flashdev *flash,<br>
off_t search_offset,<br>
@@ -115,7 +116,7 @@ int test_flashdev_get_page_by_off(<br>
return 0;<br>
}<br>
<br>
-/* Find page by index handler */<br>
+/* Get page info by index handler */<br>
int test_flashdev_get_page_by_index(<br>
rtems_flashdev *flash,<br>
off_t search_index,<br>
@@ -128,7 +129,7 @@ int test_flashdev_get_page_by_index(<br>
return 0;<br>
}<br>
<br>
-/* Page count handler */<br>
+/* Get page count handler */<br>
int test_flashdev_get_page_count(<br>
rtems_flashdev *flash,<br>
int *page_count<br>
@@ -138,13 +139,13 @@ int test_flashdev_get_page_count(<br>
return 0;<br>
}<br>
<br>
-/* Write block size handler */<br>
-int test_flashdev_get_wb_size(<br>
+/* Get min. write size handler */<br>
+int test_flashdev_get_min_write_size(<br>
rtems_flashdev *flash,<br>
- size_t *write_block_size<br>
+ size_t *min_write_size<br>
)<br>
{<br>
- *write_block_size = WB_SIZE;<br>
+ *min_write_size = g_min_write_size;<br>
return 0;<br>
}<br>
<br>
@@ -230,8 +231,13 @@ int test_flashdev_erase(<br>
}<br>
<br>
/* Initialize Flashdev and underlying driver. */<br>
-rtems_flashdev* test_flashdev_init(void)<br>
+rtems_flashdev* test_flashdev_init(size_t min_write_size)<br>
{<br>
+ if (0 == min_write_size) {<br>
+ return NULL;<br>
+ }<br>
+<br>
+ g_min_write_size = min_write_size;<br>
rtems_flashdev *flash =
rtems_flashdev_alloc_and_init(sizeof(rtems_flashdev));<br>
<br>
if (flash == NULL) {<br>
@@ -268,8 +274,32 @@ rtems_flashdev*
test_flashdev_init(void)<br>
flash->get_page_info_by_offset =
&test_flashdev_get_page_by_off;<br>
flash->get_page_info_by_index =
&test_flashdev_get_page_by_index;<br>
flash->get_page_count =
&test_flashdev_get_page_count;<br>
- flash->get_write_block_size =
&test_flashdev_get_wb_size;<br>
+ flash->get_min_write_size =
&test_flashdev_get_min_write_size;<br>
flash->region_table = ftable;<br>
<br>
return flash;<br>
}<br>
+<br>
+/* Free Flashdev and underlying driver. */<br>
+void test_flashdev_deinit(<br>
+ rtems_flashdev* flash<br>
+)<br>
+{<br>
+ if (NULL != flash)<br>
+ {<br>
+ if (NULL != flash->driver)<br>
+ {<br>
+ free(flash->region_table);<br>
+ }<br>
+ if (NULL != flash->driver)<br>
+ {<br>
+ test_flashdev* flash_driver = (test_flashdev*)
flash->driver;<br>
+ if (NULL != flash_driver->data)<br>
+ {<br>
+ free( flash_driver->data);<br>
+ }<br>
+ free(flash->driver);<br>
+ }<br>
+ rtems_flashdev_destroy_and_free(flash);<br>
+ }<br>
+}<br>
diff --git a/testsuites/libtests/flashdev01/test_flashdev.h
b/testsuites/libtests/flashdev01/test_flashdev.h<br>
index 8b03959c42..ad995854ea 100644<br>
--- a/testsuites/libtests/flashdev01/test_flashdev.h<br>
+++ b/testsuites/libtests/flashdev01/test_flashdev.h<br>
@@ -30,6 +30,8 @@<br>
<br>
#include <dev/flash/flashdev.h><br>
<br>
-rtems_flashdev* test_flashdev_init(void);<br>
+rtems_flashdev* test_flashdev_init(size_t min_write_size);<br>
+<br>
+void test_flashdev_deinit(rtems_flashdev* flash);<br>
<br>
#endif /* __TEST_FLASHDEV_H */<br>
-- <br>
2.34.1<br>
<br>
_______________________________________________<br>
devel mailing list<br>
<a href="mailto:devel@rtems.org" target="_blank"
moz-do-not-send="true" class="moz-txt-link-freetext">devel@rtems.org</a><br>
<a href="http://lists.rtems.org/mailman/listinfo/devel"
rel="noreferrer" target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">http://lists.rtems.org/mailman/listinfo/devel</a><br>
</blockquote>
</div>
</div>
</blockquote>
</body>
</html>