From 4e5eb9740b509e814e9c16aefe40a373d67bbc43 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Sun, 28 Jul 2013 14:50:27 +0200 Subject: Fixed led and reboot linker challenges in C++ environments --- src/modules/systemlib/systemlib.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/modules/systemlib/systemlib.h') diff --git a/src/modules/systemlib/systemlib.h b/src/modules/systemlib/systemlib.h index 0194b5e52..77fdfe08a 100644 --- a/src/modules/systemlib/systemlib.h +++ b/src/modules/systemlib/systemlib.h @@ -42,11 +42,11 @@ #include #include -/** Reboots the board */ -extern void up_systemreset(void) noreturn_function; - __BEGIN_DECLS +/** Reboots the board */ +__EXPORT void systemreset(void) noreturn_function; + /** Sends SIGUSR1 to all processes */ __EXPORT void killall(void); -- cgit v1.2.3 From e931d3b9cda723d63bf352ca866dc499d8df21f5 Mon Sep 17 00:00:00 2001 From: px4dev Date: Sat, 3 Aug 2013 22:35:18 -0700 Subject: Add an option to the systemreset() call and to the reboot command (-b) to reboot into the bootloader. The system will remain in the bootloader until it's reset, or until an upload is completed. --- src/modules/commander/state_machine_helper.c | 2 +- src/modules/systemlib/systemlib.c | 12 +++++++++++- src/modules/systemlib/systemlib.h | 2 +- src/systemcmds/reboot/reboot.c | 19 ++++++++++++++++++- 4 files changed, 31 insertions(+), 4 deletions(-) (limited to 'src/modules/systemlib/systemlib.h') diff --git a/src/modules/commander/state_machine_helper.c b/src/modules/commander/state_machine_helper.c index c26478785..9b6527c33 100644 --- a/src/modules/commander/state_machine_helper.c +++ b/src/modules/commander/state_machine_helper.c @@ -141,7 +141,7 @@ int do_state_update(int status_pub, struct vehicle_status_s *current_status, con current_status->flag_system_armed = false; mavlink_log_critical(mavlink_fd, "REBOOTING SYSTEM"); usleep(500000); - systemreset(); + systemreset(false); /* SPECIAL CASE: NEVER RETURNS FROM THIS FUNCTION CALL */ } else { diff --git a/src/modules/systemlib/systemlib.c b/src/modules/systemlib/systemlib.c index 96276b56a..57a751e1c 100644 --- a/src/modules/systemlib/systemlib.c +++ b/src/modules/systemlib/systemlib.c @@ -50,9 +50,19 @@ #include #include +#include + #include "systemlib.h" -__EXPORT extern void systemreset(void) { +void +systemreset(bool to_bootloader) +{ + if (to_bootloader) { + stm32_pwr_enablebkp(); + + /* XXX wow, this is evil - write a magic number into backup register zero */ + *(uint32_t *)0x40002850 = 0xb007b007; + } up_systemreset(); } diff --git a/src/modules/systemlib/systemlib.h b/src/modules/systemlib/systemlib.h index 77fdfe08a..3728f2067 100644 --- a/src/modules/systemlib/systemlib.h +++ b/src/modules/systemlib/systemlib.h @@ -45,7 +45,7 @@ __BEGIN_DECLS /** Reboots the board */ -__EXPORT void systemreset(void) noreturn_function; +__EXPORT void systemreset(bool to_bootloader) noreturn_function; /** Sends SIGUSR1 to all processes */ __EXPORT void killall(void); diff --git a/src/systemcmds/reboot/reboot.c b/src/systemcmds/reboot/reboot.c index 0fd1e2724..91a2c2eb8 100644 --- a/src/systemcmds/reboot/reboot.c +++ b/src/systemcmds/reboot/reboot.c @@ -40,14 +40,31 @@ #include #include #include +#include #include +#include __EXPORT int reboot_main(int argc, char *argv[]); int reboot_main(int argc, char *argv[]) { - systemreset(); + int ch; + bool to_bootloader = false; + + while ((ch = getopt(argc, argv, "b")) != -1) { + switch (ch) { + case 'b': + to_bootloader = true; + break; + default: + errx(1, "usage: reboot [-b]\n" + " -b reboot into the bootloader"); + + } + } + + systemreset(to_bootloader); } -- cgit v1.2.3