From f8542af6533e4c1d02a6f6779b88a0e52c10a6e6 Mon Sep 17 00:00:00 2001 From: Anna Prosvetova Date: Tue, 26 Oct 2021 18:33:38 +0300 Subject: [PATCH] [FL-1989] CI: bootloader & firmware JSON manifests (#786) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [FL-1989] CI: bootloader & firmware JSON manifests * CI: reorder steps Co-authored-by: あく --- .github/workflows/build.yml | 43 ++++++++++++++++++++++++++----------- docker/Dockerfile | 1 + make/rules.mk | 6 +++++- scripts/meta.py | 32 +++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 14 deletions(-) create mode 100644 scripts/meta.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a448c0abb..e5c59cfab 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -103,6 +103,32 @@ jobs: -o firmware/.obj/${TARGET}/full.hex -Intel done + - name: 'Generate full dfu file' + if: ${{ !github.event.pull_request.head.repo.fork }} + uses: ./.github/actions/docker + with: + run: | + for TARGET in ${TARGETS} + do + hex2dfu \ + -i firmware/.obj/${TARGET}/full.hex \ + -o artifacts/flipper-z-${TARGET}-full-${{steps.names.outputs.suffix}}.dfu \ + -l "Flipper Zero $(echo $TARGET | tr a-z A-Z)" + done + + - name: 'Generate full json file' + if: ${{ !github.event.pull_request.head.repo.fork }} + uses: ./.github/actions/docker + with: + run: | + for TARGET in ${TARGETS} + do + jq -s '.[0] * .[1]' \ + bootloader/.obj/${TARGET}/bootloader.json \ + firmware/.obj/${TARGET}/firmware.json \ + > artifacts/flipper-z-${TARGET}-full-${{steps.names.outputs.suffix}}.json + done + - name: 'Move upload files' if: ${{ !github.event.pull_request.head.repo.fork }} uses: ./.github/actions/docker @@ -116,25 +142,16 @@ jobs: artifacts/flipper-z-${TARGET}-bootloader-${{steps.names.outputs.suffix}}.bin mv bootloader/.obj/${TARGET}/bootloader.elf \ artifacts/flipper-z-${TARGET}-bootloader-${{steps.names.outputs.suffix}}.elf + mv bootloader/.obj/${TARGET}/bootloader.json \ + artifacts/flipper-z-${TARGET}-bootloader-${{steps.names.outputs.suffix}}.json mv firmware/.obj/${TARGET}/firmware.dfu \ artifacts/flipper-z-${TARGET}-firmware-${{steps.names.outputs.suffix}}.dfu mv firmware/.obj/${TARGET}/firmware.bin \ artifacts/flipper-z-${TARGET}-firmware-${{steps.names.outputs.suffix}}.bin mv firmware/.obj/${TARGET}/firmware.elf \ artifacts/flipper-z-${TARGET}-firmware-${{steps.names.outputs.suffix}}.elf - done - - - name: 'Generate full dfu file' - if: ${{ !github.event.pull_request.head.repo.fork }} - uses: ./.github/actions/docker - with: - run: | - for TARGET in ${TARGETS} - do - hex2dfu \ - -i firmware/.obj/${TARGET}/full.hex \ - -o artifacts/flipper-z-${TARGET}-full-${{steps.names.outputs.suffix}}.dfu \ - -l "Flipper Zero $(echo $TARGET | tr a-z A-Z)" + mv firmware/.obj/${TARGET}/firmware.json \ + artifacts/flipper-z-${TARGET}-firmware-${{steps.names.outputs.suffix}}.json done - name: 'Full flash asssembly: bootloader as base' diff --git a/docker/Dockerfile b/docker/Dockerfile index f130305e2..d987d75ab 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -15,6 +15,7 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install --no-instal libxml2-dev \ libxslt1-dev \ zlib1g-dev \ + jq \ wget && \ apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* diff --git a/make/rules.mk b/make/rules.mk index 390b9ee0c..9f1402b9e 100644 --- a/make/rules.mk +++ b/make/rules.mk @@ -32,7 +32,7 @@ CHECK_AND_REINIT_SUBMODULES_SHELL=\ fi $(info $(shell $(CHECK_AND_REINIT_SUBMODULES_SHELL))) -all: $(OBJ_DIR)/$(PROJECT).elf $(OBJ_DIR)/$(PROJECT).hex $(OBJ_DIR)/$(PROJECT).bin $(OBJ_DIR)/$(PROJECT).dfu +all: $(OBJ_DIR)/$(PROJECT).elf $(OBJ_DIR)/$(PROJECT).hex $(OBJ_DIR)/$(PROJECT).bin $(OBJ_DIR)/$(PROJECT).dfu $(OBJ_DIR)/$(PROJECT).json $(OBJ_DIR)/$(PROJECT).elf: $(OBJECTS) @echo "\tLD\t" $@ @@ -54,6 +54,10 @@ $(OBJ_DIR)/$(PROJECT).dfu: $(OBJ_DIR)/$(PROJECT).hex -o $(OBJ_DIR)/$(PROJECT).dfu \ -l "Flipper Zero $(shell echo $(TARGET) | tr a-z A-Z)" > /dev/null +$(OBJ_DIR)/$(PROJECT).json: $(OBJ_DIR)/$(PROJECT).dfu + @echo "\tJSON\t" $@ + @python3 ../scripts/meta.py -p $(PROJECT) $(CFLAGS) > $(OBJ_DIR)/$(PROJECT).json + $(OBJ_DIR)/%.o: %.c $(OBJ_DIR)/BUILD_FLAGS @echo "\tCC\t" $< "->" $@ @$(CC) $(CFLAGS) -c $< -o $@ diff --git a/scripts/meta.py b/scripts/meta.py new file mode 100644 index 000000000..3cb8cb78a --- /dev/null +++ b/scripts/meta.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 + +import argparse +import json + + +class Main: + def __init__(self): + # parse CFLAGS + self.parser = argparse.ArgumentParser(allow_abbrev=False) + self.parser.add_argument("-p", dest="project", required=True) + self.parser.add_argument("-DBUILD_DATE", dest="build_date", required=True) + self.parser.add_argument("-DGIT_COMMIT", dest="commit", required=True) + self.parser.add_argument("-DGIT_BRANCH", dest="branch", required=True) + self.parser.add_argument("-DTARGET", dest="target", type=int, required=True) + + def __call__(self): + self.args, _ = self.parser.parse_known_args() + + meta = {} + for k, v in vars(self.args).items(): + if k == "project": + continue + if isinstance(v, str): + v = v.strip('"') + meta[self.args.project + "_" + k] = v + + print(json.dumps(meta, indent=4)) + + +if __name__ == "__main__": + Main()()