Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
516 changes: 346 additions & 170 deletions IDE/Renesas/e2studio/RA6M4/Readme.md

Large diffs are not rendered by default.

136 changes: 133 additions & 3 deletions IDE/Renesas/e2studio/RA6M4/app_RA/.cproject

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions IDE/Renesas/e2studio/RA6M4/app_RA/.project
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.renesas.cdt.managedbuild.jsoncdb.compilationdatabase.compilationDatabaseBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
Expand All @@ -40,6 +46,7 @@
<nature>com.renesas.cdt.ddsc.contentgen.ddscNature</nature>
<nature>com.renesas.cdt.ra.contentgen.raNature</nature>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
<nature>com.renesas.cdt.managedbuild.jsoncdb.compilationdatabase.CompileCommandsNature</nature>
</natures>
<linkedResources>
<link>
Expand All @@ -52,5 +59,20 @@
<type>1</type>
<locationURI>PARENT-5-PROJECT_LOC/hal/renesas-ra.c</locationURI>
</link>
<link>
<name>src/string.c</name>
<type>1</type>
<locationURI>PARENT-5-PROJECT_LOC/src/string.c</locationURI>
</link>
<link>
<name>src/target.h</name>
<type>1</type>
<locationURI>PARENT-1-PROJECT_LOC/wolfBoot/target.h</locationURI>
</link>
<link>
<name>src/user_settings.h</name>
<type>1</type>
<locationURI>PARENT-1-PROJECT_LOC/wolfBoot/user_settings.h</locationURI>
</link>
</linkedResources>
</projectDescription>
19 changes: 19 additions & 0 deletions IDE/Renesas/e2studio/RA6M4/app_RA/script/fsp.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
Linker File for Renesas FSP
*/

INCLUDE memory_regions.ld

/* wolfBoot override: app must start after wolfBoot bootloader + image header.
* WOLFBOOT_PARTITION_BOOT_ADDRESS = 0x00010000 (64KB wolfBoot)
* IMAGE_HEADER_SIZE = 0x00000200 (512B, RSA2048)
* -> App vector table start = 0x00010200
* This must be placed AFTER INCLUDE memory_regions.ld and BEFORE fsp_gen.ld
* so that fsp_gen.ld's MEMORY block uses the overridden values.
*
* Please comment-out the following two lines when app runs stand-alone.
*/
FLASH_START = 0x00010200;
FLASH_LENGTH = 0x000EFE00;

INCLUDE fsp_gen.ld
76 changes: 59 additions & 17 deletions IDE/Renesas/e2studio/RA6M4/app_RA/src/app_RA.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* Test bare-metal application.
*
* Copyright (C) 2025 wolfSSL Inc.
* Copyright (C) 2026 wolfSSL Inc.
*
* This file is part of wolfBoot.
*
Expand All @@ -29,49 +29,83 @@
#include "hal.h"
#include "hal_data.h"
#include "wolfboot/wolfboot.h"
#include "image.h"

extern bsp_leds_t g_bsp_leds;

void R_BSP_WarmStart(bsp_warm_start_event_t event);
int myprintf(const char * sFormat, ...);

static void blink(int interval)
static const char* state2str(uint8_t s)
{
switch(s) {
case IMG_STATE_NEW: return "New";
case IMG_STATE_UPDATING: return "Updating";
case IMG_STATE_TESTING: return "Testing";
case IMG_STATE_SUCCESS: return "Success";
default: return "Unknown";
}
}

static const char* upFlag2str(uint8_t s)
{
switch(s) {
case SECT_FLAG_NEW: return "New";
case SECT_FLAG_SWAPPING: return "Swapping";
case SECT_FLAG_BACKUP: return "Backup";
case SECT_FLAG_UPDATED: return "Updated";
default: return "Unknown";
}
}

static void blink(int order)
{

int start, end, step;
int i = 0;

/* LED type structure */
bsp_leds_t leds = g_bsp_leds;

#if BSP_TZ_SECURE_BUILD

/* Enter non-secure code */
R_BSP_NonSecureEnter();
#endif

/* Define the units to be used with the software delay function */
const bsp_delay_units_t bsp_delay_units = BSP_DELAY_UNITS_MILLISECONDS * interval;
/* Calculate the delay in terms of bsp_delay_units */
const uint32_t delay = bsp_delay_units / 2;

const bsp_delay_units_t bsp_delay_units = BSP_DELAY_UNITS_MILLISECONDS;
const uint32_t freq = 1;
/* Calculate the delay: 500ms * interval per LED write */
const uint32_t delay = (uint32_t)(bsp_delay_units / (freq * 2));

/* Holds level to set for pins */
bsp_io_level_t pin_level = BSP_IO_LEVEL_LOW;
start = 0;
end = leds.led_count;
step = (order == -1)? -1 : 1;

if (order == -1) {
start = end - 1;
end = -1;
}

while (1)
{
/* Enable access to the PFS registers */
R_BSP_PinAccessEnable();


/* Update each LEDs*/
for (uint32_t i = 0; i < leds.led_count; i++)
i = start;
for (;;)
{
if (i == end) break;
/* Get pin to toggle */
uint32_t pin = leds.p_leds[i];

/* Write to this pin */
R_BSP_PinWrite((bsp_io_port_pin_t) pin, pin_level);

/* Delay */
R_BSP_SoftwareDelay(delay, bsp_delay_units);
i += step;
}

/* Protect PFS registers */
Expand All @@ -84,6 +118,8 @@ static void blink(int interval)
else {
pin_level = BSP_IO_LEVEL_LOW;
}
/* Delay */
R_BSP_SoftwareDelay(delay, bsp_delay_units);
}
}

Expand All @@ -96,15 +132,20 @@ static void printPart(uint8_t *part)
uint8_t *magic;
uint8_t state;
uint32_t ver;
uint8_t upflag;

magic = part;
myprintf("Magic: %c%c%c%c\n", magic[0], magic[1], magic[2], magic[3]);
ver = wolfBoot_get_blob_version(part);
myprintf("Version: %02x\n", ver);
state = *(part + WOLFBOOT_PARTITION_SIZE - sizeof(uint32_t) - 1);
myprintf("Status: %02x\n", state);
wolfBoot_get_partition_state(0, &state);
myprintf("Status: %02x(%s)\n", state, state2str(state));
magic = part + WOLFBOOT_PARTITION_SIZE - sizeof(uint32_t);
myprintf("Trailer Magic: %c%c%c%c\n", magic[0], magic[1], magic[2], magic[3]);
if (magic[0] != 0x42)
magic = part + WOLFBOOT_PARTITION_SIZE - WOLFBOOT_SECTOR_SIZE - sizeof(uint32_t);
myprintf("Trailer Mgc: %c%c%c%c\n", magic[0], magic[1], magic[2], magic[3]);
wolfBoot_get_update_sector_flag(0, &upflag);
myprintf("Update flag: %02x (%s)\n", upflag, upFlag2str(upflag));

#ifdef WOLFBOOT_DEBUG_PARTION
v = (uint32_t *)part;
Expand All @@ -130,6 +171,7 @@ void app_RA(void)
uint8_t firmware_version = 0;

R_BSP_WarmStart(BSP_WARM_START_POST_C);
SystemCoreClockUpdate();

hal_init();

Expand Down Expand Up @@ -175,13 +217,13 @@ void app_RA(void)

if (firmware_version == 1) {
wolfBoot_update_trigger();
blink(1);
blink(-1);
}
else if (firmware_version == 2) {
blink(5);
blink(1);
}
/* busy wait */
busy_idle:
/* flashing LEDs in busy */
blink(1);
blink(-1);
}
63 changes: 0 additions & 63 deletions IDE/Renesas/e2studio/RA6M4/app_RA/src/hal_entry.c

This file was deleted.

58 changes: 58 additions & 0 deletions IDE/Renesas/e2studio/RA6M4/app_RA/src/wolfboot_startup.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* wolfboot_startup.c
*
* Copyright (C) 2026 wolfSSL Inc.
*
* This file is part of wolfBoot.
*
* wolfBoot is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* wolfBoot is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
/*
wolfBoot-specific early startup code for RA6M4 application.
*
* When this application is booted by wolfBoot, wolfBoot's own RAM functions
* occupy 0x20000000-0x20001188 with a DIFFERENT layout than this application
* expects. The C runtime startup (SystemRuntimeInit) tries to call memcpy()
* at the address this application was linked to, but that address contains
* wolfBoot's code, not the application's memcpy, causing an immediate crash.
*
* wolfboot_pre_init() must be called from R_BSP_WarmStart(BSP_WARM_START_RESET)
* BEFORE SystemRuntimeInit runs. It copies the __ram_from_flash$$ section
* using a plain word loop (no library memcpy) so that the application's RAM
* functions are placed at their correct VMA addresses. SystemRuntimeInit will
* then redundantly copy the same data, but by that point memcpy is valid.
*/
#include <stdint.h>

/**
* Copy __ram_from_flash$$ section to its VMA before SystemRuntimeInit runs.
*
* Call this from R_BSP_WarmStart(BSP_WARM_START_RESET), which fires inside
* SystemInit() BEFORE SystemRuntimeInit() is called.
*/
void wolfboot_pre_init(void)
{
extern uint32_t __ram_from_flash$$Base;
extern uint32_t __ram_from_flash$$Limit;
extern uint32_t __ram_from_flash$$Load;

volatile uint32_t *dst = &__ram_from_flash$$Base;
volatile const uint32_t *src = (const uint32_t *)(&__ram_from_flash$$Load);
volatile const uint32_t *end = &__ram_from_flash$$Limit;

while (dst < end)
{
*dst++ = *src++;
}
}
Loading