From 9e4140329ee9a787d0f96ac2829d618d47f7973f Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 4 Feb 2014 17:24:24 +0900 Subject: kbuild: change out-of-tree build This commit changes the working directory where the build process occurs. Before this commit, build process occurred under the source tree for both in-tree and out-of-tree build. That's why we needed to add $(obj) prefix to all generated files in makefiles like follows: $(obj)u-boot.bin: $(obj)u-boot Here, $(obj) is empty for in-tree build, whereas it points to the output directory for out-of-tree build. And our old build system changes the current working directory with "make -C " syntax when descending into the sub-directories. On the other hand, Kbuild uses a different idea to handle out-of-tree build and directory descending. The build process of Kbuild always occurs under the output tree. When "O=dir/to/store/output/files" is given, the build system changes the current working directory to that directory and restarts the make. Kbuild uses "make -f $(srctree)/scripts/Makefile.build obj=" syntax for descending into sub-directories. (We can write it like "make $(obj)=" with a shorthand.) This means the current working directory is always the top of the output directory. Signed-off-by: Masahiro Yamada Tested-by: Gerhard Sittig --- dts/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'dts') diff --git a/dts/Makefile b/dts/Makefile index 6c7198f..d81f32d 100644 --- a/dts/Makefile +++ b/dts/Makefile @@ -26,7 +26,7 @@ DTC_FLAGS := -R 4 -p 0x1000 \ # Use a constant name for this so we can access it from C code. # objcopy doesn't seem to allow us to set the symbol name independently of # the filename. -DT_BIN := $(obj)dt.dtb +DT_BIN := $(obj)/dt.dtb $(DT_BIN): $(TOPDIR)/board/$(VENDOR)/dts/$(DEVICE_TREE).dts $(CPP) $(DTS_CPPFLAGS) $< -o $(DT_BIN).dts.tmp @@ -38,7 +38,7 @@ process_lds = \ # Run the compiler and get the link script from the linker GET_LDS = $(CC) $(CFLAGS) $(LDFLAGS) -Wl,--verbose 2>&1 -$(obj)dt.o: $(DT_BIN) +$(obj)/dt.o: $(DT_BIN) # We want the output format and arch. # We also hope to win a prize for ugliest Makefile / shell interaction # We look in the LDSCRIPT first. @@ -62,7 +62,7 @@ $(obj)dt.o: $(DT_BIN) \ cd $(dir ${DT_BIN}) && \ $(OBJCOPY) -I binary -O $${oformat} -B $${oarch} \ - $(notdir ${DT_BIN}) $@ + $(notdir ${DT_BIN}) $(notdir $@) rm $(DT_BIN) obj-$(CONFIG_OF_EMBED) := dt.o -- cgit v1.1 From 6825a95b0ba72c4e5667d02d8b31986e2e9abd5a Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 4 Feb 2014 17:24:28 +0900 Subject: kbuild: use Linux Kernel build scripts Now we are ready to switch over to real Kbuild. This commit disables temporary scripts: scripts/{Makefile.build.tmp, Makefile.host.tmp} and enables real Kbuild scripts: scripts/{Makefile.build,Makefile.host,Makefile.lib}. This switch is triggered by the line in scripts/Kbuild.include -build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build.tmp obj +build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj We need to adjust some build scripts for U-Boot. But smaller amount of modification is preferable. Additionally, we need to fix compiler flags which are locally added or removed. In Kbuild, it is not allowed to change CFLAGS locally. Instead, ccflags-y, asflags-y, cppflags-y, CFLAGS_$(basetarget).o, CFLAGS_REMOVE_$(basetarget).o are prepared for that purpose. Signed-off-by: Masahiro Yamada Tested-by: Gerhard Sittig --- dts/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dts') diff --git a/dts/Makefile b/dts/Makefile index d81f32d..cc6ecf6 100644 --- a/dts/Makefile +++ b/dts/Makefile @@ -36,7 +36,7 @@ process_lds = \ $(1) | sed -r -n 's/^OUTPUT_$(2)[ ("]*([^")]*).*/\1/p' # Run the compiler and get the link script from the linker -GET_LDS = $(CC) $(CFLAGS) $(LDFLAGS) -Wl,--verbose 2>&1 +GET_LDS = $(CC) $(c_flags) $(ld_flags) -Wl,--verbose 2>&1 $(obj)/dt.o: $(DT_BIN) # We want the output format and arch. -- cgit v1.1 From efcf861931f987d82b11caed75b8c2ad9d709274 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 4 Feb 2014 17:24:40 +0900 Subject: kbuild: use scripts/Makefile.clean This commit refactors cleaning targets such as clean, clobber, mrpropper, distclean with scripts/Makefile.clean. By using scripts/Makefile.clean, we can recursively descend into subdirectories and delete generated files there. We do not need add a big list of generated files to the "clean" target. Signed-off-by: Masahiro Yamada --- dts/Makefile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'dts') diff --git a/dts/Makefile b/dts/Makefile index cc6ecf6..1e7609a 100644 --- a/dts/Makefile +++ b/dts/Makefile @@ -7,12 +7,6 @@ # This Makefile builds the internal U-Boot fdt if CONFIG_OF_CONTROL is # enabled. See doc/README.fdt-control for more details. -ifeq ($(DEVICE_TREE),) -$(if $(CONFIG_DEFAULT_DEVICE_TREE),,\ -$(error Please define CONFIG_DEFAULT_DEVICE_TREE in your board header file)) -DEVICE_TREE = $(CONFIG_DEFAULT_DEVICE_TREE:"%"=%) -endif - DTS_INCDIRS = $(SRCTREE)/board/$(VENDOR)/$(BOARD)/dts DTS_INCDIRS += $(SRCTREE)/board/$(VENDOR)/dts DTS_INCDIRS += $(SRCTREE)/arch/$(ARCH)/dts @@ -28,9 +22,15 @@ DTC_FLAGS := -R 4 -p 0x1000 \ # the filename. DT_BIN := $(obj)/dt.dtb +DEVICE_TREE ?= $(CONFIG_DEFAULT_DEVICE_TREE:"%"=%) +ifeq ($(DEVICE_TREE),) +$(DT_BIN): FORCE + echo >&2 "Please define CONFIG_DEFAULT_DEVICE_TREE in your board header file" +else $(DT_BIN): $(TOPDIR)/board/$(VENDOR)/dts/$(DEVICE_TREE).dts $(CPP) $(DTS_CPPFLAGS) $< -o $(DT_BIN).dts.tmp $(DTC) $(DTC_FLAGS) -O dtb -o ${DT_BIN} $(DT_BIN).dts.tmp +endif process_lds = \ $(1) | sed -r -n 's/^OUTPUT_$(2)[ ("]*([^")]*).*/\1/p' -- cgit v1.1 From 6ab6b2afa091dbceb37719b8a81637a00834be19 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 5 Feb 2014 11:28:25 +0900 Subject: dts: re-write dts/Makefile more simply with Kbuild Useful rules in scripts/Makefile.lib allows us to easily generate a device tree blob and wrap it in assembly code. We do not need to parse a linker script to get output format and arch. This commit deletes ./u-boot.dtb since it is a copy of dts/dt.dtb. Signed-off-by: Masahiro Yamada --- dts/.gitignore | 2 ++ dts/Makefile | 72 ++++++++++++++++------------------------------------------ 2 files changed, 22 insertions(+), 52 deletions(-) create mode 100644 dts/.gitignore (limited to 'dts') diff --git a/dts/.gitignore b/dts/.gitignore new file mode 100644 index 0000000..1b37180 --- /dev/null +++ b/dts/.gitignore @@ -0,0 +1,2 @@ +*.dtb +*.dtb.S diff --git a/dts/Makefile b/dts/Makefile index 1e7609a..c47fba7 100644 --- a/dts/Makefile +++ b/dts/Makefile @@ -7,64 +7,32 @@ # This Makefile builds the internal U-Boot fdt if CONFIG_OF_CONTROL is # enabled. See doc/README.fdt-control for more details. -DTS_INCDIRS = $(SRCTREE)/board/$(VENDOR)/$(BOARD)/dts -DTS_INCDIRS += $(SRCTREE)/board/$(VENDOR)/dts -DTS_INCDIRS += $(SRCTREE)/arch/$(ARCH)/dts +DEVICE_TREE ?= $(CONFIG_DEFAULT_DEVICE_TREE:"%"=%) +ifeq ($(DEVICE_TREE),) +DEVICE_TREE := notfound +endif -DTS_CPPFLAGS := -x assembler-with-cpp -undef -D__DTS__ \ - -nostdinc $(addprefix -I,$(DTS_INCDIRS)) +DTS := $(srctree)/board/$(VENDOR)/dts/$(DEVICE_TREE).dts -DTC_FLAGS := -R 4 -p 0x1000 \ - $(addprefix -i ,$(DTS_INCDIRS)) +DTC_FLAGS += -i $(srctree)/arch/$(ARCH)/dts -R 4 -p 0x1000 -# Use a constant name for this so we can access it from C code. -# objcopy doesn't seem to allow us to set the symbol name independently of -# the filename. -DT_BIN := $(obj)/dt.dtb +$(obj)/dt.dtb: $(DTS) FORCE + $(call if_changed_dep,dtc) -DEVICE_TREE ?= $(CONFIG_DEFAULT_DEVICE_TREE:"%"=%) -ifeq ($(DEVICE_TREE),) -$(DT_BIN): FORCE - echo >&2 "Please define CONFIG_DEFAULT_DEVICE_TREE in your board header file" -else -$(DT_BIN): $(TOPDIR)/board/$(VENDOR)/dts/$(DEVICE_TREE).dts - $(CPP) $(DTS_CPPFLAGS) $< -o $(DT_BIN).dts.tmp - $(DTC) $(DTC_FLAGS) -O dtb -o ${DT_BIN} $(DT_BIN).dts.tmp -endif +targets += dt.dtb -process_lds = \ - $(1) | sed -r -n 's/^OUTPUT_$(2)[ ("]*([^")]*).*/\1/p' +$(DTS): + @echo >&2 + @echo >&2 "Device Tree Source is not specified." + @echo >&2 "Please define 'CONFIG_DEFAULT_DEVICE_TREE'" + @echo >&2 "or build with 'DEVICE_TREE=' argument" + @/bin/false -# Run the compiler and get the link script from the linker -GET_LDS = $(CC) $(c_flags) $(ld_flags) -Wl,--verbose 2>&1 +.SECONDARY: $(obj)/dt.dtb.S -$(obj)/dt.o: $(DT_BIN) - # We want the output format and arch. - # We also hope to win a prize for ugliest Makefile / shell interaction - # We look in the LDSCRIPT first. - # Then try the linker which should give us the answer. - # Then check it worked. - [ -n "$(LDSCRIPT)" ] && \ - oformat=`$(call process_lds,cat $(LDSCRIPT),FORMAT)` && \ - oarch=`$(call process_lds,cat $(LDSCRIPT),ARCH)` ;\ - \ - [ -z $${oformat} ] && \ - oformat=`$(call process_lds,$(GET_LDS),FORMAT)` ;\ - [ -z $${oarch} ] && \ - oarch=`$(call process_lds,$(GET_LDS),ARCH)` ;\ - \ - [ -z $${oformat} ] && \ - echo "Cannot read OUTPUT_FORMAT from lds file $(LDSCRIPT)" && \ - exit 1 || true ;\ - [ -z $${oarch} ] && \ - echo "Cannot read OUTPUT_ARCH from lds file $(LDSCRIPT)" && \ - exit 1 || true ;\ - \ - cd $(dir ${DT_BIN}) && \ - $(OBJCOPY) -I binary -O $${oformat} -B $${oarch} \ - $(notdir ${DT_BIN}) $(notdir $@) - rm $(DT_BIN) +obj-$(CONFIG_OF_EMBED) := dt.dtb.o -obj-$(CONFIG_OF_EMBED) := dt.o +dtbs: $(obj)/dt.dtb + @: -binary: $(DT_BIN) +clean-files := dt.dtb.S -- cgit v1.1 From 5ab502cb8900aee483dfba28700640672e0b060e Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 5 Feb 2014 11:28:26 +0900 Subject: dts: move device tree sources to arch/$(ARCH)/dts/ Unlike Linux Kernel, U-Boot historically had *.dts files under board/$(VENDOR)/dts/ and *.dtsi files under arch/$(ARCH)/dts/. I think arch/$(ARCH)/dts dicretory is a better location to store both *.dts and *.dtsi files. For example, before this commit, board/xilinx/dts directory had both Microblaze dts (microblaze-generic.dts) and ARM dts (zynq-*.dts), which are totally unrelated. This commit moves *.dts to arch/$(ARCH)/dts/ directories, allowing us to describe nicely mutiple DTBs generation in the next commit. Signed-off-by: Masahiro Yamada --- dts/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'dts') diff --git a/dts/Makefile b/dts/Makefile index c47fba7..5d2abd9 100644 --- a/dts/Makefile +++ b/dts/Makefile @@ -12,9 +12,9 @@ ifeq ($(DEVICE_TREE),) DEVICE_TREE := notfound endif -DTS := $(srctree)/board/$(VENDOR)/dts/$(DEVICE_TREE).dts +DTS := $(srctree)/arch/$(ARCH)/dts/$(DEVICE_TREE).dts -DTC_FLAGS += -i $(srctree)/arch/$(ARCH)/dts -R 4 -p 0x1000 +DTC_FLAGS += -R 4 -p 0x1000 $(obj)/dt.dtb: $(DTS) FORCE $(call if_changed_dep,dtc) -- cgit v1.1 From 3284c8b8cad9452bf0711f52699bc9a5aeb83319 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 5 Feb 2014 11:28:27 +0900 Subject: dts: generate multiple device tree blobs It is convenient to have all device trees on the same SoC compiled. It allows for later easy repackaging without the need to re-run the make file. - Build device trees with the same SoC under arch/$(ARCH)/dts - Copy the one specified by CONFIG_DEFAULT_DEVICE_TREE or DEVICE_TREE=... to dts/dt.dtb Signed-off-by: Masahiro Yamada --- dts/Makefile | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'dts') diff --git a/dts/Makefile b/dts/Makefile index 5d2abd9..9907463 100644 --- a/dts/Makefile +++ b/dts/Makefile @@ -9,24 +9,30 @@ DEVICE_TREE ?= $(CONFIG_DEFAULT_DEVICE_TREE:"%"=%) ifeq ($(DEVICE_TREE),) -DEVICE_TREE := notfound +DEVICE_TREE := unset endif -DTS := $(srctree)/arch/$(ARCH)/dts/$(DEVICE_TREE).dts +DTB := arch/$(ARCH)/dts/$(DEVICE_TREE).dtb -DTC_FLAGS += -R 4 -p 0x1000 +quiet_cmd_copy = COPY $@ + cmd_copy = cp $< $@ -$(obj)/dt.dtb: $(DTS) FORCE - $(call if_changed_dep,dtc) +$(obj)/dt.dtb: $(DTB) FORCE + $(call if_changed,copy) targets += dt.dtb -$(DTS): - @echo >&2 - @echo >&2 "Device Tree Source is not specified." - @echo >&2 "Please define 'CONFIG_DEFAULT_DEVICE_TREE'" - @echo >&2 "or build with 'DEVICE_TREE=' argument" - @/bin/false +$(DTB): arch-dtbs + $(Q)test -e $@ || ( \ + echo >&2; \ + echo >&2 "Device Tree Source is not correctly specified."; \ + echo >&2 "Please define 'CONFIG_DEFAULT_DEVICE_TREE'"; \ + echo >&2 "or build with 'DEVICE_TREE=' argument"; \ + echo >&2; \ + /bin/false) + +arch-dtbs: + $(Q)$(MAKE) $(build)=arch/$(ARCH)/dts dtbs .SECONDARY: $(obj)/dt.dtb.S @@ -36,3 +42,6 @@ dtbs: $(obj)/dt.dtb @: clean-files := dt.dtb.S + +# Let clean descend into dts directories +subdir- += ../arch/*/dts -- cgit v1.1