Skip to content

Commit

Permalink
Fix test-app entry point and setup/relocate exception and reset vectors.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgarske committed Apr 8, 2024
1 parent 790e8f8 commit df49241
Show file tree
Hide file tree
Showing 7 changed files with 227 additions and 33 deletions.
4 changes: 2 additions & 2 deletions config/examples/renesas-rx65n.config
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ DUALBANK_SWAP?=0
# Optionally switch to big endian data if MDE is set
#BIG_ENDIAN=1

# Flash is 2MB with 64KB sector size
WOLFBOOT_SECTOR_SIZE?=0x10000
# Flash is 2MB with 32KB sector size
WOLFBOOT_SECTOR_SIZE?=0x8000

# wolfBoot is last sector of flash and includes vector tables
WOLFBOOT_ORIGIN=0xFFFF0000
Expand Down
3 changes: 2 additions & 1 deletion docs/Targets.md
Original file line number Diff line number Diff line change
Expand Up @@ -1869,7 +1869,7 @@ Boot partition: 0xFFE00000
Image size 27108
```

Default Onboard Flash Memory Layout (2MB) (64KB sector):
Default Onboard Flash Memory Layout (2MB) (32KB sector):

| Description | Address | Size |
| ----------------- | ---------- | ------------------- |
Expand All @@ -1895,6 +1895,7 @@ Building RX wolfBoot requires the RX-ELF compiler. Please Download and install t
https://llvm-gcc-renesas.com/rx-download-toolchains/

Default installation path (Linux): `~/toolchains/gcc_8.3.0.202311_rx_elf`
Default installation path (Windows): `C:\ProgramData\GCC for Renesas RX 8.3.0.202305-GNURX-ELF\rx-elf\rx-elf`

Configuration:
Use `./config/examples/renesas-rx65n.config` as a starting point by copying it to the wolfBoot root as `.config`.
Expand Down
12 changes: 7 additions & 5 deletions hal/renesas-rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "hal.h"
#include "renesas-rx.h"

#include "r_flash_rx_if.h"
#include "r_flash_rx.h"

#if defined(WOLFBOOT_RENESAS_TSIP) && \
Expand All @@ -55,9 +56,7 @@ void hal_init(void)
int err;
uint32_t key_type = 0;
int tsip_key_type = -1;
/* retrive installed pubkey data from flash */
struct rsa2048_pub *encrypted_user_key_data =
(struct rsa2048_pub*)keystore_get_buffer(0);
struct rsa2048_pub *encrypted_user_key_data;
#endif

if(R_FLASH_Open() != FLASH_SUCCESS)
Expand All @@ -71,6 +70,9 @@ void hal_init(void)
hal_panic();
}

/* retrive installed pubkey data from flash */
encrypted_user_key_data = (struct rsa2048_pub*)keystore_get_buffer(0);

key_type = keystore_get_key_type(0);
switch(key_type){

Expand Down Expand Up @@ -146,7 +148,7 @@ int hal_flash_write(uint32_t addr, const uint8_t *data, int len)
uint32_t save_len = 0;

if(addr != ALIGN_FLASH(addr)) {
save_len = (addr - ALIGN_FLASH(addr)) < len ? (addr - ALIGN_FLASH(addr)) : len;
save_len = (addr - ALIGN_FLASH(addr)) < (uint32_t)len ? (addr - ALIGN_FLASH(addr)) : (uint32_t)len;
memcpy(save, (const void *)ALIGN_FLASH(addr), MIN_PROG);
memcpy(save + (addr - ALIGN_FLASH(addr)), data, save_len);
addr = ALIGN_FLASH(addr);
Expand Down Expand Up @@ -200,7 +202,7 @@ void RAMFUNCTION hal_flash_unlock(void)
{
flash_access_window_config_t info;

info.start_addr = (uint32_t) FLASH_CF_BLOCK_132;
info.start_addr = (uint32_t) FLASH_CF_BLOCK_INVALID;
info.end_addr = (uint32_t) FLASH_CF_BLOCK_0;
R_BSP_InterruptsDisable();
if(R_FLASH_Control(FLASH_CMD_ACCESSWINDOW_SET, (void *)&info)
Expand Down
1 change: 0 additions & 1 deletion src/boot_renesas.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/

#include <stdint.h>
#include <wolfssl/wolfcrypt/settings.h>
#include "wolfboot/wolfboot.h"
#include "hal.h"

Expand Down
6 changes: 3 additions & 3 deletions test-app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ ifeq ($(TARGET),ti_hercules)
APP_OBJS:=app_$(TARGET).o ../test-app/libwolfboot.o
CFLAGS+=-I"../include"
else
CFLAGS+=-g -ggdb -Wall -Wstack-usage=1024 -ffreestanding -Wno-unused -DPLATFORM_$(TARGET) -I../include -nostartfiles
ifeq ($(ARCH),RENESAS_RX)
CFLAGS+=-g -ggdb -Wall -Wno-unused -DPLATFORM_$(TARGET) -I../include
APP_OBJS:=app_renesas_rx.o ../test-app/libwolfboot.o
APP_OBJS:=app_renesas_rx.o ../test-app/libwolfboot.o ../src/boot_renesas.o ../src/boot_renesas_start.o
LDFLAGS+=-ffreestanding -nostartfiles
else
CFLAGS+=-g -ggdb -Wall -Wstack-usage=1024 -ffreestanding -Wno-unused -DPLATFORM_$(TARGET) -I../include -nostartfiles
APP_OBJS:=app_$(TARGET).o led.o system.o timer.o ../test-app/libwolfboot.o
endif
endif
Expand Down
83 changes: 62 additions & 21 deletions test-app/RENESAS_RX.ld
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
OUTPUT_ARCH(rx)
ENTRY(_start)
ENTRY(_PowerON_Reset)

MEMORY
{
RAM : ORIGIN = 0x0, LENGTH = 262144 - 16384
RAM : ORIGIN = 0x0, LENGTH = 262144
RAM2 : ORIGIN = 0x00800000, LENGTH = 393216
ROM : ORIGIN = @WOLFBOOT_TEST_APP_ADDRESS@ /* 0xFFE00000 */, LENGTH = @WOLFBOOT_TEST_APP_SIZE@ /* 2097152 */
ROM : ORIGIN = @WOLFBOOT_TEST_APP_ADDRESS@, LENGTH = @WOLFBOOT_TEST_APP_SIZE@
OFS : ORIGIN = 0xFE7F5D00, LENGTH = 128
}

SECTIONS
{
.fvectors :
{
KEEP(*(.fvectors))
} > ROM

.exvectors :
{
KEEP(*(.exvectors))
} > ROM

.rvectors :
{
_rvectors_start = .;
KEEP(*(.rvectors))
_rvectors_end = .;
} > ROM

.text :
{
PROVIDE (_start = .);
*(.text)
*(.text.*)
*(P)
Expand Down Expand Up @@ -93,18 +109,10 @@ SECTIONS
__DTOR_END__ = .;
. = ALIGN(2);
_mdata = .;
PROVIDE(__romdatastart = .);
} > ROM

.vectors :
{
PROVIDE (__vectors = .);
} > ROM

.data : AT(_mdata)
{
. = ALIGN(4);
PROVIDE (__datastart = .);
_data = .;
*(.data)
*(.data.*)
Expand All @@ -113,12 +121,9 @@ SECTIONS
*(D_2)
_edata = .;
} > RAM
PROVIDE (__romdatacopysize = SIZEOF(.data));

.bss :
{
. = ALIGN(4);
PROVIDE (__bssstart = .);
_bss = .;
*(.bss)
*(.bss.**)
Expand All @@ -130,12 +135,48 @@ SECTIONS
. = ALIGN(128);
_end = .;
} > RAM
PROVIDE (__bsssize = SIZEOF(.bss) / 4);

/* user stack is last 16KB */
.stack ORIGIN(RAM) + LENGTH(RAM) - 0x4000:
.ofs1 0xFE7F5D00: AT(0xFE7F5D00)
{
PROVIDE (__stack = .);
*(.stack)
} > RAM
KEEP(*(.ofs1))
} > OFS
.ofs2 0xFE7F5D10: AT(0xFE7F5D10)
{
KEEP(*(.ofs2))
} > OFS
.ofs3 0xFE7F5D20: AT(0xFE7F5D20)
{
KEEP(*(.ofs3))
} > OFS
.ofs4 0xFE7F5D40: AT(0xFE7F5D40)
{
KEEP(*(.ofs4))
} > OFS
.ofs5 0xFE7F5D48: AT(0xFE7F5D48)
{
KEEP(*(.ofs5))
} > OFS
.ofs6 0xFE7F5D50: AT(0xFE7F5D50)
{
KEEP(*(.ofs6))
} > OFS
.ofs7 0xFE7F5D64: AT(0xFE7F5D64)
{
KEEP(*(.ofs7))
} > OFS
.ofs8 0xFE7F5D70: AT(0xFE7F5D70)
{
KEEP(*(.ofs8))
} > OFS
}


/* reserve 16KB user stack */
PROVIDE(_ustack = ORIGIN(RAM) + LENGTH(RAM) - 0x4000 );
/* reserve 4KB interrupt stack */
PROVIDE(_istack = ORIGIN(RAM) + LENGTH(RAM) - 0x4000 - 0x1000 );

_wolfboot_partition_boot_address = @WOLFBOOT_PARTITION_BOOT_ADDRESS@;
_wolfboot_partition_size = @WOLFBOOT_PARTITION_SIZE@;
_wolfboot_partition_update_address = @WOLFBOOT_PARTITION_UPDATE_ADDRESS@;
_wolfboot_partition_swap_address = @WOLFBOOT_PARTITION_SWAP_ADDRESS@;
151 changes: 151 additions & 0 deletions test-app/app_renesas_rx.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/* app_renesas_rx.c
*
* Test bare-metal application.
*
* Copyright (C) 2024 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 2 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
*/

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "hal.h"
#include "printf.h"
#include "wolfboot/wolfboot.h"

/* route stdout to UART */
int write(int fileno, char *buf, int count)
{
(void)fileno;
uart_write(buf, count);
return count;
}

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 void printPart(uint8_t *part)
{
uint8_t *magic;
uint32_t ver;
uint8_t state;
#ifdef WOLFBOOT_DEBUG_PARTION
uint32_t *v;
int i;
#endif

magic = part;
printf("Magic: %c%c%c%c\n", magic[0], magic[1], magic[2], magic[3]);
ver = wolfBoot_get_blob_version(part);
printf("Version: %02x\n", (uint8_t)ver);
state = *(part + WOLFBOOT_PARTITION_SIZE - sizeof(uint32_t) - 1);
printf("Status: %02x (%s)\n", state, state2str(state));
magic = part + WOLFBOOT_PARTITION_SIZE - sizeof(uint32_t);
printf("Tail Mgc: %c%c%c%c\n", magic[0], magic[1], magic[2], magic[3]);

#ifdef WOLFBOOT_DEBUG_PARTION
v = (uint32_t*)part;
for (i = 0; i < 0x100/4; i++) {
if(i % 4 == 0)
print("\n%08x: ", (uint32_t)v+i*4);
print("%08x ", v[i]);
}
#endif
}

static void printPartitions(void)
{
printf("\n=== Boot Partition[%08x] ===\n", WOLFBOOT_PARTITION_BOOT_ADDRESS);
printPart((uint8_t*)WOLFBOOT_PARTITION_BOOT_ADDRESS);
printf("\n=== Update Partition[%08x] ===\n", WOLFBOOT_PARTITION_UPDATE_ADDRESS);
printPart((uint8_t*)WOLFBOOT_PARTITION_UPDATE_ADDRESS);
}

int main(void)
{
uint8_t firmware_version = 0;

uart_init();

#if !defined(WOLFBOOT_RENESAS_TSIP)
printf("| ------------------------------------------------------------------- |\n");
printf("| Renesas RX User Application in BOOT partition started by wolfBoot |\n");
printf("| ------------------------------------------------------------------- |\n\n");
#elif defined(WOLFBOOT_RENESAS_TSIP_SRCVERSION)
printf("| ------------------------------------------------------------------------------- |\n");
printf("| Renesas RX w/ TSIP(SRC) User Application in BOOT partition started by wolfBoot |\n");
printf("| ------------------------------------------------------------------------------- |\n\n");
#else
printf("| ------------------------------------------------------------------------------- |\n");
printf("| Renesas RX w/ TSIP(LIB) User Application in BOOT partition started by wolfBoot |\n");
printf("| ------------------------------------------------------------------------------- |\n\n");
#endif

hal_init();

printPartitions();

/* The same as: wolfBoot_get_image_version(PART_BOOT); */
firmware_version = wolfBoot_current_firmware_version();

printf("\nCurrent Firmware Version: %d\n", firmware_version);

if (firmware_version >= 1) {
if (firmware_version == 1) {
printf("Hit any key to call wolfBoot_success the firmware.\n");
getchar();

wolfBoot_success();
printPartitions();

printf("\nHit any key to update the firmware.\n");
getchar();

wolfBoot_update_trigger();
printf("Firmware Update is triggered\n");
printPartitions();
}
else if (firmware_version == 2) {
printf("Hit any key to call wolfBoot_success the firmware.\n");
getchar();

wolfBoot_success();
printPartitions();
}
}
else {
printf("Invalid Firmware Version\n");
goto busy_idle;
}

busy_idle:
/* busy wait */
while (1)
;

return 0;
}

0 comments on commit df49241

Please sign in to comment.