[PATCH] Add version information to bootloader and tool

18 views
Skip to first unread message

Jan Kiszka

unread,
Oct 2, 2017, 1:02:00 PM10/2/17
to efibootguard-dev
From: Jan Kiszka <jan.k...@siemens.com>

Generate a version string, either using the VERSION file for git-less
build or information obtained from the git tree. VERSION needs to be
updated on each release.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---

While testing a patch today and starring at the not-yet-working output,
the usual question came up: "What am I running?" This should provide a
better answer in the future. Machinery taken from Jailhouse.

Makefile.am | 30 ++++++++++++++++++++++++++++++
VERSION | 1 +
gen_version_h | 28 ++++++++++++++++++++++++++++
main.c | 3 ++-
tools/bg_setenv.c | 8 ++++++++
5 files changed, 69 insertions(+), 1 deletion(-)
create mode 100644 VERSION
create mode 100755 gen_version_h

diff --git a/Makefile.am b/Makefile.am
index c7dcb10..bb7e7f9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -36,6 +36,19 @@ ARFLAGS = cr
EXTRA_DIST = autogen.sh README LICENSE
CLEANFILES =

+define filechk
+ $(AM_V_at)set -e; \
+ echo ' CHK $@'; \
+ mkdir -p $(dir $@); \
+ $(filechk_$(1)) < $< > $@.tmp; \
+ if [ -r $@ ] && cmp -s $@ $@.tmp; then \
+ rm -f $@.tmp; \
+ else \
+ echo ' UPD $@'; \
+ mv -f $@.tmp $@; \
+ fi
+endef
+
#
# Static libraries
#
@@ -152,6 +165,17 @@ efibootguard_DATA = $(efi_loadername)
CLEANFILES += $(efi_objects) $(efi_solib) $(efi_loadername)
EXTRA_DIST += $(efi_sources)

+define filechk_version
+ $(top_srcdir)/gen_version_h $(top_srcdir)/
+endef
+
+GEN_VERSION_H := $(top_builddir)/version.h
+
+$(GEN_VERSION_H): $(top_srcdir)/Makefile.in FORCE
+ $(call filechk,version)
+
+CLEANFILES += $(GEN_VERSION_H)
+
$(top_builddir)/%.o: $(top_srcdir)/%.c
@$(MKDIR_P) $(shell dirname $@)/
$(AM_V_CC)$(GNUEFI_CC) $(efi_cppflags) $(efi_cflags) -c $< -o $@
@@ -168,6 +192,8 @@ $(top_builddir)/drivers/watchdog/%.o: $(top_srcdir)/drivers/watchdog/%.S
@$(MKDIR_P) $(shell dirname $@)/
$(AM_V_CC)$(GNUEFI_CC) $(efi_cppflags) $(efi_cflags) -c $< -o $@

+$(top_builddir)/main.o: $(GEN_VERSION_H)
+
$(efi_solib): $(efi_objects)
$(AM_V_CCLD)$(LD) $(efi_ldflags) $(efi_objects) \
-o $@ -lefi -lgnuefi $(shell $(CC) $(CFLAGS) -print-libgcc-file-name); \
@@ -189,3 +215,7 @@ CLEANFILES += bg_printenv

# Tests depend on libraries being built - start with "."
SUBDIRS = . tools/tests
+
+FORCE:
+
+.PHONY: FORCE
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..085135e
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+v0.1
diff --git a/gen_version_h b/gen_version_h
new file mode 100755
index 0000000..f917fe0
--- /dev/null
+++ b/gen_version_h
@@ -0,0 +1,28 @@
+#!/bin/sh
+#
+# EFI Boot Guard
+#
+# Copyright (c) Siemens AG, 2017
+#
+# Authors:
+# Jan Kiszka <jan.k...@siemens.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2. See
+# the COPYING file in the top-level directory.
+#
+
+echo "/* Auto-generated - leave alone and don't commit! */"
+echo ""
+
+cd "$1" > /dev/null
+
+if ! git rev-parse 2>/dev/null; then
+ version="`cat VERSION`"
+else
+ describe="`git describe --long --dirty --match "v[0-9].[0-9]*"`"
+ version="`echo $describe | sed -e 's/\([^-]*\)-\(.*\)/\1 (\2)/'`"
+fi
+
+cd - > /dev/null
+
+echo "#define EFIBOOTGUARD_VERSION \"$version\""
diff --git a/main.c b/main.c
index e796450..5bf38df 100644
--- a/main.c
+++ b/main.c
@@ -18,6 +18,7 @@
#include <pci/header.h>
#include <bootguard.h>
#include <configuration.h>
+#include "version.h"

extern const unsigned long init_array_start[];
extern const unsigned long init_array_end[];
@@ -104,7 +105,7 @@ EFI_STATUS efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table)
this_image = image_handle;
InitializeLib(this_image, system_table);

- Print(L"\nEFI Boot Guard\n");
+ Print(L"\nEFI Boot Guard %s\n", L""EFIBOOTGUARD_VERSION);

status =
uefi_call_wrapper(BS->OpenProtocol, 6, this_image,
diff --git a/tools/bg_setenv.c b/tools/bg_setenv.c
index 6f7f8f9..4c25d9c 100644
--- a/tools/bg_setenv.c
+++ b/tools/bg_setenv.c
@@ -15,6 +15,9 @@
#include "env_api.h"
#include "ebgenv.h"
#include "uservars.h"
+#include "version.h"
+
+#define VERSION_KEY 1000

static char doc[] =
"bg_setenv/bg_printenv - Environment tool for the EFI Boot Guard";
@@ -38,10 +41,12 @@ static struct argp_option options_setenv[] = {
{"uservar", 'x', "KEY=VAL", 0, "Set user-defined string variable. For "
"setting multiple variables, use this "
"option multiple times."},
+ {"version", VERSION_KEY, 0, 0, "Print version"},
{0}};

static struct argp_option options_printenv[] = {
{"verbose", 'v', 0, 0, "Be verbose"},
+ {"version", VERSION_KEY, 0, 0, "Print version"},
{0}};

struct arguments {
@@ -311,6 +316,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
/* Set user-defined variable(s) */
set_uservars(arg);
break;
+ case VERSION_KEY:
+ printf("EFI Boot Guard %s\n", EFIBOOTGUARD_VERSION);
+ exit(0);
case ARGP_KEY_ARG:
/* too many arguments - program terminates with call to
* argp_usage with non-zero return code */
--
2.12.3

Claudius Heine

unread,
Oct 4, 2017, 4:13:38 AM10/4/17
to [ext] Jan Kiszka, efibootguard-dev
Hi,
For in-tree build it would make sense to add 'version.h' to the
gitignore list.
Why are we needing a special define for the version key, when all the
other parameters don't need this.
I think we should be consistent here. If we change the style here, then
a separate patch would be useful.

>
> static char doc[] =
> "bg_setenv/bg_printenv - Environment tool for the EFI Boot Guard";
> @@ -38,10 +41,12 @@ static struct argp_option options_setenv[] = {
> {"uservar", 'x', "KEY=VAL", 0, "Set user-defined string variable. For "
> "setting multiple variables, use this "
> "option multiple times."},
> + {"version", VERSION_KEY, 0, 0, "Print version"},
> {0}};
>
> static struct argp_option options_printenv[] = {
> {"verbose", 'v', 0, 0, "Be verbose"},
> + {"version", VERSION_KEY, 0, 0, "Print version"},
> {0}};
>
> struct arguments {
> @@ -311,6 +316,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
> /* Set user-defined variable(s) */
> set_uservars(arg);
> break;
> + case VERSION_KEY:
> + printf("EFI Boot Guard %s\n", EFIBOOTGUARD_VERSION);
> + exit(0);
> case ARGP_KEY_ARG:
> /* too many arguments - program terminates with call to
> * argp_usage with non-zero return code */
>

Claudius

--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-54 Fax: (+49)-8142-66989-80 Email: c...@denx.de

Jan Kiszka

unread,
Oct 4, 2017, 4:28:10 AM10/4/17
to Claudius Heine, efibootguard-dev
True, will send v2.
Because all the other switches have a character as key that can also be
used as an abbreviation of the long parameter name. --version has no
such thing, so the key has to be a "non-printable" value.
Thanks,
Jan

Claudius Heine

unread,
Oct 4, 2017, 4:36:17 AM10/4/17
to Jan Kiszka, efibootguard-dev
Hi,
Ok and you wanted to avoid magic numbers in the code. Maybe change it to
'V'.

Claudius

Jan Kiszka

unread,
Oct 4, 2017, 4:43:13 AM10/4/17
to Claudius Heine, efibootguard-dev
Is "-V" a common abbreviation for version? I don't get your suggestion yet.

Jan

Claudius Heine

unread,
Oct 4, 2017, 4:45:36 AM10/4/17
to Jan Kiszka, efibootguard-dev
Yes:

$ ping -v
Usage: ping [-aAbBdDfhLnOqrRUvV64] [-c count] [-i interval] [-I interface]
[-m mark] [-M pmtudisc_option] [-l preload] [-p pattern]
[-Q tos]
[-s packetsize] [-S sndbuf] [-t ttl] [-T timestamp_option]
[-w deadline] [-W timeout] [hop1 ...] destination
Usage: ping -6 [-aAbBdDfhLnOqrRUvV] [-c count] [-i interval] [-I interface]
[-l preload] [-m mark] [-M pmtudisc_option]
[-N nodeinfo_option] [-p pattern] [-Q tclass] [-s packetsize]
[-S sndbuf] [-t ttl] [-T timestamp_option] [-w deadline]
$ ping -V
ping utility, iputils-s20161105

Jan Kiszka

unread,
Oct 4, 2017, 8:15:24 AM10/4/17
to efibootguard-dev
From: Jan Kiszka <jan.k...@siemens.com>

Generate a version string, either using the VERSION file for git-less
build or information obtained from the git tree. VERSION needs to be
updated on each release.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---

Changes in v2:
- add version.h to .gitignore
- use 'V' as key and abbreviation of --version

.gitignore | 1 +
Makefile.am | 30 ++++++++++++++++++++++++++++++
VERSION | 1 +
gen_version_h | 28 ++++++++++++++++++++++++++++
main.c | 3 ++-
tools/bg_setenv.c | 6 ++++++
6 files changed, 68 insertions(+), 1 deletion(-)
create mode 100644 VERSION
create mode 100755 gen_version_h

diff --git a/.gitignore b/.gitignore
index cad1f4a..6433560 100644
--- a/.gitignore
+++ b/.gitignore
@@ -78,3 +78,4 @@ Makefile.in
/Makefile
/tools/tests/Makefile
.deps/
+version.h
index 6f7f8f9..424b442 100644
--- a/tools/bg_setenv.c
+++ b/tools/bg_setenv.c
@@ -15,6 +15,7 @@
#include "env_api.h"
#include "ebgenv.h"
#include "uservars.h"
+#include "version.h"

static char doc[] =
"bg_setenv/bg_printenv - Environment tool for the EFI Boot Guard";
@@ -38,10 +39,12 @@ static struct argp_option options_setenv[] = {
{"uservar", 'x', "KEY=VAL", 0, "Set user-defined string variable. For "
"setting multiple variables, use this "
"option multiple times."},
+ {"version", 'V', 0, 0, "Print version"},
{0}};

static struct argp_option options_printenv[] = {
{"verbose", 'v', 0, 0, "Be verbose"},
+ {"version", 'V', 0, 0, "Print version"},
{0}};

struct arguments {
@@ -311,6 +314,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
/* Set user-defined variable(s) */
set_uservars(arg);
break;
+ case 'V':
+ printf("EFI Boot Guard %s\n", EFIBOOTGUARD_VERSION);
+ exit(0);
case ARGP_KEY_ARG:
/* too many arguments - program terminates with call to
* argp_usage with non-zero return code */
--
2.12.3

Claudius Heine

unread,
Oct 4, 2017, 8:46:50 AM10/4/17
to [ext] Jan Kiszka, efibootguard-dev
Hi Jan,

On 10/04/2017 02:15 PM, [ext] Jan Kiszka wrote:
> From: Jan Kiszka <jan.k...@siemens.com>
>
> Generate a version string, either using the VERSION file for git-less
> build or information obtained from the git tree. VERSION needs to be
> updated on each release.
>
> Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
> ---
>
> Changes in v2:
> - add version.h to .gitignore
> - use 'V' as key and abbreviation of --version

Your patch currently does not build.

https://travis-ci.org/siemens/efibootguard/jobs/283167381

It seems that version.h is not generated or can not be found.

Claudius

Jan Kiszka

unread,
Oct 4, 2017, 8:51:29 AM10/4/17
to Claudius Heine, efibootguard-dev
On 2017-10-04 14:46, Claudius Heine wrote:
> Hi Jan,
>
> On 10/04/2017 02:15 PM, [ext] Jan Kiszka wrote:
>> From: Jan Kiszka <jan.k...@siemens.com>
>>
>> Generate a version string, either using the VERSION file for git-less
>> build or information obtained from the git tree. VERSION needs to be
>> updated on each release.
>>
>> Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
>> ---
>>
>> Changes in v2:
>>   - add version.h to .gitignore
>>   - use 'V' as key and abbreviation of --version
>
> Your patch currently does not build.
>
> https://travis-ci.org/siemens/efibootguard/jobs/283167381
>
> It seems that version.h is not generated or can not be found.

Yes, unfortunately missed that as the build was broken before
(warning-related), and I didn't try a clean build locally. Fix for the
missing dep on the way.

Jan

Jan Kiszka

unread,
Oct 4, 2017, 9:07:09 AM10/4/17
to efibootguard-dev
From: Jan Kiszka <jan.k...@siemens.com>

Generate a version string, either using the VERSION file for git-less
build or information obtained from the git tree. VERSION needs to be
updated on each release.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---

Changes in v3:
- fixed dependency of bg_setenv build on version.h
- reordered version.h section in Makefile.am (no functional change)

.gitignore | 1 +
Makefile.am | 35 +++++++++++++++++++++++++++++++++++
VERSION | 1 +
gen_version_h | 28 ++++++++++++++++++++++++++++
main.c | 3 ++-
tools/bg_setenv.c | 6 ++++++
6 files changed, 73 insertions(+), 1 deletion(-)
create mode 100644 VERSION
create mode 100755 gen_version_h

diff --git a/.gitignore b/.gitignore
index cad1f4a..6433560 100644
--- a/.gitignore
+++ b/.gitignore
@@ -78,3 +78,4 @@ Makefile.in
/Makefile
/tools/tests/Makefile
.deps/
+version.h
diff --git a/Makefile.am b/Makefile.am
index c7dcb10..b11366d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -36,6 +36,33 @@ ARFLAGS = cr
EXTRA_DIST = autogen.sh README LICENSE
CLEANFILES =

+define filechk
+ $(AM_V_at)set -e; \
+ echo ' CHK $@'; \
+ mkdir -p $(dir $@); \
+ $(filechk_$(1)) < $< > $@.tmp; \
+ if [ -r $@ ] && cmp -s $@ $@.tmp; then \
+ rm -f $@.tmp; \
+ else \
+ echo ' UPD $@'; \
+ mv -f $@.tmp $@; \
+ fi
+endef
+
+#
+# Version header
+#
+define filechk_version
+ $(top_srcdir)/gen_version_h $(top_srcdir)/
+endef
+
+GEN_VERSION_H := $(top_builddir)/version.h
+
+$(GEN_VERSION_H): $(top_srcdir)/Makefile.in FORCE
+ $(call filechk,version)
+
+CLEANFILES += $(GEN_VERSION_H)
+
#
# Static libraries
#
@@ -168,6 +195,8 @@ $(top_builddir)/drivers/watchdog/%.o: $(top_srcdir)/drivers/watchdog/%.S
@$(MKDIR_P) $(shell dirname $@)/
$(AM_V_CC)$(GNUEFI_CC) $(efi_cppflags) $(efi_cflags) -c $< -o $@

+$(top_builddir)/main.o: $(GEN_VERSION_H)
+
$(efi_solib): $(efi_objects)
$(AM_V_CCLD)$(LD) $(efi_ldflags) $(efi_objects) \
-o $@ -lefi -lgnuefi $(shell $(CC) $(CFLAGS) -print-libgcc-file-name); \
@@ -178,6 +207,8 @@ $(efi_loadername): $(efi_solib)
-j .dynsym -j .rel -j .rela -j .reloc -j .init_array \
--target=efi-app-$(ARCH) $< $@

+$(top_builddir)/tools/bg_setenv-bg_setenv.o: $(GEN_VERSION_H)
+
bg_printenvdir = $(top_srcdir)

bg_printenv: $(bg_setenv)
@@ -189,3 +220,7 @@ CLEANFILES += bg_printenv
2.12.3
Reply all
Reply to author
Forward
0 new messages