diff mbox

Move dtc and libfdt sources from arch/powerpc/boot to scripts/dtc

Message ID 20090331044701.GD25418@yookeroo.seuss (mailing list archive)
State Changes Requested, archived
Delegated to: Paul Mackerras
Headers show

Commit Message

David Gibson March 31, 2009, 4:47 a.m. UTC
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 <david@gibson.dropbear.id.au>
---
 arch/powerpc/Kconfig                               |    4 +
 arch/powerpc/boot/Makefile                         |   67 +++++++-------------
 arch/powerpc/boot/simpleboot.c                     |    2 +-
 scripts/Makefile                                   |    1 +
 scripts/dtc/Makefile                               |   52 +++++++++++++++
 .../boot/dtc-src => scripts/dtc}/Makefile.dtc      |    0
 .../powerpc/boot/dtc-src => scripts/dtc}/checks.c  |    0
 {arch/powerpc/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
 {arch/powerpc/boot/dtc-src => scripts/dtc}/dtc.c   |    0
 {arch/powerpc/boot/dtc-src => scripts/dtc}/dtc.h   |    0
 .../boot/dtc-src => scripts/dtc}/flattree.c        |    0
 .../powerpc/boot/dtc-src => scripts/dtc}/fstree.c  |    0
 .../boot => scripts/dtc}/libfdt/Makefile.libfdt    |    0
 {arch/powerpc/boot => scripts/dtc}/libfdt/fdt.c    |    0
 {arch/powerpc/boot => scripts/dtc}/libfdt/fdt.h    |    0
 {arch/powerpc/boot => scripts/dtc}/libfdt/fdt_ro.c |    0
 {arch/powerpc/boot => scripts/dtc}/libfdt/fdt_rw.c |    0
 .../boot => scripts/dtc}/libfdt/fdt_strerror.c     |    0
 {arch/powerpc/boot => scripts/dtc}/libfdt/fdt_sw.c |    0
 .../powerpc/boot => scripts/dtc}/libfdt/fdt_wip.c  |    0
 {arch/powerpc/boot => scripts/dtc}/libfdt/libfdt.h |    0
 .../dtc-src => scripts/dtc/libfdt}/libfdt_env.h    |    0
 .../boot => scripts/dtc}/libfdt/libfdt_internal.h  |    0
 .../boot/dtc-src => scripts/dtc}/livetree.c        |    0
 .../powerpc/boot/dtc-src => scripts/dtc}/srcpos.c  |    0
 .../powerpc/boot/dtc-src => scripts/dtc}/srcpos.h  |    0
 .../boot/dtc-src => scripts/dtc}/treesource.c      |    0
 .../boot/dtc-src => scripts/dtc}/version_gen.h     |    0
 33 files changed, 81 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/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

Comments

Paul Mackerras April 7, 2009, 5:17 a.m. UTC | #1
David Gibson writes:

> 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.

Did you test this with a separate object directory?  I get:

$ make O=../test-64k V=1
[snip]
  gcc -Wp,-MD,scripts/dtc/.dtc-lexer.lex.o.d -Iscripts/dtc -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer  -I/home/paulus/kernel/powerpc/scripts/dtc/libfdt -Iscripts/dtc/libfdt -c -o scripts/dtc/dtc-lexer.lex.o scripts/dtc/dtc-lexer.lex.c
dtc-lexer.l:37:17: error: dtc.h: No such file or directory
dtc-lexer.l:38:20: error: srcpos.h: No such file or directory
In file included from dtc-lexer.l:39:
dtc-parser.y:42: error: expected specifier-qualifier-list before ,F!uint8_t,F"

followed by lots more errors.

Paul.
David Gibson April 21, 2009, 5:17 a.m. UTC | #2
On Tue, Apr 07, 2009 at 03:17:29PM +1000, Paul Mackerras wrote:
> David Gibson writes:
> 
> > 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.
> 
> Did you test this with a separate object directory?  I get:

Ugh.  Obviously not.  New patch coming.
diff mbox

Patch

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index ad6b1c0..c881d69 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 4458abb..8da2bf9 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,47 +147,10 @@  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
 
 ifneq ($(CROSS32_COMPILE),)
@@ -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 c58a0da..21cd480 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 <libfdt.h>
 
 BSS_STACK(4*1024);
 
diff --git a/scripts/Makefile b/scripts/Makefile
index 035182e..1a807ed 100644
--- a/scripts/Makefile
+++ b/scripts/Makefile
@@ -22,6 +22,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 0000000..c178428
--- /dev/null
+++ b/scripts/dtc/Makefile
@@ -0,0 +1,52 @@ 
+# 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_checks.o := -I$(src)/libfdt
+HOSTCFLAGS_data.o := -I$(src)/libfdt
+HOSTCFLAGS_dtc.o := -I$(src)/libfdt
+HOSTCFLAGS_flattree.o := -I$(src)/libfdt
+HOSTCFLAGS_fstree.o := -I$(src)/libfdt
+HOSTCFLAGS_livetree.o := -I$(src)/libfdt
+HOSTCFLAGS_srcpos.o := -I$(src)/libfdt
+HOSTCFLAGS_treesource.o := -I$(src)/libfdt
+
+HOSTCFLAGS_dtc-lexer.lex.o := -I$(src)/libfdt
+HOSTCFLAGS_dtc-parser.tab.o := -I$(src)/libfdt
+
+# 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