Commit 70cb0bff authored by Yann Gautier's avatar Yann Gautier Committed by Lionel Debieve
Browse files

io: change seek offset to signed long long



IO seek offset can be set to values above UINT32_MAX, this change
changes the seek offset argument from 'ssize_t' to 'signed long long'.
Fixing platform seek functions to match the new interface update.

Change-Id: I25de83b3b7abe5f52a7b0fee36f71e60cac9cfcb
Signed-off-by: default avatarYann Gautier <yann.gautier@st.com>
Signed-off-by: default avatarEtienne Carriere <etienne.carriere@st.com>
Signed-off-by: default avatarLionel Debieve <lionel.debieve@st.com>
parent 8c80c865
...@@ -27,8 +27,8 @@ typedef struct { ...@@ -27,8 +27,8 @@ typedef struct {
*/ */
int in_use; int in_use;
uintptr_t base; uintptr_t base;
size_t file_pos; unsigned long long file_pos;
size_t size; unsigned long long size;
} file_state_t; } file_state_t;
static file_state_t current_file = {0}; static file_state_t current_file = {0};
...@@ -44,7 +44,7 @@ static int memmap_dev_open(const uintptr_t dev_spec, io_dev_info_t **dev_info); ...@@ -44,7 +44,7 @@ static int memmap_dev_open(const uintptr_t dev_spec, io_dev_info_t **dev_info);
static int memmap_block_open(io_dev_info_t *dev_info, const uintptr_t spec, static int memmap_block_open(io_dev_info_t *dev_info, const uintptr_t spec,
io_entity_t *entity); io_entity_t *entity);
static int memmap_block_seek(io_entity_t *entity, int mode, static int memmap_block_seek(io_entity_t *entity, int mode,
ssize_t offset); signed long long offset);
static int memmap_block_len(io_entity_t *entity, size_t *length); static int memmap_block_len(io_entity_t *entity, size_t *length);
static int memmap_block_read(io_entity_t *entity, uintptr_t buffer, static int memmap_block_read(io_entity_t *entity, uintptr_t buffer,
size_t length, size_t *length_read); size_t length, size_t *length_read);
...@@ -131,7 +131,8 @@ static int memmap_block_open(io_dev_info_t *dev_info, const uintptr_t spec, ...@@ -131,7 +131,8 @@ static int memmap_block_open(io_dev_info_t *dev_info, const uintptr_t spec,
/* Seek to a particular file offset on the memmap device */ /* Seek to a particular file offset on the memmap device */
static int memmap_block_seek(io_entity_t *entity, int mode, ssize_t offset) static int memmap_block_seek(io_entity_t *entity, int mode,
signed long long offset)
{ {
int result = -ENOENT; int result = -ENOENT;
file_state_t *fp; file_state_t *fp;
...@@ -143,7 +144,8 @@ static int memmap_block_seek(io_entity_t *entity, int mode, ssize_t offset) ...@@ -143,7 +144,8 @@ static int memmap_block_seek(io_entity_t *entity, int mode, ssize_t offset)
fp = (file_state_t *) entity->info; fp = (file_state_t *) entity->info;
/* Assert that new file position is valid */ /* Assert that new file position is valid */
assert((offset >= 0) && (offset < fp->size)); assert((offset >= 0) &&
((unsigned long long)offset < fp->size));
/* Reset file position */ /* Reset file position */
fp->file_pos = offset; fp->file_pos = offset;
...@@ -171,7 +173,7 @@ static int memmap_block_read(io_entity_t *entity, uintptr_t buffer, ...@@ -171,7 +173,7 @@ static int memmap_block_read(io_entity_t *entity, uintptr_t buffer,
size_t length, size_t *length_read) size_t length, size_t *length_read)
{ {
file_state_t *fp; file_state_t *fp;
size_t pos_after; unsigned long long pos_after;
assert(entity != NULL); assert(entity != NULL);
assert(length_read != NULL); assert(length_read != NULL);
...@@ -198,7 +200,7 @@ static int memmap_block_write(io_entity_t *entity, const uintptr_t buffer, ...@@ -198,7 +200,7 @@ static int memmap_block_write(io_entity_t *entity, const uintptr_t buffer,
size_t length, size_t *length_written) size_t length, size_t *length_written)
{ {
file_state_t *fp; file_state_t *fp;
size_t pos_after; unsigned long long pos_after;
assert(entity != NULL); assert(entity != NULL);
assert(length_written != NULL); assert(length_written != NULL);
......
...@@ -19,17 +19,17 @@ ...@@ -19,17 +19,17 @@
typedef struct { typedef struct {
io_block_dev_spec_t *dev_spec; io_block_dev_spec_t *dev_spec;
uintptr_t base; uintptr_t base;
size_t file_pos; unsigned long long file_pos;
size_t size; unsigned long long size;
} block_dev_state_t; } block_dev_state_t;
#define is_power_of_2(x) ((x != 0) && ((x & (x - 1)) == 0)) #define is_power_of_2(x) (((x) != 0U) && (((x) & ((x) - 1U)) == 0U))
io_type_t device_type_block(void); io_type_t device_type_block(void);
static int block_open(io_dev_info_t *dev_info, const uintptr_t spec, static int block_open(io_dev_info_t *dev_info, const uintptr_t spec,
io_entity_t *entity); io_entity_t *entity);
static int block_seek(io_entity_t *entity, int mode, ssize_t offset); static int block_seek(io_entity_t *entity, int mode, signed long long offset);
static int block_read(io_entity_t *entity, uintptr_t buffer, size_t length, static int block_read(io_entity_t *entity, uintptr_t buffer, size_t length,
size_t *length_read); size_t *length_read);
static int block_write(io_entity_t *entity, const uintptr_t buffer, static int block_write(io_entity_t *entity, const uintptr_t buffer,
...@@ -148,21 +148,21 @@ static int block_open(io_dev_info_t *dev_info, const uintptr_t spec, ...@@ -148,21 +148,21 @@ static int block_open(io_dev_info_t *dev_info, const uintptr_t spec,
} }
/* parameter offset is relative address at here */ /* parameter offset is relative address at here */
static int block_seek(io_entity_t *entity, int mode, ssize_t offset) static int block_seek(io_entity_t *entity, int mode, signed long long offset)
{ {
block_dev_state_t *cur; block_dev_state_t *cur;
assert(entity->info != (uintptr_t)NULL); assert(entity->info != (uintptr_t)NULL);
cur = (block_dev_state_t *)entity->info; cur = (block_dev_state_t *)entity->info;
assert((offset >= 0) && (offset < cur->size)); assert((offset >= 0) && ((unsigned long long)offset < cur->size));
switch (mode) { switch (mode) {
case IO_SEEK_SET: case IO_SEEK_SET:
cur->file_pos = offset; cur->file_pos = (unsigned long long)offset;
break; break;
case IO_SEEK_CUR: case IO_SEEK_CUR:
cur->file_pos += offset; cur->file_pos += (unsigned long long)offset;
break; break;
default: default:
return -EINVAL; return -EINVAL;
...@@ -270,7 +270,7 @@ static int block_read(io_entity_t *entity, uintptr_t buffer, size_t length, ...@@ -270,7 +270,7 @@ static int block_read(io_entity_t *entity, uintptr_t buffer, size_t length,
buf = &(cur->dev_spec->buffer); buf = &(cur->dev_spec->buffer);
block_size = cur->dev_spec->block_size; block_size = cur->dev_spec->block_size;
assert((length <= cur->size) && assert((length <= cur->size) &&
(length > 0) && (length > 0U) &&
(ops->read != 0)); (ops->read != 0));
/* /*
...@@ -279,7 +279,7 @@ static int block_read(io_entity_t *entity, uintptr_t buffer, size_t length, ...@@ -279,7 +279,7 @@ static int block_read(io_entity_t *entity, uintptr_t buffer, size_t length,
* on the low level driver. * on the low level driver.
*/ */
count = 0; count = 0;
for (left = length; left > 0; left -= nbytes) { for (left = length; left > 0U; left -= nbytes) {
/* /*
* We must only request operations aligned to the block * We must only request operations aligned to the block
* size. Therefore if file_pos is not block-aligned, * size. Therefore if file_pos is not block-aligned,
...@@ -288,7 +288,7 @@ static int block_read(io_entity_t *entity, uintptr_t buffer, size_t length, ...@@ -288,7 +288,7 @@ static int block_read(io_entity_t *entity, uintptr_t buffer, size_t length,
* similarly, the number of bytes requested must be a * similarly, the number of bytes requested must be a
* block size multiple * block size multiple
*/ */
skip = cur->file_pos & (block_size - 1); skip = cur->file_pos & (block_size - 1U);
/* /*
* Calculate the block number containing file_pos * Calculate the block number containing file_pos
...@@ -296,7 +296,7 @@ static int block_read(io_entity_t *entity, uintptr_t buffer, size_t length, ...@@ -296,7 +296,7 @@ static int block_read(io_entity_t *entity, uintptr_t buffer, size_t length,
*/ */
lba = (cur->file_pos + cur->base) / block_size; lba = (cur->file_pos + cur->base) / block_size;
if (skip + left > buf->length) { if ((skip + left) > buf->length) {
/* /*
* The underlying read buffer is too small to * The underlying read buffer is too small to
* read all the required data - limit to just * read all the required data - limit to just
...@@ -311,7 +311,8 @@ static int block_read(io_entity_t *entity, uintptr_t buffer, size_t length, ...@@ -311,7 +311,8 @@ static int block_read(io_entity_t *entity, uintptr_t buffer, size_t length,
* block size. * block size.
*/ */
request = skip + left; request = skip + left;
request = (request + (block_size - 1)) & ~(block_size - 1); request = (request + (block_size - 1U)) &
~(block_size - 1U);
} }
request = ops->read(lba, buf->offset, request); request = ops->read(lba, buf->offset, request);
...@@ -330,7 +331,7 @@ static int block_read(io_entity_t *entity, uintptr_t buffer, size_t length, ...@@ -330,7 +331,7 @@ static int block_read(io_entity_t *entity, uintptr_t buffer, size_t length,
* the read data when copying to the user buffer. * the read data when copying to the user buffer.
*/ */
nbytes = request - skip; nbytes = request - skip;
padding = (nbytes > left) ? nbytes - left : 0; padding = (nbytes > left) ? nbytes - left : 0U;
nbytes -= padding; nbytes -= padding;
memcpy((void *)(buffer + count), memcpy((void *)(buffer + count),
...@@ -381,7 +382,7 @@ static int block_write(io_entity_t *entity, const uintptr_t buffer, ...@@ -381,7 +382,7 @@ static int block_write(io_entity_t *entity, const uintptr_t buffer,
buf = &(cur->dev_spec->buffer); buf = &(cur->dev_spec->buffer);
block_size = cur->dev_spec->block_size; block_size = cur->dev_spec->block_size;
assert((length <= cur->size) && assert((length <= cur->size) &&
(length > 0) && (length > 0U) &&
(ops->read != 0) && (ops->read != 0) &&
(ops->write != 0)); (ops->write != 0));
...@@ -391,7 +392,7 @@ static int block_write(io_entity_t *entity, const uintptr_t buffer, ...@@ -391,7 +392,7 @@ static int block_write(io_entity_t *entity, const uintptr_t buffer,
* on the low level driver. * on the low level driver.
*/ */
count = 0; count = 0;
for (left = length; left > 0; left -= nbytes) { for (left = length; left > 0U; left -= nbytes) {
/* /*
* We must only request operations aligned to the block * We must only request operations aligned to the block
* size. Therefore if file_pos is not block-aligned, * size. Therefore if file_pos is not block-aligned,
...@@ -400,7 +401,7 @@ static int block_write(io_entity_t *entity, const uintptr_t buffer, ...@@ -400,7 +401,7 @@ static int block_write(io_entity_t *entity, const uintptr_t buffer,
* similarly, the number of bytes requested must be a * similarly, the number of bytes requested must be a
* block size multiple * block size multiple
*/ */
skip = cur->file_pos & (block_size - 1); skip = cur->file_pos & (block_size - 1U);
/* /*
* Calculate the block number containing file_pos * Calculate the block number containing file_pos
...@@ -408,7 +409,7 @@ static int block_write(io_entity_t *entity, const uintptr_t buffer, ...@@ -408,7 +409,7 @@ static int block_write(io_entity_t *entity, const uintptr_t buffer,
*/ */
lba = (cur->file_pos + cur->base) / block_size; lba = (cur->file_pos + cur->base) / block_size;
if (skip + left > buf->length) { if ((skip + left) > buf->length) {
/* /*
* The underlying read buffer is too small to * The underlying read buffer is too small to
* read all the required data - limit to just * read all the required data - limit to just
...@@ -423,7 +424,8 @@ static int block_write(io_entity_t *entity, const uintptr_t buffer, ...@@ -423,7 +424,8 @@ static int block_write(io_entity_t *entity, const uintptr_t buffer,
* block size. * block size.
*/ */
request = skip + left; request = skip + left;
request = (request + (block_size - 1)) & ~(block_size - 1); request = (request + (block_size - 1U)) &
~(block_size - 1U);
} }
/* /*
...@@ -432,7 +434,7 @@ static int block_write(io_entity_t *entity, const uintptr_t buffer, ...@@ -432,7 +434,7 @@ static int block_write(io_entity_t *entity, const uintptr_t buffer,
* of the current request. * of the current request.
*/ */
nbytes = request - skip; nbytes = request - skip;
padding = (nbytes > left) ? nbytes - left : 0; padding = (nbytes > left) ? nbytes - left : 0U;
nbytes -= padding; nbytes -= padding;
/* /*
...@@ -440,14 +442,14 @@ static int block_write(io_entity_t *entity, const uintptr_t buffer, ...@@ -440,14 +442,14 @@ static int block_write(io_entity_t *entity, const uintptr_t buffer,
* some content and it means that we have to read before * some content and it means that we have to read before
* writing * writing
*/ */
if (skip > 0 || padding > 0) { if ((skip > 0U) || (padding > 0U)) {
request = ops->read(lba, buf->offset, request); request = ops->read(lba, buf->offset, request);
/* /*
* The read may return size less than * The read may return size less than
* requested. Round down to the nearest block * requested. Round down to the nearest block
* boundary * boundary
*/ */
request &= ~(block_size-1); request &= ~(block_size - 1U);
if (request <= skip) { if (request <= skip) {
/* /*
* We couldn't read enough bytes to jump over * We couldn't read enough bytes to jump over
...@@ -458,7 +460,7 @@ static int block_write(io_entity_t *entity, const uintptr_t buffer, ...@@ -458,7 +460,7 @@ static int block_write(io_entity_t *entity, const uintptr_t buffer,
return -EIO; return -EIO;
} }
nbytes = request - skip; nbytes = request - skip;
padding = (nbytes > left) ? nbytes - left : 0; padding = (nbytes > left) ? nbytes - left : 0U;
nbytes -= padding; nbytes -= padding;
} }
...@@ -477,7 +479,7 @@ static int block_write(io_entity_t *entity, const uintptr_t buffer, ...@@ -477,7 +479,7 @@ static int block_write(io_entity_t *entity, const uintptr_t buffer,
* buffer * buffer
*/ */
nbytes = request - skip; nbytes = request - skip;
padding = (nbytes > left) ? nbytes - left : 0; padding = (nbytes > left) ? nbytes - left : 0U;
nbytes -= padding; nbytes -= padding;
cur->file_pos += nbytes; cur->file_pos += nbytes;
...@@ -505,7 +507,7 @@ static int block_dev_open(const uintptr_t dev_spec, io_dev_info_t **dev_info) ...@@ -505,7 +507,7 @@ static int block_dev_open(const uintptr_t dev_spec, io_dev_info_t **dev_info)
assert(dev_info != NULL); assert(dev_info != NULL);
result = allocate_dev_info(&info); result = allocate_dev_info(&info);
if (result) if (result != 0)
return -ENOENT; return -ENOENT;
cur = (block_dev_state_t *)info->info; cur = (block_dev_state_t *)info->info;
...@@ -513,10 +515,10 @@ static int block_dev_open(const uintptr_t dev_spec, io_dev_info_t **dev_info) ...@@ -513,10 +515,10 @@ static int block_dev_open(const uintptr_t dev_spec, io_dev_info_t **dev_info)
cur->dev_spec = (io_block_dev_spec_t *)dev_spec; cur->dev_spec = (io_block_dev_spec_t *)dev_spec;
buffer = &(cur->dev_spec->buffer); buffer = &(cur->dev_spec->buffer);
block_size = cur->dev_spec->block_size; block_size = cur->dev_spec->block_size;
assert((block_size > 0) && assert((block_size > 0U) &&
(is_power_of_2(block_size) != 0) && (is_power_of_2(block_size) != 0U) &&
((buffer->offset % block_size) == 0) && ((buffer->offset % block_size) == 0U) &&
((buffer->length % block_size) == 0)); ((buffer->length % block_size) == 0U));
*dev_info = info; /* cast away const */ *dev_info = info; /* cast away const */
(void)block_size; (void)block_size;
......
...@@ -304,7 +304,8 @@ static int fip_file_open(io_dev_info_t *dev_info, const uintptr_t spec, ...@@ -304,7 +304,8 @@ static int fip_file_open(io_dev_info_t *dev_info, const uintptr_t spec,
} }
/* Seek past the FIP header into the Table of Contents */ /* Seek past the FIP header into the Table of Contents */
result = io_seek(backend_handle, IO_SEEK_SET, sizeof(fip_toc_header_t)); result = io_seek(backend_handle, IO_SEEK_SET,
(signed long long)sizeof(fip_toc_header_t));
if (result != 0) { if (result != 0) {
WARN("fip_file_open: failed to seek\n"); WARN("fip_file_open: failed to seek\n");
result = -ENOENT; result = -ENOENT;
...@@ -389,7 +390,8 @@ static int fip_file_read(io_entity_t *entity, uintptr_t buffer, size_t length, ...@@ -389,7 +390,8 @@ static int fip_file_read(io_entity_t *entity, uintptr_t buffer, size_t length,
/* Seek to the position in the FIP where the payload lives */ /* Seek to the position in the FIP where the payload lives */
file_offset = fp->entry.offset_address + fp->file_pos; file_offset = fp->entry.offset_address + fp->file_pos;
result = io_seek(backend_handle, IO_SEEK_SET, file_offset); result = io_seek(backend_handle, IO_SEEK_SET,
(signed long long)file_offset);
if (result != 0) { if (result != 0) {
WARN("fip_file_read: failed to seek\n"); WARN("fip_file_read: failed to seek\n");
result = -ENOENT; result = -ENOENT;
......
...@@ -25,8 +25,8 @@ typedef struct { ...@@ -25,8 +25,8 @@ typedef struct {
*/ */
int in_use; int in_use;
uintptr_t base; uintptr_t base;
size_t file_pos; unsigned long long file_pos;
size_t size; unsigned long long size;
} file_state_t; } file_state_t;
static file_state_t current_file = {0}; static file_state_t current_file = {0};
...@@ -42,7 +42,7 @@ static int memmap_dev_open(const uintptr_t dev_spec, io_dev_info_t **dev_info); ...@@ -42,7 +42,7 @@ static int memmap_dev_open(const uintptr_t dev_spec, io_dev_info_t **dev_info);
static int memmap_block_open(io_dev_info_t *dev_info, const uintptr_t spec, static int memmap_block_open(io_dev_info_t *dev_info, const uintptr_t spec,
io_entity_t *entity); io_entity_t *entity);
static int memmap_block_seek(io_entity_t *entity, int mode, static int memmap_block_seek(io_entity_t *entity, int mode,
ssize_t offset); signed long long offset);
static int memmap_block_len(io_entity_t *entity, size_t *length); static int memmap_block_len(io_entity_t *entity, size_t *length);
static int memmap_block_read(io_entity_t *entity, uintptr_t buffer, static int memmap_block_read(io_entity_t *entity, uintptr_t buffer,
size_t length, size_t *length_read); size_t length, size_t *length_read);
...@@ -129,7 +129,8 @@ static int memmap_block_open(io_dev_info_t *dev_info, const uintptr_t spec, ...@@ -129,7 +129,8 @@ static int memmap_block_open(io_dev_info_t *dev_info, const uintptr_t spec,
/* Seek to a particular file offset on the memmap device */ /* Seek to a particular file offset on the memmap device */
static int memmap_block_seek(io_entity_t *entity, int mode, ssize_t offset) static int memmap_block_seek(io_entity_t *entity, int mode,
signed long long offset)
{ {
int result = -ENOENT; int result = -ENOENT;
file_state_t *fp; file_state_t *fp;
...@@ -141,10 +142,11 @@ static int memmap_block_seek(io_entity_t *entity, int mode, ssize_t offset) ...@@ -141,10 +142,11 @@ static int memmap_block_seek(io_entity_t *entity, int mode, ssize_t offset)
fp = (file_state_t *) entity->info; fp = (file_state_t *) entity->info;
/* Assert that new file position is valid */ /* Assert that new file position is valid */
assert((offset >= 0) && (offset < fp->size)); assert((offset >= 0) &&
((unsigned long long)offset < fp->size));
/* Reset file position */ /* Reset file position */
fp->file_pos = offset; fp->file_pos = (unsigned long long)offset;
result = 0; result = 0;
} }
...@@ -158,7 +160,7 @@ static int memmap_block_len(io_entity_t *entity, size_t *length) ...@@ -158,7 +160,7 @@ static int memmap_block_len(io_entity_t *entity, size_t *length)
assert(entity != NULL); assert(entity != NULL);
assert(length != NULL); assert(length != NULL);
*length = ((file_state_t *)entity->info)->size; *length = (size_t)((file_state_t *)entity->info)->size;
return 0; return 0;
} }
...@@ -169,7 +171,7 @@ static int memmap_block_read(io_entity_t *entity, uintptr_t buffer, ...@@ -169,7 +171,7 @@ static int memmap_block_read(io_entity_t *entity, uintptr_t buffer,
size_t length, size_t *length_read) size_t length, size_t *length_read)
{ {
file_state_t *fp; file_state_t *fp;
size_t pos_after; unsigned long long pos_after;
assert(entity != NULL); assert(entity != NULL);
assert(length_read != NULL); assert(length_read != NULL);
...@@ -180,7 +182,8 @@ static int memmap_block_read(io_entity_t *entity, uintptr_t buffer, ...@@ -180,7 +182,8 @@ static int memmap_block_read(io_entity_t *entity, uintptr_t buffer,
pos_after = fp->file_pos + length; pos_after = fp->file_pos + length;
assert((pos_after >= fp->file_pos) && (pos_after <= fp->size)); assert((pos_after >= fp->file_pos) && (pos_after <= fp->size));
memcpy((void *)buffer, (void *)(fp->base + fp->file_pos), length); memcpy((void *)buffer,
(void *)((uintptr_t)(fp->base + fp->file_pos)), length);
*length_read = length; *length_read = length;
...@@ -196,7 +199,7 @@ static int memmap_block_write(io_entity_t *entity, const uintptr_t buffer, ...@@ -196,7 +199,7 @@ static int memmap_block_write(io_entity_t *entity, const uintptr_t buffer,
size_t length, size_t *length_written) size_t length, size_t *length_written)
{ {
file_state_t *fp; file_state_t *fp;
size_t pos_after; unsigned long long pos_after;
assert(entity != NULL); assert(entity != NULL);
assert(length_written != NULL); assert(length_written != NULL);
...@@ -207,7 +210,8 @@ static int memmap_block_write(io_entity_t *entity, const uintptr_t buffer, ...@@ -207,7 +210,8 @@ static int memmap_block_write(io_entity_t *entity, const uintptr_t buffer,
pos_after = fp->file_pos + length; pos_after = fp->file_pos + length;
assert((pos_after >= fp->file_pos) && (pos_after <= fp->size)); assert((pos_after >= fp->file_pos) && (pos_after <= fp->size));
memcpy((void *)(fp->base + fp->file_pos), (void *)buffer, length); memcpy((void *)((uintptr_t)(fp->base + fp->file_pos)),
(void *)buffer, length);
*length_written = length; *length_written = length;
......
...@@ -25,7 +25,7 @@ static io_type_t device_type_sh(void) ...@@ -25,7 +25,7 @@ static io_type_t device_type_sh(void)
static int sh_dev_open(const uintptr_t dev_spec, io_dev_info_t **dev_info); static int sh_dev_open(const uintptr_t dev_spec, io_dev_info_t **dev_info);
static int sh_file_open(io_dev_info_t *dev_info, const uintptr_t spec, static int sh_file_open(io_dev_info_t *dev_info, const uintptr_t spec,
io_entity_t *entity); io_entity_t *entity);
static int sh_file_seek(io_entity_t *entity, int mode, ssize_t offset); static int sh_file_seek(io_entity_t *entity, int mode, signed long long offset);
static int sh_file_len(io_entity_t *entity, size_t *length); static int sh_file_len(io_entity_t *entity, size_t *length);
static int sh_file_read(io_entity_t *entity, uintptr_t buffer, size_t length, static int sh_file_read(io_entity_t *entity, uintptr_t buffer, size_t length,
size_t *length_read); size_t *length_read);
...@@ -90,7 +90,7 @@ static int sh_file_open(io_dev_info_t *dev_info __unused, ...@@ -90,7 +90,7 @@ static int sh_file_open(io_dev_info_t *dev_info __unused,
/* Seek to a particular file offset on the semi-hosting device */ /* Seek to a particular file offset on the semi-hosting device */
static int sh_file_seek(io_entity_t *entity, int mode, ssize_t offset) static int sh_file_seek(io_entity_t *entity, int mode, signed long long offset)
{ {
long file_handle, sh_result; long file_handle, sh_result;
...@@ -98,7 +98,7 @@ static int sh_file_seek(io_entity_t *entity, int mode, ssize_t offset) ...@@ -98,7 +98,7 @@ static int sh_file_seek(io_entity_t *entity, int mode, ssize_t offset)
file_handle = (long)entity->info; file_handle = (long)entity->info;
sh_result = semihosting_file_seek(file_handle, offset); sh_result = semihosting_file_seek(file_handle, (ssize_t)offset);
return (sh_result == 0) ? 0 : -ENOENT; return (sh_result == 0) ? 0 : -ENOENT;
} }
......
...@@ -237,7 +237,7 @@ int io_open(uintptr_t dev_handle, const uintptr_t spec, uintptr_t *handle) ...@@ -237,7 +237,7 @@ int io_open(uintptr_t dev_handle, const uintptr_t spec, uintptr_t *handle)
/* Seek to a specific position in an IO entity */ /* Seek to a specific position in an IO entity */
int io_seek(uintptr_t handle, io_seek_mode_t mode, ssize_t offset) int io_seek(uintptr_t handle, io_seek_mode_t mode, signed long long offset)
{ {
int result = -ENODEV; int result = -ENODEV;
assert(is_valid_entity(handle) && is_valid_seek_mode(mode)); assert(is_valid_entity(handle) && is_valid_seek_mode(mode));
......
/* /*
* Copyright (c) 2015-2017, Renesas Electronics Corporation. All rights reserved. * Copyright (c) 2015-2019, Renesas Electronics Corporation. All rights reserved.
* *
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
...@@ -25,7 +25,7 @@ static int32_t emmcdrv_dev_close(io_dev_info_t *dev_info); ...@@ -25,7 +25,7 @@ static int32_t emmcdrv_dev_close(io_dev_info_t *dev_info);
typedef struct { typedef struct {
uint32_t in_use; uint32_t in_use;
uintptr_t base; uintptr_t base;
ssize_t file_pos; signed long long file_pos;
EMMC_PARTITION_ID partition; EMMC_PARTITION_ID partition;
} file_state_t; } file_state_t;
...@@ -39,7 +39,7 @@ static io_type_t device_type_emmcdrv(void) ...@@ -39,7 +39,7 @@ static io_type_t device_type_emmcdrv(void)
} }
static int32_t emmcdrv_block_seek(io_entity_t *entity, int32_t mode, static int32_t emmcdrv_block_seek(io_entity_t *entity, int32_t mode,
ssize_t offset) signed long long offset)
{ {
if (mode != IO_SEEK_SET) if (mode != IO_SEEK_SET)
return IO_FAIL; return IO_FAIL;
...@@ -59,12 +59,12 @@ static int32_t emmcdrv_block_read(io_entity_t *entity, uintptr_t buffer, ...@@ -59,12 +59,12 @@ static int32_t emmcdrv_block_read(io_entity_t *entity, uintptr_t buffer,
sector_add = current_file.file_pos >> EMMC_SECTOR_SIZE_SHIFT; sector_add = current_file.file_pos >> EMMC_SECTOR_SIZE_SHIFT;
sector_num = (length + EMMC_SECTOR_SIZE - 1U) >> EMMC_SECTOR_SIZE_SHIFT; sector_num = (length + EMMC_SECTOR_SIZE - 1U) >> EMMC_SECTOR_SIZE_SHIFT;
NOTICE("BL2: Load dst=0x%lx src=(p:%d)0x%lx(%d) len=0x%lx(%d)\n", NOTICE("BL2: Load dst=0x%lx src=(p:%d)0x%llx(%d) len=0x%lx(%d)\n",
buffer, buffer,
current_file.partition, current_file.file_pos, current_file.partition, current_file.file_pos,
sector_add, length, sector_num); sector_add, length, sector_num);
if (buffer + length - 1 <= UINT32_MAX) if ((buffer + length - 1U) <= (uintptr_t)UINT32_MAX)
emmc_dma = LOADIMAGE_FLAGS_DMA_ENABLE; emmc_dma = LOADIMAGE_FLAGS_DMA_ENABLE;
if (emmc_read_sector((uint32_t *) buffer, sector_add, sector_num, if (emmc_read_sector((uint32_t *) buffer, sector_add, sector_num,
...@@ -72,7 +72,7 @@ static int32_t emmcdrv_block_read(io_entity_t *entity, uintptr_t buffer, ...@@ -72,7 +72,7 @@ static int32_t emmcdrv_block_read(io_entity_t *entity, uintptr_t buffer,
result = IO_FAIL; result = IO_FAIL;
*length_read = length; *length_read = length;
fp->file_pos += length; fp->file_pos += (signed long long)length;
return result; return result;
} }
...@@ -82,7 +82,7 @@ static int32_t emmcdrv_block_open(io_dev_info_t *dev_info, ...@@ -82,7 +82,7 @@ static int32_t emmcdrv_block_open(io_dev_info_t *dev_info,
{ {
const io_drv_spec_t *block_spec = (io_drv_spec_t *) spec; const io_drv_spec_t *block_spec = (io_drv_spec_t *) spec;
if (current_file.in_use) { if (current_file.in_use != 0U) {
WARN("mmc_block: Only one open spec at a time\n"); WARN("mmc_block: Only one open spec at a time\n");
return IO_RESOURCES_EXHAUSTED; return IO_RESOURCES_EXHAUSTED;
} }
...@@ -103,9 +103,9 @@ static int32_t emmcdrv_block_open(io_dev_info_t *dev_info, ...@@ -103,9 +103,9 @@ static int32_t emmcdrv_block_open(io_dev_info_t *dev_info,
return IO_FAIL; return IO_FAIL;
} }
if (PARTITION_ID_USER == block_spec->partition || if ((PARTITION_ID_USER == block_spec->partition) ||
PARTITION_ID_BOOT_1 == block_spec->partition || (PARTITION_ID_BOOT_1 == block_spec->partition) ||
PARTITION_ID_BOOT_2 == block_spec->partition) (PARTITION_ID_BOOT_2 == block_spec->partition))
current_file.partition = block_spec->partition; current_file.partition = block_spec->partition;
else else
current_file.partition = emmcdrv_bootpartition; current_file.partition = emmcdrv_bootpartition;
......
/* /*
* Copyright (c) 2015-2018, Renesas Electronics Corporation. All rights reserved. * Copyright (c) 2015-2019, Renesas Electronics Corporation. All rights reserved.
* *
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
...@@ -28,7 +28,7 @@ static int32_t memdrv_dev_close(io_dev_info_t *dev_info); ...@@ -28,7 +28,7 @@ static int32_t memdrv_dev_close(io_dev_info_t *dev_info);
typedef struct { typedef struct {
uint32_t in_use; uint32_t in_use;
uintptr_t base; uintptr_t base;
ssize_t file_pos; signed long long file_pos;
} file_state_t; } file_state_t;
static file_state_t current_file = { 0 }; static file_state_t current_file = { 0 };
...@@ -47,7 +47,7 @@ static int32_t memdrv_block_open(io_dev_info_t *dev_info, const uintptr_t spec, ...@@ -47,7 +47,7 @@ static int32_t memdrv_block_open(io_dev_info_t *dev_info, const uintptr_t spec,
* spec at a time. When we have dynamic memory we can malloc and set * spec at a time. When we have dynamic memory we can malloc and set
* entity->info. * entity->info.
*/ */
if (current_file.in_use) if (current_file.in_use != 0U)
return IO_RESOURCES_EXHAUSTED; return IO_RESOURCES_EXHAUSTED;
/* File cursor offset for seek and incremental reads etc. */ /* File cursor offset for seek and incremental reads etc. */
...@@ -61,7 +61,7 @@ static int32_t memdrv_block_open(io_dev_info_t *dev_info, const uintptr_t spec, ...@@ -61,7 +61,7 @@ static int32_t memdrv_block_open(io_dev_info_t *dev_info, const uintptr_t spec,
} }
static int32_t memdrv_block_seek(io_entity_t *entity, int32_t mode, static int32_t memdrv_block_seek(io_entity_t *entity, int32_t mode,
ssize_t offset) signed long long offset)
{ {
if (mode != IO_SEEK_SET) if (mode != IO_SEEK_SET)
return IO_FAIL; return IO_FAIL;
...@@ -78,16 +78,17 @@ static int32_t memdrv_block_read(io_entity_t *entity, uintptr_t buffer, ...@@ -78,16 +78,17 @@ static int32_t memdrv_block_read(io_entity_t *entity, uintptr_t buffer,
fp = (file_state_t *) entity->info; fp = (file_state_t *) entity->info;
NOTICE("BL2: dst=0x%lx src=0x%lx len=%ld(0x%lx)\n", NOTICE("BL2: dst=0x%lx src=0x%llx len=%ld(0x%lx)\n",
buffer, fp->base + fp->file_pos, length, length); buffer, (unsigned long long)fp->base +
(unsigned long long)fp->file_pos, length, length);
if (FLASH_MEMORY_SIZE < fp->file_pos + length) { if (FLASH_MEMORY_SIZE < (fp->file_pos + (signed long long)length)) {
ERROR("BL2: check load image (source address)\n"); ERROR("BL2: check load image (source address)\n");
return IO_FAIL; return IO_FAIL;
} }
rcar_dma_exec(buffer, fp->base + fp->file_pos, length); rcar_dma_exec(buffer, fp->base + (uintptr_t)fp->file_pos, length);
fp->file_pos += length; fp->file_pos += (signed long long)length;
*cnt = length; *cnt = length;
return IO_SUCCESS; return IO_SUCCESS;
......
/* /*
* Copyright (c) 2018, ARM Limited and Contributors. All rights reserved. * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
* *
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
...@@ -20,14 +20,15 @@ static int mmc_dev_open(const uintptr_t init_params, io_dev_info_t **dev_info); ...@@ -20,14 +20,15 @@ static int mmc_dev_open(const uintptr_t init_params, io_dev_info_t **dev_info);
static int mmc_block_open(io_dev_info_t *dev_info, const uintptr_t spec, static int mmc_block_open(io_dev_info_t *dev_info, const uintptr_t spec,
io_entity_t *entity); io_entity_t *entity);
static int mmc_dev_init(io_dev_info_t *dev_info, const uintptr_t init_params); static int mmc_dev_init(io_dev_info_t *dev_info, const uintptr_t init_params);
static int mmc_block_seek(io_entity_t *entity, int mode, ssize_t offset); static int mmc_block_seek(io_entity_t *entity, int mode,
signed long long offset);
static int mmc_block_read(io_entity_t *entity, uintptr_t buffer, size_t length, static int mmc_block_read(io_entity_t *entity, uintptr_t buffer, size_t length,
size_t *length_read); size_t *length_read);
static int mmc_block_close(io_entity_t *entity); static int mmc_block_close(io_entity_t *entity);
static int mmc_dev_close(io_dev_info_t *dev_info); static int mmc_dev_close(io_dev_info_t *dev_info);
static io_type_t device_type_mmc(void); static io_type_t device_type_mmc(void);
static ssize_t seek_offset; static signed long long seek_offset;
static const io_dev_connector_t mmc_dev_connector = { static const io_dev_connector_t mmc_dev_connector = {
.dev_open = mmc_dev_open .dev_open = mmc_dev_open
...@@ -85,7 +86,8 @@ static int mmc_block_open(io_dev_info_t *dev_info, const uintptr_t spec, ...@@ -85,7 +86,8 @@ static int mmc_block_open(io_dev_info_t *dev_info, const uintptr_t spec,
} }
/* Seek to a particular file offset on the mmc device */ /* Seek to a particular file offset on the mmc device */
static int mmc_block_seek(io_entity_t *entity, int mode, ssize_t offset) static int mmc_block_seek(io_entity_t *entity, int mode,
signed long long offset)
{ {
seek_offset = offset; seek_offset = offset;
return 0; return 0;
......
...@@ -39,7 +39,7 @@ typedef struct io_dev_funcs { ...@@ -39,7 +39,7 @@ typedef struct io_dev_funcs {
io_type_t (*type)(void); io_type_t (*type)(void);
int (*open)(io_dev_info_t *dev_info, const uintptr_t spec, int (*open)(io_dev_info_t *dev_info, const uintptr_t spec,
io_entity_t *entity); io_entity_t *entity);
int (*seek)(io_entity_t *entity, int mode, ssize_t offset); int (*seek)(io_entity_t *entity, int mode, signed long long offset);
int (*size)(io_entity_t *entity, size_t *length); int (*size)(io_entity_t *entity, size_t *length);
int (*read)(io_entity_t *entity, uintptr_t buffer, size_t length, int (*read)(io_entity_t *entity, uintptr_t buffer, size_t length,
size_t *length_read); size_t *length_read);
......
...@@ -86,7 +86,7 @@ int io_dev_close(uintptr_t dev_handle); ...@@ -86,7 +86,7 @@ int io_dev_close(uintptr_t dev_handle);
/* Synchronous operations */ /* Synchronous operations */
int io_open(uintptr_t dev_handle, const uintptr_t spec, uintptr_t *handle); int io_open(uintptr_t dev_handle, const uintptr_t spec, uintptr_t *handle);
int io_seek(uintptr_t handle, io_seek_mode_t mode, ssize_t offset); int io_seek(uintptr_t handle, io_seek_mode_t mode, signed long long offset);
int io_size(uintptr_t handle, size_t *length); int io_size(uintptr_t handle, size_t *length);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment