Skip to content

Commit f0f8a14

Browse files
tomchyrlubos
authored andcommitted
suit: Introduce helper functions for exec states
Add a few helper functions to check if the execution state matches three common groups of states. Ref: NCSDK-NONE Signed-off-by: Tomasz Chyrowicz <[email protected]>
1 parent a918437 commit f0f8a14

File tree

3 files changed

+228
-0
lines changed

3 files changed

+228
-0
lines changed

subsys/suit/execution_mode/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@
66

77
config SUIT_EXECUTION_MODE
88
bool "Enable SUIT execution mode module"
9+
10+
config APP_LINK_WITH_SUIT_EXECUTION_MODE
11+
bool
12+
default y

subsys/suit/execution_mode/include/suit_execution_mode.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#ifndef SUIT_EXECUTION_MODE_H__
88
#define SUIT_EXECUTION_MODE_H__
99

10+
#include <stdbool.h>
1011
#include <suit_plat_err.h>
1112

1213
#ifdef __cplusplus
@@ -27,6 +28,7 @@ typedef enum {
2728
EXECUTION_MODE_FAIL_MPI_UNSUPPORTED,
2829
EXECUTION_MODE_FAIL_INVOKE_RECOVERY,
2930
EXECUTION_MODE_FAIL_INSTALL_NORDIC_TOP,
31+
EXECUTION_MODE_FAIL_STARTUP,
3032
} suit_execution_mode_t;
3133

3234
/**
@@ -46,6 +48,69 @@ suit_execution_mode_t suit_execution_mode_get(void);
4648
*/
4749
suit_plat_err_t suit_execution_mode_set(suit_execution_mode_t mode);
4850

51+
/**
52+
* @brief Update execution mode as a result of interrupted startup procedure.
53+
*
54+
* @details The main purpose of this API is to get out of the non-final state
55+
* (i.e. update candidate is detected and the orchestrator entry will
56+
* start processing it) if the startup procedure is interrupted
57+
* between suit_orchestrator_init(), which schedules processing of
58+
* manifests and suit_orchestrator_entry(), which executes scheduled
59+
* operations. This situation may occur as a result of BICR or UICR
60+
* misconfiguration.
61+
* Since execution mode value is used to check if the it is allowed to
62+
* modify memory regions, the mode should be changed to one of the
63+
* FAILED states in such case to unblock device recovery procedures.
64+
*
65+
* @note This API will set the execution mode to EXECUTION_MODE_FAIL_STARTUP
66+
* only if the current mode indicates a transient state.
67+
*/
68+
void suit_execution_mode_startup_failed(void);
69+
70+
/**
71+
* @brief Check if SUIT is processing installed manifests.
72+
*
73+
* @details Certain operations are not available if the SUIT orchestrator is
74+
* actively using the SUIT processor (and SUIT decoder) states.
75+
* Moreover, modifying manifests while they are processed might result
76+
* in security bridges.
77+
* To allow external modules (i.e. memory lease mechanisms) to check
78+
* if the SUIT orchestrator is booting manifests without exposing all
79+
* of the details about execution mode, this API may be used.
80+
*/
81+
bool suit_execution_mode_booting(void);
82+
83+
/**
84+
* @brief Check if SUIT is processing an update candidate.
85+
*
86+
* @details Certain operations are not available if the SUIT orchestrator is
87+
* actively using the SUIT processor (and SUIT decoder) states.
88+
* Moreover, modifying DFU partition while update canidates they are
89+
* processed might result in security bridges.
90+
* To allow external modules (i.e. memory lease mechanisms) to check
91+
* if the SUIT orchestrator is updating manifests without exposing all
92+
* of the details about execution mode, this API may be used.
93+
*/
94+
bool suit_execution_mode_updating(void);
95+
96+
/**
97+
* @brief Check if SUIT failed to process OEM manifests.
98+
*
99+
* @details Certain operations must be enabled or disabled if SUIT orchestrator
100+
* logic fails to initialize.
101+
* The most common reason for such failure is the misconfiguration of
102+
* the MPI area.
103+
* Although this failure modifies the execution mode, it is not
104+
* reflected by the suit_orchestrator_init() return code, so the rest
105+
* of the system (UICR allocation, ADAC server) can take place.
106+
* Due to that, some modules must rely on the execution mode to set
107+
* the permissions for their operation. To allow them to check
108+
* if the SUIT orchestrator is in one of the FAILED states without
109+
* exposing all of the details about execution mode, this API may be
110+
* used.
111+
*/
112+
bool suit_execution_mode_failed(void);
113+
49114
#ifdef __cplusplus
50115
}
51116
#endif

subsys/suit/execution_mode/src/suit_execution_mode.c

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,162 @@ suit_plat_err_t suit_execution_mode_set(suit_execution_mode_t mode)
2323

2424
return SUIT_PLAT_ERR_INVAL;
2525
}
26+
27+
void suit_execution_mode_startup_failed(void)
28+
{
29+
switch (current_execution_mode) {
30+
/* SUIT boot or update not yet started. */
31+
case EXECUTION_MODE_STARTUP:
32+
/* System is unprovisioned, SUIT updates Nordic components. */
33+
case EXECUTION_MODE_FAIL_INSTALL_NORDIC_TOP:
34+
/* SUIT processes update candiadate. */
35+
case EXECUTION_MODE_INSTALL:
36+
/* SUIT processes recovery update. */
37+
case EXECUTION_MODE_INSTALL_RECOVERY:
38+
/* SUIT boots from root manifest. */
39+
case EXECUTION_MODE_INVOKE:
40+
/* SUIT boots from recovery manifest. */
41+
case EXECUTION_MODE_INVOKE_RECOVERY:
42+
current_execution_mode = EXECUTION_MODE_FAIL_STARTUP;
43+
break;
44+
45+
/* System not booted, application MPI missing. */
46+
case EXECUTION_MODE_FAIL_NO_MPI:
47+
/* System not booted, invalid MPI format. */
48+
case EXECUTION_MODE_FAIL_MPI_INVALID:
49+
/* System not booted, Nordic and root class IDs not configured. */
50+
case EXECUTION_MODE_FAIL_MPI_INVALID_MISSING:
51+
/* System not booted, MPI misconfigured. */
52+
case EXECUTION_MODE_FAIL_MPI_UNSUPPORTED:
53+
/* System not booted, unable to boot recovery manifest. */
54+
case EXECUTION_MODE_FAIL_INVOKE_RECOVERY:
55+
/* System booted from root manifest. */
56+
case EXECUTION_MODE_POST_INVOKE:
57+
/* System booted from recovery manifest. */
58+
case EXECUTION_MODE_POST_INVOKE_RECOVERY:
59+
/* System failed before invoking SUIT orchestrator. */
60+
case EXECUTION_MODE_FAIL_STARTUP:
61+
break;
62+
/* default case deliberately excluded to get warnings if missing an enum case. */
63+
}
64+
}
65+
66+
bool suit_execution_mode_booting(void)
67+
{
68+
switch (current_execution_mode) {
69+
/* SUIT processes update candiadate. */
70+
case EXECUTION_MODE_INSTALL:
71+
/* SUIT processes recovery update. */
72+
case EXECUTION_MODE_INSTALL_RECOVERY:
73+
/* System is unprovisioned, SUIT updates Nordic components. */
74+
case EXECUTION_MODE_FAIL_INSTALL_NORDIC_TOP:
75+
/* System booted from root manifest. */
76+
case EXECUTION_MODE_POST_INVOKE:
77+
/* System booted from recovery manifest. */
78+
case EXECUTION_MODE_POST_INVOKE_RECOVERY:
79+
/* System not booted, application MPI missing. */
80+
case EXECUTION_MODE_FAIL_NO_MPI:
81+
/* System not booted, invalid MPI format. */
82+
case EXECUTION_MODE_FAIL_MPI_INVALID:
83+
/* System not booted, Nordic and root class IDs not configured. */
84+
case EXECUTION_MODE_FAIL_MPI_INVALID_MISSING:
85+
/* System not booted, MPI misconfigured. */
86+
case EXECUTION_MODE_FAIL_MPI_UNSUPPORTED:
87+
/* System not booted, unable to boot recovery manifest. */
88+
case EXECUTION_MODE_FAIL_INVOKE_RECOVERY:
89+
/* System failed before invoking SUIT orchestrator. */
90+
case EXECUTION_MODE_FAIL_STARTUP:
91+
return false;
92+
93+
/* SUIT boot or update not yet started. */
94+
case EXECUTION_MODE_STARTUP:
95+
/* SUIT boots from root manifest. */
96+
case EXECUTION_MODE_INVOKE:
97+
/* SUIT boots from recovery manifest. */
98+
case EXECUTION_MODE_INVOKE_RECOVERY:
99+
break;
100+
/* default case deliberately excluded to get warnings if missing an enum case. */
101+
}
102+
103+
return true;
104+
}
105+
106+
bool suit_execution_mode_updating(void)
107+
{
108+
switch (current_execution_mode) {
109+
/* SUIT boots from root manifest. */
110+
case EXECUTION_MODE_INVOKE:
111+
/* SUIT boots from recovery manifest. */
112+
case EXECUTION_MODE_INVOKE_RECOVERY:
113+
/* System booted from root manifest. */
114+
case EXECUTION_MODE_POST_INVOKE:
115+
/* System booted from recovery manifest. */
116+
case EXECUTION_MODE_POST_INVOKE_RECOVERY:
117+
/* System not booted, application MPI missing. */
118+
case EXECUTION_MODE_FAIL_NO_MPI:
119+
/* System not booted, invalid MPI format. */
120+
case EXECUTION_MODE_FAIL_MPI_INVALID:
121+
/* System not booted, Nordic and root class IDs not configured. */
122+
case EXECUTION_MODE_FAIL_MPI_INVALID_MISSING:
123+
/* System not booted, MPI misconfigured. */
124+
case EXECUTION_MODE_FAIL_MPI_UNSUPPORTED:
125+
/* System not booted, unable to boot recovery manifest. */
126+
case EXECUTION_MODE_FAIL_INVOKE_RECOVERY:
127+
/* System failed before invoking SUIT orchestrator. */
128+
case EXECUTION_MODE_FAIL_STARTUP:
129+
return false;
130+
131+
/* SUIT boot or update not yet started. */
132+
case EXECUTION_MODE_STARTUP:
133+
/* SUIT processes update candiadate. */
134+
case EXECUTION_MODE_INSTALL:
135+
/* SUIT processes recovery update. */
136+
case EXECUTION_MODE_INSTALL_RECOVERY:
137+
/* System is unprovisioned, SUIT updates Nordic components. */
138+
case EXECUTION_MODE_FAIL_INSTALL_NORDIC_TOP:
139+
break;
140+
/* default case deliberately excluded to get warnings if missing an enum case. */
141+
}
142+
143+
return true;
144+
}
145+
146+
bool suit_execution_mode_failed(void)
147+
{
148+
switch (current_execution_mode) {
149+
/* SUIT boot or update not yet started. */
150+
case EXECUTION_MODE_STARTUP:
151+
/* SUIT processes update candiadate. */
152+
case EXECUTION_MODE_INSTALL:
153+
/* SUIT processes recovery update. */
154+
case EXECUTION_MODE_INSTALL_RECOVERY:
155+
/* SUIT boots from root manifest. */
156+
case EXECUTION_MODE_INVOKE:
157+
/* SUIT boots from recovery manifest. */
158+
case EXECUTION_MODE_INVOKE_RECOVERY:
159+
/* System booted from root manifest. */
160+
case EXECUTION_MODE_POST_INVOKE:
161+
/* System booted from recovery manifest. */
162+
case EXECUTION_MODE_POST_INVOKE_RECOVERY:
163+
/* System is unprovisioned, SUIT updates Nordic components. */
164+
case EXECUTION_MODE_FAIL_INSTALL_NORDIC_TOP:
165+
return false;
166+
167+
/* System not booted, application MPI missing. */
168+
case EXECUTION_MODE_FAIL_NO_MPI:
169+
/* System not booted, invalid MPI format. */
170+
case EXECUTION_MODE_FAIL_MPI_INVALID:
171+
/* System not booted, Nordic and root class IDs not configured. */
172+
case EXECUTION_MODE_FAIL_MPI_INVALID_MISSING:
173+
/* System not booted, MPI misconfigured. */
174+
case EXECUTION_MODE_FAIL_MPI_UNSUPPORTED:
175+
/* System not booted, unable to boot recovery manifest. */
176+
case EXECUTION_MODE_FAIL_INVOKE_RECOVERY:
177+
/* System failed before invoking SUIT orchestrator. */
178+
case EXECUTION_MODE_FAIL_STARTUP:
179+
break;
180+
/* default case deliberately excluded to get warnings if missing an enum case. */
181+
}
182+
183+
return true;
184+
}

0 commit comments

Comments
 (0)