diff mbox

[v2,08/10] external/gard: Add version information

Message ID 1447216804-21501-9-git-send-email-cyril.bur@au1.ibm.com
State Accepted
Headers show

Commit Message

Cyril Bur Nov. 11, 2015, 4:40 a.m. UTC
Method for recording version is identical to pflash. Uses the current
skiboot version and any current repository state.

Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com>
---
 external/gard/Makefile                  | 20 +++++++++++++++-----
 external/gard/gard.c                    |  9 +++++++++
 external/gard/rules.mk                  | 11 ++++++++++-
 external/gard/test/results/02-usage.out |  1 +
 external/gard/test/tests/02-usage       |  2 ++
 5 files changed, 37 insertions(+), 6 deletions(-)
diff mbox

Patch

diff --git a/external/gard/Makefile b/external/gard/Makefile
index c3dc6fb..2f21607 100644
--- a/external/gard/Makefile
+++ b/external/gard/Makefile
@@ -6,7 +6,7 @@  include ../../external/common/rules.mk
 all: $(EXE)
 
 .PHONY: links
-links: libflash ccan common
+links: libflash ccan common make_version.sh
 
 libflash:
 	ln -sf ../../libflash .
@@ -17,17 +17,27 @@  ccan:
 common:
 	ln -sf ../common .
 
-check: all
+make_version.sh:
+	ln -sf ../../make_version.sh
+
+#Rebuild version.o so that the the version always matches
+#what the test suite will get from ./make_version.sh
+check: version.o all
 	@ln -sf ../../test/test.sh test/test.sh
 	@test/test-gard
 
 $(OBJS): | links arch_links
 
+.PHONY: VERSION-always
+.version: VERSION-always
+	@echo $(GARD_VERSION) > $@.tmp
+	@cmp -s $@ $@.tmp || cp $@.tmp $@
+	@rm -f $@.tmp
+
 clean: arch_clean
-	rm -f $(OBJS) $(EXE) *.o *.d
+	rm -f $(OBJS) $(EXE) *.o *.d .version .version.tmp
 
 distclean: clean
 	rm -f *.c~ *.h~ *.sh~ Makefile~ config.mk~ libflash/*.c~ libflash/*.h~
-	rm -f libflash ccan .version .version.tmp
-	rm -f common io.h make_version.sh
+	rm -f libflash ccan common io.h make_version.sh
 
diff --git a/external/gard/gard.c b/external/gard/gard.c
index b656f40..e41047f 100644
--- a/external/gard/gard.c
+++ b/external/gard/gard.c
@@ -44,6 +44,9 @@ 
 #define SYSFS_MTD_PATH "/sys/class/mtd/"
 #define FLASH_GARD_PART "GUARD"
 
+/* Full gard version number (possibly includes gitid). */
+extern const char version[];
+
 struct gard_ctx {
 	bool ecc;
 	uint32_t f_size;
@@ -637,10 +640,16 @@  struct {
 	{ "clear", "Clear GARD records", do_clear },
 };
 
+static void print_version(void)
+{
+	printf("Open-Power GARD tool %s\n", version);
+}
+
 static void usage(const char *progname)
 {
 	unsigned int i;
 
+	print_version();
 	fprintf(stderr, "Usage: %s [-a -e -f <file> -p] <command> [<args>]\n\n",
 			progname);
 	fprintf(stderr, "-e --ecc\n\tForce reading/writing with ECC bytes.\n\n");
diff --git a/external/gard/rules.mk b/external/gard/rules.mk
index bef8fbb..a78a401 100644
--- a/external/gard/rules.mk
+++ b/external/gard/rules.mk
@@ -1,7 +1,7 @@ 
 .DEFAULT_GOAL := all
 
 override CFLAGS += -O2 -Wall -Werror -I.
-OBJS      = gard.o
+OBJS      = version.o gard.o
 OBJS     += libflash/file.o libflash/libflash.o libflash/libffs.o libflash/ecc.o libflash/blocklevel.o
 OBJS     += common/arch_flash.o
 EXE       = gard
@@ -13,6 +13,15 @@  sbindir = $(prefix)/sbin
 datadir = $(prefix)/share
 mandir = $(datadir)/man
 
+GARD_VERSION ?= $(shell ./make_version.sh $(EXE))
+
+version.c: make_version.sh .version
+	@(if [ "a$(GARD_VERSION)" = "a" ]; then \
+	echo "#error You need to set GARD_VERSION environment variable" > $@ ;\
+	else \
+	echo "const char version[] = \"$(GARD_VERSION)\";" ;\
+	fi) > $@
+
 %.o : %.c
 	$(CC) $(CFLAGS) -c $< -o $@
 
diff --git a/external/gard/test/results/02-usage.out b/external/gard/test/results/02-usage.out
index e69de29..c862167 100644
--- a/external/gard/test/results/02-usage.out
+++ b/external/gard/test/results/02-usage.out
@@ -0,0 +1 @@ 
+Open-Power GARD tool VERSION
diff --git a/external/gard/test/tests/02-usage b/external/gard/test/tests/02-usage
index 768f5d0..45e5e02 100644
--- a/external/gard/test/tests/02-usage
+++ b/external/gard/test/tests/02-usage
@@ -5,6 +5,8 @@  if [ "$?" -ne 1 ] ; then
 	fail_test
 fi
 
+strip_version_from_result "gard"
+
 diff_with_result
 
 pass_test