diff --git a/Makefile b/Makefile index 48c3502..844d6e4 100644 --- a/Makefile +++ b/Makefile @@ -5,11 +5,17 @@ $(info $(shell cd src/board && echo */*)) $(error BOARD not set) endif +# Calculate version +DATE=$(shell git show --format="%cd" --date="format:%Y-%m-%d" --no-patch) +REV=$(shell git describe --always --dirty) +VERSION=$(DATE)_$(REV) + # Set build directory -BUILD=build/$(BOARD) +BUILD=build/$(BOARD)/$(VERSION) # Default target - build the board's EC firmware all: $(BUILD)/ec.rom + $(info Built '$(VERSION)' for '$(BOARD)') # Target to remove build artifacts clean: @@ -19,7 +25,7 @@ clean: COMMON_DIR=src/common SRC=$(wildcard $(COMMON_DIR)/*.c) INCLUDE=$(wildcard $(COMMON_DIR)/include/common/*.h) $(COMMON_DIR)/common.mk -CFLAGS=-I$(COMMON_DIR)/include +CFLAGS=-I$(COMMON_DIR)/include -D__VERSION__=$(VERSION) include $(COMMON_DIR)/common.mk # Include the board's source diff --git a/src/board/system76/darp5/main.c b/src/board/system76/darp5/main.c index 3b3a8df..8d4643e 100644 --- a/src/board/system76/darp5/main.c +++ b/src/board/system76/darp5/main.c @@ -19,7 +19,7 @@ #include #include #include - +#include void external_0(void) __interrupt(0) {} // timer_0 is in time.c @@ -91,7 +91,7 @@ void main(void) { gpio_set(&SMI_N, true); gpio_set(&SWI_N, true); - INFO("Hello from System76 EC for %s!\n", xstr(__BOARD__)); + INFO("System76 EC board '%s', version '%s'\n", board(), version()); for(main_cycle = 0; ; main_cycle++) { // Handle power states diff --git a/src/board/system76/galp3-c/main.c b/src/board/system76/galp3-c/main.c index 81418d6..3809667 100644 --- a/src/board/system76/galp3-c/main.c +++ b/src/board/system76/galp3-c/main.c @@ -20,7 +20,7 @@ #include #include #include - +#include void external_0(void) __interrupt(0) {} // timer_0 is in time.c @@ -93,7 +93,7 @@ void main(void) { gpio_set(&SMI_N, true); gpio_set(&SWI_N, true); - INFO("Hello from System76 EC for %s!\n", xstr(__BOARD__)); + INFO("System76 EC board '%s', version '%s'\n", board(), version()); for(main_cycle = 0; ; main_cycle++) { // Handle power states diff --git a/src/board/system76/lemp9/main.c b/src/board/system76/lemp9/main.c index 12670e8..0c93032 100644 --- a/src/board/system76/lemp9/main.c +++ b/src/board/system76/lemp9/main.c @@ -21,7 +21,7 @@ #include #include #include - +#include void external_0(void) __interrupt(0) {} // timer_0 is in time.c @@ -95,7 +95,7 @@ void main(void) { gpio_set(&SMI_N, true); gpio_set(&SWI_N, true); - INFO("Hello from System76 EC for %s!\n", xstr(__BOARD__)); + INFO("System76 EC board '%s', version '%s'\n", board(), version()); for(main_cycle = 0; ; main_cycle++) { // Handle power states diff --git a/src/common/include/common/version.h b/src/common/include/common/version.h new file mode 100644 index 0000000..ccf6c8a --- /dev/null +++ b/src/common/include/common/version.h @@ -0,0 +1,7 @@ +#ifndef _COMMON_VERSION_H +#define _COMMON_VERSION_H + +const char * board(); +const char * version(); + +#endif // _COMMON_VERSION_H diff --git a/src/common/version.c b/src/common/version.c new file mode 100644 index 0000000..04fb0f4 --- /dev/null +++ b/src/common/version.c @@ -0,0 +1,17 @@ +#include + +static const char __code BOARD[] = + "76EC_BOARD=" + xstr(__BOARD__); + +static const char __code VERSION[] = + "76EC_VERSION=" + xstr(__VERSION__); + +const char * board() { + return &BOARD[11]; +} + +const char * version() { + return &VERSION[13]; +}