Skip to content

File syn_fwboot.h

FileList > src > syntropic > system > syn_fwboot.h

Go to the source code of this file

A/B firmware boot manager — slot selection, rollback, confirm. More...

  • #include "../common/syn_defs.h"
  • #include "syn_fwimage.h"
  • #include <stdbool.h>
  • #include <stdint.h>

Classes

Type Name
struct SYN_FwBootManager
A/B firmware boot manager — slot selection and rollback state.

Public Functions

Type Name
SYN_Status syn_fwboot_confirm (SYN_FwBootManager * mgr)
Confirm the currently active slot as good.
SYN_Status syn_fwboot_init (SYN_FwBootManager * mgr, uint32_t slot_a, uint32_t slot_b)
Initialize the boot manager.
SYN_Status syn_fwboot_refresh (SYN_FwBootManager * mgr)
Reload slot headers from flash.
uint8_t syn_fwboot_select (SYN_FwBootManager * mgr, bool rollback)
Select the best slot to boot.

Public Static Functions

Type Name
uint8_t syn_fwboot_active_slot (const SYN_FwBootManager * mgr)
Get the currently active slot.
uint32_t syn_fwboot_slot_addr (const SYN_FwBootManager * mgr, uint8_t slot)
Get the flash base address of a slot.
const SYN_FwImageHeader * syn_fwboot_slot_header (const SYN_FwBootManager * mgr, uint8_t slot)
Get the cached header for a slot.

Macros

Type Name
define SYN_FW_SLOT_A 0
define SYN_FW_SLOT_B 1
define SYN_FW_SLOT_NONE 0xFF

Detailed Description

Works with syn_fwimage headers to manage dual firmware slots. Integrates with syn_boot for crash-loop detection.

** **

  • Bootloader reads both slot headers
  • syn_fwboot_select() picks the best slot to boot
  • If selected slot is NEW → mark as TESTING before jumping
  • Application calls syn_fwboot_confirm() after healthy startup
  • If boot fails → next boot sees TESTING + unhealthy → rollback

** **

SYN_FwBootManager mgr;
syn_fwboot_init(&mgr, SLOT_A_ADDR, SLOT_B_ADDR);

// In bootloader: pick which slot to run
uint8_t slot = syn_fwboot_select(&mgr);
uint32_t entry = syn_fwboot_slot_addr(&mgr, slot)
                 + sizeof(SYN_FwImageHeader);
// Jump to entry...

// In application: after successful startup
syn_fwboot_confirm(&mgr);

Public Functions Documentation

function syn_fwboot_confirm

Confirm the currently active slot as good.

SYN_Status syn_fwboot_confirm (
    SYN_FwBootManager * mgr
) 

Promotes state from TESTING to CONFIRMED. Call after the application has started successfully (after syn_boot_mark_healthy).

Parameters:

  • mgr Boot manager.

Returns:

SYN_OK if confirmed, SYN_ERROR if not in TESTING state.


function syn_fwboot_init

Initialize the boot manager.

SYN_Status syn_fwboot_init (
    SYN_FwBootManager * mgr,
    uint32_t slot_a,
    uint32_t slot_b
) 

Reads image headers from both slots.

Parameters:

  • mgr Boot manager instance.
  • slot_a Flash base address of slot A.
  • slot_b Flash base address of slot B.

Returns:

SYN_OK on success.


function syn_fwboot_refresh

Reload slot headers from flash.

SYN_Status syn_fwboot_refresh (
    SYN_FwBootManager * mgr
) 

Call after an OTA update to refresh the cached state.

Parameters:

  • mgr Boot manager.

Returns:

SYN_OK on success.


function syn_fwboot_select

Select the best slot to boot.

uint8_t syn_fwboot_select (
    SYN_FwBootManager * mgr,
    bool rollback
) 

Priority: * TESTING slot (continue testing a new image) * NEW slot (first boot of a new image — marks as TESTING) * CONFIRMED slot with highest version * Any CONFIRMED slot

If a TESTING slot failed (called with rollback=true), it's marked INVALID and the other CONFIRMED slot is selected.

Parameters:

  • mgr Boot manager.
  • rollback true if the previous boot was unhealthy (trigger rollback).

Returns:

Slot index (SYN_FW_SLOT_A or SYN_FW_SLOT_B), or SYN_FW_SLOT_NONE.


Public Static Functions Documentation

function syn_fwboot_active_slot

Get the currently active slot.

static inline uint8_t syn_fwboot_active_slot (
    const SYN_FwBootManager * mgr
) 

Parameters:

  • mgr Boot manager.

Returns:

Active slot index.


function syn_fwboot_slot_addr

Get the flash base address of a slot.

static inline uint32_t syn_fwboot_slot_addr (
    const SYN_FwBootManager * mgr,
    uint8_t slot
) 

Parameters:

  • mgr Boot manager.
  • slot Slot index (SYN_FW_SLOT_A or SYN_FW_SLOT_B).

Returns:

Flash base address, or 0 if invalid slot.


function syn_fwboot_slot_header

Get the cached header for a slot.

static inline const SYN_FwImageHeader * syn_fwboot_slot_header (
    const SYN_FwBootManager * mgr,
    uint8_t slot
) 

Parameters:

  • mgr Boot manager.
  • slot Slot index.

Returns:

Pointer to cached header, or NULL if invalid slot.


Macro Definition Documentation

define SYN_FW_SLOT_A

#define SYN_FW_SLOT_A `0`

Firmware slot A index.


define SYN_FW_SLOT_B

#define SYN_FW_SLOT_B `1`

Firmware slot B index.


define SYN_FW_SLOT_NONE

#define SYN_FW_SLOT_NONE `0xFF`

No valid slot.



The documentation for this class was generated from the following file src/syntropic/system/syn_fwboot.h