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
81 changes: 46 additions & 35 deletions IDE/Renesas/e2studio/RX72N/app_RenesasRX01/.cproject

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions IDE/Renesas/e2studio/RX72N/app_RenesasRX01/.project
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,10 @@
<type>1</type>
<locationURI>PARENT-5-PROJECT_LOC/hal/renesas-rx.c</locationURI>
</link>
<link>
<name>src/string.c</name>
<type>1</type>
<locationURI>PARENT-5-PROJECT_LOC/src/string.c</locationURI>
</link>
</linkedResources>
</projectDescription>
472 changes: 236 additions & 236 deletions IDE/Renesas/e2studio/RX72N/app_RenesasRX01/app_RenesasRX01.scfg

Large diffs are not rendered by default.

36 changes: 32 additions & 4 deletions IDE/Renesas/e2studio/RX72N/app_RenesasRX01/src/app_RenesasRX01.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
#include <string.h>
#include "hal.h"
#include "wolfboot/wolfboot.h"

#include "image.h"
#include "r_smc_entry.h"
static const char* state2str(uint8_t s)
{
switch(s) {
Expand All @@ -39,6 +40,17 @@ static const char* state2str(uint8_t s)
}
}

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 printPart(uint8_t *part)
{
#ifdef WOLFBOOT_DEBUG_PARTION
Expand All @@ -47,16 +59,21 @@ static void printPart(uint8_t *part)
#endif
uint8_t *magic;
uint8_t state;
uint8_t upflag;
uint32_t ver;

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

#ifdef WOLFBOOT_DEBUG_PARTION
v = (uint32_t *)part;
Expand All @@ -68,14 +85,25 @@ static void printPart(uint8_t *part)
#endif

}

#ifdef WOLFBOOT_DEBUG_PARTION
static void verify_flash_write(uint32_t addr, int len)
{
uint8_t *p = (uint8_t *)addr;
int i;
printf("verify addr=0x%08x: ", addr);
for (i = 0; i < len && i < 8; i++) {
printf("%02x ", p[i]);
}
printf("\n");
}
#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);
printPart((uint8_t*)(uintptr_t)WOLFBOOT_PARTITION_UPDATE_ADDRESS);
}

void main(void)
Expand Down
3 changes: 2 additions & 1 deletion IDE/Renesas/e2studio/RX72N/include/user_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,5 +278,6 @@
#else
# define WOLFSSL_SMALL_STACK
#endif

#define PRINTF_ENABLED
#define NVM_FLASH_WRITEONCE
#endif /* !H_USER_SETTINGS_ */
11 changes: 6 additions & 5 deletions IDE/Renesas/e2studio/RX72N/resouce/section_info_SWuse.esi
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?xml version="1.0" encoding="ASCII"?>
<com.renesas.linkersection.model:SectionContainer xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:com.renesas.linkersection.model="http:///LinkerSection.ecore">
<sections name="SU">
<sections name="SI">
<sectionAddress xsi:type="com.renesas.linkersection.model:FixedAddress" fixedAddress="4"/>
</sections>
<sections name="SI"/>
<sections name="B_1"/>
<sections name="R_1"/>
<sections name="B_2"/>
Expand All @@ -13,9 +12,12 @@
<sections name="B_8"/>
<sections name="R_8"/>
<sections name="RPFRAM"/>
<sections name="RPFRAM2"/>
<sections name="C_FIRMWARE_UPDATE_CONTROL_BLOCK">
<sectionAddress xsi:type="com.renesas.linkersection.model:FixedAddress" fixedAddress="1048576"/>
</sections>
<sections name="C_FIRMWARE_UPDATE_CONTROL_BLOCK_MIRROR"/>
<sections name="PResetPRG">
<sectionAddress xsi:type="com.renesas.linkersection.model:FixedAddress" fixedAddress="4290839040"/>
<sectionAddress xsi:type="com.renesas.linkersection.model:FixedAddress" fixedAddress="4290772992"/>
</sections>
<sections name="C_1"/>
<sections name="C_2"/>
Expand All @@ -27,7 +29,6 @@
<sections name="L"/>
<sections name="P"/>
<sections name="PFRAM"/>
<sections name="PFRAM2"/>
<sections name="EXCEPTVECT">
<sectionAddress xsi:type="com.renesas.linkersection.model:FixedAddress" fixedAddress="4294967168"/>
</sections>
Expand Down
146 changes: 108 additions & 38 deletions IDE/Renesas/e2studio/RX72N/wolfBoot/.cproject

Large diffs are not rendered by default.

83 changes: 64 additions & 19 deletions hal/renesas-rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@

/* forward declaration */
int hal_flash_init(void);

#if defined(WOLFBOOT_RENESAS_TSIP) && !defined(WOLFBOOT_RENESAS_APP)
static void hal_panic(void)
{
while(1)
;
}
#endif

#ifdef ENABLE_LED
void hal_led_on(void)
Expand Down Expand Up @@ -104,6 +105,21 @@ void hal_delay_us(uint32_t us)
}
}

static flash_err_t flash_check_error()
{
uint32_t st = FLASH_FSTATR;

if (st & FLASH_FSTATR_ILGLERR) return FLASH_ERR_ILGL;
if (st & FLASH_FSTATR_PRGERR) return FLASH_ERR_PRG;
if (st & FLASH_FSTATR_ERSERR) return FLASH_ERR_ERS;
if (st & FLASH_FSTATR_FLWEERR) return FLASH_ERR_FLWE;
if (st & FLASH_FSTATR_FESETERR) return FLASH_ERR_FESET;
if (st & FLASH_FSTATR_SECERR) return FLASH_ERR_SEC;
if (st & FLASH_FSTATR_OTERR) return FLASH_ERR_OT;

return FLASH_OK;

}
#ifdef DEBUG_UART

#ifndef DEBUG_UART_SCI
Expand Down Expand Up @@ -210,7 +226,6 @@ void uart_write(const char* buf, unsigned int sz)
void hal_clk_init(void)
{
uint32_t reg, i;
uint16_t stc;
uint8_t cksel = CFG_CKSEL;

PROTECT_OFF(); /* write protect off */
Expand Down Expand Up @@ -485,8 +500,23 @@ void hal_prepare_boot(void)

}

#ifdef __CCRX__
/* copy RAM functions from ROM to RAM */
static void copyfuncs(void)
{
unsigned char *dst, *src;
src = __sectop("PFRAM");
dst = __sectop("RPFRAM");
while(src < __secend("PFRAM")) {
*dst++ = *src++;
}
}
#endif
int hal_flash_init(void)
{
#ifdef __CCRX__
copyfuncs();
#endif
/* Flash Write Enable */
FLASH_FWEPROR = FLASH_FWEPROR_FLWE;

Expand All @@ -506,23 +536,34 @@ int hal_flash_init(void)
/* write up to 128 bytes at a time */
#define FLASH_FACI_CODE_BLOCK_SZ \
(FLASH_FACI_CMD_PROGRAM_CODE_LENGTH * FLASH_FACI_CMD_PROGRAM_DATA_LENGTH)
#ifdef __CCRX__
#pragma section FRAM
#endif
int RAMFUNCTION hal_flash_write(uint32_t addr, const uint8_t *data, int len)
{
int ret, i, chunk;
uint8_t codeblock[FLASH_FACI_CODE_BLOCK_SZ];
int i;
uint8_t codeblock[FLASH_FACI_CODE_BLOCK_SZ] = {0};
uint16_t* data16 = (uint16_t*)data;
uint32_t block_base;
uint32_t offset;
int write_size;
int ret;

while (len > 0) {
/* handle partial remainder */
if (len < FLASH_FACI_CODE_BLOCK_SZ) {
uint8_t *src = (uint8_t*)addr;
int remain = FLASH_FACI_CODE_BLOCK_SZ - len;
memcpy(codeblock, data16, len);
memcpy(codeblock + len, src + len, remain);
data16 = (uint16_t*)codeblock;
}
/* Align address to 128-byte boundary */
block_base = addr & ~(FLASH_FACI_CODE_BLOCK_SZ - 1);
offset = addr - block_base;

XMEMCPY(codeblock, (uint8_t*)block_base, FLASH_FACI_CODE_BLOCK_SZ);
write_size = FLASH_FACI_CODE_BLOCK_SZ - offset;
if (write_size > len)
write_size = len;

XMEMCPY(&codeblock[offset], data, write_size);
data16 = (uint16_t*)codeblock;

FLASH_FSADDR = addr;

FLASH_FSADDR = block_base;
/* flash program command */
FLASH_FACI_CMD8 = FLASH_FACI_CMD_PROGRAM;
/* number of 16-bit blocks: for code blocks is always 0x40 (64) */
Expand All @@ -539,9 +580,12 @@ int RAMFUNCTION hal_flash_write(uint32_t addr, const uint8_t *data, int len)

/* Wait for FCU operation to complete */
while ((FLASH_FSTATR & FLASH_FSTATR_FRDY) == 0);

len -= FLASH_FACI_CODE_BLOCK_SZ;
addr += FLASH_FACI_CODE_BLOCK_SZ;
if ((ret = flash_check_error()) != FLASH_OK) {
return ret;
}
len -= write_size;
addr += write_size;
data += write_size;
}
return 0;
}
Expand Down Expand Up @@ -579,7 +623,6 @@ int RAMFUNCTION hal_flash_erase(uint32_t address, int len)

static int RAMFUNCTION hal_flash_write_faw(uint32_t faw)
{
volatile uint8_t* cmdArea = (volatile uint8_t*)FLASH_FACI_CMD_AREA;

#ifndef BIG_ENDIAN_ORDER
#if defined(__CCRX__)
Expand Down Expand Up @@ -639,7 +682,9 @@ void RAMFUNCTION hal_flash_lock(void)
FLASH_FENTRYR_CODE_READ | FLASH_FENTRYR_DATA_READ);
return;
}

#ifdef __CCRX__
#pragma section
#endif
#if !defined(WOLFBOOT_NO_PARTITIONS) && !defined(TARGET_library)
void* hal_get_primary_address(void)
{
Expand All @@ -648,6 +693,6 @@ void* hal_get_primary_address(void)

void* hal_get_update_address(void)
{
return (void*)WOLFBOOT_PARTITION_UPDATE_ADDRESS;
return (void*)(uintptr_t)WOLFBOOT_PARTITION_UPDATE_ADDRESS;
}
#endif
11 changes: 11 additions & 0 deletions hal/renesas-rx.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,4 +411,15 @@ void hal_delay_us(uint32_t us);
#define ICU_PIBR(x) (*(volatile uint8_t *)(SYSTEM_BASE + 0x7700 + (x)))
#define ICU_PIAR(x) (*(volatile uint8_t *)(SYSTEM_BASE + 0x7900 + (x)))

typedef enum {
FLASH_ERR_ILGL = -7,
FLASH_ERR_PRG = -6,
FLASH_ERR_ERS = -5,
FLASH_ERR_FLWE = -4,
FLASH_ERR_FESET = -3,
FLASH_ERR_SEC = -2,
FLASH_ERR_OT = -1,
FLASH_ERR_UNKNOWN = -99,
FLASH_OK = 0
} flash_err_t;
#endif /* !_WOLFBOOT_RENESAS_RX_H_ */
11 changes: 11 additions & 0 deletions src/boot_renesas.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ static void longJump(const uint32_t *app_offset)
jmp r1;
}
#endif
static void verify_flash_write(uint32_t addr, int len)
{
uint8_t *p = (uint8_t *)addr;
int i;
printf("verify addr=0x%08x: ", addr);
for (i = 0; i < len && i < 8; i++) {
printf("%02x ", p[i]);
}
printf("\n");
}

/* Calls the application entry point */
void do_boot(const uint32_t *app_offset)
Expand Down Expand Up @@ -84,6 +94,7 @@ void do_boot(const uint32_t *app_offset)
#if defined(__RX__)
/* Do unconditional jump (r1 = app_offset) */
#if defined(__CCRX__)
printf("app_offset 0x%p\n", app_offset);
longJump(app_offset);
#else
app_entry = (void(*))(*app_offset);
Expand Down
Loading