Skip to content

Commit 8fb78c4

Browse files
committed
soc/arm/nordic_nrf: implementation of request and fetch the MCUboot mode
Implemented SoC specific function needed for posting the bootloader mode by the application and fetching it by the MCUboot. Signed-off-by: Andrzej Puzdrowski <[email protected]>API for request MCUboot mode
1 parent 8738722 commit 8fb78c4

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

soc/arm/nordic_nrf/nrf52/soc.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@ extern void z_arm_nmi_init(void);
4747
#define LOG_LEVEL CONFIG_SOC_LOG_LEVEL
4848
LOG_MODULE_REGISTER(soc);
4949

50+
int soc_mcuboot_mode_set(uint8_t mode)
51+
{
52+
nrf_power_gpregret2_set(NRF_POWER, mode);
53+
54+
return 0;
55+
}
56+
57+
uint8_t soc_mcuboot_mode_get(void)
58+
{
59+
uint8_t mode = nrf_power_gpregret2_get(NRF_POWER);
60+
61+
nrf_power_gpregret2_set(NRF_POWER, 0);
62+
63+
return mode;
64+
}
65+
5066
/* Overrides the weak ARM implementation:
5167
Set general purpose retention register and reboot */
5268
void sys_arch_reboot(int type)

soc/arm/nordic_nrf/nrf53/soc.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@
2525
#include <hal/nrf_gpio.h>
2626
#include <hal/nrf_oscillators.h>
2727
#include <hal/nrf_regulators.h>
28+
#include <hal/nrf_power.h>
2829
#elif defined(CONFIG_SOC_NRF5340_CPUNET)
2930
#include <hal/nrf_nvmc.h>
3031
#endif
3132
#include <soc_secure.h>
3233

34+
3335
#define PIN_XL1 0
3436
#define PIN_XL2 1
3537

@@ -66,6 +68,24 @@ extern void z_arm_nmi_init(void);
6668
#define LOG_LEVEL CONFIG_SOC_LOG_LEVEL
6769
LOG_MODULE_REGISTER(soc);
6870

71+
#if defined(CONFIG_SOC_NRF5340_CPUAPP)
72+
int soc_mcuboot_mode_set(uint8_t mode)
73+
{
74+
nrf_power_gpregret2_set(NRF_POWER, mode);
75+
76+
return 0;
77+
}
78+
79+
uint8_t soc_mcuboot_mode_get(void)
80+
{
81+
uint8_t mode = nrf_power_gpregret2_get(NRF_POWER);
82+
83+
nrf_power_gpregret2_set(NRF_POWER, 0);
84+
85+
return mode;
86+
}
87+
#endif
88+
6989
static int nordicsemi_nrf53_init(const struct device *arg)
7090
{
7191
uint32_t key;

soc/arm/nordic_nrf/nrf91/soc.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <arch/arm/aarch32/cortex_m/cmsis.h>
1818
#include <soc/nrfx_coredep.h>
1919
#include <logging/log.h>
20+
#include <hal/nrf_power.h>
2021

2122
#ifdef CONFIG_RUNTIME_NMI
2223
extern void z_arm_nmi_init(void);
@@ -34,6 +35,22 @@ extern void z_arm_nmi_init(void);
3435
#define LOG_LEVEL CONFIG_SOC_LOG_LEVEL
3536
LOG_MODULE_REGISTER(soc);
3637

38+
int soc_mcuboot_mode_set(uint8_t mode)
39+
{
40+
nrf_power_gpregret_ext_set(NRF_POWER, 1, mode);
41+
42+
return 0;
43+
}
44+
45+
uint8_t soc_mcuboot_mode_set(void)
46+
{
47+
uint8_t mode = nrf_power_gpregret_ext_get(NRF_POWER, 1);
48+
49+
nrf_power_gpregret_ext_set(NRF_POWER, 1, 0);
50+
51+
return mode;
52+
}
53+
3754
static int nordicsemi_nrf91_init(const struct device *arg)
3855
{
3956
uint32_t key;

0 commit comments

Comments
 (0)