Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
- cnt = fileio.size / MG_FILEIO_CHUNK;
- res = fileio.size % MG_FILEIO_CHUNK;
+ cnt = fileio_size(&fileio) / MG_FILEIO_CHUNK;
+ res = fileio_size(&fileio) % 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, CMD_ARGV[1],
- duration_elapsed(&bench), duration_kbps(&bench, fileio.size));
+ "in %fs (%0.3f kB/s)", (long)fileio_size(&fileio), CMD_ARGV[1],
+ duration_elapsed(&bench), duration_kbps(&bench, fileio_size(&fileio)));
return retval;
if (!need_size)
return retval;
if (!need_size)
- state->size = state->fileio.size;
+ state->size = fileio_size(&state->fileio);
if (nand_fileio_finish(&s) == ERROR_OK)
{
command_print(CMD_CTX, "dumped %ld bytes in %fs (%0.3f KiB/s)",
if (nand_fileio_finish(&s) == ERROR_OK)
{
command_print(CMD_CTX, "dumped %ld bytes in %fs (%0.3f KiB/s)",
- (long)s.fileio.size, duration_elapsed(&s.bench),
- duration_kbps(&s.bench, s.fileio.size));
+ (long)fileio_size(&s.fileio), duration_elapsed(&s.bench),
+ duration_kbps(&s.bench, fileio_size(&s.fileio)));
- buffer = malloc(fileio.size);
+ buffer = malloc(fileio_size(&fileio));
- if (fileio_read(&fileio, fileio.size, buffer, &buf_cnt) != ERROR_OK)
+ if (fileio_read(&fileio, fileio_size(&fileio), 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, CMD_ARGV[1], p->bank_number, offset,
- duration_elapsed(&bench), duration_kbps(&bench, fileio.size));
+ (long)fileio_size(&fileio), CMD_ARGV[1], p->bank_number, offset,
+ duration_elapsed(&bench), duration_kbps(&bench, fileio_size(&fileio)));
#include "configuration.h"
#include "fileio.h"
#include "configuration.h"
#include "fileio.h"
-static inline int fileio_open_local(struct fileio *fileio)
+struct fileio_internal {
+ const char *url;
+ ssize_t size;
+ enum fileio_type type;
+ enum fileio_access access;
+ FILE *file;
+};
+
+static inline int fileio_close_local(struct fileio_internal *fileio);
+static inline int fileio_open_local(struct fileio_internal *fileio)
if ((fileio->size < 0)||(result < 0)||(result2 < 0))
{
if ((fileio->size < 0)||(result < 0)||(result2 < 0))
{
+ fileio_close_local(fileio);
return ERROR_FILEIO_OPERATION_FAILED;
}
}
return ERROR_FILEIO_OPERATION_FAILED;
}
}
-int fileio_open(struct fileio *fileio, const char *url, enum fileio_access access_type, enum fileio_type type)
+int fileio_open(struct fileio *fileio_p, const char *url, enum fileio_access access_type, enum fileio_type type)
+ struct fileio_internal *fileio = malloc(sizeof(struct fileio_internal));
+ fileio_p->fp = fileio;
+
fileio->type = type;
fileio->access = access_type;
fileio->url = strdup(url);
fileio->type = type;
fileio->access = access_type;
fileio->url = strdup(url);
-static inline int fileio_close_local(struct fileio *fileio)
+static inline int fileio_close_local(struct fileio_internal *fileio)
{
int retval;
if ((retval = fclose(fileio->file)) != 0)
{
int retval;
if ((retval = fclose(fileio->file)) != 0)
-int fileio_close(struct fileio *fileio)
+int fileio_close(struct fileio *fileio_p)
+ struct fileio_internal *fileio = fileio_p->fp;
retval = fileio_close_local(fileio);
free((void*)fileio->url);
fileio->url = NULL;
retval = fileio_close_local(fileio);
free((void*)fileio->url);
fileio->url = NULL;
+ free(fileio);
+ fileio_p->fp = NULL;
+
-int fileio_seek(struct fileio *fileio, size_t position)
+int fileio_seek(struct fileio *fileio_p, size_t position)
+ struct fileio_internal *fileio = fileio_p->fp;
if ((retval = fseek(fileio->file, position, SEEK_SET)) != 0)
{
LOG_ERROR("couldn't seek file %s: %s", fileio->url, strerror(errno));
if ((retval = fseek(fileio->file, position, SEEK_SET)) != 0)
{
LOG_ERROR("couldn't seek file %s: %s", fileio->url, strerror(errno));
-static int fileio_local_read(struct fileio *fileio,
+static int fileio_local_read(struct fileio_internal *fileio,
size_t size, void *buffer, size_t *size_read)
{
ssize_t retval = fread(buffer, 1, size, fileio->file);
size_t size, void *buffer, size_t *size_read)
{
ssize_t retval = fread(buffer, 1, size, fileio->file);
return (retval < 0) ? retval : ERROR_OK;
}
return (retval < 0) ? retval : ERROR_OK;
}
-int fileio_read(struct fileio *fileio, size_t size, void *buffer,
+int fileio_read(struct fileio *fileio_p, size_t size, void *buffer,
+ struct fileio_internal *fileio = fileio_p->fp;
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)
+int fileio_read_u32(struct fileio *fileio_p, uint32_t *data)
{
uint8_t buf[4];
size_t size_read;
{
uint8_t buf[4];
size_t size_read;
+ struct fileio_internal *fileio = fileio_p->fp;
int retval = fileio_local_read(fileio, sizeof(uint32_t), buf, &size_read);
if (ERROR_OK == retval && sizeof(uint32_t) != size_read)
retval = -EIO;
int retval = fileio_local_read(fileio, sizeof(uint32_t), buf, &size_read);
if (ERROR_OK == retval && sizeof(uint32_t) != size_read)
retval = -EIO;
-static int fileio_local_fgets(struct fileio *fileio,
+static int fileio_local_fgets(struct fileio_internal *fileio,
size_t size, void *buffer)
{
if (fgets(buffer, size, fileio->file) == NULL)
size_t size, void *buffer)
{
if (fgets(buffer, size, fileio->file) == NULL)
-int fileio_fgets(struct fileio *fileio, size_t size, void *buffer)
+int fileio_fgets(struct fileio *fileio_p, size_t size, void *buffer)
+ struct fileio_internal *fileio = fileio_p->fp;
return fileio_local_fgets(fileio, size, buffer);
}
return fileio_local_fgets(fileio, size, buffer);
}
-static int fileio_local_write(struct fileio *fileio,
+static int fileio_local_write(struct fileio_internal *fileio,
size_t size, const void *buffer, size_t *size_written)
{
ssize_t retval = fwrite(buffer, 1, size, fileio->file);
size_t size, const void *buffer, size_t *size_written)
{
ssize_t retval = fwrite(buffer, 1, size, fileio->file);
return (retval < 0) ? retval : ERROR_OK;
}
return (retval < 0) ? retval : ERROR_OK;
}
-int fileio_write(struct fileio *fileio,
+int fileio_write(struct fileio *fileio_p,
size_t size, const void *buffer, size_t *size_written)
{
size_t size, const void *buffer, size_t *size_written)
{
+ struct fileio_internal *fileio = fileio_p->fp;
int retval = fileio_local_write(fileio, size, buffer, size_written);
if (retval == ERROR_OK)
fileio->size += *size_written;
return retval;
}
int retval = fileio_local_write(fileio, size, buffer, size_written);
if (retval == ERROR_OK)
fileio->size += *size_written;
return retval;
}
-int fileio_write_u32(struct fileio *fileio, uint32_t data)
+int fileio_write_u32(struct fileio *fileio_p, uint32_t data)
{
uint8_t buf[4];
h_u32_to_be(buf, data);
{
uint8_t buf[4];
h_u32_to_be(buf, data);
- int retval = fileio_write(fileio, 4, buf, &size_written);
+ int retval = fileio_write(fileio_p, 4, buf, &size_written);
if (ERROR_OK == retval && size_written != sizeof(uint32_t))
retval = -EIO;
return retval;
}
if (ERROR_OK == retval && size_written != sizeof(uint32_t))
retval = -EIO;
return retval;
}
+
+int fileio_size(struct fileio *fileio_p)
+{
+ struct fileio_internal *fileio = fileio_p->fp;
+ return fileio->size;
+}
FILEIO_APPENDREAD, /* open for writing, position at end, allow reading */
};
FILEIO_APPENDREAD, /* open for writing, position at end, allow reading */
};
-struct fileio {
- const char *url;
- ssize_t size;
- enum fileio_type type;
- enum fileio_access access;
- FILE *file;
+struct fileio
+{
+ /* The structure is opaque */
+ struct fileio_internal *fp;
};
int fileio_open(struct fileio *fileio,
};
int fileio_open(struct fileio *fileio,
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);
#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)
{
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 >> 1);
+ ihex->buffer = malloc(fileio_size(fileio) >> 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 >> 1);
+ mot->buffer = malloc(fileio_size(fileio) >> 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];
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 = image_binary->fileio.size;
+ image->sections[0].size = fileio_size(&image_binary->fileio);
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))
{
command_print(CMD_CTX,
if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK))
{
command_print(CMD_CTX,
- "dumped %ld bytes in %fs (%0.3f KiB/s)", (long)fileio.size,
- duration_elapsed(&bench), duration_kbps(&bench, fileio.size));
+ "dumped %ld bytes in %fs (%0.3f KiB/s)", (long)fileio_size(&fileio),
+ duration_elapsed(&bench), duration_kbps(&bench, fileio_size(&fileio)));
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)