Skip to content
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

fix and update rx72n port #384

Merged
merged 1 commit into from
Oct 25, 2023
Merged
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
82 changes: 47 additions & 35 deletions IDE/Renesas/e2studio/RX72N/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```

Expand Down Expand Up @@ -75,13 +76,13 @@ $ export PATH:$PATH:<wolfBoot>/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
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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.


```
Expand All @@ -201,73 +202,84 @@ 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
```


### 3-9 Re-boot and secure update to V2

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.

```
| ------------------------------------------------------------------- |
| Renesas RX User Application in BOOT partition started by wolfBoot |
| ------------------------------------------------------------------- |

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
Expand All @@ -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
```
Expand Down
21 changes: 20 additions & 1 deletion IDE/Renesas/e2studio/RX72N/app_RenesasRX01/src/app_RenesasRX01.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]);

Expand Down Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions IDE/Renesas/e2studio/RX72N/include/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 -\
Expand Down
37 changes: 37 additions & 0 deletions IDE/Renesas/e2studio/RX72N/resouce/section_info_SWuse.esi
Original file line number Diff line number Diff line change
@@ -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>
37 changes: 37 additions & 0 deletions IDE/Renesas/e2studio/RX72N/resouce/section_info_TSIPuse.esi
Original file line number Diff line number Diff line change
@@ -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>
26 changes: 13 additions & 13 deletions IDE/Renesas/e2studio/RX72N/x2hex.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if [ $# -ne 4 ];then
fi

VER1_ADDR=0xffc10000
VER2_ADDR=0xffdf0000
VER2_ADDR=0xffdf8000

# signature method
RSA2048_SIGN="rsa2048"
Expand Down Expand Up @@ -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}

Expand All @@ -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
2 changes: 2 additions & 0 deletions tools/keytools/keygen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading