Skip to content

Commit 37d2c34

Browse files
authored
Merge pull request #400 from AlessandroA/docs_update_debugging
Docs: Fix sample code for debug box
2 parents 0c18a5f + 052f6a3 commit 37d2c34

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

core/debug/src/debug_box.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ void debug_halt_error(THaltError reason)
9292
if (!g_debug_box.initialized || debugged_once_before) {
9393
while (1);
9494
} else {
95-
/* Remember that debug_deprivilege_and_return() has been called once.
96-
* We'll reboot after the debug handler is run, so this will go back to
97-
* zero after the reboot. */
95+
/* Remember that debug_deprivilege_and_return() has been called once. */
9896
debugged_once_before = 1;
9997

10098
/* The following arguments are passed to the destination function:

docs/api/DEBUGGING.md

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,14 @@ Instead, debug events and messages are forwarded to a special unprivileged box,
122122

123123
The debug box driver is encoded in a standard table (a C `struct`) that must be populated by a debug box at initialization time. A debug box can decide to implement only some of the available handlers, although they must all exist at least as empty functions, otherwise the program behaviour might be unpredictable.
124124

125-
Currently, only one debug handler is provided. A debug box driver will always expect a `get_version()` handler in position 0 of the function table:
125+
Currently, only one debug handler — `halt_error` — is provided. This handler only executes once, so if another fault occurs during its execution, the uVisor does not de-privilege again, halting instead. A debug box driver will also expect a `get_version()` handler in position 0 of the function table:
126+
127+
Debug box handlers can also reset the device by calling the `NVIC_SystemReset()` API. This API cannot be called from other secure boxes.
126128

127129
```C
128130
typedef struct TUvisorDebugDriver {
129131
uint32_t (*get_version)(void); /* 0. Return the implemented driver version. */
130-
void (*halt_error)(int); /* 1. Halt on error. Reboot upon return. */
132+
void (*halt_error)(int); /* 1. Halt on error. Halt upon return. */
131133
}
132134
```
133135

@@ -137,28 +139,29 @@ The following is an example of how to implement and configure a debug box.
137139
#include "mbed.h"
138140
#include "uvisor-lib/uvisor-lib.h"
139141

140-
struct box_context {
141-
uint32_t unused;
142-
};
143-
144142
static const UvisorBoxAclItem acl[] = {
143+
/* No specific ACL required. */
145144
};
146145

147146
static void box_debug_main(const void *);
148147

149148
/* Configure the debug box. */
150149
UVISOR_BOX_NAMESPACE(NULL);
151-
UVISOR_BOX_CONFIG(box_debug, UVISOR_BOX_STACK_SIZE);
152-
UVISOR_BOX_MAIN(box_debug_main, osPriorityNormal, UVISOR_BOX_STACK_SIZE);
153-
UVISOR_BOX_CONFIG(box_debug, acl, UVISOR_BOX_STACK_SIZE, box_context);
150+
UVISOR_BOX_HEAPSIZE(2048);
151+
UVISOR_BOX_MAIN(box_debug_main, osPriorityNormal, 1024);
152+
UVISOR_BOX_CONFIG(box_debug, 1024);
154153

155154
static uint32_t get_version(void) {
156155
return 0;
157156
}
158157

159158
static void halt_error(int reason) {
160159
printf("We halted with reason %i\r\n", reason);
161-
/* We will now reboot. */
160+
161+
/* If we don't do anything, the system will halt upon return. */
162+
/* A debug box handler like this one can also decide to reboot the whole
163+
* system. This is only allowed from the debug box. */
164+
NVIC_SystemReset();
162165
}
163166

164167
static void box_debug_main(const void *)
@@ -176,12 +179,7 @@ static void box_debug_main(const void *)
176179
177180
## Platform-specific details
178181
179-
Currently the following platforms are officially supported by uVisor:
180-
181-
* [NXP FRDM-K64F](http://developer.mbed.org/platforms/FRDM-K64F/).
182-
* [STMicorelectronics STM32F429I-DISCO](http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/PF259090).
183-
184-
This section provides details on how to enable debug on these platforms.
182+
This section provides details on how to enable debug on some specific hardware platforms.
185183
186184
#### NXP FRDM-K64F
187185

0 commit comments

Comments
 (0)