PER Firmware
Loading...
Searching...
No Matches
bootloader_common.h
Go to the documentation of this file.
2#ifndef PER_BOOTLOADER_COMMON_H
3#define PER_BOOTLOADER_COMMON_H
4
5#include <stdint.h>
6
7
9#define BOOTLOADER_PROTOCOL_VERSION 1U
11#define BOOTLOADER_INFO_PERIOD_MS 5000U
13#define BOOTLOADER_INFO_FLAG_BOOTLOADABLE (1U << 0U)
15#define BOOTLOADER_INFO_FLAG_READY (1U << 1U)
17#define BOOTLOADER_METADATA_MAGIC 0x50455242U
19#define BOOTLOADER_METADATA_FORMAT_VERSION 2U
21#define BOOTLOADER_METADATA_FLAG_INSTALLED_BY_BOOTLOADER (1U << 0U)
37#if defined(STM32G474xx)
38#define BL_FLASH_BASE 0x08000000U
39#define BL_FLASH_END 0x0807FFFFU
40#define BL_METADATA_ADDRESS 0x08004000U
41#define BL_METADATA_REGION_SIZE (16U * 1024U)
42#define BL_APP_ADDRESS 0x08008000U
43#define BL_APP_SLOT_SIZE (480U * 1024U)
44#define BL_APP_END (BL_APP_ADDRESS + BL_APP_SLOT_SIZE - 1U)
45#define BL_RESERVED_ADDRESS (BL_FLASH_END + 1U)
46#define BL_RESERVED_SIZE 0U
47
48_Static_assert(BL_METADATA_ADDRESS == (BL_FLASH_BASE + (16U * 1024U)),
49 "Bootloader metadata must follow the 16 KiB resident image");
50_Static_assert(BL_APP_ADDRESS == (BL_METADATA_ADDRESS + BL_METADATA_REGION_SIZE),
51 "Application must follow the 16 KiB metadata region");
52_Static_assert(BL_APP_END == BL_FLASH_END && BL_APP_END == 0x0807FFFFU,
53 "Application slot must consume the remaining STM32G474 flash");
54_Static_assert(BL_RESERVED_ADDRESS == 0x08080000U && BL_RESERVED_SIZE == 0U,
55 "There must be no flash reserved after the application slot");
56#endif
57
59#define BL_METADATA_SIZE 32U
61#define BL_WORD_SIZE 4U
63#define BL_FLASH_WRITE_SIZE 8U
64
72typedef struct __attribute__((aligned(BL_FLASH_WRITE_SIZE))) {
73 uint32_t magic;
74 uint32_t format_version;
75 uint32_t flags;
76 uint32_t crc32;
77 uint32_t address;
78 uint32_t size_bytes;
79 uint32_t bootloader_git_hash;
80 uint32_t reserved;
82
83_Static_assert(sizeof(BootloaderMetadata_t) == BL_METADATA_SIZE,
84 "Bootloader metadata must occupy one 32-byte record");
85_Static_assert((sizeof(BootloaderMetadata_t) % BL_FLASH_WRITE_SIZE) == 0U,
86 "Bootloader metadata must be flash-write aligned");
87
89uint32_t BL_getGitHash(void);
90
92typedef enum {
97 BLERROR_SIZE = 0x04,
99} BLError_t;
100
101
102#endif
#define BL_METADATA_SIZE
STM32G474RE flash layout shared with the linker scripts.
Definition bootloader_common.h:59
uint32_t BL_getGitHash(void)
Definition bootloader_common.c:6
BLError_t
Detail values accompanying BOOTLOADER_STATUS_ERROR.
Definition bootloader_common.h:92
@ BLERROR_FLASH
Definition bootloader_common.h:96
@ BLERROR_LOCKED
Definition bootloader_common.h:94
@ BLERROR_SIZE
Definition bootloader_common.h:97
@ BLERROR_NONE
Definition bootloader_common.h:93
@ BLERROR_ADDRESS
Definition bootloader_common.h:98
@ BLERROR_SEQUENCE
Definition bootloader_common.h:95
BootloaderMetadata_t
Definition bootloader_common.h:81
struct __attribute__((aligned(BL_FLASH_WRITE_SIZE)))
Metadata describing the only application the bootloader may launch.
Definition bootloader_common.h:72
#define BL_FLASH_WRITE_SIZE
Definition bootloader_common.h:63