Skip to content

Commit

Permalink
suit: Add "enter recovery button"
Browse files Browse the repository at this point in the history
This commit adds code allowing to enter SUIT foreground update
(in most cases the same as recovery) mode via keeping
a button pressed during system bootup.

Signed-off-by: Artur Hadasz <artur.hadasz@nordicsemi.no>
  • Loading branch information
ahasztag committed Nov 7, 2024
1 parent 7f9dd01 commit 9d902ff
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 0 deletions.
6 changes: 6 additions & 0 deletions samples/suit/smp_transfer/sysbuild/recovery.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@
*/

#include "../boards/nrf54h20dk_nrf54h20_cpuapp_common.dtsi"

/ {
chosen {

Check warning on line 10 in samples/suit/smp_transfer/sysbuild/recovery.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

samples/suit/smp_transfer/sysbuild/recovery.overlay:10 please, no spaces at the start of a line
recovery-button = &button0;

Check failure on line 11 in samples/suit/smp_transfer/sysbuild/recovery.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

samples/suit/smp_transfer/sysbuild/recovery.overlay:11 code indent should use tabs where possible

Check warning on line 11 in samples/suit/smp_transfer/sysbuild/recovery.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

samples/suit/smp_transfer/sysbuild/recovery.overlay:11 please, no spaces at the start of a line
};

Check warning on line 12 in samples/suit/smp_transfer/sysbuild/recovery.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

samples/suit/smp_transfer/sysbuild/recovery.overlay:12 please, no spaces at the start of a line
};
1 change: 1 addition & 0 deletions subsys/suit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ add_subdirectory_ifdef(CONFIG_SUIT_DFU orchestrator_app)
add_subdirectory_ifdef(CONFIG_SUIT_ENVELOPE_INFO envelope_info)
add_subdirectory_ifdef(CONFIG_SUIT_EXECUTION_MODE execution_mode)
add_subdirectory_ifdef(CONFIG_SUIT_VALIDATOR validator)
add_subdirectory_ifdef(CONFIG_SUIT_RECOVERY_BUTTON recovery_button)
2 changes: 2 additions & 0 deletions subsys/suit/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,12 @@ rsource "envelope_info/Kconfig"
rsource "execution_mode/Kconfig"
rsource "memory_layout/Kconfig"
rsource "validator/Kconfig"
rsource "recovery_button/Kconfig"

# Configure SUIT_LOG_LEVEL
module = SUIT
module-str = Software Updates for Internet of Things
source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"


endif # SUIT
11 changes: 11 additions & 0 deletions subsys/suit/recovery_button/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

zephyr_library()
zephyr_library_sources(src/suit_recovery_button.c)

zephyr_library_link_libraries(suit_platform_err)
zephyr_library_link_libraries(suit_utils)
16 changes: 16 additions & 0 deletions subsys/suit/recovery_button/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

menuconfig SUIT_RECOVERY_BUTTON
bool "Enable SUIT enter recovery button checking on startup"
depends on $(dt_chosen_enabled,recovery-button)
help
This will make the firmware check if the recovery button specified in the
device tree is pressed on startup. If it is, the firmware will enter
the "foreground update mode", in which the same SUIT manifests are booted
as in case of the recovery mode.

select SSF_SUIT_SERVICE_ENABLED
59 changes: 59 additions & 0 deletions subsys/suit/recovery_button/src/suit_recovery_button.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>
#include <nrfx_gpiote.h>
#include <sdfw/sdfw_services/suit_service.h>

#define RECOVERY_BUTTON_NODE DT_CHOSEN(recovery_button)
#define RECOVERY_BUTTON_PIN DT_GPIO_PIN(RECOVERY_BUTTON_NODE, gpios)
#define RECOVERY_BUTTON_PORT_NUM DT_PROP(DT_GPIO_CTLR(RECOVERY_BUTTON_NODE, gpios), port)
#define RECOVERY_BUTTON_FLAGS DT_GPIO_FLAGS(RECOVERY_BUTTON_NODE, gpios)

#define RECOVERY_BUTTON_ABS_PIN NRF_GPIO_PIN_MAP(RECOVERY_BUTTON_PORT_NUM, RECOVERY_BUTTON_PIN)
#define RECOVERY_BUTTON_PULL (RECOVERY_BUTTON_FLAGS & GPIO_PULL_UP ? NRF_GPIO_PIN_PULLUP : \
RECOVERY_BUTTON_FLAGS & GPIO_PULL_DOWN ? NRF_GPIO_PIN_PULLDOWN : \
NRF_GPIO_PIN_NOPULL)

#define RECOVERY_BUTTON_PRESSED(pin_value) (RECOVERY_BUTTON_FLAGS & GPIO_ACTIVE_LOW ? (!pin_value) \
: pin_value)

BUILD_ASSERT(DT_NODE_EXISTS(DT_CHOSEN(recovery_button)), "No recovery button chosen in dts");

static int recovery_button_check(void)
{
suit_boot_mode_t mode = SUIT_BOOT_MODE_INVOKE_RECOVERY;
suit_ssf_err_t err = SUIT_PLAT_SUCCESS;

err = suit_boot_mode_read(&mode);

if (err != SUIT_PLAT_SUCCESS) {
suit_invoke_confirm(-EPIPE);
return -EPIPE;
}

if (mode == SUIT_BOOT_MODE_INVOKE) {
nrf_gpio_pin_dir_t dir = NRF_GPIO_PIN_DIR_INPUT;
nrf_gpio_pin_input_t input = NRF_GPIO_PIN_INPUT_CONNECT;
nrf_gpio_pin_pull_t pull = RECOVERY_BUTTON_PULL;

nrf_gpio_reconfigure(RECOVERY_BUTTON_ABS_PIN, &dir, &input, &pull, NULL, NULL);

uint32_t pin_value = nrf_gpio_pin_read(RECOVERY_BUTTON_ABS_PIN);
if (RECOVERY_BUTTON_PRESSED(pin_value)) {

Check warning on line 47 in subsys/suit/recovery_button/src/suit_recovery_button.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LINE_SPACING

subsys/suit/recovery_button/src/suit_recovery_button.c:47 Missing a blank line after declarations
suit_foreground_dfu_required();
}
else

Check failure on line 50 in subsys/suit/recovery_button/src/suit_recovery_button.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

OPEN_BRACE

subsys/suit/recovery_button/src/suit_recovery_button.c:50 that open brace { should be on the previous line

Check failure on line 50 in subsys/suit/recovery_button/src/suit_recovery_button.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

ELSE_AFTER_BRACE

subsys/suit/recovery_button/src/suit_recovery_button.c:50 else should follow close brace '}'
{
suit_invoke_confirm(0);
}
}

return 0;

Check warning on line 56 in subsys/suit/recovery_button/src/suit_recovery_button.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

subsys/suit/recovery_button/src/suit_recovery_button.c:56 please, no spaces at the start of a line
}

SYS_INIT(recovery_button_check, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);

0 comments on commit 9d902ff

Please sign in to comment.