From 7dd690908876013669dff97d759ef558f8944762 Mon Sep 17 00:00:00 2001 From: Andreas Gnau Date: Sun, 9 Dec 2018 03:20:33 +0100 Subject: [PATCH 1/3] gitignore: Match MPLAB X projects in a general way --- .gitignore | 49 +++++++++---------------------------------------- 1 file changed, 9 insertions(+), 40 deletions(-) diff --git a/.gitignore b/.gitignore index cba748d0..937f8180 100644 --- a/.gitignore +++ b/.gitignore @@ -1,43 +1,12 @@ -/Bootloaders/BPv3-bootloader/firmware-v4.5/ds30loader.X/dist/default/ -/Bootloaders/BPv3-bootloader/firmware-v4.5/ds30loader.X/nbproject/private/ -/Bootloaders/BPv4-bootloader/firmware-v1/bpv4-bootloader.X/build/default/ -/Bootloaders/BPv4-bootloader/firmware-v1/bpv4-bootloader.X/dist/default/ -/Bootloaders/BPv4-bootloader/firmware-v1/bpv4-bootloader.X/nbproject/Makefile-default.mk -/Bootloaders/BPv4-bootloader/firmware-v1/bpv4-bootloader.X/nbproject/Makefile-genesis.properties -/Bootloaders/BPv4-bootloader/firmware-v1/bpv4-bootloader.X/nbproject/Makefile-impl.mk -/Bootloaders/BPv4-bootloader/firmware-v1/bpv4-bootloader.X/nbproject/Makefile-local-default.mk -/Bootloaders/BPv4-bootloader/firmware-v1/bpv4-bootloader.X/nbproject/Makefile-variables.mk -/Bootloaders/BPv4-bootloader/firmware-v1/bpv4-bootloader.X/nbproject/Package-default.bash -/Bootloaders/BPv4-bootloader/firmware-v1/bpv4-bootloader.X/nbproject/private/ -/Firmware-Alternates/ADC2UART/ADC2UART.X/build/default/ -/Firmware-Alternates/ADC2UART/ADC2UART.X/dist/default/ -/Firmware-Alternates/ADC2UART/ADC2UART.X/nbproject/private/ -/Firmware-Alternates/Blink_MODE_LED/Blink_MODE_LED.X/dist/default/ -/Firmware-Alternates/Blink_MODE_LED/Blink_MODE_LED.X/nbproject/private/ -/Firmware-Alternates/BusPirateADCDemo/Bus Pirate ADC Demo.X/nbproject/private/ -/Firmware-Alternates/BusPirateUARTDEMOTEST/UARTdemo.X/nbproject/private/ -/Firmware-Alternates/firmware-STK500v2/BusPirate-stk500.X/build/default/ -/Firmware-Alternates/firmware-STK500v2/BusPirate-stk500.X/dist/default/ -/Firmware-Alternates/firmware-STK500v2/BusPirate-stk500.X/nbproject/private/ +# MPLAB X +**/*.X/build/ +**/*.X/debug/ +**/*.X/dist/ +**/*.X/nbproject/Makefile* +**/*.X/nbproject/Package-*.bash +**/*.X/nbproject/private/ + + /Firmware/Documentation/ /Firmware/busPirate.X/*.[is] /Firmware/busPirate.X/*.map -/Firmware/busPirate.X/build/BusPirate_v3/ -/Firmware/busPirate.X/build/BusPirate_v4/ -/Firmware/busPirate.X/build/default/ -/Firmware/busPirate.X/debug/ -/Firmware/busPirate.X/dist/ -/Firmware/busPirate.X/nbproject/Makefile-BusPirate_v3.mk -/Firmware/busPirate.X/nbproject/Makefile-BusPirate_v4.mk -/Firmware/busPirate.X/nbproject/Makefile-default.mk -/Firmware/busPirate.X/nbproject/Makefile-genesis.properties -/Firmware/busPirate.X/nbproject/Makefile-impl.mk -/Firmware/busPirate.X/nbproject/Makefile-local-BusPirate_v3.mk -/Firmware/busPirate.X/nbproject/Makefile-local-BusPirate_v4.mk -/Firmware/busPirate.X/nbproject/Makefile-local-default.mk -/Firmware/busPirate.X/nbproject/Makefile-variables.mk -/Firmware/busPirate.X/nbproject/Package-BusPirate_v3.bash -/Firmware/busPirate.X/nbproject/Package-BusPirate_v4.bash -/Firmware/busPirate.X/nbproject/Package-default.bash -/Firmware/busPirate.X/nbproject/private/ -/Bootloaders/BPv3-bootloader/firmware-v4.5/ds30loader.X/build/default/ \ No newline at end of file From 9793935c3dc9478a16f492fbe79408a4517b4d16 Mon Sep 17 00:00:00 2001 From: Andreas Gnau Date: Sun, 9 Dec 2018 03:20:52 +0100 Subject: [PATCH 2/3] Embed version string in binaries via Git Use 'git describe --tags --always --dirty' to generate a version string which gets included in every binary. The --tags is necessary, because the latest tag 'v7.0' is not an annotated tag. If the git-describe-output changes, make will rebuild the required files automatically. Unfortunately, this is broken on Windows due to a bug in Microchip's toolchain: https://www.microchip.com/forums/m1061336.aspx Until that is fixed, a full rebuild is always done on Windows platforms, because builds that are a bit slower are better than hard to debug situations due to inconsistent builds. --- Firmware/base.h | 4 ++- Firmware/busPirate.X/Makefile | 29 ++++++++++++--- .../busPirate.X/nbproject/configurations.xml | 4 +-- scripts/generate-version-header | 32 +++++++++++++++++ scripts/generate-version-header.bat | 36 +++++++++++++++++++ 5 files changed, 98 insertions(+), 7 deletions(-) create mode 100755 scripts/generate-version-header create mode 100644 scripts/generate-version-header.bat diff --git a/Firmware/base.h b/Firmware/base.h index 74156095..38601157 100644 --- a/Firmware/base.h +++ b/Firmware/base.h @@ -41,10 +41,12 @@ #include "messages.h" #include "types.h" +#include "bp-version.h" + /** * @brief Firmware version string, used at startup and for the 'i' command. */ -#define BP_FIRMWARE_STRING "Community Firmware v7.1 - goo.gl/gCzQnW " +#define BP_FIRMWARE_STRING "Community Firmware " BP_GIT_VERSION_STRING " - goo.gl/gCzQnW " /** * @brief Current mode configuration settings structure. diff --git a/Firmware/busPirate.X/Makefile b/Firmware/busPirate.X/Makefile index 5edcb792..357911be 100644 --- a/Firmware/busPirate.X/Makefile +++ b/Firmware/busPirate.X/Makefile @@ -43,18 +43,38 @@ # NOCDDL -# Environment -MKDIR=mkdir +# Environment +ifeq ($(OS),Windows_NT) + MKDIR=gnumkdir +else + MKDIR=mkdir +endif CP=cp CCADMIN=CCadmin RANLIB=ranlib +# This will automatically pick the .bat-file on Windows. +GENERATE_VERSION_HEADER=../../scripts/generate-version-header +# CND_BUILDDIR is not used at all, "build" is hardcoded in generated Makefiles. +# Use our own variable BUILD_DIR instead. +BUILD_DIR=build +BP_VERSION_H=$(BUILD_DIR)/bp-version.h +# BUILD_DIR is added to include path in MPLAB X project file. # build build: .build-post -.build-pre: -# Add your pre 'build' code here... + +ifeq ($(OS),Windows_NT) +windows-workaround: clean + @echo Had to clean because of Windows-only bug: https://www.microchip.com/forums/m1061336.aspx +else +windows-workaround: +endif + +.build-pre: windows-workaround + $(MKDIR) -p $(BUILD_DIR) + $(GENERATE_VERSION_HEADER) $(BP_VERSION_H) .build-post: .build-impl # Add your post 'build' code here... @@ -65,6 +85,7 @@ clean: .clean-post .clean-pre: # Add your pre 'clean' code here... + rm -f $(BP_VERSION_H) .clean-post: .clean-impl # Add your post 'clean' code here... diff --git a/Firmware/busPirate.X/nbproject/configurations.xml b/Firmware/busPirate.X/nbproject/configurations.xml index 159bb302..4fa4ab45 100644 --- a/Firmware/busPirate.X/nbproject/configurations.xml +++ b/Firmware/busPirate.X/nbproject/configurations.xml @@ -386,7 +386,7 @@ - + @@ -952,7 +952,7 @@ - + diff --git a/scripts/generate-version-header b/scripts/generate-version-header new file mode 100755 index 00000000..a8968b19 --- /dev/null +++ b/scripts/generate-version-header @@ -0,0 +1,32 @@ +#!/bin/sh -eu +if [ $# -ne 1 ]; then + echo "Usage: $0 " >&2 + exit 1 +fi + + +output_file="$1" +output_file_tmp="$(mktemp)" +trap finish EXIT + +finish() { + rm -f "$output_file_tmp" +} + +version="$(git describe --tags --always --dirty)" + +cat > "$output_file_tmp" <" 1>&2 + exit 1 +) + +set output_file=%1 +rem Accept forward slashes as directory separator for better portability. +set "output_file=%output_file:/=\%" +set output_file_tmp=%output_file%.tmp + +for /f %%i in ('git describe --tags --always --dirty') do set version=%%i +set e=%ERRORLEVEL% +if "%version%" == "" ( + echo Failed to get version info via git. 1>&2 + echo Ensure git is in path and project is cloned by git. 1>&2 + exit %e% +) + +echo /**>%output_file_tmp% +echo * @brief Version string generated using git describe, @see BP_FIRMWARE_STRING>>%output_file_tmp% +echo */>>%output_file_tmp% +echo #define BP_GIT_VERSION_STRING "%version%">>%output_file_tmp% + + +rem Only update file if it has changed (avoids unneccessary rebuilds) +fc /b %output_file% %output_file_tmp% > NUL +IF %ERRORLEVEL% NEQ 0 ( + copy %output_file_tmp% %output_file% + echo Updated Git version string in %output_file%: %version%. +) else ( + echo No update needed for Git version string in %output_file%: %version%. +) + +rem Cleanup +del %output_file_tmp% > NUL From 8de56868c21cb16b121eca784c778679c0cc4e5f Mon Sep 17 00:00:00 2001 From: Andreas Gnau Date: Sun, 4 Nov 2018 18:45:15 +0100 Subject: [PATCH 3/3] CI: Build on CircleCI with XC16 1.36B and MPLABX 5.10 --- .circleci/config.yml | 163 ++++++++++++++++++++++++++++++++++++++++++ .circleci/mplabx.envs | 2 + .circleci/xc16.envs | 2 + 3 files changed, 167 insertions(+) create mode 100644 .circleci/config.yml create mode 100644 .circleci/mplabx.envs create mode 100644 .circleci/xc16.envs diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 00000000..f6cc98e4 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,163 @@ +version: 2 + +shared: &shared + docker: + - image: debian:stretch + environment: &shared_environment + CLICOLOR_FORCE: 1 + mplabx_dir: /opt/mplabx + + steps: + - run: + name: Install dependencies + command: | + dpkg --add-architecture i386 + apt-get update + apt-get install -y --no-install-recommends \ + wget \ + git \ + ca-certificates \ + libc6:i386 \ + make \ + procps \ + + - checkout + + - restore_cache: + name: Restore XC16 installation from cache + keys: + - xc16-{{ checksum ".circleci/xc16.envs" }} + - run: + name: Install XC16 + command: | + source ./.circleci/xc16.envs + url="https://ww1.microchip.com/downloads/en/DeviceDoc/xc16-v${xc16_version}-full-install-linux-installer.run" + xc16_inst='/tmp/xc16' + xc16_install_marker="/opt/microchip/xc16/hash-$xc16_inst_sha256" + if [ -f "$xc16_install_marker" ]; then + echo 'XC16 in cache' + exit 0 + fi + + wget -O "$xc16_inst" "$url" + chmod +x "$xc16_inst" + sha256sum -c <(echo "${xc16_inst_sha256} *${xc16_inst}") + "$xc16_inst" --version + "$xc16_inst" \ + --mode unattended \ + --unattendedmodeui none \ + --netservername localhost \ + --LicenseType FreeMode \ + + rm -fv "$xc16_inst" + touch "$xc16_install_marker" + - save_cache: + name: Save XC16 installation to cache + key: xc16-{{ checksum ".circleci/xc16.envs" }} + paths: + - /opt/microchip + + - restore_cache: + name: Restore MBLAB X installation from cache + keys: + - mplabx-{{ checksum ".circleci/mplabx.envs" }} + - run: + name: Install MPLAB X + command: | + source ./.circleci/mplabx.envs + mplabx_url="https://ww1.microchip.com/downloads/en/DeviceDoc/MPLABX-v${mplabx_version}-linux-installer.tar" + mplabx_tar='mplabx.tar' + mplabx_inst="./MPLABX-v${mplabx_version}-linux-installer.sh" + mplabx_install_marker="$mplabx_dir/hash-$mplabx_tar_sha256" + if [ -f "$mplabx_install_marker" ]; then + echo 'MPLABX in cache' + exit 0 + fi + + wget -O "$mplabx_tar" "$mplabx_url" + sha256sum -c <(echo "${mplabx_tar_sha256} *${mplabx_tar}") + tar xf "$mplabx_tar" + USER=root "$mplabx_inst" --nolibrarycheck -- --version + USER=root "$mplabx_inst" --nolibrarycheck --nox11 -- \ + --unattendedmodeui none \ + --mode unattended \ + --ipe 0 \ + --installdir "$mplabx_dir" \ + + rm -fv "$mplabx_tar" "$mplabx_inst" + touch "$mplabx_install_marker" + - save_cache: + name: Save MPLAB X installation to cache + key: mplabx-{{ checksum ".circleci/mplabx.envs" }} + paths: + - /opt/mplabx + + - run: + name: Configure + command: | + $mplabx_dir/mplab_platform/bin/prjMakefilesGenerator.sh -v "$project_dir" + + + - run: + name: Build + command: | + make -C "$project_dir" CONF="$build_config" build + + - run: + name: Prepare artifacts + command: | + # part of this is a workaround for CircleCI not supporting string interpolation or symlinks in store_artifacts + artifacts_dir="${project_dir}/dist/${build_config}/production" + git_describe="$(git describe --tags --always --long)" + mkdir ./artifacts/ + for file in $artifacts_dir/*; do + filename=$(basename -- "$file") + extension="${filename##*.}" + filename="${filename%.*}" + cp -av "$file" "./artifacts/${CIRCLE_JOB}-${filename}-${git_describe}-${CIRCLE_BUILD_NUM}.${extension}" + done + + - store_artifacts: + path: ./artifacts/ + destination: artifacts + + + +jobs: + firmware-bp-v4: + <<: *shared + environment: + <<: *shared_environment + build_config: BusPirate_v4 + project_dir: ./Firmware/busPirate.X + + firmware-bp-v3: + <<: *shared + environment: + <<: *shared_environment + build_config: BusPirate_v3 + project_dir: ./Firmware/busPirate.X + + boot-bp-v4: + <<: *shared + environment: + <<: *shared_environment + build_config: default + project_dir: ./Bootloaders/BPv4-bootloader/firmware-v1/bpv4-bootloader.X + + boot-bp-v3: + <<: *shared + environment: + <<: *shared_environment + build_config: default + project_dir: ./Bootloaders/BPv3-bootloader/firmware-v4.5/ds30loader.X + +workflows: + version: 2 + build: + jobs: + - firmware-bp-v4 + - firmware-bp-v3 + - boot-bp-v4 + - boot-bp-v3 + diff --git a/.circleci/mplabx.envs b/.circleci/mplabx.envs new file mode 100644 index 00000000..905a6d2f --- /dev/null +++ b/.circleci/mplabx.envs @@ -0,0 +1,2 @@ +mplabx_version='5.10' +mplabx_tar_sha256='44da76b8f3f64876a427a474e17ce398f3af42319694acdcc8a7587e2be7337c' diff --git a/.circleci/xc16.envs b/.circleci/xc16.envs new file mode 100644 index 00000000..7fd7f78b --- /dev/null +++ b/.circleci/xc16.envs @@ -0,0 +1,2 @@ +xc16_version='1.36B' +xc16_inst_sha256='37c1d9bd53d65556f87482e20bd5384d6f5ffa855123f7f8c65fd02b811849e6'