File tree Expand file tree Collapse file tree 2 files changed +30
-8
lines changed
dist/tools/riotboot_gen_hdr Expand file tree Collapse file tree 2 files changed +30
-8
lines changed Original file line number Diff line number Diff line change 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}
Original file line number Diff line number Diff line change 1414 * @author Kaspar Schleiser <[email protected] > 1515 */
1616
17+ #include <stdbool.h>
1718#include <stdio.h>
1819#include <string.h>
1920
2021int genhdr (int argc , char * argv []);
2122int updatehdr (int argc , char * argv []);
22- int readhdr (const char * file );
23+ int readhdr (const char * file , bool json );
2324
2425int 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
4346usage :
You can’t perform that action at this time.
0 commit comments