Skip to content

Commit 47ab59e

Browse files
committed
dist/tools/riotboot_gen_hdr: add JSON mode
1 parent 5fa6340 commit 47ab59e

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

dist/tools/riotboot_gen_hdr/genhdr.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include <errno.h>
1616
#include <limits.h>
17+
#include <stdbool.h>
1718
#include <stdio.h>
1819
#include <stdint.h>
1920
#include <string.h>
@@ -140,7 +141,23 @@ int updatehdr(int argc, char *argv[])
140141
return 0;
141142
}
142143

143-
int readhdr(const char *file)
144+
static void print_hdr(const riotboot_hdr_t *hdr)
145+
{
146+
printf("version: %u\n", hdr->version);
147+
printf("address: 0x%x\n", hdr->start_addr);
148+
printf("checksum: %svalid\n", riotboot_hdr_validate(hdr) ? "in" : "");
149+
}
150+
151+
static void print_hdr_json(const riotboot_hdr_t *hdr)
152+
{
153+
printf("{\n");
154+
printf("\t\"version\": %u,\n", hdr->version);
155+
printf("\t\"address\": %u,\n", hdr->start_addr);
156+
printf("\t\"valid\": %s\n", riotboot_hdr_validate(hdr) ? "false" : "true");
157+
printf("}\n");
158+
}
159+
160+
int readhdr(const char *file, bool json)
144161
{
145162
riotboot_hdr_t hdr = { 0 };
146163
int res = from_file(file, &hdr, sizeof(hdr));
@@ -154,9 +171,11 @@ int readhdr(const char *file)
154171
return -EIO;
155172
}
156173

157-
printf("version: %u\n", hdr.version);
158-
printf("address: 0x%x\n", hdr.start_addr);
159-
printf("checksum: %svalid\n", riotboot_hdr_validate(&hdr) ? "in" : "");
174+
if (json) {
175+
print_hdr_json(&hdr);
176+
} else {
177+
print_hdr(&hdr);
178+
}
160179

161180
return 0;
162181
}

dist/tools/riotboot_gen_hdr/main.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,19 @@
1414
* @author Kaspar Schleiser <[email protected]>
1515
*/
1616

17+
#include <stdbool.h>
1718
#include <stdio.h>
1819
#include <string.h>
1920

2021
int genhdr(int argc, char *argv[]);
2122
int updatehdr(int argc, char *argv[]);
22-
int readhdr(const char *file);
23+
int readhdr(const char *file, bool json);
2324

2425
int main(int argc, char *argv[])
2526
{
2627
char *usage = "genhdr generate [args]\n\t"
27-
"genhdr update [file] [new_version]\n\t"
28-
"genhdr show [file]";
28+
"genhdr update <file> <new_version>\n\t"
29+
"genhdr show <file> [--json]";
2930

3031
if (argc < 2) {
3132
goto usage;
@@ -37,7 +38,9 @@ int main(int argc, char *argv[])
3738
return updatehdr(argc - 1, &argv[1]);
3839
}
3940
else if (!strcmp(argv[1], "show")) {
40-
return readhdr(argv[2]);
41+
bool json = argc > 2
42+
&& !strcmp(argv[2], "--json");
43+
return readhdr(argv[2 + json], json);
4144
}
4245

4346
usage:

0 commit comments

Comments
 (0)