Skip to content

Commit

Permalink
bootloader: move boot_data_t to memory_shared.h
Browse files Browse the repository at this point in the history
To make it available to the firmware.
  • Loading branch information
benma committed Mar 21, 2024
1 parent 01f51e2 commit 22fc493
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
34 changes: 0 additions & 34 deletions src/bootloader/bootloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,40 +96,6 @@ COMPILER_PACK_RESET()
#error "incompatible variable type"
#endif

#define BOOT_NUM_FIRMWARE_SIGNING_KEYS 3u
#define BOOT_NUM_ROOT_SIGNING_KEYS 3u
#define BOOT_FIRMWARE_SIG_M 2u
#define BOOT_ROOT_SIG_M 2u
#define BOOT_PUBKEY_LEN 64u
#define BOOT_SIG_LEN 64u

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpacked"
#pragma GCC diagnostic ignored "-Wattributes"
// Packed to make the layout more explicit.
// Total size equals min erase granularity
typedef uint32_t version_t;
typedef union {
struct __attribute__((__packed__)) {
// `hardware_version` is deprecated/unused, as MPU prevents the firmware from easily reading
// this.
uint16_t hardware_version;
uint8_t is_initialized[2];
version_t signing_pubkeys_version;
uint8_t signing_pubkeys
[BOOT_PUBKEY_LEN *
BOOT_NUM_FIRMWARE_SIGNING_KEYS]; // Keep after signing_pubkeys_version
uint8_t root_signatures_of_signing_pubkeys[BOOT_SIG_LEN * BOOT_NUM_ROOT_SIGNING_KEYS];
version_t firmware_version;
uint8_t
firmware_signatures[BOOT_SIG_LEN * BOOT_NUM_FIRMWARE_SIGNING_KEYS]; // Keep after
// firmware_version
uint8_t show_firmware_hash;
} fields;
uint8_t bytes[FLASH_BOOTDATA_LEN];
} boot_data_t;

#pragma GCC diagnostic pop
// Be sure to not overflow boot data area
static_assert(sizeof(((boot_data_t*)0)->fields) <= FLASH_BOOTDATA_LEN, "boot_data_t too large");
// Be sure signing pubkey data fits within a single chunk
Expand Down
34 changes: 34 additions & 0 deletions src/memory/memory_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,40 @@
#error "Shared data chunk not correct length"
#endif

#define BOOT_NUM_FIRMWARE_SIGNING_KEYS 3u
#define BOOT_NUM_ROOT_SIGNING_KEYS 3u
#define BOOT_FIRMWARE_SIG_M 2u
#define BOOT_ROOT_SIG_M 2u
#define BOOT_PUBKEY_LEN 64u
#define BOOT_SIG_LEN 64u

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpacked"
#pragma GCC diagnostic ignored "-Wattributes"
// Packed to make the layout more explicit.
// Total size equals min erase granularity
typedef uint32_t version_t;
typedef union {
struct __attribute__((__packed__)) {
// `hardware_version` is deprecated/unused, as MPU prevents the firmware from easily reading
// this.
uint16_t hardware_version;
uint8_t is_initialized[2];
version_t signing_pubkeys_version;
uint8_t signing_pubkeys
[BOOT_PUBKEY_LEN *
BOOT_NUM_FIRMWARE_SIGNING_KEYS]; // Keep after signing_pubkeys_version
uint8_t root_signatures_of_signing_pubkeys[BOOT_SIG_LEN * BOOT_NUM_ROOT_SIGNING_KEYS];
version_t firmware_version;
uint8_t
firmware_signatures[BOOT_SIG_LEN * BOOT_NUM_FIRMWARE_SIGNING_KEYS]; // Keep after
// firmware_version
uint8_t show_firmware_hash;
} fields;
uint8_t bytes[FLASH_BOOTDATA_LEN];
} boot_data_t;
#pragma GCC diagnostic pop

// CHUNK_SHARED: Shared data between the bootloader and firmware.
// auto_enter: if sectrue_u8, bootloader mode is entered on reboot
// upside_down: passes screen orientation to the bootloader
Expand Down

0 comments on commit 22fc493

Please sign in to comment.