|
25 | 25 |
|
26 | 26 | #include "suit/transport/coap.h" |
27 | 27 | #ifdef MODULE_SUIT_STORAGE_FLASHWRITE |
| 28 | +#include "periph/flashpage.h" |
28 | 29 | #include "riotboot/slot.h" |
29 | 30 | #endif |
30 | 31 |
|
@@ -69,19 +70,47 @@ static int cmd_print_riotboot_hdr(int argc, char **argv) |
69 | 70 | (void)argc; |
70 | 71 | (void)argv; |
71 | 72 |
|
72 | | - int current_slot = riotboot_slot_current(); |
73 | | - if (current_slot != -1) { |
| 73 | + if (riotboot_slot_current() == -1) { |
| 74 | + printf("[FAILED] You're not running riotboot\n"); |
| 75 | + return -1; |
| 76 | + } |
| 77 | + if (argc == 1) { |
| 78 | + printf("Usage: %s [<slot> [activate|deactivate|confirm|dismiss]]\n", argv[0]); |
| 79 | + return 0; |
| 80 | + } |
| 81 | + int slot = atoi(argv[1]); |
| 82 | + if (argc == 2) { |
74 | 83 | /* Sometimes, udhcp output messes up the following printfs. That |
75 | | - * confuses the test script. As a workaround, just disable interrupts |
76 | | - * for a while. |
77 | | - */ |
| 84 | + * confuses the test script. As a workaround, just disable interrupts |
| 85 | + * for a while. |
| 86 | + */ |
78 | 87 | unsigned state = irq_disable(); |
79 | | - riotboot_slot_print_hdr(current_slot); |
| 88 | + riotboot_slot_print_hdr(slot); |
80 | 89 | irq_restore(state); |
| 90 | + return 0; |
81 | 91 | } |
82 | | - else { |
83 | | - printf("[FAILED] You're not running riotboot\n"); |
| 92 | + riotboot_hdr_t hdr = *riotboot_slot_get_hdr(slot); |
| 93 | + if (riotboot_hdr_is_v2(&hdr)) { |
| 94 | + if (!strcmp(argv[2], "activate")) { |
| 95 | + riotboot_hdr_set_img_state(&hdr, RIOTBOOT_HDR_IMG_STATE_ACTIVATED); |
| 96 | + } |
| 97 | + else if (!strcmp(argv[2], "deactivate")) { |
| 98 | + riotboot_hdr_set_img_state(&hdr, RIOTBOOT_HDR_IMG_STATE_DEACTIVATED); |
| 99 | + } |
| 100 | + else if (!strcmp(argv[2], "confirm")) { |
| 101 | + riotboot_hdr_set_img_state(&hdr, RIOTBOOT_HDR_IMG_STATE_CONFIRMED); |
| 102 | + } |
| 103 | + else if (!strcmp(argv[2], "dismiss")) { |
| 104 | + riotboot_hdr_set_img_state(&hdr, RIOTBOOT_HDR_IMG_STATE_DISMISSED); |
| 105 | + } |
| 106 | + else { |
| 107 | + printf("Unknown command %s\n", argv[2]); |
| 108 | + return -1; |
| 109 | + } |
| 110 | + flashpage_write(flashpage_addr(flashpage_page(riotboot_slot_get_hdr(slot))), |
| 111 | + &hdr.v2, sizeof(hdr.v2)); |
84 | 112 | } |
| 113 | + |
85 | 114 | return 0; |
86 | 115 | } |
87 | 116 |
|
|
0 commit comments