From 6ffd42548bf10cda13a01555ff4fa56d4213cdf2 Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Thu, 22 Dec 2022 19:23:29 +0000 Subject: multiboot: Refactor boot data validation, add version numbers Instead of verifying the CRC before every access of the boot data, verify the CRC once at startup and set a flag to indicate the boot data is valid. Also add a framework to support multiple boot protocol versions. Firmware declares the maximum supported protocol version using a version byte in the boot data header. The bootloader chooses the highest version supported by it and the firmware when deciding what boot protocol to use. Change-Id: I810194625dc0833f026d2a23b8d64ed467fa6aca --- firmware/export/bootdata.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'firmware/export/bootdata.h') diff --git a/firmware/export/bootdata.h b/firmware/export/bootdata.h index 322d50c20d..319f442511 100644 --- a/firmware/export/bootdata.h +++ b/firmware/export/bootdata.h @@ -22,6 +22,7 @@ #ifndef __ASSEMBLER__ #include +#include "system.h" #endif /* /!\ This file can be included in assembly files /!\ */ @@ -36,6 +37,7 @@ #define BOOT_DATA_MAGIC0 ('r' | 'b' << 8 | 'm' << 16 | 'a' << 24) #define BOOT_DATA_MAGIC1 ('g' | 'i' << 8 | 'c' << 16 | '!' << 24) +#define BOOT_DATA_VERSION 0 /* maximum size of payload */ #define BOOT_DATA_PAYLOAD_SIZE 4 @@ -58,6 +60,7 @@ struct boot_data_t struct { uint8_t boot_volume; + uint8_t version; }; uint8_t payload[BOOT_DATA_PAYLOAD_SIZE]; }; @@ -65,6 +68,9 @@ struct boot_data_t #if !defined(BOOTLOADER) extern struct boot_data_t boot_data; +extern bool boot_data_valid; + +void verify_boot_data(void) INIT_ATTR; #endif #else /* __ASSEMBLER__ */ @@ -76,7 +82,9 @@ boot_data: .word BOOT_DATA_MAGIC0 .word BOOT_DATA_MAGIC1 .word BOOT_DATA_PAYLOAD_SIZE - .space BOOT_DATA_PAYLOAD_SIZE, 0xff /* payload, initialised with value 0xff */ + .byte 0xff /* boot volume */ + .byte BOOT_DATA_VERSION /* maximum supported boot protocol version */ + .space (BOOT_DATA_PAYLOAD_SIZE - 2), 0xff /* remainder of payload */ .endm #endif -- cgit v1.2.3