Update to dtc-1.4.4

Merge dtc to upstream 558cd81bdd432769b59bff01240c44f82cfb1a9d
and merge history

Bug: 37655045
Test: Build dtc, use output dtc to build dts, can output correct dtb.
Change-Id: Ibd9a82768e999bc46e6de349ca97ba6447e85455
diff --git a/Android.mk b/Android.mk
new file mode 100644
index 0000000..ee3590e
--- /dev/null
+++ b/Android.mk
@@ -0,0 +1,29 @@
+# Copyright 2016 The Android Open Source Project
+
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_CFLAGS := \
+  -Wno-sign-compare \
+  -Wno-missing-field-initializers \
+  -Wno-unused-parameter
+LOCAL_SRC_FILES := \
+  checks.c \
+  data.c \
+  dtc.c \
+  dtc-lexer.l \
+  dtc-parser.y \
+  flattree.c \
+  fstree.c \
+  livetree.c \
+  srcpos.c \
+  treesource.c \
+  util.c
+
+LOCAL_STATIC_LIBRARIES := \
+  libfdt
+LOCAL_MODULE := dtc
+
+include $(BUILD_HOST_EXECUTABLE)
+
+include $(LOCAL_PATH)/libfdt/Android.mk
diff --git a/Documentation/dt-object-internal.txt b/Documentation/dt-object-internal.txt
index 51d68ab..624aa43 100644
--- a/Documentation/dt-object-internal.txt
+++ b/Documentation/dt-object-internal.txt
@@ -308,3 +308,20 @@
 DT object loaded. The __local_fixups__ node records the offset relative to the
 start of every local reference within that property so that the loader can apply
 the offset.
+
+There is an alternative syntax to the expanded form for overlays with phandle
+targets which makes the format similar to the one using in .dtsi include files.
+
+So for the &ocp target example above one can simply write:
+
+/dts-v1/;
+/plugin/;
+&ocp {
+	/* bar peripheral */
+	bar {
+		compatible = "corp,bar";
+		... /* various properties and child nodes */
+	}
+};
+
+The resulting dtb object is identical.
diff --git a/README.version b/README.version
new file mode 100644
index 0000000..50213c0
--- /dev/null
+++ b/README.version
@@ -0,0 +1,3 @@
+URL: https://git.kernel.org/cgit/utils/dtc/dtc.git/commit/?id=120775eb1cf39f8dcecd695c3ff1cfef8aeb669d
+Version: 1.4.2 plus bugfixes
+Owners: cphoenix
diff --git a/dtc-lexer.l b/dtc-lexer.l
index fd825eb..13f4b06 100644
--- a/dtc-lexer.l
+++ b/dtc-lexer.l
@@ -36,7 +36,7 @@
 %{
 #include "dtc.h"
 #include "srcpos.h"
-#include "dtc-parser.tab.h"
+#include "dtc-parser.h"
 
 YYLTYPE yylloc;
 extern bool treesource_error;
diff --git a/dtc-parser.y b/dtc-parser.y
index ca3f500..affc81a 100644
--- a/dtc-parser.y
+++ b/dtc-parser.y
@@ -182,10 +182,19 @@
 		{
 			struct node *target = get_node_by_ref($1, $2);
 
-			if (target)
+			if (target) {
 				merge_nodes(target, $3);
-			else
-				ERROR(&@2, "Label or path %s not found", $2);
+			} else {
+				/*
+				 * We rely on the rule being always:
+				 *   versioninfo plugindecl memreserves devicetree
+				 * so $-1 is what we want (plugindecl)
+				 */
+				if ($<flags>-1 & DTSF_PLUGIN)
+					add_orphan_node($1, $3, $2);
+				else
+					ERROR(&@2, "Label or path %s not found", $2);
+			}
 			$$ = $1;
 		}
 	| devicetree DT_DEL_NODE DT_REF ';'
@@ -200,6 +209,11 @@
 
 			$$ = $1;
 		}
+	| /* empty */
+		{
+			/* build empty node */
+			$$ = name_node(build_node(NULL, NULL), "");
+		}
 	;
 
 nodedef:
diff --git a/dtc.h b/dtc.h
index 403b79d..e031a5a 100644
--- a/dtc.h
+++ b/dtc.h
@@ -197,6 +197,7 @@
 struct node *name_node(struct node *node, char *name);
 struct node *chain_node(struct node *first, struct node *list);
 struct node *merge_nodes(struct node *old_node, struct node *new_node);
+void add_orphan_node(struct node *old_node, struct node *new_node, char *ref);
 
 void add_property(struct node *node, struct property *prop);
 void delete_property_by_name(struct node *node, char *name);
diff --git a/libfdt/Android.mk b/libfdt/Android.mk
new file mode 100644
index 0000000..a4fff1e
--- /dev/null
+++ b/libfdt/Android.mk
@@ -0,0 +1,36 @@
+LOCAL_PATH:= $(call my-dir)
+
+common_src_files := \
+  fdt.c \
+  fdt_ro.c \
+  fdt_wip.c \
+  fdt_sw.c \
+  fdt_rw.c \
+  fdt_strerror.c \
+  fdt_empty_tree.c \
+  fdt_addresses.c \
+  fdt_overlay.c
+
+#################################################
+
+include $(CLEAR_VARS)
+
+LOCAL_CFLAGS := -Wno-macro-redefined -Wno-sign-compare
+LOCAL_SRC_FILES := $(common_src_files)
+LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
+LOCAL_MODULE := libfdt
+
+include $(BUILD_STATIC_LIBRARY)
+
+#################################################
+
+
+include $(CLEAR_VARS)
+
+LOCAL_CFLAGS := -Wno-macro-redefined -Wno-sign-compare
+LOCAL_SRC_FILES := $(common_src_files)
+LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
+LOCAL_MODULE := libfdt
+
+include $(BUILD_HOST_STATIC_LIBRARY)
+
diff --git a/livetree.c b/livetree.c
index 3673de0..90580be 100644
--- a/livetree.c
+++ b/livetree.c
@@ -216,6 +216,28 @@
 	return old_node;
 }
 
+void add_orphan_node(struct node *dt, struct node *new_node, char *ref)
+{
+	static unsigned int next_orphan_fragment = 0;
+	struct node *node;
+	struct property *p;
+	struct data d = empty_data;
+	char *name;
+
+	d = data_add_marker(d, REF_PHANDLE, ref);
+	d = data_append_integer(d, 0xffffffff, 32);
+
+	p = build_property("target", d);
+
+	xasprintf(&name, "fragment@%u",
+			next_orphan_fragment++);
+	name_node(new_node, "__overlay__");
+	node = build_node(p, new_node);
+	name_node(node, name);
+
+	add_child(dt, node);
+}
+
 struct node *chain_node(struct node *first, struct node *list)
 {
 	assert(first->next_sibling == NULL);
diff --git a/util.c b/util.c
index 9953c32..6ae5976 100644
--- a/util.c
+++ b/util.c
@@ -34,7 +34,7 @@
 
 #include "libfdt.h"
 #include "util.h"
-#include "version_gen.h"
+#include "version_non_gen.h"
 
 char *xstrdup(const char *s)
 {
diff --git a/version_non_gen.h b/version_non_gen.h
new file mode 100644
index 0000000..71d542d
--- /dev/null
+++ b/version_non_gen.h
@@ -0,0 +1 @@
+#define DTC_VERSION "DTC 1.4.4-Android-build"