diff --git a/bootloader/signatures.c b/bootloader/signatures.c index 37e5f67b8..ec6ca3af6 100644 --- a/bootloader/signatures.c +++ b/bootloader/signatures.c @@ -119,7 +119,11 @@ bool firmware_present_new(void) { const image_header *hdr = (const image_header *)FLASH_PTR(FLASH_FWHEADER_START); if (hdr->magic != FIRMWARE_MAGIC_NEW) return false; - if (hdr->hdrlen != FLASH_FWHEADER_LEN) return false; + // we need to ignore hdrlen for now + // because we keep reset_handler ptr there + // for compatibility with older bootloaders + // after this is no longer necessary, let's uncomment the line below: + // if (hdr->hdrlen != FLASH_FWHEADER_LEN) return false; if (hdr->codelen > FLASH_APP_LEN) return false; if (hdr->codelen < 4096) return false; diff --git a/firmware/bl_check.c b/firmware/bl_check.c index 50c8ac488..04cd8644b 100644 --- a/firmware/bl_check.c +++ b/firmware/bl_check.c @@ -26,7 +26,7 @@ #include "gettext.h" #include "util.h" -int known_bootloader(int r, const uint8_t *hash) { +static int known_bootloader(int r, const uint8_t *hash) { if (r != 32) return 0; if (0 == memcmp(hash, "\xbf\x72\xe2\x5e\x2c\x2f\xc1\xba\x57\x04\x50\xfa\xdf\xb6\x6f\xaa\x5a\x71\x6d\xcd\xc0\x33\x35\x88\x55\x7b\x77\x54\x0a\xb8\x7e\x98", 32)) return 1; // 1.2.0a if (0 == memcmp(hash, "\x77\xb8\xe2\xf2\x5f\xaa\x8e\x8c\x7d\x9f\x5b\x32\x3b\x27\xce\x05\x6c\xa3\xdb\xc2\x3f\x56\xc3\x7e\xe3\x3f\x97\x7c\xa6\xeb\x4d\x3e", 32)) return 1; // 1.2.0b @@ -44,7 +44,7 @@ int known_bootloader(int r, const uint8_t *hash) { if (0 == memcmp(hash, "\x3e\xc4\xbd\xd5\x77\xea\x0c\x36\xc7\xba\xb7\xb9\xa3\x5b\x87\x17\xb3\xf1\xfc\x2f\x80\x9e\x69\x0c\x8a\xbe\x5b\x05\xfb\xc2\x43\xc6", 32)) return 1; // 1.6.0 shipped with fw 1.7.0 if (0 == memcmp(hash, "\x8e\x83\x02\x3f\x0d\x4f\x82\x4f\x64\x71\x20\x75\x2b\x6c\x71\x6f\x55\xd7\x95\x70\x66\x8f\xd4\x90\x65\xd5\xb7\x97\x6e\x7a\x6e\x19", 32)) return 1; // 1.6.0 shipped with fw 1.7.1 and 1.7.2 if (0 == memcmp(hash, "\xa2\x36\x6e\x77\xde\x8e\xfd\xfd\xc9\x99\xf4\x72\x20\xc0\x16\xe3\x3f\x6d\x24\x24\xe2\x45\x90\x79\x11\x7a\x90\xb3\xa8\x88\xba\xdd", 32)) return 1; // 1.6.1 shipped with fw 1.7.3 - if (0 == memcmp(hash, "\xaf\x19\x47\x7b\xf1\x4c\x33\x81\x34\x78\xd3\x29\x46\x58\x3b\x5d\xcf\xb2\x13\xc5\xba\x92\x81\x1e\x46\x50\x8e\xd0\x14\xb7\xa6\x14", 32)) return 1; // 1.8.0 shipped with fw 1.8.0 + if (0 == memcmp(hash, "\xd2\xe7\x5b\x31\xaa\x66\x88\x74\x90\x3a\x30\x9e\x65\xc9\x4d\x0b\x36\x6b\x1d\xc8\xca\x8d\xda\x37\xba\x6f\x16\x6e\x50\x82\xae\xda", 32)) return 1; // 1.8.0 shipped with fw 1.8.0 return 0; } diff --git a/firmware/header.S b/firmware/header.S index 9333fb238..46e4aa375 100644 --- a/firmware/header.S +++ b/firmware/header.S @@ -9,7 +9,7 @@ g_header: .byte 'T','R','Z','F' // magic - .word g_header_end - g_header // hdrlen + .word reset_handler // reset handler, replace later with : .word g_header_end - g_header // hdrlen .word 0 // expiry .word _codelen // codelen .byte VERSION_MAJOR // vmajor diff --git a/startup.s b/startup.s index 59a87e1af..ce75ba1a7 100644 --- a/startup.s +++ b/startup.s @@ -19,6 +19,16 @@ memset_reg: .global reset_handler .type reset_handler, STT_FUNC reset_handler: +// we need to perform this in case an old bootloader +// is starting the new firmware, these will be set incorrectly + ldr r0, =0xE000ED08 // r0 = VTOR address + ldr r1, =0x08010400 // r1 = FLASH_APP_START + str r1, [r0] // assign + ldr r0, =_stack // r0 = stack pointer + msr msp, r0 // set stack pointer + dsb + isb + ldr r0, =_ram_start // r0 - point to beginning of SRAM ldr r1, =_ram_end // r1 - point to byte after the end of SRAM ldr r2, =0 // r2 - the byte-sized value to be written