This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf9160 non-secure boot hard-fault

Hi all,

I’m currently working with the nrf9160 sip on a bare metal firmware project. I know the official support path is only with Zephyr OS but I’m facing an issue I’m not able to solve so far.

I want to take advantage of the Trustzone feature, to do so I created a minimal bootloader running in secure zone and responsible for setting up part of the flash/SRAM and peripherals as non-secure before trying to jump in the non-secure application. For some reasons, the bootloader get a hard-fault when it tries to load the reset handler of the non-secure app.

In order to reduce the unknown, I ported the SPM sample code provided as reference to my bootloader. Here is the debug output I’m getting:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Flash region Domain Permissions
00 0x00000 0x08000 Secure rwxl
01 0x08000 0x10000 Secure rwxl
02 0x10000 0x18000 Secure rwxl
03 0x18000 0x20000 Secure rwxl
04 0x20000 0x28000 Secure rwxl
05 0x28000 0x30000 Secure rwxl
06 0x30000 0x38000 Secure rwxl
07 0x38000 0x40000 Secure rwxl
08 0x40000 0x48000 Non-Secure rwxl
09 0x48000 0x50000 Non-Secure rwxl
10 0x50000 0x58000 Non-Secure rwxl
11 0x58000 0x60000 Non-Secure rwxl
12 0x60000 0x68000 Non-Secure rwxl
13 0x68000 0x70000 Non-Secure rwxl
14 0x70000 0x78000 Non-Secure rwxl
15 0x78000 0x80000 Non-Secure rwxl
16 0x80000 0x88000 Non-Secure rwxl
17 0x88000 0x90000 Non-Secure rwxl
18 0x90000 0x98000 Non-Secure rwxl
19 0x98000 0xa0000 Non-Secure rwxl
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Here is the bootloader code:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
extern int main(void);
extern int early_boot(void);
#define APP_ADDR 0x40000
static void spm_configure_ns(const tz_nonsecure_setup_conf_t
*spm_ns_conf);
static void spm_config_flash(void);
static void spm_config_sram(void);
static bool usel_or_split(uint8_t id);
static int spm_config_peripheral(uint8_t id, bool dma_present);
static void spm_config_peripherals(void);
static void spm_jump(void)
static void spm_config(void);
extern unsigned long _sidata; /* start address for the initialization values of the .data section. defined in linker script */
extern unsigned long _sdata; /* start address for the .data section. defined in linker script */
extern unsigned long _edata; /* end address for the .data section. defined in linker script */
extern unsigned long _sbss; /* start address for the .bss section. defined in linker script */
extern unsigned long _ebss; /* end address for the .bss section. defined in linker script */
extern unsigned long _estack; /* end address for the .bss section. defined in linker script */
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Besides, initializing the non-secure flash/SRAM area and peripherals, is there anything else I should take of?