Part of making the fileio API more robust.
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
if (ret != ERROR_OK)
return ret;
if (ret != ERROR_OK)
return ret;
buffer = malloc(MG_FILEIO_CHUNK);
if (!buffer) {
fileio_close(&fileio);
return ERROR_FAIL;
}
buffer = malloc(MG_FILEIO_CHUNK);
if (!buffer) {
fileio_close(&fileio);
return ERROR_FAIL;
}
+ int retval = fileio_size(&fileio, &filesize);
+ if (retval != ERROR_OK) {
+ fileio_close(&fileio);
+ return retval;
+ }
- cnt = fileio_size(&fileio) / MG_FILEIO_CHUNK;
- res = fileio_size(&fileio) % MG_FILEIO_CHUNK;
+ cnt = filesize / MG_FILEIO_CHUNK;
+ res = filesize % MG_FILEIO_CHUNK;
struct duration bench;
duration_start(&bench);
struct duration bench;
duration_start(&bench);
if (duration_measure(&bench) == ERROR_OK)
{
command_print(CMD_CTX, "wrote %ld bytes from file %s "
if (duration_measure(&bench) == ERROR_OK)
{
command_print(CMD_CTX, "wrote %ld bytes from file %s "
- "in %fs (%0.3f kB/s)", (long)fileio_size(&fileio), CMD_ARGV[1],
- duration_elapsed(&bench), duration_kbps(&bench, fileio_size(&fileio)));
+ "in %fs (%0.3f kB/s)", (long)filesize, CMD_ARGV[1],
+ duration_elapsed(&bench), duration_kbps(&bench, filesize));
return retval;
if (!need_size)
return retval;
if (!need_size)
- state->size = fileio_size(&state->fileio);
+ {
+ int filesize;
+ retval = fileio_size(&state->fileio, &filesize);
+ if (retval != ERROR_OK)
+ return retval;
+ state->size = filesize;
+ }
if (nand_fileio_finish(&s) == ERROR_OK)
{
if (nand_fileio_finish(&s) == ERROR_OK)
{
+ int filesize;
+ retval = fileio_size(&s.fileio, &filesize);
+ if (retval != ERROR_OK)
+ return retval;
+
command_print(CMD_CTX, "dumped %ld bytes in %fs (%0.3f KiB/s)",
command_print(CMD_CTX, "dumped %ld bytes in %fs (%0.3f KiB/s)",
- (long)fileio_size(&s.fileio), duration_elapsed(&s.bench),
- duration_kbps(&s.bench, fileio_size(&s.fileio)));
+ (long)filesize, duration_elapsed(&s.bench),
+ duration_kbps(&s.bench, filesize));
- buffer = malloc(fileio_size(&fileio));
+ int filesize;
+ retval = fileio_size(&fileio, &filesize);
+ if (retval != ERROR_OK)
+ {
+ fileio_close(&fileio);
+ return retval;
+ }
+
+ buffer = malloc(filesize);
+ if (buffer == NULL)
+ {
+ fileio_close(&fileio);
+ LOG_ERROR("Out of memory");
+ return ERROR_FAIL;
+ }
- if (fileio_read(&fileio, fileio_size(&fileio), buffer, &buf_cnt) != ERROR_OK)
+ if (fileio_read(&fileio, filesize, buffer, &buf_cnt) != ERROR_OK)
{
free(buffer);
fileio_close(&fileio);
{
free(buffer);
fileio_close(&fileio);
{
command_print(CMD_CTX, "wrote %ld bytes from file %s to flash bank %u"
" at offset 0x%8.8" PRIx32 " in %fs (%0.3f KiB/s)",
{
command_print(CMD_CTX, "wrote %ld bytes from file %s to flash bank %u"
" at offset 0x%8.8" PRIx32 " in %fs (%0.3f KiB/s)",
- (long)fileio_size(&fileio), CMD_ARGV[1], p->bank_number, offset,
- duration_elapsed(&bench), duration_kbps(&bench, fileio_size(&fileio)));
+ (long)filesize, CMD_ARGV[1], p->bank_number, offset,
+ duration_elapsed(&bench), duration_kbps(&bench, filesize));
-int fileio_size(struct fileio *fileio_p)
+/**
+ * FIX!!!!
+ *
+ * For now this can not fail, but that's because a seek was executed
+ * on startup.
+ *
+ * Avoiding the seek on startup opens up for using streams.
+ *
+ */
+int fileio_size(struct fileio *fileio_p, int *size)
{
struct fileio_internal *fileio = fileio_p->fp;
{
struct fileio_internal *fileio = fileio_p->fp;
+ *size = fileio->size;
+ return ERROR_OK;
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 fileio_size(struct fileio *fileio);
+int fileio_size(struct fileio *fileio, int *size);
#define ERROR_FILEIO_LOCATION_UNKNOWN (-1200)
#define ERROR_FILEIO_NOT_FOUND (-1201)
#define ERROR_FILEIO_LOCATION_UNKNOWN (-1200)
#define ERROR_FILEIO_NOT_FOUND (-1201)
- if (fileio_size(&file) % 4)
+ int filesize;
+ int retval = fileio_size(&file, &filesize);
+ if (retval != ERROR_OK)
+ {
+ fileio_close(&file);
+ return retval;
+ }
+
+ if (filesize % 4)
{
command_print(CMD_CTX, "size isn't a multiple of 4, no valid trace data");
fileio_close(&file);
{
command_print(CMD_CTX, "size isn't a multiple of 4, no valid trace data");
fileio_close(&file);
/* we can't determine the number of sections that we'll have to create ahead of time,
* so we locally hold them until parsing is finished */
/* we can't determine the number of sections that we'll have to create ahead of time,
* so we locally hold them until parsing is finished */
- ihex->buffer = malloc(fileio_size(fileio) >> 1);
+ int filesize;
+ int retval;
+ retval = fileio_size(fileio, &filesize);
+ if (retval != ERROR_OK)
+ return retval;
+
+ ihex->buffer = malloc(filesize >> 1);
cooked_bytes = 0x0;
image->num_sections = 0;
section[image->num_sections].private = &ihex->buffer[cooked_bytes];
cooked_bytes = 0x0;
image->num_sections = 0;
section[image->num_sections].private = &ihex->buffer[cooked_bytes];
/* we can't determine the number of sections that we'll have to create ahead of time,
* so we locally hold them until parsing is finished */
/* we can't determine the number of sections that we'll have to create ahead of time,
* so we locally hold them until parsing is finished */
- mot->buffer = malloc(fileio_size(fileio) >> 1);
+ int retval;
+ int filesize;
+ retval = fileio_size(fileio, &filesize);
+ if (retval != ERROR_OK)
+ return retval;
+
+ mot->buffer = malloc(filesize >> 1);
cooked_bytes = 0x0;
image->num_sections = 0;
section[image->num_sections].private = &mot->buffer[cooked_bytes];
cooked_bytes = 0x0;
image->num_sections = 0;
section[image->num_sections].private = &mot->buffer[cooked_bytes];
+ int filesize;
+ retval = fileio_size(&image_binary->fileio, &filesize);
+ if (retval != ERROR_OK)
+ {
+ fileio_close(&image_binary->fileio);
+ return retval;
+ }
image->num_sections = 1;
image->sections = malloc(sizeof(struct imagesection));
image->sections[0].base_address = 0x0;
image->num_sections = 1;
image->sections = malloc(sizeof(struct imagesection));
image->sections[0].base_address = 0x0;
- image->sections[0].size = fileio_size(&image_binary->fileio);
+ image->sections[0].size = filesize;
image->sections[0].flags = 0;
}
else if (image->type == IMAGE_IHEX)
image->sections[0].flags = 0;
}
else if (image->type == IMAGE_IHEX)
if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK))
{
if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK))
{
+ int filesize;
+ retval = fileio_size(&fileio, &filesize);
+ if (retval != ERROR_OK)
+ return retval;
- "dumped %ld bytes in %fs (%0.3f KiB/s)", (long)fileio_size(&fileio),
- duration_elapsed(&bench), duration_kbps(&bench, fileio_size(&fileio)));
+ "dumped %ld bytes in %fs (%0.3f KiB/s)", (long)filesize,
+ duration_elapsed(&bench), duration_kbps(&bench, filesize));
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)