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.
This commit is contained in:
px4dev 2013-08-03 22:35:18 -07:00
parent fbd5aae8c6
commit e931d3b9cd
4 changed files with 31 additions and 4 deletions

View File

@ -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 {

View File

@ -50,9 +50,19 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <stm32_pwr.h>
#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();
}

View File

@ -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);

View File

@ -40,14 +40,31 @@
#include <nuttx/config.h>
#include <unistd.h>
#include <stdio.h>
#include <getopt.h>
#include <systemlib/systemlib.h>
#include <systemlib/err.h>
__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);
}