From 8cc8272fb3a90938c863872e19063587d1c701e8 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Thu, 12 Oct 2017 16:02:40 +0200 Subject: [PATCH] build: pass gitrev, use it in fatal_error --- Makefile | 7 +++++-- SConscript.unix | 2 +- embed/trezorhal/common.c | 5 +++++ embed/unix/common.c | 5 +++++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 72582108b..95490ebd8 100644 --- a/Makefile +++ b/Makefile @@ -38,6 +38,9 @@ BOARDLOADER_MAXSIZE = 49152 BOOTLOADER_MAXSIZE = 131072 FIRMWARE_MAXSIZE = 786432 +GITREV=$(shell git rev-parse --short HEAD) +CFLAGS += -DGITREV=$(GITREV) + ## help commands: help: ## show this help @@ -87,10 +90,10 @@ build_firmware: res build_cross ## build firmware with frozen modules $(SCONS) CFLAGS="$(CFLAGS)" build/firmware/firmware.bin build_unix: ## build unix port - $(SCONS) build/unix/micropython $(UNIX_PORT_OPTS) + $(SCONS) CFLAGS="$(CFLAGS)" build/unix/micropython $(UNIX_PORT_OPTS) build_unix_noui: ## build unix port without UI support - $(SCONS) build/unix/micropython $(UNIX_PORT_OPTS) TREZOR_NOUI=1 + $(SCONS) CFLAGS="$(CFLAGS)" build/unix/micropython $(UNIX_PORT_OPTS) TREZOR_NOUI=1 build_cross: ## build mpy-cross port $(MAKE) -C vendor/micropython/mpy-cross $(CROSS_PORT_OPTS) diff --git a/SConscript.unix b/SConscript.unix index 6856686fe..8b215430e 100644 --- a/SConscript.unix +++ b/SConscript.unix @@ -221,7 +221,7 @@ SOURCE_EMIT_NATIVE = ['vendor/micropython/py/emitnative.c'] SOURCE_QSTR = SOURCE_MOD + SOURCE_MICROPYTHON + SOURCE_UNIX + SOURCE_EMIT_NATIVE -env = Environment(ENV=os.environ) +env = Environment(ENV=os.environ, CFLAGS=ARGUMENTS.get('CFLAGS', '')) env.Tool('micropython') diff --git a/embed/trezorhal/common.c b/embed/trezorhal/common.c index bb64f05a2..f141fa1d1 100644 --- a/embed/trezorhal/common.c +++ b/embed/trezorhal/common.c @@ -22,6 +22,11 @@ void __attribute__((noreturn)) __fatal_error(const char *expr, const char *msg, if (func) { display_printf("func: %s\n", func); } +#ifdef GITREV +#define XSTR(s) STR(s) +#define STR(s) #s + display_printf("rev : %s\n", XSTR(GITREV)); +#endif for (;;); } diff --git a/embed/unix/common.c b/embed/unix/common.c index 7b1e98131..f0a674ad4 100644 --- a/embed/unix/common.c +++ b/embed/unix/common.c @@ -18,5 +18,10 @@ void __attribute__((noreturn)) __fatal_error(const char *expr, const char *msg, if (func) { printf("func: %s\n", func); } +#ifdef GITREV +#define XSTR(s) STR(s) +#define STR(s) #s + printf("rev : %s\n", XSTR(GITREV)); +#endif exit(1); }