mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
102 lines
2.6 KiB
C
102 lines
2.6 KiB
C
/*
|
|
* Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.de>
|
|
*
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
* directory for more details.
|
|
*/
|
|
|
|
/**
|
|
* @ingroup tests
|
|
* @{
|
|
*
|
|
* @file
|
|
* @brief riotboot_flashwrite test application
|
|
*
|
|
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
|
* @}
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "thread.h"
|
|
#include "irq.h"
|
|
#include "net/nanocoap_sock.h"
|
|
|
|
#include "shell.h"
|
|
|
|
#include "riotboot/slot.h"
|
|
#include "riotboot/flashwrite.h"
|
|
|
|
#define MAIN_QUEUE_SIZE (8)
|
|
static msg_t _main_msg_queue[MAIN_QUEUE_SIZE];
|
|
|
|
static int cmd_print_riotboot_hdr(int argc, char **argv)
|
|
{
|
|
(void)argc;
|
|
(void)argv;
|
|
|
|
int current_slot = riotboot_slot_current();
|
|
if (current_slot != -1) {
|
|
/* Sometimes, udhcp output messes up the following printfs. That
|
|
* confuses the test script. As a workaround, just disable interrupts
|
|
* for a while.
|
|
*/
|
|
unsigned state = irq_disable();
|
|
riotboot_slot_print_hdr(current_slot);
|
|
irq_restore(state);
|
|
}
|
|
else {
|
|
puts("[FAILED] You're not running riotboot");
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static int cmd_print_current_slot(int argc, char **argv)
|
|
{
|
|
(void)argc;
|
|
(void)argv;
|
|
/* Sometimes, udhcp output messes up the following printfs. That
|
|
* confuses the test script. As a workaround, just disable interrupts
|
|
* for a while.
|
|
*/
|
|
unsigned state = irq_disable();
|
|
printf("Running from slot %d\n", riotboot_slot_current());
|
|
irq_restore(state);
|
|
return 0;
|
|
}
|
|
|
|
static int cmd_riotboot_invalidate(int argc, char **argv)
|
|
{
|
|
if (argc < 2) {
|
|
puts("usage: riotboot-invalidate <slot number>");
|
|
}
|
|
riotboot_flashwrite_invalidate(atoi(argv[1]));
|
|
return 0;
|
|
}
|
|
|
|
static const shell_command_t shell_commands[] = {
|
|
{ "current-slot", "Print current slot number", cmd_print_current_slot },
|
|
{ "riotboot-hdr", "Print current slot header", cmd_print_riotboot_hdr },
|
|
{ "riotboot-invalidate", "Invalidate slot <slot number>", cmd_riotboot_invalidate },
|
|
{ NULL, NULL, NULL }
|
|
};
|
|
|
|
int main(void)
|
|
{
|
|
puts("riotboot_flashwrite test application");
|
|
|
|
cmd_print_current_slot(0, NULL);
|
|
cmd_print_riotboot_hdr(0, NULL);
|
|
|
|
/* the shell contains commands that receive packets via GNRC and thus
|
|
needs a msg queue */
|
|
msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE);
|
|
|
|
puts("Starting the shell");
|
|
char line_buf[SHELL_DEFAULT_BUFSIZE];
|
|
shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
|
|
|
|
return 0;
|
|
}
|