dtoc: Support copying the contents of a node into another

This permits implementation of a simple templating system, where a node
can be reused as a base for others.

For now this adds new subnodes after any existing ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/tools/dtoc/test/dtoc_test_copy.dts b/tools/dtoc/test/dtoc_test_copy.dts
new file mode 100644
index 0000000..85e2c34
--- /dev/null
+++ b/tools/dtoc/test/dtoc_test_copy.dts
@@ -0,0 +1,76 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Test device tree file for dtoc
+ *
+ * Copyright 2017 Google, Inc
+ */
+
+/dts-v1/;
+
+/ {
+	#address-cells = <1>;
+	#size-cells = <1>;
+	reference = <&over>;	/* nake sure that the 'over' phandle exists */
+
+	dest {
+		bootph-all;
+		compatible = "sandbox,spl-test";
+		stringarray = "one";
+		longbytearray = [09 0a 0b 0c 0d 0e 0f 10];
+		maybe-empty-int = <1>;
+
+		first@0 {
+			a-prop = <456>;
+			b-prop = <1>;
+		};
+
+		existing {
+		};
+
+		base {
+			second {
+				second3 {
+				};
+
+				second2 {
+					new-prop;
+				};
+
+				second1 {
+					new-prop;
+				};
+
+				second4 {
+				};
+			};
+		};
+	};
+
+	base {
+		compatible = "sandbox,i2c";
+		bootph-all;
+		#address-cells = <1>;
+		#size-cells = <0>;
+		over: over {
+			compatible = "sandbox,pmic";
+			bootph-all;
+			reg = <9>;
+			low-power;
+		};
+
+		first@0 {
+			reg = <0>;
+			a-prop = <123>;
+		};
+
+		second: second {
+			second1 {
+				some-prop;
+			};
+
+			second2 {
+				some-prop;
+			};
+		};
+	};
+};