1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Aidan MacDonald 2022-12-22 19:23:29 +00:00
parent af644e02a1
commit 6ffd42548b
11 changed files with 150 additions and 59 deletions

View file

@ -22,6 +22,7 @@
#ifndef __ASSEMBLER__
#include <stdint.h>
#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