cpukit/flashdev: Clarify interface and update consumers

This clarifies the flashdev out of band read and write interfaces and
updates any consumers of those interfaces. This was partially refactored
at one point and the refactoring didn't extend to the consumers as it
should have.
This commit is contained in:
Kinsey Moore
2026-07-27 12:15:22 +10:00
committed by Chris Johns
parent baeeb5db18
commit 098ba8472d
5 changed files with 49 additions and 30 deletions
+2 -6
View File
@@ -282,9 +282,7 @@ static int flash_sim_oob_read(
uint64_t start_time = rtems_clock_get_uptime_nanoseconds();
struct nand_priv_data *flash_driver = (struct nand_priv_data *) flash->driver;
struct flash_sim_flashdev_attributes *attr = &flash_driver->attr;
uint32_t page_index = offset / attr->page_size_bytes;
uint32_t oob_offset = page_index * attr->page_oob_bytes;
unsigned char *chunk = &flash_driver->oob[ oob_offset ];
unsigned char *chunk = &flash_driver->oob[ offset ];
memcpy( buffer, chunk, size_of_buffer );
@@ -303,9 +301,7 @@ static int flash_sim_oob_write(
uint64_t start_time = rtems_clock_get_uptime_nanoseconds();
struct nand_priv_data *flash_driver = (struct nand_priv_data *) flash->driver;
struct flash_sim_flashdev_attributes *attr = &flash_driver->attr;
uint32_t page_index = offset / attr->page_size_bytes;
uint32_t oob_offset = page_index * attr->page_oob_bytes;
unsigned char *chunk = &flash_driver->oob[ oob_offset ];
unsigned char *chunk = &flash_driver->oob[ offset ];
const uint8_t *cbuff = buffer;
size_t i;
+32 -19
View File
@@ -141,6 +141,36 @@ static int do_block_mark_bad(
return ioctl(fd, RTEMS_FLASHDEV_IOCTL_REGION_SECTOR_MARK_BAD, &o_offset);
}
static uint32_t do_get_oob_size(
rtems_jffs2_flash_control *super
)
{
int rv;
int fd = fileno(get_flash_control( super )->handle);
size_t bytes_per_page = 0;
rv = ioctl(fd, RTEMS_FLASHDEV_IOCTL_OOB_BYTES_PER_PAGE, &bytes_per_page);
if (rv != 0) {
return 0;
}
return bytes_per_page;
}
static uint32_t page_offset_to_oob_offset(
rtems_jffs2_flash_control *super,
uint32_t page_offset
)
{
uint32_t page_size = super->write_size;
uint32_t oob_bytes_per_page = do_get_oob_size(super);
uint32_t page_index = page_offset / page_size;
/* JFFS2 only makes these requests on even page boundaries */
return page_index * oob_bytes_per_page;
}
static int do_read_oob(
rtems_jffs2_flash_control *super,
uint32_t offset,
@@ -151,7 +181,7 @@ static int do_read_oob(
int fd = fileno(get_flash_control( super )->handle);
rtems_flashdev_ioctl_oob_rw_info args;
args.offset = offset;
args.offset = page_offset_to_oob_offset(super, offset);
args.count = ooblen;
args.buffer = oobbuf;
@@ -168,30 +198,13 @@ static int do_write_oob(
int fd = fileno(get_flash_control( super )->handle);
rtems_flashdev_ioctl_oob_rw_info args;
args.offset = offset;
args.offset = page_offset_to_oob_offset(super, offset);
args.count = ooblen;
args.buffer = oobbuf;
return ioctl(fd, RTEMS_FLASHDEV_IOCTL_REGION_OOB_WRITE, &args);
}
static uint32_t do_get_oob_size(
rtems_jffs2_flash_control *super
)
{
int rv;
int fd = fileno(get_flash_control( super )->handle);
size_t bytes_per_page = 0;
rv = ioctl(fd, RTEMS_FLASHDEV_IOCTL_OOB_BYTES_PER_PAGE, &bytes_per_page);
if (rv != 0) {
return 0;
}
return bytes_per_page;
}
static void do_destroy( rtems_jffs2_flash_control *super )
{
flash_control *self = get_flash_control( super );
+4 -4
View File
@@ -331,8 +331,8 @@ static int xnandpsu_oob_read(
return -EIO;
}
/* Get page index */
uint32_t PageIndex = offset / nandpsu->Geometry.BytesPerPage;
/* Get page index, offset is in oob-space */
uint32_t PageIndex = offset / nandpsu->Geometry.SpareBytesPerPage;
spare_bytes = rtems_malloc( SpareBytesPerPage );
if ( spare_bytes == NULL ) {
@@ -402,8 +402,8 @@ static int xnandpsu_oob_write(
memcpy( buffer, oobbuf, ooblen );
}
/* Get page index */
uint32_t PageIndex = offset / nandpsu->Geometry.BytesPerPage;
/* Get page index, offset is in oob-space */
uint32_t PageIndex = offset / nandpsu->Geometry.SpareBytesPerPage;
sc = XNandPsu_WriteSpareBytes( nandpsu, PageIndex, buffer );
free( spare_bytes );