Skip to content

Commit c6f6ce8

Browse files
authored
Merge pull request #40 from wolfSSL/iar
Example workspace/project to build under IAR
2 parents 2ce2949 + 0beb343 commit c6f6ce8

30 files changed

Lines changed: 11384 additions & 305 deletions

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ src/rsa4096_pub_key.c
5757

5858
# keygen binaries
5959
tools/keytools/sign
60+
tools/keytools/keygen
6061

6162
# Vim swap files
6263
.*.swp
@@ -84,3 +85,8 @@ config/*.ld
8485
.vs
8586
*.filters
8687
*.user
88+
89+
# IAR files not under version control
90+
IDE/IAR/settings
91+
IDE/IAR/*.ewt
92+

IDE/IAR/README.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# wolfBoot demo application for IAR EWARM
2+
3+
Instruction to compile and test under MS Windows.
4+
5+
6+
## Target platform
7+
8+
This example application has been configured to work on STM32F4.
9+
10+
wolfBoot is stored and executed at the beginning of the flash (0x08000000), while the signed
11+
application image starts at address 0x08020000.
12+
13+
14+
15+
## Workspace
16+
17+
The workspace [wolfboot-test-app.eww](./wolfboot-test-app.eww) contains two projects:
18+
- wolfBoot
19+
- wolfBoot-test-app
20+
21+
Each project will compile into a separate binary, the two binaries can be uploaded to the target using
22+
ST-Link utilities (e.g. [STSW-LINK004](https://www.st.com/en/development-tools/stsw-link004.html)) as explained below.
23+
24+
## Instructions
25+
26+
### Creating the keys
27+
28+
This step is required to compile the bootloader.
29+
30+
Open a command line terminal in the [IAR](./) directory. Execute the following script:
31+
32+
```
33+
generate_key.bat
34+
35+
```
36+
37+
The script will generate a keypair. The file `ecc256.der` in the root of the repository contains the private key that will be used
38+
to sign valid firmware images. The file `src/ecc256_pub_key.c` now contains the public key that the bootloader embeds in its codebase
39+
to use it later to verify the image.
40+
41+
42+
### Compiling and linking the images
43+
44+
Now both projects (wolfboot and wolfboot-test-app) can be compiled and linked.
45+
The two resulting images will be placed in the output directory `Debug/Exe`:
46+
- wolfboot.bin
47+
- wolfboot-test-app.bin
48+
49+
### Signing the firmware image
50+
51+
The test application (main firmware) must be now tagged with a version number and signed. This is done by the script `sign_test_app.bat`.
52+
53+
The script requires one numeric argument that is used as the version tag for the signed image. Running it with version "1":
54+
55+
```
56+
sign_test_app.bat 1
57+
```
58+
59+
Will create a new file named `wolfboot-test-app_v1_signed.bin`, which will be placed in the output directory `Debug/Exe`.
60+
61+
62+
### Uploading the binary images to the target
63+
64+
Using the ST-LINK Utility, perform the following steps:
65+
66+
1. Erase the entire flash memory
67+
68+
![Erase flash](../../docs/png/windows_erase.png)
69+
70+
*Erase the entire flash memory before uploading the binary files*
71+
72+
73+
2. Upload `wolfboot.bin` to addess 0x08000000
74+
75+
![Upload bootloader](../../docs/png/windows_upload_1.png)
76+
77+
78+
3. Upload `wolfboot-test-app_v1_signed.bin` to address 0x08020000. Ensure that the flag "Skip Flash Erase" is active.
79+
80+
![Upload firmware](../../docs/png/windows_upload_2.png)
81+
82+
83+
### Verify that the system is up and running
84+
85+
If you are using a STM32F407-discovery board, a red LED will turn on upon application boot.
86+
87+
88+

IDE/IAR/generate_key.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
keytools\keygen.exe --ecc256 ..\..\src\ecc256_pub_key.c
2+
move ecc256.der ..\..\

IDE/IAR/keys/ecc256.der

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
�w��J>ߑ`+.� l��]�)|���Z��6@i����D�IIUFG��4/�#+�g ?��U3d��*�����j�K�1Է޴[��8�/�r��}ѩ��

IDE/IAR/keys/ecc256_pub_key.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* This file has been generated and contains the public key which is
3+
* used by wolfBoot to verify the updates.
4+
*/
5+
#include <stdint.h>
6+
7+
#warning "USING PRE-GENERATED EXAMPLE ECC KEY -- BOOTLOADER IS NOT SECURE!"
8+
9+
10+
const uint8_t ecc256_pub_key[64] = {
11+
0xFA, 0x77, 0xAE, 0xC6, 0x4A, 0x3E, 0xDF, 0x91,
12+
0x60, 0x2B, 0x2E, 0x83, 0x12, 0x0C, 0x6C, 0x91,
13+
0x8C, 0x5D, 0xC2, 0x29, 0x7C, 0xB8, 0x91, 0xEA,
14+
0x5A, 0x12, 0xE0, 0x8E, 0x36, 0x40, 0x69, 0x8D,
15+
0xE1, 0xDC, 0xF6, 0x44, 0x7F, 0xD9, 0x16, 0x49,
16+
0x49, 0x55, 0x1F, 0x46, 0x47, 0xB7, 0x83, 0x34,
17+
0x04, 0x2F, 0x9B, 0x23, 0x2B, 0x84, 0x67, 0x09,
18+
0x3F, 0xFC, 0xCE, 0x55, 0x33, 0x64, 0xCB, 0xE8
19+
};
20+
const uint32_t ecc256_pub_key_len = 64;

IDE/IAR/keytools/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Pre-compiled Key management tools for windows (64bit)
2+
3+
Full sources available in the [keytools](../../../tools/keytools) directory in this repository.

IDE/IAR/keytools/keygen.exe

745 KB
Binary file not shown.

IDE/IAR/keytools/sign.exe

747 KB
Binary file not shown.

IDE/IAR/sign_test_app.bat

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
echo off
2+
3+
if "%~1"=="" goto fail
4+
5+
keytools\sign.exe --ecc256 --sha256 Debug\Exe\wolfboot-test-app.bin ..\..\ecc256.der %1
6+
7+
goto out
8+
9+
:fail
10+
echo please specify a version number.
11+
12+
:out
13+

IDE/IAR/test-app.icf

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*###ICF### Section handled by ICF editor, don't touch! ****/
2+
/*-Editor annotation file-*/
3+
/* IcfEditorFile="$TOOLKIT_DIR$\config\linker\ST\IcfEditor\stm32f40x_fsmc.xml" */
4+
/*-Specials-*/
5+
define symbol __ICFEDIT_intvec_start__ = 0x08020100;
6+
/*-Memory Regions-*/
7+
define symbol __ICFEDIT_region_FLASH_start__ = 0x08020100;
8+
define symbol __ICFEDIT_region_FLASH_end__ = 0x0803FFFF;
9+
define symbol __ICFEDIT_region_FSMC11_start__ = 0x0;
10+
define symbol __ICFEDIT_region_FSMC11_end__ = 0x0;
11+
define symbol __ICFEDIT_region_FSMC12_start__ = 0x0;
12+
define symbol __ICFEDIT_region_FSMC12_end__ = 0x0;
13+
define symbol __ICFEDIT_region_FSMC13_start__ = 0x0;
14+
define symbol __ICFEDIT_region_FSMC13_end__ = 0x0;
15+
define symbol __ICFEDIT_region_FSMC14_start__ = 0x0;
16+
define symbol __ICFEDIT_region_FSMC14_end__ = 0x0;
17+
define symbol __ICFEDIT_region_NAND1_start__ = 0x0;
18+
define symbol __ICFEDIT_region_NAND1_end__ = 0x0;
19+
define symbol __ICFEDIT_region_NAND2_start__ = 0x0;
20+
define symbol __ICFEDIT_region_NAND2_end__ = 0x0;
21+
define symbol __ICFEDIT_region_PCARD_start__ = 0x0;
22+
define symbol __ICFEDIT_region_PCARD_end__ = 0x0;
23+
define symbol __ICFEDIT_region_CCRAM_start__ = 0x10000000;
24+
define symbol __ICFEDIT_region_CCRAM_end__ = 0x1000FFFF;
25+
define symbol __ICFEDIT_region_SRAM1_start__ = 0x20000000;
26+
define symbol __ICFEDIT_region_SRAM1_end__ = 0x2001BFFF;
27+
define symbol __ICFEDIT_region_SRAM2_start__ = 0x2001C000;
28+
define symbol __ICFEDIT_region_SRAM2_end__ = 0x2001FFFF;
29+
define symbol __ICFEDIT_region_BKPR_start__ = 0x40024000;
30+
define symbol __ICFEDIT_region_BKPR_end__ = 0x40024FFF;
31+
/*-Sizes-*/
32+
define symbol __ICFEDIT_size_cstack__ = 0x2000;
33+
define symbol __ICFEDIT_size_heap__ = 0x2000;
34+
/**** End of ICF editor section. ###ICF###*/
35+
36+
define memory mem with size = 4G;
37+
define region FLASH_region = mem:[from __ICFEDIT_region_FLASH_start__ to __ICFEDIT_region_FLASH_end__ ];
38+
define region FSMC_region = mem:[from __ICFEDIT_region_FSMC11_start__ to __ICFEDIT_region_FSMC11_end__]
39+
| mem:[from __ICFEDIT_region_FSMC12_start__ to __ICFEDIT_region_FSMC12_end__]
40+
| mem:[from __ICFEDIT_region_FSMC13_start__ to __ICFEDIT_region_FSMC13_end__]
41+
| mem:[from __ICFEDIT_region_FSMC14_start__ to __ICFEDIT_region_FSMC14_end__];
42+
define region NAND_region = mem:[from __ICFEDIT_region_NAND1_start__ to __ICFEDIT_region_NAND1_end__ ]
43+
| mem:[from __ICFEDIT_region_NAND2_start__ to __ICFEDIT_region_NAND2_end__ ];
44+
define region PCARD_region = mem:[from __ICFEDIT_region_PCARD_start__ to __ICFEDIT_region_PCARD_end__ ];
45+
define region CCRAM_region = mem:[from __ICFEDIT_region_CCRAM_start__ to __ICFEDIT_region_CCRAM_end__ ];
46+
define region SRAM_region = mem:[from __ICFEDIT_region_SRAM1_start__ to __ICFEDIT_region_SRAM1_end__ ]
47+
| mem:[from __ICFEDIT_region_SRAM2_start__ to __ICFEDIT_region_SRAM2_end__ ];
48+
define region BKPR_region = mem:[from __ICFEDIT_region_BKPR_start__ to __ICFEDIT_region_BKPR_end__ ];
49+
50+
define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { };
51+
define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { };
52+
53+
initialize by copy { readwrite };
54+
//initialize by copy with packing = none { section __DLIB_PERTHREAD }; // Required in a multi-threaded application
55+
56+
place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };
57+
58+
place in FLASH_region { readonly };
59+
place in PCARD_region { readonly section application_specific_ro };
60+
place in CCRAM_region { section .ccram };
61+
place in SRAM_region { readwrite, block CSTACK, block HEAP };
62+
place in BKPR_region { section .backup_sram };

0 commit comments

Comments
 (0)