Skip to content

Commit 74565a3

Browse files
authored
Merge pull request #710 from miyazakh/update_ra6m4
Update Renesas RA6M4 port
2 parents c737d80 + 4b9b7bc commit 74565a3

File tree

17 files changed

+1408
-596
lines changed

17 files changed

+1408
-596
lines changed

IDE/Renesas/e2studio/RA6M4/Readme.md

Lines changed: 346 additions & 170 deletions
Large diffs are not rendered by default.

IDE/Renesas/e2studio/RA6M4/app_RA/.cproject

Lines changed: 133 additions & 3 deletions
Large diffs are not rendered by default.

IDE/Renesas/e2studio/RA6M4/app_RA/.project

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
<arguments>
3333
</arguments>
3434
</buildCommand>
35+
<buildCommand>
36+
<name>com.renesas.cdt.managedbuild.jsoncdb.compilationdatabase.compilationDatabaseBuilder</name>
37+
<triggers>full,incremental,</triggers>
38+
<arguments>
39+
</arguments>
40+
</buildCommand>
3541
</buildSpec>
3642
<natures>
3743
<nature>org.eclipse.cdt.core.cnature</nature>
@@ -40,6 +46,7 @@
4046
<nature>com.renesas.cdt.ddsc.contentgen.ddscNature</nature>
4147
<nature>com.renesas.cdt.ra.contentgen.raNature</nature>
4248
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
49+
<nature>com.renesas.cdt.managedbuild.jsoncdb.compilationdatabase.CompileCommandsNature</nature>
4350
</natures>
4451
<linkedResources>
4552
<link>
@@ -52,5 +59,20 @@
5259
<type>1</type>
5360
<locationURI>PARENT-5-PROJECT_LOC/hal/renesas-ra.c</locationURI>
5461
</link>
62+
<link>
63+
<name>src/string.c</name>
64+
<type>1</type>
65+
<locationURI>PARENT-5-PROJECT_LOC/src/string.c</locationURI>
66+
</link>
67+
<link>
68+
<name>src/target.h</name>
69+
<type>1</type>
70+
<locationURI>PARENT-1-PROJECT_LOC/wolfBoot/target.h</locationURI>
71+
</link>
72+
<link>
73+
<name>src/user_settings.h</name>
74+
<type>1</type>
75+
<locationURI>PARENT-1-PROJECT_LOC/wolfBoot/user_settings.h</locationURI>
76+
</link>
5577
</linkedResources>
5678
</projectDescription>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
Linker File for Renesas FSP
3+
*/
4+
5+
INCLUDE memory_regions.ld
6+
7+
/* wolfBoot override: app must start after wolfBoot bootloader + image header.
8+
* WOLFBOOT_PARTITION_BOOT_ADDRESS = 0x00010000 (64KB wolfBoot)
9+
* IMAGE_HEADER_SIZE = 0x00000200 (512B, RSA2048)
10+
* -> App vector table start = 0x00010200
11+
* This must be placed AFTER INCLUDE memory_regions.ld and BEFORE fsp_gen.ld
12+
* so that fsp_gen.ld's MEMORY block uses the overridden values.
13+
*
14+
* Please comment-out the following two lines when app runs stand-alone.
15+
*/
16+
FLASH_START = 0x00010200;
17+
FLASH_LENGTH = 0x000EFE00;
18+
19+
INCLUDE fsp_gen.ld

IDE/Renesas/e2studio/RA6M4/app_RA/src/app_RA.c

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* Test bare-metal application.
44
*
5-
* Copyright (C) 2025 wolfSSL Inc.
5+
* Copyright (C) 2026 wolfSSL Inc.
66
*
77
* This file is part of wolfBoot.
88
*
@@ -29,49 +29,83 @@
2929
#include "hal.h"
3030
#include "hal_data.h"
3131
#include "wolfboot/wolfboot.h"
32+
#include "image.h"
3233

3334
extern bsp_leds_t g_bsp_leds;
3435

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

38-
static void blink(int interval)
39+
static const char* state2str(uint8_t s)
3940
{
41+
switch(s) {
42+
case IMG_STATE_NEW: return "New";
43+
case IMG_STATE_UPDATING: return "Updating";
44+
case IMG_STATE_TESTING: return "Testing";
45+
case IMG_STATE_SUCCESS: return "Success";
46+
default: return "Unknown";
47+
}
48+
}
49+
50+
static const char* upFlag2str(uint8_t s)
51+
{
52+
switch(s) {
53+
case SECT_FLAG_NEW: return "New";
54+
case SECT_FLAG_SWAPPING: return "Swapping";
55+
case SECT_FLAG_BACKUP: return "Backup";
56+
case SECT_FLAG_UPDATED: return "Updated";
57+
default: return "Unknown";
58+
}
59+
}
60+
61+
static void blink(int order)
62+
{
63+
64+
int start, end, step;
65+
int i = 0;
4066

4167
/* LED type structure */
4268
bsp_leds_t leds = g_bsp_leds;
4369

4470
#if BSP_TZ_SECURE_BUILD
45-
4671
/* Enter non-secure code */
4772
R_BSP_NonSecureEnter();
4873
#endif
4974

5075
/* Define the units to be used with the software delay function */
51-
const bsp_delay_units_t bsp_delay_units = BSP_DELAY_UNITS_MILLISECONDS * interval;
52-
/* Calculate the delay in terms of bsp_delay_units */
53-
const uint32_t delay = bsp_delay_units / 2;
54-
76+
const bsp_delay_units_t bsp_delay_units = BSP_DELAY_UNITS_MILLISECONDS;
77+
const uint32_t freq = 1;
78+
/* Calculate the delay: 500ms * interval per LED write */
79+
const uint32_t delay = (uint32_t)(bsp_delay_units / (freq * 2));
80+
5581
/* Holds level to set for pins */
5682
bsp_io_level_t pin_level = BSP_IO_LEVEL_LOW;
83+
start = 0;
84+
end = leds.led_count;
85+
step = (order == -1)? -1 : 1;
86+
87+
if (order == -1) {
88+
start = end - 1;
89+
end = -1;
90+
}
5791

5892
while (1)
5993
{
6094
/* Enable access to the PFS registers */
6195
R_BSP_PinAccessEnable();
6296

63-
6497
/* Update each LEDs*/
65-
for (uint32_t i = 0; i < leds.led_count; i++)
98+
i = start;
99+
for (;;)
66100
{
101+
if (i == end) break;
67102
/* Get pin to toggle */
68103
uint32_t pin = leds.p_leds[i];
69-
70104
/* Write to this pin */
71105
R_BSP_PinWrite((bsp_io_port_pin_t) pin, pin_level);
72106

73-
/* Delay */
74107
R_BSP_SoftwareDelay(delay, bsp_delay_units);
108+
i += step;
75109
}
76110

77111
/* Protect PFS registers */
@@ -84,6 +118,8 @@ static void blink(int interval)
84118
else {
85119
pin_level = BSP_IO_LEVEL_LOW;
86120
}
121+
/* Delay */
122+
R_BSP_SoftwareDelay(delay, bsp_delay_units);
87123
}
88124
}
89125

@@ -96,15 +132,20 @@ static void printPart(uint8_t *part)
96132
uint8_t *magic;
97133
uint8_t state;
98134
uint32_t ver;
135+
uint8_t upflag;
99136

100137
magic = part;
101138
myprintf("Magic: %c%c%c%c\n", magic[0], magic[1], magic[2], magic[3]);
102139
ver = wolfBoot_get_blob_version(part);
103140
myprintf("Version: %02x\n", ver);
104-
state = *(part + WOLFBOOT_PARTITION_SIZE - sizeof(uint32_t) - 1);
105-
myprintf("Status: %02x\n", state);
141+
wolfBoot_get_partition_state(0, &state);
142+
myprintf("Status: %02x(%s)\n", state, state2str(state));
106143
magic = part + WOLFBOOT_PARTITION_SIZE - sizeof(uint32_t);
107-
myprintf("Trailer Magic: %c%c%c%c\n", magic[0], magic[1], magic[2], magic[3]);
144+
if (magic[0] != 0x42)
145+
magic = part + WOLFBOOT_PARTITION_SIZE - WOLFBOOT_SECTOR_SIZE - sizeof(uint32_t);
146+
myprintf("Trailer Mgc: %c%c%c%c\n", magic[0], magic[1], magic[2], magic[3]);
147+
wolfBoot_get_update_sector_flag(0, &upflag);
148+
myprintf("Update flag: %02x (%s)\n", upflag, upFlag2str(upflag));
108149

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

132173
R_BSP_WarmStart(BSP_WARM_START_POST_C);
174+
SystemCoreClockUpdate();
133175

134176
hal_init();
135177

@@ -175,13 +217,13 @@ void app_RA(void)
175217

176218
if (firmware_version == 1) {
177219
wolfBoot_update_trigger();
178-
blink(1);
220+
blink(-1);
179221
}
180222
else if (firmware_version == 2) {
181-
blink(5);
223+
blink(1);
182224
}
183225
/* busy wait */
184226
busy_idle:
185227
/* flashing LEDs in busy */
186-
blink(1);
228+
blink(-1);
187229
}

IDE/Renesas/e2studio/RA6M4/app_RA/src/hal_entry.c

Lines changed: 0 additions & 63 deletions
This file was deleted.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/* wolfboot_startup.c
2+
*
3+
* Copyright (C) 2026 wolfSSL Inc.
4+
*
5+
* This file is part of wolfBoot.
6+
*
7+
* wolfBoot is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation; either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* wolfBoot is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20+
*/
21+
/*
22+
wolfBoot-specific early startup code for RA6M4 application.
23+
*
24+
* When this application is booted by wolfBoot, wolfBoot's own RAM functions
25+
* occupy 0x20000000-0x20001188 with a DIFFERENT layout than this application
26+
* expects. The C runtime startup (SystemRuntimeInit) tries to call memcpy()
27+
* at the address this application was linked to, but that address contains
28+
* wolfBoot's code, not the application's memcpy, causing an immediate crash.
29+
*
30+
* wolfboot_pre_init() must be called from R_BSP_WarmStart(BSP_WARM_START_RESET)
31+
* BEFORE SystemRuntimeInit runs. It copies the __ram_from_flash$$ section
32+
* using a plain word loop (no library memcpy) so that the application's RAM
33+
* functions are placed at their correct VMA addresses. SystemRuntimeInit will
34+
* then redundantly copy the same data, but by that point memcpy is valid.
35+
*/
36+
#include <stdint.h>
37+
38+
/**
39+
* Copy __ram_from_flash$$ section to its VMA before SystemRuntimeInit runs.
40+
*
41+
* Call this from R_BSP_WarmStart(BSP_WARM_START_RESET), which fires inside
42+
* SystemInit() BEFORE SystemRuntimeInit() is called.
43+
*/
44+
void wolfboot_pre_init(void)
45+
{
46+
extern uint32_t __ram_from_flash$$Base;
47+
extern uint32_t __ram_from_flash$$Limit;
48+
extern uint32_t __ram_from_flash$$Load;
49+
50+
volatile uint32_t *dst = &__ram_from_flash$$Base;
51+
volatile const uint32_t *src = (const uint32_t *)(&__ram_from_flash$$Load);
52+
volatile const uint32_t *end = &__ram_from_flash$$Limit;
53+
54+
while (dst < end)
55+
{
56+
*dst++ = *src++;
57+
}
58+
}

0 commit comments

Comments
 (0)