Skip to contentSkip to conversation

Makefile: Add build time and compiler info string

PATCH New Anup Patel 6 participants 8 messages Oct 20, 2021 – Oct 21, 2021 Kbuild

lore
Share & tools
lore

Anup Patel

author
#0 lore raw

PATCH v6 1/1 Makefile: Add build time and compiler info string

From: Wei Fu <[email protected]>

When we are doing opensbi development, we want to know the build time and compiler info for debug purpose.

To enable this message, please add "BUILD_INFO=y", like:

```
make BUILD_INFO=y
```

NOTE: Using BUILD_INFO=y without specifying SOURCE_DATE_EPOCH will violate "reproducible builds". So it's ONLY for development and debug purpose, and should NOT be used in a product which follows "reproducible builds".

---
Changes since v5:
- BUILD_DATE_EPOCH is non-standard name so rename it back to SOURCE_DATE_EPOCH
- Updated README.md and commit description to clearly state when BUILD_INFO=y violates reprodcible builds
Changes since v4:
- Updated build date format to +%Y-%m-%d %H:%M:%S %z
- Rename SOURCE_DATE_EPOCH to BUILD_DATE_EPOCH

---
 Makefile           | 31 +++++++++++++++++++++++++++++++
 README.md          | 24 ++++++++++++++++++++++++
 lib/sbi/sbi_init.c |  8 ++++++++
 3 files changed, 63 insertions(+)
Makefile +31 -0
index 16d9dca..8623c1c 100644
@@ -150,6 +150,25 @@ endif
 # Check whether the linker supports creating PIEs
 OPENSBI_LD_PIE := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) $(USE_LD_FLAG) -fPIE -nostdlib -Wl,-pie -x c /dev/null -o /dev/null >/dev/null 2>&1 && echo y || echo n)
 
+# Build Info:
+# OPENSBI_BUILD_TIME_STAMP -- the compilation time stamp
+# OPENSBI_BUILD_COMPILER_VERSION -- the compiler version info
+BUILD_INFO ?= n
+ifeq ($(BUILD_INFO),y)
+OPENSBI_BUILD_DATE_FMT = +%Y-%m-%d %H:%M:%S %z
+ifdef SOURCE_DATE_EPOCH
+	OPENSBI_BUILD_TIME_STAMP ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" \
+		"$(OPENSBI_BUILD_DATE_FMT)" 2>/dev/null || \
+		date -u -r "$(SOURCE_DATE_EPOCH)" \
+		"$(OPENSBI_BUILD_DATE_FMT)" 2>/dev/null || \
+		date -u "$(OPENSBI_BUILD_DATE_FMT)")
+else
+	OPENSBI_BUILD_TIME_STAMP ?= $(shell date "$(OPENSBI_BUILD_DATE_FMT)")
+endif
+OPENSBI_BUILD_COMPILER_VERSION=$(shell $(CC) -v 2>&1 | grep ' version ' | \
+	sed 's/[[:space:]]*$$//')
+endif
+
 # Setup list of objects.mk files
 ifdef PLATFORM
 platform-object-mks=$(shell if [ -d $(platform_src_dir)/ ]; then find $(platform_src_dir) -iname "objects.mk" | sort -r; fi)
@@ -247,6 +266,10 @@ GENFLAGS	+=	-I$(include_dir)
 ifneq ($(OPENSBI_VERSION_GIT),)
 GENFLAGS	+=	-DOPENSBI_VERSION_GIT="\"$(OPENSBI_VERSION_GIT)\""
 endif
+ifeq ($(BUILD_INFO),y)
+GENFLAGS	+=	-DOPENSBI_BUILD_TIME_STAMP="\"$(OPENSBI_BUILD_TIME_STAMP)\""
+GENFLAGS	+=	-DOPENSBI_BUILD_COMPILER_VERSION="\"$(OPENSBI_BUILD_COMPILER_VERSION)\""
+endif
 GENFLAGS	+=	$(libsbiutils-genflags-y)
 GENFLAGS	+=	$(platform-genflags-y)
 GENFLAGS	+=	$(firmware-genflags-y)
@@ -398,6 +421,11 @@ $(build_dir)/%.dep: $(src_dir)/%.c
 $(build_dir)/%.o: $(src_dir)/%.c
 	$(call compile_cc,$@,$<)
 
+ifeq ($(BUILD_INFO),y)
+$(build_dir)/lib/sbi/sbi_init.o: $(libsbi_dir)/sbi_init.c FORCE
+	$(call compile_cc,$@,$<)
+endif
+
 $(build_dir)/%.dep: $(src_dir)/%.S
 	$(call compile_as_dep,$@,$<)
 
@@ -551,3 +579,6 @@ ifeq ($(install_root_dir),$(install_root_dir_default)/usr)
 	$(if $(V), @echo " RM        $(install_root_dir_default)")
 	$(CMD_PREFIX)rm -rf $(install_root_dir_default)
 endif
+
+.PHONY: FORCE
+FORCE:
README.md +24 -0
index 9fdf097..54fabe4 100644
@@ -254,6 +254,29 @@ to produce broken binaries with missing relocations; it is therefore currently
 recommended that this combination be avoided or *FW_PIC=n* be used to disable
 building OpenSBI as a position-independent binary.
 
+Building with timestamp and compiler info
+-----------------------------------------
+
+When doing development, we may want to know the build time and compiler info
+for debug purpose. OpenSBI can also be built with timestamp and compiler info.
+To build with those info and print it out@boot time, we can just simply add
+`BUILD_INFO=y`, like:
+```
+make BUILD_INFO=y
+```
+
+But if you have used `BUILD_INFO=y`, and want to switch back to `BUILD_INFO=n`,
+you must do
+```
+make clean
+```
+before the next build.
+
+NOTE: Using `BUILD_INFO=y` without specifying SOURCE_DATE_EPOCH will violate
+[reproducible builds]. This definition is ONLY for development and debug
+purpose, and should NOT be used in a product which follows "reproducible
+builds".
+
 Contributing to OpenSBI
 -----------------------
 
@@ -336,3 +359,4 @@ make I=<install_directory> install_docs
 [Doxygen manual]: http://www.doxygen.nl/manual/index.html
 [Kendryte standalone SDK]: https://github.com/kendryte/kendryte-standalone-sdk
 [third party notices]: ThirdPartyNotices.md
+[reproducible builds]: https://reproducible-builds.org
lib/sbi/sbi_init.c +8 -0
index 843659e..b1c7cf0 100644
@@ -48,6 +48,14 @@ static void sbi_boot_print_banner(struct sbi_scratch *scratch)
 		   OPENSBI_VERSION_MINOR);
 #endif
 
+#ifdef OPENSBI_BUILD_TIME_STAMP
+	sbi_printf("Build time: %s\n", OPENSBI_BUILD_TIME_STAMP);
+#endif
+
+#ifdef OPENSBI_BUILD_COMPILER_VERSION
+	sbi_printf("Build compiler: %s\n", OPENSBI_BUILD_COMPILER_VERSION);
+#endif
+
 	sbi_printf(BANNER);
 }
 
Signature · 1 line
2.25.1
#1 lore raw

PATCH v6 1/1 Makefile: Add build time and compiler info string

Quoted 26 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Anup" == Anup Patel <[email protected]> writes:

From: Wei Fu <[email protected]>
When we are doing opensbi development, we want to know the build time and compiler info for debug purpose.

To enable this message, please add "BUILD_INFO=y", like:

```
make BUILD_INFO=y
```

NOTE: Using BUILD_INFO=y without specifying SOURCE_DATE_EPOCH will violate "reproducible builds". So it's ONLY for development and debug purpose, and should NOT be used in a product which follows "reproducible builds".

---
Changes since v5:
- BUILD_DATE_EPOCH is non-standard name so rename it back to SOURCE_DATE_EPOCH
- Updated README.md and commit description to clearly state when BUILD_INFO=y violates reprodcible builds

..

Makefile endif · line 164

Quoted 12 lines
Makefile +12 -0
+# Build Info:
+# OPENSBI_BUILD_TIME_STAMP -- the compilation time stamp
+# OPENSBI_BUILD_COMPILER_VERSION -- the compiler version info
+BUILD_INFO ?= n
+ifeq ($(BUILD_INFO),y)
+OPENSBI_BUILD_DATE_FMT = +%Y-%m-%d %H:%M:%S %z
+ifdef SOURCE_DATE_EPOCH
+	OPENSBI_BUILD_TIME_STAMP ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" \
+		"$(OPENSBI_BUILD_DATE_FMT)" 2>/dev/null || \
+		date -u -r "$(SOURCE_DATE_EPOCH)" \
+		"$(OPENSBI_BUILD_DATE_FMT)" 2>/dev/null || \
+		date -u "$(OPENSBI_BUILD_DATE_FMT)")

What is this date -r fallback about? According to the spec, SOURCE_DATE_EPOCH is always a unix timestamp, never a filename:

https://reproducible-builds.org/specs/source-date-epoch/

With that dropped we could get rid of some of the repeated code, E.G.:

OPENSBI_BUILD_TIME_STAMP ?= \
$(shell date $(if $(SOURCE_DATE_EPOCH),-u -d "@$(SOURCE_DATE_EPOCH)") "$(OPENSBI_BUILD_DATE_FMT)")

Signature · 1 line
Bye, Peter Korsgaard
#2 lore raw

PATCH v6 1/1 Makefile: Add build time and compiler info string

Quoted 30 lines · Peter Korsgaard
Quoted 27 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

"Anup" == Anup Patel <[email protected]> writes:

From: Wei Fu <[email protected]>
When we are doing opensbi development, we want to know the build time and compiler info for debug purpose.

To enable this message, please add "BUILD_INFO=y", like:

```
make BUILD_INFO=y
```

NOTE: Using BUILD_INFO=y without specifying SOURCE_DATE_EPOCH will violate "reproducible builds". So it's ONLY for development and debug purpose, and should NOT be used in a product which follows "reproducible builds".

---
Changes since v5:
- BUILD_DATE_EPOCH is non-standard name so rename it back to SOURCE_DATE_EPOCH
- Updated README.md and commit description to clearly state when BUILD_INFO=y violates reprodcible builds

..

Quoted 15 lines

Makefile endif · line 164

Quoted 12 lines
Makefile +12 -0
+# Build Info:
+# OPENSBI_BUILD_TIME_STAMP -- the compilation time stamp
+# OPENSBI_BUILD_COMPILER_VERSION -- the compiler version info
+BUILD_INFO ?= n
+ifeq ($(BUILD_INFO),y)
+OPENSBI_BUILD_DATE_FMT = +%Y-%m-%d %H:%M:%S %z
+ifdef SOURCE_DATE_EPOCH
+	OPENSBI_BUILD_TIME_STAMP ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" \
+		"$(OPENSBI_BUILD_DATE_FMT)" 2>/dev/null || \
+		date -u -r "$(SOURCE_DATE_EPOCH)" \
+		"$(OPENSBI_BUILD_DATE_FMT)" 2>/dev/null || \
+		date -u "$(OPENSBI_BUILD_DATE_FMT)")

What is this date -r fallback about? According to the spec, SOURCE_DATE_EPOCH is always a unix timestamp, never a filename:

GNU date and BSD date have a different but similar interface.

This is the sequence recommended by the Reproducible Builds project[1].

Jess

[1] https://reproducible-builds.org/docs/source-date-epoch/#makefile

#3 lore raw

PATCH v6 1/1 Makefile: Add build time and compiler info string

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Jessica" == Jessica Clarke <[email protected]> writes:

Hi,

Quoted 10 lines
Quoted 2 lines

What is this date -r fallback about? According to the spec, SOURCE_DATE_EPOCH is always a unix timestamp, never a filename:

GNU date and BSD date have a different but similar interface.

This is the sequence recommended by the Reproducible Builds project[1].

Jess

[1] https://reproducible-builds.org/docs/source-date-epoch/#makefile

Ahh, good to know - Thanks.

Signature · 1 line
Bye, Peter Korsgaard
Applied
#4 lore raw

PATCH v6 1/1 Makefile: Add build time and compiler info string

In reply to Anup Patel
Quoted 12 lines · Anup Patel

From: Wei Fu <[email protected]>

When we are doing opensbi development, we want to know the build time and compiler info for debug purpose.

To enable this message, please add "BUILD_INFO=y", like:

```
make BUILD_INFO=y
```
Quoted 8 lines

NOTE: Using BUILD_INFO=y without specifying SOURCE_DATE_EPOCH will violate "reproducible builds". So it's ONLY for development and debug purpose, and should NOT be used in a product which follows "reproducible builds".

Applied this patch to the riscv/opensbi repo

Regards,
Anup

Quoted 136 lines

---
Changes since v5:
- BUILD_DATE_EPOCH is non-standard name so rename it back to SOURCE_DATE_EPOCH
- Updated README.md and commit description to clearly state when BUILD_INFO=y violates reprodcible builds
Changes since v4:
- Updated build date format to +%Y-%m-%d %H:%M:%S %z
- Rename SOURCE_DATE_EPOCH to BUILD_DATE_EPOCH

---
 Makefile           | 31 +++++++++++++++++++++++++++++++
 README.md          | 24 ++++++++++++++++++++++++
 lib/sbi/sbi_init.c |  8 ++++++++
 3 files changed, 63 insertions(+)
Makefile +31 -0
index 16d9dca..8623c1c 100644
@@ -150,6 +150,25 @@ endif
 # Check whether the linker supports creating PIEs
 OPENSBI_LD_PIE := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) $(USE_LD_FLAG) -fPIE -nostdlib -Wl,-pie -x c /dev/null -o /dev/null >/dev/null 2>&1 && echo y || echo n)
 
+# Build Info:
+# OPENSBI_BUILD_TIME_STAMP -- the compilation time stamp
+# OPENSBI_BUILD_COMPILER_VERSION -- the compiler version info
+BUILD_INFO ?= n
+ifeq ($(BUILD_INFO),y)
+OPENSBI_BUILD_DATE_FMT = +%Y-%m-%d %H:%M:%S %z
+ifdef SOURCE_DATE_EPOCH
+       OPENSBI_BUILD_TIME_STAMP ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" \
+               "$(OPENSBI_BUILD_DATE_FMT)" 2>/dev/null || \
+               date -u -r "$(SOURCE_DATE_EPOCH)" \
+               "$(OPENSBI_BUILD_DATE_FMT)" 2>/dev/null || \
+               date -u "$(OPENSBI_BUILD_DATE_FMT)")
+else
+       OPENSBI_BUILD_TIME_STAMP ?= $(shell date "$(OPENSBI_BUILD_DATE_FMT)")
+endif
+OPENSBI_BUILD_COMPILER_VERSION=$(shell $(CC) -v 2>&1 | grep ' version ' | \
+       sed 's/[[:space:]]*$$//')
+endif
+
 # Setup list of objects.mk files
 ifdef PLATFORM
 platform-object-mks=$(shell if [ -d $(platform_src_dir)/ ]; then find $(platform_src_dir) -iname "objects.mk" | sort -r; fi)
@@ -247,6 +266,10 @@ GENFLAGS   +=      -I$(include_dir)
 ifneq ($(OPENSBI_VERSION_GIT),)
 GENFLAGS       +=      -DOPENSBI_VERSION_GIT="\"$(OPENSBI_VERSION_GIT)\""
 endif
+ifeq ($(BUILD_INFO),y)
+GENFLAGS       +=      -DOPENSBI_BUILD_TIME_STAMP="\"$(OPENSBI_BUILD_TIME_STAMP)\""
+GENFLAGS       +=      -DOPENSBI_BUILD_COMPILER_VERSION="\"$(OPENSBI_BUILD_COMPILER_VERSION)\""
+endif
 GENFLAGS       +=      $(libsbiutils-genflags-y)
 GENFLAGS       +=      $(platform-genflags-y)
 GENFLAGS       +=      $(firmware-genflags-y)
@@ -398,6 +421,11 @@ $(build_dir)/%.dep: $(src_dir)/%.c
 $(build_dir)/%.o: $(src_dir)/%.c
        $(call compile_cc,$@,$<)
 
+ifeq ($(BUILD_INFO),y)
+$(build_dir)/lib/sbi/sbi_init.o: $(libsbi_dir)/sbi_init.c FORCE
+       $(call compile_cc,$@,$<)
+endif
+
 $(build_dir)/%.dep: $(src_dir)/%.S
        $(call compile_as_dep,$@,$<)
 
@@ -551,3 +579,6 @@ ifeq ($(install_root_dir),$(install_root_dir_default)/usr)
        $(if $(V), @echo " RM        $(install_root_dir_default)")
        $(CMD_PREFIX)rm -rf $(install_root_dir_default)
 endif
+
+.PHONY: FORCE
+FORCE:
README.md +24 -0
index 9fdf097..54fabe4 100644
@@ -254,6 +254,29 @@ to produce broken binaries with missing relocations; it is therefore currently
 recommended that this combination be avoided or *FW_PIC=n* be used to disable
 building OpenSBI as a position-independent binary.
 
+Building with timestamp and compiler info
+-----------------------------------------
+
+When doing development, we may want to know the build time and compiler info
+for debug purpose. OpenSBI can also be built with timestamp and compiler info.
+To build with those info and print it out at boot time, we can just simply add
+`BUILD_INFO=y`, like:
+```
+make BUILD_INFO=y
+```
+
+But if you have used `BUILD_INFO=y`, and want to switch back to `BUILD_INFO=n`,
+you must do
+```
+make clean
+```
+before the next build.
+
+NOTE: Using `BUILD_INFO=y` without specifying SOURCE_DATE_EPOCH will violate
+[reproducible builds]. This definition is ONLY for development and debug
+purpose, and should NOT be used in a product which follows "reproducible
+builds".
+
 Contributing to OpenSBI
 -----------------------
 
@@ -336,3 +359,4 @@ make I=<install_directory> install_docs
 [Doxygen manual]: http://www.doxygen.nl/manual/index.html
 [Kendryte standalone SDK]: https://github.com/kendryte/kendryte-standalone-sdk
 [third party notices]: ThirdPartyNotices.md
+[reproducible builds]: https://reproducible-builds.org
lib/sbi/sbi_init.c +8 -1
index 843659e..b1c7cf0 100644
@@ -48,6 +48,14 @@ static void sbi_boot_print_banner(struct sbi_scratch *scratch)
                   OPENSBI_VERSION_MINOR);
 #endif
 
+#ifdef OPENSBI_BUILD_TIME_STAMP
+       sbi_printf("Build time: %s\n", OPENSBI_BUILD_TIME_STAMP);
+#endif
+
+#ifdef OPENSBI_BUILD_COMPILER_VERSION
+       sbi_printf("Build compiler: %s\n", OPENSBI_BUILD_COMPILER_VERSION);
+#endif
+
        sbi_printf(BANNER);
 }
 
--

2.25.1

#5 lore raw

PATCH v6 1/1 Makefile: Add build time and compiler info string

Hi Anup,

Great thanks for all your help!

I was busy on some RISCV koji project, and was distracted for some days. I do apologize.

Great thanks for all your great efforts to post two more version for it !

Great thanks ! :-)

Anup Patel <[email protected]> ?2021?10?21??? ??12:07???

Quoted 169 lines · Anup Patel
Quoted 12 lines

From: Wei Fu <[email protected]>

When we are doing opensbi development, we want to know the build time and compiler info for debug purpose.

To enable this message, please add "BUILD_INFO=y", like:

```
make BUILD_INFO=y
```
Quoted 8 lines

NOTE: Using BUILD_INFO=y without specifying SOURCE_DATE_EPOCH will violate "reproducible builds". So it's ONLY for development and debug purpose, and should NOT be used in a product which follows "reproducible builds".

Applied this patch to the riscv/opensbi repo

Regards,
Anup

Quoted 134 lines

---
Changes since v5:
- BUILD_DATE_EPOCH is non-standard name so rename it back to SOURCE_DATE_EPOCH
- Updated README.md and commit description to clearly state when BUILD_INFO=y violates reprodcible builds
Changes since v4:
- Updated build date format to +%Y-%m-%d %H:%M:%S %z
- Rename SOURCE_DATE_EPOCH to BUILD_DATE_EPOCH

---
 Makefile           | 31 +++++++++++++++++++++++++++++++
 README.md          | 24 ++++++++++++++++++++++++
 lib/sbi/sbi_init.c |  8 ++++++++
 3 files changed, 63 insertions(+)
Makefile +31 -0
index 16d9dca..8623c1c 100644
@@ -150,6 +150,25 @@ endif
 # Check whether the linker supports creating PIEs
 OPENSBI_LD_PIE := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) $(USE_LD_FLAG) -fPIE -nostdlib -Wl,-pie -x c /dev/null -o /dev/null >/dev/null 2>&1 && echo y || echo n)
 
+# Build Info:
+# OPENSBI_BUILD_TIME_STAMP -- the compilation time stamp
+# OPENSBI_BUILD_COMPILER_VERSION -- the compiler version info
+BUILD_INFO ?= n
+ifeq ($(BUILD_INFO),y)
+OPENSBI_BUILD_DATE_FMT = +%Y-%m-%d %H:%M:%S %z
+ifdef SOURCE_DATE_EPOCH
+       OPENSBI_BUILD_TIME_STAMP ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" \
+               "$(OPENSBI_BUILD_DATE_FMT)" 2>/dev/null || \
+               date -u -r "$(SOURCE_DATE_EPOCH)" \
+               "$(OPENSBI_BUILD_DATE_FMT)" 2>/dev/null || \
+               date -u "$(OPENSBI_BUILD_DATE_FMT)")
+else
+       OPENSBI_BUILD_TIME_STAMP ?= $(shell date "$(OPENSBI_BUILD_DATE_FMT)")
+endif
+OPENSBI_BUILD_COMPILER_VERSION=$(shell $(CC) -v 2>&1 | grep ' version ' | \
+       sed 's/[[:space:]]*$$//')
+endif
+
 # Setup list of objects.mk files
 ifdef PLATFORM
 platform-object-mks=$(shell if [ -d $(platform_src_dir)/ ]; then find $(platform_src_dir) -iname "objects.mk" | sort -r; fi)
@@ -247,6 +266,10 @@ GENFLAGS   +=      -I$(include_dir)
 ifneq ($(OPENSBI_VERSION_GIT),)
 GENFLAGS       +=      -DOPENSBI_VERSION_GIT="\"$(OPENSBI_VERSION_GIT)\""
 endif
+ifeq ($(BUILD_INFO),y)
+GENFLAGS       +=      -DOPENSBI_BUILD_TIME_STAMP="\"$(OPENSBI_BUILD_TIME_STAMP)\""
+GENFLAGS       +=      -DOPENSBI_BUILD_COMPILER_VERSION="\"$(OPENSBI_BUILD_COMPILER_VERSION)\""
+endif
 GENFLAGS       +=      $(libsbiutils-genflags-y)
 GENFLAGS       +=      $(platform-genflags-y)
 GENFLAGS       +=      $(firmware-genflags-y)
@@ -398,6 +421,11 @@ $(build_dir)/%.dep: $(src_dir)/%.c
 $(build_dir)/%.o: $(src_dir)/%.c
        $(call compile_cc,$@,$<)
 
+ifeq ($(BUILD_INFO),y)
+$(build_dir)/lib/sbi/sbi_init.o: $(libsbi_dir)/sbi_init.c FORCE
+       $(call compile_cc,$@,$<)
+endif
+
 $(build_dir)/%.dep: $(src_dir)/%.S
        $(call compile_as_dep,$@,$<)
 
@@ -551,3 +579,6 @@ ifeq ($(install_root_dir),$(install_root_dir_default)/usr)
        $(if $(V), @echo " RM        $(install_root_dir_default)")
        $(CMD_PREFIX)rm -rf $(install_root_dir_default)
 endif
+
+.PHONY: FORCE
+FORCE:
README.md +24 -0
index 9fdf097..54fabe4 100644
@@ -254,6 +254,29 @@ to produce broken binaries with missing relocations; it is therefore currently
 recommended that this combination be avoided or *FW_PIC=n* be used to disable
 building OpenSBI as a position-independent binary.
 
+Building with timestamp and compiler info
+-----------------------------------------
+
+When doing development, we may want to know the build time and compiler info
+for debug purpose. OpenSBI can also be built with timestamp and compiler info.
+To build with those info and print it out at boot time, we can just simply add
+`BUILD_INFO=y`, like:
+```
+make BUILD_INFO=y
+```
+
+But if you have used `BUILD_INFO=y`, and want to switch back to `BUILD_INFO=n`,
+you must do
+```
+make clean
+```
+before the next build.
+
+NOTE: Using `BUILD_INFO=y` without specifying SOURCE_DATE_EPOCH will violate
+[reproducible builds]. This definition is ONLY for development and debug
+purpose, and should NOT be used in a product which follows "reproducible
+builds".
+
 Contributing to OpenSBI
 -----------------------
 
@@ -336,3 +359,4 @@ make I=<install_directory> install_docs
 [Doxygen manual]: http://www.doxygen.nl/manual/index.html
 [Kendryte standalone SDK]: https://github.com/kendryte/kendryte-standalone-sdk
 [third party notices]: ThirdPartyNotices.md
+[reproducible builds]: https://reproducible-builds.org
lib/sbi/sbi_init.c +8 -1
index 843659e..b1c7cf0 100644
@@ -48,6 +48,14 @@ static void sbi_boot_print_banner(struct sbi_scratch *scratch)
                   OPENSBI_VERSION_MINOR);
 #endif
 
+#ifdef OPENSBI_BUILD_TIME_STAMP
+       sbi_printf("Build time: %s\n", OPENSBI_BUILD_TIME_STAMP);
+#endif
+
+#ifdef OPENSBI_BUILD_COMPILER_VERSION
+       sbi_printf("Build compiler: %s\n", OPENSBI_BUILD_COMPILER_VERSION);
+#endif
+
        sbi_printf(BANNER);
 }
 
--
Quoted 2 lines

2.25.1

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

#6 lore raw

PATCH v6 1/1 Makefile: Add build time and compiler info string

Quoted 11 lines · Fu Wei

Hi Anup,

Great thanks for all your help!

I was busy on some RISCV koji project, and was distracted for some days. I do apologize.

Great thanks for all your great efforts to post two more version for it !

Great thanks ! :-)

No need to thank. This was a useful change so I had to take it.

Regards,
Anup

Quoted 171 lines

Anup Patel <[email protected]> ?2021?10?21??? ??12:07???

Quoted 169 lines · Anup Patel
Quoted 12 lines

From: Wei Fu <[email protected]>

When we are doing opensbi development, we want to know the build time and compiler info for debug purpose.

To enable this message, please add "BUILD_INFO=y", like:

```
make BUILD_INFO=y
```
Quoted 8 lines

NOTE: Using BUILD_INFO=y without specifying SOURCE_DATE_EPOCH will violate "reproducible builds". So it's ONLY for development and debug purpose, and should NOT be used in a product which follows "reproducible builds".

Applied this patch to the riscv/opensbi repo

Regards,
Anup

Quoted 134 lines

---
Changes since v5:
- BUILD_DATE_EPOCH is non-standard name so rename it back to SOURCE_DATE_EPOCH
- Updated README.md and commit description to clearly state when BUILD_INFO=y violates reprodcible builds
Changes since v4:
- Updated build date format to +%Y-%m-%d %H:%M:%S %z
- Rename SOURCE_DATE_EPOCH to BUILD_DATE_EPOCH

---
 Makefile           | 31 +++++++++++++++++++++++++++++++
 README.md          | 24 ++++++++++++++++++++++++
 lib/sbi/sbi_init.c |  8 ++++++++
 3 files changed, 63 insertions(+)
Makefile +31 -0
index 16d9dca..8623c1c 100644
@@ -150,6 +150,25 @@ endif
 # Check whether the linker supports creating PIEs
 OPENSBI_LD_PIE := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) $(USE_LD_FLAG) -fPIE -nostdlib -Wl,-pie -x c /dev/null -o /dev/null >/dev/null 2>&1 && echo y || echo n)
 
+# Build Info:
+# OPENSBI_BUILD_TIME_STAMP -- the compilation time stamp
+# OPENSBI_BUILD_COMPILER_VERSION -- the compiler version info
+BUILD_INFO ?= n
+ifeq ($(BUILD_INFO),y)
+OPENSBI_BUILD_DATE_FMT = +%Y-%m-%d %H:%M:%S %z
+ifdef SOURCE_DATE_EPOCH
+       OPENSBI_BUILD_TIME_STAMP ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" \
+               "$(OPENSBI_BUILD_DATE_FMT)" 2>/dev/null || \
+               date -u -r "$(SOURCE_DATE_EPOCH)" \
+               "$(OPENSBI_BUILD_DATE_FMT)" 2>/dev/null || \
+               date -u "$(OPENSBI_BUILD_DATE_FMT)")
+else
+       OPENSBI_BUILD_TIME_STAMP ?= $(shell date "$(OPENSBI_BUILD_DATE_FMT)")
+endif
+OPENSBI_BUILD_COMPILER_VERSION=$(shell $(CC) -v 2>&1 | grep ' version ' | \
+       sed 's/[[:space:]]*$$//')
+endif
+
 # Setup list of objects.mk files
 ifdef PLATFORM
 platform-object-mks=$(shell if [ -d $(platform_src_dir)/ ]; then find $(platform_src_dir) -iname "objects.mk" | sort -r; fi)
@@ -247,6 +266,10 @@ GENFLAGS   +=      -I$(include_dir)
 ifneq ($(OPENSBI_VERSION_GIT),)
 GENFLAGS       +=      -DOPENSBI_VERSION_GIT="\"$(OPENSBI_VERSION_GIT)\""
 endif
+ifeq ($(BUILD_INFO),y)
+GENFLAGS       +=      -DOPENSBI_BUILD_TIME_STAMP="\"$(OPENSBI_BUILD_TIME_STAMP)\""
+GENFLAGS       +=      -DOPENSBI_BUILD_COMPILER_VERSION="\"$(OPENSBI_BUILD_COMPILER_VERSION)\""
+endif
 GENFLAGS       +=      $(libsbiutils-genflags-y)
 GENFLAGS       +=      $(platform-genflags-y)
 GENFLAGS       +=      $(firmware-genflags-y)
@@ -398,6 +421,11 @@ $(build_dir)/%.dep: $(src_dir)/%.c
 $(build_dir)/%.o: $(src_dir)/%.c
        $(call compile_cc,$@,$<)
 
+ifeq ($(BUILD_INFO),y)
+$(build_dir)/lib/sbi/sbi_init.o: $(libsbi_dir)/sbi_init.c FORCE
+       $(call compile_cc,$@,$<)
+endif
+
 $(build_dir)/%.dep: $(src_dir)/%.S
        $(call compile_as_dep,$@,$<)
 
@@ -551,3 +579,6 @@ ifeq ($(install_root_dir),$(install_root_dir_default)/usr)
        $(if $(V), @echo " RM        $(install_root_dir_default)")
        $(CMD_PREFIX)rm -rf $(install_root_dir_default)
 endif
+
+.PHONY: FORCE
+FORCE:
README.md +24 -0
index 9fdf097..54fabe4 100644
@@ -254,6 +254,29 @@ to produce broken binaries with missing relocations; it is therefore currently
 recommended that this combination be avoided or *FW_PIC=n* be used to disable
 building OpenSBI as a position-independent binary.
 
+Building with timestamp and compiler info
+-----------------------------------------
+
+When doing development, we may want to know the build time and compiler info
+for debug purpose. OpenSBI can also be built with timestamp and compiler info.
+To build with those info and print it out at boot time, we can just simply add
+`BUILD_INFO=y`, like:
+```
+make BUILD_INFO=y
+```
+
+But if you have used `BUILD_INFO=y`, and want to switch back to `BUILD_INFO=n`,
+you must do
+```
+make clean
+```
+before the next build.
+
+NOTE: Using `BUILD_INFO=y` without specifying SOURCE_DATE_EPOCH will violate
+[reproducible builds]. This definition is ONLY for development and debug
+purpose, and should NOT be used in a product which follows "reproducible
+builds".
+
 Contributing to OpenSBI
 -----------------------
 
@@ -336,3 +359,4 @@ make I=<install_directory> install_docs
 [Doxygen manual]: http://www.doxygen.nl/manual/index.html
 [Kendryte standalone SDK]: https://github.com/kendryte/kendryte-standalone-sdk
 [third party notices]: ThirdPartyNotices.md
+[reproducible builds]: https://reproducible-builds.org
lib/sbi/sbi_init.c +8 -1
index 843659e..b1c7cf0 100644
@@ -48,6 +48,14 @@ static void sbi_boot_print_banner(struct sbi_scratch *scratch)
                   OPENSBI_VERSION_MINOR);
 #endif
 
+#ifdef OPENSBI_BUILD_TIME_STAMP
+       sbi_printf("Build time: %s\n", OPENSBI_BUILD_TIME_STAMP);
+#endif
+
+#ifdef OPENSBI_BUILD_COMPILER_VERSION
+       sbi_printf("Build compiler: %s\n", OPENSBI_BUILD_COMPILER_VERSION);
+#endif
+
        sbi_printf(BANNER);
 }
 
--
Quoted 2 lines

2.25.1

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

#7 lore raw

PATCH v6 1/1 Makefile: Add build time and compiler info string

In reply to Anup Patel
Quoted 19 lines · Anup Patel
Quoted 17 lines · Anup Patel

From: Wei Fu <[email protected]>

When we are doing opensbi development, we want to know the build time and compiler info for debug purpose.

To enable this message, please add "BUILD_INFO=y", like:

```
make BUILD_INFO=y
```

NOTE: Using BUILD_INFO=y without specifying SOURCE_DATE_EPOCH will violate "reproducible builds". So it's ONLY for development and debug purpose, and should NOT be used in a product which follows "reproducible builds".

Quoted 6 lines
Quoted 3 lines

Applied this patch to the riscv/opensbi repo

Please cc people who gave comments to previous versions, and wait for a day or two before the applying.

Regards,
Bin