From 47e70e62771d161615951a6f0a540ad015bec8d7 Mon Sep 17 00:00:00 2001 From: 3djc Date: Thu, 19 Mar 2020 11:40:34 +0100 Subject: [PATCH] Radiomaster production firmware build tool --- radio/src/CMakeLists.txt | 4 ++ radio/src/stamp.cpp | 2 + tools/build-radiomaster.py | 77 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100755 tools/build-radiomaster.py diff --git a/radio/src/CMakeLists.txt b/radio/src/CMakeLists.txt index 8124cf651..20852450c 100644 --- a/radio/src/CMakeLists.txt +++ b/radio/src/CMakeLists.txt @@ -340,6 +340,10 @@ if(JUMPER_RELEASE) add_definitions(-DJUMPER_RELEASE) endif() +if(RADIOMASTER_RELEASE) + add_definitions(-DRADIOMASTER_RELEASE) +endif() + if(TBS_RELEASE) add_definitions(-DTBS_RELEASE) endif() diff --git a/radio/src/stamp.cpp b/radio/src/stamp.cpp index 2369955b3..f4f8b836a 100644 --- a/radio/src/stamp.cpp +++ b/radio/src/stamp.cpp @@ -36,6 +36,8 @@ #define DISPLAY_VERSION "FrSky" #elif defined(JUMPER_RELEASE) #define DISPLAY_VERSION "JumperRC" +#elif defined(RADIOMASTER_RELEASE) +#define DISPLAY_VERSION "Radiomaster" #elif defined(TBS_RELEASE) #define DISPLAY_VERSION "TBS" #else diff --git a/tools/build-radiomaster.py b/tools/build-radiomaster.py new file mode 100755 index 000000000..83faa31bb --- /dev/null +++ b/tools/build-radiomaster.py @@ -0,0 +1,77 @@ +#!/usr/bin/python3 + +import argparse +import datetime +import os +from builtins import NotADirectoryError +import shutil +import tempfile + + +boards = { + "TX16S_1": { + "PCB": "X10", + "PCBREV": "TX16S", + "DEFAULT_MODE": "1", + }, + "TX16S_2": { + "PCB": "X10", + "PCBREV": "TX16S", + "DEFAULT_MODE": "2", + } +} + +translations = [ + "EN", +] + + +def timestamp(): + return datetime.datetime.now().strftime("%y%m%d") + + +def build(board, translation, srcdir): + cmake_options = " ".join(["-D%s=%s" % (key, value) for key, value in boards[board].items()]) + cwd = os.getcwd() + if not os.path.exists("output"): + os.mkdir("output") + path = tempfile.mkdtemp() + os.chdir(path) + command = "cmake %s -DTRANSLATIONS=%s -DRADIOMASTER_RELEASE=YES %s" % (cmake_options, translation, srcdir) + print(command) + os.system(command) + os.system("make firmware -j6") + os.chdir(cwd) + index = 0 + while 1: + suffix = "" if index == 0 else "_%d" % index + filename = "output/firmware_%s_%s_%s%s.bin" % (board.lower(), translation.lower(), timestamp(), suffix) + if not os.path.exists(filename): + shutil.copy("%s/firmware.bin" % path, filename) + break + index += 1 + shutil.rmtree(path) + + +def dir_path(string): + if os.path.isdir(string): + return string + else: + raise NotADirectoryError(string) + + +def main(): + parser = argparse.ArgumentParser(description="Build Radiomaster firmware") + parser.add_argument("-b", "--boards", action="append", help="Destination boards", required=True) + parser.add_argument("-t", "--translations", action="append", help="Translations", required=True) + parser.add_argument("srcdir", type=dir_path) + + args = parser.parse_args() + + for board in (boards.keys() if "ALL" in args.boards else args.boards): + for translation in (translations if "ALL" in args.translations else args.translations): + build(board, translation, args.srcdir) + + +if __name__ == "__main__": + main()