From 2bd96a95d06e59b292fb8cacac8196ede59c272d Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Thu, 7 Aug 2025 11:54:42 +0100 Subject: [PATCH 1/2] [nrf fromlist] boot: zephyr: Fix including asn1 when ed25519 is used Fixes wrongly including the asn1 MBEDTLS file when the Kconfig is set to not include it Upstream PR #: 2416 Signed-off-by: Jamie McCrae --- boot/zephyr/CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/boot/zephyr/CMakeLists.txt b/boot/zephyr/CMakeLists.txt index 2f47766e3..abb0f9a2d 100644 --- a/boot/zephyr/CMakeLists.txt +++ b/boot/zephyr/CMakeLists.txt @@ -309,8 +309,13 @@ elseif(CONFIG_BOOT_SIGNATURE_TYPE_ED25519 OR CONFIG_BOOT_ENCRYPT_X25519) ${FIAT_DIR}/src/curve25519.c ) else() + if(MBEDTLS_ASN1_DIR) + zephyr_library_sources( + ${MBEDTLS_ASN1_DIR}/src/asn1parse.c + ) + endif() + zephyr_library_sources( - ${MBEDTLS_ASN1_DIR}/src/asn1parse.c ${BOOT_DIR}/bootutil/src/ed25519_psa.c ) endif() From e158c072f337240b6e6ae9c049cafff84f9e572d Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Thu, 7 Aug 2025 11:58:29 +0100 Subject: [PATCH 2/2] [nrf noup] boot: zephyr: Fix bm IO button check nrf-squash! [nrf noup] boot: zephyr: Add bm firmware loader code Fixes IO in BM mode to use the hal directly rather than a library that increases the build size by 2.5KiB for a simple button check Signed-off-by: Jamie McCrae --- boot/zephyr/io_bm.c | 45 +++++++++------------------------------------ 1 file changed, 9 insertions(+), 36 deletions(-) diff --git a/boot/zephyr/io_bm.c b/boot/zephyr/io_bm.c index 3f65a5d0e..798cf7a3f 100644 --- a/boot/zephyr/io_bm.c +++ b/boot/zephyr/io_bm.c @@ -89,31 +89,13 @@ void io_led_set(int value) bool io_detect_pin(void) { - int rc; bool pin_active; - rc = bm_buttons_init( - &(struct bm_buttons_config){ - .pin_number = BOARD_PIN_BTN_0, - .active_state = BM_BUTTONS_ACTIVE_LOW, - .pull_config = BM_BUTTONS_PIN_PULLUP, - }, - 1, - BM_BUTTONS_DETECTION_DELAY_MIN_US); - if (rc) { - BOOT_LOG_ERR("Failed to initialize buttons: %d", rc); - return false; - } + nrf_gpio_cfg_input(BOARD_PIN_BTN_0, BM_BUTTONS_PIN_PULLUP); - rc = bm_buttons_enable(); - if (rc) { - BOOT_LOG_ERR("Failed to enable button detection: %d", rc); - return false; - } + pin_active = (bool)nrf_gpio_pin_read(BOARD_PIN_BTN_0); - pin_active = bm_buttons_is_pressed(BOARD_PIN_BTN_0); - - if (pin_active) { + if (!pin_active) { if (BUTTON_0_DETECT_DELAY > 0) { #ifdef CONFIG_MULTITHREADING k_sleep(K_MSEC(50)); @@ -125,13 +107,15 @@ bool io_detect_pin(void) int64_t timestamp = k_uptime_get(); for(;;) { - pin_active = bm_buttons_is_pressed(BOARD_PIN_BTN_0); + uint32_t delta; + + pin_active = (bool)nrf_gpio_pin_read(BOARD_PIN_BTN_0); /* Get delta from when this started */ - uint32_t delta = k_uptime_get() - timestamp; + delta = k_uptime_get() - timestamp; /* If not pressed OR if pressed > debounce period, stop. */ - if (delta >= BUTTON_0_DETECT_DELAY || !pin_active) { + if (delta >= BUTTON_0_DETECT_DELAY || pin_active) { break; } @@ -145,18 +129,7 @@ bool io_detect_pin(void) } } - rc = bm_buttons_disable(); - - if (rc) { - BOOT_LOG_ERR("Failed to disable buttons: %d", rc); - } - - rc = bm_buttons_deinit(); - if (rc) { - BOOT_LOG_ERR("Failed to de-initialize buttons: %d", rc); - } - - return (bool)pin_active; + return (bool)!pin_active; } #endif