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