fileio: improve API types
Use size_t instead of uint32_t when specifying file sizes. Update all consumers up through the layers to use size_t when required. These changes should be safe, but the higher-levels will need to be updated further to receive the intended benefits (i.e. large file support). Add error checking for fileio_read and file_write. Previously, all errors were being silently ignored, so this change might cause some problems for some people in some cases. However, it gives us the chance to handle any errors that do occur at higher-levels, rather than burying our heads in the sand.
This commit is contained in:
+4
-3
@@ -152,8 +152,8 @@ FLASH_BANK_COMMAND_HANDLER(ecosflash_flash_bank_command)
|
||||
|
||||
static int loadDriver(struct ecosflash_flash_bank *info)
|
||||
{
|
||||
uint32_t buf_cnt;
|
||||
uint32_t image_size;
|
||||
size_t buf_cnt;
|
||||
size_t image_size;
|
||||
struct image image;
|
||||
|
||||
image.base_address_set = 0;
|
||||
@@ -182,7 +182,8 @@ static int loadDriver(struct ecosflash_flash_bank *info)
|
||||
}
|
||||
target_write_buffer(target, image.sections[i].base_address, buf_cnt, buffer);
|
||||
image_size += buf_cnt;
|
||||
LOG_DEBUG("%" PRIu32 " byte written at address 0x%8.8" PRIx32 "", buf_cnt, image.sections[i].base_address);
|
||||
LOG_DEBUG("%zu bytes written at address 0x%8.8" PRIx32 "",
|
||||
buf_cnt, image.sections[i].base_address);
|
||||
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
+2
-2
@@ -811,7 +811,6 @@ COMMAND_HANDLER(handle_flash_write_bank_command)
|
||||
{
|
||||
uint32_t offset;
|
||||
uint8_t *buffer;
|
||||
uint32_t buf_cnt;
|
||||
struct fileio fileio;
|
||||
|
||||
if (argc != 3)
|
||||
@@ -833,6 +832,7 @@ COMMAND_HANDLER(handle_flash_write_bank_command)
|
||||
}
|
||||
|
||||
buffer = malloc(fileio.size);
|
||||
size_t buf_cnt;
|
||||
if (fileio_read(&fileio, fileio.size, buffer, &buf_cnt) != ERROR_OK)
|
||||
{
|
||||
free(buffer);
|
||||
@@ -1059,7 +1059,7 @@ static int flash_write_unlock(struct target *target, struct image *image, uint32
|
||||
/* read sections to the buffer */
|
||||
while (buffer_size < run_size)
|
||||
{
|
||||
uint32_t size_read;
|
||||
size_t size_read;
|
||||
|
||||
size_read = run_size - buffer_size;
|
||||
if (size_read > image->sections[section].size - section_offset)
|
||||
|
||||
+2
-2
@@ -631,7 +631,7 @@ COMMAND_HANDLER(lpc2900_handle_read_custom_command)
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint32_t nwritten;
|
||||
size_t nwritten;
|
||||
ret = fileio_write( &fileio, sizeof(customer),
|
||||
(const uint8_t *)customer, &nwritten );
|
||||
if( ret != ERROR_OK )
|
||||
@@ -755,7 +755,7 @@ COMMAND_HANDLER(lpc2900_handle_write_custom_command)
|
||||
/* Page 4 */
|
||||
uint32_t offset = ISS_CUSTOMER_START1 % FLASH_PAGE_SIZE;
|
||||
memset( page, 0xff, FLASH_PAGE_SIZE );
|
||||
uint32_t size_read;
|
||||
size_t size_read;
|
||||
retval = image_read_section( &image, 0, 0,
|
||||
ISS_CUSTOMER_SIZE1, &page[offset], &size_read);
|
||||
if( retval != ERROR_OK )
|
||||
|
||||
+4
-2
@@ -705,7 +705,7 @@ static int mg_mflash_write(uint32_t addr, uint8_t *buff, uint32_t len)
|
||||
|
||||
COMMAND_HANDLER(mg_write_cmd)
|
||||
{
|
||||
uint32_t address, buf_cnt, cnt, res, i;
|
||||
uint32_t address, cnt, res, i;
|
||||
uint8_t *buffer;
|
||||
struct fileio fileio;
|
||||
int ret;
|
||||
@@ -732,6 +732,7 @@ COMMAND_HANDLER(mg_write_cmd)
|
||||
struct duration bench;
|
||||
duration_start(&bench);
|
||||
|
||||
size_t buf_cnt;
|
||||
for (i = 0; i < cnt; i++) {
|
||||
if ((ret = fileio_read(&fileio, MG_FILEIO_CHUNK, buffer, &buf_cnt)) !=
|
||||
ERROR_OK)
|
||||
@@ -769,7 +770,7 @@ mg_write_cmd_err:
|
||||
|
||||
COMMAND_HANDLER(mg_dump_cmd)
|
||||
{
|
||||
uint32_t address, size_written, size, cnt, res, i;
|
||||
uint32_t address, size, cnt, res, i;
|
||||
uint8_t *buffer;
|
||||
struct fileio fileio;
|
||||
int ret;
|
||||
@@ -797,6 +798,7 @@ COMMAND_HANDLER(mg_dump_cmd)
|
||||
struct duration bench;
|
||||
duration_start(&bench);
|
||||
|
||||
size_t size_written;
|
||||
for (i = 0; i < cnt; i++) {
|
||||
if ((ret = mg_mflash_read(address, buffer, MG_FILEIO_CHUNK)) != ERROR_OK)
|
||||
goto mg_dump_cmd_err;
|
||||
|
||||
+3
-3
@@ -1453,8 +1453,8 @@ static COMMAND_HELPER(nand_fileio_parse_args, struct nand_fileio_state *state,
|
||||
static int nand_fileio_read(struct nand_device *nand,
|
||||
struct nand_fileio_state *s)
|
||||
{
|
||||
uint32_t total_read = 0;
|
||||
uint32_t one_read;
|
||||
size_t total_read = 0;
|
||||
size_t one_read;
|
||||
|
||||
if (NULL != s->page)
|
||||
{
|
||||
@@ -1616,7 +1616,7 @@ COMMAND_HANDLER(handle_nand_dump_command)
|
||||
|
||||
while (s.size > 0)
|
||||
{
|
||||
uint32_t size_written;
|
||||
size_t size_written;
|
||||
int retval = nand_read_page(nand, s.address / nand->page_size,
|
||||
s.page, s.page_size, s.oob, s.oob_size);
|
||||
if (ERROR_OK != retval)
|
||||
|
||||
Reference in New Issue
Block a user