renesas-rx: fix build for GCC RX 8.3/14.2

pull/845/head
David Garske 2026-07-24 08:40:34 -07:00 committed by Daniele Lacamera
parent d66d9b119f
commit eaa39be9e4
14 changed files with 92 additions and 27 deletions

13
arch.mk
View File

@ -765,8 +765,7 @@ ifeq ($(ARCH),RENESAS_RX)
CFLAGS+=-ffunction-sections -fdata-sections
CFLAGS+=-B$(dir $(CROSS_COMPILE))
LDFLAGS+=-gc-sections -Map=wolfboot.map
LDFLAGS+=-T $(LSCRIPT) -L$(dir $(CROSS_COMPILE))../lib
LIBS+=-lgcc
LDFLAGS+=-T $(LSCRIPT)
endif
# Renesas specific files
@ -795,10 +794,20 @@ ifeq ($(ARCH),RENESAS_RX)
endif
endif
# ld is invoked directly, so add libgcc for the selected multilib (GNU RX
# stores it per-endianness/-nofpu under lib/gcc/..., not in ../lib).
ifeq ($(USE_GCC),0)
LIBS+=$(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
endif
ifeq ($(PKA),1)
CFLAGS+=-DWOLFBOOT_RENESAS_TSIP
CFLAGS+=-DWOLFBOOT_DEVID_PUBKEY=7890
CFLAGS+=-DWOLFBOOT_DEVID_CRYPT=7891
# GCC RX 14.2 -Werror=enum-conversion trips on the wolfSSL TSIP port; add
# the relaxation only if the compiler knows the warning (RX 8.3 does not).
CFLAGS+=$(shell echo '' | $(CC) -xc -fsyntax-only \
-Wno-error=enum-conversion - >/dev/null 2>&1 && echo -Wno-error=enum-conversion)
RX_DRIVER_PATH?=./lib
OBJS+=$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/cryptocb.o \

View File

@ -3,7 +3,7 @@ TARGET?=rx65n
SIGN?=ECC256
HASH?=SHA256
DEBUG?=0
DEBUG_UART?=0
DEBUG_UART?=1
VTOR?=1
NO_ASM?=0
NO_MPU=1

View File

@ -214,6 +214,14 @@ void uart_write(const char* buf, unsigned int sz)
SCI_TDR(DEBUG_UART_SCI) = c;
}
}
void uart_read(char* buf, unsigned int sz)
{
uint32_t pos = 0;
while (sz-- > 0) {
while ((SCI_SSR(DEBUG_UART_SCI) & SCI_SSR_RDRF) == 0);
buf[pos++] = (char)SCI_RDR(DEBUG_UART_SCI);
}
}
#endif /* DEBUG_UART */
/* LOCO clock is used out of reset */

View File

@ -134,7 +134,9 @@ SECTIONS
_edata = .;
} > RAM
.bss :
/* Pin .bss LMA to its VMA; else it chains past ROM at the top of the
* address space and newer ld errors "LMA wraps around address space". */
.bss (NOLOAD) : AT (ADDR (.bss))
{
_bss = .;
*(.dynbss)

View File

@ -133,7 +133,9 @@ SECTIONS
_edata = .;
} > RAM
.bss :
/* Pin .bss LMA to its VMA; else it chains past ROM at the top of the
* address space and newer ld errors "LMA wraps around address space". */
.bss (NOLOAD) : AT (ADDR (.bss))
{
_bss = .;
*(.dynbss)

View File

@ -39,6 +39,9 @@
void uart_init(void);
#endif
void uart_write(const char* buf, unsigned int sz);
#if defined(__RX__)
void uart_read(char* buf, unsigned int sz);
#endif
/* turn on small printf support in string.c */
#if !defined(PRINTF_ENABLED) && !defined(NO_PRINTF_UART)

View File

@ -198,9 +198,9 @@ extern int tolower(int c);
# if !defined(WOLFBOOT_TPM)
# define NO_ECC_SIGN
# define NO_ECC_DHE
/* For Renesas RX do not enable the misc.c constant time code
* due to issue with 64-bit types */
# if defined(__RX__)
/* Old GNU RX 4.x miscompiled misc.c 64-bit constant-time ops;
* newer RX needs them (sp_int.c uses ctMaskLT). */
# if defined(__RX__) && defined(__GNUC__) && (__GNUC__ < 5)
# define WOLFSSL_NO_CT_OPS /* don't use constant time ops in misc.c */
# endif
# if !defined(WOLFBOOT_ENABLE_WOLFHSM_CLIENT) && \

View File

@ -936,7 +936,8 @@ ifeq ($(DEBUG_SYMBOLS),1)
CFLAGS+=-ggdb3
else ifneq ($(ARCH),AURIX_TC3)
ifneq ($(USE_CLANG),1)
CFLAGS+=-gstabs
# -gstabs was removed in GCC 12; -gdwarf-4 works on old and new GCC
CFLAGS+=-gdwarf-4
endif
endif
endif

View File

@ -127,13 +127,9 @@ __rx_fini:
.global _exit
.type _exit, @function
/* call to exit */
/* main never returns; halt. Don't call newlib __call_exitprocs -- wolfBoot
* does not link libc, so it fails to link on newer binutils. */
_exit:
mov #0, r2
#ifndef NO_LEADING_UNDERSCORE
mov #___call_exitprocs, r7
#endif
jsr r7
_loop_here:
bra _loop_here

View File

@ -99,13 +99,19 @@ else
CFLAGS+=-ggdb3
else ifneq ($(ARCH),AURIX_TC3)
ifneq ($(USE_CLANG),1)
CFLAGS+=-gstabs
# -gstabs was removed in GCC 12; -gdwarf-4 works on old and new GCC
CFLAGS+=-gdwarf-4
endif
endif
ifeq ($(ARCH),RENESAS_RX)
APP_OBJS:=app_renesas_rx.o ../test-app/libwolfboot.o ../src/boot_renesas.o ../src/boot_renesas_start.o ../hal/renesas-rx.o
LDFLAGS+=-ffreestanding -nostartfiles
# -ffreestanding/-nostartfiles are gcc-driver flags. Only pass them when
# linking via gcc (USE_GCC=1); for USE_GCC=0 rx-elf-ld is invoked directly
# and rejects them (-ffreestanding is already in CFLAGS; ld adds no crt).
ifeq ($(USE_GCC),1)
LDFLAGS+=-ffreestanding -nostartfiles
endif
CFLAGS+=-DWOLFBOOT_RENESAS_APP
else ifeq ($(WOLFHAL),1)
APP_OBJS:=app_wolfhal.o led.o system.o timer.o ../test-app/libwolfboot.o
@ -116,6 +122,13 @@ endif
include ../arch.mk
# The Renesas RX app links with ld directly (USE_GCC=0), with no gcc driver to
# pull in newlib. syscalls.o provides a minimal stdio (printf/putchar/snprintf/
# malloc) on top of uart_write, so the app links without libc.
ifeq ($(ARCH),RENESAS_RX)
APP_OBJS+=syscalls.o
endif
ifeq ($(USE_CLANG),1)
APP_NEEDS_STRING:=1
endif
@ -136,8 +149,12 @@ ifeq ($(WOLFCRYPT_TZ_WOLFHSM),1)
WOLFCRYPT_TZ_WOLFHSM=1
endif
# Setup default linker flags
# Setup default linker flags (gcc-driver form). Renesas RX links with ld
# directly (USE_GCC=0) and gets its -T/-gc-sections/oformat from arch.mk, so
# these gcc-driver flags (-Wl,/-nostartfiles and a duplicate -T) are skipped.
ifneq ($(ARCH),RENESAS_RX)
LDFLAGS+=-T $(LSCRIPT) -Wl,-gc-sections -Wl,-Map=image.map -nostartfiles
endif
# Setup default objcopy flags
OBJCOPY_FLAGS+=--gap-fill $(FILL_BYTE)

View File

@ -34,10 +34,26 @@
int write(int fileno, char *buf, int count)
{
(void)fileno;
#ifdef DEBUG_UART
uart_write(buf, count);
#else
(void)buf;
#endif
return count;
}
/* wait for a single key from the UART (used to pause the demo) */
int getchar(void)
{
#ifdef DEBUG_UART
char c = 0;
uart_read(&c, 1);
return (int)(unsigned char)c;
#else
return -1;
#endif
}
static const char* state2str(uint8_t s)
{
switch (s) {
@ -90,7 +106,9 @@ int main(void)
{
uint8_t firmware_version = 0;
#ifdef DEBUG_UART
uart_init();
#endif
#if !defined(WOLFBOOT_RENESAS_TSIP)
printf("| ------------------------------------------------------------------- |\n");

View File

@ -125,6 +125,15 @@ void _exit(int status)
}
}
#if defined(__RX__)
/* GCC emits calls to abort() for trap paths; the RX app links without libc,
* so provide it here (halt). */
void abort(void)
{
_exit(1);
}
#endif
int _kill(int pid, int sig)
{
errno = EINVAL;

View File

@ -72,7 +72,7 @@ int binentry_address_compare(const void* a, const void* b)
}
}
#ifdef _WIN32
#ifdef _MSC_VER
/* 'strerror' has been explicitly marked deprecated */
static const char* win_strerror(int err, char* buf, size_t bufsz) {
if (strerror_s(buf, bufsz, err) != 0) {
@ -83,7 +83,7 @@ static const char* win_strerror(int err, char* buf, size_t bufsz) {
#endif
int main(int argc, const char* argv[]) {
#ifdef _WIN32
#ifdef _MSC_VER
char errbuf[128] = { 0 };
errno_t fe;
#endif
@ -127,7 +127,7 @@ int main(int argc, const char* argv[]) {
entries[i].fname = argv[2 * i + 3];
if (stat(entries[i].fname, &st)) {
#ifdef _WIN32
#ifdef _MSC_VER
fprintf(stderr, "unable to stat %s: %s\n",
entries[i].fname, win_strerror(errno, errbuf, sizeof errbuf));
#else
@ -166,7 +166,7 @@ int main(int argc, const char* argv[]) {
}
// TODO: consider handling stdout "-"
#ifdef _WIN32
#ifdef _MSC_VER
fe = fopen_s(&fo, outname, "wb");
if (fo == NULL || fe != 0) {
fprintf(stderr, "opening %s failed %s\n",
@ -184,7 +184,7 @@ int main(int argc, const char* argv[]) {
cur_add = entries[0].address;
for (i=0; i<num_entries; i++) {
size_t fillSz = entries[i].address - cur_add;
#ifdef _WIN32
#ifdef _MSC_VER
fe = fopen_s(&fi, entries[i].fname, "rb");
if (fi == NULL || fe != 0) {
fprintf(stderr, "opening %s failed %s\n",

View File

@ -1393,11 +1393,11 @@ static int make_header_ex(int is_diff, uint8_t *pubkey, uint32_t pubkey_sz,
off_t chain_file_sz = file_stat.st_size;
if (chain_file_sz < 0) {
printf("Warning: certificate chain file size is invalid "
"(%jd)\n", (intmax_t)chain_file_sz);
"(%" PRIdMAX ")\n", (intmax_t)chain_file_sz);
}
else if ((uintmax_t)chain_file_sz > (uintmax_t)MAX_TLV_LEN) {
printf("Error: Certificate chain too large for TLV encoding "
"(%ju > %u)\n", (uintmax_t)chain_file_sz, MAX_TLV_LEN);
"(%" PRIuMAX " > %u)\n", (uintmax_t)chain_file_sz, MAX_TLV_LEN);
goto failure;
}
else {
@ -1584,7 +1584,7 @@ static int make_header_ex(int is_diff, uint8_t *pubkey, uint32_t pubkey_sz,
if ((file_stat.st_size < 0) ||
((uintmax_t)file_stat.st_size > (uintmax_t)UINT32_MAX)) {
printf("Error: Invalid certificate chain file size (%jd)\n",
printf("Error: Invalid certificate chain file size (%" PRIdMAX ")\n",
(intmax_t)file_stat.st_size);
fclose(f);
f = NULL;
@ -2563,7 +2563,7 @@ static int base_diff(const char *f_base, uint8_t *pubkey, uint32_t pubkey_sz, in
(cc_stat.st_size >= 0)) {
if ((uintmax_t)cc_stat.st_size > (uintmax_t)MAX_TLV_LEN) {
printf("Error: Certificate chain too large for TLV encoding "
"(%ju > %u)\n", (uintmax_t)cc_stat.st_size, MAX_TLV_LEN);
"(%" PRIuMAX " > %u)\n", (uintmax_t)cc_stat.st_size, MAX_TLV_LEN);
goto cleanup;
}
cert_chain_sz = (uint32_t)cc_stat.st_size;