From 2a1bf197e114aba997d180563c539e1681160f2b Mon Sep 17 00:00:00 2001 From: tychovrahe Date: Wed, 18 Dec 2024 09:58:06 +0100 Subject: [PATCH] feat(ble): integrate MCU boot into trezor-ble app, add stay in bootloader pin [no changelog] --- west/trezor/README.md | 2 +- .../t3w1_revA_nrf52832/t3w1_revA_nrf52832.dts | 21 +++++---------- .../mcuboot.conf.without_serial_recovery | 25 ----------------- west/trezor/trezor-ble/prj.conf | 5 ++++ west/trezor/trezor-ble/src/main.c | 27 +++++++++---------- west/trezor/trezor-ble/sysbuild.conf | 5 ++++ .../trezor-ble/{ => sysbuild}/mcuboot.conf | 2 ++ west/trezor/west.yml | 4 --- 8 files changed, 32 insertions(+), 59 deletions(-) delete mode 100644 west/trezor/trezor-ble/mcuboot.conf.without_serial_recovery create mode 100644 west/trezor/trezor-ble/sysbuild.conf rename west/trezor/trezor-ble/{ => sysbuild}/mcuboot.conf (90%) diff --git a/west/trezor/README.md b/west/trezor/README.md index 76a691f0f1..bfa505e9ea 100644 --- a/west/trezor/README.md +++ b/west/trezor/README.md @@ -61,7 +61,7 @@ west update Build the application for the t3w1_revA_nrf52832 board: ```sh cd trezor -west build ./trezor-ble -b t3w1_revA_nrf52832 +west build ./trezor-ble -b t3w1_revA_nrf52832 --sysbuild ``` diff --git a/west/trezor/boards/arm/t3w1_revA_nrf52832/t3w1_revA_nrf52832.dts b/west/trezor/boards/arm/t3w1_revA_nrf52832/t3w1_revA_nrf52832.dts index 0345e59760..bc700d196e 100644 --- a/west/trezor/boards/arm/t3w1_revA_nrf52832/t3w1_revA_nrf52832.dts +++ b/west/trezor/boards/arm/t3w1_revA_nrf52832/t3w1_revA_nrf52832.dts @@ -27,28 +27,24 @@ leds { compatible = "gpio-leds"; led0: led_0 { - gpios = <&gpio0 12 GPIO_ACTIVE_LOW>; + gpios = <&gpio0 25 GPIO_ACTIVE_HIGH>; label = "Green LED 0"; }; led1: led_1 { - gpios = <&gpio0 14 GPIO_ACTIVE_LOW>; + gpios = <&gpio0 12 GPIO_ACTIVE_HIGH>; label = "Green LED 1"; }; - out0: out_0 { - gpios = <&gpio0 25 GPIO_ACTIVE_HIGH>; - label = "FW Running"; - }; }; buttons { compatible = "gpio-keys"; button0: button_0 { - gpios = <&gpio0 27 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + gpios = <&gpio0 14 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>; label = "Push button switch 0"; zephyr,code = ; }; trezor_ready: trezor_ready { - gpios = <&gpio0 29 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>; + gpios = <&gpio0 29 ( GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>; label = "Trezor ready"; zephyr,code = ; }; @@ -59,9 +55,8 @@ led0 = &led0; led1 = &led1; sw0 = &button0; - bootloader-led0 = &led0; + bootloader-botton0 = &button0; mcuboot-button0 = &button0; - mcuboot-led0 = &led0; watchdog0 = &wdt0; }; }; @@ -118,11 +113,7 @@ }; slot0_partition: partition@c000 { label = "image-0"; - reg = <0x0000C000 0x37000>; - }; - slot1_partition: partition@43000 { - label = "image-1"; - reg = <0x00043000 0x37000>; + reg = <0x0000C000 0x7A000>; }; storage_partition: partition@7a000 { label = "storage"; diff --git a/west/trezor/trezor-ble/mcuboot.conf.without_serial_recovery b/west/trezor/trezor-ble/mcuboot.conf.without_serial_recovery deleted file mode 100644 index 4682152457..0000000000 --- a/west/trezor/trezor-ble/mcuboot.conf.without_serial_recovery +++ /dev/null @@ -1,25 +0,0 @@ -#CONFIG_PM_PARTITION_SIZE_MCUBOOT=0x10000 - -#CONFIG_SERIAL=y -#CONFIG_UART_LINE_CTRL=y -#CONFIG_UART_NRFX=y -#CONFIG_UART_INTERRUPT_DRIVEN=n - -# MCUBoot serial -CONFIG_GPIO=y -CONFIG_GPIO_NRFX_INTERRUPT=n -#CONFIG_MCUBOOT_SERIAL=y -#CONFIG_BOOT_SERIAL_CDC_ACM=y -#CONFIG_BOOT_SERIAL_UART=y - -#CONFIG_LOG_BACKEND_UART=y - -#CONFIG_BOOT_SERIAL_DETECT_PIN=11 -#CONFIG_MCUMGR_SMP_UART=y -CONFIG_MCUBOOT_BOOTLOADER_MODE_SINGLE_APP=y -CONFIG_SINGLE_APPLICATION_SLOT=y - -CONFIG_RTT_CONSOLE=y -CONFIG_USE_SEGGER_RTT=y -CONFIG_UART_CONSOLE=n - diff --git a/west/trezor/trezor-ble/prj.conf b/west/trezor/trezor-ble/prj.conf index 73820932c1..07a21bcffe 100644 --- a/west/trezor/trezor-ble/prj.conf +++ b/west/trezor/trezor-ble/prj.conf @@ -89,3 +89,8 @@ CONFIG_LOG_PRINTK=n CONFIG_NANOPB=n CONFIG_ASSERT=y + + +# bootloader +#CONFIG_SECURE_BOOT=y +CONFIG_BOOTLOADER_MCUBOOT=y diff --git a/west/trezor/trezor-ble/src/main.c b/west/trezor/trezor-ble/src/main.c index fe4f8d5598..b3ec826300 100644 --- a/west/trezor/trezor-ble/src/main.c +++ b/west/trezor/trezor-ble/src/main.c @@ -46,8 +46,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #define RUN_STATUS_LED DK_LED1 #define RUN_LED_BLINK_INTERVAL 1000 -#define FW_RUNNING_SIG DK_LED3 -#define CON_STATUS_LED DK_LED2 +#define FW_RUNNING_SIG DK_LED2 static K_SEM_DEFINE(ble_init_ok, 0, 1); static K_SEM_DEFINE(led_init_ok, 0, 1); @@ -231,7 +230,7 @@ void ble_write_thread(void) { } void led_thread(void) { - bool connected = false; +// bool connected = false; int blink_status = 0; /* Don't go any further until BLE is initialized */ k_sem_take(&led_init_ok, K_FOREVER); @@ -240,17 +239,17 @@ void led_thread(void) { blink_status++; dk_set_led(RUN_STATUS_LED, (blink_status) % 2); - connected = is_connected(); - - if (connected) { - dk_set_led_on(CON_STATUS_LED); - } else { - if (is_advertising() && !is_advertising_whitelist()) { - dk_set_led(CON_STATUS_LED, (blink_status) % 2); - } else { - dk_set_led_off(CON_STATUS_LED); - } - } +// connected = is_connected(); +// +// if (connected) { +// dk_set_led_on(CON_STATUS_LED); +// } else { +// if (is_advertising() && !is_advertising_whitelist()) { +// dk_set_led(CON_STATUS_LED, (blink_status) % 2); +// } else { +// dk_set_led_off(CON_STATUS_LED); +// } +// } k_sleep(K_MSEC(RUN_LED_BLINK_INTERVAL)); } diff --git a/west/trezor/trezor-ble/sysbuild.conf b/west/trezor/trezor-ble/sysbuild.conf new file mode 100644 index 0000000000..00dcdb4d4b --- /dev/null +++ b/west/trezor/trezor-ble/sysbuild.conf @@ -0,0 +1,5 @@ +# Sysbuild configuration file. + +# Enable MCUboot +SB_CONFIG_BOOTLOADER_MCUBOOT=y +SB_CONFIG_MCUBOOT_MODE_SINGLE_APP=y diff --git a/west/trezor/trezor-ble/mcuboot.conf b/west/trezor/trezor-ble/sysbuild/mcuboot.conf similarity index 90% rename from west/trezor/trezor-ble/mcuboot.conf rename to west/trezor/trezor-ble/sysbuild/mcuboot.conf index 13a3d5ed2f..cce9abfcc3 100644 --- a/west/trezor/trezor-ble/mcuboot.conf +++ b/west/trezor/trezor-ble/sysbuild/mcuboot.conf @@ -9,6 +9,7 @@ CONFIG_UART_NRFX=y CONFIG_GPIO=y CONFIG_GPIO_NRFX_INTERRUPT=n CONFIG_MCUBOOT_SERIAL=y +CONFIG_BOOT_MGMT_ECHO=y CONFIG_BOOT_SERIAL_CDC_ACM=y CONFIG_BOOT_SERIAL_UART=y @@ -18,6 +19,7 @@ CONFIG_BOOT_SERIAL_UART=y #CONFIG_MCUMGR_SMP_UART=y CONFIG_MCUBOOT_BOOTLOADER_MODE_SINGLE_APP=y CONFIG_SINGLE_APPLICATION_SLOT=y +CONFIG_BOOT_VALIDATE_SLOT0=y CONFIG_RTT_CONSOLE=y CONFIG_USE_SEGGER_RTT=y diff --git a/west/trezor/west.yml b/west/trezor/west.yml index 0a91db7e95..66e23f9871 100644 --- a/west/trezor/west.yml +++ b/west/trezor/west.yml @@ -15,7 +15,3 @@ manifest: repo-path: sdk-nrf revision: v2.7.0 import: true - - name: mcuboot - url: https://github.com/hiviah/mcuboot - path: bootloader/mcuboot - revision: edfe1e1465dbc698bf9a195816247913490ab391