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.
12 files changed:
static int loadDriver(struct ecosflash_flash_bank *info)
{
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;
struct image image;
image.base_address_set = 0;
}
target_write_buffer(target, image.sections[i].base_address, buf_cnt, buffer);
image_size += buf_cnt;
}
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);
{
uint32_t offset;
uint8_t *buffer;
{
uint32_t offset;
uint8_t *buffer;
struct fileio fileio;
if (argc != 3)
struct fileio fileio;
if (argc != 3)
}
buffer = malloc(fileio.size);
}
buffer = malloc(fileio.size);
if (fileio_read(&fileio, fileio.size, buffer, &buf_cnt) != ERROR_OK)
{
free(buffer);
if (fileio_read(&fileio, fileio.size, buffer, &buf_cnt) != ERROR_OK)
{
free(buffer);
/* read sections to the buffer */
while (buffer_size < run_size)
{
/* read sections to the buffer */
while (buffer_size < run_size)
{
size_read = run_size - buffer_size;
if (size_read > image->sections[section].size - section_offset)
size_read = run_size - buffer_size;
if (size_read > image->sections[section].size - section_offset)
ret = fileio_write( &fileio, sizeof(customer),
(const uint8_t *)customer, &nwritten );
if( ret != ERROR_OK )
ret = fileio_write( &fileio, sizeof(customer),
(const uint8_t *)customer, &nwritten );
if( ret != ERROR_OK )
/* Page 4 */
uint32_t offset = ISS_CUSTOMER_START1 % FLASH_PAGE_SIZE;
memset( page, 0xff, FLASH_PAGE_SIZE );
/* Page 4 */
uint32_t offset = ISS_CUSTOMER_START1 % FLASH_PAGE_SIZE;
memset( page, 0xff, FLASH_PAGE_SIZE );
retval = image_read_section( &image, 0, 0,
ISS_CUSTOMER_SIZE1, &page[offset], &size_read);
if( retval != ERROR_OK )
retval = image_read_section( &image, 0, 0,
ISS_CUSTOMER_SIZE1, &page[offset], &size_read);
if( retval != ERROR_OK )
COMMAND_HANDLER(mg_write_cmd)
{
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;
uint8_t *buffer;
struct fileio fileio;
int ret;
struct duration bench;
duration_start(&bench);
struct duration bench;
duration_start(&bench);
for (i = 0; i < cnt; i++) {
if ((ret = fileio_read(&fileio, MG_FILEIO_CHUNK, buffer, &buf_cnt)) !=
ERROR_OK)
for (i = 0; i < cnt; i++) {
if ((ret = fileio_read(&fileio, MG_FILEIO_CHUNK, buffer, &buf_cnt)) !=
ERROR_OK)
COMMAND_HANDLER(mg_dump_cmd)
{
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;
uint8_t *buffer;
struct fileio fileio;
int ret;
struct duration bench;
duration_start(&bench);
struct duration bench;
duration_start(&bench);
for (i = 0; i < cnt; i++) {
if ((ret = mg_mflash_read(address, buffer, MG_FILEIO_CHUNK)) != ERROR_OK)
goto mg_dump_cmd_err;
for (i = 0; i < cnt; i++) {
if ((ret = mg_mflash_read(address, buffer, MG_FILEIO_CHUNK)) != ERROR_OK)
goto mg_dump_cmd_err;
static int nand_fileio_read(struct nand_device *nand,
struct nand_fileio_state *s)
{
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;
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)
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)
-int fileio_seek(struct fileio *fileio, uint32_t position)
+int fileio_seek(struct fileio *fileio, size_t position)
{
int retval;
if ((retval = fseek(fileio->file, position, SEEK_SET)) != 0)
{
int retval;
if ((retval = fseek(fileio->file, position, SEEK_SET)) != 0)
-static inline int fileio_local_read(struct fileio *fileio, uint32_t size, uint8_t *buffer, uint32_t *size_read)
+static int fileio_local_read(struct fileio *fileio,
+ size_t size, void *buffer, size_t *size_read)
- *size_read = fread(buffer, 1, size, fileio->file);
-
- return ERROR_OK;
+ ssize_t retval = fread(buffer, 1, size, fileio->file);
+ *size_read = (retval >= 0) ? retval : 0;
+ return (retval < 0) ? retval : ERROR_OK;
-int fileio_read(struct fileio *fileio, uint32_t size, uint8_t *buffer, uint32_t *size_read)
+int fileio_read(struct fileio *fileio, size_t size, void *buffer,
+ size_t *size_read)
{
return fileio_local_read(fileio, size, buffer, size_read);
}
{
return fileio_local_read(fileio, size, buffer, size_read);
}
int fileio_read_u32(struct fileio *fileio, uint32_t *data)
{
uint8_t buf[4];
int fileio_read_u32(struct fileio *fileio, uint32_t *data)
{
uint8_t buf[4];
- uint32_t size_read;
- int retval;
-
- if ((retval = fileio_local_read(fileio, 4, buf, &size_read)) != ERROR_OK)
- return retval;
- *data = be_to_h_u32(buf);
-
- return ERROR_OK;
+ size_t size_read;
+ int retval = fileio_local_read(fileio, sizeof(uint32_t), buf, &size_read);
+ if (ERROR_OK == retval && sizeof(uint32_t) != size_read)
+ retval = -EIO;
+ if (ERROR_OK == retval)
+ *data = be_to_h_u32(buf);
+ return retval;
-static inline int fileio_local_fgets(struct fileio *fileio, uint32_t size, char *buffer)
+static int fileio_local_fgets(struct fileio *fileio,
+ size_t size, void *buffer)
{
if (fgets(buffer, size, fileio->file) == NULL)
return ERROR_FILEIO_OPERATION_FAILED;
{
if (fgets(buffer, size, fileio->file) == NULL)
return ERROR_FILEIO_OPERATION_FAILED;
-int fileio_fgets(struct fileio *fileio, uint32_t size, char *buffer)
+int fileio_fgets(struct fileio *fileio, size_t size, void *buffer)
{
return fileio_local_fgets(fileio, size, buffer);
}
{
return fileio_local_fgets(fileio, size, buffer);
}
-static inline int fileio_local_write(struct fileio *fileio, uint32_t size, const uint8_t *buffer, uint32_t *size_written)
+static int fileio_local_write(struct fileio *fileio,
+ size_t size, const void *buffer, size_t *size_written)
- *size_written = fwrite(buffer, 1, size, fileio->file);
-
- return ERROR_OK;
+ ssize_t retval = fwrite(buffer, 1, size, fileio->file);
+ *size_written = (retval >= 0) ? retval : 0;
+ return (retval < 0) ? retval : ERROR_OK;
-int fileio_write(struct fileio *fileio, uint32_t size, const uint8_t *buffer, uint32_t *size_written)
+int fileio_write(struct fileio *fileio,
+ size_t size, const void *buffer, size_t *size_written)
- int retval;
-
- retval = fileio_local_write(fileio, size, buffer, size_written);
-
+ int retval = fileio_local_write(fileio, size, buffer, size_written);
if (retval == ERROR_OK)
fileio->size += *size_written;
if (retval == ERROR_OK)
fileio->size += *size_written;
}
int fileio_write_u32(struct fileio *fileio, uint32_t data)
{
uint8_t buf[4];
}
int fileio_write_u32(struct fileio *fileio, uint32_t data)
{
uint8_t buf[4];
- uint32_t size_written;
- int retval;
-
- if ((retval = fileio_local_write(fileio, 4, buf, &size_written)) != ERROR_OK)
- return retval;
+ size_t size_written;
+ int retval = fileio_write(fileio, 4, buf, &size_written);
+ if (ERROR_OK == retval && size_written != sizeof(uint32_t))
+ retval = -EIO;
const char *url, enum fileio_access access, enum fileio_type type);
int fileio_close(struct fileio *fileio);
const char *url, enum fileio_access access, enum fileio_type type);
int fileio_close(struct fileio *fileio);
-int fileio_seek(struct fileio *fileio, uint32_t position);
-int fileio_fgets(struct fileio *fileio, uint32_t size, char *buffer);
+int fileio_seek(struct fileio *fileio, size_t position);
+int fileio_fgets(struct fileio *fileio, size_t size, void *buffer);
int fileio_read(struct fileio *fileio,
int fileio_read(struct fileio *fileio,
- uint32_t size, uint8_t *buffer, uint32_t *size_read);
+ size_t size, void *buffer, size_t *size_read);
int fileio_write(struct fileio *fileio,
int fileio_write(struct fileio *fileio,
- uint32_t size, const uint8_t *buffer, uint32_t *size_written);
+ size_t size, const void *buffer, size_t *size_written);
int fileio_read_u32(struct fileio *fileio, uint32_t *data);
int fileio_write_u32(struct fileio *fileio, uint32_t data);
int fileio_read_u32(struct fileio *fileio, uint32_t *data);
int fileio_write_u32(struct fileio *fileio, uint32_t data);
{
int i;
int section = -1;
{
int i;
int section = -1;
uint32_t opcode;
int retval;
uint32_t opcode;
int retval;
{
int retval;
struct fileio fileio;
{
int retval;
struct fileio fileio;
uint8_t buffer[9];
/* read the first 4 bytes of image */
uint8_t buffer[9];
/* read the first 4 bytes of image */
uint32_t record_type;
uint32_t checksum;
uint8_t cal_checksum = 0;
uint32_t record_type;
uint32_t checksum;
uint8_t cal_checksum = 0;
- uint32_t bytes_read = 0;
if (sscanf(&lpszLine[bytes_read], ":%2" SCNx32 "%4" SCNx32 "%2" SCNx32 , &count, &address, &record_type) != 3)
{
if (sscanf(&lpszLine[bytes_read], ":%2" SCNx32 "%4" SCNx32 "%2" SCNx32 , &count, &address, &record_type) != 3)
{
static int image_elf_read_headers(struct image *image)
{
struct image_elf *elf = image->type_private;
static int image_elf_read_headers(struct image *image)
{
struct image_elf *elf = image->type_private;
uint32_t i,j;
int retval;
uint32_t i,j;
int retval;
-static int image_elf_read_section(struct image *image, int section, uint32_t offset, uint32_t size, uint8_t *buffer, uint32_t *size_read)
+static int image_elf_read_section(struct image *image, int section, uint32_t offset, uint32_t size, uint8_t *buffer, size_t *size_read)
{
struct image_elf *elf = image->type_private;
Elf32_Phdr *segment = (Elf32_Phdr *)image->sections[section].private;
{
struct image_elf *elf = image->type_private;
Elf32_Phdr *segment = (Elf32_Phdr *)image->sections[section].private;
- uint32_t read_size,really_read;
+ size_t read_size,really_read;
int retval;
*size_read = 0;
int retval;
*size_read = 0;
{
/* maximal size present in file for the current segment */
read_size = MIN(size, field32(elf,segment->p_filesz)-offset);
{
/* maximal size present in file for the current segment */
read_size = MIN(size, field32(elf,segment->p_filesz)-offset);
- LOG_DEBUG("read elf: size = 0x%" PRIx32 " at 0x%" PRIx32 "",read_size,
+ LOG_DEBUG("read elf: size = 0x%zu at 0x%" PRIx32 "", read_size,
field32(elf,segment->p_offset) + offset);
/* read initialized area of the segment */
if ((retval = fileio_seek(&elf->fileio, field32(elf,segment->p_offset) + offset)) != ERROR_OK)
field32(elf,segment->p_offset) + offset);
/* read initialized area of the segment */
if ((retval = fileio_seek(&elf->fileio, field32(elf,segment->p_offset) + offset)) != ERROR_OK)
-int image_read_section(struct image *image, int section, uint32_t offset, uint32_t size, uint8_t *buffer, uint32_t *size_read)
+int image_read_section(struct image *image, int section, uint32_t offset, uint32_t size, uint8_t *buffer, size_t *size_read)
int image_open(struct image *image, const char *url, const char *type_string);
int image_read_section(struct image *image, int section, uint32_t offset,
int image_open(struct image *image, const char *url, const char *type_string);
int image_read_section(struct image *image, int section, uint32_t offset,
- uint32_t size, uint8_t *buffer, uint32_t *size_read);
+ uint32_t size, uint8_t *buffer, size_t *size_read);
void image_close(struct image *image);
int image_add_section(struct image *image, uint32_t base, uint32_t size,
void image_close(struct image *image);
int image_add_section(struct image *image, uint32_t base, uint32_t size,
COMMAND_HANDLER(handle_load_image_command)
{
uint8_t *buffer;
COMMAND_HANDLER(handle_load_image_command)
{
uint8_t *buffer;
uint32_t image_size;
uint32_t min_address = 0;
uint32_t max_address = 0xffffffff;
uint32_t image_size;
uint32_t min_address = 0;
uint32_t max_address = 0xffffffff;
int retval = ERROR_OK;
while (size > 0)
{
int retval = ERROR_OK;
while (size > 0)
{
uint32_t this_run_size = (size > 560) ? 560 : size;
retval = target_read_buffer(target, address, this_run_size, buffer);
if (retval != ERROR_OK)
uint32_t this_run_size = (size > 560) ? 560 : size;
retval = target_read_buffer(target, address, this_run_size, buffer);
if (retval != ERROR_OK)
static COMMAND_HELPER(handle_verify_image_command_internal, int verify)
{
uint8_t *buffer;
static COMMAND_HELPER(handle_verify_image_command_internal, int verify)
{
uint8_t *buffer;
uint32_t image_size;
int i;
int retval;
uint32_t image_size;
int i;
int retval;
- command_print(cmd_ctx, "address 0x%08" PRIx32 " length 0x%08" PRIx32 "",
+ command_print(cmd_ctx, "address 0x%08" PRIx32 " length 0x%08zx",
image.sections[i].base_address,
buf_cnt);
}
image.sections[i].base_address,
buf_cnt);
}
COMMAND_HANDLER(handle_fast_load_image_command)
{
uint8_t *buffer;
COMMAND_HANDLER(handle_fast_load_image_command)
{
uint8_t *buffer;
uint32_t image_size;
uint32_t min_address = 0;
uint32_t max_address = 0xffffffff;
uint32_t image_size;
uint32_t min_address = 0;
uint32_t max_address = 0xffffffff;
struct xscale_common *xscale = target_to_xscale(target);
int i;
int section = -1;
struct xscale_common *xscale = target_to_xscale(target);
int i;
int section = -1;
uint32_t opcode;
int retval;
uint32_t opcode;
int retval;
Linking to existing account procedure
If you already have an account and want to add another login method
you
MUST first sign in with your existing account and
then change URL to read
https://review.openocd.org/login/?link
to get to this page again but this time it'll work for linking. Thank you.
SSH host keys fingerprints
1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=.. |
|+o.. . |
|*.o . . |
|+B . . . |
|Bo. = o S |
|Oo.+ + = |
|oB=.* = . o |
| =+=.+ + E |
|. .=o . o |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)