Skip to content

Commit 718a823

Browse files
nvlsianpumbolivar-nordic
authored andcommitted
[nrf temphack] do_boot: clean peripherals state before boot
Do some cleanup of nRF peripherals. This is necessary since Zephyr doesn't have any driver deinitialization functionality, and we'd like to leave peripherals in a more predictable state before booting the Zephyr image. Signed-off-by: Andrzej Puzdrowski <[email protected]> Signed-off-by: Robert Lubos <[email protected]> Signed-off-by: Torsten Rasmussen <[email protected]> Signed-off-by: Øyvind Rønningstad <[email protected]> Signed-off-by: Martí Bolívar <[email protected]> Signed-off-by: Håkon Øye Amundsen <[email protected]> Signed-off-by: Ioannis Glaropoulos <[email protected]> Signed-off-by: Johann Fischer <[email protected]> (cherry picked from commit 18a0a8a) Signed-off-by: Trond Einar Snekvik <[email protected]> (cherry picked from commit eb3c812)
1 parent 81ab01a commit 718a823

File tree

5 files changed

+86
-1
lines changed

5 files changed

+86
-1
lines changed

boot/zephyr/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,3 +301,9 @@ zephyr_library_sources(
301301
${BOOT_DIR}/zephyr/arm_cleanup.c
302302
)
303303
endif()
304+
305+
if(CONFIG_MCUBOOT_NRF_CLEANUP_PERIPHERAL)
306+
zephyr_library_sources(
307+
${BOOT_DIR}/zephyr/nrf_cleanup.c
308+
)
309+
endif()

boot/zephyr/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ config MCUBOOT_CLEANUP_ARM_CORE
186186
by default, if they are chain-loadable by MCUboot, so MCUboot does
187187
not need to perform such a cleanup itself.
188188

189+
config MCUBOOT_NRF_CLEANUP_PERIPHERAL
190+
bool "Perform peripheral cleanup before chain-load the application"
191+
depends on SOC_FAMILY_NRF
192+
default y
193+
189194
config MBEDTLS_CFG_FILE
190195
default "mcuboot-mbedtls-cfg.h"
191196

boot/zephyr/include/nrf_cleanup.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (c) 2020 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
5+
*/
6+
7+
#ifndef H_NRF_CLEANUP_
8+
#define H_NRF_CLEANUP_
9+
10+
/**
11+
* Perform cleanup on some peripheral resources used by MCUBoot prior chainload
12+
* the application.
13+
*
14+
* This function disables all RTC instances and UARTE instances.
15+
* It Disables their interrupts signals as well.
16+
*/
17+
void nrf_cleanup_peripheral(void);
18+
19+
#endif

boot/zephyr/main.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ K_SEM_DEFINE(boot_log_sem, 1, 1);
9494
#include <pm_config.h>
9595
#endif
9696

97+
#if CONFIG_MCUBOOT_NRF_CLEANUP_PERIPHERAL
98+
#include <nrf_cleanup.h>
99+
#endif
100+
97101
#ifdef CONFIG_SOC_FAMILY_NRF
98102
#include <hal/nrf_power.h>
99103

@@ -212,7 +216,9 @@ static void do_boot(struct boot_rsp *rsp)
212216
}
213217
#endif
214218
#endif
215-
219+
#if CONFIG_MCUBOOT_NRF_CLEANUP_PERIPHERAL
220+
nrf_cleanup_peripheral();
221+
#endif
216222
#if CONFIG_MCUBOOT_CLEANUP_ARM_CORE
217223
cleanup_arm_nvic(); /* cleanup NVIC registers */
218224

boot/zephyr/nrf_cleanup.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2020 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
5+
*/
6+
7+
#include <hal/nrf_clock.h>
8+
#if defined(NRF_UARTE0) || defined(NRF_UARTE1)
9+
#include <hal/nrf_uarte.h>
10+
#endif
11+
#if defined(NRF_RTC0) || defined(NRF_RTC1) || defined(NRF_RTC2)
12+
#include <hal/nrf_rtc.h>
13+
#endif
14+
15+
#if defined(NRF_RTC0) || defined(NRF_RTC1) || defined(NRF_RTC2)
16+
static inline void nrf_cleanup_rtc(NRF_RTC_Type * rtc_reg)
17+
{
18+
nrf_rtc_task_trigger(rtc_reg, NRF_RTC_TASK_STOP);
19+
nrf_rtc_event_disable(rtc_reg, 0xFFFFFFFF);
20+
nrf_rtc_int_disable(rtc_reg, 0xFFFFFFFF);
21+
}
22+
#endif
23+
24+
static void nrf_cleanup_clock(void)
25+
{
26+
nrf_clock_int_disable(NRF_CLOCK, 0xFFFFFFFF);
27+
}
28+
29+
void nrf_cleanup_peripheral(void)
30+
{
31+
#if defined(NRF_RTC0)
32+
nrf_cleanup_rtc(NRF_RTC0);
33+
#endif
34+
#if defined(NRF_RTC1)
35+
nrf_cleanup_rtc(NRF_RTC1);
36+
#endif
37+
#if defined(NRF_RTC2)
38+
nrf_cleanup_rtc(NRF_RTC2);
39+
#endif
40+
#if defined(NRF_UARTE0)
41+
nrf_uarte_disable(NRF_UARTE0);
42+
nrf_uarte_int_disable(NRF_UARTE0, 0xFFFFFFFF);
43+
#endif
44+
#if defined(NRF_UARTE1)
45+
nrf_uarte_disable(NRF_UARTE1);
46+
nrf_uarte_int_disable(NRF_UARTE1, 0xFFFFFFFF);
47+
#endif
48+
nrf_cleanup_clock();
49+
}

0 commit comments

Comments
 (0)