From a686fd557792dd873a43c2d6db6c4bc0f60d0539 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Tue, 1 Nov 2022 21:13:11 +0100 Subject: [PATCH] Updated build system with firmware hash and release info generator --- .gitignore | 1 + Makefile | 10 ++++++++-- release_hashes.py | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 release_hashes.py diff --git a/.gitignore b/.gitignore index 2b2762b..9451935 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ TODO Release/*.hex Release/*.zip +Release/*.json diff --git a/Makefile b/Makefile index 09a3385..5f6eb41 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,6 @@ -prep: +prep: prep-avr prep-esp32 prep-samd + +prep-avr: arduino-cli core update-index --config-file arduino-cli.yaml arduino-cli core install arduino:avr arduino-cli core install unsignedio:avr @@ -8,6 +10,7 @@ prep-esp32: arduino-cli core install esp32:esp32 arduino-cli lib install "Adafruit SSD1306" arduino-cli lib install "AXP202X_Library" + arduino-cli lib install "Crypto" prep-samd: arduino-cli core update-index --config-file arduino-cli.yaml @@ -86,7 +89,10 @@ upload-mega2560: release: release-all -release-all: release-rnode release-mega2560 release-tbeam release-lora32_v20 release-lora32_v21 release-lora32_v20_extled release-lora32_v21_extled release-featheresp32 release-genericesp32 release-heltec32_v2 release-heltec32_v2_extled release-rnode_ng_20 release-rnode_ng_21 +release-all: release-rnode release-mega2560 release-tbeam release-lora32_v20 release-lora32_v21 release-lora32_v20_extled release-lora32_v21_extled release-featheresp32 release-genericesp32 release-heltec32_v2 release-heltec32_v2_extled release-rnode_ng_20 release-rnode_ng_21 release-hashes + +release-hashes: + python ./release_hashes.py > ./Release/release.json release-rnode: arduino-cli compile --fqbn unsignedio:avr:rnode -e diff --git a/release_hashes.py b/release_hashes.py new file mode 100644 index 0000000..282dae6 --- /dev/null +++ b/release_hashes.py @@ -0,0 +1,33 @@ +import os +import json +import hashlib + +major_version = None +minor_version = None +target_version = None + +file = open("Config.h", "rb") +config_data = file.read().splitlines() +for line in config_data: + dline = line.decode("utf-8").strip() + components = dline.split() + if dline.startswith("#define MAJ_VERS"): + major_version = "%01d" % ord(bytes.fromhex(dline.split()[2].split("x")[1])) + if dline.startswith("#define MIN_VERS"): + minor_version = "%02d" % ord(bytes.fromhex(dline.split()[2].split("x")[1])) + +target_version = major_version+"."+minor_version + +release_hashes = {} +target_dir = "./Release" +files = os.listdir(target_dir) +for filename in files: + if os.path.isfile(os.path.join(target_dir, filename)): + if filename.startswith("rnode_firmware"): + file = open(os.path.join(target_dir, filename), "rb") + release_hashes[filename] = { + "hash": hashlib.sha256(file.read()).hexdigest(), + "version": target_version + } + +print(json.dumps(release_hashes)) \ No newline at end of file