Skip to content

Commit d62ac24

Browse files
authored
Merge pull request #3469 from jepler/noreturn
Add some NORETURN attributes
2 parents 1606517 + dd6e7f5 commit d62ac24

File tree

11 files changed

+40
-10
lines changed

11 files changed

+40
-10
lines changed

ports/atmel-samd/reset.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include "reset.h"
3030
#include "supervisor/filesystem.h"
3131

32+
void NVIC_SystemReset(void) NORETURN;
33+
3234
void reset(void) {
3335
filesystem_flush();
3436
NVIC_SystemReset();

ports/atmel-samd/reset.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@
2929
#include <stdbool.h>
3030
#include <stdint.h>
3131

32+
#include "py/mpconfig.h"
33+
3234
// Copied from inc/uf2.h in https://github.com/Microsoft/uf2-samd21
3335
#define DBL_TAP_MAGIC 0xf01669ef // Randomly selected, adjusted to have first and last bit set
3436
#define DBL_TAP_MAGIC_QUICK_BOOT 0xf02669ef
3537

3638
extern uint32_t _bootloader_dbl_tap;
3739

38-
void reset_to_bootloader(void);
39-
void reset(void);
40+
void reset_to_bootloader(void) NORETURN;
41+
void reset(void) NORETURN;
4042
bool bootloader_available(void);
4143

4244
#endif // MICROPY_INCLUDED_ATMEL_SAMD_RESET_H

ports/cxd56/supervisor/port.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ safe_mode_t port_init(void) {
7171

7272
void reset_cpu(void) {
7373
boardctl(BOARDIOC_RESET, 0);
74+
for (;;) {
75+
}
7476
}
7577

7678
void reset_port(void) {
@@ -91,6 +93,9 @@ void reset_port(void) {
9193
}
9294

9395
void reset_to_bootloader(void) {
96+
boardctl(BOARDIOC_RESET, 0);
97+
for (;;) {
98+
}
9499
}
95100

96101
supervisor_allocation* port_fixed_stack(void) {

ports/esp32s2/supervisor/port.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ uint32_t heap_size;
5656

5757
STATIC esp_timer_handle_t _tick_timer;
5858

59+
extern void esp_restart(void) NORETURN;
60+
5961
void tick_timer_cb(void* arg) {
6062
supervisor_tick();
6163
}
@@ -118,9 +120,11 @@ void reset_port(void) {
118120
}
119121

120122
void reset_to_bootloader(void) {
123+
esp_restart();
121124
}
122125

123126
void reset_cpu(void) {
127+
esp_restart();
124128
}
125129

126130
uint32_t *port_heap_get_bottom(void) {

ports/litex/supervisor/port.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,17 @@ void reset_port(void) {
8585

8686
void reset_to_bootloader(void) {
8787
reboot_ctrl_write(0xac);
88+
for(;;) {}
8889
}
8990

9091
void reset_cpu(void) {
92+
// "You can reset Fomu by writing a special value to the CSR_REBOOT_CTRL
93+
// register at 0xe0006000L. All writes to this register must start with
94+
// 0xac, to ensure random values aren’t written. We can reboot Fomu by
95+
// simply writing this value" --
96+
// https://workshop.fomu.im/en/latest/riscv.html
97+
reboot_ctrl_write(0xac);
98+
for(;;) {}
9199
}
92100

93101
supervisor_allocation* port_fixed_stack(void) {

ports/mimxrt10xx/reset.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@
3030
#include <stdbool.h>
3131
#include <stdint.h>
3232

33+
#include "py/mpconfig.h"
34+
3335
// Copied from inc/uf2.h in https://github.com/Microsoft/uf2-samd21
3436
#define DBL_TAP_MAGIC 0xf01669ef // Randomly selected, adjusted to have first and last bit set
3537
#define DBL_TAP_MAGIC_QUICK_BOOT 0xf02669ef
3638

37-
void reset_to_bootloader(void);
38-
void reset(void);
39+
void reset_to_bootloader(void) NORETURN;
40+
void reset(void) NORETURN;
3941
bool bootloader_available(void);
4042

4143
#endif // MICROPY_INCLUDED_MIMXRT10XX_RESET_H

ports/nrf/supervisor/port.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ void reset_cpu(void) {
234234
uint32_t ticks = nrfx_rtc_counter_get(&rtc_instance);
235235
overflow_tracker.overflowed_ticks += ticks / 32;
236236
NVIC_SystemReset();
237+
for (;;) {
238+
}
237239
}
238240

239241
// The uninitialized data section is placed directly after BSS, under the theory

ports/stm/supervisor/port.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656

5757
#include STM32_HAL_H
5858

59+
void NVIC_SystemReset(void) NORETURN;
60+
5961
#if (CPY_STM32H7) || (CPY_STM32F7)
6062

6163
// Device memories must be accessed in order.
@@ -247,7 +249,7 @@ void reset_port(void) {
247249
}
248250

249251
void reset_to_bootloader(void) {
250-
252+
NVIC_SystemReset();
251253
}
252254

253255
void reset_cpu(void) {

supervisor/port.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ extern uint32_t _ebss;
4444
safe_mode_t port_init(void);
4545

4646
// Reset the microcontroller completely.
47-
void reset_cpu(void);
47+
void reset_cpu(void) NORETURN;
4848

4949
// Reset the microcontroller state.
5050
void reset_port(void);
@@ -53,7 +53,7 @@ void reset_port(void);
5353
void reset_board(void);
5454

5555
// Reset to the bootloader
56-
void reset_to_bootloader(void);
56+
void reset_to_bootloader(void) NORETURN;
5757

5858
// Get stack limit address
5959
uint32_t *port_stack_get_limit(void);

supervisor/shared/safe_mode.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#ifndef MICROPY_INCLUDED_SUPERVISOR_SAFE_MODE_H
2828
#define MICROPY_INCLUDED_SUPERVISOR_SAFE_MODE_H
2929

30+
#include "py/mpconfig.h"
31+
3032
typedef enum {
3133
NO_SAFE_MODE = 0,
3234
BROWNOUT,
@@ -48,7 +50,7 @@ typedef enum {
4850
safe_mode_t wait_for_safe_mode_reset(void);
4951

5052
void safe_mode_on_next_reset(safe_mode_t reason);
51-
void reset_into_safe_mode(safe_mode_t reason);
53+
void reset_into_safe_mode(safe_mode_t reason) NORETURN;
5254

5355
void print_safe_mode_message(safe_mode_t reason);
5456

supervisor/stub/safe_mode.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@
2626

2727
#include "supervisor/shared/safe_mode.h"
2828

29+
#include <stdlib.h>
30+
2931
safe_mode_t wait_for_safe_mode_reset(void) {
3032
return NO_SAFE_MODE;
3133
}
3234

3335
void reset_into_safe_mode(safe_mode_t reason) {
3436
(void) reason;
35-
for (;;) {
36-
}
37+
abort();
3738
}
3839

3940
void print_safe_mode_message(safe_mode_t reason) {

0 commit comments

Comments
 (0)