From 97824b7f0230a5fe0e101a444d4ba7d6f625f01d Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Fri, 3 Apr 2015 20:21:33 -0700 Subject: [PATCH] Use git describe for version in generated header file. --- .gitignore | 1 + scripts/setlocalversion | 82 ------------------------- src/Makefile | 15 ++--- src/command.c | 5 +- src/platforms/f4discovery/Makefile.inc | 1 - src/platforms/f4discovery/platform.h | 5 +- src/platforms/launchpad-icdi/platform.h | 6 +- src/platforms/libftdi/platform.c | 6 ++ src/platforms/native/Makefile.inc | 1 - src/platforms/stlink/Makefile.inc | 1 - src/platforms/stlink/platform.h | 7 ++- src/platforms/swlink/Makefile.inc | 1 - src/platforms/swlink/platform.h | 7 ++- 13 files changed, 33 insertions(+), 105 deletions(-) delete mode 100755 scripts/setlocalversion diff --git a/.gitignore b/.gitignore index 162d624..a40d44d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +src/include/version.h blackmagic *.bin *.hex diff --git a/scripts/setlocalversion b/scripts/setlocalversion deleted file mode 100755 index 46989b8..0000000 --- a/scripts/setlocalversion +++ /dev/null @@ -1,82 +0,0 @@ -#!/bin/sh -# -# This scripts adds local version information from the version -# control systems git, mercurial (hg) and subversion (svn). -# -# If something goes wrong, send a mail the kernel build mailinglist -# (see MAINTAINERS) and CC Nico Schottelius -# . -# -# - -usage() { - echo "Usage: $0 [srctree]" >&2 - exit 1 -} - -cd "${1:-.}" || usage - -# Check for git and a git repo. -if head=`git rev-parse --verify --short HEAD 2>/dev/null`; then - - # If we are at a tagged commit (like "v2.6.30-rc6"), we ignore it, - # because this version is defined in the top level Makefile. - if [ -z "`git describe --exact-match 2>/dev/null`" ]; then - - # If we are past a tagged commit (like "v2.6.30-rc5-302-g72357d5"), - # we pretty print it. - if atag="`git describe 2>/dev/null`"; then - echo "$atag" | awk -F- '{printf("-%05d-%s", $(NF-1),$(NF))}' - - # If we don't have a tag at all we print -g{commitish}. - else - printf '%s%s' -g $head - fi - fi - - # Is this git on svn? - if git config --get svn-remote.svn.url >/dev/null; then - printf -- '-svn%s' "`git svn find-rev $head`" - fi - - # Update index only on r/w media - [ -w . ] && git update-index --refresh --unmerged > /dev/null - - # Check for uncommitted changes - if git diff-index --name-only HEAD | grep -v "^scripts/package" \ - | read dummy; then - printf '%s' -dirty - fi - - # All done with git - exit -fi - -# Check for mercurial and a mercurial repo. -if hgid=`hg id 2>/dev/null`; then - tag=`printf '%s' "$hgid" | cut -d' ' -f2` - - # Do we have an untagged version? - if [ -z "$tag" -o "$tag" = tip ]; then - id=`printf '%s' "$hgid" | sed 's/[+ ].*//'` - printf '%s%s' -hg "$id" - fi - - # Are there uncommitted changes? - # These are represented by + after the changeset id. - case "$hgid" in - *+|*+\ *) printf '%s' -dirty ;; - esac - - # All done with mercurial - exit -fi - -# Check for svn and a svn repo. -if rev=`svn info 2>/dev/null | grep '^Last Changed Rev'`; then - rev=`echo $rev | awk '{print $NF}'` - printf -- '-svn%s' "$rev" - - # All done with svn - exit -fi diff --git a/src/Makefile b/src/Makefile index 80e86fe..d1dc7f9 100644 --- a/src/Makefile +++ b/src/Makefile @@ -7,12 +7,9 @@ MAKEFLAGS += --no-print-dir Q := @ endif -BUILDDATE := `date +"%Y%m%d"` - CFLAGS += -Wall -Wextra -Wno-char-subscripts\ - -O2 -std=gnu99 -g3 -DBUILDDATE=\"$(BUILDDATE)\"\ + -O2 -std=gnu99 -g3 -MD \ -I. -Iinclude -Iplatforms/common -I$(PLATFORM_DIR) \ - -DVERSION_SUFFIX=\"`../scripts/setlocalversion`\" -MD SRC = \ adiv5.c \ @@ -49,9 +46,9 @@ include $(PLATFORM_DIR)/Makefile.inc OBJ = $(SRC:.c=.o) -blackmagic: $(OBJ) +blackmagic: include/version.h $(OBJ) @echo " LD $@" - $(Q)$(CC) -o $@ $^ $(LDFLAGS) + $(Q)$(CC) -o $@ $(OBJ) $(LDFLAGS) %.o: %.c @echo " CC $<" @@ -65,7 +62,7 @@ blackmagic: $(OBJ) @echo " OBJCOPY $@" $(Q)$(OBJCOPY) -O ihex $^ $@ -.PHONY: clean host_clean all_platforms +.PHONY: clean host_clean all_platforms FORCE clean: host_clean $(Q)echo " CLEAN" @@ -86,5 +83,9 @@ all_platforms: fi ;\ done +include/version.h: FORCE + $(Q)echo " GIT include/version.h" + $(Q)echo "#define FIRMWARE_VERSION \"`git describe --dirty`\"" > $@ + -include *.d diff --git a/src/command.c b/src/command.c index f271085..64e4ed6 100644 --- a/src/command.c +++ b/src/command.c @@ -29,6 +29,7 @@ #include "target.h" #include "morse.h" #include "adiv5.h" +#include "version.h" #ifdef PLATFORM_HAS_TRACESWO # include "traceswo.h" @@ -106,8 +107,8 @@ int command_process(target *t, char *cmd) bool cmd_version(void) { - gdb_out("Black Magic Probe (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")\n"); - gdb_out("Copyright (C) 2011 Black Sphere Technologies Ltd.\n"); + gdb_out("Black Magic Probe (Firmware " FIRMWARE_VERSION ")\n"); + gdb_out("Copyright (C) 2015 Black Sphere Technologies Ltd.\n"); gdb_out("License GPLv3+: GNU GPL version 3 or later " "\n\n"); diff --git a/src/platforms/f4discovery/Makefile.inc b/src/platforms/f4discovery/Makefile.inc index e2bebfd..e57bb0e 100644 --- a/src/platforms/f4discovery/Makefile.inc +++ b/src/platforms/f4discovery/Makefile.inc @@ -16,7 +16,6 @@ LDFLAGS = -lopencm3_stm32f4 -Wl,--defsym,_stack=0x20006000 \ VPATH += platforms/stm32 SRC += cdcacm.c \ - platform.c \ traceswo.c \ usbuart.c \ serialno.c \ diff --git a/src/platforms/f4discovery/platform.h b/src/platforms/f4discovery/platform.h index 3c5c582..300a3c1 100644 --- a/src/platforms/f4discovery/platform.h +++ b/src/platforms/f4discovery/platform.h @@ -28,12 +28,13 @@ #include "gpio.h" #include "morse.h" #include "timing.h" +#include "version.h" #include #define PLATFORM_HAS_TRACESWO -#define BOARD_IDENT "Black Magic Probe (F4Discovery), (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" -#define BOARD_IDENT_DFU "Black Magic (Upgrade) for F4Discovery, (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" +#define BOARD_IDENT "Black Magic Probe (F4Discovery), (Firmware " FIRMWARE_VERSION ")" +#define BOARD_IDENT_DFU "Black Magic (Upgrade) for F4Discovery, (Firmware " FIRMWARE_VERSION ")" #define DFU_IDENT "Black Magic Firmware Upgrade (F4Discovery" #define DFU_IFACE_STRING "@Internal Flash /0x08000000/1*016Ka,3*016Kg,1*064Kg,7*128Kg" diff --git a/src/platforms/launchpad-icdi/platform.h b/src/platforms/launchpad-icdi/platform.h index eb3ac6e..dc2efcf 100644 --- a/src/platforms/launchpad-icdi/platform.h +++ b/src/platforms/launchpad-icdi/platform.h @@ -24,8 +24,10 @@ #include #include -#define BOARD_IDENT "Black Magic Probe (Launchpad ICDI), (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" -#define BOARD_IDENT_DFU "Black Magic (Upgrade) for Launchpad, (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" +#include "version.h" + +#define BOARD_IDENT "Black Magic Probe (Launchpad ICDI), (Firmware " FIRMWARE_VERSION ")" +#define BOARD_IDENT_DFU "Black Magic (Upgrade) for Launchpad, (Firmware " FIRMWARE_VERSION ")" #define DFU_IDENT "Black Magic Firmware Upgrade (Launchpad)" #define DFU_IFACE_STRING "lolwut" diff --git a/src/platforms/libftdi/platform.c b/src/platforms/libftdi/platform.c index 634090d..0f16263 100644 --- a/src/platforms/libftdi/platform.c +++ b/src/platforms/libftdi/platform.c @@ -19,6 +19,7 @@ */ #include "general.h" #include "gdb_if.h" +#include "version.h" #include @@ -157,6 +158,11 @@ void platform_init(int argc, char **argv) if(cable_desc[index].cbus_ddr) ftdi_init[8]= cable_desc[index].cbus_ddr; + printf("\nBlack Magic Probe (" FIRMWARE_VERSION ")\n"); + printf("Copyright (C) 2015 Black Sphere Technologies Ltd.\n"); + printf("License GPLv3+: GNU GPL version 3 or later " + "\n\n"); + if(ftdic) { ftdi_usb_close(ftdic); ftdi_free(ftdic); diff --git a/src/platforms/native/Makefile.inc b/src/platforms/native/Makefile.inc index 6ec60b1..8365555 100644 --- a/src/platforms/native/Makefile.inc +++ b/src/platforms/native/Makefile.inc @@ -15,7 +15,6 @@ LDFLAGS = $(LDFLAGS_BOOT) -Wl,-Ttext=0x8002000 VPATH += platforms/stm32 SRC += cdcacm.c \ - platform.c \ traceswo.c \ usbuart.c \ serialno.c \ diff --git a/src/platforms/stlink/Makefile.inc b/src/platforms/stlink/Makefile.inc index 40635cf..dd1ab41 100644 --- a/src/platforms/stlink/Makefile.inc +++ b/src/platforms/stlink/Makefile.inc @@ -15,7 +15,6 @@ LDFLAGS = $(LDFLAGS_BOOT) -Wl,-Ttext=0x8002000 VPATH += platforms/stm32 SRC += cdcacm.c \ - platform.c \ usbuart.c \ serialno.c \ timing.c \ diff --git a/src/platforms/stlink/platform.h b/src/platforms/stlink/platform.h index f026db3..c304db2 100644 --- a/src/platforms/stlink/platform.h +++ b/src/platforms/stlink/platform.h @@ -27,6 +27,7 @@ #include "gdb_packet.h" #include "gpio.h" #include "timing.h" +#include "version.h" #include #include @@ -34,9 +35,9 @@ #include -#define BOARD_IDENT "Black Magic Probe (STLINK), (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" -#define BOARD_IDENT_DFU "Black Magic (Upgrade) for STLink/Discovery, (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" -#define BOARD_IDENT_UPD "Black Magic (DFU Upgrade) for STLink/Discovery, (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" +#define BOARD_IDENT "Black Magic Probe (STLINK), (Firmware " FIRMWARE_VERSION ")" +#define BOARD_IDENT_DFU "Black Magic (Upgrade) for STLink/Discovery, (Firmware " FIRMWARE_VERSION ")" +#define BOARD_IDENT_UPD "Black Magic (DFU Upgrade) for STLink/Discovery, (Firmware " FIRMWARE_VERSION ")" #define DFU_IDENT "Black Magic Firmware Upgrade (STLINK)" #define DFU_IFACE_STRING "@Internal Flash /0x08000000/8*001Ka,56*001Kg" #define UPD_IFACE_STRING "@Internal Flash /0x08000000/8*001Kg" diff --git a/src/platforms/swlink/Makefile.inc b/src/platforms/swlink/Makefile.inc index ca793d4..8899471 100644 --- a/src/platforms/swlink/Makefile.inc +++ b/src/platforms/swlink/Makefile.inc @@ -15,7 +15,6 @@ LDFLAGS = $(LDFLAGS_BOOT) -Wl,-Ttext=0x8002000 VPATH += platforms/stm32 SRC += cdcacm.c \ - platform.c \ usbuart.c \ serialno.c \ timing.c \ diff --git a/src/platforms/swlink/platform.h b/src/platforms/swlink/platform.h index 27cc299..ffa35cf 100644 --- a/src/platforms/swlink/platform.h +++ b/src/platforms/swlink/platform.h @@ -27,12 +27,13 @@ #include "gdb_packet.h" #include "gpio.h" #include "timing.h" +#include "version.h" #include -#define BOARD_IDENT "Black Magic Probe (SWLINK), (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" -#define BOARD_IDENT_DFU "Black Magic (Upgrade), STM8S Discovery, (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" -#define BOARD_IDENT_UPD "Black Magic (DFU Upgrade), STM8S Discovery, (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" +#define BOARD_IDENT "Black Magic Probe (SWLINK), (Firmware " FIRMWARE_VERSION ")" +#define BOARD_IDENT_DFU "Black Magic (Upgrade), STM8S Discovery, (Firmware " FIRMWARE_VERSION ")" +#define BOARD_IDENT_UPD "Black Magic (DFU Upgrade), STM8S Discovery, (Firmware " FIRMWARE_VERSION ")" #define DFU_IDENT "Black Magic Firmware Upgrade (SWLINK)" #define DFU_IFACE_STRING "@Internal Flash /0x08000000/8*001Ka,56*001Kg" #define UPD_IFACE_STRING "@Internal Flash /0x08000000/8*001Kg"