fix and update rx72n

pull/388/head
Hideki Miyazaki 2023-10-20 16:21:33 +09:00 committed by Daniele Lacamera
parent 445cd7bae2
commit 0f5b5abf5f
7 changed files with 158 additions and 51 deletions

View File

@ -44,9 +44,10 @@ Flash Allocation:
0xffc10000: Primary partition (Header) 0xffc10000: Primary partition (Header)
0xffc10100: Primary partition (Application image) /* When it uses IMAGE_HEADER_SIZE 256, e.g. ED25519, EC256, EC384 or EC512 */ 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 */ 0xffc10200: Primary partition (Application image) /* When it uses IMAGE_HEADER_SIZE 512, e.g. RSA2048, RSA3072 */
0xffdf0000: Update partition (Header) 0xffdf8000: Update partition (Header)
0xffdf0100: Update partition (Application image) 0xffdf8100: Update partition (Application image) /* When it uses IMAGE_HEADER_SIZE 256, e.g. ED25519, EC256, EC384 or EC512 */
0xfffd0000: Swap sector 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:<wolfBoot>/tools/keytools
$ keygen --ecc256 -g ./pri-ecc256.der $ keygen --ecc256 -g ./pri-ecc256.der
``` ```
This generates a pair of private and public keys with -g option. The private key is stored 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 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. 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 If you have an existing key pair, you can use -i option to import the pablic
key to the store. 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 --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). 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 (app_RenesasRx01.bin) by rx-elf-objcopy.exe command as follows. -R are for eliminate unnecessary
secrions. 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. Now, you can download and start wolfBoot program by e2Studio debugger.
After starting the program, you can see the partition information as follows. After starting the program, you can see the partition information as follows.
If the boot program succeeds integrity and authenticity check, it initiate the 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] === === Boot Partition[ffc10000] ===
Magic: WOLF Magic: WOLF
Version: 01 Version: 01
Status: ff Status: ff (New)
Tail Mgc: ???? Tail Mgc: <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
=== Update Partition[ffdf0000] === === Update Partition[ffdf8000] ===
Magic: WOLF Magic: <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Version: 02 Version: 00
Status: ff Status: ff (New)
Tail Mgc: ???? Tail Mgc: <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Current Firmware Version: 1 Current Firmware Version: 1
Hit any key to call wolfBoot_success the firmware. Hit any key to call wolfBoot_success the firmware.
``` ```
After hitting any key, the application calls wolfBoot_success() to set boot partition After hitting any key, the application calls wolfBoot_success() to set boot partition
state and wait for any key again. 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").
``` ```
=== Boot Partition[ffc10000] === === Boot Partition[ffc10000] ===
Magic: WOLF Magic: WOLF
Version: 01 Version: 01
Status: 00 Status: 00 (Success)
Tail Mgc: BOOT Tail Mgc: BOOT
=== Update Partition[ffdf0000] === === Update Partition[ffdf8000] ===
Magic: WOLF Magic: <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Version: 02 Version: 00
Status: ff Status: 00 (Success)
Tail Mgc: ???? 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 ### 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. You can download it by the flash programmer.
``` ```
$ sign --ecc256 app_RenesasRx01.bin ../../../../../pri-ecc256.der 2.0 $ 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. 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 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 Current Firmware Version: 1
....
Hit any key to update the firmware. Hit any key to update the firmware.
Firmware Update is triggered
``` ```
After you see the message, hit any key so that the application calls After you see the message, hit any key so that the application calls
wolfBoot_update_trigger() which changes the partition status and triggers 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: <20><><EFBFBD><EFBFBD>
Version: 00
Status: 70 (Updating)
Tail Mgc: BOOT
```
Since this is just a trigger, the application can continue the process. 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 In the demo application it outputs a message "Firmware Update is triggered" and enters
@ -291,11 +303,11 @@ Version: 02
Status: 10 Status: 10
Tail Mgc: BOOT Tail Mgc: BOOT
=== Update Partition[ffdf0000] === === Update Partition[ffdf8000] ===
Magic: WOLF Magic: WOLF
Version: 01 Version: 01
Status: ff Status: 30
Tail Mgc: ???? Tail Mgc: BOOT
Current Firmware Version: 2 Current Firmware Version: 2
``` ```

View File

@ -28,6 +28,17 @@
#include "hal.h" #include "hal.h"
#include "wolfboot/wolfboot.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) static void printPart(uint8_t *part)
{ {
#ifdef WOLFBOOT_DEBUG_PARTION #ifdef WOLFBOOT_DEBUG_PARTION
@ -43,7 +54,7 @@ static void printPart(uint8_t *part)
ver = wolfBoot_get_blob_version(part); ver = wolfBoot_get_blob_version(part);
printf("Version: %02x\n", ver); printf("Version: %02x\n", ver);
state = *(part + WOLFBOOT_PARTITION_SIZE - sizeof(uint32_t) - 1); 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); magic = part + WOLFBOOT_PARTITION_SIZE - sizeof(uint32_t);
printf("Tail Mgc: %c%c%c%c\n", magic[0], magic[1], magic[2], magic[3]); 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(); wolfBoot_update_trigger();
printf("Firmware Update is triggered\n"); 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 { } else {
printf("Invalid Firmware Version\n"); printf("Invalid Firmware Version\n");

View File

@ -67,9 +67,9 @@
#define WOLFBOOT_PARTITION_SWAP_ADDRESS 0x0 #define WOLFBOOT_PARTITION_SWAP_ADDRESS 0x0
#else #else
#define WOLFBOOT_BOOT_SIZE 0x20000 #define WOLFBOOT_BOOT_SIZE 0x10000
#define WOLFBOOT_RX_EXCVECT 0x10000 #define WOLFBOOT_RX_EXCVECT 0x10000
#define WOLFBOOT_SECTOR_SIZE 0x20000 #define WOLFBOOT_SECTOR_SIZE 0x10000
#define WOLFBOOT_PARTITION_SIZE\ #define WOLFBOOT_PARTITION_SIZE\
((WOLFBOOT_FLASH_SIZE - WOLFBOOT_BOOT_SIZE -\ ((WOLFBOOT_FLASH_SIZE - WOLFBOOT_BOOT_SIZE -\

View File

@ -0,0 +1,37 @@
<?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">
<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"/>
<sections name="R_2"/>
<sections name="B"/>
<sections name="R"/>
<sections name="B_8"/>
<sections name="R_8"/>
<sections name="RPFRAM"/>
<sections name="RPFRAM2"/>
<sections name="PResetPRG">
<sectionAddress xsi:type="com.renesas.linkersection.model:FixedAddress" fixedAddress="4290839040"/>
</sections>
<sections name="C_1"/>
<sections name="C_2"/>
<sections name="C"/>
<sections name="C_8"/>
<sections name="C$*"/>
<sections name="D*"/>
<sections name="W*"/>
<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>
<sections name="RESETVECT">
<sectionAddress xsi:type="com.renesas.linkersection.model:FixedAddress" fixedAddress="4294967292"/>
</sections>
</com.renesas.linkersection.model:SectionContainer>

View File

@ -0,0 +1,37 @@
<?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">
<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"/>
<sections name="R_2"/>
<sections name="B"/>
<sections name="R"/>
<sections name="B_8"/>
<sections name="R_8"/>
<sections name="RPFRAM"/>
<sections name="RPFRAM2"/>
<sections name="PResetPRG">
<sectionAddress xsi:type="com.renesas.linkersection.model:FixedAddress" fixedAddress="4291232256"/>
</sections>
<sections name="C_1"/>
<sections name="C_2"/>
<sections name="C"/>
<sections name="C_8"/>
<sections name="C$*"/>
<sections name="D*"/>
<sections name="W*"/>
<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>
<sections name="RESETVECT">
<sectionAddress xsi:type="com.renesas.linkersection.model:FixedAddress" fixedAddress="4294967292"/>
</sections>
</com.renesas.linkersection.model:SectionContainer>

View File

@ -23,7 +23,7 @@ if [ $# -ne 4 ];then
fi fi
VER1_ADDR=0xffc10000 VER1_ADDR=0xffc10000
VER2_ADDR=0xffdf0000 VER2_ADDR=0xffdf8000
# signature method # signature method
RSA2048_SIGN="rsa2048" RSA2048_SIGN="rsa2048"
@ -78,21 +78,21 @@ if [ $TSIPUSE -eq 1 -o $TSIPUSE -eq 2 ]; then
fi fi
echo "Version 1 app start address : " $VER1_ADDR echo "Version 1 app start address : " $VER1_ADDR
echo "Version 2 app start address : " $VER2_ADDR echo "Version 2 app start address : " $VER2_ADDR
echo "Signature method : " $SIGN_METHOD echo "Signature method : " $SIGN_METHOD
echo echo
echo COPY app_RenesasRx01.x to RXELF_BIN_DIR to convert bin file echo COPY app_RenesasRx01.x to RXELF_BIN_DIR to convert bin file
cp ${APP_RX}/HardwareDebug/app_RenesasRx01.x "${RXELF_BIN_DIR}" cp ${APP_RX}/HardwareDebug/app_RenesasRx01.x "${RXELF_BIN_DIR}"
pushd "${RXELF_BIN_DIR}" pushd "${RXELF_BIN_DIR}"
echo echo
echo Run rx-elf-objcopy.exe to generate bin 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 "${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 echo copy app_RenesasRx01.bin to wolfBoot folder to sign
cp app_RenesasRx01.bin ${WOLFBOOT_DIR} cp app_RenesasRx01.bin ${WOLFBOOT_DIR}
@ -102,34 +102,34 @@ echo "generate key"
keygen --${SIGN_METHOD} -g ./pri-${SIGN_METHOD}.der keygen --${SIGN_METHOD} -g ./pri-${SIGN_METHOD}.der
echo echo
echo sign app_RenesasRx01.bin for version 1 echo sign app_RenesasRx01.bin for version 1
sign --${SIGN_METHOD}${SIGN_METHOD_EX} app_RenesasRx01.bin ./pri-${SIGN_METHOD}.der 1.0 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 echo sign app_RenesasRx01.bin for version 2
sign --${SIGN_METHOD}${SIGN_METHOD_EX} app_RenesasRx01.bin ./pri-${SIGN_METHOD}.der 2.0 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 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_v1.0_signed.bin "${RXELF_BIN_DIR}"
cp app_RenesasRx01_v2.0_signed.bin "${RXELF_BIN_DIR}" cp app_RenesasRx01_v2.0_signed.bin "${RXELF_BIN_DIR}"
popd popd
echo echo
echo Run rx-elf-objcopy.exe to generate hex for version 1 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 "${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 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 "${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} echo move *.hex to ${CURRENT}
mv app_RenesasRx01_v1.0_signed.hex app_RenesasRx01_v2.0_signed.hex ${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 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 rm -rf app_RenesasRx01.x app_RenesasRx01.bin app_RenesasRx01_v1.0_signed.bin app_RenesasRx01_v2.0_signed.bin
popd popd

View File

@ -129,6 +129,8 @@ const char Cfile_Banner[]="/* Keystore file for wolfBoot, automatically generate
const char Store_hdr[] = "\n" const char Store_hdr[] = "\n"
"#if defined(__APPLE__) && defined(__MACH__)\n" "#if defined(__APPLE__) && defined(__MACH__)\n"
"#define KEYSTORE_SECTION __attribute__((section (\"__KEYSTORE,__keystore\")))\n" "#define KEYSTORE_SECTION __attribute__((section (\"__KEYSTORE,__keystore\")))\n"
"#elif defined(__CCRX__)\n"
"#define KEYSTORE_SECTION\n"
"#else\n" "#else\n"
"#define KEYSTORE_SECTION __attribute__((section (\".keystore\")))\n" "#define KEYSTORE_SECTION __attribute__((section (\".keystore\")))\n"
"#endif\n\n" "#endif\n\n"