-
Notifications
You must be signed in to change notification settings - Fork 139
[Renesas RX72N CCRX] Move flash functions to RAM for flash operation #689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like this could still just use memcpy or be a version that isn't a "RAMFUNCTION" and pass in the normal dst, src, size? |
||
| { | ||
| 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}; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| 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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should be using memcpy because it uses wolfboot's string.c. Are you sure you can't build the RX72 CCRX without the stdlib?? |
||
| 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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"); | ||
| } | ||
|
Comment on lines
+58
to
+67
|
||
|
|
||
| /* 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); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is defined but never called in the codebase. If it's intended for debugging purposes, consider either removing it or using it in appropriate places. If it's meant to be kept for future use, add a comment explaining its purpose.