Skip to contentSkip to conversation

[RFC PATCH v2 0/4]

RFC PATCH In review Alexandre Torgue 3 participants 7 messages Feb 21, 2020 – Feb 26, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover [RFC PATCH v2 0/4]

Hi,

The goal of this series is to add device tree build information in dtb. This information can be dtb build date, where devicetree files come from, who built the dtb ... Actually, same kind of information that you can find in the Linux banner which is printout during kernel boot. Having the same kind of information for device tree is useful for debugging and maintenance.

A file (dtb-build.txt) containing a string with build information (e.g., From Linux 5.5.0-rc1 by alex the Mon Jan 13 18:25:38 CET 2020) is generated by "gen_dtb_build_info.sh" script.

This file has to be included manually in each dts file that would like to use this build information.

of/fdt.c is modified to printout "build-info" property during Kernel boot and scripts/Makefile.lib is modified to call "gen_dtb_build_info.sh" script.

Patch 1 & 2 script and of/fdt.c updates
Patch 3 is an example of use in stm32mp157c-dk2.dts file. Patch 4 is a tentative to make it automatic (not yet 100% functional).

regards
Alex

Changes since v1;
- Remove modification in dtc (no more -B option)
- Generate a file containing build info which is directly included in dts file.

Regards
Alex

Alexandre Torgue (4):
scripts: Add script to generate dtb build information
of: fdt: print dtb build information
ARM: dts: stm32: Add dtb build information entry for stm32mp157c-dk2
script: make automatic dtb build info generation

 arch/arm/boot/dts/stm32mp157c-dk2.dts |  1 +
 drivers/of/fdt.c                      |  9 +++++++++
 scripts/Makefile.lib                  |  3 +++
 scripts/gen_dtb_build_info.sh         | 12 ++++++++++++
 4 files changed, 25 insertions(+)
 create mode 100755 scripts/gen_dtb_build_info.sh
Signature · 1 line
2.17.1
#1 lore raw

RFC PATCH v2 1/4 scripts: Add script to generate dtb build information

This commit adds a new script to create a file (in dts file directory) with some information (date, Linux version, user). This file could then be used to populate "build-info" property in every dts file that would use this build information:

Example:

/ {
	...
	build-info = /incbin/("dtb-build.txt");
	...
};
scripts/Makefile.lib +2 -0
index bae62549e3d2..a5af84ef4ffc 100644
@@ -246,6 +246,7 @@ quiet_cmd_gzip = GZIP    $@
 # DTC
 # ---------------------------------------------------------------------------
 DTC ?= $(objtree)/scripts/dtc/dtc
+DTB_GEN_INFO ?= $(objtree)/scripts/gen_dtb_build_info.sh
 
 # Disable noisy checks by default
 ifeq ($(findstring 1,$(KBUILD_EXTRA_WARN)),)
@@ -286,6 +287,7 @@ $(obj)/%.dtb.S: $(obj)/%.dtb FORCE
 
 quiet_cmd_dtc = DTC     $@
 cmd_dtc = mkdir -p $(dir ${dtc-tmp}) ; \
+	$(DTB_GEN_INFO) $(src) ; \
 	$(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
 	$(DTC) -O $(2) -o $@ -b 0 \
 		$(addprefix -i,$(dir $<) $(DTC_INCLUDE)) $(DTC_FLAGS) \
scripts/gen_dtb_build_info.sh new file +10 -0
new file mode 100755
index 000000000000..0cd8bd98e410
@@ -0,0 +1,10 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+set -o nounset
+
+DTB_DIR=$1
+DTB_COMPILE_BY=$(whoami | sed 's/\\/\\\\/')
+DTB_INFO="From Linux $KERNELRELEASE by $DTB_COMPILE_BY the $(date).\0"
+
+printf "$DTB_INFO" > "$DTB_DIR/dtb-build.txt"
Signature · 1 line
2.17.1
#2 lore raw

Re: [RFC PATCH v2 1/4] scripts: Add script to generate dtb build information

Hi.

Quoted 53 lines · Alexandre Torgue

This commit adds a new script to create a file (in dts file directory) with some information (date, Linux version, user). This file could then be used to populate "build-info" property in every dts file that would use this build information:

Example:

/ {
        ...
        build-info = /incbin/("dtb-build.txt");
        ...
};
scripts/Makefile.lib +2 -0
index bae62549e3d2..a5af84ef4ffc 100644
@@ -246,6 +246,7 @@ quiet_cmd_gzip = GZIP    $@
 # DTC
 # ---------------------------------------------------------------------------
 DTC ?= $(objtree)/scripts/dtc/dtc
+DTB_GEN_INFO ?= $(objtree)/scripts/gen_dtb_build_info.sh
 
 # Disable noisy checks by default
 ifeq ($(findstring 1,$(KBUILD_EXTRA_WARN)),)
@@ -286,6 +287,7 @@ $(obj)/%.dtb.S: $(obj)/%.dtb FORCE
 
 quiet_cmd_dtc = DTC     $@
 cmd_dtc = mkdir -p $(dir ${dtc-tmp}) ; \
+       $(DTB_GEN_INFO) $(src) ; \
        $(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
        $(DTC) -O $(2) -o $@ -b 0 \
                $(addprefix -i,$(dir $<) $(DTC_INCLUDE)) $(DTC_FLAGS) \
scripts/gen_dtb_build_info.sh new file +10 -1
new file mode 100755
index 000000000000..0cd8bd98e410
@@ -0,0 +1,10 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+set -o nounset
+
+DTB_DIR=$1
+DTB_COMPILE_BY=$(whoami | sed 's/\\/\\\\/')
+DTB_INFO="From Linux $KERNELRELEASE by $DTB_COMPILE_BY the $(date).\0"
+
+printf "$DTB_INFO" > "$DTB_DIR/dtb-build.txt"
--
Quoted 2 lines

2.17.1

There are more than 1000 *.dts files
in arch/arm/boot/dts/.

So, with this patch, the build system will creates arch/arm/boot/dts/dtb-build.txt 1000 times.

Does it work with parallel build ?

Think about what would happen
with 'make -j32 ARCH=arm dtbs'

The 32 threads will write to
arch/arm/boot/dts/dtb-build.txt
at the same time.

Then, some of DTB would very likely to
include the broken dtb-build.txt

A list of missing parts in this approach:

- make it work with parallel build
- clean it up with 'make clean'
- add it .gitignore (and Documentation/dontdiff)

Signature · 2 lines
Best Regards
Masahiro Yamada
#3 lore raw

Re: [RFC PATCH v2 1/4] scripts: Add script to generate dtb build information

Hi Alexandre,

Quoted 82 lines · Masahiro Yamada

Hi.

Quoted 53 lines · Alexandre Torgue

This commit adds a new script to create a file (in dts file directory) with some information (date, Linux version, user). This file could then be used to populate "build-info" property in every dts file that would use this build information:

Example:

/ {
        ...
        build-info = /incbin/("dtb-build.txt");
        ...
};
scripts/Makefile.lib +2 -0
index bae62549e3d2..a5af84ef4ffc 100644
@@ -246,6 +246,7 @@ quiet_cmd_gzip = GZIP    $@
 # DTC
 # ---------------------------------------------------------------------------
 DTC ?= $(objtree)/scripts/dtc/dtc
+DTB_GEN_INFO ?= $(objtree)/scripts/gen_dtb_build_info.sh
 
 # Disable noisy checks by default
 ifeq ($(findstring 1,$(KBUILD_EXTRA_WARN)),)
@@ -286,6 +287,7 @@ $(obj)/%.dtb.S: $(obj)/%.dtb FORCE
 
 quiet_cmd_dtc = DTC     $@
 cmd_dtc = mkdir -p $(dir ${dtc-tmp}) ; \
+       $(DTB_GEN_INFO) $(src) ; \
        $(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
        $(DTC) -O $(2) -o $@ -b 0 \
                $(addprefix -i,$(dir $<) $(DTC_INCLUDE)) $(DTC_FLAGS) \
scripts/gen_dtb_build_info.sh new file +10 -1
new file mode 100755
index 000000000000..0cd8bd98e410
@@ -0,0 +1,10 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+set -o nounset
+
+DTB_DIR=$1
+DTB_COMPILE_BY=$(whoami | sed 's/\\/\\\\/')
+DTB_INFO="From Linux $KERNELRELEASE by $DTB_COMPILE_BY the $(date).\0"
+
+printf "$DTB_INFO" > "$DTB_DIR/dtb-build.txt"
--
Quoted 2 lines

2.17.1

There are more than 1000 *.dts files
in arch/arm/boot/dts/.

So, with this patch, the build system will creates arch/arm/boot/dts/dtb-build.txt 1000 times.

Does it work with parallel build ?

Think about what would happen
with 'make -j32 ARCH=arm dtbs'

The 32 threads will write to
arch/arm/boot/dts/dtb-build.txt
at the same time.

Then, some of DTB would very likely to
include the broken dtb-build.txt

Quoted 8 lines

A list of missing parts in this approach:

- make it work with parallel build
- clean it up with 'make clean'
- add it .gitignore (and Documentation/dontdiff)

You might be able to rework script 'version_dtb_increment_once' from my previous attempt at this concept. I do not know if the build system has changed since 2015 in a way that would make the script incorrect or if it is still valid.

https://lore.kernel.org/linux-arm-kernel/[email protected]/

-Frank

#4 lore raw

RFC PATCH v2 2/4 of: fdt: print dtb build information

In reply to Alexandre Torgue

This commit prints out DTB build information (build time, dts source version used, ...) if "Build-info" property exists in DTB root node.

drivers/of/fdt.c +9 -0
index 2cdf64d2456f..aa5989039746 100644
@@ -1224,9 +1224,18 @@ bool __init early_init_dt_scan(void *params)
  */
 void __init unflatten_device_tree(void)
 {
+	const char *build_info;
+	unsigned long dt_root;
+
 	__unflatten_device_tree(initial_boot_params, NULL, &of_root,
 				early_init_dt_alloc_memory_arch, false);
 
+	/* If available, provide dtb build information */
+	dt_root = of_get_flat_dt_root();
+	build_info = of_get_flat_dt_prop(dt_root, "build-info", NULL);
+	if (build_info)
+		pr_info("%s\n", build_info);
+
 	/* Get pointer to "/chosen" and "/aliases" nodes for use everywhere */
 	of_alias_scan(early_init_dt_alloc_memory_arch);
 
Signature · 1 line
2.17.1
#5 lore raw

RFC PATCH v2 3/4 ARM: dts: stm32: Add dtb build information entry for stm32mp157c-dk2

In reply to Alexandre Torgue

dtb-build.txt is a file containing device tree build information (date, source version ...). This file is used to fill "build-info" entry which will be displayed during kernel boot.

arch/arm/boot/dts/stm32mp157c-dk2.dts +1 -0
index 7985b80967ca..387d3bcf5fa3 100644
@@ -15,6 +15,7 @@
 / {
 	model = "STMicroelectronics STM32MP157C-DK2 Discovery Board";
 	compatible = "st,stm32mp157c-dk2", "st,stm32mp157";
+	build-info = /incbin/("dtb-build.txt");
 
 	aliases {
 		ethernet0 = &ethernet0;
Signature · 1 line
2.17.1
#6 lore raw

RFC PATCH v2 4/4 script: make automatic dtb build info generation

In reply to Alexandre Torgue

Append each "xxx.dtb.dts.tmp" file with "build-info" entry during dtb build. It allows to get build information (date, source version, ...) for each device tree without modify them manually.

scripts/Makefile.lib +1 -0
index a5af84ef4ffc..f084e78267b2 100644
@@ -289,6 +289,7 @@ quiet_cmd_dtc = DTC     $@
 cmd_dtc = mkdir -p $(dir ${dtc-tmp}) ; \
 	$(DTB_GEN_INFO) $(src) ; \
 	$(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
+	$(DTB_GEN_INFO) $(src) $(dtc-tmp) ; \
 	$(DTC) -O $(2) -o $@ -b 0 \
 		$(addprefix -i,$(dir $<) $(DTC_INCLUDE)) $(DTC_FLAGS) \
 		-d $(depfile).dtc.tmp $(dtc-tmp) ; \
scripts/gen_dtb_build_info.sh +3 -1
index 0cd8bd98e410..72f31e386787 100755
@@ -6,5 +6,7 @@ set -o nounset
 DTB_DIR=$1
 DTB_COMPILE_BY=$(whoami | sed 's/\\/\\\\/')
 DTB_INFO="From Linux $KERNELRELEASE by $DTB_COMPILE_BY the $(date).\0"
+DTS_FILE=$2
 
-printf "$DTB_INFO" > "$DTB_DIR/dtb-build.txt"
+printf "$DTB_INFO" > "arch/arm/boot/dts/dtb-build.txt"
+echo "&{/} {build-info = /incbin/(\"dtb-build.txt\");};" >> $DTS_FILE
Signature · 1 line
2.17.1