diff --git a/IDE/Renesas/e2studio/RX72N/app_RenesasRX01/.cproject b/IDE/Renesas/e2studio/RX72N/app_RenesasRX01/.cproject index 6417016d1b..287af8b91f 100644 --- a/IDE/Renesas/e2studio/RX72N/app_RenesasRX01/.cproject +++ b/IDE/Renesas/e2studio/RX72N/app_RenesasRX01/.cproject @@ -29,15 +29,15 @@ - - - - - - - - - - - - - - - + - - - - - - @@ -174,6 +184,7 @@ + diff --git a/IDE/Renesas/e2studio/RX72N/app_RenesasRX01/.project b/IDE/Renesas/e2studio/RX72N/app_RenesasRX01/.project index 0a81fbfddb..cb2082f1c1 100644 --- a/IDE/Renesas/e2studio/RX72N/app_RenesasRX01/.project +++ b/IDE/Renesas/e2studio/RX72N/app_RenesasRX01/.project @@ -44,5 +44,10 @@ 1 PARENT-5-PROJECT_LOC/hal/renesas-rx.c + + src/string.c + 1 + PARENT-5-PROJECT_LOC/src/string.c + diff --git a/IDE/Renesas/e2studio/RX72N/app_RenesasRX01/app_RenesasRX01.scfg b/IDE/Renesas/e2studio/RX72N/app_RenesasRX01/app_RenesasRX01.scfg index 2b6da9cacf..ee8e277877 100644 --- a/IDE/Renesas/e2studio/RX72N/app_RenesasRX01/app_RenesasRX01.scfg +++ b/IDE/Renesas/e2studio/RX72N/app_RenesasRX01/app_RenesasRX01.scfg @@ -11,11 +11,11 @@ - + diff --git a/hal/renesas-rx.c b/hal/renesas-rx.c index ef765c97f6..ca36892bcd 100644 --- a/hal/renesas-rx.c +++ b/hal/renesas-rx.c @@ -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) @@ -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 @@ -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 */ @@ -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; @@ -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) */ @@ -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; } @@ -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__) @@ -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) { @@ -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 diff --git a/hal/renesas-rx.h b/hal/renesas-rx.h index 1b44dea7f9..cd96a732b0 100644 --- a/hal/renesas-rx.h +++ b/hal/renesas-rx.h @@ -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_ */ diff --git a/src/boot_renesas.c b/src/boot_renesas.c index 4983caa782..0f18c2cc9f 100644 --- a/src/boot_renesas.c +++ b/src/boot_renesas.c @@ -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) @@ -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); diff --git a/src/libwolfboot.c b/src/libwolfboot.c index 8f5ab88063..7e3abd008a 100644 --- a/src/libwolfboot.c +++ b/src/libwolfboot.c @@ -218,7 +218,9 @@ void WEAKFUNCTION hal_cache_invalidate(void) { /* if cache flushing is required implement in hal */ } - +#ifdef __CCRX__ +#pragma section FRAM +#endif static int RAMFUNCTION nvm_select_fresh_sector(int part) { int sel; @@ -377,7 +379,9 @@ static int RAMFUNCTION partition_magic_write(uint8_t part, uintptr_t addr) ret = hal_flash_erase(addr_read, WOLFBOOT_SECTOR_SIZE); return ret; } - +#ifdef __CCRX__ +#pragma section +#endif #else # define trailer_write(part,addr, val) hal_flash_write(addr, (void *)&val, 1) # define partition_magic_write(part,addr) hal_flash_write(addr, \ @@ -395,6 +399,9 @@ void RAMFUNCTION set_trailer_at(uint8_t part, uint32_t at, uint8_t val); void RAMFUNCTION set_partition_magic(uint8_t part); #elif !defined(WOLFBOOT_FIXED_PARTITIONS) +#ifdef __CCRX__ +#pragma section FRAM +#endif static uint8_t* RAMFUNCTION get_trailer_at(uint8_t part, uint32_t at) { (void)part; @@ -413,9 +420,13 @@ static void RAMFUNCTION set_partition_magic(uint8_t part) (void)part; return; } - +#ifdef __CCRX__ +#pragma section +#endif #else - +#ifdef __CCRX__ +#pragma section FRAM +#endif /** * @brief Get the trailer at a specific address * @@ -550,12 +561,18 @@ static void RAMFUNCTION set_partition_magic(uint8_t part) } } } +#ifdef __CCRX__ +#pragma section +#endif #endif #endif /* !MOCK_PARTITION_TRAILER */ #ifdef WOLFBOOT_FIXED_PARTITIONS +#ifdef __CCRX__ +#pragma section FRAM +#endif /** * @brief Get the magic trailer of a partition. * @@ -843,6 +860,9 @@ void RAMFUNCTION wolfBoot_success(void) wolfBoot_erase_encrypt_key(); #endif } +#ifdef __CCRX__ +#pragma section +#endif #endif /* WOLFBOOT_FIXED_PARTITIONS */ /** diff --git a/src/string.c b/src/string.c index ed85f8fa03..2bf72ed021 100644 --- a/src/string.c +++ b/src/string.c @@ -27,7 +27,7 @@ #endif #include -#ifndef TARGET_library +#if !defined(TARGET_library) && !defined(__CCRX__) #include #else size_t strlen(const char *s); /* forward declaration */ @@ -40,7 +40,7 @@ size_t strlen(const char *s); /* forward declaration */ #endif #endif -#if !defined(__IAR_SYSTEMS_ICC__) && !defined(TARGET_X86_64_EFI) +#if !defined(__IAR_SYSTEMS_ICC__) && !defined(TARGET_X86_64_EFI) && !defined(__CCRX__) /* for RAMFUNCTION */ #include "image.h" #endif @@ -76,7 +76,6 @@ int isalpha(int c) return (isupper(c) || islower(c)); } -#if !defined(__CCRX__) /* Renesas CCRX */ #if !defined(__IAR_SYSTEMS_ICC__) && !defined(TARGET_X86_64_EFI) void *memset(void *s, int c, size_t n) { @@ -115,7 +114,6 @@ int strcmp(const char *s1, const char *s2) return diff; } -#endif /* Renesas CCRX */ int strcasecmp(const char *s1, const char *s2) { @@ -153,7 +151,6 @@ int strncasecmp(const char *s1, const char *s2, size_t n) return diff; } -#if !defined(__CCRX__) /* Renesas CCRX */ char *strncat(char *dest, const char *src, size_t n) { size_t i = 0; @@ -240,11 +237,8 @@ void* memchr(void const *s, int c_in, size_t n) } return NULL; } - -#endif /* __CCRX__ Renesas CCRX */ #endif /* !BUILD_LOADER_STAGE1 || (PRINTF_ENABLED && DEBUG_UART) */ -#if !defined(__CCRX__) /* Renesas CCRX */ #if !(defined(BUILD_LOADER_STAGE1) && defined(ARCH_PPC)) || defined(DEBUG_UART) size_t strlen(const char *s) { @@ -259,6 +253,10 @@ size_t strlen(const char *s) #if !defined(__IAR_SYSTEMS_ICC__) && !defined(TARGET_X86_64_EFI) /* some of the hal_flash_ functions need this during updates */ +#ifdef __CCRX__ + #define RAMFUNCTION + #pragma section FRAM +#endif void RAMFUNCTION *memcpy(void *dst, const void *src, size_t n) { size_t i; @@ -286,7 +284,7 @@ void RAMFUNCTION *memcpy(void *dst, const void *src, size_t n) } #endif /* IAR */ -#ifndef __IAR_SYSTEMS_ICC__ +#if !defined(__IAR_SYSTEMS_ICC__) && !defined(__CCRX__) void *memmove(void *dst, const void *src, size_t n) { int i; @@ -304,7 +302,6 @@ void *memmove(void *dst, const void *src, size_t n) } } #endif -#endif /* __CCRX__ Renesas CCRX */ #endif /* WOLFBOOT_USE_STDLIBC */ #if defined(PRINTF_ENABLED) && defined(DEBUG_UART) diff --git a/src/update_flash.c b/src/update_flash.c index 0524f4b4de..eec2d1a295 100644 --- a/src/update_flash.c +++ b/src/update_flash.c @@ -46,6 +46,10 @@ int WP11_Library_Init(void); #error "MMU is not yet supported for update_flash.c, please consider update_ram.c instead" #endif +#ifdef __CCRX__ +#pragma section FRAM +#endif + #ifdef RAM_CODE #ifndef TARGET_rp2350 extern unsigned int _start_text; @@ -62,7 +66,6 @@ static uint8_t buffer[FLASHBUFFER_SIZE] XALIGNED(4); # endif #endif - static void RAMFUNCTION wolfBoot_erase_bootloader(void) { uint32_t len = WOLFBOOT_PARTITION_BOOT_ADDRESS - ARCH_FLASH_OFFSET; @@ -410,6 +413,9 @@ static int RAMFUNCTION wolfBoot_swap_and_final_erase(int resume) return 0; } +#ifdef __CCRX__ +#pragma section +#endif #endif /* !DISABLE_BACKUP && !CUSTOM_PARTITION_TRAILER */ #ifdef DELTA_UPDATES @@ -645,7 +651,9 @@ static int wolfBoot_delta_update(struct wolfBoot_image *boot, #else #define MAX_UPDATE_SIZE (size_t)((WOLFBOOT_PARTITION_SIZE - (2 *WOLFBOOT_SECTOR_SIZE))) #endif - +#ifdef __CCRX__ +#pragma section FRAM +#endif static int wolfBoot_get_total_size(struct wolfBoot_image* boot, struct wolfBoot_image* update) { @@ -1062,8 +1070,9 @@ static int RAMFUNCTION wolfBoot_update(int fallback_allowed) #endif return 0; } - - +#ifdef __CCRX__ +#pragma section +#endif #if defined(ARCH_SIM) && defined(WOLFBOOT_TPM) && defined(WOLFBOOT_TPM_SEAL) int wolfBoot_unlock_disk(void) @@ -1172,7 +1181,9 @@ int wolfBoot_unlock_disk(void) return ret; } #endif - +#ifdef __CCRX__ +#pragma section FRAM +#endif void RAMFUNCTION wolfBoot_start(void) { int bootRet; @@ -1330,7 +1341,9 @@ void RAMFUNCTION wolfBoot_start(void) do_boot((void *)boot.fw_base); } - +#ifdef __CCRX__ +#pragma section +#endif #ifdef WOLFBOOT_ARMORED # ifdef __GNUC__ # pragma GCC pop_options