From f6bfc205c8803b74a02154f21585a6a83643bf2a Mon Sep 17 00:00:00 2001 From: xychen Date: Mon, 2 Sep 2024 12:39:00 +0800 Subject: [PATCH] [nanokit] Set up GHA for releases --- .github/workflows/build.yml | 29 +++++++++++++++++++ tools/mergehex.py | 56 +++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 tools/mergehex.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3a020abd4..1ed1ef431 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,6 +2,8 @@ on: push: pull_request: workflow_dispatch: + release: + types: [published] jobs: build: @@ -45,6 +47,7 @@ jobs: run: | python tools/progen_compile.py -t cmake_gcc_arm -g ninja csk6_nanokit_bl csk6_nanokit_if cp -v projectfiles/cmake_gcc_arm/*/build/*_crc.hex . + python tools/mergehex.py -o csk6_nanokit_factory_all.hex csk6_nanokit_bl_crc.hex csk6_nanokit_if_crc.hex - name: Upload artifacts uses: actions/upload-artifact@v4 @@ -52,3 +55,29 @@ jobs: name: firmware_${{ github.run_id }} path: | *.hex + + publish: + needs: build + if: github.event_name == 'release' + + runs-on: ubuntu-latest + + steps: + - name: Download distributables + uses: actions/download-artifact@v4 + with: + pattern: firmware_* + path: firmware/ + + - name: Rename binaries + run: | + ls -la firmware/ + for f in firmware/*.hex; do + mv $f ${f%.hex}_${{ github.event.release.tag_name }}.hex + done + + - name: Upload assets to release + uses: csexton/release-asset-action@v3 + with: + pattern: firmware/* + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/tools/mergehex.py b/tools/mergehex.py new file mode 100644 index 000000000..6d81dbe18 --- /dev/null +++ b/tools/mergehex.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2018 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: Apache-2.0 + +# This merges a set of input hex files into a single output hex file. +# Any conflicts will result in an error being reported. + +from intelhex import IntelHex +from intelhex import AddressOverlapError + +import argparse + + +def merge_hex_files(output, input_hex_files, overlap): + ih = IntelHex() + + for hex_file_path in input_hex_files: + to_merge = IntelHex(hex_file_path) + + # Since 'arm-none-eabi-objcopy' incorrectly inserts record + # type '03 - Start Segment Address', we need to remove the + # start_addr to avoid conflicts when merging. + to_merge.start_addr = None + + try: + ih.merge(to_merge, overlap=overlap) + except AddressOverlapError: + raise AddressOverlapError("{} has merge issues".format(hex_file_path)) + + ih.write_hex_file(output) + + +def parse_args(): + parser = argparse.ArgumentParser( + description="Merge hex files.", + formatter_class=argparse.RawDescriptionHelpFormatter, allow_abbrev=False) + parser.add_argument("-o", "--output", required=False, default="merged.hex", + type=argparse.FileType('w', encoding='UTF-8'), + help="Output file name.") + parser.add_argument("--overlap", default="error", + help="What to do when files overlap (error, ignore, replace). " + "See IntelHex.merge() for more info.") + parser.add_argument("input_files", nargs='*') + return parser.parse_args() + + +def main(): + args = parse_args() + + merge_hex_files(args.output, args.input_files, args.overlap) + + +if __name__ == "__main__": + main()