2019-10-11 22:59:48 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 Alexandre Abadie <alexandre.abadie@inria.fr>
|
|
|
|
*
|
|
|
|
* 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 sys_shell_commands
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Trigger a firmware update from the shell
|
|
|
|
*
|
|
|
|
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
|
|
|
*
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
2022-05-31 23:27:27 +02:00
|
|
|
#include "shell.h"
|
2022-04-14 08:39:28 +02:00
|
|
|
#include "suit/storage.h"
|
2022-05-31 23:27:27 +02:00
|
|
|
#include "suit/transport/coap.h"
|
2022-04-14 08:39:28 +02:00
|
|
|
|
2022-09-04 23:26:30 +02:00
|
|
|
#ifdef MODULE_SUIT_STORAGE_FLASHWRITE
|
|
|
|
#include "riotboot/flashwrite.h"
|
|
|
|
#include "periph/pm.h"
|
|
|
|
#endif
|
|
|
|
|
2022-04-14 08:39:28 +02:00
|
|
|
static void _print_usage(char **argv)
|
|
|
|
{
|
|
|
|
printf("Usage: %s fetch <manifest url>\n", argv[0]);
|
|
|
|
printf(" %s seq_no\n", argv[0]);
|
2022-09-04 23:26:30 +02:00
|
|
|
if (IS_USED(MODULE_SUIT_STORAGE_FLASHWRITE)) {
|
|
|
|
printf(" %s revert\n", argv[0]);
|
|
|
|
}
|
2022-04-14 08:39:28 +02:00
|
|
|
}
|
2019-10-11 22:59:48 +02:00
|
|
|
|
2022-06-08 08:51:38 +02:00
|
|
|
static int _suit_handler(int argc, char **argv)
|
2019-10-11 22:59:48 +02:00
|
|
|
{
|
2022-04-14 08:39:28 +02:00
|
|
|
if (argc < 2) {
|
|
|
|
_print_usage(argv);
|
2019-10-11 22:59:48 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-04-14 08:39:28 +02:00
|
|
|
if (strcmp(argv[1], "fetch") == 0) {
|
2022-09-03 23:22:31 +02:00
|
|
|
suit_worker_trigger(argv[2], strlen(argv[2]));
|
2022-04-14 08:39:28 +02:00
|
|
|
}
|
|
|
|
else if (strcmp(argv[1], "seq_no") == 0) {
|
|
|
|
uint32_t seq_no = 0;
|
|
|
|
suit_storage_get_highest_seq_no(&seq_no);
|
2022-04-21 10:53:57 +02:00
|
|
|
printf("seq_no: 0x%08" PRIx32 "\n", seq_no);
|
2022-04-14 08:39:28 +02:00
|
|
|
}
|
2022-09-04 23:26:30 +02:00
|
|
|
#ifdef MODULE_SUIT_STORAGE_FLASHWRITE
|
|
|
|
else if (strcmp(argv[1], "revert") == 0) {
|
|
|
|
int res = riotboot_flashwrite_invalidate_latest();
|
|
|
|
if (res) {
|
|
|
|
printf("revert failed: %d\n", res);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("reverted to previous version, rebooting…\n");
|
|
|
|
pm_reboot();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2022-04-14 08:39:28 +02:00
|
|
|
else {
|
|
|
|
_print_usage(argv);
|
|
|
|
return -1;
|
|
|
|
}
|
2019-10-11 22:59:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2022-05-31 23:27:27 +02:00
|
|
|
|
|
|
|
SHELL_COMMAND(suit, "Trigger a SUIT firmware update", _suit_handler);
|