ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
main.c File Reference

Copy-to-run HIL demo: launch one embedded image at the SRAM run base. More...

#include <stdint.h>
#include <string.h>
#include "payload_image.h"
#include "ra8_attributes.h"
#include "ra8_boot_entry.h"
#include "ra8_dfu.h"
Include dependency graph for main.c:

Go to the source code of this file.

Enumerations

enum  dcr_vt_t : uint32_t {
  k_dcr_sram_mask = 0xFF000000U ,
  k_dcr_sram_base = 0x22000000U ,
  k_dcr_thumb_bit = 0x00000001U
}
 Sanity-check masks for the embedded image's vector table. More...
enum  dcr_probe_t : uintptr_t {
  k_dcr_probe_sentinel_addr = 0x22010000U ,
  k_dcr_probe_counter_addr = 0x22010004U
}
 Fixed SRAM probe-word addresses the copied-to-run payload writes. More...

Functions

static void internal_dcr_panic_halt (void)
 Park forever in WFI – copy-to-run did not happen (alive gate fails).
void main (void)
 Entry: launch the embedded copy-to-run image; never returns on success.

Variables

volatile uint32_t g_dcr_run_sentinel
 Memprobe anchor for the payload's proof-of-run sentinel (0x22010000).
volatile uint32_t g_dcr_run_heartbeat
 Memprobe liveness counter the copied-to-run payload advances (0x22010004).

Detailed Description

Copy-to-run HIL demo: launch one embedded image at the SRAM run base.

Tag
[Ring 6 / APP] {World: S}

The unattended, self-contained proof of the dfu_bootloader's copy-to-run scheme (issue #97): an image linked ONCE at the SRAM run base (k_ra8_dfu_run_base) runs from wherever it is staged, with no per-slot build.

This app embeds that image (payload_image.h, generated from payload.c by examples/ek_ra8d2/hw_validated/hil/dfu_copy_to_run/scripts/build_payload.sh) and hands it to the shared ra8_dfu_launch – the exact launcher the bootloader uses for a validated slot. ra8_dfu_launch copies the image to k_ra8_dfu_run_base and branches there; the payload then spins in the SRAM run window forever (writing a sentinel + heartbeat at a fixed probe word).

How HIL verifies it (alive gate)

hil.conf is HIL_MODE=alive. After the hand-off the PC lives in the SRAM copy-to-run window (0x22020000+) – a region only reachable BY copying-to-run and branching there, since this app's own code is in MRAM. So "PC in the SRAM run window, CycleCnt advancing, CFSR/HFSR clean, not in a fault spinner" is a specific proof that copy-to-run executed. If the launch's run-target check fails (it never should: a fixed run base + a valid length), control returns and parks in internal_dcr_panic_halt, which the alive gate flags as a fault spinner.

Unlike the bootloader's alive gate (which can also pass via the DFU-device fallback when no slot is valid), this app ALWAYS copies-to-run, so its alive pass is unambiguous.

Author
Brighton Sikarskie
Date
2026-06-16
Since
0.1.0

Definition in file main.c.

Enumeration Type Documentation

◆ dcr_probe_t

enum dcr_probe_t : uintptr_t

Fixed SRAM probe-word addresses the copied-to-run payload writes.

Mirror of payload.c's k_payload_probe_sentinel / k_payload_probe_counter. Once ra8_dfu_launch branches into it, the payload (running from the SRAM run window) writes a proof-of-run sentinel and a free-running heartbeat at these two fixed words. They sit above this app's low-SRAM .bss/.data and below the run base (0x22020000), so neither this app nor the payload image overwrites them. linker_script.ld pins g_dcr_run_sentinel / g_dcr_run_heartbeat here so the J-Link memprobe gate (HIL_MODE=jlink_memprobe) can resolve the heartbeat by name.

Enumerator
k_dcr_probe_sentinel_addr 

Sentinel word address.

k_dcr_probe_counter_addr 

Heartbeat word address.

Definition at line 72 of file main.c.

◆ dcr_vt_t

enum dcr_vt_t : uint32_t

Sanity-check masks for the embedded image's vector table.

Enumerator
k_dcr_sram_mask 

Top byte of an SRAM address.

k_dcr_sram_base 

SRAM window base (initial-SP check).

k_dcr_thumb_bit 

Reset vector must carry the Thumb bit.

Definition at line 53 of file main.c.

Function Documentation

◆ internal_dcr_panic_halt()

void internal_dcr_panic_halt ( void )
static

Park forever in WFI – copy-to-run did not happen (alive gate fails).

Returns
Does not return.
Precondition
Reached only when ra8_dfu_launch returned (run-target check failed).
Interrupts are in any state.
Postcondition
The CPU spins; the alive gate sees a fault-spinner PC and fails.
No further app code runs.
Note
Named *panic_halt so the HIL alive gate's fault-spinner check matches.
Since
0.1.0

Definition at line 113 of file main.c.

References RA8_INTERNAL.

Referenced by main().

◆ main()

void main ( void )

Entry: launch the embedded copy-to-run image; never returns on success.

The application entry point Reset_Handler hands control to.

Precondition
Reset_Handler copied .data and zeroed .bss; SystemInit ran.
The embedded image's first two words are a valid MSP + Thumb reset vector.
Postcondition
On success, control is at the image's reset vector in the SRAM run window.
On a failed run-target check, control parks in internal_dcr_panic_halt.
Note
Single entry point; not re-entrant.
Since
0.1.0

Definition at line 130 of file main.c.

References g_dcr_run_heartbeat, g_dcr_run_sentinel, internal_dcr_panic_halt(), k_dcr_probe_counter_addr, k_dcr_probe_sentinel_addr, k_dcr_sram_base, k_dcr_sram_mask, k_dcr_thumb_bit, k_ra8_dfu_run_base, memcpy(), ra8_dfu_launch(), and s_payload_image.

Variable Documentation

◆ g_dcr_run_heartbeat

volatile uint32_t g_dcr_run_heartbeat

Memprobe liveness counter the copied-to-run payload advances (0x22010004).

A reserved 4-byte word pinned by linker_script.ld to k_dcr_probe_counter_addr. The payload increments the word at this address forever once copy-to-run branches into it, so hil_jlink_memprobe.sh sees it advance – proof the image ran via copy-to-run (the only writer of this word). This app reserves the word but never writes it.

Warning
Written exclusively by the SRAM-resident payload, never by this app.
Since
0.1.0

Definition at line 101 of file main.c.

Referenced by main().

◆ g_dcr_run_sentinel

volatile uint32_t g_dcr_run_sentinel

Memprobe anchor for the payload's proof-of-run sentinel (0x22010000).

A reserved 4-byte word pinned by linker_script.ld to k_dcr_probe_sentinel_addr. This app never touches it – the copied-to-run payload writes k_payload_sentinel_value here. It exists only so nm can resolve a named symbol at the sentinel word.

Warning
Written exclusively by the SRAM-resident payload, never by this app.
Since
0.1.0

Definition at line 87 of file main.c.

Referenced by main().