55 proto[
'magic'] =
"PX4FWv1"
57 proto[
'board_revision'] = 0
60 proto[
'description'] =
""
61 proto[
'git_identity'] =
""
62 proto[
'build_time'] = 0
63 proto[
'image'] =
bytes()
64 proto[
'image_size'] = 0
68 parser = argparse.ArgumentParser(description=
"Firmware generator for the PX autopilot system.")
69 parser.add_argument(
"--prototype", action=
"store", help=
"read a prototype description from a file")
70 parser.add_argument(
"--board_id", action=
"store", help=
"set the board ID required")
71 parser.add_argument(
"--board_revision", action=
"store", help=
"set the board revision required")
72 parser.add_argument(
"--version", action=
"store", help=
"set a version string")
73 parser.add_argument(
"--summary", action=
"store", help=
"set a brief description")
74 parser.add_argument(
"--description", action=
"store", help=
"set a longer description")
75 parser.add_argument(
"--git_identity", action=
"store", help=
"the working directory to check for git identity")
76 parser.add_argument(
"--image", action=
"store", help=
"the firmware image")
77 args = parser.parse_args()
80 if args.prototype !=
None:
81 f = open(args.prototype,
"r")
87 desc[
'build_time'] = int(time.time())
89 if args.board_id !=
None:
90 desc[
'board_id'] = int(args.board_id)
91 if args.board_revision !=
None:
92 desc[
'board_revision'] = int(args.board_revision)
93 if args.version !=
None:
94 desc[
'version'] = str(args.version)
95 if args.summary !=
None:
96 desc[
'summary'] = str(args.summary)
97 if args.description !=
None:
98 desc[
'description'] = str(args.description)
99 if args.git_identity !=
None:
100 cmd =
" ".join([
"git",
"--git-dir", args.git_identity +
"/.git",
"describe",
"--always",
"--dirty"])
101 p = subprocess.Popen(cmd, shell=
True, stdout=subprocess.PIPE).stdout
102 desc[
'git_identity'] = str(p.read().strip())
104 if args.image !=
None:
105 f = open(args.image,
"rb")
107 desc[
'image_size'] = len(bytes)
108 desc[
'image'] = base64.b64encode(zlib.compress(bytes,9)).decode(
'utf-8')
110 print(json.dumps(desc, indent=4))
static int print(char **out, const char *format, va_list args)