mirror of https://github.com/wolfSSL/wolfBoot.git
Fix bug with fixed partitions not setting `hdr` and `trailer` correctly.
parent
2a481af879
commit
7cb8d3a66f
23
src/image.c
23
src/image.c
|
@ -786,16 +786,14 @@ uint32_t wolfBoot_image_size(uint8_t *image)
|
|||
|
||||
int wolfBoot_open_image_address(struct wolfBoot_image* img, uint8_t* image)
|
||||
{
|
||||
uint32_t *magic;
|
||||
|
||||
|
||||
magic = (uint32_t *)(image);
|
||||
uint32_t *magic = (uint32_t *)(image);
|
||||
if (*magic != WOLFBOOT_MAGIC) {
|
||||
wolfBoot_printf("Boot header magic 0x%08x invalid at %p\n",
|
||||
*magic, image);
|
||||
return -1;
|
||||
}
|
||||
img->fw_size = wolfBoot_image_size(image);
|
||||
wolfBoot_printf("Part: Size %d\n", img->fw_size);
|
||||
#ifdef WOLFBOOT_FIXED_PARTITIONS
|
||||
if (img->fw_size > (WOLFBOOT_PARTITION_SIZE - IMAGE_HEADER_SIZE)) {
|
||||
wolfBoot_printf("Image size %d > max %d\n",
|
||||
|
@ -803,13 +801,13 @@ int wolfBoot_open_image_address(struct wolfBoot_image* img, uint8_t* image)
|
|||
img->fw_size = 0;
|
||||
return -1;
|
||||
}
|
||||
img->trailer = img->hdr + WOLFBOOT_PARTITION_SIZE;
|
||||
#else
|
||||
/* This function was called directly, img->hdr is not yet set */
|
||||
img->hdr = image;
|
||||
#endif
|
||||
if (!img->hdr_ok) {
|
||||
img->hdr = image;
|
||||
img->hdr_ok = 1;
|
||||
}
|
||||
img->fw_base = img->hdr + IMAGE_HEADER_SIZE;
|
||||
img->trailer = img->hdr + WOLFBOOT_PARTITION_SIZE;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -861,8 +859,8 @@ int wolfBoot_open_image(struct wolfBoot_image *img, uint8_t part)
|
|||
memset(img, 0, sizeof(struct wolfBoot_image));
|
||||
img->part = part;
|
||||
if (part == PART_SWAP) {
|
||||
img->hdr_ok = 1;
|
||||
img->hdr = (void*)WOLFBOOT_PARTITION_SWAP_ADDRESS;
|
||||
img->hdr_ok = 1;
|
||||
img->fw_base = img->hdr;
|
||||
img->fw_size = WOLFBOOT_SECTOR_SIZE;
|
||||
return 0;
|
||||
|
@ -888,11 +886,14 @@ int wolfBoot_open_image(struct wolfBoot_image *img, uint8_t part)
|
|||
if (part == PART_BOOT) {
|
||||
img->hdr = (void*)WOLFBOOT_PARTITION_BOOT_ADDRESS;
|
||||
wolfBoot_printf("Boot partition: %p\n", img->hdr);
|
||||
} else if (part == PART_UPDATE) {
|
||||
}
|
||||
else if (part == PART_UPDATE) {
|
||||
img->hdr = (void*)WOLFBOOT_PARTITION_UPDATE_ADDRESS;
|
||||
wolfBoot_printf("Update partition: %p\n", img->hdr);
|
||||
} else
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* fetch header address
|
||||
* (or copy from external device to a local buffer via fetch_hdr_cpy)
|
||||
|
|
Loading…
Reference in New Issue