diff --git a/libfdt/Makefile b/libfdt/Makefile
index 126fa2c02f7a8f5b7d4df4479bf767f1eac47154..d166cce7968feb9ba45a01dd166176e4771fbb05 100644
--- a/libfdt/Makefile
+++ b/libfdt/Makefile
@@ -27,7 +27,7 @@ LIB	= $(obj)libfdt.a
 
 SOBJS	=
 
-COBJS-y += fdt.o fdt_ro.o fdt_rw.o fdt_strerror.o fdt_sw.o fdt_wip.o
+COBJS-$(CONFIG_OF_LIBFDT) += fdt.o fdt_ro.o fdt_rw.o fdt_strerror.o fdt_sw.o fdt_wip.o
 
 COBJS	:= $(COBJS-y)
 SRCS 	:= $(SOBJS:.o=.S) $(COBJS:.o=.c)
diff --git a/libfdt/fdt.c b/libfdt/fdt.c
index 1ee67ad19cd8ba118bf5d1c85f4c5f2f1ac75b41..212b83838c6ebba4289d0610d78ba838a5914e30 100644
--- a/libfdt/fdt.c
+++ b/libfdt/fdt.c
@@ -16,9 +16,6 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
-#include "config.h"
-#if CONFIG_OF_LIBFDT
-
 #include "libfdt_env.h"
 
 #include <fdt.h>
@@ -86,5 +83,3 @@ int fdt_move(const void *fdt, void *buf, int bufsize)
 	memmove(buf, fdt, fdt_totalsize(fdt));
 	return 0;
 }
-
-#endif /* CONFIG_OF_LIBFDT */
diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c
index 46d525db1453ad29caad64890039008a373754af..bc1a5f4240e8d6a4540c2a04641dc1179122d3ee 100644
--- a/libfdt/fdt_ro.c
+++ b/libfdt/fdt_ro.c
@@ -16,9 +16,6 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
-#include "config.h"
-#if CONFIG_OF_LIBFDT
-
 #include "libfdt_env.h"
 
 #include <fdt.h>
@@ -532,5 +529,3 @@ int fdt_get_reservemap(void *fdt, int n, struct fdt_reserve_entry *re)
 	}
 	return 0;
 }
-
-#endif /* CONFIG_OF_LIBFDT */
diff --git a/libfdt/fdt_rw.c b/libfdt/fdt_rw.c
index 55fcc41d1a2abd2852878b9d9760d17a57998799..852b6e6a9abd0e3482e1de97c8abb0f2b620f191 100644
--- a/libfdt/fdt_rw.c
+++ b/libfdt/fdt_rw.c
@@ -16,9 +16,6 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
-#include "config.h"
-#if CONFIG_OF_LIBFDT
-
 #include "libfdt_env.h"
 
 #include <fdt.h>
@@ -320,5 +317,3 @@ int fdt_pack(void *fdt)
 	fdt_set_header(fdt, totalsize, _blob_data_size(fdt));
 	return 0;
 }
-
-#endif /* CONFIG_OF_LIBFDT */
diff --git a/libfdt/fdt_strerror.c b/libfdt/fdt_strerror.c
index b49c952f346023d4e5441f39c7f2b51ed394f995..7f231ce460e79faab020e6337f86be137da306af 100644
--- a/libfdt/fdt_strerror.c
+++ b/libfdt/fdt_strerror.c
@@ -16,9 +16,6 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
-#include "config.h"
-#if CONFIG_OF_LIBFDT
-
 #include "libfdt_env.h"
 
 #include <fdt.h>
@@ -65,5 +62,3 @@ const char *fdt_strerror(int errval)
 
 	return "<unknown error>";
 }
-
-#endif /* CONFIG_OF_LIBFDT */
diff --git a/libfdt/fdt_sw.c b/libfdt/fdt_sw.c
index c7eea8ff39e524139df44154645509d9de0693a6..672f4ddd9474255398f23080ceec3d16989b0578 100644
--- a/libfdt/fdt_sw.c
+++ b/libfdt/fdt_sw.c
@@ -16,9 +16,6 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
-#include "config.h"
-#if CONFIG_OF_LIBFDT
-
 #include "libfdt_env.h"
 
 #include <fdt.h>
@@ -227,5 +224,3 @@ int fdt_finish(void *fdt)
 	fdt_set_header(fdt, magic, FDT_MAGIC);
 	return 0;
 }
-
-#endif /* CONFIG_OF_LIBFDT */
diff --git a/libfdt/fdt_wip.c b/libfdt/fdt_wip.c
index 2d39aabe1fe9872c2a9e5e441979426244e063fd..2d2ed37c477787cc66625d5248bbd5eddc08ea2b 100644
--- a/libfdt/fdt_wip.c
+++ b/libfdt/fdt_wip.c
@@ -16,9 +16,6 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
-#include "config.h"
-#if CONFIG_OF_LIBFDT
-
 #include "libfdt_env.h"
 
 #include <fdt.h>
@@ -138,5 +135,3 @@ int fdt_replace_reservemap_entry(void *fdt, int n, uint64_t addr, uint64_t size)
 
 	return 0;
 }
-
-#endif /* CONFIG_OF_LIBFDT */