[PATCH rtems6 - v2 12/16] flashdev: Add erase info to page info
berndmoessner80 at gmail.com
berndmoessner80 at gmail.com
Sun Jan 7 18:18:46 UTC 2024
From: Bernd Moessner <berndmoessner80 at gmail.com>
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'):
/* Get page count */
return flashdev_shell_get_page_count(dev_path);
@@ -437,7 +437,7 @@ int flashdev_shell_get_jedec_id( char *dev_path ) {
return 0;
}
-static int flashdev_shell_get_page_by_off(
+static int flashdev_shell_get_page_info_by_offset(
char *dev_path,
int argc,
char *argv[]
@@ -451,7 +451,7 @@ static int flashdev_shell_get_page_by_off(
);
}
-static int flashdev_shell_get_page_by_idx(
+static int flashdev_shell_get_page_info_by_index(
char *dev_path,
int argc,
char *argv[]
@@ -578,6 +578,12 @@ static int flashdev_shell_page(
pg_info.page_info.size
);
+ printf(
+ "Erase block offset: 0x%jx\nErase block length: 0x%zx\n",
+ pg_info.erase_info.offset,
+ pg_info.erase_info.size
+ );
+
/* Clean up */
close(fd);
return 0;
diff --git a/testsuites/libtests/flashdev01/init.c b/testsuites/libtests/flashdev01/init.c
index 8fe1d083f3..84e2c7859d 100644
--- a/testsuites/libtests/flashdev01/init.c
+++ b/testsuites/libtests/flashdev01/init.c
@@ -39,7 +39,7 @@
#define TEST_DATA_SIZE (PAGE_SIZE * PAGE_COUNT)
#define PAGE_COUNT 16
#define PAGE_SIZE 128
-#define MIN_WRTIE_BLOCK_SIZE 1
+#define ERASE_BLOCK_SIZE 256
const char rtems_test_name[] = "FLASHDEV 1";
const char test_string[] = "My test string!";
@@ -70,6 +70,7 @@ static void run_test(void) {
/* Initalize the flash device driver and flashdev */
flash = test_flashdev_init( PAGE_COUNT,
PAGE_SIZE,
+ ERASE_BLOCK_SIZE,
min_write_write_block_size_in[loop]);
rtems_test_assert(flash != NULL);
@@ -131,6 +132,16 @@ static void run_test(void) {
rtems_test_assert(!status);
rtems_test_assert(type == RTEMS_FLASHDEV_NOR);
+ /* Test getting page info */
+ pg_info.location = 0;
+
+ status = ioctl(fd, RTEMS_FLASHDEV_IOCTL_GET_PAGEINFO_BY_OFFSET, &pg_info);
+ rtems_test_assert(!status);
+ rtems_test_assert(pg_info.page_info.offset == 0);
+ rtems_test_assert(pg_info.page_info.size == PAGE_SIZE);
+ rtems_test_assert(pg_info.erase_info.offset == 0);
+ rtems_test_assert(pg_info.erase_info.size == ERASE_BLOCK_SIZE);
+
/* Test getting page info from offset */
pg_info.location = PAGE_SIZE + PAGE_SIZE/2;
@@ -138,6 +149,8 @@ static void run_test(void) {
rtems_test_assert(!status);
rtems_test_assert(pg_info.page_info.offset == PAGE_SIZE);
rtems_test_assert(pg_info.page_info.size == PAGE_SIZE);
+ rtems_test_assert(pg_info.erase_info.offset == 0);
+ rtems_test_assert(pg_info.erase_info.size == ERASE_BLOCK_SIZE);
/* Test getting page info from index */
pg_info.location = 2;
@@ -145,6 +158,8 @@ static void run_test(void) {
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);
+ rtems_test_assert(pg_info.erase_info.offset == ERASE_BLOCK_SIZE);
+ rtems_test_assert(pg_info.erase_info.size == ERASE_BLOCK_SIZE);
/* Test getting page count */
status = ioctl(fd, RTEMS_FLASHDEV_IOCTL_GET_PAGE_COUNT, &page_count);
@@ -173,6 +188,7 @@ static void run_test(void) {
/* Initalize the flash device driver and flashdev */
flash = test_flashdev_init( PAGE_COUNT,
PAGE_SIZE,
+ ERASE_BLOCK_SIZE,
min_write_write_block_size_in[1]);
rtems_test_assert(flash != NULL);
diff --git a/testsuites/libtests/flashdev01/test_flashdev.c b/testsuites/libtests/flashdev01/test_flashdev.c
index d7f8a2fe67..fe72923c6c 100644
--- a/testsuites/libtests/flashdev01/test_flashdev.c
+++ b/testsuites/libtests/flashdev01/test_flashdev.c
@@ -37,6 +37,7 @@
size_t g_min_write_block_size = 0;
size_t g_page_count = 0;
size_t g_page_size = 0;
+size_t g_erase_block_size = 0;
size_t g_test_data_size = 0;
/**
@@ -50,18 +51,22 @@ typedef struct test_flashdev {
rtems_flashdev_region regions[MAX_NUM_REGIONS];
} test_flashdev;
-int test_flashdev_get_page_by_offset(
+int test_flashdev_get_page_info_by_offset(
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
);
-int test_flashdev_get_page_by_index(
+int test_flashdev_get_page_info_by_index(
rtems_flashdev *flash,
off_t search_index,
off_t *page_offset,
- size_t *page_size
+ size_t *page_size,
+ off_t *erase_offset,
+ size_t *erase_size
);
int test_flashdev_get_page_count(
@@ -104,28 +109,36 @@ int test_flashdev_erase(
);
/* Get page info by offset handler */
-int test_flashdev_get_page_by_offset(
+int test_flashdev_get_page_info_by_offset(
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
)
{
*page_offset = search_offset - (search_offset%g_page_size);
*page_size = g_page_size;
+ *erase_size = g_erase_block_size;
+ *erase_offset = *page_offset - (*page_offset % *erase_size);
return 0;
}
/* Get page by index handler */
-int test_flashdev_get_page_by_index(
+int test_flashdev_get_page_info_by_index(
rtems_flashdev *flash,
off_t search_index,
off_t *page_offset,
- size_t *page_size
+ size_t *page_size,
+ off_t *erase_offset,
+ size_t *erase_size
)
{
*page_offset = search_index * g_page_size;
*page_size = g_page_size;
+ *erase_size = g_erase_block_size;
+ *erase_offset = *page_offset - (*page_offset % *erase_size);
return 0;
}
@@ -234,6 +247,7 @@ int test_flashdev_erase(
rtems_flashdev* test_flashdev_init(
size_t page_count,
size_t page_size,
+ size_t erase_block_size,
size_t min_write_block_size
)
{
@@ -243,15 +257,28 @@ rtems_flashdev* test_flashdev_init(
if (0 == page_size) {
return NULL;
}
+ if (0 == erase_block_size) {
+ return NULL;
+ }
if (0 == min_write_block_size) {
return NULL;
}
-
g_page_count = page_count;
g_page_size = page_size;
+ g_erase_block_size = erase_block_size;
g_min_write_block_size = min_write_block_size;
g_test_data_size = g_page_size * g_page_count;
+ if (g_test_data_size % g_erase_block_size) {
+ return NULL;
+ }
+ if (g_erase_block_size % g_page_size) {
+ return NULL;
+ }
+ if (g_page_size % min_write_block_size) {
+ return NULL;
+ }
+
rtems_flashdev *flash = rtems_flashdev_alloc_and_init(sizeof(rtems_flashdev));
if (flash == NULL) {
@@ -285,8 +312,8 @@ rtems_flashdev* test_flashdev_init(
flash->erase = &test_flashdev_erase;
flash->get_jedec_id = &test_flashdev_get_jedec_id;
flash->get_flash_type = &test_flashdev_get_type;
- flash->get_page_info_by_offset = &test_flashdev_get_page_by_offset;
- flash->get_page_info_by_index = &test_flashdev_get_page_by_index;
+ flash->get_page_info_by_offset = &test_flashdev_get_page_info_by_offset;
+ flash->get_page_info_by_index = &test_flashdev_get_page_info_by_index;
flash->get_page_count = &test_flashdev_get_page_count;
flash->get_min_write_block_size = &test_flashdev_get_min_write_block_size;
flash->region_table = ftable;
diff --git a/testsuites/libtests/flashdev01/test_flashdev.h b/testsuites/libtests/flashdev01/test_flashdev.h
index ca2838ecd2..7205e28472 100644
--- a/testsuites/libtests/flashdev01/test_flashdev.h
+++ b/testsuites/libtests/flashdev01/test_flashdev.h
@@ -33,6 +33,7 @@
rtems_flashdev* test_flashdev_init(
size_t page_count,
size_t page_size,
+ size_t erase_block_size,
size_t min_write_block_size
);
--
2.34.1
More information about the devel
mailing list