PER Firmware
Loading...
Searching...
No Matches
bootloader.c File Reference
#include "bootloader/bootloader.h"
#include <string.h>
#include "can_library/generated/can_version.h"
#include "bootloader/bootloader_common.h"
#include "phal_G4/crc/crc.h"
#include "phal_G4/fdcan/fdcan.h"
#include "phal_G4/flash/flash.h"
#include "phal_G4/gpio/gpio.h"
#include "phal_G4/rcc/rcc.h"
#include "node_defs.h"
Include dependency graph for bootloader.c:

Macros

#define BL_RX_QUEUE_LENGTH   16U
 
#define BL_RAM_START   0x20000000U
 
#define BL_RAM_END   0x2001FFFFU
 

Enumerations

enum  BLState_t {
  BL_STATE_STARTUP , BL_STATE_READY , BL_STATE_UPDATING , BL_STATE_CHECKING ,
  BL_STATE_RECOVERY
}
 

Functions

static bool bl_size_is_valid (uint32_t size_bytes)
 
static bool bl_range_is_valid (uint32_t address, uint32_t size_bytes)
 
static uint32_t bl_message_id (const CanMsgTypeDef_t *message)
 
static bool bl_message_is_bootloader_traffic (const CanMsgTypeDef_t *message)
 
static void bl_send_status (bootloader_status_t status, uint32_t detail)
 
static void bl_send_info (void)
 
static bool bl_flush_pending_word (void)
 
static bool bl_write_word (uint32_t index, uint32_t word)
 
static uint32_t bl_physical_size (uint32_t size_bytes)
 
static bool bl_invalidate_metadata (void)
 
static bool bl_begin_update (uint32_t size_bytes)
 
static bool bl_write_metadata (uint32_t crc32, uint32_t size_bytes)
 
static bool bl_application_crc_is_valid (uint32_t address, uint32_t size_bytes, uint32_t expected_crc)
 
static bool bl_vector_is_valid (uint32_t app_address, uint32_t size_bytes)
 
static bool bl_commit_update (uint32_t expected_crc)
 
bool BL_checkAndBoot (void)
 Validate the committed image and transfer control to it.
 
static uint32_t bl_uint32_data (const CanMsgTypeDef_t *message)
 
static void bl_process_message (const CanMsgTypeDef_t *message)
 
void SysTick_Handler (void)
 
static void bl_process_queued_messages (void)
 
void BL_poll (void)
 Process every frame currently queued by the FDCAN receive interrupt.
 
static void bl_enable_irq (FDCAN_GlobalTypeDef *peripheral)
 
void BL_init (void)
 Configure the node-specific transport and announce readiness.
 
void PHAL_FDCAN_rxCallback (CanMsgTypeDef_t *message)
 Weak callback fired once per received frame.
 

Variables

static volatile CanMsgTypeDef_t bl_rx_queue [BL_RX_QUEUE_LENGTH]
 
static volatile uint8_t bl_rx_head
 
static volatile uint8_t bl_rx_tail
 
static BLState_t current_state = BL_STATE_STARTUP
 
static BLState_t next_state = BL_STATE_STARTUP
 
static bool bl_boot_status_requested
 
static bool bl_update_active
 
static volatile uint32_t bl_millis
 
static uint32_t bl_startup_start_ms
 
static uint32_t bl_last_info_ms
 
static bool bl_info_sent
 
static uint32_t bl_firmware_size
 
static uint32_t bl_total_words
 
static uint32_t bl_next_word
 
static uint32_t bl_pending_word
 
static bool bl_pending_word_valid
 

Macro Definition Documentation

◆ BL_RAM_END

#define BL_RAM_END   0x2001FFFFU

◆ BL_RAM_START

#define BL_RAM_START   0x20000000U

◆ BL_RX_QUEUE_LENGTH

#define BL_RX_QUEUE_LENGTH   16U

Enumeration Type Documentation

◆ BLState_t

enum BLState_t
Enumerator
BL_STATE_STARTUP 
BL_STATE_READY 
BL_STATE_UPDATING 
BL_STATE_CHECKING 
BL_STATE_RECOVERY 

Function Documentation

◆ bl_application_crc_is_valid()

static bool bl_application_crc_is_valid ( uint32_t address,
uint32_t size_bytes,
uint32_t expected_crc )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bl_begin_update()

static bool bl_begin_update ( uint32_t size_bytes)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BL_checkAndBoot()

bool BL_checkAndBoot ( void )

Validate the committed image and transfer control to it.

Metadata, vector-table values, and application CRC are checked before VTOR and MSP are changed.

Returns
false when validation fails or the application reset handler returns.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bl_commit_update()

static bool bl_commit_update ( uint32_t expected_crc)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bl_enable_irq()

static void bl_enable_irq ( FDCAN_GlobalTypeDef * peripheral)
static
Here is the caller graph for this function:

◆ bl_flush_pending_word()

static bool bl_flush_pending_word ( void )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BL_init()

void BL_init ( void )

Configure the node-specific transport and announce readiness.

The system clock must be configured before this function is called.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ bl_invalidate_metadata()

static bool bl_invalidate_metadata ( void )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bl_message_id()

static uint32_t bl_message_id ( const CanMsgTypeDef_t * message)
static
Here is the caller graph for this function:

◆ bl_message_is_bootloader_traffic()

static bool bl_message_is_bootloader_traffic ( const CanMsgTypeDef_t * message)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bl_physical_size()

static uint32_t bl_physical_size ( uint32_t size_bytes)
static
Here is the caller graph for this function:

◆ BL_poll()

void BL_poll ( void )

Process every frame currently queued by the FDCAN receive interrupt.

Call repeatedly from main context. This function is the sole queue consumer and owns all flash and CRC work; the receive ISR only copies matching frames into the bounded software queue.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ bl_process_message()

static void bl_process_message ( const CanMsgTypeDef_t * message)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bl_process_queued_messages()

static void bl_process_queued_messages ( void )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bl_range_is_valid()

static bool bl_range_is_valid ( uint32_t address,
uint32_t size_bytes )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bl_send_info()

static void bl_send_info ( void )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bl_send_status()

static void bl_send_status ( bootloader_status_t status,
uint32_t detail )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bl_size_is_valid()

static bool bl_size_is_valid ( uint32_t size_bytes)
static
Here is the caller graph for this function:

◆ bl_uint32_data()

static uint32_t bl_uint32_data ( const CanMsgTypeDef_t * message)
static
Here is the caller graph for this function:

◆ bl_vector_is_valid()

static bool bl_vector_is_valid ( uint32_t app_address,
uint32_t size_bytes )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bl_write_metadata()

static bool bl_write_metadata ( uint32_t crc32,
uint32_t size_bytes )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bl_write_word()

static bool bl_write_word ( uint32_t index,
uint32_t word )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PHAL_FDCAN_rxCallback()

void PHAL_FDCAN_rxCallback ( CanMsgTypeDef_t * msg)

Weak callback fired once per received frame.

Called from FDCANx_IT0_IRQHandler (interrupt context) for every frame popped from RX FIFO0.

Default implementation does nothing.

Parameters
msgthe received frame (valid only for the duration of the call)
Here is the call graph for this function:

◆ SysTick_Handler()

void SysTick_Handler ( void )

Variable Documentation

◆ bl_boot_status_requested

bool bl_boot_status_requested
static

◆ bl_firmware_size

uint32_t bl_firmware_size
static

◆ bl_info_sent

bool bl_info_sent
static

◆ bl_last_info_ms

uint32_t bl_last_info_ms
static

◆ bl_millis

volatile uint32_t bl_millis
static

◆ bl_next_word

uint32_t bl_next_word
static

◆ bl_pending_word

uint32_t bl_pending_word
static

◆ bl_pending_word_valid

bool bl_pending_word_valid
static

◆ bl_rx_head

volatile uint8_t bl_rx_head
static

◆ bl_rx_queue

volatile CanMsgTypeDef_t bl_rx_queue[BL_RX_QUEUE_LENGTH]
static

◆ bl_rx_tail

volatile uint8_t bl_rx_tail
static

◆ bl_startup_start_ms

uint32_t bl_startup_start_ms
static

◆ bl_total_words

uint32_t bl_total_words
static

◆ bl_update_active

bool bl_update_active
static

◆ current_state

BLState_t current_state = BL_STATE_STARTUP
static

◆ next_state

BLState_t next_state = BL_STATE_STARTUP
static