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,
uint8_t *local_buffer;
boot_api_image_header_t *header =
(boot_api_image_header_t *)first_lba_buffer;
size_t hdr_sz = sizeof(boot_api_image_header_t);
assert(entity != NULL);
assert(buffer != 0U);
......@@ -286,16 +287,13 @@ static int stm32image_partition_read(io_entity_t *entity, uintptr_t buffer,
}
/* Part of image already loaded with the header */
memcpy(local_buffer, (uint8_t *)first_lba_buffer +
sizeof(boot_api_image_header_t),
MAX_LBA_SIZE - sizeof(boot_api_image_header_t));
local_buffer += MAX_LBA_SIZE - sizeof(boot_api_image_header_t);
memcpy(local_buffer, (uint8_t *)first_lba_buffer + hdr_sz,
MAX_LBA_SIZE - hdr_sz);
local_buffer += MAX_LBA_SIZE - hdr_sz;
offset = MAX_LBA_SIZE;
/* New image length to be read */
local_length = round_up(length -
((MAX_LBA_SIZE) -
sizeof(boot_api_image_header_t)),
local_length = round_up(length - ((MAX_LBA_SIZE) - hdr_sz),
stm32image_dev.lba_size);
if ((header->load_address != 0U) &&
......@@ -326,7 +324,7 @@ static int stm32image_partition_read(io_entity_t *entity, uintptr_t buffer,
local_length, length_read);
/* 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) {
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