Minor libfdt changes to enable TF integration

* Move libfdt API headers to include/lib/libfdt
* Add libfdt.mk helper makefile
* Remove unused libfdt files
* Minor changes to fdt.h and libfdt.h to make them C99 compliant

Co-Authored-By: Jens Wiklander <jens.wiklander@linaro.org>

Change-Id: I425842c2b111dcd5fb6908cc698064de4f77220e
diff --git a/lib/libfdt/fdt.h b/include/lib/libfdt/fdt.h
similarity index 96%
rename from lib/libfdt/fdt.h
rename to include/lib/libfdt/fdt.h
index 526aedb..6331998 100644
--- a/lib/libfdt/fdt.h
+++ b/include/lib/libfdt/fdt.h
@@ -52,8 +52,16 @@
  *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+/*
+ * Portions copyright (c) 2016, ARM Limited and Contributors.
+ * All rights reserved.
+ */
+
 #ifndef __ASSEMBLY__
 
+#include <libfdt_env.h>
+
+
 struct fdt_header {
 	fdt32_t magic;			 /* magic word FDT_MAGIC */
 	fdt32_t totalsize;		 /* total size of DT block */
@@ -80,14 +88,14 @@
 
 struct fdt_node_header {
 	fdt32_t tag;
-	char name[0];
+	char name[];
 };
 
 struct fdt_property {
 	fdt32_t tag;
 	fdt32_t len;
 	fdt32_t nameoff;
-	char data[0];
+	char data[];
 };
 
 #endif /* !__ASSEMBLY */
diff --git a/lib/libfdt/libfdt.h b/include/lib/libfdt/libfdt.h
similarity index 98%
rename from lib/libfdt/libfdt.h
rename to include/lib/libfdt/libfdt.h
index 32d5227..74f4895 100644
--- a/lib/libfdt/libfdt.h
+++ b/include/lib/libfdt/libfdt.h
@@ -51,6 +51,11 @@
  *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+/*
+ * Portions copyright (c) 2016, ARM Limited and Contributors.
+ * All rights reserved.
+ */
+
 #include <libfdt_env.h>
 #include <fdt.h>
 
@@ -186,16 +191,16 @@
 		struct fdt_header *fdth = (struct fdt_header*)fdt; \
 		fdth->name = cpu_to_fdt32(val); \
 	}
-__fdt_set_hdr(magic);
-__fdt_set_hdr(totalsize);
-__fdt_set_hdr(off_dt_struct);
-__fdt_set_hdr(off_dt_strings);
-__fdt_set_hdr(off_mem_rsvmap);
-__fdt_set_hdr(version);
-__fdt_set_hdr(last_comp_version);
-__fdt_set_hdr(boot_cpuid_phys);
-__fdt_set_hdr(size_dt_strings);
-__fdt_set_hdr(size_dt_struct);
+__fdt_set_hdr(magic)
+__fdt_set_hdr(totalsize)
+__fdt_set_hdr(off_dt_struct)
+__fdt_set_hdr(off_dt_strings)
+__fdt_set_hdr(off_mem_rsvmap)
+__fdt_set_hdr(version)
+__fdt_set_hdr(last_comp_version)
+__fdt_set_hdr(boot_cpuid_phys)
+__fdt_set_hdr(size_dt_strings)
+__fdt_set_hdr(size_dt_struct)
 #undef __fdt_set_hdr
 
 /**
diff --git a/lib/libfdt/libfdt_env.h b/include/lib/libfdt/libfdt_env.h
similarity index 100%
rename from lib/libfdt/libfdt_env.h
rename to include/lib/libfdt/libfdt_env.h
diff --git a/lib/libfdt/Makefile.libfdt b/lib/libfdt/Makefile.libfdt
deleted file mode 100644
index 09c322e..0000000
--- a/lib/libfdt/Makefile.libfdt
+++ /dev/null
@@ -1,11 +0,0 @@
-# Makefile.libfdt
-#
-# This is not a complete Makefile of itself.  Instead, it is designed to
-# be easily embeddable into other systems of Makefiles.
-#
-LIBFDT_soname = libfdt.$(SHAREDLIB_EXT).1
-LIBFDT_INCLUDES = fdt.h libfdt.h libfdt_env.h
-LIBFDT_VERSION = version.lds
-LIBFDT_SRCS = fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c fdt_empty_tree.c \
-	fdt_addresses.c
-LIBFDT_OBJS = $(LIBFDT_SRCS:%.c=%.o)
diff --git a/lib/libfdt/TODO b/lib/libfdt/TODO
deleted file mode 100644
index 288437e..0000000
--- a/lib/libfdt/TODO
+++ /dev/null
@@ -1,3 +0,0 @@
-- Tree traversal functions
-- Graft function
-- Complete libfdt.h documenting comments
diff --git a/lib/libfdt/libfdt.mk b/lib/libfdt/libfdt.mk
new file mode 100644
index 0000000..f2e8d09
--- /dev/null
+++ b/lib/libfdt/libfdt.mk
@@ -0,0 +1,41 @@
+#
+# Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# Redistributions of source code must retain the above copyright notice, this
+# list of conditions and the following disclaimer.
+#
+# Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+#
+# Neither the name of ARM nor the names of its contributors may be used
+# to endorse or promote products derived from this software without specific
+# prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+LIBFDT_SRCS	:=	$(addprefix lib/libfdt/,	\
+			fdt.c				\
+			fdt_addresses.c			\
+			fdt_empty_tree.c		\
+			fdt_ro.c			\
+			fdt_rw.c			\
+			fdt_strerror.c			\
+			fdt_sw.c			\
+			fdt_wip.c)			\
+
+INCLUDES	+=	-Iinclude/lib/libfdt
diff --git a/lib/libfdt/version.lds b/lib/libfdt/version.lds
deleted file mode 100644
index 80b322b..0000000
--- a/lib/libfdt/version.lds
+++ /dev/null
@@ -1,60 +0,0 @@
-LIBFDT_1.2 {
-	global:
-		fdt_next_node;
-		fdt_check_header;
-		fdt_move;
-		fdt_string;
-		fdt_num_mem_rsv;
-		fdt_get_mem_rsv;
-		fdt_subnode_offset_namelen;
-		fdt_subnode_offset;
-		fdt_path_offset;
-		fdt_get_name;
-		fdt_get_property_namelen;
-		fdt_get_property;
-		fdt_getprop_namelen;
-		fdt_getprop;
-		fdt_get_phandle;
-		fdt_get_alias_namelen;
-		fdt_get_alias;
-		fdt_get_path;
-		fdt_supernode_atdepth_offset;
-		fdt_node_depth;
-		fdt_parent_offset;
-		fdt_node_offset_by_prop_value;
-		fdt_node_offset_by_phandle;
-		fdt_node_check_compatible;
-		fdt_node_offset_by_compatible;
-		fdt_setprop_inplace;
-		fdt_nop_property;
-		fdt_nop_node;
-		fdt_create;
-		fdt_add_reservemap_entry;
-		fdt_finish_reservemap;
-		fdt_begin_node;
-		fdt_property;
-		fdt_end_node;
-		fdt_finish;
-		fdt_open_into;
-		fdt_pack;
-		fdt_add_mem_rsv;
-		fdt_del_mem_rsv;
-		fdt_set_name;
-		fdt_setprop;
-		fdt_delprop;
-		fdt_add_subnode_namelen;
-		fdt_add_subnode;
-		fdt_del_node;
-		fdt_strerror;
-		fdt_offset_ptr;
-		fdt_next_tag;
-		fdt_appendprop;
-		fdt_create_empty_tree;
-		fdt_first_property_offset;
-		fdt_get_property_by_offset;
-		fdt_getprop_by_offset;
-		fdt_next_property_offset;
-
-	local:
-		*;
-};