From 34c6fb987a16ecce93fdb786116787dc5be237aa Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Sat, 10 Feb 2018 17:52:45 +0100 Subject: [PATCH] embed/bootloader: better detection of broken firmware at start --- embed/bootloader/main.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/embed/bootloader/main.c b/embed/bootloader/main.c index 711c74ff25..3b54fb28e2 100644 --- a/embed/bootloader/main.c +++ b/embed/bootloader/main.c @@ -227,14 +227,20 @@ main_start: image_header hdr; secbool firmware_present; - // detect whether the devices contains a firmware + // detect whether the devices contains a valid firmware firmware_present = load_vendor_header_keys((const uint8_t *)FIRMWARE_START, &vhdr); + if (sectrue == firmware_present) { + firmware_present = check_vendor_keys_lock(&vhdr); + } if (sectrue == firmware_present) { firmware_present = load_image_header((const uint8_t *)(FIRMWARE_START + vhdr.hdrlen), FIRMWARE_IMAGE_MAGIC, FIRMWARE_IMAGE_MAXSIZE, vhdr.vsig_m, vhdr.vsig_n, vhdr.vpub, &hdr); } + if (sectrue == firmware_present) { + firmware_present = check_image_contents(&hdr, IMAGE_HEADER_SIZE + vhdr.hdrlen, firmware_sectors, FIRMWARE_SECTORS_COUNT); + } - // start the bootloader if no firmware found ... + // start the bootloader if no or broken firmware found ... if (firmware_present != sectrue) { // show intro animation