diff --git a/core/include/kernel.h b/core/include/kernel.h index d4fe43b049db692f40161751f60295c852a63e78..8232d345107b65c6cbf534a9b13bb0afc661e126 100644 --- a/core/include/kernel.h +++ b/core/include/kernel.h @@ -13,7 +13,7 @@ * @file kernel.h * @brief Kernel compile time configuration * - * A reboot() function is also provided (and used by core_panic() when needed). + * A int reboot(int mode) function is also provided (and used by core_panic() when needed). * * @author Freie Universität Berlin, Computer Systems & Telematics * @author Kaspar Schleiser <kaspar@schleiser.de> @@ -89,9 +89,13 @@ extern config_t sysconfig; * * This function is used by core_panic() when the DEVELHELP macro is not defined. * - * @return WARNING: this function NEVER returns! + * @param mode The reboot mode (unused for now) + * + * @return This call never returns when successful. -1 is returned otherwise. */ -NORETURN void reboot(void); +int reboot(int mode); + +#define RB_AUTOBOOT 0 /* << Reboot the system in the usual fashion */ /** @} */ #endif /* KERNEL_H_ */ diff --git a/core/include/kernel_internal.h b/core/include/kernel_internal.h index 34ff547739fb3f011a078b2c1078028412ba794e..26a02697f6666434e674d704200e571c23f5f547 100644 --- a/core/include/kernel_internal.h +++ b/core/include/kernel_internal.h @@ -51,5 +51,15 @@ void sched_task_exit(void); */ void thread_print_stack(void); +/** + * @brief Reboot the system + * + * @param mode The argument is ignored and only used for conformity + * with existing reboot implementations for now. + * + * @return This call never returns when successful. -1 is returned otherwise. + */ +int reboot_arch(int mode); + /** @} */ #endif /* KERNEL_INTERNAL_H_ */ diff --git a/core/reboot.c b/core/reboot.c new file mode 100644 index 0000000000000000000000000000000000000000..bf02e5ab656912636335a980f45b64baa2f66f94 --- /dev/null +++ b/core/reboot.c @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2014 Ludwig Ortmann + * + * This file is subject to the terms and conditions of the GNU Lesser General + * Public License. See the file LICENSE in the top level directory for more + * details. + */ + +/** + * @ingroup core_util + * @{ + * + * @file reboot.c + * @brief Reboot function + * + * @author Ludwig Ortmann <ludwig.ortmann@fu-berlin.de + * + * @} + */ + +#include "kernel.h" +#include "kernel_internal.h" + +int reboot(int mode) +{ + if (mode != RB_AUTOBOOT) { + return -1; + } + + return reboot_arch(mode); +} diff --git a/cpu/arm_common/arm_cpu.c b/cpu/arm_common/arm_cpu.c index 92347d3727d0bd8d760e5be4e24a2f4509593d21..a615327c2d46cf768c2bfaec5ae3576ce53b3cdb 100644 --- a/cpu/arm_common/arm_cpu.c +++ b/cpu/arm_common/arm_cpu.c @@ -86,9 +86,13 @@ void thread_print_stack(void) printf("STACK (%u)= %X \n", i, *s); } -NORETURN void reboot(void) +int reboot_arch(int mode) { + (void) mode; + while (1) { arm_reset(); } + + return -1; } diff --git a/cpu/arm_common/crash.c b/cpu/arm_common/crash.c index bfb00d73a470afff59f0a69e75f81012e8b777eb..e04f58a93350c23741a71c5318407a67fab847f2 100644 --- a/cpu/arm_common/crash.c +++ b/cpu/arm_common/crash.c @@ -58,6 +58,6 @@ NORETURN void core_panic(int crash_code, const char *message) } #else /* DEVELHELP not set => reboot system */ - reboot(); + (void) reboot(RB_AUTOBOOT); #endif } diff --git a/cpu/lpc1768/cpu.c b/cpu/lpc1768/cpu.c index f5d6630195b79fb6c42b11a9e6bd27875b5346bb..1c925e63ff5d55068462e5046caa2133c17d516a 100644 --- a/cpu/lpc1768/cpu.c +++ b/cpu/lpc1768/cpu.c @@ -126,9 +126,13 @@ __attribute__((naked,noreturn)) void arm_reset(void) ); } -NORETURN void reboot(void) +int reboot_arch(int mode) { + (void) mode; + while (1) { arm_reset(); } + + return -1; } diff --git a/cpu/lpc1768/crash.c b/cpu/lpc1768/crash.c index 534fdf2900a8b99deb5d7fbe45cc6781f38f5af1..f90711d02c8483c09fc61a2278c4c1c0aa4607af 100644 --- a/cpu/lpc1768/crash.c +++ b/cpu/lpc1768/crash.c @@ -59,6 +59,6 @@ NORETURN void core_panic(int crash_code, const char *message) } #else /* DEVELHELP not set => reboot system */ - reboot(); + (void) reboot(RB_AUTOBOOT); #endif } diff --git a/cpu/msp430-common/cpu.c b/cpu/msp430-common/cpu.c index a6b6489d6f1a48f6cca7d1ab671db6f333ed97e9..64f41c164f52bc7352505c907a679747e08c2d4d 100644 --- a/cpu/msp430-common/cpu.c +++ b/cpu/msp430-common/cpu.c @@ -90,11 +90,15 @@ int inISR() /******************************************************************************/ /* System reboot */ -NORETURN void reboot(void) +int reboot_arch(int mode) { + (void) mode; + /* force an hardware reboot ("Power-Up Clear"), by writing an illegal value to the watchdog control register */ while (1) { WDTCTL = 0x0000; } + + return -1; } diff --git a/cpu/msp430-common/crash.c b/cpu/msp430-common/crash.c index 41522eb5e028768407c36cb6b97caa0d8652deab..cec66385cba7aac75fcefa4b544599d99af4ffe4 100644 --- a/cpu/msp430-common/crash.c +++ b/cpu/msp430-common/crash.c @@ -58,6 +58,6 @@ NORETURN void core_panic(int crash_code, const char *message) } #else /* DEVELHELP not set => reboot system */ - reboot(); + (void) reboot(RB_AUTOBOOT); #endif } diff --git a/cpu/native/crash.c b/cpu/native/crash.c index 00d5244e9e6dd1c4bae5af6decdb89fa0389485d..d04a2bb72faf1f3d1764c1db996fe4b0e45b054d 100644 --- a/cpu/native/crash.c +++ b/cpu/native/crash.c @@ -55,7 +55,7 @@ NORETURN void core_panic(int crash_code, const char *message) just use the (developer-)friendly core-dump feature */ kill(getpid(), SIGTRAP); #else - reboot(); + (void) reboot(RB_AUTOBOOT); #endif /* proove the compiler that we won't return from this function diff --git a/cpu/native/native_cpu.c b/cpu/native/native_cpu.c index b515b5054b3a7016b0a21bed31f44e7d187c1998..d6a71e9c4a2846533fc608d8e811e8483c25c1db 100644 --- a/cpu/native/native_cpu.c +++ b/cpu/native/native_cpu.c @@ -63,13 +63,19 @@ char __end_stack[SIGSTKSZ]; fd_set _native_rfds; #endif -NORETURN void reboot(void) +int reboot_arch(int mode) { + (void) mode; + printf("\n\n\t\t!! REBOOT !!\n\n"); + if (execve(_native_argv[0], _native_argv, NULL) == -1) { err(EXIT_FAILURE, "reboot: execve"); } + errx(EXIT_FAILURE, "reboot: this should not habe been reached"); + + return -1; } /** diff --git a/sys/shell/commands/sc_sys.c b/sys/shell/commands/sc_sys.c index 5bb381d3f4c956ed0e421042a6db9cbd5b37cf6e..199730f9614c56afea57c056036f89081dd2849e 100644 --- a/sys/shell/commands/sc_sys.c +++ b/sys/shell/commands/sc_sys.c @@ -22,5 +22,5 @@ void _reboot_handler(int argc, char **argv) (void) argc; (void) argv; - reboot(); + (void) reboot(RB_AUTOBOOT); }