[PATCH] scripts/Makefile.lib: add -D__U_BOOT__ to dtc_cpp_flags

Rasmus Villemoes rasmus.villemoes at prevas.dk
Fri Jul 1 09:27:59 CEST 2022


When trying to use the exact same device tree source to build the dtbs
used with U-Boot and linux, one often runs into various problems. For
example, files under include/dt-bindings/ might not be completely in
sync, so some #defines are available in linux but not in U-Boot.

It's also possible that there are nodes/hardware one simply doesn't
need or want to describe to U-Boot, e.g. to reduce the size of the
.dtb (for SPL, there's already the whole fdtgrep machinery to deal
with that, but not for U-Boot proper), or configuration settings like
watchdog timeout one wants to make different between linux and U-Boot.

So in order to allow such tweaks, add an explicit define of the macro
__U_BOOT__. Since U-Boot includes linux/kconfig.h (and defines
__ASSEMBLY__ to make that work) while linux doesn't, one could also
use __ASSEMBLY__ or just about any known-to-be-defined CONFIG_* macro
as a proxy, but it's much more readable, maintainable and robust if
one's .dts has "ifdef __U_BOOT__" rather than "ifdef __ASSEMBLY__".

Signed-off-by: Rasmus Villemoes <rasmus.villemoes at prevas.dk>
---
 scripts/Makefile.lib | 1 +
 1 file changed, 1 insertion(+)

diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 3db2550085..4183767a62 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -190,6 +190,7 @@ dtc_cpp_flags  = -Wp,-MD,$(depfile).pre.tmp -nostdinc                    \
 		 -I$(srctree)/arch/$(ARCH)/dts/include                   \
 		 -I$(srctree)/include                                    \
 		 -D__ASSEMBLY__                                          \
+		 -D__U_BOOT__                                            \
 		 -undef -D__DTS__
 
 # Finds the multi-part object the current object will be linked into
-- 
2.31.1



More information about the U-Boot mailing list