Skip to content

Commit f43b9eb

Browse files
committed
Add secure call user callback
1 parent 2ece61c commit f43b9eb

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

trustzone/hello_trustzone/nonsecure.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include "hardware/clocks.h"
44
#include "pico/stdlib.h"
55

6+
#include "secure_call_user_callbacks.h"
7+
68
bool repeating_timer_callback(__unused struct repeating_timer *t) {
79
printf("NS Repeat at %lld\n", time_us_64());
810
return true;
@@ -27,6 +29,7 @@ int main() {
2729

2830
for (int i=0; i < 10; i++) {
2931
printf("Hello, world, from non-secure!\n");
32+
rom_secure_call(1, 2, 3, i, SECURE_CALL_PRINT_VALUES);
3033
sleep_ms(1000);
3134
}
3235

trustzone/hello_trustzone/secure.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "hardware/watchdog.h"
55
#include "pico/secure.h"
66

7+
#include "secure_call_user_callbacks.h"
8+
79

810
bool repeating_timer_callback(__unused struct repeating_timer *t) {
911
watchdog_update();
@@ -23,6 +25,17 @@ void hardfault_callback(void) {
2325
}
2426

2527

28+
int secure_call_user_callback(uint32_t a, uint32_t b, uint32_t c, uint32_t d, uint32_t fn) {
29+
switch (fn) {
30+
case SECURE_CALL_PRINT_VALUES:
31+
printf("NS called secure_call with %d %d %d %d\n", a, b, c, d);
32+
return BOOTROM_OK;
33+
default:
34+
return BOOTROM_ERROR_INVALID_ARG;
35+
}
36+
}
37+
38+
2639
int main()
2740
{
2841
stdio_init_all();
@@ -38,6 +51,9 @@ int main()
3851
watchdog_enable(1100, true);
3952
add_repeating_timer_ms(-1000, repeating_timer_callback, NULL, &timer);
4053

54+
// Create user callback
55+
rom_secure_call_add_user_callback(secure_call_user_callback, SECURE_CALL_CALLBACKS_MASK);
56+
4157
// Get boot partition
4258
boot_info_t info;
4359
rom_get_boot_info(&info);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma once
2+
3+
#define SECURE_CALL_CALLBACKS_MASK 0xfedc
4+
5+
#define SECURE_CALL_PRINT_VALUES ((SECURE_CALL_CALLBACKS_MASK << 16) | 0x1)

0 commit comments

Comments
 (0)