From 9fffb55f66127b52c937ede5196ebfa0c0d50bce Mon Sep 17 00:00:00 2001 From: David Gibson Date: Thu, 30 Apr 2009 15:25:53 +1000 Subject: [PATCH] Move dtc and libfdt sources from arch/powerpc/boot to scripts/dtc The powerpc kernel always requires an Open Firmware like device tree to supply device information. On systems without OF, this comes from a flattened device tree blob. This blob is usually generated by dtc, a tool which compiles a text description of the device tree into the flattened format used by the kernel. Sometimes, the bootwrapper makes small changes to the pre-compiled device tree blob (e.g. filling in the size of RAM). To do this it uses the libfdt library. Because these are only used on powerpc, the code for both these tools is included under arch/powerpc/boot (these were imported and are periodically updated from the upstream dtc tree). However, the microblaze architecture, currently being prepared for merging to mainline also uses dtc to produce device tree blobs. A few other archs have also mentioned some interest in using dtc. Therefore, this patch moves dtc and libfdt from arch/powerpc into scripts, where it can be used by any architecture. The vast bulk of this patch is a literal move, the rest is adjusting the various Makefiles to use dtc and libfdt correctly from their new locations. Signed-off-by: David Gibson Signed-off-by: Linus Torvalds --- arch/powerpc/Kconfig | 4 ++ arch/powerpc/boot/Makefile | 67 +++++++------------ arch/powerpc/boot/simpleboot.c | 2 +- scripts/Makefile | 1 + scripts/dtc/Makefile | 54 +++++++++++++++ .../boot/dtc-src => scripts/dtc}/Makefile.dtc | 0 .../boot/dtc-src => scripts/dtc}/checks.c | 0 .../boot/dtc-src => scripts/dtc}/data.c | 0 .../boot/dtc-src => scripts/dtc}/dtc-lexer.l | 0 .../dtc}/dtc-lexer.lex.c_shipped | 0 .../dtc}/dtc-parser.tab.c_shipped | 0 .../dtc}/dtc-parser.tab.h_shipped | 0 .../boot/dtc-src => scripts/dtc}/dtc-parser.y | 0 .../boot/dtc-src => scripts/dtc}/dtc.c | 0 .../boot/dtc-src => scripts/dtc}/dtc.h | 0 .../boot/dtc-src => scripts/dtc}/flattree.c | 0 .../boot/dtc-src => scripts/dtc}/fstree.c | 0 .../dtc}/libfdt/Makefile.libfdt | 0 .../powerpc/boot => scripts/dtc}/libfdt/fdt.c | 0 .../powerpc/boot => scripts/dtc}/libfdt/fdt.h | 0 .../boot => scripts/dtc}/libfdt/fdt_ro.c | 0 .../boot => scripts/dtc}/libfdt/fdt_rw.c | 0 .../dtc}/libfdt/fdt_strerror.c | 0 .../boot => scripts/dtc}/libfdt/fdt_sw.c | 0 .../boot => scripts/dtc}/libfdt/fdt_wip.c | 0 .../boot => scripts/dtc}/libfdt/libfdt.h | 0 .../dtc/libfdt}/libfdt_env.h | 0 .../dtc}/libfdt/libfdt_internal.h | 0 .../boot/dtc-src => scripts/dtc}/livetree.c | 0 .../boot/dtc-src => scripts/dtc}/srcpos.c | 0 .../boot/dtc-src => scripts/dtc}/srcpos.h | 0 .../boot/dtc-src => scripts/dtc}/treesource.c | 0 .../dtc-src => scripts/dtc}/version_gen.h | 0 33 files changed, 83 insertions(+), 45 deletions(-) create mode 100644 scripts/dtc/Makefile rename {arch/powerpc/boot/dtc-src => scripts/dtc}/Makefile.dtc (100%) rename {arch/powerpc/boot/dtc-src => scripts/dtc}/checks.c (100%) rename {arch/powerpc/boot/dtc-src => scripts/dtc}/data.c (100%) rename {arch/powerpc/boot/dtc-src => scripts/dtc}/dtc-lexer.l (100%) rename {arch/powerpc/boot/dtc-src => scripts/dtc}/dtc-lexer.lex.c_shipped (100%) rename {arch/powerpc/boot/dtc-src => scripts/dtc}/dtc-parser.tab.c_shipped (100%) rename {arch/powerpc/boot/dtc-src => scripts/dtc}/dtc-parser.tab.h_shipped (100%) rename {arch/powerpc/boot/dtc-src => scripts/dtc}/dtc-parser.y (100%) rename {arch/powerpc/boot/dtc-src => scripts/dtc}/dtc.c (100%) rename {arch/powerpc/boot/dtc-src => scripts/dtc}/dtc.h (100%) rename {arch/powerpc/boot/dtc-src => scripts/dtc}/flattree.c (100%) rename {arch/powerpc/boot/dtc-src => scripts/dtc}/fstree.c (100%) rename {arch/powerpc/boot => scripts/dtc}/libfdt/Makefile.libfdt (100%) rename {arch/powerpc/boot => scripts/dtc}/libfdt/fdt.c (100%) rename {arch/powerpc/boot => scripts/dtc}/libfdt/fdt.h (100%) rename {arch/powerpc/boot => scripts/dtc}/libfdt/fdt_ro.c (100%) rename {arch/powerpc/boot => scripts/dtc}/libfdt/fdt_rw.c (100%) rename {arch/powerpc/boot => scripts/dtc}/libfdt/fdt_strerror.c (100%) rename {arch/powerpc/boot => scripts/dtc}/libfdt/fdt_sw.c (100%) rename {arch/powerpc/boot => scripts/dtc}/libfdt/fdt_wip.c (100%) rename {arch/powerpc/boot => scripts/dtc}/libfdt/libfdt.h (100%) rename {arch/powerpc/boot/dtc-src => scripts/dtc/libfdt}/libfdt_env.h (100%) rename {arch/powerpc/boot => scripts/dtc}/libfdt/libfdt_internal.h (100%) rename {arch/powerpc/boot/dtc-src => scripts/dtc}/livetree.c (100%) rename {arch/powerpc/boot/dtc-src => scripts/dtc}/srcpos.c (100%) rename {arch/powerpc/boot/dtc-src => scripts/dtc}/srcpos.h (100%) rename {arch/powerpc/boot/dtc-src => scripts/dtc}/treesource.c (100%) rename {arch/powerpc/boot/dtc-src => scripts/dtc}/version_gen.h (100%) diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index 4c7804551362..a0d1146a0578 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -181,6 +181,10 @@ config SYS_SUPPORTS_APM_EMULATION default y if PMAC_APM_EMU bool +config DTC + bool + default y + config DEFAULT_UIMAGE bool help diff --git a/arch/powerpc/boot/Makefile b/arch/powerpc/boot/Makefile index 4458abb67c51..8da2bf963b57 100644 --- a/arch/powerpc/boot/Makefile +++ b/arch/powerpc/boot/Makefile @@ -33,7 +33,7 @@ ifeq ($(call cc-option-yn, -fstack-protector),y) BOOTCFLAGS += -fno-stack-protector endif -BOOTCFLAGS += -I$(obj) -I$(srctree)/$(obj) -I$(srctree)/$(src)/libfdt +BOOTCFLAGS += -I$(obj) -I$(srctree)/$(obj) DTS_FLAGS ?= -p 1024 @@ -53,9 +53,14 @@ zliblinuxheader := zlib.h zconf.h zutil.h $(addprefix $(obj)/,$(zlib) cuboot-c2k.o gunzip_util.o main.o prpmc2800.o): \ $(addprefix $(obj)/,$(zliblinuxheader)) $(addprefix $(obj)/,$(zlibheader)) -src-libfdt := fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c +libfdt := fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c +libfdtheader := fdt.h libfdt.h libfdt_internal.h + +$(addprefix $(obj)/,$(libfdt) libfdt-wrapper.o simpleboot.o): \ + $(addprefix $(obj)/,$(libfdtheader)) + src-wlib := string.S crt0.S crtsavres.S stdio.c main.c \ - $(addprefix libfdt/,$(src-libfdt)) libfdt-wrapper.c \ + $(libfdt) libfdt-wrapper.c \ ns16550.c serial.c simple_alloc.c div64.S util.S \ gunzip_util.c elf_util.c $(zlib) devtree.c oflib.c ofconsole.c \ 4xx.c ebony.c mv64x60.c mpsc.c mv64x60_i2c.c cuboot.c bamboo.c \ @@ -96,6 +101,12 @@ $(addprefix $(obj)/,$(zlibheader)): $(obj)/%: $(srctree)/lib/zlib_inflate/% $(addprefix $(obj)/,$(zliblinuxheader)): $(obj)/%: $(srctree)/include/linux/% $(call cmd,copy_zliblinuxheader) +quiet_cmd_copy_libfdt = COPY $@ + cmd_copy_libfdt = cp $< $@ + +$(addprefix $(obj)/,$(libfdt) $(libfdtheader)): $(obj)/%: $(srctree)/scripts/dtc/libfdt/% + $(call cmd,copy_libfdt) + $(obj)/empty.c: @touch $@ @@ -103,6 +114,7 @@ $(obj)/zImage.lds $(obj)/zImage.coff.lds $(obj)/zImage.ps3.lds: $(obj)/%: $(srct @cp $< $@ clean-files := $(zlib) $(zlibheader) $(zliblinuxheader) \ + $(libfdt) $(libfdtheader) \ empty.c zImage.coff.lds zImage.ps3.lds zImage.lds quiet_cmd_bootcc = BOOTCC $@ @@ -114,6 +126,8 @@ quiet_cmd_bootas = BOOTAS $@ quiet_cmd_bootar = BOOTAR $@ cmd_bootar = $(CROSS32AR) -cr $@.$$$$ $(filter-out FORCE,$^); mv $@.$$$$ $@ +$(obj-libfdt): $(obj)/%.o: $(srctree)/scripts/dtc/libfdt/%.c FORCE + $(call if_changed_dep,bootcc) $(patsubst %.c,%.o, $(filter %.c, $(src-boot))): %.o: %.c FORCE $(Q)mkdir -p $(dir $@) $(call if_changed_dep,bootcc) @@ -124,7 +138,7 @@ $(patsubst %.S,%.o, $(filter %.S, $(src-boot))): %.o: %.S FORCE $(obj)/wrapper.a: $(obj-wlib) FORCE $(call if_changed,bootar) -hostprogs-y := addnote addRamDisk hack-coff mktree dtc +hostprogs-y := addnote addRamDisk hack-coff mktree targets += $(patsubst $(obj)/%,%,$(obj-boot) wrapper.a) extra-y := $(obj)/wrapper.a $(obj-plat) $(obj)/empty.o \ @@ -133,46 +147,9 @@ extra-y := $(obj)/wrapper.a $(obj-plat) $(obj)/empty.o \ dtstree := $(srctree)/$(src)/dts wrapper :=$(srctree)/$(src)/wrapper -wrapperbits := $(extra-y) $(addprefix $(obj)/,addnote hack-coff mktree dtc) \ +wrapperbits := $(extra-y) $(addprefix $(obj)/,addnote hack-coff mktree) \ $(wrapper) FORCE -############# -# Bits for building dtc -# DTC_GENPARSER := 1 # Uncomment to rebuild flex/bison output - -dtc-objs := dtc.o flattree.o fstree.o data.o livetree.o treesource.o srcpos.o checks.o -dtc-objs += dtc-lexer.lex.o dtc-parser.tab.o -dtc-objs := $(addprefix dtc-src/, $(dtc-objs)) - -# prerequisites on generated files needs to be explicit -$(obj)/dtc-src/dtc-parser.tab.o: $(obj)/dtc-src/dtc-parser.tab.c $(obj)/dtc-src/dtc-parser.tab.h -$(obj)/dtc-src/dtc-lexer.lex.o: $(obj)/dtc-src/dtc-lexer.lex.c $(obj)/dtc-src/dtc-parser.tab.h - -HOSTCFLAGS += -I$(src)/dtc-src/ -I$(src)/libfdt/ - -targets += dtc-src/dtc-parser.tab.c -targets += dtc-src/dtc-lexer.lex.c - -clean-files += dtc-src/dtc-parser.tab.h - -ifdef DTC_GENPARSER -BISON = bison -FLEX = flex - -quiet_cmd_bison = BISON $@ - cmd_bison = $(BISON) -o$@ -d $<; cp $@ $@_shipped -quiet_cmd_flex = FLEX $@ - cmd_flex = $(FLEX) -o$@ $<; cp $@ $@_shipped - -$(obj)/dtc-src/dtc-parser.tab.c: $(src)/dtc-src/dtc-parser.y FORCE - $(call if_changed,bison) - -$(obj)/dtc-src/dtc-parser.tab.h: $(obj)/dtc-src/dtc-parser.tab.c - -$(obj)/dtc-src/dtc-lexer.lex.c: $(src)/dtc-src/dtc-lexer.l FORCE - $(call if_changed,flex) -endif - ############# # Bits for building various flavours of zImage @@ -347,8 +324,10 @@ $(obj)/treeImage.%: vmlinux $(obj)/%.dtb $(wrapperbits) $(call if_changed,wrap,treeboot-$*,,$(obj)/$*.dtb) # Rule to build device tree blobs -$(obj)/%.dtb: $(dtstree)/%.dts $(obj)/dtc - $(obj)/dtc -O dtb -o $(obj)/$*.dtb -b 0 $(DTS_FLAGS) $(dtstree)/$*.dts +DTC = $(objtree)/scripts/dtc/dtc + +$(obj)/%.dtb: $(dtstree)/%.dts + $(DTC) -O dtb -o $(obj)/$*.dtb -b 0 $(DTS_FLAGS) $(dtstree)/$*.dts # If there isn't a platform selected then just strip the vmlinux. ifeq (,$(image-y)) diff --git a/arch/powerpc/boot/simpleboot.c b/arch/powerpc/boot/simpleboot.c index c58a0dada992..21cd48074ec8 100644 --- a/arch/powerpc/boot/simpleboot.c +++ b/arch/powerpc/boot/simpleboot.c @@ -19,7 +19,7 @@ #include "types.h" #include "io.h" #include "stdio.h" -#include "libfdt/libfdt.h" +#include BSS_STACK(4*1024); diff --git a/scripts/Makefile b/scripts/Makefile index aafdf064feef..9dd5b25a1d53 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -21,6 +21,7 @@ hostprogs-y += unifdef subdir-$(CONFIG_MODVERSIONS) += genksyms subdir-y += mod subdir-$(CONFIG_SECURITY_SELINUX) += selinux +subdir-$(CONFIG_DTC) += dtc # Let clean descend into subdirs subdir- += basic kconfig package selinux diff --git a/scripts/dtc/Makefile b/scripts/dtc/Makefile new file mode 100644 index 000000000000..01cdb36fc583 --- /dev/null +++ b/scripts/dtc/Makefile @@ -0,0 +1,54 @@ +# scripts/dtc makefile + +hostprogs-y := dtc +always := $(hostprogs-y) + +dtc-objs := dtc.o flattree.o fstree.o data.o livetree.o treesource.o \ + srcpos.o checks.o +dtc-objs += dtc-lexer.lex.o dtc-parser.tab.o + +# Source files need to get at the userspace version of libfdt_env.h to compile + +HOSTCFLAGS_DTC := -I$(src) -I$(src)/libfdt + +HOSTCFLAGS_checks.o := $(HOSTCFLAGS_DTC) +HOSTCFLAGS_data.o := $(HOSTCFLAGS_DTC) +HOSTCFLAGS_dtc.o := $(HOSTCFLAGS_DTC) +HOSTCFLAGS_flattree.o := $(HOSTCFLAGS_DTC) +HOSTCFLAGS_fstree.o := $(HOSTCFLAGS_DTC) +HOSTCFLAGS_livetree.o := $(HOSTCFLAGS_DTC) +HOSTCFLAGS_srcpos.o := $(HOSTCFLAGS_DTC) +HOSTCFLAGS_treesource.o := $(HOSTCFLAGS_DTC) + +HOSTCFLAGS_dtc-lexer.lex.o := $(HOSTCFLAGS_DTC) +HOSTCFLAGS_dtc-parser.tab.o := $(HOSTCFLAGS_DTC) + +# dependencies on generated files need to be listed explicitly +$(obj)/dtc-parser.tab.o: $(obj)/dtc-parser.tab.c $(obj)/dtc-parser.tab.h +$(obj)/dtc-lexer.lex.o: $(obj)/dtc-lexer.lex.c $(obj)/dtc-parser.tab.h + +targets += dtc-parser.tab.c dtc-lexer.lex.c + +clean-files += dtc-parser.tab.h + +# GENERATE_PARSER := 1 # Uncomment to rebuild flex/bison output + +ifdef GENERATE_PARSER + +BISON = bison +FLEX = flex + +quiet_cmd_bison = BISON $@ + cmd_bison = $(BISON) -o$@ -d $<; cp $@ $@_shipped +quiet_cmd_flex = FLEX $@ + cmd_flex = $(FLEX) -o$@ $<; cp $@ $@_shipped + +$(obj)/dtc-parser.tab.c: $(src)/dtc-parser.y FORCE + $(call if_changed,bison) + +$(obj)/dtc-parser.tab.h: $(obj)/dtc-parser.tab.c + +$(obj)/dtc-lexer.lex.c: $(src)/dtc-lexer.l FORCE + $(call if_changed,flex) + +endif diff --git a/arch/powerpc/boot/dtc-src/Makefile.dtc b/scripts/dtc/Makefile.dtc similarity index 100% rename from arch/powerpc/boot/dtc-src/Makefile.dtc rename to scripts/dtc/Makefile.dtc diff --git a/arch/powerpc/boot/dtc-src/checks.c b/scripts/dtc/checks.c similarity index 100% rename from arch/powerpc/boot/dtc-src/checks.c rename to scripts/dtc/checks.c diff --git a/arch/powerpc/boot/dtc-src/data.c b/scripts/dtc/data.c similarity index 100% rename from arch/powerpc/boot/dtc-src/data.c rename to scripts/dtc/data.c diff --git a/arch/powerpc/boot/dtc-src/dtc-lexer.l b/scripts/dtc/dtc-lexer.l similarity index 100% rename from arch/powerpc/boot/dtc-src/dtc-lexer.l rename to scripts/dtc/dtc-lexer.l diff --git a/arch/powerpc/boot/dtc-src/dtc-lexer.lex.c_shipped b/scripts/dtc/dtc-lexer.lex.c_shipped similarity index 100% rename from arch/powerpc/boot/dtc-src/dtc-lexer.lex.c_shipped rename to scripts/dtc/dtc-lexer.lex.c_shipped diff --git a/arch/powerpc/boot/dtc-src/dtc-parser.tab.c_shipped b/scripts/dtc/dtc-parser.tab.c_shipped similarity index 100% rename from arch/powerpc/boot/dtc-src/dtc-parser.tab.c_shipped rename to scripts/dtc/dtc-parser.tab.c_shipped diff --git a/arch/powerpc/boot/dtc-src/dtc-parser.tab.h_shipped b/scripts/dtc/dtc-parser.tab.h_shipped similarity index 100% rename from arch/powerpc/boot/dtc-src/dtc-parser.tab.h_shipped rename to scripts/dtc/dtc-parser.tab.h_shipped diff --git a/arch/powerpc/boot/dtc-src/dtc-parser.y b/scripts/dtc/dtc-parser.y similarity index 100% rename from arch/powerpc/boot/dtc-src/dtc-parser.y rename to scripts/dtc/dtc-parser.y diff --git a/arch/powerpc/boot/dtc-src/dtc.c b/scripts/dtc/dtc.c similarity index 100% rename from arch/powerpc/boot/dtc-src/dtc.c rename to scripts/dtc/dtc.c diff --git a/arch/powerpc/boot/dtc-src/dtc.h b/scripts/dtc/dtc.h similarity index 100% rename from arch/powerpc/boot/dtc-src/dtc.h rename to scripts/dtc/dtc.h diff --git a/arch/powerpc/boot/dtc-src/flattree.c b/scripts/dtc/flattree.c similarity index 100% rename from arch/powerpc/boot/dtc-src/flattree.c rename to scripts/dtc/flattree.c diff --git a/arch/powerpc/boot/dtc-src/fstree.c b/scripts/dtc/fstree.c similarity index 100% rename from arch/powerpc/boot/dtc-src/fstree.c rename to scripts/dtc/fstree.c diff --git a/arch/powerpc/boot/libfdt/Makefile.libfdt b/scripts/dtc/libfdt/Makefile.libfdt similarity index 100% rename from arch/powerpc/boot/libfdt/Makefile.libfdt rename to scripts/dtc/libfdt/Makefile.libfdt diff --git a/arch/powerpc/boot/libfdt/fdt.c b/scripts/dtc/libfdt/fdt.c similarity index 100% rename from arch/powerpc/boot/libfdt/fdt.c rename to scripts/dtc/libfdt/fdt.c diff --git a/arch/powerpc/boot/libfdt/fdt.h b/scripts/dtc/libfdt/fdt.h similarity index 100% rename from arch/powerpc/boot/libfdt/fdt.h rename to scripts/dtc/libfdt/fdt.h diff --git a/arch/powerpc/boot/libfdt/fdt_ro.c b/scripts/dtc/libfdt/fdt_ro.c similarity index 100% rename from arch/powerpc/boot/libfdt/fdt_ro.c rename to scripts/dtc/libfdt/fdt_ro.c diff --git a/arch/powerpc/boot/libfdt/fdt_rw.c b/scripts/dtc/libfdt/fdt_rw.c similarity index 100% rename from arch/powerpc/boot/libfdt/fdt_rw.c rename to scripts/dtc/libfdt/fdt_rw.c diff --git a/arch/powerpc/boot/libfdt/fdt_strerror.c b/scripts/dtc/libfdt/fdt_strerror.c similarity index 100% rename from arch/powerpc/boot/libfdt/fdt_strerror.c rename to scripts/dtc/libfdt/fdt_strerror.c diff --git a/arch/powerpc/boot/libfdt/fdt_sw.c b/scripts/dtc/libfdt/fdt_sw.c similarity index 100% rename from arch/powerpc/boot/libfdt/fdt_sw.c rename to scripts/dtc/libfdt/fdt_sw.c diff --git a/arch/powerpc/boot/libfdt/fdt_wip.c b/scripts/dtc/libfdt/fdt_wip.c similarity index 100% rename from arch/powerpc/boot/libfdt/fdt_wip.c rename to scripts/dtc/libfdt/fdt_wip.c diff --git a/arch/powerpc/boot/libfdt/libfdt.h b/scripts/dtc/libfdt/libfdt.h similarity index 100% rename from arch/powerpc/boot/libfdt/libfdt.h rename to scripts/dtc/libfdt/libfdt.h diff --git a/arch/powerpc/boot/dtc-src/libfdt_env.h b/scripts/dtc/libfdt/libfdt_env.h similarity index 100% rename from arch/powerpc/boot/dtc-src/libfdt_env.h rename to scripts/dtc/libfdt/libfdt_env.h diff --git a/arch/powerpc/boot/libfdt/libfdt_internal.h b/scripts/dtc/libfdt/libfdt_internal.h similarity index 100% rename from arch/powerpc/boot/libfdt/libfdt_internal.h rename to scripts/dtc/libfdt/libfdt_internal.h diff --git a/arch/powerpc/boot/dtc-src/livetree.c b/scripts/dtc/livetree.c similarity index 100% rename from arch/powerpc/boot/dtc-src/livetree.c rename to scripts/dtc/livetree.c diff --git a/arch/powerpc/boot/dtc-src/srcpos.c b/scripts/dtc/srcpos.c similarity index 100% rename from arch/powerpc/boot/dtc-src/srcpos.c rename to scripts/dtc/srcpos.c diff --git a/arch/powerpc/boot/dtc-src/srcpos.h b/scripts/dtc/srcpos.h similarity index 100% rename from arch/powerpc/boot/dtc-src/srcpos.h rename to scripts/dtc/srcpos.h diff --git a/arch/powerpc/boot/dtc-src/treesource.c b/scripts/dtc/treesource.c similarity index 100% rename from arch/powerpc/boot/dtc-src/treesource.c rename to scripts/dtc/treesource.c diff --git a/arch/powerpc/boot/dtc-src/version_gen.h b/scripts/dtc/version_gen.h similarity index 100% rename from arch/powerpc/boot/dtc-src/version_gen.h rename to scripts/dtc/version_gen.h -- 2.30.2