Increase stack/heap for Zynq. Add additional Zynq debugging logs for update_ram.c. Pass return code from `wolfBoot_verify_signature` when calling `wolfBoot_verify_authenticity`.

pull/87/head
David Garske 2020-04-07 12:28:19 -07:00 committed by Daniele Lacamera
parent 14b8dc2cd6
commit 709ce000a7
3 changed files with 40 additions and 9 deletions

View File

@ -1,8 +1,8 @@
/* Linker Script for Zynq MP */ /* Linker Script for Zynq MP */
/* Stack increased to 32KB for RSA 4096-bit */ /* Stack increased to 64KB for RSA 4096-bit */
_STACK_SIZE = DEFINED(_STACK_SIZE) ? _STACK_SIZE : 0x8000; _STACK_SIZE = DEFINED(_STACK_SIZE) ? _STACK_SIZE : 0x10000;
_HEAP_SIZE = DEFINED(_HEAP_SIZE) ? _HEAP_SIZE : 0x2000; _HEAP_SIZE = DEFINED(_HEAP_SIZE) ? _HEAP_SIZE : 0x10000;
_EL0_STACK_SIZE = DEFINED(_EL0_STACK_SIZE) ? _EL0_STACK_SIZE : 1024; _EL0_STACK_SIZE = DEFINED(_EL0_STACK_SIZE) ? _EL0_STACK_SIZE : 1024;
_EL1_STACK_SIZE = DEFINED(_EL1_STACK_SIZE) ? _EL1_STACK_SIZE : 2048; _EL1_STACK_SIZE = DEFINED(_EL1_STACK_SIZE) ? _EL1_STACK_SIZE : 2048;

View File

@ -666,6 +666,7 @@ int wolfBoot_verify_integrity(struct wolfBoot_image *img)
int wolfBoot_verify_authenticity(struct wolfBoot_image *img) int wolfBoot_verify_authenticity(struct wolfBoot_image *img)
{ {
int ret;
uint8_t *stored_signature; uint8_t *stored_signature;
uint16_t stored_signature_size; uint16_t stored_signature_size;
uint8_t *pubkey_hint; uint8_t *pubkey_hint;
@ -694,8 +695,8 @@ int wolfBoot_verify_authenticity(struct wolfBoot_image *img)
return -1; return -1;
img->sha_hash = digest; img->sha_hash = digest;
} }
if (wolfBoot_verify_signature(img->sha_hash, stored_signature) != 0) if ((ret = wolfBoot_verify_signature(img->sha_hash, stored_signature)) != 0)
return -1; return ret;
img->signature_ok = 1; img->signature_ok = 1;
return 0; return 0;
} }

View File

@ -29,6 +29,11 @@
#include "wolfboot/wolfboot.h" #include "wolfboot/wolfboot.h"
#include <string.h> #include <string.h>
#ifdef DEBUG_ZYNQ
#include <stdio.h>
#include "xil_printf.h"
#endif
extern void hal_flash_dualbank_swap(void); extern void hal_flash_dualbank_swap(void);
static inline void boot_panic(void) static inline void boot_panic(void)
@ -39,7 +44,7 @@ static inline void boot_panic(void)
void RAMFUNCTION wolfBoot_start(void) void RAMFUNCTION wolfBoot_start(void)
{ {
int active; int active, ret[3];
struct wolfBoot_image os_image; struct wolfBoot_image os_image;
uint32_t* load_address = (uint32_t*)WOLFBOOT_LOAD_ADDRESS; uint32_t* load_address = (uint32_t*)WOLFBOOT_LOAD_ADDRESS;
uint8_t* image_ptr; uint8_t* image_ptr;
@ -50,6 +55,10 @@ void RAMFUNCTION wolfBoot_start(void)
active = wolfBoot_dualboot_candidate(); active = wolfBoot_dualboot_candidate();
#ifdef DEBUG_ZYNQ
xil_printf("Active Part %d\n", active);
#endif
if (active < 0) /* panic if no images available */ if (active < 0) /* panic if no images available */
boot_panic(); boot_panic();
@ -64,9 +73,13 @@ void RAMFUNCTION wolfBoot_start(void)
} }
for (;;) { for (;;) {
if ((wolfBoot_open_image(&os_image, active) < 0) || if (((ret[0] = wolfBoot_open_image(&os_image, active)) < 0) ||
(wolfBoot_verify_integrity(&os_image) < 0) || ((ret[1] = wolfBoot_verify_integrity(&os_image)) < 0) ||
(wolfBoot_verify_authenticity(&os_image) < 0)) { ((ret[2] = wolfBoot_verify_authenticity(&os_image)) < 0)) {
#ifdef DEBUG_ZYNQ
xil_printf("Part %d: Failure: %d %d %d\n", active, ret[0], ret[1], ret[2]);
#endif
/* panic if authentication fails and no backup */ /* panic if authentication fails and no backup */
if (!wolfBoot_fallback_is_possible()) if (!wolfBoot_fallback_is_possible())
@ -83,6 +96,10 @@ void RAMFUNCTION wolfBoot_start(void)
} }
} }
#ifdef DEBUG_ZYNQ
xil_printf("Firmware Valid\n");
#endif
/* First time we boot this update, set to TESTING to await /* First time we boot this update, set to TESTING to await
* confirmation from the system * confirmation from the system
*/ */
@ -109,6 +126,10 @@ void RAMFUNCTION wolfBoot_start(void)
#ifdef EXT_FLASH #ifdef EXT_FLASH
/* Load image to RAM */ /* Load image to RAM */
if (PART_IS_EXT(&os_image)) { if (PART_IS_EXT(&os_image)) {
#ifdef DEBUG_ZYNQ
xil_printf("Loading %d to RAM at %08lx\n", os_image.fw_size, load_address);
#endif
ext_flash_read((uintptr_t)os_image.fw_base, ext_flash_read((uintptr_t)os_image.fw_base,
(uint8_t*)load_address, (uint8_t*)load_address,
os_image.fw_size); os_image.fw_size);
@ -123,6 +144,10 @@ void RAMFUNCTION wolfBoot_start(void)
#ifdef EXT_FLASH #ifdef EXT_FLASH
/* Load DTS to RAM */ /* Load DTS to RAM */
if (PART_IS_EXT(&os_image)) { if (PART_IS_EXT(&os_image)) {
#ifdef DEBUG_ZYNQ
xil_printf("Loading DTS %d to RAM at %08lx\n", os_image.fw_size, dts_address);
#endif
ext_flash_read((uintptr_t)os_image.fw_base, ext_flash_read((uintptr_t)os_image.fw_base,
(uint8_t*)dts_address, (uint8_t*)dts_address,
os_image.fw_size); os_image.fw_size);
@ -132,6 +157,11 @@ void RAMFUNCTION wolfBoot_start(void)
#endif #endif
hal_prepare_boot(); hal_prepare_boot();
#ifdef DEBUG_ZYNQ
xil_printf("Booting at %08lx\n", load_address);
#endif
#ifdef MMU #ifdef MMU
do_boot((uint32_t*)load_address, (uint32_t*)dts_address); do_boot((uint32_t*)load_address, (uint32_t*)dts_address);
#else #else