Skip to content

Add some NORETURN attributes #3469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ports/atmel-samd/reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "reset.h"
#include "supervisor/filesystem.h"

void NVIC_SystemReset(void) NORETURN;

void reset(void) {
filesystem_flush();
NVIC_SystemReset();
Expand Down
6 changes: 4 additions & 2 deletions ports/atmel-samd/reset.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@
#include <stdbool.h>
#include <stdint.h>

#include "py/mpconfig.h"

// Copied from inc/uf2.h in https://github.com/Microsoft/uf2-samd21
#define DBL_TAP_MAGIC 0xf01669ef // Randomly selected, adjusted to have first and last bit set
#define DBL_TAP_MAGIC_QUICK_BOOT 0xf02669ef

extern uint32_t _bootloader_dbl_tap;

void reset_to_bootloader(void);
void reset(void);
void reset_to_bootloader(void) NORETURN;
void reset(void) NORETURN;
bool bootloader_available(void);

#endif // MICROPY_INCLUDED_ATMEL_SAMD_RESET_H
5 changes: 5 additions & 0 deletions ports/cxd56/supervisor/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ safe_mode_t port_init(void) {

void reset_cpu(void) {
boardctl(BOARDIOC_RESET, 0);
for (;;) {
}
}

void reset_port(void) {
Expand All @@ -91,6 +93,9 @@ void reset_port(void) {
}

void reset_to_bootloader(void) {
boardctl(BOARDIOC_RESET, 0);
for (;;) {
}
}

supervisor_allocation* port_fixed_stack(void) {
Expand Down
4 changes: 4 additions & 0 deletions ports/esp32s2/supervisor/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ uint32_t heap_size;

STATIC esp_timer_handle_t _tick_timer;

extern void esp_restart(void) NORETURN;

void tick_timer_cb(void* arg) {
supervisor_tick();
}
Expand Down Expand Up @@ -118,9 +120,11 @@ void reset_port(void) {
}

void reset_to_bootloader(void) {
esp_restart();
}

void reset_cpu(void) {
esp_restart();
}

uint32_t *port_heap_get_bottom(void) {
Expand Down
8 changes: 8 additions & 0 deletions ports/litex/supervisor/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,17 @@ void reset_port(void) {

void reset_to_bootloader(void) {
reboot_ctrl_write(0xac);
for(;;) {}
}

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

supervisor_allocation* port_fixed_stack(void) {
Expand Down
6 changes: 4 additions & 2 deletions ports/mimxrt10xx/reset.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@
#include <stdbool.h>
#include <stdint.h>

#include "py/mpconfig.h"

// Copied from inc/uf2.h in https://github.com/Microsoft/uf2-samd21
#define DBL_TAP_MAGIC 0xf01669ef // Randomly selected, adjusted to have first and last bit set
#define DBL_TAP_MAGIC_QUICK_BOOT 0xf02669ef

void reset_to_bootloader(void);
void reset(void);
void reset_to_bootloader(void) NORETURN;
void reset(void) NORETURN;
bool bootloader_available(void);

#endif // MICROPY_INCLUDED_MIMXRT10XX_RESET_H
2 changes: 2 additions & 0 deletions ports/nrf/supervisor/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ void reset_cpu(void) {
uint32_t ticks = nrfx_rtc_counter_get(&rtc_instance);
overflow_tracker.overflowed_ticks += ticks / 32;
NVIC_SystemReset();
for (;;) {
}
}

// The uninitialized data section is placed directly after BSS, under the theory
Expand Down
4 changes: 3 additions & 1 deletion ports/stm/supervisor/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@

#include STM32_HAL_H

void NVIC_SystemReset(void) NORETURN;

#if (CPY_STM32H7) || (CPY_STM32F7)

// Device memories must be accessed in order.
Expand Down Expand Up @@ -247,7 +249,7 @@ void reset_port(void) {
}

void reset_to_bootloader(void) {

NVIC_SystemReset();
}

void reset_cpu(void) {
Expand Down
4 changes: 2 additions & 2 deletions supervisor/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ extern uint32_t _ebss;
safe_mode_t port_init(void);

// Reset the microcontroller completely.
void reset_cpu(void);
void reset_cpu(void) NORETURN;

// Reset the microcontroller state.
void reset_port(void);
Expand All @@ -53,7 +53,7 @@ void reset_port(void);
void reset_board(void);

// Reset to the bootloader
void reset_to_bootloader(void);
void reset_to_bootloader(void) NORETURN;

// Get stack limit address
uint32_t *port_stack_get_limit(void);
Expand Down
4 changes: 3 additions & 1 deletion supervisor/shared/safe_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#ifndef MICROPY_INCLUDED_SUPERVISOR_SAFE_MODE_H
#define MICROPY_INCLUDED_SUPERVISOR_SAFE_MODE_H

#include "py/mpconfig.h"

typedef enum {
NO_SAFE_MODE = 0,
BROWNOUT,
Expand All @@ -48,7 +50,7 @@ typedef enum {
safe_mode_t wait_for_safe_mode_reset(void);

void safe_mode_on_next_reset(safe_mode_t reason);
void reset_into_safe_mode(safe_mode_t reason);
void reset_into_safe_mode(safe_mode_t reason) NORETURN;

void print_safe_mode_message(safe_mode_t reason);

Expand Down
5 changes: 3 additions & 2 deletions supervisor/stub/safe_mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@

#include "supervisor/shared/safe_mode.h"

#include <stdlib.h>

safe_mode_t wait_for_safe_mode_reset(void) {
return NO_SAFE_MODE;
}

void reset_into_safe_mode(safe_mode_t reason) {
(void) reason;
for (;;) {
}
abort();
}

void print_safe_mode_message(safe_mode_t reason) {
Expand Down