Files
bootloader/include/bootloader_config.h
rovina d2b8bd7940 Initial commit: STM32 Bootloader extension module
Add a production-ready, educational bootloader extension for STM32 MCUs.

Core features:
- Custom binary protocol with CRC16/CRC32 verification
- AES-256 encryption for firmware security
- Dual-bank firmware management with rollback support
- Version management and firmware validation
- Modular architecture with BSP abstraction layer

Project structure:
- include/: Header files (bootloader.h, bsp_flash.h, bsp_uart.h)
- src/: Core implementation (bootloader, protocol, crypto, firmware manager)
- port/: MCU-specific adaptation layer (STM32F4xx)
- docs/: Documentation (integration guide, porting guide)

Supported platforms:
- STM32F4xx (primary)
- STM32F1xx (via porting)

Quick start:
1. Copy extension module to project
2. Configure bootloader_config.h
3. Modify linker script for APP_BASE_ADDR
4. Build and flash bootloader to 0x08000000

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-02 15:03:51 +08:00

86 lines
2.6 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#ifndef BOOTLOADER_CONFIG_H
#define BOOTLOADER_CONFIG_H
/*
* MCU Platform and Feature Configuration for STM32F4xx Bootloader
*/
#define MCU_FAMILY_STM32F4XX 1
#define MCU_FAMILY_STM32F1XX 0
/*
* Flash Memory Layout Configuration
*/
#define BOOTLOADER_SIZE_KB 32
#define BOOTLOADER_BASE_ADDR 0x08000000
#define BOOTLOADER_END_ADDR 0x08007FFF
#define APP_BASE_ADDR 0x08008000
#define BANK1_ADDR 0x08008000
#define BANK1_SIZE (192 * 1024)
#define BANK2_ADDR 0x08038000
#define BANK2_SIZE (192 * 1024)
#define VERSION_INFO_ADDR 0x08007C00
#define VERSION_INFO_SIZE 1024
#define APP_SIZE_MAX BANK1_SIZE
/*
* Uart Configuration for Bootloader Communication
*/
#define BOOT_UART_INSTANCE USART1
#define BOOT_UART_BAUDRATE 115200
#define BOOT_UART_TIMEOUT_MS 3000
#define BOOT_UART_BUFFER_SIZE 2048
/*
* Protocol Configuration for Firmware Update
*/
#define PROTOCOL_FRAME_HEAD 0xAA
#define PROTOCOL_FRAME_TAIL 0x55
#define PROTOCOL_MAX_DATA_LEN 1024
#define PROTOCOL_RETRY_COUNT 3
#define PROTOCOL_RETRY_DELAY_MS 100
/*
* Bootloader Feature Configuration
*/
#define BOOT_ENABLE_AES 1
#define BOOT_ENABLE_CRC 1
#define BOOT_ENABLE_DUAL_BANK 1
#define BOOT_ENABLE_VERSION_MGR 1
#define BOOT_ENABLE_LOG 1
/*
* Security Configuration for Bootloader
*/
#define BOOT_AES_KEY_SIZE 256
#define BOOT_AES_IV_SIZE 16
// AES-256密钥示例实际应用应从安全区域读取
#define BOOT_AES_KEY {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, \
0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, \
0x09, 0xcf, 0x4f, 0x3c, 0x76, 0x2e, \
0x71, 0x60, 0xf3, 0x8b, 0x4d, 0xa5, \
0x6a, 0x78, 0x4d, 0x90, 0x45, 0x19, \
0x0c, 0xfe}
/*
* Other Configuration
*/
#define BOOT_TRIGGER_TIMEOUT_MS 3000
/* Logging Macros */
#if BOOT_ENABLE_LOG
#define BOOT_LOG_DEBUG(fmt, ...) do { printf("[DEBUG] " fmt "\r\n", ##__VA_ARGS__); } while(0)
#define BOOT_LOG_INFO(fmt, ...) do { printf("[INFO] " fmt "\r\n", ##__VA_ARGS__); } while(0)
#define BOOT_LOG_WARN(fmt, ...) do { printf("[WARN] " fmt "\r\n", ##__VA_ARGS__); } while(0)
#define BOOT_LOG_ERROR(fmt, ...) do { printf("[ERROR] " fmt "\r\n", ##__VA_ARGS__); } while(0)
#else
#define BOOT_LOG_DEBUG(fmt, ...) do { } while(0)
#define BOOT_LOG_INFO(fmt, ...) do { } while(0)
#define BOOT_LOG_WARN(fmt, ...) do { } while(0)
#define BOOT_LOG_ERROR(fmt, ...) do { } while(0)
#endif
#endif