Commit b6561c12 authored by Yann Gautier's avatar Yann Gautier Committed by Yann Gautier
Browse files

refactor(io_stm32image): add header size variable



A variable hdr_sz is created in stm32image_partition_read() function.
It just represents the size of the stm32 image header but it really
improves the readability of the function.

Change-Id: I95ec62a78a4b6c6a75b0d8c8aa0faef8bee424da
Signed-off-by: default avatarYann Gautier <yann.gautier@st.com>
parent c1d732d0
...@@ -250,6 +250,7 @@ static int stm32image_partition_read(io_entity_t *entity, uintptr_t buffer, ...@@ -250,6 +250,7 @@ static int stm32image_partition_read(io_entity_t *entity, uintptr_t buffer,
uint8_t *local_buffer; uint8_t *local_buffer;
boot_api_image_header_t *header = boot_api_image_header_t *header =
(boot_api_image_header_t *)first_lba_buffer; (boot_api_image_header_t *)first_lba_buffer;
size_t hdr_sz = sizeof(boot_api_image_header_t);
assert(entity != NULL); assert(entity != NULL);
assert(buffer != 0U); assert(buffer != 0U);
...@@ -286,16 +287,13 @@ static int stm32image_partition_read(io_entity_t *entity, uintptr_t buffer, ...@@ -286,16 +287,13 @@ static int stm32image_partition_read(io_entity_t *entity, uintptr_t buffer,
} }
/* Part of image already loaded with the header */ /* Part of image already loaded with the header */
memcpy(local_buffer, (uint8_t *)first_lba_buffer + memcpy(local_buffer, (uint8_t *)first_lba_buffer + hdr_sz,
sizeof(boot_api_image_header_t), MAX_LBA_SIZE - hdr_sz);
MAX_LBA_SIZE - sizeof(boot_api_image_header_t)); local_buffer += MAX_LBA_SIZE - hdr_sz;
local_buffer += MAX_LBA_SIZE - sizeof(boot_api_image_header_t);
offset = MAX_LBA_SIZE; offset = MAX_LBA_SIZE;
/* New image length to be read */ /* New image length to be read */
local_length = round_up(length - local_length = round_up(length - ((MAX_LBA_SIZE) - hdr_sz),
((MAX_LBA_SIZE) -
sizeof(boot_api_image_header_t)),
stm32image_dev.lba_size); stm32image_dev.lba_size);
if ((header->load_address != 0U) && if ((header->load_address != 0U) &&
...@@ -326,7 +324,7 @@ static int stm32image_partition_read(io_entity_t *entity, uintptr_t buffer, ...@@ -326,7 +324,7 @@ static int stm32image_partition_read(io_entity_t *entity, uintptr_t buffer,
local_length, length_read); local_length, length_read);
/* Adding part of size already read from header */ /* Adding part of size already read from header */
*length_read += MAX_LBA_SIZE - sizeof(boot_api_image_header_t); *length_read += MAX_LBA_SIZE - hdr_sz;
if (result != 0) { if (result != 0) {
ERROR("%s: io_read (%i)\n", __func__, result); ERROR("%s: io_read (%i)\n", __func__, result);
......
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