2020-02-21 16:13:20

by Alexandre Torgue

[permalink] [raw]
Subject: [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

--
2.17.1


2020-02-21 16:13:23

by Alexandre Torgue

[permalink] [raw]
Subject: [RFC PATCH v2 4/4] script: make automatic dtb build info generation

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.

Signed-off-by: Alexandre Torgue <[email protected]>

diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index a5af84ef4ffc..f084e78267b2 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -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) ; \
diff --git a/scripts/gen_dtb_build_info.sh b/scripts/gen_dtb_build_info.sh
index 0cd8bd98e410..72f31e386787 100755
--- a/scripts/gen_dtb_build_info.sh
+++ b/scripts/gen_dtb_build_info.sh
@@ -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
--
2.17.1

2020-02-21 16:13:59

by Alexandre Torgue

[permalink] [raw]
Subject: [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");
...
};

Signed-off-by: Alexandre Torgue <[email protected]>

diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index bae62549e3d2..a5af84ef4ffc 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -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) \
diff --git a/scripts/gen_dtb_build_info.sh b/scripts/gen_dtb_build_info.sh
new file mode 100755
index 000000000000..0cd8bd98e410
--- /dev/null
+++ b/scripts/gen_dtb_build_info.sh
@@ -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"
--
2.17.1

2020-02-21 16:15:40

by Alexandre Torgue

[permalink] [raw]
Subject: [RFC PATCH v2 2/4] of: fdt: print dtb build information

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

Signed-off-by: Alexandre Torgue <[email protected]>

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 2cdf64d2456f..aa5989039746 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -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);

--
2.17.1

2020-02-24 17:46:13

by Masahiro Yamada

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

Hi.

On Sat, Feb 22, 2020 at 1:12 AM Alexandre Torgue
<[email protected]> wrote:
>
> 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");
> ...
> };
>
> Signed-off-by: Alexandre Torgue <[email protected]>
>
> diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
> index bae62549e3d2..a5af84ef4ffc 100644
> --- a/scripts/Makefile.lib
> +++ b/scripts/Makefile.lib
> @@ -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) \
> diff --git a/scripts/gen_dtb_build_info.sh b/scripts/gen_dtb_build_info.sh
> new file mode 100755
> index 000000000000..0cd8bd98e410
> --- /dev/null
> +++ b/scripts/gen_dtb_build_info.sh
> @@ -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"
> --
> 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)



--
Best Regards
Masahiro Yamada

2020-02-26 16:40:27

by Frank Rowand

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

Hi Alexandre,

On 2/24/20 11:45 AM, Masahiro Yamada wrote:
> Hi.
>
> On Sat, Feb 22, 2020 at 1:12 AM Alexandre Torgue
> <[email protected]> wrote:
>>
>> 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");
>> ...
>> };
>>
>> Signed-off-by: Alexandre Torgue <[email protected]>
>>
>> diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
>> index bae62549e3d2..a5af84ef4ffc 100644
>> --- a/scripts/Makefile.lib
>> +++ b/scripts/Makefile.lib
>> @@ -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) \
>> diff --git a/scripts/gen_dtb_build_info.sh b/scripts/gen_dtb_build_info.sh
>> new file mode 100755
>> index 000000000000..0cd8bd98e410
>> --- /dev/null
>> +++ b/scripts/gen_dtb_build_info.sh
>> @@ -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"
>> --
>> 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)
>
>
>

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