From 235d0672afda3737678a7315cee11d2b75f5e3ab Mon Sep 17 00:00:00 2001 From: Hideki Miyazaki Date: Fri, 20 Oct 2023 16:21:33 +0900 Subject: [PATCH] fix and update rx72n --- IDE/Renesas/e2studio/RX72N/Readme.md | 82 +++++++++++-------- .../app_RenesasRX01/src/app_RenesasRX01.c | 21 ++++- IDE/Renesas/e2studio/RX72N/include/target.h | 4 +- .../RX72N/resouce/section_info_SWuse.esi | 37 +++++++++ .../RX72N/resouce/section_info_TSIPuse.esi | 37 +++++++++ IDE/Renesas/e2studio/RX72N/x2hex.sh | 26 +++--- tools/keytools/keygen.c | 2 + 7 files changed, 158 insertions(+), 51 deletions(-) create mode 100644 IDE/Renesas/e2studio/RX72N/resouce/section_info_SWuse.esi create mode 100644 IDE/Renesas/e2studio/RX72N/resouce/section_info_TSIPuse.esi diff --git a/IDE/Renesas/e2studio/RX72N/Readme.md b/IDE/Renesas/e2studio/RX72N/Readme.md index 798a494a8..70e0af53f 100644 --- a/IDE/Renesas/e2studio/RX72N/Readme.md +++ b/IDE/Renesas/e2studio/RX72N/Readme.md @@ -44,9 +44,10 @@ Flash Allocation: 0xffc10000: Primary partition (Header) 0xffc10100: Primary partition (Application image) /* When it uses IMAGE_HEADER_SIZE 256, e.g. ED25519, EC256, EC384 or EC512 */ 0xffc10200: Primary partition (Application image) /* When it uses IMAGE_HEADER_SIZE 512, e.g. RSA2048, RSA3072 */ -0xffdf0000: Update partition (Header) -0xffdf0100: Update partition (Application image) -0xfffd0000: Swap sector +0xffdf8000: Update partition (Header) +0xffdf8100: Update partition (Application image) /* When it uses IMAGE_HEADER_SIZE 256, e.g. ED25519, EC256, EC384 or EC512 */ +0xffdf8200: Update partition (Application image) /* When it uses IMAGE_HEADER_SIZE 512, e.g. RSA2048, RSA3072 */ +0xfffe0000: Swap sector ``` @@ -75,13 +76,13 @@ $ export PATH:$PATH:/tools/keytools $ keygen --ecc256 -g ./pri-ecc256.der ``` -This generates a pair of private and public keys with -g option. The private key is stored -in the specified file. The public key is stored in a key store as a C source code +This generates a pair of private and public keys with -g option. The private key is stored +in the specified file. The public key is stored in a key store as a C source code in "src/keystore.c" soo that it can be compiled and linked with wolfBoot. If you have an existing key pair, you can use -i option to import the pablic key to the store. -You can specify various signature algorithms such as +You can specify various signature algorithms such as ``` --ed25519 --ed448 --ecc256 --ecc384 --ecc521 --rsa2048 --rsa3072 @@ -140,7 +141,7 @@ Pre-Include Code Origin and entry point (PResetPRG) is "0xffc10200" (See Section Viewer of Linker Section). ``` -app_RenesasRx01.x in ELF is generated under HardwareDebug. You can derive bair binary file +app_RenesasRx01.x in ELF is generated under HardwareDebug. You can derive bair binary file (app_RenesasRx01.bin) by rx-elf-objcopy.exe command as follows. -R are for eliminate unnecessary secrions. @@ -189,7 +190,7 @@ $ rx-elf-objcopy.exe -I binary -O srec --change-addresses=0xffc10000 app_Renesas Now, you can download and start wolfBoot program by e2Studio debugger. After starting the program, you can see the partition information as follows. If the boot program succeeds integrity and authenticity check, it initiate the -application V1. +application V1. ``` @@ -201,51 +202,47 @@ application V1. === Boot Partition[ffc10000] === Magic: WOLF Version: 01 -Status: ff -Tail Mgc: ???? +Status: ff (New) +Tail Mgc: ���� -=== Update Partition[ffdf0000] === -Magic: WOLF -Version: 02 -Status: ff -Tail Mgc: ???? +=== Update Partition[ffdf8000] === +Magic: ���� +Version: 00 +Status: ff (New) +Tail Mgc: ���� Current Firmware Version: 1 Hit any key to call wolfBoot_success the firmware. ``` After hitting any key, the application calls wolfBoot_success() to set boot partition -state and wait for any key again. - -If you re-start the boot program at this moment, -after checking the integrity and authenticity, it jumps to the application. -You can see the state is Success("00"). +state and wait for any key again. ``` === Boot Partition[ffc10000] === Magic: WOLF Version: 01 -Status: 00 +Status: 00 (Success) Tail Mgc: BOOT -=== Update Partition[ffdf0000] === -Magic: WOLF -Version: 02 -Status: ff -Tail Mgc: ???? +=== Update Partition[ffdf8000] === +Magic: ���� +Version: 00 +Status: 00 (Success) +Tail Mgc: BOOT -Hit any key to update the firmware. ``` +You can see the state is Success("00"). ### 3-8 Generate Signed app V2 and download it -Similar to V1, you can signe and generate a binary of V2. The update partition starts at "0xffdf0000". +Similar to V1, you can signe and generate a binary of V2. The update partition starts at "0xffdf8000". You can download it by the flash programmer. ``` $ sign --ecc256 app_RenesasRx01.bin ../../../../../pri-ecc256.der 2.0 -rx-elf-objcopy.exe -I binary -O srec --change-addresses=0xffdf0000 app_RenesasRx01_v2.0_signed.bin app_RenesasRx01_v2.0_signed.hex +rx-elf-objcopy.exe -I binary -O srec --change-addresses=0xffdf8000 app_RenesasRx01_v2.0_signed.bin app_RenesasRx01_v2.0_signed.hex ``` @@ -253,7 +250,7 @@ rx-elf-objcopy.exe -I binary -O srec --change-addresses=0xffdf0000 app_RenesasRx Now the image is downloaded but note that the partition status is not changed yet. When it is re-boot, it checks integrity and authenticity of V1 and initiate V1 as in -step 6. +step 8. ``` | ------------------------------------------------------------------- | @@ -261,13 +258,28 @@ step 6. | ------------------------------------------------------------------- | Current Firmware Version: 1 +.... Hit any key to update the firmware. -Firmware Update is triggered ``` After you see the message, hit any key so that the application calls wolfBoot_update_trigger() which changes the partition status and triggers -updating the firmware. +updating the firmware. You will see the following messages. + +``` +Firmware Update is triggered +=== Boot Partition[ffc10000] === +Magic: WOLF +Version: 01 +Status: 00 (Success) +Tail Mgc: BOOT + +=== Update Partition[ffdf8000] === +Magic: ���� +Version: 00 +Status: 70 (Updating) +Tail Mgc: BOOT +``` Since this is just a trigger, the application can continue the process. In the demo application it outputs a message "Firmware Update is triggered" and enters @@ -291,11 +303,11 @@ Version: 02 Status: 10 Tail Mgc: BOOT -=== Update Partition[ffdf0000] === +=== Update Partition[ffdf8000] === Magic: WOLF Version: 01 -Status: ff -Tail Mgc: ???? +Status: 30 +Tail Mgc: BOOT Current Firmware Version: 2 ``` diff --git a/IDE/Renesas/e2studio/RX72N/app_RenesasRX01/src/app_RenesasRX01.c b/IDE/Renesas/e2studio/RX72N/app_RenesasRX01/src/app_RenesasRX01.c index c727d61ad..c1b854499 100644 --- a/IDE/Renesas/e2studio/RX72N/app_RenesasRX01/src/app_RenesasRX01.c +++ b/IDE/Renesas/e2studio/RX72N/app_RenesasRX01/src/app_RenesasRX01.c @@ -28,6 +28,17 @@ #include "hal.h" #include "wolfboot/wolfboot.h" +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) { #ifdef WOLFBOOT_DEBUG_PARTION @@ -43,7 +54,7 @@ static void printPart(uint8_t *part) ver = wolfBoot_get_blob_version(part); printf("Version: %02x\n", ver); state = *(part + WOLFBOOT_PARTITION_SIZE - sizeof(uint32_t) - 1); - printf("Status: %02x\n", state); + 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]); @@ -107,6 +118,14 @@ void main(void) 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"); diff --git a/IDE/Renesas/e2studio/RX72N/include/target.h b/IDE/Renesas/e2studio/RX72N/include/target.h index 2880621bc..5a7ef2592 100644 --- a/IDE/Renesas/e2studio/RX72N/include/target.h +++ b/IDE/Renesas/e2studio/RX72N/include/target.h @@ -67,9 +67,9 @@ #define WOLFBOOT_PARTITION_SWAP_ADDRESS 0x0 #else - #define WOLFBOOT_BOOT_SIZE 0x20000 + #define WOLFBOOT_BOOT_SIZE 0x10000 #define WOLFBOOT_RX_EXCVECT 0x10000 - #define WOLFBOOT_SECTOR_SIZE 0x20000 + #define WOLFBOOT_SECTOR_SIZE 0x10000 #define WOLFBOOT_PARTITION_SIZE\ ((WOLFBOOT_FLASH_SIZE - WOLFBOOT_BOOT_SIZE -\ diff --git a/IDE/Renesas/e2studio/RX72N/resouce/section_info_SWuse.esi b/IDE/Renesas/e2studio/RX72N/resouce/section_info_SWuse.esi new file mode 100644 index 000000000..634882863 --- /dev/null +++ b/IDE/Renesas/e2studio/RX72N/resouce/section_info_SWuse.esi @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/IDE/Renesas/e2studio/RX72N/resouce/section_info_TSIPuse.esi b/IDE/Renesas/e2studio/RX72N/resouce/section_info_TSIPuse.esi new file mode 100644 index 000000000..9765e5f93 --- /dev/null +++ b/IDE/Renesas/e2studio/RX72N/resouce/section_info_TSIPuse.esi @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/IDE/Renesas/e2studio/RX72N/x2hex.sh b/IDE/Renesas/e2studio/RX72N/x2hex.sh index 10591d149..03007a2b4 100644 --- a/IDE/Renesas/e2studio/RX72N/x2hex.sh +++ b/IDE/Renesas/e2studio/RX72N/x2hex.sh @@ -23,7 +23,7 @@ if [ $# -ne 4 ];then fi VER1_ADDR=0xffc10000 -VER2_ADDR=0xffdf0000 +VER2_ADDR=0xffdf8000 # signature method RSA2048_SIGN="rsa2048" @@ -78,21 +78,21 @@ if [ $TSIPUSE -eq 1 -o $TSIPUSE -eq 2 ]; then fi -echo "Version 1 app start address : " $VER1_ADDR -echo "Version 2 app start address : " $VER2_ADDR +echo "Version 1 app start address : " $VER1_ADDR +echo "Version 2 app start address : " $VER2_ADDR echo "Signature method : " $SIGN_METHOD -echo +echo echo COPY app_RenesasRx01.x to RXELF_BIN_DIR to convert bin file cp ${APP_RX}/HardwareDebug/app_RenesasRx01.x "${RXELF_BIN_DIR}" pushd "${RXELF_BIN_DIR}" -echo +echo echo Run rx-elf-objcopy.exe to generate bin "${RXELF_OBJCPY_BIN}" -O binary -R '$ADDR_C_FE7F5D00' -R '$ADDR_C_FE7F5D10' -R '$ADDR_C_FE7F5D20' -R '$ADDR_C_FE7F5D30' -R '$ADDR_C_FE7F5D40' -R '$ADDR_C_FE7F5D48' -R '$ADDR_C_FE7F5D50' -R '$ADDR_C_FE7F5D64' -R '$ADDR_C_FE7F5D70' -R EXCEPTVECT -R RESETVECT app_RenesasRx01.x app_RenesasRx01.bin -echo +echo echo copy app_RenesasRx01.bin to wolfBoot folder to sign cp app_RenesasRx01.bin ${WOLFBOOT_DIR} @@ -102,34 +102,34 @@ echo "generate key" keygen --${SIGN_METHOD} -g ./pri-${SIGN_METHOD}.der -echo +echo echo sign app_RenesasRx01.bin for version 1 sign --${SIGN_METHOD}${SIGN_METHOD_EX} app_RenesasRx01.bin ./pri-${SIGN_METHOD}.der 1.0 -echo +echo echo sign app_RenesasRx01.bin for version 2 sign --${SIGN_METHOD}${SIGN_METHOD_EX} app_RenesasRx01.bin ./pri-${SIGN_METHOD}.der 2.0 -echo +echo echo copy app_RenesasRx01_v1.0/v2.0_signed.bin RXELF_BIN_DIR cp app_RenesasRx01_v1.0_signed.bin "${RXELF_BIN_DIR}" cp app_RenesasRx01_v2.0_signed.bin "${RXELF_BIN_DIR}" popd -echo +echo echo Run rx-elf-objcopy.exe to generate hex for version 1 "${RXELF_OBJCPY_BIN}" -I binary -O srec --change-addresses=${VER1_ADDR} app_RenesasRx01_v1.0_signed.bin app_RenesasRx01_v1.0_signed.hex -echo +echo echo Run rx-elf-objcopy.exe to generate hex for version 2 "${RXELF_OBJCPY_BIN}" -I binary -O srec --change-addresses=${VER2_ADDR} app_RenesasRx01_v2.0_signed.bin app_RenesasRx01_v2.0_signed.hex -echo +echo echo move *.hex to ${CURRENT} mv app_RenesasRx01_v1.0_signed.hex app_RenesasRx01_v2.0_signed.hex ${CURRENT} -echo +echo echo Clean up all copied and generated files rm -rf app_RenesasRx01.x app_RenesasRx01.bin app_RenesasRx01_v1.0_signed.bin app_RenesasRx01_v2.0_signed.bin popd diff --git a/tools/keytools/keygen.c b/tools/keytools/keygen.c index 9ebdc12a0..c758e7c60 100644 --- a/tools/keytools/keygen.c +++ b/tools/keytools/keygen.c @@ -129,6 +129,8 @@ const char Cfile_Banner[]="/* Keystore file for wolfBoot, automatically generate const char Store_hdr[] = "\n" "#if defined(__APPLE__) && defined(__MACH__)\n" "#define KEYSTORE_SECTION __attribute__((section (\"__KEYSTORE,__keystore\")))\n" + "#elif defined(__CCRX__)\n" + "#define KEYSTORE_SECTION\n" "#else\n" "#define KEYSTORE_SECTION __attribute__((section (\".keystore\")))\n" "#endif\n\n"