From cb13fb65deccd26ced2d0493c257b9bc6f54611a Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Sat, 24 Aug 2019 08:51:17 +0200 Subject: [PATCH] Store version in the bootloader. Debug code. --- fido2/ctap.c | 6 ++++++ fido2/version.c | 2 +- fido2/version.h | 2 ++ targets/stm32l432/bootloader/bootloader.c | 13 +++++++++++++ targets/stm32l432/bootloader/main.c | 8 ++++++++ 5 files changed, 30 insertions(+), 1 deletion(-) diff --git a/fido2/ctap.c b/fido2/ctap.c index dea0f3f..c7b6e62 100644 --- a/fido2/ctap.c +++ b/fido2/ctap.c @@ -1712,8 +1712,14 @@ static void ctap_state_init() ctap_reset_rk(); } +#include "version.h" void ctap_init() { + printf1(TAG_ERR,"Current firmware version address: %p\r\n", &firmware_version); + printf1(TAG_ERR,"Current firmware version: %d.%d.%d.%d (%02x.%02x.%02x.%02x)\r\n", + firmware_version.major, firmware_version.minor, firmware_version.patch, firmware_version.reserved, + firmware_version.major, firmware_version.minor, firmware_version.patch, firmware_version.reserved + ); crypto_ecc256_init(); authenticator_read_state(&STATE); diff --git a/fido2/version.c b/fido2/version.c index dd8da5b..d8c2252 100644 --- a/fido2/version.c +++ b/fido2/version.c @@ -1,7 +1,7 @@ #include "version.h" -static const version_t firmware_version __attribute__ ((section (".flag"))) __attribute__ ((__used__)) = { +const version_t firmware_version __attribute__ ((section (".flag"))) __attribute__ ((__used__)) = { .major = SOLO_VERSION_MAJ, .minor = SOLO_VERSION_MIN, .patch = SOLO_VERSION_PATCH, diff --git a/fido2/version.h b/fido2/version.h index 95c98f3..3671c16 100644 --- a/fido2/version.h +++ b/fido2/version.h @@ -33,5 +33,7 @@ typedef struct { } version_t; bool is_newer(const version_t* const newer, const version_t* const older); +const version_t firmware_version ; + #endif diff --git a/targets/stm32l432/bootloader/bootloader.c b/targets/stm32l432/bootloader/bootloader.c index e8b79b8..eec838b 100644 --- a/targets/stm32l432/bootloader/bootloader.c +++ b/targets/stm32l432/bootloader/bootloader.c @@ -112,7 +112,20 @@ uint8_t * last_addr; bool is_firmware_version_newer_or_equal() { + printf1(TAG_BOOT, "Dump last 8 bytes: %p\r\n", last_addr); + dump_hex1(TAG_BOOT, last_addr, 8); + + printf1(TAG_BOOT,"Current firmware version: %u.%u.%u.%u (%02x.%02x.%02x.%02x)\r\n", + current_firmware_version.major, current_firmware_version.minor, current_firmware_version.patch, current_firmware_version.reserved, + current_firmware_version.major, current_firmware_version.minor, current_firmware_version.patch, current_firmware_version.reserved + ); + dump_hex1(TAG_BOOT, (uint8_t*)(¤t_firmware_version) - 16, 32); volatile version_t * new_version = ((volatile version_t *) last_addr); + printf1(TAG_BOOT,"Uploaded firmware version: %u.%u.%u.%u (%02x.%02x.%02x.%02x)\r\n", + new_version->major, new_version->minor, new_version->patch, new_version->reserved, + new_version->major, new_version->minor, new_version->patch, new_version->reserved + ); + dump_hex1(TAG_BOOT, (uint8_t *) last_addr, 8); dump_hex1(TAG_BOOT, (uint8_t *) NEW_FW_VERSION_ADDR, 8); dump_hex1(TAG_BOOT, (uint8_t *) NEW_FW_VERSION_ADDR+8, 8); diff --git a/targets/stm32l432/bootloader/main.c b/targets/stm32l432/bootloader/main.c index c3bf736..1448ea7 100644 --- a/targets/stm32l432/bootloader/main.c +++ b/targets/stm32l432/bootloader/main.c @@ -138,6 +138,14 @@ int main() printf1(TAG_GEN,"recv'ing hid msg \n"); + extern volatile version_t current_firmware_version; + printf1(TAG_BOOT,"Current firmware version address: %p\r\n", ¤t_firmware_version); + printf1(TAG_BOOT,"Current firmware version: %d.%d.%d.%d (%02x.%02x.%02x.%02x)\r\n", + current_firmware_version.major, current_firmware_version.minor, current_firmware_version.patch, current_firmware_version.reserved, + current_firmware_version.major, current_firmware_version.minor, current_firmware_version.patch, current_firmware_version.reserved + ); + dump_hex1(TAG_BOOT, (uint8_t*)(¤t_firmware_version) - 16, 32); + while(1) {