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: Yann Gautier <yann.gautier@st.com>
This commit is contained in:
Yann Gautier 2020-06-19 11:38:24 +02:00 committed by Yann Gautier
parent c1d732d0db
commit b6561c1217
1 changed files with 6 additions and 8 deletions

View File

@ -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);