Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/817907/?format=api
{ "id": 817907, "url": "http://patchwork.ozlabs.org/api/patches/817907/?format=api", "web_url": "http://patchwork.ozlabs.org/project/uboot/patch/1506263222-7080-2-git-send-email-trini@konsulko.com/", "project": { "id": 18, "url": "http://patchwork.ozlabs.org/api/projects/18/?format=api", "name": "U-Boot", "link_name": "uboot", "list_id": "u-boot.lists.denx.de", "list_email": "u-boot@lists.denx.de", "web_url": null, "scm_url": null, "webscm_url": null, "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<1506263222-7080-2-git-send-email-trini@konsulko.com>", "list_archive_url": null, "date": "2017-09-24T14:26:58", "name": "[U-Boot,1/5] scripts/dtc: Update to upstream version v1.4.3", "commit_ref": "c0e032e0090d6541549b19cc47e06ccd1f302893", "pull_url": null, "state": "accepted", "archived": false, "hash": "5a96960499d1425b7da49aab73dc12a6342e4582", "submitter": { "id": 65875, "url": "http://patchwork.ozlabs.org/api/people/65875/?format=api", "name": "Tom Rini", "email": "trini@konsulko.com" }, "delegate": { "id": 3651, "url": "http://patchwork.ozlabs.org/api/users/3651/?format=api", "username": "trini", "first_name": "Tom", "last_name": "Rini", "email": "trini@ti.com" }, "mbox": "http://patchwork.ozlabs.org/project/uboot/patch/1506263222-7080-2-git-send-email-trini@konsulko.com/mbox/", "series": [ { "id": 4816, "url": "http://patchwork.ozlabs.org/api/series/4816/?format=api", "web_url": "http://patchwork.ozlabs.org/project/uboot/list/?series=4816", "date": "2017-09-24T14:26:57", "name": "Follow the Linux Kernel in building dtc as needed", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/4816/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/817907/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/817907/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<u-boot-bounces@lists.denx.de>", "X-Original-To": "incoming@patchwork.ozlabs.org", "Delivered-To": "patchwork-incoming@bilbo.ozlabs.org", "Authentication-Results": "ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=lists.denx.de\n\t(client-ip=81.169.180.215; helo=lists.denx.de;\n\tenvelope-from=u-boot-bounces@lists.denx.de;\n\treceiver=<UNKNOWN>)", "Received": [ "from lists.denx.de (dione.denx.de [81.169.180.215])\n\tby ozlabs.org (Postfix) with ESMTP id 3y0VSJ4pVKz9sDB\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon, 25 Sep 2017 00:47:44 +1000 (AEST)", "by lists.denx.de (Postfix, from userid 105)\n\tid 683B6C220EE; Sun, 24 Sep 2017 14:45:25 +0000 (UTC)", "from lists.denx.de (localhost [IPv6:::1])\n\tby lists.denx.de (Postfix) with ESMTP id 40DF6C2212F;\n\tSun, 24 Sep 2017 14:41:47 +0000 (UTC)", "by lists.denx.de (Postfix, from userid 105)\n\tid 5DE6EC220A3; Sun, 24 Sep 2017 14:39:47 +0000 (UTC)", "from mail-yw0-f171.google.com (mail-yw0-f171.google.com\n\t[209.85.161.171])\n\tby lists.denx.de (Postfix) with ESMTPS id 9A0B9C220BF\n\tfor <u-boot@lists.denx.de>; Sun, 24 Sep 2017 14:39:35 +0000 (UTC)", "by mail-yw0-f171.google.com with SMTP id l4so3284201ywa.6\n\tfor <u-boot@lists.denx.de>; Sun, 24 Sep 2017 07:39:35 -0700 (PDT)", "from localhost.localdomain (cpe-65-184-142-68.ec.res.rr.com.\n\t[65.184.142.68]) by smtp.gmail.com with ESMTPSA id\n\tu194sm1849559ywu.38.2017.09.24.07.39.29 for <u-boot@lists.denx.de>\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);\n\tSun, 24 Sep 2017 07:39:29 -0700 (PDT)" ], "X-Spam-Checker-Version": "SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de", "X-Spam-Level": "", "X-Spam-Status": "No, score=-0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE,\n\tRCVD_IN_MSPIKE_H3,\n\tRCVD_IN_MSPIKE_WL autolearn=unavailable autolearn_force=no\n\tversion=3.4.0", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:subject:date:message-id:in-reply-to\n\t:references;\n\tbh=KvyktFz0CBnrbL2iCHA4OF/o0aph0jVbS23doGVIgxQ=;\n\tb=r/FmGDlAZYu9ggfqdeOMXN8UXOC1QVyHEK0cdi57GnKLF9tNwSK408PBqGLV8C/sPF\n\tntEA8lkBmJtvJpB9NO4X6Ml5wMIuTGjA6UZoXKJh0JEWxSDb+pDOFGRGFDUlL7wGFZCi\n\tC8CSjkVnB5w7oF/N3uN++0GNwfh9pDe1ekYKx8gr/W7CUVqQsZRrMCH/ZXUyf1RQFJjP\n\tfkBnGLTBxV/XUxQl/VxghNFdelbXFYAoOOdAugnmcZ03FXbHcpp+nnnF3kiNh7fDXIDR\n\t4eBTjuxBW9dimZBB5BdQZgq/6tBipMuggTeuLn/A/7hpTjwtV2s6GhYtA7JoEB9Helln\n\tpOTQ==", "X-Gm-Message-State": "AHPjjUjk8jzbakuYNkQG1Ibo29D1ilGZHYjOLXfMj5o+05VS+VTld/N3\n\t8odbAxs8zOz2JflM0A0Y5dcl", "X-Google-Smtp-Source": "AOwi7QBRlbQO3G27oAGdetlOl7DloUfOoAyf33boWvmaLxBkFXgcPbCJe0GLMnRR5Wy7yJPmXyia1A==", "X-Received": "by 10.129.109.208 with SMTP id\n\ti199mr2872589ywc.378.1506263971120; \n\tSun, 24 Sep 2017 07:39:31 -0700 (PDT)", "From": "Tom Rini <trini@konsulko.com>", "To": "u-boot@lists.denx.de", "Date": "Sun, 24 Sep 2017 10:26:58 -0400", "Message-Id": "<1506263222-7080-2-git-send-email-trini@konsulko.com>", "X-Mailer": "git-send-email 1.9.1", "In-Reply-To": "<1506263222-7080-1-git-send-email-trini@konsulko.com>", "References": "<1506263222-7080-1-git-send-email-trini@konsulko.com>", "X-Mailman-Approved-At": "Sun, 24 Sep 2017 14:41:45 +0000", "Subject": "[U-Boot] [PATCH 1/5] scripts/dtc: Update to upstream version v1.4.3", "X-BeenThere": "u-boot@lists.denx.de", "X-Mailman-Version": "2.1.18", "Precedence": "list", "List-Id": "U-Boot discussion <u-boot.lists.denx.de>", "List-Unsubscribe": "<https://lists.denx.de/options/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=unsubscribe>", "List-Archive": "<http://lists.denx.de/pipermail/u-boot/>", "List-Post": "<mailto:u-boot@lists.denx.de>", "List-Help": "<mailto:u-boot-request@lists.denx.de?subject=help>", "List-Subscribe": "<https://lists.denx.de/listinfo/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=subscribe>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=\"utf-8\"", "Content-Transfer-Encoding": "base64", "Errors-To": "u-boot-bounces@lists.denx.de", "Sender": "\"U-Boot\" <u-boot-bounces@lists.denx.de>" }, "content": "Using the update-dtc-source.sh script from Linux v4.14-rc1 import the\nportions of dtc that we require. We bring in update-dtc-source.sh and\nscripts/dtc/Makefile from Linux v4.14-rc1. Rework DTC_FLAGS handling to\nnot require a test.\n\nSigned-off-by: Tom Rini <trini@konsulko.com>\n---\n scripts/Kbuild.include | 5 -\n scripts/Makefile.extrawarn | 16 +-\n scripts/dtc/Makefile | 31 +\n scripts/dtc/Makefile.dtc | 18 +\n scripts/dtc/checks.c | 849 +++++++++++++\n scripts/dtc/data.c | 269 ++++\n scripts/dtc/dtc-lexer.l | 311 +++++\n scripts/dtc/dtc-lexer.lex.c_shipped | 2260 +++++++++++++++++++++++++++++++++\n scripts/dtc/dtc-parser.tab.c_shipped | 2301 ++++++++++++++++++++++++++++++++++\n scripts/dtc/dtc-parser.tab.h_shipped | 123 ++\n scripts/dtc/dtc-parser.y | 519 ++++++++\n scripts/dtc/dtc.c | 366 ++++++\n scripts/dtc/dtc.h | 285 +++++\n scripts/dtc/flattree.c | 946 ++++++++++++++\n scripts/dtc/fstree.c | 90 ++\n scripts/dtc/libfdt/Makefile.libfdt | 11 +\n scripts/dtc/libfdt/fdt.c | 251 ++++\n scripts/dtc/libfdt/fdt.h | 111 ++\n scripts/dtc/libfdt/fdt_empty_tree.c | 84 ++\n scripts/dtc/libfdt/fdt_ro.c | 703 +++++++++++\n scripts/dtc/libfdt/fdt_rw.c | 491 ++++++++\n scripts/dtc/libfdt/fdt_strerror.c | 102 ++\n scripts/dtc/libfdt/fdt_sw.c | 288 +++++\n scripts/dtc/libfdt/fdt_wip.c | 139 ++\n scripts/dtc/libfdt/libfdt.h | 1833 +++++++++++++++++++++++++++\n scripts/dtc/libfdt/libfdt_env.h | 112 ++\n scripts/dtc/libfdt/libfdt_internal.h | 95 ++\n scripts/dtc/livetree.c | 980 +++++++++++++++\n scripts/dtc/srcpos.c | 302 +++++\n scripts/dtc/srcpos.h | 118 ++\n scripts/dtc/treesource.c | 284 +++++\n scripts/dtc/update-dtc-source.sh | 81 ++\n scripts/dtc/util.c | 473 +++++++\n scripts/dtc/util.h | 265 ++++\n scripts/dtc/version_gen.h | 1 +\n 35 files changed, 15100 insertions(+), 13 deletions(-)\n create mode 100644 scripts/dtc/Makefile\n create mode 100644 scripts/dtc/Makefile.dtc\n create mode 100644 scripts/dtc/checks.c\n create mode 100644 scripts/dtc/data.c\n create mode 100644 scripts/dtc/dtc-lexer.l\n create mode 100644 scripts/dtc/dtc-lexer.lex.c_shipped\n create mode 100644 scripts/dtc/dtc-parser.tab.c_shipped\n create mode 100644 scripts/dtc/dtc-parser.tab.h_shipped\n create mode 100644 scripts/dtc/dtc-parser.y\n create mode 100644 scripts/dtc/dtc.c\n create mode 100644 scripts/dtc/dtc.h\n create mode 100644 scripts/dtc/flattree.c\n create mode 100644 scripts/dtc/fstree.c\n create mode 100644 scripts/dtc/libfdt/Makefile.libfdt\n create mode 100644 scripts/dtc/libfdt/fdt.c\n create mode 100644 scripts/dtc/libfdt/fdt.h\n create mode 100644 scripts/dtc/libfdt/fdt_empty_tree.c\n create mode 100644 scripts/dtc/libfdt/fdt_ro.c\n create mode 100644 scripts/dtc/libfdt/fdt_rw.c\n create mode 100644 scripts/dtc/libfdt/fdt_strerror.c\n create mode 100644 scripts/dtc/libfdt/fdt_sw.c\n create mode 100644 scripts/dtc/libfdt/fdt_wip.c\n create mode 100644 scripts/dtc/libfdt/libfdt.h\n create mode 100644 scripts/dtc/libfdt/libfdt_env.h\n create mode 100644 scripts/dtc/libfdt/libfdt_internal.h\n create mode 100644 scripts/dtc/livetree.c\n create mode 100644 scripts/dtc/srcpos.c\n create mode 100644 scripts/dtc/srcpos.h\n create mode 100644 scripts/dtc/treesource.c\n create mode 100755 scripts/dtc/update-dtc-source.sh\n create mode 100644 scripts/dtc/util.c\n create mode 100644 scripts/dtc/util.h\n create mode 100644 scripts/dtc/version_gen.h", "diff": "diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include\nindex a3a5c59d0da2..2c7918ad3721 100644\n--- a/scripts/Kbuild.include\n+++ b/scripts/Kbuild.include\n@@ -172,11 +172,6 @@ ld-version = $(shell $(LD) --version | $(srctree)/scripts/ld-version.sh)\n # Usage: $(call ld-ifversion, -ge, 22252, y)\n ld-ifversion = $(shell [ $(ld-version) $(1) $(2) ] && echo $(3) || echo $(4))\n \n-# dtc-option\n-# Usage: DTC_FLAGS += $(call dtc-option,-Wno-unit_address_vs_reg)\n-dtc-option = $(call try-run,\\\n-\techo '/dts-v1/; / {};' | $(DTC) $(1),$(1),$(2))\n-\n ######\n \n ###\ndiff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn\nindex 90dc149df3d9..1d3a5705946d 100644\n--- a/scripts/Makefile.extrawarn\n+++ b/scripts/Makefile.extrawarn\n@@ -58,8 +58,8 @@ endif\n \n KBUILD_CFLAGS += $(warning)\n \n-dtc-warning-2 += $(call dtc-option,-Wnode_name_chars_strict)\n-dtc-warning-2 += $(call dtc-option,-Wproperty_name_chars_strict)\n+dtc-warning-2 += -Wnode_name_chars_strict\n+dtc-warning-2 += -Wproperty_name_chars_strict\n \n dtc-warning := $(dtc-warning-$(findstring 1, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)))\n dtc-warning += $(dtc-warning-$(findstring 2, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)))\n@@ -70,11 +70,11 @@ DTC_FLAGS += $(dtc-warning)\n else\n \n # Disable noisy checks by default\n-DTC_FLAGS += $(call dtc-option,-Wno-unit_address_vs_reg)\n-DTC_FLAGS += $(call dtc-option,-Wno-simple_bus_reg)\n-DTC_FLAGS += $(call dtc-option,-Wno-unit_address_format)\n-DTC_FLAGS += $(call dtc-option,-Wno-pci_bridge)\n-DTC_FLAGS += $(call dtc-option,-Wno-pci_device_bus_num)\n-DTC_FLAGS += $(call dtc-option,-Wno-pci_device_reg)\n+DTC_FLAGS += -Wno-unit_address_vs_reg\n+DTC_FLAGS += -Wno-simple_bus_reg\n+DTC_FLAGS += -Wno-unit_address_format\n+DTC_FLAGS += -Wno-pci_bridge\n+DTC_FLAGS += -Wno-pci_device_bus_num\n+DTC_FLAGS += -Wno-pci_device_reg\n \n endif\ndiff --git a/scripts/dtc/Makefile b/scripts/dtc/Makefile\nnew file mode 100644\nindex 000000000000..2a48022c41e7\n--- /dev/null\n+++ b/scripts/dtc/Makefile\n@@ -0,0 +1,31 @@\n+# scripts/dtc makefile\n+\n+hostprogs-y\t:= dtc\n+always\t\t:= $(hostprogs-y)\n+\n+dtc-objs\t:= dtc.o flattree.o fstree.o data.o livetree.o treesource.o \\\n+\t\t srcpos.o checks.o util.o\n+dtc-objs\t+= dtc-lexer.lex.o dtc-parser.tab.o\n+\n+# Source files need to get at the userspace version of libfdt_env.h to compile\n+\n+HOSTCFLAGS_DTC := -I$(src) -I$(src)/libfdt\n+\n+HOSTCFLAGS_checks.o := $(HOSTCFLAGS_DTC)\n+HOSTCFLAGS_data.o := $(HOSTCFLAGS_DTC)\n+HOSTCFLAGS_dtc.o := $(HOSTCFLAGS_DTC)\n+HOSTCFLAGS_flattree.o := $(HOSTCFLAGS_DTC)\n+HOSTCFLAGS_fstree.o := $(HOSTCFLAGS_DTC)\n+HOSTCFLAGS_livetree.o := $(HOSTCFLAGS_DTC)\n+HOSTCFLAGS_srcpos.o := $(HOSTCFLAGS_DTC)\n+HOSTCFLAGS_treesource.o := $(HOSTCFLAGS_DTC)\n+HOSTCFLAGS_util.o := $(HOSTCFLAGS_DTC)\n+\n+HOSTCFLAGS_dtc-lexer.lex.o := $(HOSTCFLAGS_DTC)\n+HOSTCFLAGS_dtc-parser.tab.o := $(HOSTCFLAGS_DTC)\n+\n+# dependencies on generated files need to be listed explicitly\n+$(obj)/dtc-lexer.lex.o: $(obj)/dtc-parser.tab.h\n+\n+# generated files need to be cleaned explicitly\n+clean-files\t:= dtc-lexer.lex.c dtc-parser.tab.c dtc-parser.tab.h\ndiff --git a/scripts/dtc/Makefile.dtc b/scripts/dtc/Makefile.dtc\nnew file mode 100644\nindex 000000000000..bece49b35535\n--- /dev/null\n+++ b/scripts/dtc/Makefile.dtc\n@@ -0,0 +1,18 @@\n+# Makefile.dtc\n+#\n+# This is not a complete Makefile of itself. Instead, it is designed to\n+# be easily embeddable into other systems of Makefiles.\n+#\n+DTC_SRCS = \\\n+\tchecks.c \\\n+\tdata.c \\\n+\tdtc.c \\\n+\tflattree.c \\\n+\tfstree.c \\\n+\tlivetree.c \\\n+\tsrcpos.c \\\n+\ttreesource.c \\\n+\tutil.c\n+\n+DTC_GEN_SRCS = dtc-lexer.lex.c dtc-parser.tab.c\n+DTC_OBJS = $(DTC_SRCS:%.c=%.o) $(DTC_GEN_SRCS:%.c=%.o)\ndiff --git a/scripts/dtc/checks.c b/scripts/dtc/checks.c\nnew file mode 100644\nindex 000000000000..0e8b978c360c\n--- /dev/null\n+++ b/scripts/dtc/checks.c\n@@ -0,0 +1,849 @@\n+/*\n+ * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2007.\n+ *\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License as\n+ * published by the Free Software Foundation; either version 2 of the\n+ * License, or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\n+ * USA\n+ */\n+\n+#include \"dtc.h\"\n+\n+#ifdef TRACE_CHECKS\n+#define TRACE(c, ...) \\\n+\tdo { \\\n+\t\tfprintf(stderr, \"=== %s: \", (c)->name); \\\n+\t\tfprintf(stderr, __VA_ARGS__); \\\n+\t\tfprintf(stderr, \"\\n\"); \\\n+\t} while (0)\n+#else\n+#define TRACE(c, fmt, ...)\tdo { } while (0)\n+#endif\n+\n+enum checkstatus {\n+\tUNCHECKED = 0,\n+\tPREREQ,\n+\tPASSED,\n+\tFAILED,\n+};\n+\n+struct check;\n+\n+typedef void (*check_fn)(struct check *c, struct dt_info *dti, struct node *node);\n+\n+struct check {\n+\tconst char *name;\n+\tcheck_fn fn;\n+\tvoid *data;\n+\tbool warn, error;\n+\tenum checkstatus status;\n+\tbool inprogress;\n+\tint num_prereqs;\n+\tstruct check **prereq;\n+};\n+\n+#define CHECK_ENTRY(_nm, _fn, _d, _w, _e, ...)\t \\\n+\tstatic struct check *_nm##_prereqs[] = { __VA_ARGS__ }; \\\n+\tstatic struct check _nm = { \\\n+\t\t.name = #_nm, \\\n+\t\t.fn = (_fn), \\\n+\t\t.data = (_d), \\\n+\t\t.warn = (_w), \\\n+\t\t.error = (_e), \\\n+\t\t.status = UNCHECKED, \\\n+\t\t.num_prereqs = ARRAY_SIZE(_nm##_prereqs), \\\n+\t\t.prereq = _nm##_prereqs, \\\n+\t};\n+#define WARNING(_nm, _fn, _d, ...) \\\n+\tCHECK_ENTRY(_nm, _fn, _d, true, false, __VA_ARGS__)\n+#define ERROR(_nm, _fn, _d, ...) \\\n+\tCHECK_ENTRY(_nm, _fn, _d, false, true, __VA_ARGS__)\n+#define CHECK(_nm, _fn, _d, ...) \\\n+\tCHECK_ENTRY(_nm, _fn, _d, false, false, __VA_ARGS__)\n+\n+#ifdef __GNUC__\n+static inline void check_msg(struct check *c, struct dt_info *dti,\n+\t\t\t const char *fmt, ...) __attribute__((format (printf, 3, 4)));\n+#endif\n+static inline void check_msg(struct check *c, struct dt_info *dti,\n+\t\t\t const char *fmt, ...)\n+{\n+\tva_list ap;\n+\tva_start(ap, fmt);\n+\n+\tif ((c->warn && (quiet < 1))\n+\t || (c->error && (quiet < 2))) {\n+\t\tfprintf(stderr, \"%s: %s (%s): \",\n+\t\t\tstrcmp(dti->outname, \"-\") ? dti->outname : \"<stdout>\",\n+\t\t\t(c->error) ? \"ERROR\" : \"Warning\", c->name);\n+\t\tvfprintf(stderr, fmt, ap);\n+\t\tfprintf(stderr, \"\\n\");\n+\t}\n+\tva_end(ap);\n+}\n+\n+#define FAIL(c, dti, ...)\t\t\t\t\t\t\\\n+\tdo {\t\t\t\t\t\t\t\t\\\n+\t\tTRACE((c), \"\\t\\tFAILED at %s:%d\", __FILE__, __LINE__);\t\\\n+\t\t(c)->status = FAILED;\t\t\t\t\t\\\n+\t\tcheck_msg((c), dti, __VA_ARGS__);\t\t\t\\\n+\t} while (0)\n+\n+static void check_nodes_props(struct check *c, struct dt_info *dti, struct node *node)\n+{\n+\tstruct node *child;\n+\n+\tTRACE(c, \"%s\", node->fullpath);\n+\tif (c->fn)\n+\t\tc->fn(c, dti, node);\n+\n+\tfor_each_child(node, child)\n+\t\tcheck_nodes_props(c, dti, child);\n+}\n+\n+static bool run_check(struct check *c, struct dt_info *dti)\n+{\n+\tstruct node *dt = dti->dt;\n+\tbool error = false;\n+\tint i;\n+\n+\tassert(!c->inprogress);\n+\n+\tif (c->status != UNCHECKED)\n+\t\tgoto out;\n+\n+\tc->inprogress = true;\n+\n+\tfor (i = 0; i < c->num_prereqs; i++) {\n+\t\tstruct check *prq = c->prereq[i];\n+\t\terror = error || run_check(prq, dti);\n+\t\tif (prq->status != PASSED) {\n+\t\t\tc->status = PREREQ;\n+\t\t\tcheck_msg(c, dti, \"Failed prerequisite '%s'\",\n+\t\t\t\t c->prereq[i]->name);\n+\t\t}\n+\t}\n+\n+\tif (c->status != UNCHECKED)\n+\t\tgoto out;\n+\n+\tcheck_nodes_props(c, dti, dt);\n+\n+\tif (c->status == UNCHECKED)\n+\t\tc->status = PASSED;\n+\n+\tTRACE(c, \"\\tCompleted, status %d\", c->status);\n+\n+out:\n+\tc->inprogress = false;\n+\tif ((c->status != PASSED) && (c->error))\n+\t\terror = true;\n+\treturn error;\n+}\n+\n+/*\n+ * Utility check functions\n+ */\n+\n+/* A check which always fails, for testing purposes only */\n+static inline void check_always_fail(struct check *c, struct dt_info *dti,\n+\t\t\t\t struct node *node)\n+{\n+\tFAIL(c, dti, \"always_fail check\");\n+}\n+CHECK(always_fail, check_always_fail, NULL);\n+\n+static void check_is_string(struct check *c, struct dt_info *dti,\n+\t\t\t struct node *node)\n+{\n+\tstruct property *prop;\n+\tchar *propname = c->data;\n+\n+\tprop = get_property(node, propname);\n+\tif (!prop)\n+\t\treturn; /* Not present, assumed ok */\n+\n+\tif (!data_is_one_string(prop->val))\n+\t\tFAIL(c, dti, \"\\\"%s\\\" property in %s is not a string\",\n+\t\t propname, node->fullpath);\n+}\n+#define WARNING_IF_NOT_STRING(nm, propname) \\\n+\tWARNING(nm, check_is_string, (propname))\n+#define ERROR_IF_NOT_STRING(nm, propname) \\\n+\tERROR(nm, check_is_string, (propname))\n+\n+static void check_is_cell(struct check *c, struct dt_info *dti,\n+\t\t\t struct node *node)\n+{\n+\tstruct property *prop;\n+\tchar *propname = c->data;\n+\n+\tprop = get_property(node, propname);\n+\tif (!prop)\n+\t\treturn; /* Not present, assumed ok */\n+\n+\tif (prop->val.len != sizeof(cell_t))\n+\t\tFAIL(c, dti, \"\\\"%s\\\" property in %s is not a single cell\",\n+\t\t propname, node->fullpath);\n+}\n+#define WARNING_IF_NOT_CELL(nm, propname) \\\n+\tWARNING(nm, check_is_cell, (propname))\n+#define ERROR_IF_NOT_CELL(nm, propname) \\\n+\tERROR(nm, check_is_cell, (propname))\n+\n+/*\n+ * Structural check functions\n+ */\n+\n+static void check_duplicate_node_names(struct check *c, struct dt_info *dti,\n+\t\t\t\t struct node *node)\n+{\n+\tstruct node *child, *child2;\n+\n+\tfor_each_child(node, child)\n+\t\tfor (child2 = child->next_sibling;\n+\t\t child2;\n+\t\t child2 = child2->next_sibling)\n+\t\t\tif (streq(child->name, child2->name))\n+\t\t\t\tFAIL(c, dti, \"Duplicate node name %s\",\n+\t\t\t\t child->fullpath);\n+}\n+ERROR(duplicate_node_names, check_duplicate_node_names, NULL);\n+\n+static void check_duplicate_property_names(struct check *c, struct dt_info *dti,\n+\t\t\t\t\t struct node *node)\n+{\n+\tstruct property *prop, *prop2;\n+\n+\tfor_each_property(node, prop) {\n+\t\tfor (prop2 = prop->next; prop2; prop2 = prop2->next) {\n+\t\t\tif (prop2->deleted)\n+\t\t\t\tcontinue;\n+\t\t\tif (streq(prop->name, prop2->name))\n+\t\t\t\tFAIL(c, dti, \"Duplicate property name %s in %s\",\n+\t\t\t\t prop->name, node->fullpath);\n+\t\t}\n+\t}\n+}\n+ERROR(duplicate_property_names, check_duplicate_property_names, NULL);\n+\n+#define LOWERCASE\t\"abcdefghijklmnopqrstuvwxyz\"\n+#define UPPERCASE\t\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"\n+#define DIGITS\t\t\"0123456789\"\n+#define PROPNODECHARS\tLOWERCASE UPPERCASE DIGITS \",._+*#?-\"\n+#define PROPNODECHARSSTRICT\tLOWERCASE UPPERCASE DIGITS \",-\"\n+\n+static void check_node_name_chars(struct check *c, struct dt_info *dti,\n+\t\t\t\t struct node *node)\n+{\n+\tint n = strspn(node->name, c->data);\n+\n+\tif (n < strlen(node->name))\n+\t\tFAIL(c, dti, \"Bad character '%c' in node %s\",\n+\t\t node->name[n], node->fullpath);\n+}\n+ERROR(node_name_chars, check_node_name_chars, PROPNODECHARS \"@\");\n+\n+static void check_node_name_chars_strict(struct check *c, struct dt_info *dti,\n+\t\t\t\t\t struct node *node)\n+{\n+\tint n = strspn(node->name, c->data);\n+\n+\tif (n < node->basenamelen)\n+\t\tFAIL(c, dti, \"Character '%c' not recommended in node %s\",\n+\t\t node->name[n], node->fullpath);\n+}\n+CHECK(node_name_chars_strict, check_node_name_chars_strict, PROPNODECHARSSTRICT);\n+\n+static void check_node_name_format(struct check *c, struct dt_info *dti,\n+\t\t\t\t struct node *node)\n+{\n+\tif (strchr(get_unitname(node), '@'))\n+\t\tFAIL(c, dti, \"Node %s has multiple '@' characters in name\",\n+\t\t node->fullpath);\n+}\n+ERROR(node_name_format, check_node_name_format, NULL, &node_name_chars);\n+\n+static void check_unit_address_vs_reg(struct check *c, struct dt_info *dti,\n+\t\t\t\t struct node *node)\n+{\n+\tconst char *unitname = get_unitname(node);\n+\tstruct property *prop = get_property(node, \"reg\");\n+\n+\tif (!prop) {\n+\t\tprop = get_property(node, \"ranges\");\n+\t\tif (prop && !prop->val.len)\n+\t\t\tprop = NULL;\n+\t}\n+\n+\tif (prop) {\n+\t\tif (!unitname[0])\n+\t\t\tFAIL(c, dti, \"Node %s has a reg or ranges property, but no unit name\",\n+\t\t\t node->fullpath);\n+\t} else {\n+\t\tif (unitname[0])\n+\t\t\tFAIL(c, dti, \"Node %s has a unit name, but no reg property\",\n+\t\t\t node->fullpath);\n+\t}\n+}\n+WARNING(unit_address_vs_reg, check_unit_address_vs_reg, NULL);\n+\n+static void check_property_name_chars(struct check *c, struct dt_info *dti,\n+\t\t\t\t struct node *node)\n+{\n+\tstruct property *prop;\n+\n+\tfor_each_property(node, prop) {\n+\t\tint n = strspn(prop->name, c->data);\n+\n+\t\tif (n < strlen(prop->name))\n+\t\t\tFAIL(c, dti, \"Bad character '%c' in property name \\\"%s\\\", node %s\",\n+\t\t\t prop->name[n], prop->name, node->fullpath);\n+\t}\n+}\n+ERROR(property_name_chars, check_property_name_chars, PROPNODECHARS);\n+\n+static void check_property_name_chars_strict(struct check *c,\n+\t\t\t\t\t struct dt_info *dti,\n+\t\t\t\t\t struct node *node)\n+{\n+\tstruct property *prop;\n+\n+\tfor_each_property(node, prop) {\n+\t\tconst char *name = prop->name;\n+\t\tint n = strspn(name, c->data);\n+\n+\t\tif (n == strlen(prop->name))\n+\t\t\tcontinue;\n+\n+\t\t/* Certain names are whitelisted */\n+\t\tif (streq(name, \"device_type\"))\n+\t\t\tcontinue;\n+\n+\t\t/*\n+\t\t * # is only allowed at the beginning of property names not counting\n+\t\t * the vendor prefix.\n+\t\t */\n+\t\tif (name[n] == '#' && ((n == 0) || (name[n-1] == ','))) {\n+\t\t\tname += n + 1;\n+\t\t\tn = strspn(name, c->data);\n+\t\t}\n+\t\tif (n < strlen(name))\n+\t\t\tFAIL(c, dti, \"Character '%c' not recommended in property name \\\"%s\\\", node %s\",\n+\t\t\t name[n], prop->name, node->fullpath);\n+\t}\n+}\n+CHECK(property_name_chars_strict, check_property_name_chars_strict, PROPNODECHARSSTRICT);\n+\n+#define DESCLABEL_FMT\t\"%s%s%s%s%s\"\n+#define DESCLABEL_ARGS(node,prop,mark)\t\t\\\n+\t((mark) ? \"value of \" : \"\"),\t\t\\\n+\t((prop) ? \"'\" : \"\"), \\\n+\t((prop) ? (prop)->name : \"\"), \\\n+\t((prop) ? \"' in \" : \"\"), (node)->fullpath\n+\n+static void check_duplicate_label(struct check *c, struct dt_info *dti,\n+\t\t\t\t const char *label, struct node *node,\n+\t\t\t\t struct property *prop, struct marker *mark)\n+{\n+\tstruct node *dt = dti->dt;\n+\tstruct node *othernode = NULL;\n+\tstruct property *otherprop = NULL;\n+\tstruct marker *othermark = NULL;\n+\n+\tothernode = get_node_by_label(dt, label);\n+\n+\tif (!othernode)\n+\t\totherprop = get_property_by_label(dt, label, &othernode);\n+\tif (!othernode)\n+\t\tothermark = get_marker_label(dt, label, &othernode,\n+\t\t\t\t\t &otherprop);\n+\n+\tif (!othernode)\n+\t\treturn;\n+\n+\tif ((othernode != node) || (otherprop != prop) || (othermark != mark))\n+\t\tFAIL(c, dti, \"Duplicate label '%s' on \" DESCLABEL_FMT\n+\t\t \" and \" DESCLABEL_FMT,\n+\t\t label, DESCLABEL_ARGS(node, prop, mark),\n+\t\t DESCLABEL_ARGS(othernode, otherprop, othermark));\n+}\n+\n+static void check_duplicate_label_node(struct check *c, struct dt_info *dti,\n+\t\t\t\t struct node *node)\n+{\n+\tstruct label *l;\n+\tstruct property *prop;\n+\n+\tfor_each_label(node->labels, l)\n+\t\tcheck_duplicate_label(c, dti, l->label, node, NULL, NULL);\n+\n+\tfor_each_property(node, prop) {\n+\t\tstruct marker *m = prop->val.markers;\n+\n+\t\tfor_each_label(prop->labels, l)\n+\t\t\tcheck_duplicate_label(c, dti, l->label, node, prop, NULL);\n+\n+\t\tfor_each_marker_of_type(m, LABEL)\n+\t\t\tcheck_duplicate_label(c, dti, m->ref, node, prop, m);\n+\t}\n+}\n+ERROR(duplicate_label, check_duplicate_label_node, NULL);\n+\n+static cell_t check_phandle_prop(struct check *c, struct dt_info *dti,\n+\t\t\t\t struct node *node, const char *propname)\n+{\n+\tstruct node *root = dti->dt;\n+\tstruct property *prop;\n+\tstruct marker *m;\n+\tcell_t phandle;\n+\n+\tprop = get_property(node, propname);\n+\tif (!prop)\n+\t\treturn 0;\n+\n+\tif (prop->val.len != sizeof(cell_t)) {\n+\t\tFAIL(c, dti, \"%s has bad length (%d) %s property\",\n+\t\t node->fullpath, prop->val.len, prop->name);\n+\t\treturn 0;\n+\t}\n+\n+\tm = prop->val.markers;\n+\tfor_each_marker_of_type(m, REF_PHANDLE) {\n+\t\tassert(m->offset == 0);\n+\t\tif (node != get_node_by_ref(root, m->ref))\n+\t\t\t/* \"Set this node's phandle equal to some\n+\t\t\t * other node's phandle\". That's nonsensical\n+\t\t\t * by construction. */ {\n+\t\t\tFAIL(c, dti, \"%s in %s is a reference to another node\",\n+\t\t\t prop->name, node->fullpath);\n+\t\t}\n+\t\t/* But setting this node's phandle equal to its own\n+\t\t * phandle is allowed - that means allocate a unique\n+\t\t * phandle for this node, even if it's not otherwise\n+\t\t * referenced. The value will be filled in later, so\n+\t\t * we treat it as having no phandle data for now. */\n+\t\treturn 0;\n+\t}\n+\n+\tphandle = propval_cell(prop);\n+\n+\tif ((phandle == 0) || (phandle == -1)) {\n+\t\tFAIL(c, dti, \"%s has bad value (0x%x) in %s property\",\n+\t\t node->fullpath, phandle, prop->name);\n+\t\treturn 0;\n+\t}\n+\n+\treturn phandle;\n+}\n+\n+static void check_explicit_phandles(struct check *c, struct dt_info *dti,\n+\t\t\t\t struct node *node)\n+{\n+\tstruct node *root = dti->dt;\n+\tstruct node *other;\n+\tcell_t phandle, linux_phandle;\n+\n+\t/* Nothing should have assigned phandles yet */\n+\tassert(!node->phandle);\n+\n+\tphandle = check_phandle_prop(c, dti, node, \"phandle\");\n+\n+\tlinux_phandle = check_phandle_prop(c, dti, node, \"linux,phandle\");\n+\n+\tif (!phandle && !linux_phandle)\n+\t\t/* No valid phandles; nothing further to check */\n+\t\treturn;\n+\n+\tif (linux_phandle && phandle && (phandle != linux_phandle))\n+\t\tFAIL(c, dti, \"%s has mismatching 'phandle' and 'linux,phandle'\"\n+\t\t \" properties\", node->fullpath);\n+\n+\tif (linux_phandle && !phandle)\n+\t\tphandle = linux_phandle;\n+\n+\tother = get_node_by_phandle(root, phandle);\n+\tif (other && (other != node)) {\n+\t\tFAIL(c, dti, \"%s has duplicated phandle 0x%x (seen before at %s)\",\n+\t\t node->fullpath, phandle, other->fullpath);\n+\t\treturn;\n+\t}\n+\n+\tnode->phandle = phandle;\n+}\n+ERROR(explicit_phandles, check_explicit_phandles, NULL);\n+\n+static void check_name_properties(struct check *c, struct dt_info *dti,\n+\t\t\t\t struct node *node)\n+{\n+\tstruct property **pp, *prop = NULL;\n+\n+\tfor (pp = &node->proplist; *pp; pp = &((*pp)->next))\n+\t\tif (streq((*pp)->name, \"name\")) {\n+\t\t\tprop = *pp;\n+\t\t\tbreak;\n+\t\t}\n+\n+\tif (!prop)\n+\t\treturn; /* No name property, that's fine */\n+\n+\tif ((prop->val.len != node->basenamelen+1)\n+\t || (memcmp(prop->val.val, node->name, node->basenamelen) != 0)) {\n+\t\tFAIL(c, dti, \"\\\"name\\\" property in %s is incorrect (\\\"%s\\\" instead\"\n+\t\t \" of base node name)\", node->fullpath, prop->val.val);\n+\t} else {\n+\t\t/* The name property is correct, and therefore redundant.\n+\t\t * Delete it */\n+\t\t*pp = prop->next;\n+\t\tfree(prop->name);\n+\t\tdata_free(prop->val);\n+\t\tfree(prop);\n+\t}\n+}\n+ERROR_IF_NOT_STRING(name_is_string, \"name\");\n+ERROR(name_properties, check_name_properties, NULL, &name_is_string);\n+\n+/*\n+ * Reference fixup functions\n+ */\n+\n+static void fixup_phandle_references(struct check *c, struct dt_info *dti,\n+\t\t\t\t struct node *node)\n+{\n+\tstruct node *dt = dti->dt;\n+\tstruct property *prop;\n+\n+\tfor_each_property(node, prop) {\n+\t\tstruct marker *m = prop->val.markers;\n+\t\tstruct node *refnode;\n+\t\tcell_t phandle;\n+\n+\t\tfor_each_marker_of_type(m, REF_PHANDLE) {\n+\t\t\tassert(m->offset + sizeof(cell_t) <= prop->val.len);\n+\n+\t\t\trefnode = get_node_by_ref(dt, m->ref);\n+\t\t\tif (! refnode) {\n+\t\t\t\tif (!(dti->dtsflags & DTSF_PLUGIN))\n+\t\t\t\t\tFAIL(c, dti, \"Reference to non-existent node or \"\n+\t\t\t\t\t\t\t\"label \\\"%s\\\"\\n\", m->ref);\n+\t\t\t\telse /* mark the entry as unresolved */\n+\t\t\t\t\t*((cell_t *)(prop->val.val + m->offset)) =\n+\t\t\t\t\t\tcpu_to_fdt32(0xffffffff);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\tphandle = get_node_phandle(dt, refnode);\n+\t\t\t*((cell_t *)(prop->val.val + m->offset)) = cpu_to_fdt32(phandle);\n+\t\t}\n+\t}\n+}\n+ERROR(phandle_references, fixup_phandle_references, NULL,\n+ &duplicate_node_names, &explicit_phandles);\n+\n+static void fixup_path_references(struct check *c, struct dt_info *dti,\n+\t\t\t\t struct node *node)\n+{\n+\tstruct node *dt = dti->dt;\n+\tstruct property *prop;\n+\n+\tfor_each_property(node, prop) {\n+\t\tstruct marker *m = prop->val.markers;\n+\t\tstruct node *refnode;\n+\t\tchar *path;\n+\n+\t\tfor_each_marker_of_type(m, REF_PATH) {\n+\t\t\tassert(m->offset <= prop->val.len);\n+\n+\t\t\trefnode = get_node_by_ref(dt, m->ref);\n+\t\t\tif (!refnode) {\n+\t\t\t\tFAIL(c, dti, \"Reference to non-existent node or label \\\"%s\\\"\\n\",\n+\t\t\t\t m->ref);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\tpath = refnode->fullpath;\n+\t\t\tprop->val = data_insert_at_marker(prop->val, m, path,\n+\t\t\t\t\t\t\t strlen(path) + 1);\n+\t\t}\n+\t}\n+}\n+ERROR(path_references, fixup_path_references, NULL, &duplicate_node_names);\n+\n+/*\n+ * Semantic checks\n+ */\n+WARNING_IF_NOT_CELL(address_cells_is_cell, \"#address-cells\");\n+WARNING_IF_NOT_CELL(size_cells_is_cell, \"#size-cells\");\n+WARNING_IF_NOT_CELL(interrupt_cells_is_cell, \"#interrupt-cells\");\n+\n+WARNING_IF_NOT_STRING(device_type_is_string, \"device_type\");\n+WARNING_IF_NOT_STRING(model_is_string, \"model\");\n+WARNING_IF_NOT_STRING(status_is_string, \"status\");\n+\n+static void fixup_addr_size_cells(struct check *c, struct dt_info *dti,\n+\t\t\t\t struct node *node)\n+{\n+\tstruct property *prop;\n+\n+\tnode->addr_cells = -1;\n+\tnode->size_cells = -1;\n+\n+\tprop = get_property(node, \"#address-cells\");\n+\tif (prop)\n+\t\tnode->addr_cells = propval_cell(prop);\n+\n+\tprop = get_property(node, \"#size-cells\");\n+\tif (prop)\n+\t\tnode->size_cells = propval_cell(prop);\n+}\n+WARNING(addr_size_cells, fixup_addr_size_cells, NULL,\n+\t&address_cells_is_cell, &size_cells_is_cell);\n+\n+#define node_addr_cells(n) \\\n+\t(((n)->addr_cells == -1) ? 2 : (n)->addr_cells)\n+#define node_size_cells(n) \\\n+\t(((n)->size_cells == -1) ? 1 : (n)->size_cells)\n+\n+static void check_reg_format(struct check *c, struct dt_info *dti,\n+\t\t\t struct node *node)\n+{\n+\tstruct property *prop;\n+\tint addr_cells, size_cells, entrylen;\n+\n+\tprop = get_property(node, \"reg\");\n+\tif (!prop)\n+\t\treturn; /* No \"reg\", that's fine */\n+\n+\tif (!node->parent) {\n+\t\tFAIL(c, dti, \"Root node has a \\\"reg\\\" property\");\n+\t\treturn;\n+\t}\n+\n+\tif (prop->val.len == 0)\n+\t\tFAIL(c, dti, \"\\\"reg\\\" property in %s is empty\", node->fullpath);\n+\n+\taddr_cells = node_addr_cells(node->parent);\n+\tsize_cells = node_size_cells(node->parent);\n+\tentrylen = (addr_cells + size_cells) * sizeof(cell_t);\n+\n+\tif (!entrylen || (prop->val.len % entrylen) != 0)\n+\t\tFAIL(c, dti, \"\\\"reg\\\" property in %s has invalid length (%d bytes) \"\n+\t\t \"(#address-cells == %d, #size-cells == %d)\",\n+\t\t node->fullpath, prop->val.len, addr_cells, size_cells);\n+}\n+WARNING(reg_format, check_reg_format, NULL, &addr_size_cells);\n+\n+static void check_ranges_format(struct check *c, struct dt_info *dti,\n+\t\t\t\tstruct node *node)\n+{\n+\tstruct property *prop;\n+\tint c_addr_cells, p_addr_cells, c_size_cells, p_size_cells, entrylen;\n+\n+\tprop = get_property(node, \"ranges\");\n+\tif (!prop)\n+\t\treturn;\n+\n+\tif (!node->parent) {\n+\t\tFAIL(c, dti, \"Root node has a \\\"ranges\\\" property\");\n+\t\treturn;\n+\t}\n+\n+\tp_addr_cells = node_addr_cells(node->parent);\n+\tp_size_cells = node_size_cells(node->parent);\n+\tc_addr_cells = node_addr_cells(node);\n+\tc_size_cells = node_size_cells(node);\n+\tentrylen = (p_addr_cells + c_addr_cells + c_size_cells) * sizeof(cell_t);\n+\n+\tif (prop->val.len == 0) {\n+\t\tif (p_addr_cells != c_addr_cells)\n+\t\t\tFAIL(c, dti, \"%s has empty \\\"ranges\\\" property but its \"\n+\t\t\t \"#address-cells (%d) differs from %s (%d)\",\n+\t\t\t node->fullpath, c_addr_cells, node->parent->fullpath,\n+\t\t\t p_addr_cells);\n+\t\tif (p_size_cells != c_size_cells)\n+\t\t\tFAIL(c, dti, \"%s has empty \\\"ranges\\\" property but its \"\n+\t\t\t \"#size-cells (%d) differs from %s (%d)\",\n+\t\t\t node->fullpath, c_size_cells, node->parent->fullpath,\n+\t\t\t p_size_cells);\n+\t} else if ((prop->val.len % entrylen) != 0) {\n+\t\tFAIL(c, dti, \"\\\"ranges\\\" property in %s has invalid length (%d bytes) \"\n+\t\t \"(parent #address-cells == %d, child #address-cells == %d, \"\n+\t\t \"#size-cells == %d)\", node->fullpath, prop->val.len,\n+\t\t p_addr_cells, c_addr_cells, c_size_cells);\n+\t}\n+}\n+WARNING(ranges_format, check_ranges_format, NULL, &addr_size_cells);\n+\n+/*\n+ * Style checks\n+ */\n+static void check_avoid_default_addr_size(struct check *c, struct dt_info *dti,\n+\t\t\t\t\t struct node *node)\n+{\n+\tstruct property *reg, *ranges;\n+\n+\tif (!node->parent)\n+\t\treturn; /* Ignore root node */\n+\n+\treg = get_property(node, \"reg\");\n+\tranges = get_property(node, \"ranges\");\n+\n+\tif (!reg && !ranges)\n+\t\treturn;\n+\n+\tif (node->parent->addr_cells == -1)\n+\t\tFAIL(c, dti, \"Relying on default #address-cells value for %s\",\n+\t\t node->fullpath);\n+\n+\tif (node->parent->size_cells == -1)\n+\t\tFAIL(c, dti, \"Relying on default #size-cells value for %s\",\n+\t\t node->fullpath);\n+}\n+WARNING(avoid_default_addr_size, check_avoid_default_addr_size, NULL,\n+\t&addr_size_cells);\n+\n+static void check_obsolete_chosen_interrupt_controller(struct check *c,\n+\t\t\t\t\t\t struct dt_info *dti,\n+\t\t\t\t\t\t struct node *node)\n+{\n+\tstruct node *dt = dti->dt;\n+\tstruct node *chosen;\n+\tstruct property *prop;\n+\n+\tif (node != dt)\n+\t\treturn;\n+\n+\n+\tchosen = get_node_by_path(dt, \"/chosen\");\n+\tif (!chosen)\n+\t\treturn;\n+\n+\tprop = get_property(chosen, \"interrupt-controller\");\n+\tif (prop)\n+\t\tFAIL(c, dti, \"/chosen has obsolete \\\"interrupt-controller\\\" \"\n+\t\t \"property\");\n+}\n+WARNING(obsolete_chosen_interrupt_controller,\n+\tcheck_obsolete_chosen_interrupt_controller, NULL);\n+\n+static struct check *check_table[] = {\n+\t&duplicate_node_names, &duplicate_property_names,\n+\t&node_name_chars, &node_name_format, &property_name_chars,\n+\t&name_is_string, &name_properties,\n+\n+\t&duplicate_label,\n+\n+\t&explicit_phandles,\n+\t&phandle_references, &path_references,\n+\n+\t&address_cells_is_cell, &size_cells_is_cell, &interrupt_cells_is_cell,\n+\t&device_type_is_string, &model_is_string, &status_is_string,\n+\n+\t&property_name_chars_strict,\n+\t&node_name_chars_strict,\n+\n+\t&addr_size_cells, ®_format, &ranges_format,\n+\n+\t&unit_address_vs_reg,\n+\n+\t&avoid_default_addr_size,\n+\t&obsolete_chosen_interrupt_controller,\n+\n+\t&always_fail,\n+};\n+\n+static void enable_warning_error(struct check *c, bool warn, bool error)\n+{\n+\tint i;\n+\n+\t/* Raising level, also raise it for prereqs */\n+\tif ((warn && !c->warn) || (error && !c->error))\n+\t\tfor (i = 0; i < c->num_prereqs; i++)\n+\t\t\tenable_warning_error(c->prereq[i], warn, error);\n+\n+\tc->warn = c->warn || warn;\n+\tc->error = c->error || error;\n+}\n+\n+static void disable_warning_error(struct check *c, bool warn, bool error)\n+{\n+\tint i;\n+\n+\t/* Lowering level, also lower it for things this is the prereq\n+\t * for */\n+\tif ((warn && c->warn) || (error && c->error)) {\n+\t\tfor (i = 0; i < ARRAY_SIZE(check_table); i++) {\n+\t\t\tstruct check *cc = check_table[i];\n+\t\t\tint j;\n+\n+\t\t\tfor (j = 0; j < cc->num_prereqs; j++)\n+\t\t\t\tif (cc->prereq[j] == c)\n+\t\t\t\t\tdisable_warning_error(cc, warn, error);\n+\t\t}\n+\t}\n+\n+\tc->warn = c->warn && !warn;\n+\tc->error = c->error && !error;\n+}\n+\n+void parse_checks_option(bool warn, bool error, const char *arg)\n+{\n+\tint i;\n+\tconst char *name = arg;\n+\tbool enable = true;\n+\n+\tif ((strncmp(arg, \"no-\", 3) == 0)\n+\t || (strncmp(arg, \"no_\", 3) == 0)) {\n+\t\tname = arg + 3;\n+\t\tenable = false;\n+\t}\n+\n+\tfor (i = 0; i < ARRAY_SIZE(check_table); i++) {\n+\t\tstruct check *c = check_table[i];\n+\n+\t\tif (streq(c->name, name)) {\n+\t\t\tif (enable)\n+\t\t\t\tenable_warning_error(c, warn, error);\n+\t\t\telse\n+\t\t\t\tdisable_warning_error(c, warn, error);\n+\t\t\treturn;\n+\t\t}\n+\t}\n+\n+\tdie(\"Unrecognized check name \\\"%s\\\"\\n\", name);\n+}\n+\n+void process_checks(bool force, struct dt_info *dti)\n+{\n+\tint i;\n+\tint error = 0;\n+\n+\tfor (i = 0; i < ARRAY_SIZE(check_table); i++) {\n+\t\tstruct check *c = check_table[i];\n+\n+\t\tif (c->warn || c->error)\n+\t\t\terror = error || run_check(c, dti);\n+\t}\n+\n+\tif (error) {\n+\t\tif (!force) {\n+\t\t\tfprintf(stderr, \"ERROR: Input tree has errors, aborting \"\n+\t\t\t\t\"(use -f to force output)\\n\");\n+\t\t\texit(2);\n+\t\t} else if (quiet < 3) {\n+\t\t\tfprintf(stderr, \"Warning: Input tree has errors, \"\n+\t\t\t\t\"output forced\\n\");\n+\t\t}\n+\t}\n+}\ndiff --git a/scripts/dtc/data.c b/scripts/dtc/data.c\nnew file mode 100644\nindex 000000000000..8cae23746882\n--- /dev/null\n+++ b/scripts/dtc/data.c\n@@ -0,0 +1,269 @@\n+/*\n+ * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.\n+ *\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License as\n+ * published by the Free Software Foundation; either version 2 of the\n+ * License, or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\n+ * USA\n+ */\n+\n+#include \"dtc.h\"\n+\n+void data_free(struct data d)\n+{\n+\tstruct marker *m, *nm;\n+\n+\tm = d.markers;\n+\twhile (m) {\n+\t\tnm = m->next;\n+\t\tfree(m->ref);\n+\t\tfree(m);\n+\t\tm = nm;\n+\t}\n+\n+\tif (d.val)\n+\t\tfree(d.val);\n+}\n+\n+struct data data_grow_for(struct data d, int xlen)\n+{\n+\tstruct data nd;\n+\tint newsize;\n+\n+\tif (xlen == 0)\n+\t\treturn d;\n+\n+\tnd = d;\n+\n+\tnewsize = xlen;\n+\n+\twhile ((d.len + xlen) > newsize)\n+\t\tnewsize *= 2;\n+\n+\tnd.val = xrealloc(d.val, newsize);\n+\n+\treturn nd;\n+}\n+\n+struct data data_copy_mem(const char *mem, int len)\n+{\n+\tstruct data d;\n+\n+\td = data_grow_for(empty_data, len);\n+\n+\td.len = len;\n+\tmemcpy(d.val, mem, len);\n+\n+\treturn d;\n+}\n+\n+struct data data_copy_escape_string(const char *s, int len)\n+{\n+\tint i = 0;\n+\tstruct data d;\n+\tchar *q;\n+\n+\td = data_grow_for(empty_data, len + 1);\n+\n+\tq = d.val;\n+\twhile (i < len) {\n+\t\tchar c = s[i++];\n+\n+\t\tif (c == '\\\\')\n+\t\t\tc = get_escape_char(s, &i);\n+\n+\t\tq[d.len++] = c;\n+\t}\n+\n+\tq[d.len++] = '\\0';\n+\treturn d;\n+}\n+\n+struct data data_copy_file(FILE *f, size_t maxlen)\n+{\n+\tstruct data d = empty_data;\n+\n+\twhile (!feof(f) && (d.len < maxlen)) {\n+\t\tsize_t chunksize, ret;\n+\n+\t\tif (maxlen == -1)\n+\t\t\tchunksize = 4096;\n+\t\telse\n+\t\t\tchunksize = maxlen - d.len;\n+\n+\t\td = data_grow_for(d, chunksize);\n+\t\tret = fread(d.val + d.len, 1, chunksize, f);\n+\n+\t\tif (ferror(f))\n+\t\t\tdie(\"Error reading file into data: %s\", strerror(errno));\n+\n+\t\tif (d.len + ret < d.len)\n+\t\t\tdie(\"Overflow reading file into data\\n\");\n+\n+\t\td.len += ret;\n+\t}\n+\n+\treturn d;\n+}\n+\n+struct data data_append_data(struct data d, const void *p, int len)\n+{\n+\td = data_grow_for(d, len);\n+\tmemcpy(d.val + d.len, p, len);\n+\td.len += len;\n+\treturn d;\n+}\n+\n+struct data data_insert_at_marker(struct data d, struct marker *m,\n+\t\t\t\t const void *p, int len)\n+{\n+\td = data_grow_for(d, len);\n+\tmemmove(d.val + m->offset + len, d.val + m->offset, d.len - m->offset);\n+\tmemcpy(d.val + m->offset, p, len);\n+\td.len += len;\n+\n+\t/* Adjust all markers after the one we're inserting at */\n+\tm = m->next;\n+\tfor_each_marker(m)\n+\t\tm->offset += len;\n+\treturn d;\n+}\n+\n+static struct data data_append_markers(struct data d, struct marker *m)\n+{\n+\tstruct marker **mp = &d.markers;\n+\n+\t/* Find the end of the markerlist */\n+\twhile (*mp)\n+\t\tmp = &((*mp)->next);\n+\t*mp = m;\n+\treturn d;\n+}\n+\n+struct data data_merge(struct data d1, struct data d2)\n+{\n+\tstruct data d;\n+\tstruct marker *m2 = d2.markers;\n+\n+\td = data_append_markers(data_append_data(d1, d2.val, d2.len), m2);\n+\n+\t/* Adjust for the length of d1 */\n+\tfor_each_marker(m2)\n+\t\tm2->offset += d1.len;\n+\n+\td2.markers = NULL; /* So data_free() doesn't clobber them */\n+\tdata_free(d2);\n+\n+\treturn d;\n+}\n+\n+struct data data_append_integer(struct data d, uint64_t value, int bits)\n+{\n+\tuint8_t value_8;\n+\tuint16_t value_16;\n+\tuint32_t value_32;\n+\tuint64_t value_64;\n+\n+\tswitch (bits) {\n+\tcase 8:\n+\t\tvalue_8 = value;\n+\t\treturn data_append_data(d, &value_8, 1);\n+\n+\tcase 16:\n+\t\tvalue_16 = cpu_to_fdt16(value);\n+\t\treturn data_append_data(d, &value_16, 2);\n+\n+\tcase 32:\n+\t\tvalue_32 = cpu_to_fdt32(value);\n+\t\treturn data_append_data(d, &value_32, 4);\n+\n+\tcase 64:\n+\t\tvalue_64 = cpu_to_fdt64(value);\n+\t\treturn data_append_data(d, &value_64, 8);\n+\n+\tdefault:\n+\t\tdie(\"Invalid literal size (%d)\\n\", bits);\n+\t}\n+}\n+\n+struct data data_append_re(struct data d, const struct fdt_reserve_entry *re)\n+{\n+\tstruct fdt_reserve_entry bere;\n+\n+\tbere.address = cpu_to_fdt64(re->address);\n+\tbere.size = cpu_to_fdt64(re->size);\n+\n+\treturn data_append_data(d, &bere, sizeof(bere));\n+}\n+\n+struct data data_append_cell(struct data d, cell_t word)\n+{\n+\treturn data_append_integer(d, word, sizeof(word) * 8);\n+}\n+\n+struct data data_append_addr(struct data d, uint64_t addr)\n+{\n+\treturn data_append_integer(d, addr, sizeof(addr) * 8);\n+}\n+\n+struct data data_append_byte(struct data d, uint8_t byte)\n+{\n+\treturn data_append_data(d, &byte, 1);\n+}\n+\n+struct data data_append_zeroes(struct data d, int len)\n+{\n+\td = data_grow_for(d, len);\n+\n+\tmemset(d.val + d.len, 0, len);\n+\td.len += len;\n+\treturn d;\n+}\n+\n+struct data data_append_align(struct data d, int align)\n+{\n+\tint newlen = ALIGN(d.len, align);\n+\treturn data_append_zeroes(d, newlen - d.len);\n+}\n+\n+struct data data_add_marker(struct data d, enum markertype type, char *ref)\n+{\n+\tstruct marker *m;\n+\n+\tm = xmalloc(sizeof(*m));\n+\tm->offset = d.len;\n+\tm->type = type;\n+\tm->ref = ref;\n+\tm->next = NULL;\n+\n+\treturn data_append_markers(d, m);\n+}\n+\n+bool data_is_one_string(struct data d)\n+{\n+\tint i;\n+\tint len = d.len;\n+\n+\tif (len == 0)\n+\t\treturn false;\n+\n+\tfor (i = 0; i < len-1; i++)\n+\t\tif (d.val[i] == '\\0')\n+\t\t\treturn false;\n+\n+\tif (d.val[len-1] != '\\0')\n+\t\treturn false;\n+\n+\treturn true;\n+}\ndiff --git a/scripts/dtc/dtc-lexer.l b/scripts/dtc/dtc-lexer.l\nnew file mode 100644\nindex 000000000000..52bed7b74940\n--- /dev/null\n+++ b/scripts/dtc/dtc-lexer.l\n@@ -0,0 +1,311 @@\n+/*\n+ * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.\n+ *\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License as\n+ * published by the Free Software Foundation; either version 2 of the\n+ * License, or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\n+ * USA\n+ */\n+\n+%option noyywrap nounput noinput never-interactive\n+\n+%x BYTESTRING\n+%x PROPNODENAME\n+%s V1\n+\n+PROPNODECHAR\t[a-zA-Z0-9,._+*#?@-]\n+PATHCHAR\t({PROPNODECHAR}|[/])\n+LABEL\t\t[a-zA-Z_][a-zA-Z0-9_]*\n+STRING\t\t\\\"([^\\\\\"]|\\\\.)*\\\"\n+CHAR_LITERAL\t'([^']|\\\\')*'\n+WS\t\t[[:space:]]\n+COMMENT\t\t\"/*\"([^*]|\\*+[^*/])*\\*+\"/\"\n+LINECOMMENT\t\"//\".*\\n\n+\n+%{\n+#include \"dtc.h\"\n+#include \"srcpos.h\"\n+#include \"dtc-parser.tab.h\"\n+\n+YYLTYPE yylloc;\n+extern bool treesource_error;\n+\n+/* CAUTION: this will stop working if we ever use yyless() or yyunput() */\n+#define\tYY_USER_ACTION \\\n+\t{ \\\n+\t\tsrcpos_update(&yylloc, yytext, yyleng); \\\n+\t}\n+\n+/*#define LEXDEBUG\t1*/\n+\n+#ifdef LEXDEBUG\n+#define DPRINT(fmt, ...)\tfprintf(stderr, fmt, ##__VA_ARGS__)\n+#else\n+#define DPRINT(fmt, ...)\tdo { } while (0)\n+#endif\n+\n+static int dts_version = 1;\n+\n+#define BEGIN_DEFAULT()\t\tDPRINT(\"<V1>\\n\"); \\\n+\t\t\t\tBEGIN(V1); \\\n+\n+static void push_input_file(const char *filename);\n+static bool pop_input_file(void);\n+#ifdef __GNUC__\n+static void lexical_error(const char *fmt, ...)\n+\t__attribute__((format (printf, 1, 2)));\n+#else\n+static void lexical_error(const char *fmt, ...);\n+#endif\n+\n+%}\n+\n+%%\n+<*>\"/include/\"{WS}*{STRING} {\n+\t\t\tchar *name = strchr(yytext, '\\\"') + 1;\n+\t\t\tyytext[yyleng-1] = '\\0';\n+\t\t\tpush_input_file(name);\n+\t\t}\n+\n+<*>^\"#\"(line)?[ \\t]+[0-9]+[ \\t]+{STRING}([ \\t]+[0-9]+)? {\n+\t\t\tchar *line, *fnstart, *fnend;\n+\t\t\tstruct data fn;\n+\t\t\t/* skip text before line # */\n+\t\t\tline = yytext;\n+\t\t\twhile (!isdigit((unsigned char)*line))\n+\t\t\t\tline++;\n+\n+\t\t\t/* regexp ensures that first and list \"\n+\t\t\t * in the whole yytext are those at\n+\t\t\t * beginning and end of the filename string */\n+\t\t\tfnstart = memchr(yytext, '\"', yyleng);\n+\t\t\tfor (fnend = yytext + yyleng - 1;\n+\t\t\t *fnend != '\"'; fnend--)\n+\t\t\t\t;\n+\t\t\tassert(fnstart && fnend && (fnend > fnstart));\n+\n+\t\t\tfn = data_copy_escape_string(fnstart + 1,\n+\t\t\t\t\t\t fnend - fnstart - 1);\n+\n+\t\t\t/* Don't allow nuls in filenames */\n+\t\t\tif (memchr(fn.val, '\\0', fn.len - 1))\n+\t\t\t\tlexical_error(\"nul in line number directive\");\n+\n+\t\t\t/* -1 since #line is the number of the next line */\n+\t\t\tsrcpos_set_line(xstrdup(fn.val), atoi(line) - 1);\n+\t\t\tdata_free(fn);\n+\t\t}\n+\n+<*><<EOF>>\t\t{\n+\t\t\tif (!pop_input_file()) {\n+\t\t\t\tyyterminate();\n+\t\t\t}\n+\t\t}\n+\n+<*>{STRING}\t{\n+\t\t\tDPRINT(\"String: %s\\n\", yytext);\n+\t\t\tyylval.data = data_copy_escape_string(yytext+1,\n+\t\t\t\t\tyyleng-2);\n+\t\t\treturn DT_STRING;\n+\t\t}\n+\n+<*>\"/dts-v1/\"\t{\n+\t\t\tDPRINT(\"Keyword: /dts-v1/\\n\");\n+\t\t\tdts_version = 1;\n+\t\t\tBEGIN_DEFAULT();\n+\t\t\treturn DT_V1;\n+\t\t}\n+\n+<*>\"/plugin/\"\t{\n+\t\t\tDPRINT(\"Keyword: /plugin/\\n\");\n+\t\t\treturn DT_PLUGIN;\n+\t\t}\n+\n+<*>\"/memreserve/\"\t{\n+\t\t\tDPRINT(\"Keyword: /memreserve/\\n\");\n+\t\t\tBEGIN_DEFAULT();\n+\t\t\treturn DT_MEMRESERVE;\n+\t\t}\n+\n+<*>\"/bits/\"\t{\n+\t\t\tDPRINT(\"Keyword: /bits/\\n\");\n+\t\t\tBEGIN_DEFAULT();\n+\t\t\treturn DT_BITS;\n+\t\t}\n+\n+<*>\"/delete-property/\"\t{\n+\t\t\tDPRINT(\"Keyword: /delete-property/\\n\");\n+\t\t\tDPRINT(\"<PROPNODENAME>\\n\");\n+\t\t\tBEGIN(PROPNODENAME);\n+\t\t\treturn DT_DEL_PROP;\n+\t\t}\n+\n+<*>\"/delete-node/\"\t{\n+\t\t\tDPRINT(\"Keyword: /delete-node/\\n\");\n+\t\t\tDPRINT(\"<PROPNODENAME>\\n\");\n+\t\t\tBEGIN(PROPNODENAME);\n+\t\t\treturn DT_DEL_NODE;\n+\t\t}\n+\n+<*>{LABEL}:\t{\n+\t\t\tDPRINT(\"Label: %s\\n\", yytext);\n+\t\t\tyylval.labelref = xstrdup(yytext);\n+\t\t\tyylval.labelref[yyleng-1] = '\\0';\n+\t\t\treturn DT_LABEL;\n+\t\t}\n+\n+<V1>([0-9]+|0[xX][0-9a-fA-F]+)(U|L|UL|LL|ULL)? {\n+\t\t\tchar *e;\n+\t\t\tDPRINT(\"Integer Literal: '%s'\\n\", yytext);\n+\n+\t\t\terrno = 0;\n+\t\t\tyylval.integer = strtoull(yytext, &e, 0);\n+\n+\t\t\tif (*e && e[strspn(e, \"UL\")]) {\n+\t\t\t\tlexical_error(\"Bad integer literal '%s'\",\n+\t\t\t\t\t yytext);\n+\t\t\t}\n+\n+\t\t\tif (errno == ERANGE)\n+\t\t\t\tlexical_error(\"Integer literal '%s' out of range\",\n+\t\t\t\t\t yytext);\n+\t\t\telse\n+\t\t\t\t/* ERANGE is the only strtoull error triggerable\n+\t\t\t\t * by strings matching the pattern */\n+\t\t\t\tassert(errno == 0);\n+\t\t\treturn DT_LITERAL;\n+\t\t}\n+\n+<*>{CHAR_LITERAL}\t{\n+\t\t\tstruct data d;\n+\t\t\tDPRINT(\"Character literal: %s\\n\", yytext);\n+\n+\t\t\td = data_copy_escape_string(yytext+1, yyleng-2);\n+\t\t\tif (d.len == 1) {\n+\t\t\t\tlexical_error(\"Empty character literal\");\n+\t\t\t\tyylval.integer = 0;\n+\t\t\t} else {\n+\t\t\t\tyylval.integer = (unsigned char)d.val[0];\n+\n+\t\t\t\tif (d.len > 2)\n+\t\t\t\t\tlexical_error(\"Character literal has %d\"\n+\t\t\t\t\t\t \" characters instead of 1\",\n+\t\t\t\t\t\t d.len - 1);\n+\t\t\t}\n+\n+\t\t\tdata_free(d);\n+\t\t\treturn DT_CHAR_LITERAL;\n+\t\t}\n+\n+<*>\\&{LABEL}\t{\t/* label reference */\n+\t\t\tDPRINT(\"Ref: %s\\n\", yytext+1);\n+\t\t\tyylval.labelref = xstrdup(yytext+1);\n+\t\t\treturn DT_REF;\n+\t\t}\n+\n+<*>\"&{/\"{PATHCHAR}*\\}\t{\t/* new-style path reference */\n+\t\t\tyytext[yyleng-1] = '\\0';\n+\t\t\tDPRINT(\"Ref: %s\\n\", yytext+2);\n+\t\t\tyylval.labelref = xstrdup(yytext+2);\n+\t\t\treturn DT_REF;\n+\t\t}\n+\n+<BYTESTRING>[0-9a-fA-F]{2} {\n+\t\t\tyylval.byte = strtol(yytext, NULL, 16);\n+\t\t\tDPRINT(\"Byte: %02x\\n\", (int)yylval.byte);\n+\t\t\treturn DT_BYTE;\n+\t\t}\n+\n+<BYTESTRING>\"]\"\t{\n+\t\t\tDPRINT(\"/BYTESTRING\\n\");\n+\t\t\tBEGIN_DEFAULT();\n+\t\t\treturn ']';\n+\t\t}\n+\n+<PROPNODENAME>\\\\?{PROPNODECHAR}+ {\n+\t\t\tDPRINT(\"PropNodeName: %s\\n\", yytext);\n+\t\t\tyylval.propnodename = xstrdup((yytext[0] == '\\\\') ?\n+\t\t\t\t\t\t\tyytext + 1 : yytext);\n+\t\t\tBEGIN_DEFAULT();\n+\t\t\treturn DT_PROPNODENAME;\n+\t\t}\n+\n+\"/incbin/\"\t{\n+\t\t\tDPRINT(\"Binary Include\\n\");\n+\t\t\treturn DT_INCBIN;\n+\t\t}\n+\n+<*>{WS}+\t/* eat whitespace */\n+<*>{COMMENT}+\t/* eat C-style comments */\n+<*>{LINECOMMENT}+ /* eat C++-style comments */\n+\n+<*>\"<<\"\t\t{ return DT_LSHIFT; };\n+<*>\">>\"\t\t{ return DT_RSHIFT; };\n+<*>\"<=\"\t\t{ return DT_LE; };\n+<*>\">=\"\t\t{ return DT_GE; };\n+<*>\"==\"\t\t{ return DT_EQ; };\n+<*>\"!=\"\t\t{ return DT_NE; };\n+<*>\"&&\"\t\t{ return DT_AND; };\n+<*>\"||\"\t\t{ return DT_OR; };\n+\n+<*>.\t\t{\n+\t\t\tDPRINT(\"Char: %c (\\\\x%02x)\\n\", yytext[0],\n+\t\t\t\t(unsigned)yytext[0]);\n+\t\t\tif (yytext[0] == '[') {\n+\t\t\t\tDPRINT(\"<BYTESTRING>\\n\");\n+\t\t\t\tBEGIN(BYTESTRING);\n+\t\t\t}\n+\t\t\tif ((yytext[0] == '{')\n+\t\t\t || (yytext[0] == ';')) {\n+\t\t\t\tDPRINT(\"<PROPNODENAME>\\n\");\n+\t\t\t\tBEGIN(PROPNODENAME);\n+\t\t\t}\n+\t\t\treturn yytext[0];\n+\t\t}\n+\n+%%\n+\n+static void push_input_file(const char *filename)\n+{\n+\tassert(filename);\n+\n+\tsrcfile_push(filename);\n+\n+\tyyin = current_srcfile->f;\n+\n+\tyypush_buffer_state(yy_create_buffer(yyin, YY_BUF_SIZE));\n+}\n+\n+\n+static bool pop_input_file(void)\n+{\n+\tif (srcfile_pop() == 0)\n+\t\treturn false;\n+\n+\tyypop_buffer_state();\n+\tyyin = current_srcfile->f;\n+\n+\treturn true;\n+}\n+\n+static void lexical_error(const char *fmt, ...)\n+{\n+\tva_list ap;\n+\n+\tva_start(ap, fmt);\n+\tsrcpos_verror(&yylloc, \"Lexical error\", fmt, ap);\n+\tva_end(ap);\n+\n+\ttreesource_error = true;\n+}\ndiff --git a/scripts/dtc/dtc-lexer.lex.c_shipped b/scripts/dtc/dtc-lexer.lex.c_shipped\nnew file mode 100644\nindex 000000000000..d77fdfe59059\n--- /dev/null\n+++ b/scripts/dtc/dtc-lexer.lex.c_shipped\n@@ -0,0 +1,2260 @@\n+#line 2 \"dtc-lexer.lex.c\"\n+\n+#line 4 \"dtc-lexer.lex.c\"\n+\n+#define YY_INT_ALIGNED short int\n+\n+/* A lexical scanner generated by flex */\n+\n+#define FLEX_SCANNER\n+#define YY_FLEX_MAJOR_VERSION 2\n+#define YY_FLEX_MINOR_VERSION 5\n+#define YY_FLEX_SUBMINOR_VERSION 35\n+#if YY_FLEX_SUBMINOR_VERSION > 0\n+#define FLEX_BETA\n+#endif\n+\n+/* First, we deal with platform-specific or compiler-specific issues. */\n+\n+/* begin standard C headers. */\n+#include <stdio.h>\n+#include <string.h>\n+#include <errno.h>\n+#include <stdlib.h>\n+\n+/* end standard C headers. */\n+\n+/* flex integer type definitions */\n+\n+#ifndef FLEXINT_H\n+#define FLEXINT_H\n+\n+/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */\n+\n+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L\n+\n+/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,\n+ * if you want the limit (max/min) macros for int types. \n+ */\n+#ifndef __STDC_LIMIT_MACROS\n+#define __STDC_LIMIT_MACROS 1\n+#endif\n+\n+#include <inttypes.h>\n+typedef int8_t flex_int8_t;\n+typedef uint8_t flex_uint8_t;\n+typedef int16_t flex_int16_t;\n+typedef uint16_t flex_uint16_t;\n+typedef int32_t flex_int32_t;\n+typedef uint32_t flex_uint32_t;\n+#else\n+typedef signed char flex_int8_t;\n+typedef short int flex_int16_t;\n+typedef int flex_int32_t;\n+typedef unsigned char flex_uint8_t; \n+typedef unsigned short int flex_uint16_t;\n+typedef unsigned int flex_uint32_t;\n+\n+/* Limits of integral types. */\n+#ifndef INT8_MIN\n+#define INT8_MIN (-128)\n+#endif\n+#ifndef INT16_MIN\n+#define INT16_MIN (-32767-1)\n+#endif\n+#ifndef INT32_MIN\n+#define INT32_MIN (-2147483647-1)\n+#endif\n+#ifndef INT8_MAX\n+#define INT8_MAX (127)\n+#endif\n+#ifndef INT16_MAX\n+#define INT16_MAX (32767)\n+#endif\n+#ifndef INT32_MAX\n+#define INT32_MAX (2147483647)\n+#endif\n+#ifndef UINT8_MAX\n+#define UINT8_MAX (255U)\n+#endif\n+#ifndef UINT16_MAX\n+#define UINT16_MAX (65535U)\n+#endif\n+#ifndef UINT32_MAX\n+#define UINT32_MAX (4294967295U)\n+#endif\n+\n+#endif /* ! C99 */\n+\n+#endif /* ! FLEXINT_H */\n+\n+#ifdef __cplusplus\n+\n+/* The \"const\" storage-class-modifier is valid. */\n+#define YY_USE_CONST\n+\n+#else\t/* ! __cplusplus */\n+\n+/* C99 requires __STDC__ to be defined as 1. */\n+#if defined (__STDC__)\n+\n+#define YY_USE_CONST\n+\n+#endif\t/* defined (__STDC__) */\n+#endif\t/* ! __cplusplus */\n+\n+#ifdef YY_USE_CONST\n+#define yyconst const\n+#else\n+#define yyconst\n+#endif\n+\n+/* Returned upon end-of-file. */\n+#define YY_NULL 0\n+\n+/* Promotes a possibly negative, possibly signed char to an unsigned\n+ * integer for use as an array index. If the signed char is negative,\n+ * we want to instead treat it as an 8-bit unsigned char, hence the\n+ * double cast.\n+ */\n+#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)\n+\n+/* Enter a start condition. This macro really ought to take a parameter,\n+ * but we do it the disgusting crufty way forced on us by the ()-less\n+ * definition of BEGIN.\n+ */\n+#define BEGIN (yy_start) = 1 + 2 *\n+\n+/* Translate the current start state into a value that can be later handed\n+ * to BEGIN to return to the state. The YYSTATE alias is for lex\n+ * compatibility.\n+ */\n+#define YY_START (((yy_start) - 1) / 2)\n+#define YYSTATE YY_START\n+\n+/* Action number for EOF rule of a given start state. */\n+#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)\n+\n+/* Special action meaning \"start processing a new file\". */\n+#define YY_NEW_FILE yyrestart(yyin )\n+\n+#define YY_END_OF_BUFFER_CHAR 0\n+\n+/* Size of default input buffer. */\n+#ifndef YY_BUF_SIZE\n+#ifdef __ia64__\n+/* On IA-64, the buffer size is 16k, not 8k.\n+ * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.\n+ * Ditto for the __ia64__ case accordingly.\n+ */\n+#define YY_BUF_SIZE 32768\n+#else\n+#define YY_BUF_SIZE 16384\n+#endif /* __ia64__ */\n+#endif\n+\n+/* The state buf must be large enough to hold one state per character in the main buffer.\n+ */\n+#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))\n+\n+#ifndef YY_TYPEDEF_YY_BUFFER_STATE\n+#define YY_TYPEDEF_YY_BUFFER_STATE\n+typedef struct yy_buffer_state *YY_BUFFER_STATE;\n+#endif\n+\n+extern int yyleng;\n+\n+extern FILE *yyin, *yyout;\n+\n+#define EOB_ACT_CONTINUE_SCAN 0\n+#define EOB_ACT_END_OF_FILE 1\n+#define EOB_ACT_LAST_MATCH 2\n+\n+ #define YY_LESS_LINENO(n)\n+ \n+/* Return all but the first \"n\" matched characters back to the input stream. */\n+#define yyless(n) \\\n+\tdo \\\n+\t\t{ \\\n+\t\t/* Undo effects of setting up yytext. */ \\\n+ int yyless_macro_arg = (n); \\\n+ YY_LESS_LINENO(yyless_macro_arg);\\\n+\t\t*yy_cp = (yy_hold_char); \\\n+\t\tYY_RESTORE_YY_MORE_OFFSET \\\n+\t\t(yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \\\n+\t\tYY_DO_BEFORE_ACTION; /* set up yytext again */ \\\n+\t\t} \\\n+\twhile ( 0 )\n+\n+#define unput(c) yyunput( c, (yytext_ptr) )\n+\n+#ifndef YY_TYPEDEF_YY_SIZE_T\n+#define YY_TYPEDEF_YY_SIZE_T\n+typedef size_t yy_size_t;\n+#endif\n+\n+#ifndef YY_STRUCT_YY_BUFFER_STATE\n+#define YY_STRUCT_YY_BUFFER_STATE\n+struct yy_buffer_state\n+\t{\n+\tFILE *yy_input_file;\n+\n+\tchar *yy_ch_buf;\t\t/* input buffer */\n+\tchar *yy_buf_pos;\t\t/* current position in input buffer */\n+\n+\t/* Size of input buffer in bytes, not including room for EOB\n+\t * characters.\n+\t */\n+\tyy_size_t yy_buf_size;\n+\n+\t/* Number of characters read into yy_ch_buf, not including EOB\n+\t * characters.\n+\t */\n+\tint yy_n_chars;\n+\n+\t/* Whether we \"own\" the buffer - i.e., we know we created it,\n+\t * and can realloc() it to grow it, and should free() it to\n+\t * delete it.\n+\t */\n+\tint yy_is_our_buffer;\n+\n+\t/* Whether this is an \"interactive\" input source; if so, and\n+\t * if we're using stdio for input, then we want to use getc()\n+\t * instead of fread(), to make sure we stop fetching input after\n+\t * each newline.\n+\t */\n+\tint yy_is_interactive;\n+\n+\t/* Whether we're considered to be at the beginning of a line.\n+\t * If so, '^' rules will be active on the next match, otherwise\n+\t * not.\n+\t */\n+\tint yy_at_bol;\n+\n+ int yy_bs_lineno; /**< The line count. */\n+ int yy_bs_column; /**< The column count. */\n+ \n+\t/* Whether to try to fill the input buffer when we reach the\n+\t * end of it.\n+\t */\n+\tint yy_fill_buffer;\n+\n+\tint yy_buffer_status;\n+\n+#define YY_BUFFER_NEW 0\n+#define YY_BUFFER_NORMAL 1\n+\t/* When an EOF's been seen but there's still some text to process\n+\t * then we mark the buffer as YY_EOF_PENDING, to indicate that we\n+\t * shouldn't try reading from the input source any more. We might\n+\t * still have a bunch of tokens to match, though, because of\n+\t * possible backing-up.\n+\t *\n+\t * When we actually see the EOF, we change the status to \"new\"\n+\t * (via yyrestart()), so that the user can continue scanning by\n+\t * just pointing yyin at a new input file.\n+\t */\n+#define YY_BUFFER_EOF_PENDING 2\n+\n+\t};\n+#endif /* !YY_STRUCT_YY_BUFFER_STATE */\n+\n+/* Stack of input buffers. */\n+static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */\n+static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */\n+static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */\n+\n+/* We provide macros for accessing buffer states in case in the\n+ * future we want to put the buffer states in a more general\n+ * \"scanner state\".\n+ *\n+ * Returns the top of the stack, or NULL.\n+ */\n+#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \\\n+ ? (yy_buffer_stack)[(yy_buffer_stack_top)] \\\n+ : NULL)\n+\n+/* Same as previous macro, but useful when we know that the buffer stack is not\n+ * NULL or when we need an lvalue. For internal use only.\n+ */\n+#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)]\n+\n+/* yy_hold_char holds the character lost when yytext is formed. */\n+static char yy_hold_char;\n+static int yy_n_chars;\t\t/* number of characters read into yy_ch_buf */\n+int yyleng;\n+\n+/* Points to current character in buffer. */\n+static char *yy_c_buf_p = (char *) 0;\n+static int yy_init = 0;\t\t/* whether we need to initialize */\n+static int yy_start = 0;\t/* start state number */\n+\n+/* Flag which is used to allow yywrap()'s to do buffer switches\n+ * instead of setting up a fresh yyin. A bit of a hack ...\n+ */\n+static int yy_did_buffer_switch_on_eof;\n+\n+void yyrestart (FILE *input_file );\n+void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer );\n+YY_BUFFER_STATE yy_create_buffer (FILE *file,int size );\n+void yy_delete_buffer (YY_BUFFER_STATE b );\n+void yy_flush_buffer (YY_BUFFER_STATE b );\n+void yypush_buffer_state (YY_BUFFER_STATE new_buffer );\n+void yypop_buffer_state (void );\n+\n+static void yyensure_buffer_stack (void );\n+static void yy_load_buffer_state (void );\n+static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file );\n+\n+#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER )\n+\n+YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size );\n+YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str );\n+YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,int len );\n+\n+void *yyalloc (yy_size_t );\n+void *yyrealloc (void *,yy_size_t );\n+void yyfree (void * );\n+\n+#define yy_new_buffer yy_create_buffer\n+\n+#define yy_set_interactive(is_interactive) \\\n+\t{ \\\n+\tif ( ! YY_CURRENT_BUFFER ){ \\\n+ yyensure_buffer_stack (); \\\n+\t\tYY_CURRENT_BUFFER_LVALUE = \\\n+ yy_create_buffer(yyin,YY_BUF_SIZE ); \\\n+\t} \\\n+\tYY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \\\n+\t}\n+\n+#define yy_set_bol(at_bol) \\\n+\t{ \\\n+\tif ( ! YY_CURRENT_BUFFER ){\\\n+ yyensure_buffer_stack (); \\\n+\t\tYY_CURRENT_BUFFER_LVALUE = \\\n+ yy_create_buffer(yyin,YY_BUF_SIZE ); \\\n+\t} \\\n+\tYY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \\\n+\t}\n+\n+#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)\n+\n+/* Begin user sect3 */\n+\n+#define yywrap(n) 1\n+#define YY_SKIP_YYWRAP\n+\n+typedef unsigned char YY_CHAR;\n+\n+FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;\n+\n+typedef int yy_state_type;\n+\n+extern int yylineno;\n+\n+int yylineno = 1;\n+\n+extern char *yytext;\n+#define yytext_ptr yytext\n+\n+static yy_state_type yy_get_previous_state (void );\n+static yy_state_type yy_try_NUL_trans (yy_state_type current_state );\n+static int yy_get_next_buffer (void );\n+static void yy_fatal_error (yyconst char msg[] );\n+\n+/* Done after the current pattern has been matched and before the\n+ * corresponding action - sets up yytext.\n+ */\n+#define YY_DO_BEFORE_ACTION \\\n+\t(yytext_ptr) = yy_bp; \\\n+\tyyleng = (size_t) (yy_cp - yy_bp); \\\n+\t(yy_hold_char) = *yy_cp; \\\n+\t*yy_cp = '\\0'; \\\n+\t(yy_c_buf_p) = yy_cp;\n+\n+#define YY_NUM_RULES 31\n+#define YY_END_OF_BUFFER 32\n+/* This struct is not used in this scanner,\n+ but its presence is necessary. */\n+struct yy_trans_info\n+\t{\n+\tflex_int32_t yy_verify;\n+\tflex_int32_t yy_nxt;\n+\t};\n+static yyconst flex_int16_t yy_accept[166] =\n+ { 0,\n+ 0, 0, 0, 0, 0, 0, 0, 0, 32, 30,\n+ 19, 19, 30, 30, 30, 30, 30, 30, 30, 30,\n+ 30, 30, 30, 30, 30, 30, 16, 17, 17, 30,\n+ 17, 11, 11, 19, 27, 0, 3, 0, 28, 13,\n+ 0, 0, 12, 0, 0, 0, 0, 0, 0, 0,\n+ 0, 22, 24, 26, 25, 23, 0, 10, 29, 0,\n+ 0, 0, 15, 15, 17, 17, 17, 11, 11, 11,\n+ 0, 13, 0, 12, 0, 0, 0, 21, 0, 0,\n+ 0, 0, 0, 0, 0, 0, 0, 17, 11, 11,\n+ 11, 0, 14, 20, 0, 0, 0, 0, 0, 0,\n+\n+ 0, 0, 0, 0, 17, 0, 0, 0, 0, 0,\n+ 0, 0, 0, 0, 0, 17, 7, 0, 0, 0,\n+ 0, 0, 0, 0, 2, 0, 0, 0, 0, 0,\n+ 0, 0, 0, 0, 4, 18, 0, 0, 5, 2,\n+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n+ 0, 0, 1, 0, 0, 0, 0, 6, 9, 0,\n+ 0, 0, 0, 8, 0\n+ } ;\n+\n+static yyconst flex_int32_t yy_ec[256] =\n+ { 0,\n+ 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,\n+ 4, 4, 4, 1, 1, 1, 1, 1, 1, 1,\n+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n+ 1, 2, 5, 6, 7, 1, 1, 8, 9, 1,\n+ 1, 10, 11, 11, 12, 11, 13, 14, 15, 16,\n+ 16, 16, 16, 16, 16, 16, 16, 17, 1, 18,\n+ 19, 20, 11, 11, 21, 21, 21, 21, 21, 21,\n+ 22, 22, 22, 22, 22, 23, 22, 22, 22, 22,\n+ 22, 22, 22, 22, 24, 22, 22, 25, 22, 22,\n+ 1, 26, 27, 1, 22, 1, 21, 28, 29, 30,\n+\n+ 31, 21, 32, 22, 33, 22, 22, 34, 35, 36,\n+ 37, 38, 22, 39, 40, 41, 42, 43, 22, 25,\n+ 44, 22, 45, 46, 47, 1, 1, 1, 1, 1,\n+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n+\n+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n+ 1, 1, 1, 1, 1\n+ } ;\n+\n+static yyconst flex_int32_t yy_meta[48] =\n+ { 0,\n+ 1, 1, 1, 1, 1, 1, 2, 3, 1, 2,\n+ 2, 2, 4, 5, 5, 5, 6, 1, 1, 1,\n+ 7, 8, 8, 8, 8, 1, 1, 7, 7, 7,\n+ 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,\n+ 8, 8, 8, 8, 3, 1, 4\n+ } ;\n+\n+static yyconst flex_int16_t yy_base[180] =\n+ { 0,\n+ 0, 393, 35, 392, 66, 391, 38, 107, 397, 401,\n+ 55, 113, 377, 112, 111, 111, 114, 42, 376, 106,\n+ 377, 347, 126, 120, 0, 147, 401, 0, 124, 0,\n+ 137, 158, 170, 163, 401, 153, 401, 389, 401, 0,\n+ 378, 120, 401, 131, 380, 386, 355, 139, 351, 355,\n+ 351, 401, 401, 401, 401, 401, 367, 401, 401, 185,\n+ 350, 346, 401, 364, 0, 185, 347, 189, 356, 355,\n+ 0, 0, 330, 180, 366, 141, 372, 361, 332, 338,\n+ 331, 341, 334, 326, 205, 331, 337, 329, 401, 341,\n+ 167, 316, 401, 349, 348, 320, 328, 346, 180, 318,\n+\n+ 324, 209, 324, 320, 322, 342, 338, 309, 306, 315,\n+ 305, 315, 312, 192, 342, 341, 401, 293, 306, 282,\n+ 268, 252, 255, 203, 285, 282, 272, 268, 252, 233,\n+ 232, 239, 208, 107, 401, 401, 238, 211, 401, 211,\n+ 212, 208, 228, 203, 215, 207, 233, 222, 212, 211,\n+ 203, 227, 401, 237, 225, 204, 185, 401, 401, 149,\n+ 128, 88, 42, 401, 401, 253, 259, 267, 271, 275,\n+ 281, 288, 292, 300, 308, 312, 318, 326, 334\n+ } ;\n+\n+static yyconst flex_int16_t yy_def[180] =\n+ { 0,\n+ 165, 1, 1, 3, 165, 5, 1, 1, 165, 165,\n+ 165, 165, 165, 166, 167, 168, 165, 165, 165, 165,\n+ 169, 165, 165, 165, 170, 169, 165, 171, 172, 171,\n+ 171, 165, 165, 165, 165, 166, 165, 166, 165, 173,\n+ 165, 168, 165, 168, 174, 175, 165, 165, 165, 165,\n+ 165, 165, 165, 165, 165, 165, 169, 165, 165, 165,\n+ 165, 165, 165, 169, 171, 172, 171, 165, 165, 165,\n+ 176, 173, 177, 168, 174, 174, 175, 165, 165, 165,\n+ 165, 165, 165, 165, 165, 165, 165, 171, 165, 165,\n+ 176, 177, 165, 165, 165, 165, 165, 165, 165, 165,\n+\n+ 165, 165, 165, 165, 171, 165, 165, 165, 165, 165,\n+ 165, 165, 165, 178, 165, 171, 165, 165, 165, 165,\n+ 165, 165, 165, 178, 165, 178, 165, 165, 165, 165,\n+ 165, 165, 165, 165, 165, 165, 165, 165, 165, 165,\n+ 165, 165, 165, 165, 165, 165, 165, 179, 165, 165,\n+ 165, 179, 165, 179, 165, 165, 165, 165, 165, 165,\n+ 165, 165, 165, 165, 0, 165, 165, 165, 165, 165,\n+ 165, 165, 165, 165, 165, 165, 165, 165, 165\n+ } ;\n+\n+static yyconst flex_int16_t yy_nxt[449] =\n+ { 0,\n+ 10, 11, 12, 11, 13, 14, 10, 15, 16, 10,\n+ 10, 10, 17, 10, 10, 10, 10, 18, 19, 20,\n+ 21, 21, 21, 21, 21, 10, 10, 21, 21, 21,\n+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,\n+ 21, 21, 21, 21, 10, 22, 10, 24, 25, 25,\n+ 25, 32, 33, 33, 164, 26, 34, 34, 34, 52,\n+ 53, 27, 26, 26, 26, 26, 10, 11, 12, 11,\n+ 13, 14, 28, 15, 16, 28, 28, 28, 24, 28,\n+ 28, 28, 10, 18, 19, 20, 29, 29, 29, 29,\n+ 29, 30, 10, 29, 29, 29, 29, 29, 29, 29,\n+\n+ 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,\n+ 10, 22, 10, 23, 34, 34, 34, 37, 39, 43,\n+ 32, 33, 33, 45, 55, 56, 46, 60, 43, 45,\n+ 65, 163, 46, 65, 65, 65, 44, 38, 60, 74,\n+ 58, 47, 141, 48, 142, 44, 49, 47, 50, 48,\n+ 76, 51, 62, 94, 50, 41, 44, 51, 37, 61,\n+ 64, 64, 64, 58, 34, 34, 34, 64, 162, 80,\n+ 67, 68, 68, 68, 64, 64, 64, 64, 38, 81,\n+ 69, 70, 71, 68, 68, 68, 60, 161, 43, 69,\n+ 70, 65, 69, 70, 65, 65, 65, 125, 85, 85,\n+\n+ 85, 58, 68, 68, 68, 44, 102, 110, 125, 133,\n+ 102, 69, 70, 111, 114, 160, 159, 126, 85, 85,\n+ 85, 140, 140, 140, 140, 140, 140, 153, 126, 147,\n+ 147, 147, 153, 148, 147, 147, 147, 158, 148, 165,\n+ 157, 156, 155, 151, 150, 149, 146, 154, 145, 144,\n+ 143, 139, 154, 36, 36, 36, 36, 36, 36, 36,\n+ 36, 40, 138, 137, 136, 40, 40, 42, 42, 42,\n+ 42, 42, 42, 42, 42, 57, 57, 57, 57, 63,\n+ 135, 63, 65, 134, 165, 65, 133, 65, 65, 66,\n+ 132, 131, 66, 66, 66, 66, 72, 130, 72, 72,\n+\n+ 75, 75, 75, 75, 75, 75, 75, 75, 77, 77,\n+ 77, 77, 77, 77, 77, 77, 91, 129, 91, 92,\n+ 128, 92, 92, 127, 92, 92, 124, 124, 124, 124,\n+ 124, 124, 124, 124, 152, 152, 152, 152, 152, 152,\n+ 152, 152, 60, 60, 123, 122, 121, 120, 119, 118,\n+ 117, 45, 116, 111, 115, 113, 112, 109, 108, 107,\n+ 46, 106, 93, 89, 105, 104, 103, 101, 100, 99,\n+ 98, 97, 96, 95, 78, 76, 93, 90, 89, 88,\n+ 58, 87, 86, 58, 84, 83, 82, 79, 78, 76,\n+ 73, 165, 59, 58, 54, 35, 165, 31, 23, 23,\n+\n+ 9, 165, 165, 165, 165, 165, 165, 165, 165, 165,\n+ 165, 165, 165, 165, 165, 165, 165, 165, 165, 165,\n+ 165, 165, 165, 165, 165, 165, 165, 165, 165, 165,\n+ 165, 165, 165, 165, 165, 165, 165, 165, 165, 165,\n+ 165, 165, 165, 165, 165, 165, 165, 165\n+ } ;\n+\n+static yyconst flex_int16_t yy_chk[449] =\n+ { 0,\n+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n+ 1, 1, 1, 1, 1, 1, 1, 3, 3, 3,\n+ 3, 7, 7, 7, 163, 3, 11, 11, 11, 18,\n+ 18, 3, 3, 3, 3, 3, 5, 5, 5, 5,\n+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,\n+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,\n+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,\n+\n+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,\n+ 5, 5, 5, 8, 12, 12, 12, 14, 15, 16,\n+ 8, 8, 8, 17, 20, 20, 17, 23, 42, 24,\n+ 29, 162, 24, 29, 29, 29, 16, 14, 31, 44,\n+ 29, 17, 134, 17, 134, 42, 17, 24, 17, 24,\n+ 76, 17, 24, 76, 24, 15, 44, 24, 36, 23,\n+ 26, 26, 26, 26, 34, 34, 34, 26, 161, 48,\n+ 31, 32, 32, 32, 26, 26, 26, 26, 36, 48,\n+ 32, 32, 32, 33, 33, 33, 60, 160, 74, 91,\n+ 91, 66, 33, 33, 66, 66, 66, 114, 60, 60,\n+\n+ 60, 66, 68, 68, 68, 74, 85, 99, 124, 133,\n+ 102, 68, 68, 99, 102, 157, 156, 114, 85, 85,\n+ 85, 133, 133, 133, 140, 140, 140, 148, 124, 143,\n+ 143, 143, 152, 143, 147, 147, 147, 155, 147, 154,\n+ 151, 150, 149, 146, 145, 144, 142, 148, 141, 138,\n+ 137, 132, 152, 166, 166, 166, 166, 166, 166, 166,\n+ 166, 167, 131, 130, 129, 167, 167, 168, 168, 168,\n+ 168, 168, 168, 168, 168, 169, 169, 169, 169, 170,\n+ 128, 170, 171, 127, 126, 171, 125, 171, 171, 172,\n+ 123, 122, 172, 172, 172, 172, 173, 121, 173, 173,\n+\n+ 174, 174, 174, 174, 174, 174, 174, 174, 175, 175,\n+ 175, 175, 175, 175, 175, 175, 176, 120, 176, 177,\n+ 119, 177, 177, 118, 177, 177, 178, 178, 178, 178,\n+ 178, 178, 178, 178, 179, 179, 179, 179, 179, 179,\n+ 179, 179, 116, 115, 113, 112, 111, 110, 109, 108,\n+ 107, 106, 105, 104, 103, 101, 100, 98, 97, 96,\n+ 95, 94, 92, 90, 88, 87, 86, 84, 83, 82,\n+ 81, 80, 79, 78, 77, 75, 73, 70, 69, 67,\n+ 64, 62, 61, 57, 51, 50, 49, 47, 46, 45,\n+ 41, 38, 22, 21, 19, 13, 9, 6, 4, 2,\n+\n+ 165, 165, 165, 165, 165, 165, 165, 165, 165, 165,\n+ 165, 165, 165, 165, 165, 165, 165, 165, 165, 165,\n+ 165, 165, 165, 165, 165, 165, 165, 165, 165, 165,\n+ 165, 165, 165, 165, 165, 165, 165, 165, 165, 165,\n+ 165, 165, 165, 165, 165, 165, 165, 165\n+ } ;\n+\n+static yy_state_type yy_last_accepting_state;\n+static char *yy_last_accepting_cpos;\n+\n+extern int yy_flex_debug;\n+int yy_flex_debug = 0;\n+\n+/* The intent behind this definition is that it'll catch\n+ * any uses of REJECT which flex missed.\n+ */\n+#define REJECT reject_used_but_not_detected\n+#define yymore() yymore_used_but_not_detected\n+#define YY_MORE_ADJ 0\n+#define YY_RESTORE_YY_MORE_OFFSET\n+char *yytext;\n+#line 1 \"dtc-lexer.l\"\n+/*\n+ * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.\n+ *\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License as\n+ * published by the Free Software Foundation; either version 2 of the\n+ * License, or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\n+ * USA\n+ */\n+#define YY_NO_INPUT 1\n+\n+\n+\n+#line 37 \"dtc-lexer.l\"\n+#include \"dtc.h\"\n+#include \"srcpos.h\"\n+#include \"dtc-parser.tab.h\"\n+\n+YYLTYPE yylloc;\n+extern bool treesource_error;\n+\n+/* CAUTION: this will stop working if we ever use yyless() or yyunput() */\n+#define\tYY_USER_ACTION \\\n+\t{ \\\n+\t\tsrcpos_update(&yylloc, yytext, yyleng); \\\n+\t}\n+\n+/*#define LEXDEBUG\t1*/\n+\n+#ifdef LEXDEBUG\n+#define DPRINT(fmt, ...)\tfprintf(stderr, fmt, ##__VA_ARGS__)\n+#else\n+#define DPRINT(fmt, ...)\tdo { } while (0)\n+#endif\n+\n+static int dts_version = 1;\n+\n+#define BEGIN_DEFAULT()\t\tDPRINT(\"<V1>\\n\"); \\\n+\t\t\t\tBEGIN(V1); \\\n+\n+static void push_input_file(const char *filename);\n+static bool pop_input_file(void);\n+#ifdef __GNUC__\n+static void lexical_error(const char *fmt, ...)\n+\t__attribute__((format (printf, 1, 2)));\n+#else\n+static void lexical_error(const char *fmt, ...);\n+#endif\n+\n+#line 674 \"dtc-lexer.lex.c\"\n+\n+#define INITIAL 0\n+#define BYTESTRING 1\n+#define PROPNODENAME 2\n+#define V1 3\n+\n+#ifndef YY_NO_UNISTD_H\n+/* Special case for \"unistd.h\", since it is non-ANSI. We include it way\n+ * down here because we want the user's section 1 to have been scanned first.\n+ * The user has a chance to override it with an option.\n+ */\n+#include <unistd.h>\n+#endif\n+\n+#ifndef YY_EXTRA_TYPE\n+#define YY_EXTRA_TYPE void *\n+#endif\n+\n+static int yy_init_globals (void );\n+\n+/* Accessor methods to globals.\n+ These are made visible to non-reentrant scanners for convenience. */\n+\n+int yylex_destroy (void );\n+\n+int yyget_debug (void );\n+\n+void yyset_debug (int debug_flag );\n+\n+YY_EXTRA_TYPE yyget_extra (void );\n+\n+void yyset_extra (YY_EXTRA_TYPE user_defined );\n+\n+FILE *yyget_in (void );\n+\n+void yyset_in (FILE * in_str );\n+\n+FILE *yyget_out (void );\n+\n+void yyset_out (FILE * out_str );\n+\n+int yyget_leng (void );\n+\n+char *yyget_text (void );\n+\n+int yyget_lineno (void );\n+\n+void yyset_lineno (int line_number );\n+\n+/* Macros after this point can all be overridden by user definitions in\n+ * section 1.\n+ */\n+\n+#ifndef YY_SKIP_YYWRAP\n+#ifdef __cplusplus\n+extern \"C\" int yywrap (void );\n+#else\n+extern int yywrap (void );\n+#endif\n+#endif\n+\n+#ifndef yytext_ptr\n+static void yy_flex_strncpy (char *,yyconst char *,int );\n+#endif\n+\n+#ifdef YY_NEED_STRLEN\n+static int yy_flex_strlen (yyconst char * );\n+#endif\n+\n+#ifndef YY_NO_INPUT\n+\n+#ifdef __cplusplus\n+static int yyinput (void );\n+#else\n+static int input (void );\n+#endif\n+\n+#endif\n+\n+/* Amount of stuff to slurp up with each read. */\n+#ifndef YY_READ_BUF_SIZE\n+#ifdef __ia64__\n+/* On IA-64, the buffer size is 16k, not 8k */\n+#define YY_READ_BUF_SIZE 16384\n+#else\n+#define YY_READ_BUF_SIZE 8192\n+#endif /* __ia64__ */\n+#endif\n+\n+/* Copy whatever the last rule matched to the standard output. */\n+#ifndef ECHO\n+/* This used to be an fputs(), but since the string might contain NUL's,\n+ * we now use fwrite().\n+ */\n+#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0)\n+#endif\n+\n+/* Gets input and stuffs it into \"buf\". number of characters read, or YY_NULL,\n+ * is returned in \"result\".\n+ */\n+#ifndef YY_INPUT\n+#define YY_INPUT(buf,result,max_size) \\\n+\tif ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \\\n+\t\t{ \\\n+\t\tint c = '*'; \\\n+\t\tsize_t n; \\\n+\t\tfor ( n = 0; n < max_size && \\\n+\t\t\t (c = getc( yyin )) != EOF && c != '\\n'; ++n ) \\\n+\t\t\tbuf[n] = (char) c; \\\n+\t\tif ( c == '\\n' ) \\\n+\t\t\tbuf[n++] = (char) c; \\\n+\t\tif ( c == EOF && ferror( yyin ) ) \\\n+\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\\n+\t\tresult = n; \\\n+\t\t} \\\n+\telse \\\n+\t\t{ \\\n+\t\terrno=0; \\\n+\t\twhile ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \\\n+\t\t\t{ \\\n+\t\t\tif( errno != EINTR) \\\n+\t\t\t\t{ \\\n+\t\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\\n+\t\t\t\tbreak; \\\n+\t\t\t\t} \\\n+\t\t\terrno=0; \\\n+\t\t\tclearerr(yyin); \\\n+\t\t\t} \\\n+\t\t}\\\n+\\\n+\n+#endif\n+\n+/* No semi-colon after return; correct usage is to write \"yyterminate();\" -\n+ * we don't want an extra ';' after the \"return\" because that will cause\n+ * some compilers to complain about unreachable statements.\n+ */\n+#ifndef yyterminate\n+#define yyterminate() return YY_NULL\n+#endif\n+\n+/* Number of entries by which start-condition stack grows. */\n+#ifndef YY_START_STACK_INCR\n+#define YY_START_STACK_INCR 25\n+#endif\n+\n+/* Report a fatal error. */\n+#ifndef YY_FATAL_ERROR\n+#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )\n+#endif\n+\n+/* end tables serialization structures and prototypes */\n+\n+/* Default declaration of generated scanner - a define so the user can\n+ * easily add parameters.\n+ */\n+#ifndef YY_DECL\n+#define YY_DECL_IS_OURS 1\n+\n+extern int yylex (void);\n+\n+#define YY_DECL int yylex (void)\n+#endif /* !YY_DECL */\n+\n+/* Code executed at the beginning of each rule, after yytext and yyleng\n+ * have been set up.\n+ */\n+#ifndef YY_USER_ACTION\n+#define YY_USER_ACTION\n+#endif\n+\n+/* Code executed at the end of each rule. */\n+#ifndef YY_BREAK\n+#define YY_BREAK break;\n+#endif\n+\n+#define YY_RULE_SETUP \\\n+\tif ( yyleng > 0 ) \\\n+\t\tYY_CURRENT_BUFFER_LVALUE->yy_at_bol = \\\n+\t\t\t\t(yytext[yyleng - 1] == '\\n'); \\\n+\tYY_USER_ACTION\n+\n+/** The main scanner function which does all the work.\n+ */\n+YY_DECL\n+{\n+\tregister yy_state_type yy_current_state;\n+\tregister char *yy_cp, *yy_bp;\n+\tregister int yy_act;\n+ \n+#line 74 \"dtc-lexer.l\"\n+\n+#line 867 \"dtc-lexer.lex.c\"\n+\n+\tif ( !(yy_init) )\n+\t\t{\n+\t\t(yy_init) = 1;\n+\n+#ifdef YY_USER_INIT\n+\t\tYY_USER_INIT;\n+#endif\n+\n+\t\tif ( ! (yy_start) )\n+\t\t\t(yy_start) = 1;\t/* first start state */\n+\n+\t\tif ( ! yyin )\n+\t\t\tyyin = stdin;\n+\n+\t\tif ( ! yyout )\n+\t\t\tyyout = stdout;\n+\n+\t\tif ( ! YY_CURRENT_BUFFER ) {\n+\t\t\tyyensure_buffer_stack ();\n+\t\t\tYY_CURRENT_BUFFER_LVALUE =\n+\t\t\t\tyy_create_buffer(yyin,YY_BUF_SIZE );\n+\t\t}\n+\n+\t\tyy_load_buffer_state( );\n+\t\t}\n+\n+\twhile ( 1 )\t\t/* loops until end-of-file is reached */\n+\t\t{\n+\t\tyy_cp = (yy_c_buf_p);\n+\n+\t\t/* Support of yytext. */\n+\t\t*yy_cp = (yy_hold_char);\n+\n+\t\t/* yy_bp points to the position in yy_ch_buf of the start of\n+\t\t * the current run.\n+\t\t */\n+\t\tyy_bp = yy_cp;\n+\n+\t\tyy_current_state = (yy_start);\n+\t\tyy_current_state += YY_AT_BOL();\n+yy_match:\n+\t\tdo\n+\t\t\t{\n+\t\t\tregister YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];\n+\t\t\tif ( yy_accept[yy_current_state] )\n+\t\t\t\t{\n+\t\t\t\t(yy_last_accepting_state) = yy_current_state;\n+\t\t\t\t(yy_last_accepting_cpos) = yy_cp;\n+\t\t\t\t}\n+\t\t\twhile ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )\n+\t\t\t\t{\n+\t\t\t\tyy_current_state = (int) yy_def[yy_current_state];\n+\t\t\t\tif ( yy_current_state >= 166 )\n+\t\t\t\t\tyy_c = yy_meta[(unsigned int) yy_c];\n+\t\t\t\t}\n+\t\t\tyy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];\n+\t\t\t++yy_cp;\n+\t\t\t}\n+\t\twhile ( yy_current_state != 165 );\n+\t\tyy_cp = (yy_last_accepting_cpos);\n+\t\tyy_current_state = (yy_last_accepting_state);\n+\n+yy_find_action:\n+\t\tyy_act = yy_accept[yy_current_state];\n+\n+\t\tYY_DO_BEFORE_ACTION;\n+\n+do_action:\t/* This label is used only to access EOF actions. */\n+\n+\t\tswitch ( yy_act )\n+\t{ /* beginning of action switch */\n+\t\t\tcase 0: /* must back up */\n+\t\t\t/* undo the effects of YY_DO_BEFORE_ACTION */\n+\t\t\t*yy_cp = (yy_hold_char);\n+\t\t\tyy_cp = (yy_last_accepting_cpos);\n+\t\t\tyy_current_state = (yy_last_accepting_state);\n+\t\t\tgoto yy_find_action;\n+\n+case 1:\n+/* rule 1 can match eol */\n+YY_RULE_SETUP\n+#line 75 \"dtc-lexer.l\"\n+{\n+\t\t\tchar *name = strchr(yytext, '\\\"') + 1;\n+\t\t\tyytext[yyleng-1] = '\\0';\n+\t\t\tpush_input_file(name);\n+\t\t}\n+\tYY_BREAK\n+case 2:\n+/* rule 2 can match eol */\n+YY_RULE_SETUP\n+#line 81 \"dtc-lexer.l\"\n+{\n+\t\t\tchar *line, *fnstart, *fnend;\n+\t\t\tstruct data fn;\n+\t\t\t/* skip text before line # */\n+\t\t\tline = yytext;\n+\t\t\twhile (!isdigit((unsigned char)*line))\n+\t\t\t\tline++;\n+\n+\t\t\t/* regexp ensures that first and list \"\n+\t\t\t * in the whole yytext are those at\n+\t\t\t * beginning and end of the filename string */\n+\t\t\tfnstart = memchr(yytext, '\"', yyleng);\n+\t\t\tfor (fnend = yytext + yyleng - 1;\n+\t\t\t *fnend != '\"'; fnend--)\n+\t\t\t\t;\n+\t\t\tassert(fnstart && fnend && (fnend > fnstart));\n+\n+\t\t\tfn = data_copy_escape_string(fnstart + 1,\n+\t\t\t\t\t\t fnend - fnstart - 1);\n+\n+\t\t\t/* Don't allow nuls in filenames */\n+\t\t\tif (memchr(fn.val, '\\0', fn.len - 1))\n+\t\t\t\tlexical_error(\"nul in line number directive\");\n+\n+\t\t\t/* -1 since #line is the number of the next line */\n+\t\t\tsrcpos_set_line(xstrdup(fn.val), atoi(line) - 1);\n+\t\t\tdata_free(fn);\n+\t\t}\n+\tYY_BREAK\n+case YY_STATE_EOF(INITIAL):\n+case YY_STATE_EOF(BYTESTRING):\n+case YY_STATE_EOF(PROPNODENAME):\n+case YY_STATE_EOF(V1):\n+#line 110 \"dtc-lexer.l\"\n+{\n+\t\t\tif (!pop_input_file()) {\n+\t\t\t\tyyterminate();\n+\t\t\t}\n+\t\t}\n+\tYY_BREAK\n+case 3:\n+/* rule 3 can match eol */\n+YY_RULE_SETUP\n+#line 116 \"dtc-lexer.l\"\n+{\n+\t\t\tDPRINT(\"String: %s\\n\", yytext);\n+\t\t\tyylval.data = data_copy_escape_string(yytext+1,\n+\t\t\t\t\tyyleng-2);\n+\t\t\treturn DT_STRING;\n+\t\t}\n+\tYY_BREAK\n+case 4:\n+YY_RULE_SETUP\n+#line 123 \"dtc-lexer.l\"\n+{\n+\t\t\tDPRINT(\"Keyword: /dts-v1/\\n\");\n+\t\t\tdts_version = 1;\n+\t\t\tBEGIN_DEFAULT();\n+\t\t\treturn DT_V1;\n+\t\t}\n+\tYY_BREAK\n+case 5:\n+YY_RULE_SETUP\n+#line 130 \"dtc-lexer.l\"\n+{\n+\t\t\tDPRINT(\"Keyword: /plugin/\\n\");\n+\t\t\treturn DT_PLUGIN;\n+\t\t}\n+\tYY_BREAK\n+case 6:\n+YY_RULE_SETUP\n+#line 135 \"dtc-lexer.l\"\n+{\n+\t\t\tDPRINT(\"Keyword: /memreserve/\\n\");\n+\t\t\tBEGIN_DEFAULT();\n+\t\t\treturn DT_MEMRESERVE;\n+\t\t}\n+\tYY_BREAK\n+case 7:\n+YY_RULE_SETUP\n+#line 141 \"dtc-lexer.l\"\n+{\n+\t\t\tDPRINT(\"Keyword: /bits/\\n\");\n+\t\t\tBEGIN_DEFAULT();\n+\t\t\treturn DT_BITS;\n+\t\t}\n+\tYY_BREAK\n+case 8:\n+YY_RULE_SETUP\n+#line 147 \"dtc-lexer.l\"\n+{\n+\t\t\tDPRINT(\"Keyword: /delete-property/\\n\");\n+\t\t\tDPRINT(\"<PROPNODENAME>\\n\");\n+\t\t\tBEGIN(PROPNODENAME);\n+\t\t\treturn DT_DEL_PROP;\n+\t\t}\n+\tYY_BREAK\n+case 9:\n+YY_RULE_SETUP\n+#line 154 \"dtc-lexer.l\"\n+{\n+\t\t\tDPRINT(\"Keyword: /delete-node/\\n\");\n+\t\t\tDPRINT(\"<PROPNODENAME>\\n\");\n+\t\t\tBEGIN(PROPNODENAME);\n+\t\t\treturn DT_DEL_NODE;\n+\t\t}\n+\tYY_BREAK\n+case 10:\n+YY_RULE_SETUP\n+#line 161 \"dtc-lexer.l\"\n+{\n+\t\t\tDPRINT(\"Label: %s\\n\", yytext);\n+\t\t\tyylval.labelref = xstrdup(yytext);\n+\t\t\tyylval.labelref[yyleng-1] = '\\0';\n+\t\t\treturn DT_LABEL;\n+\t\t}\n+\tYY_BREAK\n+case 11:\n+YY_RULE_SETUP\n+#line 168 \"dtc-lexer.l\"\n+{\n+\t\t\tchar *e;\n+\t\t\tDPRINT(\"Integer Literal: '%s'\\n\", yytext);\n+\n+\t\t\terrno = 0;\n+\t\t\tyylval.integer = strtoull(yytext, &e, 0);\n+\n+\t\t\tif (*e && e[strspn(e, \"UL\")]) {\n+\t\t\t\tlexical_error(\"Bad integer literal '%s'\",\n+\t\t\t\t\t yytext);\n+\t\t\t}\n+\n+\t\t\tif (errno == ERANGE)\n+\t\t\t\tlexical_error(\"Integer literal '%s' out of range\",\n+\t\t\t\t\t yytext);\n+\t\t\telse\n+\t\t\t\t/* ERANGE is the only strtoull error triggerable\n+\t\t\t\t * by strings matching the pattern */\n+\t\t\t\tassert(errno == 0);\n+\t\t\treturn DT_LITERAL;\n+\t\t}\n+\tYY_BREAK\n+case 12:\n+/* rule 12 can match eol */\n+YY_RULE_SETUP\n+#line 190 \"dtc-lexer.l\"\n+{\n+\t\t\tstruct data d;\n+\t\t\tDPRINT(\"Character literal: %s\\n\", yytext);\n+\n+\t\t\td = data_copy_escape_string(yytext+1, yyleng-2);\n+\t\t\tif (d.len == 1) {\n+\t\t\t\tlexical_error(\"Empty character literal\");\n+\t\t\t\tyylval.integer = 0;\n+\t\t\t} else {\n+\t\t\t\tyylval.integer = (unsigned char)d.val[0];\n+\n+\t\t\t\tif (d.len > 2)\n+\t\t\t\t\tlexical_error(\"Character literal has %d\"\n+\t\t\t\t\t\t \" characters instead of 1\",\n+\t\t\t\t\t\t d.len - 1);\n+\t\t\t}\n+\n+\t\t\tdata_free(d);\n+\t\t\treturn DT_CHAR_LITERAL;\n+\t\t}\n+\tYY_BREAK\n+case 13:\n+YY_RULE_SETUP\n+#line 211 \"dtc-lexer.l\"\n+{\t/* label reference */\n+\t\t\tDPRINT(\"Ref: %s\\n\", yytext+1);\n+\t\t\tyylval.labelref = xstrdup(yytext+1);\n+\t\t\treturn DT_REF;\n+\t\t}\n+\tYY_BREAK\n+case 14:\n+YY_RULE_SETUP\n+#line 217 \"dtc-lexer.l\"\n+{\t/* new-style path reference */\n+\t\t\tyytext[yyleng-1] = '\\0';\n+\t\t\tDPRINT(\"Ref: %s\\n\", yytext+2);\n+\t\t\tyylval.labelref = xstrdup(yytext+2);\n+\t\t\treturn DT_REF;\n+\t\t}\n+\tYY_BREAK\n+case 15:\n+YY_RULE_SETUP\n+#line 224 \"dtc-lexer.l\"\n+{\n+\t\t\tyylval.byte = strtol(yytext, NULL, 16);\n+\t\t\tDPRINT(\"Byte: %02x\\n\", (int)yylval.byte);\n+\t\t\treturn DT_BYTE;\n+\t\t}\n+\tYY_BREAK\n+case 16:\n+YY_RULE_SETUP\n+#line 230 \"dtc-lexer.l\"\n+{\n+\t\t\tDPRINT(\"/BYTESTRING\\n\");\n+\t\t\tBEGIN_DEFAULT();\n+\t\t\treturn ']';\n+\t\t}\n+\tYY_BREAK\n+case 17:\n+YY_RULE_SETUP\n+#line 236 \"dtc-lexer.l\"\n+{\n+\t\t\tDPRINT(\"PropNodeName: %s\\n\", yytext);\n+\t\t\tyylval.propnodename = xstrdup((yytext[0] == '\\\\') ?\n+\t\t\t\t\t\t\tyytext + 1 : yytext);\n+\t\t\tBEGIN_DEFAULT();\n+\t\t\treturn DT_PROPNODENAME;\n+\t\t}\n+\tYY_BREAK\n+case 18:\n+YY_RULE_SETUP\n+#line 244 \"dtc-lexer.l\"\n+{\n+\t\t\tDPRINT(\"Binary Include\\n\");\n+\t\t\treturn DT_INCBIN;\n+\t\t}\n+\tYY_BREAK\n+case 19:\n+/* rule 19 can match eol */\n+YY_RULE_SETUP\n+#line 249 \"dtc-lexer.l\"\n+/* eat whitespace */\n+\tYY_BREAK\n+case 20:\n+/* rule 20 can match eol */\n+YY_RULE_SETUP\n+#line 250 \"dtc-lexer.l\"\n+/* eat C-style comments */\n+\tYY_BREAK\n+case 21:\n+/* rule 21 can match eol */\n+YY_RULE_SETUP\n+#line 251 \"dtc-lexer.l\"\n+/* eat C++-style comments */\n+\tYY_BREAK\n+case 22:\n+YY_RULE_SETUP\n+#line 253 \"dtc-lexer.l\"\n+{ return DT_LSHIFT; };\n+\tYY_BREAK\n+case 23:\n+YY_RULE_SETUP\n+#line 254 \"dtc-lexer.l\"\n+{ return DT_RSHIFT; };\n+\tYY_BREAK\n+case 24:\n+YY_RULE_SETUP\n+#line 255 \"dtc-lexer.l\"\n+{ return DT_LE; };\n+\tYY_BREAK\n+case 25:\n+YY_RULE_SETUP\n+#line 256 \"dtc-lexer.l\"\n+{ return DT_GE; };\n+\tYY_BREAK\n+case 26:\n+YY_RULE_SETUP\n+#line 257 \"dtc-lexer.l\"\n+{ return DT_EQ; };\n+\tYY_BREAK\n+case 27:\n+YY_RULE_SETUP\n+#line 258 \"dtc-lexer.l\"\n+{ return DT_NE; };\n+\tYY_BREAK\n+case 28:\n+YY_RULE_SETUP\n+#line 259 \"dtc-lexer.l\"\n+{ return DT_AND; };\n+\tYY_BREAK\n+case 29:\n+YY_RULE_SETUP\n+#line 260 \"dtc-lexer.l\"\n+{ return DT_OR; };\n+\tYY_BREAK\n+case 30:\n+YY_RULE_SETUP\n+#line 262 \"dtc-lexer.l\"\n+{\n+\t\t\tDPRINT(\"Char: %c (\\\\x%02x)\\n\", yytext[0],\n+\t\t\t\t(unsigned)yytext[0]);\n+\t\t\tif (yytext[0] == '[') {\n+\t\t\t\tDPRINT(\"<BYTESTRING>\\n\");\n+\t\t\t\tBEGIN(BYTESTRING);\n+\t\t\t}\n+\t\t\tif ((yytext[0] == '{')\n+\t\t\t || (yytext[0] == ';')) {\n+\t\t\t\tDPRINT(\"<PROPNODENAME>\\n\");\n+\t\t\t\tBEGIN(PROPNODENAME);\n+\t\t\t}\n+\t\t\treturn yytext[0];\n+\t\t}\n+\tYY_BREAK\n+case 31:\n+YY_RULE_SETUP\n+#line 277 \"dtc-lexer.l\"\n+ECHO;\n+\tYY_BREAK\n+#line 1265 \"dtc-lexer.lex.c\"\n+\n+\tcase YY_END_OF_BUFFER:\n+\t\t{\n+\t\t/* Amount of text matched not including the EOB char. */\n+\t\tint yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1;\n+\n+\t\t/* Undo the effects of YY_DO_BEFORE_ACTION. */\n+\t\t*yy_cp = (yy_hold_char);\n+\t\tYY_RESTORE_YY_MORE_OFFSET\n+\n+\t\tif ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )\n+\t\t\t{\n+\t\t\t/* We're scanning a new file or input source. It's\n+\t\t\t * possible that this happened because the user\n+\t\t\t * just pointed yyin at a new source and called\n+\t\t\t * yylex(). If so, then we have to assure\n+\t\t\t * consistency between YY_CURRENT_BUFFER and our\n+\t\t\t * globals. Here is the right place to do so, because\n+\t\t\t * this is the first action (other than possibly a\n+\t\t\t * back-up) that will match for the new input source.\n+\t\t\t */\n+\t\t\t(yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;\n+\t\t\tYY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;\n+\t\t\tYY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;\n+\t\t\t}\n+\n+\t\t/* Note that here we test for yy_c_buf_p \"<=\" to the position\n+\t\t * of the first EOB in the buffer, since yy_c_buf_p will\n+\t\t * already have been incremented past the NUL character\n+\t\t * (since all states make transitions on EOB to the\n+\t\t * end-of-buffer state). Contrast this with the test\n+\t\t * in input().\n+\t\t */\n+\t\tif ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )\n+\t\t\t{ /* This was really a NUL. */\n+\t\t\tyy_state_type yy_next_state;\n+\n+\t\t\t(yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text;\n+\n+\t\t\tyy_current_state = yy_get_previous_state( );\n+\n+\t\t\t/* Okay, we're now positioned to make the NUL\n+\t\t\t * transition. We couldn't have\n+\t\t\t * yy_get_previous_state() go ahead and do it\n+\t\t\t * for us because it doesn't know how to deal\n+\t\t\t * with the possibility of jamming (and we don't\n+\t\t\t * want to build jamming into it because then it\n+\t\t\t * will run more slowly).\n+\t\t\t */\n+\n+\t\t\tyy_next_state = yy_try_NUL_trans( yy_current_state );\n+\n+\t\t\tyy_bp = (yytext_ptr) + YY_MORE_ADJ;\n+\n+\t\t\tif ( yy_next_state )\n+\t\t\t\t{\n+\t\t\t\t/* Consume the NUL. */\n+\t\t\t\tyy_cp = ++(yy_c_buf_p);\n+\t\t\t\tyy_current_state = yy_next_state;\n+\t\t\t\tgoto yy_match;\n+\t\t\t\t}\n+\n+\t\t\telse\n+\t\t\t\t{\n+\t\t\t\tyy_cp = (yy_last_accepting_cpos);\n+\t\t\t\tyy_current_state = (yy_last_accepting_state);\n+\t\t\t\tgoto yy_find_action;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\telse switch ( yy_get_next_buffer( ) )\n+\t\t\t{\n+\t\t\tcase EOB_ACT_END_OF_FILE:\n+\t\t\t\t{\n+\t\t\t\t(yy_did_buffer_switch_on_eof) = 0;\n+\n+\t\t\t\tif ( yywrap( ) )\n+\t\t\t\t\t{\n+\t\t\t\t\t/* Note: because we've taken care in\n+\t\t\t\t\t * yy_get_next_buffer() to have set up\n+\t\t\t\t\t * yytext, we can now set up\n+\t\t\t\t\t * yy_c_buf_p so that if some total\n+\t\t\t\t\t * hoser (like flex itself) wants to\n+\t\t\t\t\t * call the scanner after we return the\n+\t\t\t\t\t * YY_NULL, it'll still work - another\n+\t\t\t\t\t * YY_NULL will get returned.\n+\t\t\t\t\t */\n+\t\t\t\t\t(yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ;\n+\n+\t\t\t\t\tyy_act = YY_STATE_EOF(YY_START);\n+\t\t\t\t\tgoto do_action;\n+\t\t\t\t\t}\n+\n+\t\t\t\telse\n+\t\t\t\t\t{\n+\t\t\t\t\tif ( ! (yy_did_buffer_switch_on_eof) )\n+\t\t\t\t\t\tYY_NEW_FILE;\n+\t\t\t\t\t}\n+\t\t\t\tbreak;\n+\t\t\t\t}\n+\n+\t\t\tcase EOB_ACT_CONTINUE_SCAN:\n+\t\t\t\t(yy_c_buf_p) =\n+\t\t\t\t\t(yytext_ptr) + yy_amount_of_matched_text;\n+\n+\t\t\t\tyy_current_state = yy_get_previous_state( );\n+\n+\t\t\t\tyy_cp = (yy_c_buf_p);\n+\t\t\t\tyy_bp = (yytext_ptr) + YY_MORE_ADJ;\n+\t\t\t\tgoto yy_match;\n+\n+\t\t\tcase EOB_ACT_LAST_MATCH:\n+\t\t\t\t(yy_c_buf_p) =\n+\t\t\t\t&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)];\n+\n+\t\t\t\tyy_current_state = yy_get_previous_state( );\n+\n+\t\t\t\tyy_cp = (yy_c_buf_p);\n+\t\t\t\tyy_bp = (yytext_ptr) + YY_MORE_ADJ;\n+\t\t\t\tgoto yy_find_action;\n+\t\t\t}\n+\t\tbreak;\n+\t\t}\n+\n+\tdefault:\n+\t\tYY_FATAL_ERROR(\n+\t\t\t\"fatal flex scanner internal error--no action found\" );\n+\t} /* end of action switch */\n+\t\t} /* end of scanning one token */\n+} /* end of yylex */\n+\n+/* yy_get_next_buffer - try to read in a new buffer\n+ *\n+ * Returns a code representing an action:\n+ *\tEOB_ACT_LAST_MATCH -\n+ *\tEOB_ACT_CONTINUE_SCAN - continue scanning from current position\n+ *\tEOB_ACT_END_OF_FILE - end of file\n+ */\n+static int yy_get_next_buffer (void)\n+{\n+ \tregister char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;\n+\tregister char *source = (yytext_ptr);\n+\tregister int number_to_move, i;\n+\tint ret_val;\n+\n+\tif ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] )\n+\t\tYY_FATAL_ERROR(\n+\t\t\"fatal flex scanner internal error--end of buffer missed\" );\n+\n+\tif ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )\n+\t\t{ /* Don't try to fill the buffer, so this is an EOF. */\n+\t\tif ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 )\n+\t\t\t{\n+\t\t\t/* We matched a single character, the EOB, so\n+\t\t\t * treat this as a final EOF.\n+\t\t\t */\n+\t\t\treturn EOB_ACT_END_OF_FILE;\n+\t\t\t}\n+\n+\t\telse\n+\t\t\t{\n+\t\t\t/* We matched some text prior to the EOB, first\n+\t\t\t * process it.\n+\t\t\t */\n+\t\t\treturn EOB_ACT_LAST_MATCH;\n+\t\t\t}\n+\t\t}\n+\n+\t/* Try to read more data. */\n+\n+\t/* First move last chars to start of buffer. */\n+\tnumber_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1;\n+\n+\tfor ( i = 0; i < number_to_move; ++i )\n+\t\t*(dest++) = *(source++);\n+\n+\tif ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )\n+\t\t/* don't do the read, it's not guaranteed to return an EOF,\n+\t\t * just force an EOF\n+\t\t */\n+\t\tYY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0;\n+\n+\telse\n+\t\t{\n+\t\t\tint num_to_read =\n+\t\t\tYY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;\n+\n+\t\twhile ( num_to_read <= 0 )\n+\t\t\t{ /* Not enough room in the buffer - grow it. */\n+\n+\t\t\t/* just a shorter name for the current buffer */\n+\t\t\tYY_BUFFER_STATE b = YY_CURRENT_BUFFER;\n+\n+\t\t\tint yy_c_buf_p_offset =\n+\t\t\t\t(int) ((yy_c_buf_p) - b->yy_ch_buf);\n+\n+\t\t\tif ( b->yy_is_our_buffer )\n+\t\t\t\t{\n+\t\t\t\tint new_size = b->yy_buf_size * 2;\n+\n+\t\t\t\tif ( new_size <= 0 )\n+\t\t\t\t\tb->yy_buf_size += b->yy_buf_size / 8;\n+\t\t\t\telse\n+\t\t\t\t\tb->yy_buf_size *= 2;\n+\n+\t\t\t\tb->yy_ch_buf = (char *)\n+\t\t\t\t\t/* Include room in for 2 EOB chars. */\n+\t\t\t\t\tyyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 );\n+\t\t\t\t}\n+\t\t\telse\n+\t\t\t\t/* Can't grow it, we don't own it. */\n+\t\t\t\tb->yy_ch_buf = 0;\n+\n+\t\t\tif ( ! b->yy_ch_buf )\n+\t\t\t\tYY_FATAL_ERROR(\n+\t\t\t\t\"fatal error - scanner input buffer overflow\" );\n+\n+\t\t\t(yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset];\n+\n+\t\t\tnum_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -\n+\t\t\t\t\t\tnumber_to_move - 1;\n+\n+\t\t\t}\n+\n+\t\tif ( num_to_read > YY_READ_BUF_SIZE )\n+\t\t\tnum_to_read = YY_READ_BUF_SIZE;\n+\n+\t\t/* Read in more data. */\n+\t\tYY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),\n+\t\t\t(yy_n_chars), (size_t) num_to_read );\n+\n+\t\tYY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);\n+\t\t}\n+\n+\tif ( (yy_n_chars) == 0 )\n+\t\t{\n+\t\tif ( number_to_move == YY_MORE_ADJ )\n+\t\t\t{\n+\t\t\tret_val = EOB_ACT_END_OF_FILE;\n+\t\t\tyyrestart(yyin );\n+\t\t\t}\n+\n+\t\telse\n+\t\t\t{\n+\t\t\tret_val = EOB_ACT_LAST_MATCH;\n+\t\t\tYY_CURRENT_BUFFER_LVALUE->yy_buffer_status =\n+\t\t\t\tYY_BUFFER_EOF_PENDING;\n+\t\t\t}\n+\t\t}\n+\n+\telse\n+\t\tret_val = EOB_ACT_CONTINUE_SCAN;\n+\n+\tif ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {\n+\t\t/* Extend the array by 50%, plus the number we really need. */\n+\t\tyy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1);\n+\t\tYY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size );\n+\t\tif ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )\n+\t\t\tYY_FATAL_ERROR( \"out of dynamic memory in yy_get_next_buffer()\" );\n+\t}\n+\n+\t(yy_n_chars) += number_to_move;\n+\tYY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR;\n+\tYY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR;\n+\n+\t(yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];\n+\n+\treturn ret_val;\n+}\n+\n+/* yy_get_previous_state - get the state just before the EOB char was reached */\n+\n+ static yy_state_type yy_get_previous_state (void)\n+{\n+\tregister yy_state_type yy_current_state;\n+\tregister char *yy_cp;\n+ \n+\tyy_current_state = (yy_start);\n+\tyy_current_state += YY_AT_BOL();\n+\n+\tfor ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )\n+\t\t{\n+\t\tregister YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);\n+\t\tif ( yy_accept[yy_current_state] )\n+\t\t\t{\n+\t\t\t(yy_last_accepting_state) = yy_current_state;\n+\t\t\t(yy_last_accepting_cpos) = yy_cp;\n+\t\t\t}\n+\t\twhile ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )\n+\t\t\t{\n+\t\t\tyy_current_state = (int) yy_def[yy_current_state];\n+\t\t\tif ( yy_current_state >= 166 )\n+\t\t\t\tyy_c = yy_meta[(unsigned int) yy_c];\n+\t\t\t}\n+\t\tyy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];\n+\t\t}\n+\n+\treturn yy_current_state;\n+}\n+\n+/* yy_try_NUL_trans - try to make a transition on the NUL character\n+ *\n+ * synopsis\n+ *\tnext_state = yy_try_NUL_trans( current_state );\n+ */\n+ static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state )\n+{\n+\tregister int yy_is_jam;\n+ \tregister char *yy_cp = (yy_c_buf_p);\n+\n+\tregister YY_CHAR yy_c = 1;\n+\tif ( yy_accept[yy_current_state] )\n+\t\t{\n+\t\t(yy_last_accepting_state) = yy_current_state;\n+\t\t(yy_last_accepting_cpos) = yy_cp;\n+\t\t}\n+\twhile ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )\n+\t\t{\n+\t\tyy_current_state = (int) yy_def[yy_current_state];\n+\t\tif ( yy_current_state >= 166 )\n+\t\t\tyy_c = yy_meta[(unsigned int) yy_c];\n+\t\t}\n+\tyy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];\n+\tyy_is_jam = (yy_current_state == 165);\n+\n+\treturn yy_is_jam ? 0 : yy_current_state;\n+}\n+\n+#ifndef YY_NO_INPUT\n+#ifdef __cplusplus\n+ static int yyinput (void)\n+#else\n+ static int input (void)\n+#endif\n+\n+{\n+\tint c;\n+ \n+\t*(yy_c_buf_p) = (yy_hold_char);\n+\n+\tif ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR )\n+\t\t{\n+\t\t/* yy_c_buf_p now points to the character we want to return.\n+\t\t * If this occurs *before* the EOB characters, then it's a\n+\t\t * valid NUL; if not, then we've hit the end of the buffer.\n+\t\t */\n+\t\tif ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )\n+\t\t\t/* This was really a NUL. */\n+\t\t\t*(yy_c_buf_p) = '\\0';\n+\n+\t\telse\n+\t\t\t{ /* need more input */\n+\t\t\tint offset = (yy_c_buf_p) - (yytext_ptr);\n+\t\t\t++(yy_c_buf_p);\n+\n+\t\t\tswitch ( yy_get_next_buffer( ) )\n+\t\t\t\t{\n+\t\t\t\tcase EOB_ACT_LAST_MATCH:\n+\t\t\t\t\t/* This happens because yy_g_n_b()\n+\t\t\t\t\t * sees that we've accumulated a\n+\t\t\t\t\t * token and flags that we need to\n+\t\t\t\t\t * try matching the token before\n+\t\t\t\t\t * proceeding. But for input(),\n+\t\t\t\t\t * there's no matching to consider.\n+\t\t\t\t\t * So convert the EOB_ACT_LAST_MATCH\n+\t\t\t\t\t * to EOB_ACT_END_OF_FILE.\n+\t\t\t\t\t */\n+\n+\t\t\t\t\t/* Reset buffer status. */\n+\t\t\t\t\tyyrestart(yyin );\n+\n+\t\t\t\t\t/*FALLTHROUGH*/\n+\n+\t\t\t\tcase EOB_ACT_END_OF_FILE:\n+\t\t\t\t\t{\n+\t\t\t\t\tif ( yywrap( ) )\n+\t\t\t\t\t\treturn EOF;\n+\n+\t\t\t\t\tif ( ! (yy_did_buffer_switch_on_eof) )\n+\t\t\t\t\t\tYY_NEW_FILE;\n+#ifdef __cplusplus\n+\t\t\t\t\treturn yyinput();\n+#else\n+\t\t\t\t\treturn input();\n+#endif\n+\t\t\t\t\t}\n+\n+\t\t\t\tcase EOB_ACT_CONTINUE_SCAN:\n+\t\t\t\t\t(yy_c_buf_p) = (yytext_ptr) + offset;\n+\t\t\t\t\tbreak;\n+\t\t\t\t}\n+\t\t\t}\n+\t\t}\n+\n+\tc = *(unsigned char *) (yy_c_buf_p);\t/* cast for 8-bit char's */\n+\t*(yy_c_buf_p) = '\\0';\t/* preserve yytext */\n+\t(yy_hold_char) = *++(yy_c_buf_p);\n+\n+\tYY_CURRENT_BUFFER_LVALUE->yy_at_bol = (c == '\\n');\n+\n+\treturn c;\n+}\n+#endif\t/* ifndef YY_NO_INPUT */\n+\n+/** Immediately switch to a different input stream.\n+ * @param input_file A readable stream.\n+ * \n+ * @note This function does not reset the start condition to @c INITIAL .\n+ */\n+ void yyrestart (FILE * input_file )\n+{\n+ \n+\tif ( ! YY_CURRENT_BUFFER ){\n+ yyensure_buffer_stack ();\n+\t\tYY_CURRENT_BUFFER_LVALUE =\n+ yy_create_buffer(yyin,YY_BUF_SIZE );\n+\t}\n+\n+\tyy_init_buffer(YY_CURRENT_BUFFER,input_file );\n+\tyy_load_buffer_state( );\n+}\n+\n+/** Switch to a different input buffer.\n+ * @param new_buffer The new input buffer.\n+ * \n+ */\n+ void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer )\n+{\n+ \n+\t/* TODO. We should be able to replace this entire function body\n+\t * with\n+\t *\t\tyypop_buffer_state();\n+\t *\t\tyypush_buffer_state(new_buffer);\n+ */\n+\tyyensure_buffer_stack ();\n+\tif ( YY_CURRENT_BUFFER == new_buffer )\n+\t\treturn;\n+\n+\tif ( YY_CURRENT_BUFFER )\n+\t\t{\n+\t\t/* Flush out information for old buffer. */\n+\t\t*(yy_c_buf_p) = (yy_hold_char);\n+\t\tYY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);\n+\t\tYY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);\n+\t\t}\n+\n+\tYY_CURRENT_BUFFER_LVALUE = new_buffer;\n+\tyy_load_buffer_state( );\n+\n+\t/* We don't actually know whether we did this switch during\n+\t * EOF (yywrap()) processing, but the only time this flag\n+\t * is looked at is after yywrap() is called, so it's safe\n+\t * to go ahead and always set it.\n+\t */\n+\t(yy_did_buffer_switch_on_eof) = 1;\n+}\n+\n+static void yy_load_buffer_state (void)\n+{\n+ \t(yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;\n+\t(yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;\n+\tyyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;\n+\t(yy_hold_char) = *(yy_c_buf_p);\n+}\n+\n+/** Allocate and initialize an input buffer state.\n+ * @param file A readable stream.\n+ * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.\n+ * \n+ * @return the allocated buffer state.\n+ */\n+ YY_BUFFER_STATE yy_create_buffer (FILE * file, int size )\n+{\n+\tYY_BUFFER_STATE b;\n+ \n+\tb = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) );\n+\tif ( ! b )\n+\t\tYY_FATAL_ERROR( \"out of dynamic memory in yy_create_buffer()\" );\n+\n+\tb->yy_buf_size = size;\n+\n+\t/* yy_ch_buf has to be 2 characters longer than the size given because\n+\t * we need to put in 2 end-of-buffer characters.\n+\t */\n+\tb->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 );\n+\tif ( ! b->yy_ch_buf )\n+\t\tYY_FATAL_ERROR( \"out of dynamic memory in yy_create_buffer()\" );\n+\n+\tb->yy_is_our_buffer = 1;\n+\n+\tyy_init_buffer(b,file );\n+\n+\treturn b;\n+}\n+\n+/** Destroy the buffer.\n+ * @param b a buffer created with yy_create_buffer()\n+ * \n+ */\n+ void yy_delete_buffer (YY_BUFFER_STATE b )\n+{\n+ \n+\tif ( ! b )\n+\t\treturn;\n+\n+\tif ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */\n+\t\tYY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;\n+\n+\tif ( b->yy_is_our_buffer )\n+\t\tyyfree((void *) b->yy_ch_buf );\n+\n+\tyyfree((void *) b );\n+}\n+\n+/* Initializes or reinitializes a buffer.\n+ * This function is sometimes called more than once on the same buffer,\n+ * such as during a yyrestart() or at EOF.\n+ */\n+ static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file )\n+\n+{\n+\tint oerrno = errno;\n+ \n+\tyy_flush_buffer(b );\n+\n+\tb->yy_input_file = file;\n+\tb->yy_fill_buffer = 1;\n+\n+ /* If b is the current buffer, then yy_init_buffer was _probably_\n+ * called from yyrestart() or through yy_get_next_buffer.\n+ * In that case, we don't want to reset the lineno or column.\n+ */\n+ if (b != YY_CURRENT_BUFFER){\n+ b->yy_bs_lineno = 1;\n+ b->yy_bs_column = 0;\n+ }\n+\n+ b->yy_is_interactive = 0;\n+ \n+\terrno = oerrno;\n+}\n+\n+/** Discard all buffered characters. On the next scan, YY_INPUT will be called.\n+ * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.\n+ * \n+ */\n+ void yy_flush_buffer (YY_BUFFER_STATE b )\n+{\n+ \tif ( ! b )\n+\t\treturn;\n+\n+\tb->yy_n_chars = 0;\n+\n+\t/* We always need two end-of-buffer characters. The first causes\n+\t * a transition to the end-of-buffer state. The second causes\n+\t * a jam in that state.\n+\t */\n+\tb->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;\n+\tb->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;\n+\n+\tb->yy_buf_pos = &b->yy_ch_buf[0];\n+\n+\tb->yy_at_bol = 1;\n+\tb->yy_buffer_status = YY_BUFFER_NEW;\n+\n+\tif ( b == YY_CURRENT_BUFFER )\n+\t\tyy_load_buffer_state( );\n+}\n+\n+/** Pushes the new state onto the stack. The new state becomes\n+ * the current state. This function will allocate the stack\n+ * if necessary.\n+ * @param new_buffer The new state.\n+ * \n+ */\n+void yypush_buffer_state (YY_BUFFER_STATE new_buffer )\n+{\n+ \tif (new_buffer == NULL)\n+\t\treturn;\n+\n+\tyyensure_buffer_stack();\n+\n+\t/* This block is copied from yy_switch_to_buffer. */\n+\tif ( YY_CURRENT_BUFFER )\n+\t\t{\n+\t\t/* Flush out information for old buffer. */\n+\t\t*(yy_c_buf_p) = (yy_hold_char);\n+\t\tYY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);\n+\t\tYY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);\n+\t\t}\n+\n+\t/* Only push if top exists. Otherwise, replace top. */\n+\tif (YY_CURRENT_BUFFER)\n+\t\t(yy_buffer_stack_top)++;\n+\tYY_CURRENT_BUFFER_LVALUE = new_buffer;\n+\n+\t/* copied from yy_switch_to_buffer. */\n+\tyy_load_buffer_state( );\n+\t(yy_did_buffer_switch_on_eof) = 1;\n+}\n+\n+/** Removes and deletes the top of the stack, if present.\n+ * The next element becomes the new top.\n+ * \n+ */\n+void yypop_buffer_state (void)\n+{\n+ \tif (!YY_CURRENT_BUFFER)\n+\t\treturn;\n+\n+\tyy_delete_buffer(YY_CURRENT_BUFFER );\n+\tYY_CURRENT_BUFFER_LVALUE = NULL;\n+\tif ((yy_buffer_stack_top) > 0)\n+\t\t--(yy_buffer_stack_top);\n+\n+\tif (YY_CURRENT_BUFFER) {\n+\t\tyy_load_buffer_state( );\n+\t\t(yy_did_buffer_switch_on_eof) = 1;\n+\t}\n+}\n+\n+/* Allocates the stack if it does not exist.\n+ * Guarantees space for at least one push.\n+ */\n+static void yyensure_buffer_stack (void)\n+{\n+\tint num_to_alloc;\n+ \n+\tif (!(yy_buffer_stack)) {\n+\n+\t\t/* First allocation is just for 2 elements, since we don't know if this\n+\t\t * scanner will even need a stack. We use 2 instead of 1 to avoid an\n+\t\t * immediate realloc on the next call.\n+ */\n+\t\tnum_to_alloc = 1;\n+\t\t(yy_buffer_stack) = (struct yy_buffer_state**)yyalloc\n+\t\t\t\t\t\t\t\t(num_to_alloc * sizeof(struct yy_buffer_state*)\n+\t\t\t\t\t\t\t\t);\n+\t\tif ( ! (yy_buffer_stack) )\n+\t\t\tYY_FATAL_ERROR( \"out of dynamic memory in yyensure_buffer_stack()\" );\n+\t\t\t\t\t\t\t\t \n+\t\tmemset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));\n+\t\t\t\t\n+\t\t(yy_buffer_stack_max) = num_to_alloc;\n+\t\t(yy_buffer_stack_top) = 0;\n+\t\treturn;\n+\t}\n+\n+\tif ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){\n+\n+\t\t/* Increase the buffer to prepare for a possible push. */\n+\t\tint grow_size = 8 /* arbitrary grow size */;\n+\n+\t\tnum_to_alloc = (yy_buffer_stack_max) + grow_size;\n+\t\t(yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc\n+\t\t\t\t\t\t\t\t((yy_buffer_stack),\n+\t\t\t\t\t\t\t\tnum_to_alloc * sizeof(struct yy_buffer_state*)\n+\t\t\t\t\t\t\t\t);\n+\t\tif ( ! (yy_buffer_stack) )\n+\t\t\tYY_FATAL_ERROR( \"out of dynamic memory in yyensure_buffer_stack()\" );\n+\n+\t\t/* zero only the new slots.*/\n+\t\tmemset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*));\n+\t\t(yy_buffer_stack_max) = num_to_alloc;\n+\t}\n+}\n+\n+/** Setup the input buffer state to scan directly from a user-specified character buffer.\n+ * @param base the character buffer\n+ * @param size the size in bytes of the character buffer\n+ * \n+ * @return the newly allocated buffer state object. \n+ */\n+YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size )\n+{\n+\tYY_BUFFER_STATE b;\n+ \n+\tif ( size < 2 ||\n+\t base[size-2] != YY_END_OF_BUFFER_CHAR ||\n+\t base[size-1] != YY_END_OF_BUFFER_CHAR )\n+\t\t/* They forgot to leave room for the EOB's. */\n+\t\treturn 0;\n+\n+\tb = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) );\n+\tif ( ! b )\n+\t\tYY_FATAL_ERROR( \"out of dynamic memory in yy_scan_buffer()\" );\n+\n+\tb->yy_buf_size = size - 2;\t/* \"- 2\" to take care of EOB's */\n+\tb->yy_buf_pos = b->yy_ch_buf = base;\n+\tb->yy_is_our_buffer = 0;\n+\tb->yy_input_file = 0;\n+\tb->yy_n_chars = b->yy_buf_size;\n+\tb->yy_is_interactive = 0;\n+\tb->yy_at_bol = 1;\n+\tb->yy_fill_buffer = 0;\n+\tb->yy_buffer_status = YY_BUFFER_NEW;\n+\n+\tyy_switch_to_buffer(b );\n+\n+\treturn b;\n+}\n+\n+/** Setup the input buffer state to scan a string. The next call to yylex() will\n+ * scan from a @e copy of @a str.\n+ * @param yystr a NUL-terminated string to scan\n+ * \n+ * @return the newly allocated buffer state object.\n+ * @note If you want to scan bytes that may contain NUL values, then use\n+ * yy_scan_bytes() instead.\n+ */\n+YY_BUFFER_STATE yy_scan_string (yyconst char * yystr )\n+{\n+ \n+\treturn yy_scan_bytes(yystr,strlen(yystr) );\n+}\n+\n+/** Setup the input buffer state to scan the given bytes. The next call to yylex() will\n+ * scan from a @e copy of @a bytes.\n+ * @param yybytes the byte buffer to scan\n+ * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.\n+ * \n+ * @return the newly allocated buffer state object.\n+ */\n+YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, int _yybytes_len )\n+{\n+\tYY_BUFFER_STATE b;\n+\tchar *buf;\n+\tyy_size_t n;\n+\tint i;\n+ \n+\t/* Get memory for full buffer, including space for trailing EOB's. */\n+\tn = _yybytes_len + 2;\n+\tbuf = (char *) yyalloc(n );\n+\tif ( ! buf )\n+\t\tYY_FATAL_ERROR( \"out of dynamic memory in yy_scan_bytes()\" );\n+\n+\tfor ( i = 0; i < _yybytes_len; ++i )\n+\t\tbuf[i] = yybytes[i];\n+\n+\tbuf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;\n+\n+\tb = yy_scan_buffer(buf,n );\n+\tif ( ! b )\n+\t\tYY_FATAL_ERROR( \"bad buffer in yy_scan_bytes()\" );\n+\n+\t/* It's okay to grow etc. this buffer, and we should throw it\n+\t * away when we're done.\n+\t */\n+\tb->yy_is_our_buffer = 1;\n+\n+\treturn b;\n+}\n+\n+#ifndef YY_EXIT_FAILURE\n+#define YY_EXIT_FAILURE 2\n+#endif\n+\n+static void yy_fatal_error (yyconst char* msg )\n+{\n+ \t(void) fprintf( stderr, \"%s\\n\", msg );\n+\texit( YY_EXIT_FAILURE );\n+}\n+\n+/* Redefine yyless() so it works in section 3 code. */\n+\n+#undef yyless\n+#define yyless(n) \\\n+\tdo \\\n+\t\t{ \\\n+\t\t/* Undo effects of setting up yytext. */ \\\n+ int yyless_macro_arg = (n); \\\n+ YY_LESS_LINENO(yyless_macro_arg);\\\n+\t\tyytext[yyleng] = (yy_hold_char); \\\n+\t\t(yy_c_buf_p) = yytext + yyless_macro_arg; \\\n+\t\t(yy_hold_char) = *(yy_c_buf_p); \\\n+\t\t*(yy_c_buf_p) = '\\0'; \\\n+\t\tyyleng = yyless_macro_arg; \\\n+\t\t} \\\n+\twhile ( 0 )\n+\n+/* Accessor methods (get/set functions) to struct members. */\n+\n+/** Get the current line number.\n+ * \n+ */\n+int yyget_lineno (void)\n+{\n+ \n+ return yylineno;\n+}\n+\n+/** Get the input stream.\n+ * \n+ */\n+FILE *yyget_in (void)\n+{\n+ return yyin;\n+}\n+\n+/** Get the output stream.\n+ * \n+ */\n+FILE *yyget_out (void)\n+{\n+ return yyout;\n+}\n+\n+/** Get the length of the current token.\n+ * \n+ */\n+int yyget_leng (void)\n+{\n+ return yyleng;\n+}\n+\n+/** Get the current token.\n+ * \n+ */\n+\n+char *yyget_text (void)\n+{\n+ return yytext;\n+}\n+\n+/** Set the current line number.\n+ * @param line_number\n+ * \n+ */\n+void yyset_lineno (int line_number )\n+{\n+ \n+ yylineno = line_number;\n+}\n+\n+/** Set the input stream. This does not discard the current\n+ * input buffer.\n+ * @param in_str A readable stream.\n+ * \n+ * @see yy_switch_to_buffer\n+ */\n+void yyset_in (FILE * in_str )\n+{\n+ yyin = in_str ;\n+}\n+\n+void yyset_out (FILE * out_str )\n+{\n+ yyout = out_str ;\n+}\n+\n+int yyget_debug (void)\n+{\n+ return yy_flex_debug;\n+}\n+\n+void yyset_debug (int bdebug )\n+{\n+ yy_flex_debug = bdebug ;\n+}\n+\n+static int yy_init_globals (void)\n+{\n+ /* Initialization is the same as for the non-reentrant scanner.\n+ * This function is called from yylex_destroy(), so don't allocate here.\n+ */\n+\n+ (yy_buffer_stack) = 0;\n+ (yy_buffer_stack_top) = 0;\n+ (yy_buffer_stack_max) = 0;\n+ (yy_c_buf_p) = (char *) 0;\n+ (yy_init) = 0;\n+ (yy_start) = 0;\n+\n+/* Defined in main.c */\n+#ifdef YY_STDINIT\n+ yyin = stdin;\n+ yyout = stdout;\n+#else\n+ yyin = (FILE *) 0;\n+ yyout = (FILE *) 0;\n+#endif\n+\n+ /* For future reference: Set errno on error, since we are called by\n+ * yylex_init()\n+ */\n+ return 0;\n+}\n+\n+/* yylex_destroy is for both reentrant and non-reentrant scanners. */\n+int yylex_destroy (void)\n+{\n+ \n+ /* Pop the buffer stack, destroying each element. */\n+\twhile(YY_CURRENT_BUFFER){\n+\t\tyy_delete_buffer(YY_CURRENT_BUFFER );\n+\t\tYY_CURRENT_BUFFER_LVALUE = NULL;\n+\t\tyypop_buffer_state();\n+\t}\n+\n+\t/* Destroy the stack itself. */\n+\tyyfree((yy_buffer_stack) );\n+\t(yy_buffer_stack) = NULL;\n+\n+ /* Reset the globals. This is important in a non-reentrant scanner so the next time\n+ * yylex() is called, initialization will occur. */\n+ yy_init_globals( );\n+\n+ return 0;\n+}\n+\n+/*\n+ * Internal utility routines.\n+ */\n+\n+#ifndef yytext_ptr\n+static void yy_flex_strncpy (char* s1, yyconst char * s2, int n )\n+{\n+\tregister int i;\n+\tfor ( i = 0; i < n; ++i )\n+\t\ts1[i] = s2[i];\n+}\n+#endif\n+\n+#ifdef YY_NEED_STRLEN\n+static int yy_flex_strlen (yyconst char * s )\n+{\n+\tregister int n;\n+\tfor ( n = 0; s[n]; ++n )\n+\t\t;\n+\n+\treturn n;\n+}\n+#endif\n+\n+void *yyalloc (yy_size_t size )\n+{\n+\treturn (void *) malloc( size );\n+}\n+\n+void *yyrealloc (void * ptr, yy_size_t size )\n+{\n+\t/* The cast to (char *) in the following accommodates both\n+\t * implementations that use char* generic pointers, and those\n+\t * that use void* generic pointers. It works with the latter\n+\t * because both ANSI C and C++ allow castless assignment from\n+\t * any pointer type to void*, and deal with argument conversions\n+\t * as though doing an assignment.\n+\t */\n+\treturn (void *) realloc( (char *) ptr, size );\n+}\n+\n+void yyfree (void * ptr )\n+{\n+\tfree( (char *) ptr );\t/* see yyrealloc() for (char *) cast */\n+}\n+\n+#define YYTABLES_NAME \"yytables\"\n+\n+#line 277 \"dtc-lexer.l\"\n+\n+\n+\n+static void push_input_file(const char *filename)\n+{\n+\tassert(filename);\n+\n+\tsrcfile_push(filename);\n+\n+\tyyin = current_srcfile->f;\n+\n+\tyypush_buffer_state(yy_create_buffer(yyin,YY_BUF_SIZE));\n+}\n+\n+\n+static bool pop_input_file(void)\n+{\n+\tif (srcfile_pop() == 0)\n+\t\treturn false;\n+\n+\tyypop_buffer_state();\n+\tyyin = current_srcfile->f;\n+\n+\treturn true;\n+}\n+\n+static void lexical_error(const char *fmt, ...)\n+{\n+\tva_list ap;\n+\n+\tva_start(ap, fmt);\n+\tsrcpos_verror(&yylloc, \"Lexical error\", fmt, ap);\n+\tva_end(ap);\n+\n+\ttreesource_error = true;\n+}\n+\ndiff --git a/scripts/dtc/dtc-parser.tab.c_shipped b/scripts/dtc/dtc-parser.tab.c_shipped\nnew file mode 100644\nindex 000000000000..4d10814b3f39\n--- /dev/null\n+++ b/scripts/dtc/dtc-parser.tab.c_shipped\n@@ -0,0 +1,2301 @@\n+/* A Bison parser, made by GNU Bison 3.0.2. */\n+\n+/* Bison implementation for Yacc-like parsers in C\n+\n+ Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.\n+\n+ This program is free software: you can redistribute it and/or modify\n+ it under the terms of the GNU General Public License as published by\n+ the Free Software Foundation, either version 3 of the License, or\n+ (at your option) any later version.\n+\n+ This program is distributed in the hope that it will be useful,\n+ but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n+ GNU General Public License for more details.\n+\n+ You should have received a copy of the GNU General Public License\n+ along with this program. If not, see <http://www.gnu.org/licenses/>. */\n+\n+/* As a special exception, you may create a larger work that contains\n+ part or all of the Bison parser skeleton and distribute that work\n+ under terms of your choice, so long as that work isn't itself a\n+ parser generator using the skeleton or a modified version thereof\n+ as a parser skeleton. Alternatively, if you modify or redistribute\n+ the parser skeleton itself, you may (at your option) remove this\n+ special exception, which will cause the skeleton and the resulting\n+ Bison output files to be licensed under the GNU General Public\n+ License without this special exception.\n+\n+ This special exception was added by the Free Software Foundation in\n+ version 2.2 of Bison. */\n+\n+/* C LALR(1) parser skeleton written by Richard Stallman, by\n+ simplifying the original so-called \"semantic\" parser. */\n+\n+/* All symbols defined below should begin with yy or YY, to avoid\n+ infringing on user name space. This should be done even for local\n+ variables, as they might otherwise be expanded by user macros.\n+ There are some unavoidable exceptions within include files to\n+ define necessary library symbols; they are noted \"INFRINGES ON\n+ USER NAME SPACE\" below. */\n+\n+/* Identify Bison output. */\n+#define YYBISON 1\n+\n+/* Bison version. */\n+#define YYBISON_VERSION \"3.0.2\"\n+\n+/* Skeleton name. */\n+#define YYSKELETON_NAME \"yacc.c\"\n+\n+/* Pure parsers. */\n+#define YYPURE 0\n+\n+/* Push parsers. */\n+#define YYPUSH 0\n+\n+/* Pull parsers. */\n+#define YYPULL 1\n+\n+\n+\n+\n+/* Copy the first part of user declarations. */\n+#line 20 \"dtc-parser.y\" /* yacc.c:339 */\n+\n+#include <stdio.h>\n+#include <inttypes.h>\n+\n+#include \"dtc.h\"\n+#include \"srcpos.h\"\n+\n+extern int yylex(void);\n+extern void yyerror(char const *s);\n+#define ERROR(loc, ...) \\\n+\tdo { \\\n+\t\tsrcpos_error((loc), \"Error\", __VA_ARGS__); \\\n+\t\ttreesource_error = true; \\\n+\t} while (0)\n+\n+extern struct dt_info *parser_output;\n+extern bool treesource_error;\n+\n+#line 85 \"dtc-parser.tab.c\" /* yacc.c:339 */\n+\n+# ifndef YY_NULLPTR\n+# if defined __cplusplus && 201103L <= __cplusplus\n+# define YY_NULLPTR nullptr\n+# else\n+# define YY_NULLPTR 0\n+# endif\n+# endif\n+\n+/* Enabling verbose error messages. */\n+#ifdef YYERROR_VERBOSE\n+# undef YYERROR_VERBOSE\n+# define YYERROR_VERBOSE 1\n+#else\n+# define YYERROR_VERBOSE 0\n+#endif\n+\n+/* In a future release of Bison, this section will be replaced\n+ by #include \"dtc-parser.tab.h\". */\n+#ifndef YY_YY_DTC_PARSER_TAB_H_INCLUDED\n+# define YY_YY_DTC_PARSER_TAB_H_INCLUDED\n+/* Debug traces. */\n+#ifndef YYDEBUG\n+# define YYDEBUG 0\n+#endif\n+#if YYDEBUG\n+extern int yydebug;\n+#endif\n+\n+/* Token type. */\n+#ifndef YYTOKENTYPE\n+# define YYTOKENTYPE\n+ enum yytokentype\n+ {\n+ DT_V1 = 258,\n+ DT_PLUGIN = 259,\n+ DT_MEMRESERVE = 260,\n+ DT_LSHIFT = 261,\n+ DT_RSHIFT = 262,\n+ DT_LE = 263,\n+ DT_GE = 264,\n+ DT_EQ = 265,\n+ DT_NE = 266,\n+ DT_AND = 267,\n+ DT_OR = 268,\n+ DT_BITS = 269,\n+ DT_DEL_PROP = 270,\n+ DT_DEL_NODE = 271,\n+ DT_PROPNODENAME = 272,\n+ DT_LITERAL = 273,\n+ DT_CHAR_LITERAL = 274,\n+ DT_BYTE = 275,\n+ DT_STRING = 276,\n+ DT_LABEL = 277,\n+ DT_REF = 278,\n+ DT_INCBIN = 279\n+ };\n+#endif\n+\n+/* Value type. */\n+#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED\n+typedef union YYSTYPE YYSTYPE;\n+union YYSTYPE\n+{\n+#line 39 \"dtc-parser.y\" /* yacc.c:355 */\n+\n+\tchar *propnodename;\n+\tchar *labelref;\n+\tuint8_t byte;\n+\tstruct data data;\n+\n+\tstruct {\n+\t\tstruct data\tdata;\n+\t\tint\t\tbits;\n+\t} array;\n+\n+\tstruct property *prop;\n+\tstruct property *proplist;\n+\tstruct node *node;\n+\tstruct node *nodelist;\n+\tstruct reserve_info *re;\n+\tuint64_t integer;\n+\tunsigned int flags;\n+\n+#line 170 \"dtc-parser.tab.c\" /* yacc.c:355 */\n+};\n+# define YYSTYPE_IS_TRIVIAL 1\n+# define YYSTYPE_IS_DECLARED 1\n+#endif\n+\n+/* Location type. */\n+#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED\n+typedef struct YYLTYPE YYLTYPE;\n+struct YYLTYPE\n+{\n+ int first_line;\n+ int first_column;\n+ int last_line;\n+ int last_column;\n+};\n+# define YYLTYPE_IS_DECLARED 1\n+# define YYLTYPE_IS_TRIVIAL 1\n+#endif\n+\n+\n+extern YYSTYPE yylval;\n+extern YYLTYPE yylloc;\n+int yyparse (void);\n+\n+#endif /* !YY_YY_DTC_PARSER_TAB_H_INCLUDED */\n+\n+/* Copy the second part of user declarations. */\n+\n+#line 199 \"dtc-parser.tab.c\" /* yacc.c:358 */\n+\n+#ifdef short\n+# undef short\n+#endif\n+\n+#ifdef YYTYPE_UINT8\n+typedef YYTYPE_UINT8 yytype_uint8;\n+#else\n+typedef unsigned char yytype_uint8;\n+#endif\n+\n+#ifdef YYTYPE_INT8\n+typedef YYTYPE_INT8 yytype_int8;\n+#else\n+typedef signed char yytype_int8;\n+#endif\n+\n+#ifdef YYTYPE_UINT16\n+typedef YYTYPE_UINT16 yytype_uint16;\n+#else\n+typedef unsigned short int yytype_uint16;\n+#endif\n+\n+#ifdef YYTYPE_INT16\n+typedef YYTYPE_INT16 yytype_int16;\n+#else\n+typedef short int yytype_int16;\n+#endif\n+\n+#ifndef YYSIZE_T\n+# ifdef __SIZE_TYPE__\n+# define YYSIZE_T __SIZE_TYPE__\n+# elif defined size_t\n+# define YYSIZE_T size_t\n+# elif ! defined YYSIZE_T\n+# include <stddef.h> /* INFRINGES ON USER NAME SPACE */\n+# define YYSIZE_T size_t\n+# else\n+# define YYSIZE_T unsigned int\n+# endif\n+#endif\n+\n+#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)\n+\n+#ifndef YY_\n+# if defined YYENABLE_NLS && YYENABLE_NLS\n+# if ENABLE_NLS\n+# include <libintl.h> /* INFRINGES ON USER NAME SPACE */\n+# define YY_(Msgid) dgettext (\"bison-runtime\", Msgid)\n+# endif\n+# endif\n+# ifndef YY_\n+# define YY_(Msgid) Msgid\n+# endif\n+#endif\n+\n+#ifndef YY_ATTRIBUTE\n+# if (defined __GNUC__ \\\n+ && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \\\n+ || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C\n+# define YY_ATTRIBUTE(Spec) __attribute__(Spec)\n+# else\n+# define YY_ATTRIBUTE(Spec) /* empty */\n+# endif\n+#endif\n+\n+#ifndef YY_ATTRIBUTE_PURE\n+# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__))\n+#endif\n+\n+#ifndef YY_ATTRIBUTE_UNUSED\n+# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))\n+#endif\n+\n+#if !defined _Noreturn \\\n+ && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)\n+# if defined _MSC_VER && 1200 <= _MSC_VER\n+# define _Noreturn __declspec (noreturn)\n+# else\n+# define _Noreturn YY_ATTRIBUTE ((__noreturn__))\n+# endif\n+#endif\n+\n+/* Suppress unused-variable warnings by \"using\" E. */\n+#if ! defined lint || defined __GNUC__\n+# define YYUSE(E) ((void) (E))\n+#else\n+# define YYUSE(E) /* empty */\n+#endif\n+\n+#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__\n+/* Suppress an incorrect diagnostic about yylval being uninitialized. */\n+# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \\\n+ _Pragma (\"GCC diagnostic push\") \\\n+ _Pragma (\"GCC diagnostic ignored \\\"-Wuninitialized\\\"\")\\\n+ _Pragma (\"GCC diagnostic ignored \\\"-Wmaybe-uninitialized\\\"\")\n+# define YY_IGNORE_MAYBE_UNINITIALIZED_END \\\n+ _Pragma (\"GCC diagnostic pop\")\n+#else\n+# define YY_INITIAL_VALUE(Value) Value\n+#endif\n+#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN\n+# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN\n+# define YY_IGNORE_MAYBE_UNINITIALIZED_END\n+#endif\n+#ifndef YY_INITIAL_VALUE\n+# define YY_INITIAL_VALUE(Value) /* Nothing. */\n+#endif\n+\n+\n+#if ! defined yyoverflow || YYERROR_VERBOSE\n+\n+/* The parser invokes alloca or malloc; define the necessary symbols. */\n+\n+# ifdef YYSTACK_USE_ALLOCA\n+# if YYSTACK_USE_ALLOCA\n+# ifdef __GNUC__\n+# define YYSTACK_ALLOC __builtin_alloca\n+# elif defined __BUILTIN_VA_ARG_INCR\n+# include <alloca.h> /* INFRINGES ON USER NAME SPACE */\n+# elif defined _AIX\n+# define YYSTACK_ALLOC __alloca\n+# elif defined _MSC_VER\n+# include <malloc.h> /* INFRINGES ON USER NAME SPACE */\n+# define alloca _alloca\n+# else\n+# define YYSTACK_ALLOC alloca\n+# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS\n+# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */\n+ /* Use EXIT_SUCCESS as a witness for stdlib.h. */\n+# ifndef EXIT_SUCCESS\n+# define EXIT_SUCCESS 0\n+# endif\n+# endif\n+# endif\n+# endif\n+# endif\n+\n+# ifdef YYSTACK_ALLOC\n+ /* Pacify GCC's 'empty if-body' warning. */\n+# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)\n+# ifndef YYSTACK_ALLOC_MAXIMUM\n+ /* The OS might guarantee only one guard page at the bottom of the stack,\n+ and a page size can be as small as 4096 bytes. So we cannot safely\n+ invoke alloca (N) if N exceeds 4096. Use a slightly smaller number\n+ to allow for a few compiler-allocated temporary stack slots. */\n+# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */\n+# endif\n+# else\n+# define YYSTACK_ALLOC YYMALLOC\n+# define YYSTACK_FREE YYFREE\n+# ifndef YYSTACK_ALLOC_MAXIMUM\n+# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM\n+# endif\n+# if (defined __cplusplus && ! defined EXIT_SUCCESS \\\n+ && ! ((defined YYMALLOC || defined malloc) \\\n+ && (defined YYFREE || defined free)))\n+# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */\n+# ifndef EXIT_SUCCESS\n+# define EXIT_SUCCESS 0\n+# endif\n+# endif\n+# ifndef YYMALLOC\n+# define YYMALLOC malloc\n+# if ! defined malloc && ! defined EXIT_SUCCESS\n+void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */\n+# endif\n+# endif\n+# ifndef YYFREE\n+# define YYFREE free\n+# if ! defined free && ! defined EXIT_SUCCESS\n+void free (void *); /* INFRINGES ON USER NAME SPACE */\n+# endif\n+# endif\n+# endif\n+#endif /* ! defined yyoverflow || YYERROR_VERBOSE */\n+\n+\n+#if (! defined yyoverflow \\\n+ && (! defined __cplusplus \\\n+ || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \\\n+ && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))\n+\n+/* A type that is properly aligned for any stack member. */\n+union yyalloc\n+{\n+ yytype_int16 yyss_alloc;\n+ YYSTYPE yyvs_alloc;\n+ YYLTYPE yyls_alloc;\n+};\n+\n+/* The size of the maximum gap between one aligned stack and the next. */\n+# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)\n+\n+/* The size of an array large to enough to hold all stacks, each with\n+ N elements. */\n+# define YYSTACK_BYTES(N) \\\n+ ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \\\n+ + 2 * YYSTACK_GAP_MAXIMUM)\n+\n+# define YYCOPY_NEEDED 1\n+\n+/* Relocate STACK from its old location to the new one. The\n+ local variables YYSIZE and YYSTACKSIZE give the old and new number of\n+ elements in the stack, and YYPTR gives the new location of the\n+ stack. Advance YYPTR to a properly aligned location for the next\n+ stack. */\n+# define YYSTACK_RELOCATE(Stack_alloc, Stack) \\\n+ do \\\n+ { \\\n+ YYSIZE_T yynewbytes; \\\n+ YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \\\n+ Stack = &yyptr->Stack_alloc; \\\n+ yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \\\n+ yyptr += yynewbytes / sizeof (*yyptr); \\\n+ } \\\n+ while (0)\n+\n+#endif\n+\n+#if defined YYCOPY_NEEDED && YYCOPY_NEEDED\n+/* Copy COUNT objects from SRC to DST. The source and destination do\n+ not overlap. */\n+# ifndef YYCOPY\n+# if defined __GNUC__ && 1 < __GNUC__\n+# define YYCOPY(Dst, Src, Count) \\\n+ __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))\n+# else\n+# define YYCOPY(Dst, Src, Count) \\\n+ do \\\n+ { \\\n+ YYSIZE_T yyi; \\\n+ for (yyi = 0; yyi < (Count); yyi++) \\\n+ (Dst)[yyi] = (Src)[yyi]; \\\n+ } \\\n+ while (0)\n+# endif\n+# endif\n+#endif /* !YYCOPY_NEEDED */\n+\n+/* YYFINAL -- State number of the termination state. */\n+#define YYFINAL 6\n+/* YYLAST -- Last index in YYTABLE. */\n+#define YYLAST 138\n+\n+/* YYNTOKENS -- Number of terminals. */\n+#define YYNTOKENS 48\n+/* YYNNTS -- Number of nonterminals. */\n+#define YYNNTS 30\n+/* YYNRULES -- Number of rules. */\n+#define YYNRULES 84\n+/* YYNSTATES -- Number of states. */\n+#define YYNSTATES 149\n+\n+/* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned\n+ by yylex, with out-of-bounds checking. */\n+#define YYUNDEFTOK 2\n+#define YYMAXUTOK 279\n+\n+#define YYTRANSLATE(YYX) \\\n+ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)\n+\n+/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM\n+ as returned by yylex, without out-of-bounds checking. */\n+static const yytype_uint8 yytranslate[] =\n+{\n+ 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n+ 2, 2, 2, 47, 2, 2, 2, 45, 41, 2,\n+ 33, 35, 44, 42, 34, 43, 2, 26, 2, 2,\n+ 2, 2, 2, 2, 2, 2, 2, 2, 38, 25,\n+ 36, 29, 30, 37, 2, 2, 2, 2, 2, 2,\n+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n+ 2, 31, 2, 32, 40, 2, 2, 2, 2, 2,\n+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n+ 2, 2, 2, 27, 39, 28, 46, 2, 2, 2,\n+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n+ 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,\n+ 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,\n+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24\n+};\n+\n+#if YYDEBUG\n+ /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */\n+static const yytype_uint16 yyrline[] =\n+{\n+ 0, 109, 109, 117, 121, 128, 129, 139, 142, 149,\n+ 153, 161, 165, 170, 181, 191, 206, 214, 217, 224,\n+ 228, 232, 236, 244, 248, 252, 256, 260, 276, 286,\n+ 294, 297, 301, 308, 324, 329, 348, 362, 369, 370,\n+ 371, 378, 382, 383, 387, 388, 392, 393, 397, 398,\n+ 402, 403, 407, 408, 412, 413, 414, 418, 419, 420,\n+ 421, 422, 426, 427, 428, 432, 433, 434, 438, 439,\n+ 448, 457, 461, 462, 463, 464, 469, 472, 476, 484,\n+ 487, 491, 499, 503, 507\n+};\n+#endif\n+\n+#if YYDEBUG || YYERROR_VERBOSE || 0\n+/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.\n+ First, the terminals, then, starting at YYNTOKENS, nonterminals. */\n+static const char *const yytname[] =\n+{\n+ \"$end\", \"error\", \"$undefined\", \"DT_V1\", \"DT_PLUGIN\", \"DT_MEMRESERVE\",\n+ \"DT_LSHIFT\", \"DT_RSHIFT\", \"DT_LE\", \"DT_GE\", \"DT_EQ\", \"DT_NE\", \"DT_AND\",\n+ \"DT_OR\", \"DT_BITS\", \"DT_DEL_PROP\", \"DT_DEL_NODE\", \"DT_PROPNODENAME\",\n+ \"DT_LITERAL\", \"DT_CHAR_LITERAL\", \"DT_BYTE\", \"DT_STRING\", \"DT_LABEL\",\n+ \"DT_REF\", \"DT_INCBIN\", \"';'\", \"'/'\", \"'{'\", \"'}'\", \"'='\", \"'>'\", \"'['\",\n+ \"']'\", \"'('\", \"','\", \"')'\", \"'<'\", \"'?'\", \"':'\", \"'|'\", \"'^'\", \"'&'\",\n+ \"'+'\", \"'-'\", \"'*'\", \"'%'\", \"'~'\", \"'!'\", \"$accept\", \"sourcefile\",\n+ \"header\", \"headers\", \"memreserves\", \"memreserve\", \"devicetree\",\n+ \"nodedef\", \"proplist\", \"propdef\", \"propdata\", \"propdataprefix\",\n+ \"arrayprefix\", \"integer_prim\", \"integer_expr\", \"integer_trinary\",\n+ \"integer_or\", \"integer_and\", \"integer_bitor\", \"integer_bitxor\",\n+ \"integer_bitand\", \"integer_eq\", \"integer_rela\", \"integer_shift\",\n+ \"integer_add\", \"integer_mul\", \"integer_unary\", \"bytestring\", \"subnodes\",\n+ \"subnode\", YY_NULLPTR\n+};\n+#endif\n+\n+# ifdef YYPRINT\n+/* YYTOKNUM[NUM] -- (External) token number corresponding to the\n+ (internal) symbol number NUM (which must be that of a token). */\n+static const yytype_uint16 yytoknum[] =\n+{\n+ 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,\n+ 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,\n+ 275, 276, 277, 278, 279, 59, 47, 123, 125, 61,\n+ 62, 91, 93, 40, 44, 41, 60, 63, 58, 124,\n+ 94, 38, 43, 45, 42, 37, 126, 33\n+};\n+# endif\n+\n+#define YYPACT_NINF -44\n+\n+#define yypact_value_is_default(Yystate) \\\n+ (!!((Yystate) == (-44)))\n+\n+#define YYTABLE_NINF -1\n+\n+#define yytable_value_is_error(Yytable_value) \\\n+ 0\n+\n+ /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing\n+ STATE-NUM. */\n+static const yytype_int8 yypact[] =\n+{\n+ 14, 27, 61, 14, 8, 18, -44, -44, 37, 8,\n+ 40, 8, 64, -44, -44, -12, 37, -44, 50, 52,\n+ -44, -44, -12, -12, -12, -44, 51, -44, -4, 78,\n+ 53, 54, 55, 17, 2, 30, 38, -3, -44, 66,\n+ -44, -44, 70, 72, 50, 50, -44, -44, -44, -44,\n+ -12, -12, -12, -12, -12, -12, -12, -12, -12, -12,\n+ -12, -12, -12, -12, -12, -12, -12, -12, -12, -44,\n+ 3, 73, 50, -44, -44, 78, 59, 53, 54, 55,\n+ 17, 2, 2, 30, 30, 30, 30, 38, 38, -3,\n+ -3, -44, -44, -44, 82, 83, 44, 3, -44, 74,\n+ 3, -44, -44, -12, 76, 79, -44, -44, -44, -44,\n+ -44, 80, -44, -44, -44, -44, -44, -10, 36, -44,\n+ -44, -44, -44, 85, -44, -44, -44, 75, -44, -44,\n+ 21, 71, 88, -6, -44, -44, -44, -44, -44, 11,\n+ -44, -44, -44, 37, -44, 77, 37, 81, -44\n+};\n+\n+ /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.\n+ Performed when YYTABLE does not specify something else to do. Zero\n+ means the default is an error. */\n+static const yytype_uint8 yydefact[] =\n+{\n+ 0, 0, 0, 5, 7, 3, 1, 6, 0, 0,\n+ 0, 7, 0, 38, 39, 0, 0, 10, 0, 2,\n+ 8, 4, 0, 0, 0, 72, 0, 41, 42, 44,\n+ 46, 48, 50, 52, 54, 57, 64, 67, 71, 0,\n+ 17, 11, 0, 0, 0, 0, 73, 74, 75, 40,\n+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,\n+ 79, 0, 0, 14, 12, 45, 0, 47, 49, 51,\n+ 53, 55, 56, 60, 61, 59, 58, 62, 63, 65,\n+ 66, 69, 68, 70, 0, 0, 0, 0, 18, 0,\n+ 79, 15, 13, 0, 0, 0, 20, 30, 82, 22,\n+ 84, 0, 81, 80, 43, 21, 83, 0, 0, 16,\n+ 29, 19, 31, 0, 23, 32, 26, 0, 76, 34,\n+ 0, 0, 0, 0, 37, 36, 24, 35, 33, 0,\n+ 77, 78, 25, 0, 28, 0, 0, 0, 27\n+};\n+\n+ /* YYPGOTO[NTERM-NUM]. */\n+static const yytype_int8 yypgoto[] =\n+{\n+ -44, -44, -44, 103, 99, 104, -44, -43, -44, -21,\n+ -44, -44, -44, -8, 63, 9, -44, 65, 67, 68,\n+ 69, 62, 26, 4, 22, 23, -19, -44, 20, 28\n+};\n+\n+ /* YYDEFGOTO[NTERM-NUM]. */\n+static const yytype_int16 yydefgoto[] =\n+{\n+ -1, 2, 3, 4, 10, 11, 19, 41, 70, 98,\n+ 117, 118, 130, 25, 26, 27, 28, 29, 30, 31,\n+ 32, 33, 34, 35, 36, 37, 38, 133, 99, 100\n+};\n+\n+ /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If\n+ positive, shift that token. If negative, reduce the rule whose\n+ number is the opposite. If YYTABLE_NINF, syntax error. */\n+static const yytype_uint8 yytable[] =\n+{\n+ 16, 73, 74, 46, 47, 48, 13, 14, 39, 50,\n+ 58, 59, 120, 8, 140, 121, 141, 1, 94, 95,\n+ 96, 15, 12, 66, 122, 97, 142, 56, 57, 102,\n+ 9, 22, 60, 51, 23, 24, 62, 63, 61, 13,\n+ 14, 67, 68, 134, 135, 143, 144, 91, 92, 93,\n+ 123, 136, 5, 108, 15, 13, 14, 124, 125, 126,\n+ 127, 6, 83, 84, 85, 86, 18, 128, 42, 106,\n+ 15, 40, 129, 107, 43, 44, 109, 40, 45, 112,\n+ 64, 65, 81, 82, 87, 88, 49, 89, 90, 21,\n+ 52, 69, 53, 71, 54, 72, 55, 103, 101, 104,\n+ 105, 115, 111, 131, 116, 119, 7, 138, 132, 139,\n+ 20, 146, 114, 17, 76, 75, 148, 80, 0, 77,\n+ 113, 78, 137, 79, 0, 110, 0, 0, 0, 0,\n+ 0, 0, 0, 0, 0, 145, 0, 0, 147\n+};\n+\n+static const yytype_int16 yycheck[] =\n+{\n+ 8, 44, 45, 22, 23, 24, 18, 19, 16, 13,\n+ 8, 9, 22, 5, 20, 25, 22, 3, 15, 16,\n+ 17, 33, 4, 26, 34, 22, 32, 10, 11, 72,\n+ 22, 43, 30, 37, 46, 47, 6, 7, 36, 18,\n+ 19, 44, 45, 22, 23, 34, 35, 66, 67, 68,\n+ 14, 30, 25, 96, 33, 18, 19, 21, 22, 23,\n+ 24, 0, 58, 59, 60, 61, 26, 31, 16, 25,\n+ 33, 27, 36, 29, 22, 23, 97, 27, 26, 100,\n+ 42, 43, 56, 57, 62, 63, 35, 64, 65, 25,\n+ 12, 25, 39, 23, 40, 23, 41, 38, 25, 17,\n+ 17, 25, 28, 18, 25, 25, 3, 36, 33, 21,\n+ 11, 34, 103, 9, 51, 50, 35, 55, -1, 52,\n+ 100, 53, 130, 54, -1, 97, -1, -1, -1, -1,\n+ -1, -1, -1, -1, -1, 143, -1, -1, 146\n+};\n+\n+ /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing\n+ symbol of state STATE-NUM. */\n+static const yytype_uint8 yystos[] =\n+{\n+ 0, 3, 49, 50, 51, 25, 0, 51, 5, 22,\n+ 52, 53, 4, 18, 19, 33, 61, 53, 26, 54,\n+ 52, 25, 43, 46, 47, 61, 62, 63, 64, 65,\n+ 66, 67, 68, 69, 70, 71, 72, 73, 74, 61,\n+ 27, 55, 16, 22, 23, 26, 74, 74, 74, 35,\n+ 13, 37, 12, 39, 40, 41, 10, 11, 8, 9,\n+ 30, 36, 6, 7, 42, 43, 26, 44, 45, 25,\n+ 56, 23, 23, 55, 55, 65, 62, 66, 67, 68,\n+ 69, 70, 70, 71, 71, 71, 71, 72, 72, 73,\n+ 73, 74, 74, 74, 15, 16, 17, 22, 57, 76,\n+ 77, 25, 55, 38, 17, 17, 25, 29, 55, 57,\n+ 77, 28, 57, 76, 63, 25, 25, 58, 59, 25,\n+ 22, 25, 34, 14, 21, 22, 23, 24, 31, 36,\n+ 60, 18, 33, 75, 22, 23, 30, 61, 36, 21,\n+ 20, 22, 32, 34, 35, 61, 34, 61, 35\n+};\n+\n+ /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */\n+static const yytype_uint8 yyr1[] =\n+{\n+ 0, 48, 49, 50, 50, 51, 51, 52, 52, 53,\n+ 53, 54, 54, 54, 54, 54, 55, 56, 56, 57,\n+ 57, 57, 57, 58, 58, 58, 58, 58, 58, 58,\n+ 59, 59, 59, 60, 60, 60, 60, 60, 61, 61,\n+ 61, 62, 63, 63, 64, 64, 65, 65, 66, 66,\n+ 67, 67, 68, 68, 69, 69, 69, 70, 70, 70,\n+ 70, 70, 71, 71, 71, 72, 72, 72, 73, 73,\n+ 73, 73, 74, 74, 74, 74, 75, 75, 75, 76,\n+ 76, 76, 77, 77, 77\n+};\n+\n+ /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */\n+static const yytype_uint8 yyr2[] =\n+{\n+ 0, 2, 3, 2, 4, 1, 2, 0, 2, 4,\n+ 2, 2, 3, 4, 3, 4, 5, 0, 2, 4,\n+ 2, 3, 2, 2, 3, 4, 2, 9, 5, 2,\n+ 0, 2, 2, 3, 1, 2, 2, 2, 1, 1,\n+ 3, 1, 1, 5, 1, 3, 1, 3, 1, 3,\n+ 1, 3, 1, 3, 1, 3, 3, 1, 3, 3,\n+ 3, 3, 3, 3, 1, 3, 3, 1, 3, 3,\n+ 3, 1, 1, 2, 2, 2, 0, 2, 2, 0,\n+ 2, 2, 2, 3, 2\n+};\n+\n+\n+#define yyerrok (yyerrstatus = 0)\n+#define yyclearin (yychar = YYEMPTY)\n+#define YYEMPTY (-2)\n+#define YYEOF 0\n+\n+#define YYACCEPT goto yyacceptlab\n+#define YYABORT goto yyabortlab\n+#define YYERROR goto yyerrorlab\n+\n+\n+#define YYRECOVERING() (!!yyerrstatus)\n+\n+#define YYBACKUP(Token, Value) \\\n+do \\\n+ if (yychar == YYEMPTY) \\\n+ { \\\n+ yychar = (Token); \\\n+ yylval = (Value); \\\n+ YYPOPSTACK (yylen); \\\n+ yystate = *yyssp; \\\n+ goto yybackup; \\\n+ } \\\n+ else \\\n+ { \\\n+ yyerror (YY_(\"syntax error: cannot back up\")); \\\n+ YYERROR; \\\n+ } \\\n+while (0)\n+\n+/* Error token number */\n+#define YYTERROR 1\n+#define YYERRCODE 256\n+\n+\n+/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].\n+ If N is 0, then set CURRENT to the empty location which ends\n+ the previous symbol: RHS[0] (always defined). */\n+\n+#ifndef YYLLOC_DEFAULT\n+# define YYLLOC_DEFAULT(Current, Rhs, N) \\\n+ do \\\n+ if (N) \\\n+ { \\\n+ (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \\\n+ (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \\\n+ (Current).last_line = YYRHSLOC (Rhs, N).last_line; \\\n+ (Current).last_column = YYRHSLOC (Rhs, N).last_column; \\\n+ } \\\n+ else \\\n+ { \\\n+ (Current).first_line = (Current).last_line = \\\n+ YYRHSLOC (Rhs, 0).last_line; \\\n+ (Current).first_column = (Current).last_column = \\\n+ YYRHSLOC (Rhs, 0).last_column; \\\n+ } \\\n+ while (0)\n+#endif\n+\n+#define YYRHSLOC(Rhs, K) ((Rhs)[K])\n+\n+\n+/* Enable debugging if requested. */\n+#if YYDEBUG\n+\n+# ifndef YYFPRINTF\n+# include <stdio.h> /* INFRINGES ON USER NAME SPACE */\n+# define YYFPRINTF fprintf\n+# endif\n+\n+# define YYDPRINTF(Args) \\\n+do { \\\n+ if (yydebug) \\\n+ YYFPRINTF Args; \\\n+} while (0)\n+\n+\n+/* YY_LOCATION_PRINT -- Print the location on the stream.\n+ This macro was not mandated originally: define only if we know\n+ we won't break user code: when these are the locations we know. */\n+\n+#ifndef YY_LOCATION_PRINT\n+# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL\n+\n+/* Print *YYLOCP on YYO. Private, do not rely on its existence. */\n+\n+YY_ATTRIBUTE_UNUSED\n+static unsigned\n+yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp)\n+{\n+ unsigned res = 0;\n+ int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0;\n+ if (0 <= yylocp->first_line)\n+ {\n+ res += YYFPRINTF (yyo, \"%d\", yylocp->first_line);\n+ if (0 <= yylocp->first_column)\n+ res += YYFPRINTF (yyo, \".%d\", yylocp->first_column);\n+ }\n+ if (0 <= yylocp->last_line)\n+ {\n+ if (yylocp->first_line < yylocp->last_line)\n+ {\n+ res += YYFPRINTF (yyo, \"-%d\", yylocp->last_line);\n+ if (0 <= end_col)\n+ res += YYFPRINTF (yyo, \".%d\", end_col);\n+ }\n+ else if (0 <= end_col && yylocp->first_column < end_col)\n+ res += YYFPRINTF (yyo, \"-%d\", end_col);\n+ }\n+ return res;\n+ }\n+\n+# define YY_LOCATION_PRINT(File, Loc) \\\n+ yy_location_print_ (File, &(Loc))\n+\n+# else\n+# define YY_LOCATION_PRINT(File, Loc) ((void) 0)\n+# endif\n+#endif\n+\n+\n+# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \\\n+do { \\\n+ if (yydebug) \\\n+ { \\\n+ YYFPRINTF (stderr, \"%s \", Title); \\\n+ yy_symbol_print (stderr, \\\n+ Type, Value, Location); \\\n+ YYFPRINTF (stderr, \"\\n\"); \\\n+ } \\\n+} while (0)\n+\n+\n+/*----------------------------------------.\n+| Print this symbol's value on YYOUTPUT. |\n+`----------------------------------------*/\n+\n+static void\n+yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)\n+{\n+ FILE *yyo = yyoutput;\n+ YYUSE (yyo);\n+ YYUSE (yylocationp);\n+ if (!yyvaluep)\n+ return;\n+# ifdef YYPRINT\n+ if (yytype < YYNTOKENS)\n+ YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);\n+# endif\n+ YYUSE (yytype);\n+}\n+\n+\n+/*--------------------------------.\n+| Print this symbol on YYOUTPUT. |\n+`--------------------------------*/\n+\n+static void\n+yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)\n+{\n+ YYFPRINTF (yyoutput, \"%s %s (\",\n+ yytype < YYNTOKENS ? \"token\" : \"nterm\", yytname[yytype]);\n+\n+ YY_LOCATION_PRINT (yyoutput, *yylocationp);\n+ YYFPRINTF (yyoutput, \": \");\n+ yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp);\n+ YYFPRINTF (yyoutput, \")\");\n+}\n+\n+/*------------------------------------------------------------------.\n+| yy_stack_print -- Print the state stack from its BOTTOM up to its |\n+| TOP (included). |\n+`------------------------------------------------------------------*/\n+\n+static void\n+yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)\n+{\n+ YYFPRINTF (stderr, \"Stack now\");\n+ for (; yybottom <= yytop; yybottom++)\n+ {\n+ int yybot = *yybottom;\n+ YYFPRINTF (stderr, \" %d\", yybot);\n+ }\n+ YYFPRINTF (stderr, \"\\n\");\n+}\n+\n+# define YY_STACK_PRINT(Bottom, Top) \\\n+do { \\\n+ if (yydebug) \\\n+ yy_stack_print ((Bottom), (Top)); \\\n+} while (0)\n+\n+\n+/*------------------------------------------------.\n+| Report that the YYRULE is going to be reduced. |\n+`------------------------------------------------*/\n+\n+static void\n+yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule)\n+{\n+ unsigned long int yylno = yyrline[yyrule];\n+ int yynrhs = yyr2[yyrule];\n+ int yyi;\n+ YYFPRINTF (stderr, \"Reducing stack by rule %d (line %lu):\\n\",\n+ yyrule - 1, yylno);\n+ /* The symbols being reduced. */\n+ for (yyi = 0; yyi < yynrhs; yyi++)\n+ {\n+ YYFPRINTF (stderr, \" $%d = \", yyi + 1);\n+ yy_symbol_print (stderr,\n+ yystos[yyssp[yyi + 1 - yynrhs]],\n+ &(yyvsp[(yyi + 1) - (yynrhs)])\n+ , &(yylsp[(yyi + 1) - (yynrhs)]) );\n+ YYFPRINTF (stderr, \"\\n\");\n+ }\n+}\n+\n+# define YY_REDUCE_PRINT(Rule) \\\n+do { \\\n+ if (yydebug) \\\n+ yy_reduce_print (yyssp, yyvsp, yylsp, Rule); \\\n+} while (0)\n+\n+/* Nonzero means print parse trace. It is left uninitialized so that\n+ multiple parsers can coexist. */\n+int yydebug;\n+#else /* !YYDEBUG */\n+# define YYDPRINTF(Args)\n+# define YY_SYMBOL_PRINT(Title, Type, Value, Location)\n+# define YY_STACK_PRINT(Bottom, Top)\n+# define YY_REDUCE_PRINT(Rule)\n+#endif /* !YYDEBUG */\n+\n+\n+/* YYINITDEPTH -- initial size of the parser's stacks. */\n+#ifndef YYINITDEPTH\n+# define YYINITDEPTH 200\n+#endif\n+\n+/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only\n+ if the built-in stack extension method is used).\n+\n+ Do not make this value too large; the results are undefined if\n+ YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)\n+ evaluated with infinite-precision integer arithmetic. */\n+\n+#ifndef YYMAXDEPTH\n+# define YYMAXDEPTH 10000\n+#endif\n+\n+\n+#if YYERROR_VERBOSE\n+\n+# ifndef yystrlen\n+# if defined __GLIBC__ && defined _STRING_H\n+# define yystrlen strlen\n+# else\n+/* Return the length of YYSTR. */\n+static YYSIZE_T\n+yystrlen (const char *yystr)\n+{\n+ YYSIZE_T yylen;\n+ for (yylen = 0; yystr[yylen]; yylen++)\n+ continue;\n+ return yylen;\n+}\n+# endif\n+# endif\n+\n+# ifndef yystpcpy\n+# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE\n+# define yystpcpy stpcpy\n+# else\n+/* Copy YYSRC to YYDEST, returning the address of the terminating '\\0' in\n+ YYDEST. */\n+static char *\n+yystpcpy (char *yydest, const char *yysrc)\n+{\n+ char *yyd = yydest;\n+ const char *yys = yysrc;\n+\n+ while ((*yyd++ = *yys++) != '\\0')\n+ continue;\n+\n+ return yyd - 1;\n+}\n+# endif\n+# endif\n+\n+# ifndef yytnamerr\n+/* Copy to YYRES the contents of YYSTR after stripping away unnecessary\n+ quotes and backslashes, so that it's suitable for yyerror. The\n+ heuristic is that double-quoting is unnecessary unless the string\n+ contains an apostrophe, a comma, or backslash (other than\n+ backslash-backslash). YYSTR is taken from yytname. If YYRES is\n+ null, do not copy; instead, return the length of what the result\n+ would have been. */\n+static YYSIZE_T\n+yytnamerr (char *yyres, const char *yystr)\n+{\n+ if (*yystr == '\"')\n+ {\n+ YYSIZE_T yyn = 0;\n+ char const *yyp = yystr;\n+\n+ for (;;)\n+ switch (*++yyp)\n+ {\n+ case '\\'':\n+ case ',':\n+ goto do_not_strip_quotes;\n+\n+ case '\\\\':\n+ if (*++yyp != '\\\\')\n+ goto do_not_strip_quotes;\n+ /* Fall through. */\n+ default:\n+ if (yyres)\n+ yyres[yyn] = *yyp;\n+ yyn++;\n+ break;\n+\n+ case '\"':\n+ if (yyres)\n+ yyres[yyn] = '\\0';\n+ return yyn;\n+ }\n+ do_not_strip_quotes: ;\n+ }\n+\n+ if (! yyres)\n+ return yystrlen (yystr);\n+\n+ return yystpcpy (yyres, yystr) - yyres;\n+}\n+# endif\n+\n+/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message\n+ about the unexpected token YYTOKEN for the state stack whose top is\n+ YYSSP.\n+\n+ Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is\n+ not large enough to hold the message. In that case, also set\n+ *YYMSG_ALLOC to the required number of bytes. Return 2 if the\n+ required number of bytes is too large to store. */\n+static int\n+yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,\n+ yytype_int16 *yyssp, int yytoken)\n+{\n+ YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);\n+ YYSIZE_T yysize = yysize0;\n+ enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };\n+ /* Internationalized format string. */\n+ const char *yyformat = YY_NULLPTR;\n+ /* Arguments of yyformat. */\n+ char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];\n+ /* Number of reported tokens (one for the \"unexpected\", one per\n+ \"expected\"). */\n+ int yycount = 0;\n+\n+ /* There are many possibilities here to consider:\n+ - If this state is a consistent state with a default action, then\n+ the only way this function was invoked is if the default action\n+ is an error action. In that case, don't check for expected\n+ tokens because there are none.\n+ - The only way there can be no lookahead present (in yychar) is if\n+ this state is a consistent state with a default action. Thus,\n+ detecting the absence of a lookahead is sufficient to determine\n+ that there is no unexpected or expected token to report. In that\n+ case, just report a simple \"syntax error\".\n+ - Don't assume there isn't a lookahead just because this state is a\n+ consistent state with a default action. There might have been a\n+ previous inconsistent state, consistent state with a non-default\n+ action, or user semantic action that manipulated yychar.\n+ - Of course, the expected token list depends on states to have\n+ correct lookahead information, and it depends on the parser not\n+ to perform extra reductions after fetching a lookahead from the\n+ scanner and before detecting a syntax error. Thus, state merging\n+ (from LALR or IELR) and default reductions corrupt the expected\n+ token list. However, the list is correct for canonical LR with\n+ one exception: it will still contain any token that will not be\n+ accepted due to an error action in a later state.\n+ */\n+ if (yytoken != YYEMPTY)\n+ {\n+ int yyn = yypact[*yyssp];\n+ yyarg[yycount++] = yytname[yytoken];\n+ if (!yypact_value_is_default (yyn))\n+ {\n+ /* Start YYX at -YYN if negative to avoid negative indexes in\n+ YYCHECK. In other words, skip the first -YYN actions for\n+ this state because they are default actions. */\n+ int yyxbegin = yyn < 0 ? -yyn : 0;\n+ /* Stay within bounds of both yycheck and yytname. */\n+ int yychecklim = YYLAST - yyn + 1;\n+ int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;\n+ int yyx;\n+\n+ for (yyx = yyxbegin; yyx < yyxend; ++yyx)\n+ if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR\n+ && !yytable_value_is_error (yytable[yyx + yyn]))\n+ {\n+ if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)\n+ {\n+ yycount = 1;\n+ yysize = yysize0;\n+ break;\n+ }\n+ yyarg[yycount++] = yytname[yyx];\n+ {\n+ YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);\n+ if (! (yysize <= yysize1\n+ && yysize1 <= YYSTACK_ALLOC_MAXIMUM))\n+ return 2;\n+ yysize = yysize1;\n+ }\n+ }\n+ }\n+ }\n+\n+ switch (yycount)\n+ {\n+# define YYCASE_(N, S) \\\n+ case N: \\\n+ yyformat = S; \\\n+ break\n+ YYCASE_(0, YY_(\"syntax error\"));\n+ YYCASE_(1, YY_(\"syntax error, unexpected %s\"));\n+ YYCASE_(2, YY_(\"syntax error, unexpected %s, expecting %s\"));\n+ YYCASE_(3, YY_(\"syntax error, unexpected %s, expecting %s or %s\"));\n+ YYCASE_(4, YY_(\"syntax error, unexpected %s, expecting %s or %s or %s\"));\n+ YYCASE_(5, YY_(\"syntax error, unexpected %s, expecting %s or %s or %s or %s\"));\n+# undef YYCASE_\n+ }\n+\n+ {\n+ YYSIZE_T yysize1 = yysize + yystrlen (yyformat);\n+ if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))\n+ return 2;\n+ yysize = yysize1;\n+ }\n+\n+ if (*yymsg_alloc < yysize)\n+ {\n+ *yymsg_alloc = 2 * yysize;\n+ if (! (yysize <= *yymsg_alloc\n+ && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))\n+ *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;\n+ return 1;\n+ }\n+\n+ /* Avoid sprintf, as that infringes on the user's name space.\n+ Don't have undefined behavior even if the translation\n+ produced a string with the wrong number of \"%s\"s. */\n+ {\n+ char *yyp = *yymsg;\n+ int yyi = 0;\n+ while ((*yyp = *yyformat) != '\\0')\n+ if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)\n+ {\n+ yyp += yytnamerr (yyp, yyarg[yyi++]);\n+ yyformat += 2;\n+ }\n+ else\n+ {\n+ yyp++;\n+ yyformat++;\n+ }\n+ }\n+ return 0;\n+}\n+#endif /* YYERROR_VERBOSE */\n+\n+/*-----------------------------------------------.\n+| Release the memory associated to this symbol. |\n+`-----------------------------------------------*/\n+\n+static void\n+yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp)\n+{\n+ YYUSE (yyvaluep);\n+ YYUSE (yylocationp);\n+ if (!yymsg)\n+ yymsg = \"Deleting\";\n+ YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);\n+\n+ YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN\n+ YYUSE (yytype);\n+ YY_IGNORE_MAYBE_UNINITIALIZED_END\n+}\n+\n+\n+\n+\n+/* The lookahead symbol. */\n+int yychar;\n+\n+/* The semantic value of the lookahead symbol. */\n+YYSTYPE yylval;\n+/* Location data for the lookahead symbol. */\n+YYLTYPE yylloc\n+# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL\n+ = { 1, 1, 1, 1 }\n+# endif\n+;\n+/* Number of syntax errors so far. */\n+int yynerrs;\n+\n+\n+/*----------.\n+| yyparse. |\n+`----------*/\n+\n+int\n+yyparse (void)\n+{\n+ int yystate;\n+ /* Number of tokens to shift before error messages enabled. */\n+ int yyerrstatus;\n+\n+ /* The stacks and their tools:\n+ 'yyss': related to states.\n+ 'yyvs': related to semantic values.\n+ 'yyls': related to locations.\n+\n+ Refer to the stacks through separate pointers, to allow yyoverflow\n+ to reallocate them elsewhere. */\n+\n+ /* The state stack. */\n+ yytype_int16 yyssa[YYINITDEPTH];\n+ yytype_int16 *yyss;\n+ yytype_int16 *yyssp;\n+\n+ /* The semantic value stack. */\n+ YYSTYPE yyvsa[YYINITDEPTH];\n+ YYSTYPE *yyvs;\n+ YYSTYPE *yyvsp;\n+\n+ /* The location stack. */\n+ YYLTYPE yylsa[YYINITDEPTH];\n+ YYLTYPE *yyls;\n+ YYLTYPE *yylsp;\n+\n+ /* The locations where the error started and ended. */\n+ YYLTYPE yyerror_range[3];\n+\n+ YYSIZE_T yystacksize;\n+\n+ int yyn;\n+ int yyresult;\n+ /* Lookahead token as an internal (translated) token number. */\n+ int yytoken = 0;\n+ /* The variables used to return semantic value and location from the\n+ action routines. */\n+ YYSTYPE yyval;\n+ YYLTYPE yyloc;\n+\n+#if YYERROR_VERBOSE\n+ /* Buffer for error messages, and its allocated size. */\n+ char yymsgbuf[128];\n+ char *yymsg = yymsgbuf;\n+ YYSIZE_T yymsg_alloc = sizeof yymsgbuf;\n+#endif\n+\n+#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N))\n+\n+ /* The number of symbols on the RHS of the reduced rule.\n+ Keep to zero when no symbol should be popped. */\n+ int yylen = 0;\n+\n+ yyssp = yyss = yyssa;\n+ yyvsp = yyvs = yyvsa;\n+ yylsp = yyls = yylsa;\n+ yystacksize = YYINITDEPTH;\n+\n+ YYDPRINTF ((stderr, \"Starting parse\\n\"));\n+\n+ yystate = 0;\n+ yyerrstatus = 0;\n+ yynerrs = 0;\n+ yychar = YYEMPTY; /* Cause a token to be read. */\n+ yylsp[0] = yylloc;\n+ goto yysetstate;\n+\n+/*------------------------------------------------------------.\n+| yynewstate -- Push a new state, which is found in yystate. |\n+`------------------------------------------------------------*/\n+ yynewstate:\n+ /* In all cases, when you get here, the value and location stacks\n+ have just been pushed. So pushing a state here evens the stacks. */\n+ yyssp++;\n+\n+ yysetstate:\n+ *yyssp = yystate;\n+\n+ if (yyss + yystacksize - 1 <= yyssp)\n+ {\n+ /* Get the current used size of the three stacks, in elements. */\n+ YYSIZE_T yysize = yyssp - yyss + 1;\n+\n+#ifdef yyoverflow\n+ {\n+ /* Give user a chance to reallocate the stack. Use copies of\n+ these so that the &'s don't force the real ones into\n+ memory. */\n+ YYSTYPE *yyvs1 = yyvs;\n+ yytype_int16 *yyss1 = yyss;\n+ YYLTYPE *yyls1 = yyls;\n+\n+ /* Each stack pointer address is followed by the size of the\n+ data in use in that stack, in bytes. This used to be a\n+ conditional around just the two extra args, but that might\n+ be undefined if yyoverflow is a macro. */\n+ yyoverflow (YY_(\"memory exhausted\"),\n+ &yyss1, yysize * sizeof (*yyssp),\n+ &yyvs1, yysize * sizeof (*yyvsp),\n+ &yyls1, yysize * sizeof (*yylsp),\n+ &yystacksize);\n+\n+ yyls = yyls1;\n+ yyss = yyss1;\n+ yyvs = yyvs1;\n+ }\n+#else /* no yyoverflow */\n+# ifndef YYSTACK_RELOCATE\n+ goto yyexhaustedlab;\n+# else\n+ /* Extend the stack our own way. */\n+ if (YYMAXDEPTH <= yystacksize)\n+ goto yyexhaustedlab;\n+ yystacksize *= 2;\n+ if (YYMAXDEPTH < yystacksize)\n+ yystacksize = YYMAXDEPTH;\n+\n+ {\n+ yytype_int16 *yyss1 = yyss;\n+ union yyalloc *yyptr =\n+ (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));\n+ if (! yyptr)\n+ goto yyexhaustedlab;\n+ YYSTACK_RELOCATE (yyss_alloc, yyss);\n+ YYSTACK_RELOCATE (yyvs_alloc, yyvs);\n+ YYSTACK_RELOCATE (yyls_alloc, yyls);\n+# undef YYSTACK_RELOCATE\n+ if (yyss1 != yyssa)\n+ YYSTACK_FREE (yyss1);\n+ }\n+# endif\n+#endif /* no yyoverflow */\n+\n+ yyssp = yyss + yysize - 1;\n+ yyvsp = yyvs + yysize - 1;\n+ yylsp = yyls + yysize - 1;\n+\n+ YYDPRINTF ((stderr, \"Stack size increased to %lu\\n\",\n+ (unsigned long int) yystacksize));\n+\n+ if (yyss + yystacksize - 1 <= yyssp)\n+ YYABORT;\n+ }\n+\n+ YYDPRINTF ((stderr, \"Entering state %d\\n\", yystate));\n+\n+ if (yystate == YYFINAL)\n+ YYACCEPT;\n+\n+ goto yybackup;\n+\n+/*-----------.\n+| yybackup. |\n+`-----------*/\n+yybackup:\n+\n+ /* Do appropriate processing given the current state. Read a\n+ lookahead token if we need one and don't already have one. */\n+\n+ /* First try to decide what to do without reference to lookahead token. */\n+ yyn = yypact[yystate];\n+ if (yypact_value_is_default (yyn))\n+ goto yydefault;\n+\n+ /* Not known => get a lookahead token if don't already have one. */\n+\n+ /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */\n+ if (yychar == YYEMPTY)\n+ {\n+ YYDPRINTF ((stderr, \"Reading a token: \"));\n+ yychar = yylex ();\n+ }\n+\n+ if (yychar <= YYEOF)\n+ {\n+ yychar = yytoken = YYEOF;\n+ YYDPRINTF ((stderr, \"Now at end of input.\\n\"));\n+ }\n+ else\n+ {\n+ yytoken = YYTRANSLATE (yychar);\n+ YY_SYMBOL_PRINT (\"Next token is\", yytoken, &yylval, &yylloc);\n+ }\n+\n+ /* If the proper action on seeing token YYTOKEN is to reduce or to\n+ detect an error, take that action. */\n+ yyn += yytoken;\n+ if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)\n+ goto yydefault;\n+ yyn = yytable[yyn];\n+ if (yyn <= 0)\n+ {\n+ if (yytable_value_is_error (yyn))\n+ goto yyerrlab;\n+ yyn = -yyn;\n+ goto yyreduce;\n+ }\n+\n+ /* Count tokens shifted since error; after three, turn off error\n+ status. */\n+ if (yyerrstatus)\n+ yyerrstatus--;\n+\n+ /* Shift the lookahead token. */\n+ YY_SYMBOL_PRINT (\"Shifting\", yytoken, &yylval, &yylloc);\n+\n+ /* Discard the shifted token. */\n+ yychar = YYEMPTY;\n+\n+ yystate = yyn;\n+ YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN\n+ *++yyvsp = yylval;\n+ YY_IGNORE_MAYBE_UNINITIALIZED_END\n+ *++yylsp = yylloc;\n+ goto yynewstate;\n+\n+\n+/*-----------------------------------------------------------.\n+| yydefault -- do the default action for the current state. |\n+`-----------------------------------------------------------*/\n+yydefault:\n+ yyn = yydefact[yystate];\n+ if (yyn == 0)\n+ goto yyerrlab;\n+ goto yyreduce;\n+\n+\n+/*-----------------------------.\n+| yyreduce -- Do a reduction. |\n+`-----------------------------*/\n+yyreduce:\n+ /* yyn is the number of a rule to reduce with. */\n+ yylen = yyr2[yyn];\n+\n+ /* If YYLEN is nonzero, implement the default value of the action:\n+ '$$ = $1'.\n+\n+ Otherwise, the following line sets YYVAL to garbage.\n+ This behavior is undocumented and Bison\n+ users should not rely upon it. Assigning to YYVAL\n+ unconditionally makes the parser a bit smaller, and it avoids a\n+ GCC warning that YYVAL may be used uninitialized. */\n+ yyval = yyvsp[1-yylen];\n+\n+ /* Default location. */\n+ YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);\n+ YY_REDUCE_PRINT (yyn);\n+ switch (yyn)\n+ {\n+ case 2:\n+#line 110 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\tparser_output = build_dt_info((yyvsp[-2].flags), (yyvsp[-1].re), (yyvsp[0].node),\n+\t\t\t guess_boot_cpuid((yyvsp[0].node)));\n+\t\t}\n+#line 1476 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 3:\n+#line 118 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\t(yyval.flags) = DTSF_V1;\n+\t\t}\n+#line 1484 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 4:\n+#line 122 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\t(yyval.flags) = DTSF_V1 | DTSF_PLUGIN;\n+\t\t}\n+#line 1492 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 6:\n+#line 130 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\tif ((yyvsp[0].flags) != (yyvsp[-1].flags))\n+\t\t\t\tERROR(&(yylsp[0]), \"Header flags don't match earlier ones\");\n+\t\t\t(yyval.flags) = (yyvsp[-1].flags);\n+\t\t}\n+#line 1502 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 7:\n+#line 139 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\t(yyval.re) = NULL;\n+\t\t}\n+#line 1510 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 8:\n+#line 143 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\t(yyval.re) = chain_reserve_entry((yyvsp[-1].re), (yyvsp[0].re));\n+\t\t}\n+#line 1518 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 9:\n+#line 150 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\t(yyval.re) = build_reserve_entry((yyvsp[-2].integer), (yyvsp[-1].integer));\n+\t\t}\n+#line 1526 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 10:\n+#line 154 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\tadd_label(&(yyvsp[0].re)->labels, (yyvsp[-1].labelref));\n+\t\t\t(yyval.re) = (yyvsp[0].re);\n+\t\t}\n+#line 1535 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 11:\n+#line 162 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\t(yyval.node) = name_node((yyvsp[0].node), \"\");\n+\t\t}\n+#line 1543 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 12:\n+#line 166 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\t(yyval.node) = merge_nodes((yyvsp[-2].node), (yyvsp[0].node));\n+\t\t}\n+#line 1551 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 13:\n+#line 171 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\tstruct node *target = get_node_by_ref((yyvsp[-3].node), (yyvsp[-1].labelref));\n+\n+\t\t\tif (target) {\n+\t\t\t\tadd_label(&target->labels, (yyvsp[-2].labelref));\n+\t\t\t\tmerge_nodes(target, (yyvsp[0].node));\n+\t\t\t} else\n+\t\t\t\tERROR(&(yylsp[-1]), \"Label or path %s not found\", (yyvsp[-1].labelref));\n+\t\t\t(yyval.node) = (yyvsp[-3].node);\n+\t\t}\n+#line 1566 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 14:\n+#line 182 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\tstruct node *target = get_node_by_ref((yyvsp[-2].node), (yyvsp[-1].labelref));\n+\n+\t\t\tif (target)\n+\t\t\t\tmerge_nodes(target, (yyvsp[0].node));\n+\t\t\telse\n+\t\t\t\tERROR(&(yylsp[-1]), \"Label or path %s not found\", (yyvsp[-1].labelref));\n+\t\t\t(yyval.node) = (yyvsp[-2].node);\n+\t\t}\n+#line 1580 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 15:\n+#line 192 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\tstruct node *target = get_node_by_ref((yyvsp[-3].node), (yyvsp[-1].labelref));\n+\n+\t\t\tif (target)\n+\t\t\t\tdelete_node(target);\n+\t\t\telse\n+\t\t\t\tERROR(&(yylsp[-1]), \"Label or path %s not found\", (yyvsp[-1].labelref));\n+\n+\n+\t\t\t(yyval.node) = (yyvsp[-3].node);\n+\t\t}\n+#line 1596 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 16:\n+#line 207 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\t(yyval.node) = build_node((yyvsp[-3].proplist), (yyvsp[-2].nodelist));\n+\t\t}\n+#line 1604 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 17:\n+#line 214 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\t(yyval.proplist) = NULL;\n+\t\t}\n+#line 1612 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 18:\n+#line 218 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\t(yyval.proplist) = chain_property((yyvsp[0].prop), (yyvsp[-1].proplist));\n+\t\t}\n+#line 1620 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 19:\n+#line 225 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\t(yyval.prop) = build_property((yyvsp[-3].propnodename), (yyvsp[-1].data));\n+\t\t}\n+#line 1628 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 20:\n+#line 229 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\t(yyval.prop) = build_property((yyvsp[-1].propnodename), empty_data);\n+\t\t}\n+#line 1636 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 21:\n+#line 233 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\t(yyval.prop) = build_property_delete((yyvsp[-1].propnodename));\n+\t\t}\n+#line 1644 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 22:\n+#line 237 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\tadd_label(&(yyvsp[0].prop)->labels, (yyvsp[-1].labelref));\n+\t\t\t(yyval.prop) = (yyvsp[0].prop);\n+\t\t}\n+#line 1653 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 23:\n+#line 245 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\t(yyval.data) = data_merge((yyvsp[-1].data), (yyvsp[0].data));\n+\t\t}\n+#line 1661 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 24:\n+#line 249 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\t(yyval.data) = data_merge((yyvsp[-2].data), (yyvsp[-1].array).data);\n+\t\t}\n+#line 1669 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 25:\n+#line 253 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\t(yyval.data) = data_merge((yyvsp[-3].data), (yyvsp[-1].data));\n+\t\t}\n+#line 1677 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 26:\n+#line 257 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\t(yyval.data) = data_add_marker((yyvsp[-1].data), REF_PATH, (yyvsp[0].labelref));\n+\t\t}\n+#line 1685 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 27:\n+#line 261 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\tFILE *f = srcfile_relative_open((yyvsp[-5].data).val, NULL);\n+\t\t\tstruct data d;\n+\n+\t\t\tif ((yyvsp[-3].integer) != 0)\n+\t\t\t\tif (fseek(f, (yyvsp[-3].integer), SEEK_SET) != 0)\n+\t\t\t\t\tdie(\"Couldn't seek to offset %llu in \\\"%s\\\": %s\",\n+\t\t\t\t\t (unsigned long long)(yyvsp[-3].integer), (yyvsp[-5].data).val,\n+\t\t\t\t\t strerror(errno));\n+\n+\t\t\td = data_copy_file(f, (yyvsp[-1].integer));\n+\n+\t\t\t(yyval.data) = data_merge((yyvsp[-8].data), d);\n+\t\t\tfclose(f);\n+\t\t}\n+#line 1705 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 28:\n+#line 277 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\tFILE *f = srcfile_relative_open((yyvsp[-1].data).val, NULL);\n+\t\t\tstruct data d = empty_data;\n+\n+\t\t\td = data_copy_file(f, -1);\n+\n+\t\t\t(yyval.data) = data_merge((yyvsp[-4].data), d);\n+\t\t\tfclose(f);\n+\t\t}\n+#line 1719 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 29:\n+#line 287 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\t(yyval.data) = data_add_marker((yyvsp[-1].data), LABEL, (yyvsp[0].labelref));\n+\t\t}\n+#line 1727 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 30:\n+#line 294 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\t(yyval.data) = empty_data;\n+\t\t}\n+#line 1735 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 31:\n+#line 298 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\t(yyval.data) = (yyvsp[-1].data);\n+\t\t}\n+#line 1743 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 32:\n+#line 302 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\t(yyval.data) = data_add_marker((yyvsp[-1].data), LABEL, (yyvsp[0].labelref));\n+\t\t}\n+#line 1751 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 33:\n+#line 309 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\tunsigned long long bits;\n+\n+\t\t\tbits = (yyvsp[-1].integer);\n+\n+\t\t\tif ((bits != 8) && (bits != 16) &&\n+\t\t\t (bits != 32) && (bits != 64)) {\n+\t\t\t\tERROR(&(yylsp[-1]), \"Array elements must be\"\n+\t\t\t\t \" 8, 16, 32 or 64-bits\");\n+\t\t\t\tbits = 32;\n+\t\t\t}\n+\n+\t\t\t(yyval.array).data = empty_data;\n+\t\t\t(yyval.array).bits = bits;\n+\t\t}\n+#line 1771 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 34:\n+#line 325 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\t(yyval.array).data = empty_data;\n+\t\t\t(yyval.array).bits = 32;\n+\t\t}\n+#line 1780 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 35:\n+#line 330 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\tif ((yyvsp[-1].array).bits < 64) {\n+\t\t\t\tuint64_t mask = (1ULL << (yyvsp[-1].array).bits) - 1;\n+\t\t\t\t/*\n+\t\t\t\t * Bits above mask must either be all zero\n+\t\t\t\t * (positive within range of mask) or all one\n+\t\t\t\t * (negative and sign-extended). The second\n+\t\t\t\t * condition is true if when we set all bits\n+\t\t\t\t * within the mask to one (i.e. | in the\n+\t\t\t\t * mask), all bits are one.\n+\t\t\t\t */\n+\t\t\t\tif (((yyvsp[0].integer) > mask) && (((yyvsp[0].integer) | mask) != -1ULL))\n+\t\t\t\t\tERROR(&(yylsp[0]), \"Value out of range for\"\n+\t\t\t\t\t \" %d-bit array element\", (yyvsp[-1].array).bits);\n+\t\t\t}\n+\n+\t\t\t(yyval.array).data = data_append_integer((yyvsp[-1].array).data, (yyvsp[0].integer), (yyvsp[-1].array).bits);\n+\t\t}\n+#line 1803 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 36:\n+#line 349 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\tuint64_t val = ~0ULL >> (64 - (yyvsp[-1].array).bits);\n+\n+\t\t\tif ((yyvsp[-1].array).bits == 32)\n+\t\t\t\t(yyvsp[-1].array).data = data_add_marker((yyvsp[-1].array).data,\n+\t\t\t\t\t\t\t REF_PHANDLE,\n+\t\t\t\t\t\t\t (yyvsp[0].labelref));\n+\t\t\telse\n+\t\t\t\tERROR(&(yylsp[0]), \"References are only allowed in \"\n+\t\t\t\t\t \"arrays with 32-bit elements.\");\n+\n+\t\t\t(yyval.array).data = data_append_integer((yyvsp[-1].array).data, val, (yyvsp[-1].array).bits);\n+\t\t}\n+#line 1821 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 37:\n+#line 363 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\t(yyval.array).data = data_add_marker((yyvsp[-1].array).data, LABEL, (yyvsp[0].labelref));\n+\t\t}\n+#line 1829 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 40:\n+#line 372 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\t(yyval.integer) = (yyvsp[-1].integer);\n+\t\t}\n+#line 1837 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 43:\n+#line 383 \"dtc-parser.y\" /* yacc.c:1646 */\n+ { (yyval.integer) = (yyvsp[-4].integer) ? (yyvsp[-2].integer) : (yyvsp[0].integer); }\n+#line 1843 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 45:\n+#line 388 \"dtc-parser.y\" /* yacc.c:1646 */\n+ { (yyval.integer) = (yyvsp[-2].integer) || (yyvsp[0].integer); }\n+#line 1849 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 47:\n+#line 393 \"dtc-parser.y\" /* yacc.c:1646 */\n+ { (yyval.integer) = (yyvsp[-2].integer) && (yyvsp[0].integer); }\n+#line 1855 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 49:\n+#line 398 \"dtc-parser.y\" /* yacc.c:1646 */\n+ { (yyval.integer) = (yyvsp[-2].integer) | (yyvsp[0].integer); }\n+#line 1861 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 51:\n+#line 403 \"dtc-parser.y\" /* yacc.c:1646 */\n+ { (yyval.integer) = (yyvsp[-2].integer) ^ (yyvsp[0].integer); }\n+#line 1867 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 53:\n+#line 408 \"dtc-parser.y\" /* yacc.c:1646 */\n+ { (yyval.integer) = (yyvsp[-2].integer) & (yyvsp[0].integer); }\n+#line 1873 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 55:\n+#line 413 \"dtc-parser.y\" /* yacc.c:1646 */\n+ { (yyval.integer) = (yyvsp[-2].integer) == (yyvsp[0].integer); }\n+#line 1879 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 56:\n+#line 414 \"dtc-parser.y\" /* yacc.c:1646 */\n+ { (yyval.integer) = (yyvsp[-2].integer) != (yyvsp[0].integer); }\n+#line 1885 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 58:\n+#line 419 \"dtc-parser.y\" /* yacc.c:1646 */\n+ { (yyval.integer) = (yyvsp[-2].integer) < (yyvsp[0].integer); }\n+#line 1891 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 59:\n+#line 420 \"dtc-parser.y\" /* yacc.c:1646 */\n+ { (yyval.integer) = (yyvsp[-2].integer) > (yyvsp[0].integer); }\n+#line 1897 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 60:\n+#line 421 \"dtc-parser.y\" /* yacc.c:1646 */\n+ { (yyval.integer) = (yyvsp[-2].integer) <= (yyvsp[0].integer); }\n+#line 1903 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 61:\n+#line 422 \"dtc-parser.y\" /* yacc.c:1646 */\n+ { (yyval.integer) = (yyvsp[-2].integer) >= (yyvsp[0].integer); }\n+#line 1909 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 62:\n+#line 426 \"dtc-parser.y\" /* yacc.c:1646 */\n+ { (yyval.integer) = (yyvsp[-2].integer) << (yyvsp[0].integer); }\n+#line 1915 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 63:\n+#line 427 \"dtc-parser.y\" /* yacc.c:1646 */\n+ { (yyval.integer) = (yyvsp[-2].integer) >> (yyvsp[0].integer); }\n+#line 1921 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 65:\n+#line 432 \"dtc-parser.y\" /* yacc.c:1646 */\n+ { (yyval.integer) = (yyvsp[-2].integer) + (yyvsp[0].integer); }\n+#line 1927 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 66:\n+#line 433 \"dtc-parser.y\" /* yacc.c:1646 */\n+ { (yyval.integer) = (yyvsp[-2].integer) - (yyvsp[0].integer); }\n+#line 1933 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 68:\n+#line 438 \"dtc-parser.y\" /* yacc.c:1646 */\n+ { (yyval.integer) = (yyvsp[-2].integer) * (yyvsp[0].integer); }\n+#line 1939 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 69:\n+#line 440 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\tif ((yyvsp[0].integer) != 0) {\n+\t\t\t\t(yyval.integer) = (yyvsp[-2].integer) / (yyvsp[0].integer);\n+\t\t\t} else {\n+\t\t\t\tERROR(&(yyloc), \"Division by zero\");\n+\t\t\t\t(yyval.integer) = 0;\n+\t\t\t}\n+\t\t}\n+#line 1952 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 70:\n+#line 449 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\tif ((yyvsp[0].integer) != 0) {\n+\t\t\t\t(yyval.integer) = (yyvsp[-2].integer) % (yyvsp[0].integer);\n+\t\t\t} else {\n+\t\t\t\tERROR(&(yyloc), \"Division by zero\");\n+\t\t\t\t(yyval.integer) = 0;\n+\t\t\t}\n+\t\t}\n+#line 1965 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 73:\n+#line 462 \"dtc-parser.y\" /* yacc.c:1646 */\n+ { (yyval.integer) = -(yyvsp[0].integer); }\n+#line 1971 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 74:\n+#line 463 \"dtc-parser.y\" /* yacc.c:1646 */\n+ { (yyval.integer) = ~(yyvsp[0].integer); }\n+#line 1977 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 75:\n+#line 464 \"dtc-parser.y\" /* yacc.c:1646 */\n+ { (yyval.integer) = !(yyvsp[0].integer); }\n+#line 1983 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 76:\n+#line 469 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\t(yyval.data) = empty_data;\n+\t\t}\n+#line 1991 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 77:\n+#line 473 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\t(yyval.data) = data_append_byte((yyvsp[-1].data), (yyvsp[0].byte));\n+\t\t}\n+#line 1999 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 78:\n+#line 477 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\t(yyval.data) = data_add_marker((yyvsp[-1].data), LABEL, (yyvsp[0].labelref));\n+\t\t}\n+#line 2007 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 79:\n+#line 484 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\t(yyval.nodelist) = NULL;\n+\t\t}\n+#line 2015 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 80:\n+#line 488 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\t(yyval.nodelist) = chain_node((yyvsp[-1].node), (yyvsp[0].nodelist));\n+\t\t}\n+#line 2023 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 81:\n+#line 492 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\tERROR(&(yylsp[0]), \"Properties must precede subnodes\");\n+\t\t\tYYERROR;\n+\t\t}\n+#line 2032 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 82:\n+#line 500 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\t(yyval.node) = name_node((yyvsp[0].node), (yyvsp[-1].propnodename));\n+\t\t}\n+#line 2040 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 83:\n+#line 504 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\t(yyval.node) = name_node(build_node_delete(), (yyvsp[-1].propnodename));\n+\t\t}\n+#line 2048 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+ case 84:\n+#line 508 \"dtc-parser.y\" /* yacc.c:1646 */\n+ {\n+\t\t\tadd_label(&(yyvsp[0].node)->labels, (yyvsp[-1].labelref));\n+\t\t\t(yyval.node) = (yyvsp[0].node);\n+\t\t}\n+#line 2057 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ break;\n+\n+\n+#line 2061 \"dtc-parser.tab.c\" /* yacc.c:1646 */\n+ default: break;\n+ }\n+ /* User semantic actions sometimes alter yychar, and that requires\n+ that yytoken be updated with the new translation. We take the\n+ approach of translating immediately before every use of yytoken.\n+ One alternative is translating here after every semantic action,\n+ but that translation would be missed if the semantic action invokes\n+ YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or\n+ if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an\n+ incorrect destructor might then be invoked immediately. In the\n+ case of YYERROR or YYBACKUP, subsequent parser actions might lead\n+ to an incorrect destructor call or verbose syntax error message\n+ before the lookahead is translated. */\n+ YY_SYMBOL_PRINT (\"-> $$ =\", yyr1[yyn], &yyval, &yyloc);\n+\n+ YYPOPSTACK (yylen);\n+ yylen = 0;\n+ YY_STACK_PRINT (yyss, yyssp);\n+\n+ *++yyvsp = yyval;\n+ *++yylsp = yyloc;\n+\n+ /* Now 'shift' the result of the reduction. Determine what state\n+ that goes to, based on the state we popped back to and the rule\n+ number reduced by. */\n+\n+ yyn = yyr1[yyn];\n+\n+ yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;\n+ if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)\n+ yystate = yytable[yystate];\n+ else\n+ yystate = yydefgoto[yyn - YYNTOKENS];\n+\n+ goto yynewstate;\n+\n+\n+/*--------------------------------------.\n+| yyerrlab -- here on detecting error. |\n+`--------------------------------------*/\n+yyerrlab:\n+ /* Make sure we have latest lookahead translation. See comments at\n+ user semantic actions for why this is necessary. */\n+ yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);\n+\n+ /* If not already recovering from an error, report this error. */\n+ if (!yyerrstatus)\n+ {\n+ ++yynerrs;\n+#if ! YYERROR_VERBOSE\n+ yyerror (YY_(\"syntax error\"));\n+#else\n+# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \\\n+ yyssp, yytoken)\n+ {\n+ char const *yymsgp = YY_(\"syntax error\");\n+ int yysyntax_error_status;\n+ yysyntax_error_status = YYSYNTAX_ERROR;\n+ if (yysyntax_error_status == 0)\n+ yymsgp = yymsg;\n+ else if (yysyntax_error_status == 1)\n+ {\n+ if (yymsg != yymsgbuf)\n+ YYSTACK_FREE (yymsg);\n+ yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);\n+ if (!yymsg)\n+ {\n+ yymsg = yymsgbuf;\n+ yymsg_alloc = sizeof yymsgbuf;\n+ yysyntax_error_status = 2;\n+ }\n+ else\n+ {\n+ yysyntax_error_status = YYSYNTAX_ERROR;\n+ yymsgp = yymsg;\n+ }\n+ }\n+ yyerror (yymsgp);\n+ if (yysyntax_error_status == 2)\n+ goto yyexhaustedlab;\n+ }\n+# undef YYSYNTAX_ERROR\n+#endif\n+ }\n+\n+ yyerror_range[1] = yylloc;\n+\n+ if (yyerrstatus == 3)\n+ {\n+ /* If just tried and failed to reuse lookahead token after an\n+ error, discard it. */\n+\n+ if (yychar <= YYEOF)\n+ {\n+ /* Return failure if at end of input. */\n+ if (yychar == YYEOF)\n+ YYABORT;\n+ }\n+ else\n+ {\n+ yydestruct (\"Error: discarding\",\n+ yytoken, &yylval, &yylloc);\n+ yychar = YYEMPTY;\n+ }\n+ }\n+\n+ /* Else will try to reuse lookahead token after shifting the error\n+ token. */\n+ goto yyerrlab1;\n+\n+\n+/*---------------------------------------------------.\n+| yyerrorlab -- error raised explicitly by YYERROR. |\n+`---------------------------------------------------*/\n+yyerrorlab:\n+\n+ /* Pacify compilers like GCC when the user code never invokes\n+ YYERROR and the label yyerrorlab therefore never appears in user\n+ code. */\n+ if (/*CONSTCOND*/ 0)\n+ goto yyerrorlab;\n+\n+ yyerror_range[1] = yylsp[1-yylen];\n+ /* Do not reclaim the symbols of the rule whose action triggered\n+ this YYERROR. */\n+ YYPOPSTACK (yylen);\n+ yylen = 0;\n+ YY_STACK_PRINT (yyss, yyssp);\n+ yystate = *yyssp;\n+ goto yyerrlab1;\n+\n+\n+/*-------------------------------------------------------------.\n+| yyerrlab1 -- common code for both syntax error and YYERROR. |\n+`-------------------------------------------------------------*/\n+yyerrlab1:\n+ yyerrstatus = 3; /* Each real token shifted decrements this. */\n+\n+ for (;;)\n+ {\n+ yyn = yypact[yystate];\n+ if (!yypact_value_is_default (yyn))\n+ {\n+ yyn += YYTERROR;\n+ if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)\n+ {\n+ yyn = yytable[yyn];\n+ if (0 < yyn)\n+ break;\n+ }\n+ }\n+\n+ /* Pop the current state because it cannot handle the error token. */\n+ if (yyssp == yyss)\n+ YYABORT;\n+\n+ yyerror_range[1] = *yylsp;\n+ yydestruct (\"Error: popping\",\n+ yystos[yystate], yyvsp, yylsp);\n+ YYPOPSTACK (1);\n+ yystate = *yyssp;\n+ YY_STACK_PRINT (yyss, yyssp);\n+ }\n+\n+ YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN\n+ *++yyvsp = yylval;\n+ YY_IGNORE_MAYBE_UNINITIALIZED_END\n+\n+ yyerror_range[2] = yylloc;\n+ /* Using YYLLOC is tempting, but would change the location of\n+ the lookahead. YYLOC is available though. */\n+ YYLLOC_DEFAULT (yyloc, yyerror_range, 2);\n+ *++yylsp = yyloc;\n+\n+ /* Shift the error token. */\n+ YY_SYMBOL_PRINT (\"Shifting\", yystos[yyn], yyvsp, yylsp);\n+\n+ yystate = yyn;\n+ goto yynewstate;\n+\n+\n+/*-------------------------------------.\n+| yyacceptlab -- YYACCEPT comes here. |\n+`-------------------------------------*/\n+yyacceptlab:\n+ yyresult = 0;\n+ goto yyreturn;\n+\n+/*-----------------------------------.\n+| yyabortlab -- YYABORT comes here. |\n+`-----------------------------------*/\n+yyabortlab:\n+ yyresult = 1;\n+ goto yyreturn;\n+\n+#if !defined yyoverflow || YYERROR_VERBOSE\n+/*-------------------------------------------------.\n+| yyexhaustedlab -- memory exhaustion comes here. |\n+`-------------------------------------------------*/\n+yyexhaustedlab:\n+ yyerror (YY_(\"memory exhausted\"));\n+ yyresult = 2;\n+ /* Fall through. */\n+#endif\n+\n+yyreturn:\n+ if (yychar != YYEMPTY)\n+ {\n+ /* Make sure we have latest lookahead translation. See comments at\n+ user semantic actions for why this is necessary. */\n+ yytoken = YYTRANSLATE (yychar);\n+ yydestruct (\"Cleanup: discarding lookahead\",\n+ yytoken, &yylval, &yylloc);\n+ }\n+ /* Do not reclaim the symbols of the rule whose action triggered\n+ this YYABORT or YYACCEPT. */\n+ YYPOPSTACK (yylen);\n+ YY_STACK_PRINT (yyss, yyssp);\n+ while (yyssp != yyss)\n+ {\n+ yydestruct (\"Cleanup: popping\",\n+ yystos[*yyssp], yyvsp, yylsp);\n+ YYPOPSTACK (1);\n+ }\n+#ifndef yyoverflow\n+ if (yyss != yyssa)\n+ YYSTACK_FREE (yyss);\n+#endif\n+#if YYERROR_VERBOSE\n+ if (yymsg != yymsgbuf)\n+ YYSTACK_FREE (yymsg);\n+#endif\n+ return yyresult;\n+}\n+#line 514 \"dtc-parser.y\" /* yacc.c:1906 */\n+\n+\n+void yyerror(char const *s)\n+{\n+\tERROR(&yylloc, \"%s\", s);\n+}\ndiff --git a/scripts/dtc/dtc-parser.tab.h_shipped b/scripts/dtc/dtc-parser.tab.h_shipped\nnew file mode 100644\nindex 000000000000..e7b04dd0162b\n--- /dev/null\n+++ b/scripts/dtc/dtc-parser.tab.h_shipped\n@@ -0,0 +1,123 @@\n+/* A Bison parser, made by GNU Bison 3.0.2. */\n+\n+/* Bison interface for Yacc-like parsers in C\n+\n+ Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.\n+\n+ This program is free software: you can redistribute it and/or modify\n+ it under the terms of the GNU General Public License as published by\n+ the Free Software Foundation, either version 3 of the License, or\n+ (at your option) any later version.\n+\n+ This program is distributed in the hope that it will be useful,\n+ but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n+ GNU General Public License for more details.\n+\n+ You should have received a copy of the GNU General Public License\n+ along with this program. If not, see <http://www.gnu.org/licenses/>. */\n+\n+/* As a special exception, you may create a larger work that contains\n+ part or all of the Bison parser skeleton and distribute that work\n+ under terms of your choice, so long as that work isn't itself a\n+ parser generator using the skeleton or a modified version thereof\n+ as a parser skeleton. Alternatively, if you modify or redistribute\n+ the parser skeleton itself, you may (at your option) remove this\n+ special exception, which will cause the skeleton and the resulting\n+ Bison output files to be licensed under the GNU General Public\n+ License without this special exception.\n+\n+ This special exception was added by the Free Software Foundation in\n+ version 2.2 of Bison. */\n+\n+#ifndef YY_YY_DTC_PARSER_TAB_H_INCLUDED\n+# define YY_YY_DTC_PARSER_TAB_H_INCLUDED\n+/* Debug traces. */\n+#ifndef YYDEBUG\n+# define YYDEBUG 0\n+#endif\n+#if YYDEBUG\n+extern int yydebug;\n+#endif\n+\n+/* Token type. */\n+#ifndef YYTOKENTYPE\n+# define YYTOKENTYPE\n+ enum yytokentype\n+ {\n+ DT_V1 = 258,\n+ DT_PLUGIN = 259,\n+ DT_MEMRESERVE = 260,\n+ DT_LSHIFT = 261,\n+ DT_RSHIFT = 262,\n+ DT_LE = 263,\n+ DT_GE = 264,\n+ DT_EQ = 265,\n+ DT_NE = 266,\n+ DT_AND = 267,\n+ DT_OR = 268,\n+ DT_BITS = 269,\n+ DT_DEL_PROP = 270,\n+ DT_DEL_NODE = 271,\n+ DT_PROPNODENAME = 272,\n+ DT_LITERAL = 273,\n+ DT_CHAR_LITERAL = 274,\n+ DT_BYTE = 275,\n+ DT_STRING = 276,\n+ DT_LABEL = 277,\n+ DT_REF = 278,\n+ DT_INCBIN = 279\n+ };\n+#endif\n+\n+/* Value type. */\n+#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED\n+typedef union YYSTYPE YYSTYPE;\n+union YYSTYPE\n+{\n+#line 39 \"dtc-parser.y\" /* yacc.c:1909 */\n+\n+\tchar *propnodename;\n+\tchar *labelref;\n+\tuint8_t byte;\n+\tstruct data data;\n+\n+\tstruct {\n+\t\tstruct data\tdata;\n+\t\tint\t\tbits;\n+\t} array;\n+\n+\tstruct property *prop;\n+\tstruct property *proplist;\n+\tstruct node *node;\n+\tstruct node *nodelist;\n+\tstruct reserve_info *re;\n+\tuint64_t integer;\n+\tunsigned int flags;\n+\n+#line 99 \"dtc-parser.tab.h\" /* yacc.c:1909 */\n+};\n+# define YYSTYPE_IS_TRIVIAL 1\n+# define YYSTYPE_IS_DECLARED 1\n+#endif\n+\n+/* Location type. */\n+#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED\n+typedef struct YYLTYPE YYLTYPE;\n+struct YYLTYPE\n+{\n+ int first_line;\n+ int first_column;\n+ int last_line;\n+ int last_column;\n+};\n+# define YYLTYPE_IS_DECLARED 1\n+# define YYLTYPE_IS_TRIVIAL 1\n+#endif\n+\n+\n+extern YYSTYPE yylval;\n+extern YYLTYPE yylloc;\n+int yyparse (void);\n+\n+#endif /* !YY_YY_DTC_PARSER_TAB_H_INCLUDED */\ndiff --git a/scripts/dtc/dtc-parser.y b/scripts/dtc/dtc-parser.y\nnew file mode 100644\nindex 000000000000..ca3f5003427c\n--- /dev/null\n+++ b/scripts/dtc/dtc-parser.y\n@@ -0,0 +1,519 @@\n+/*\n+ * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.\n+ *\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License as\n+ * published by the Free Software Foundation; either version 2 of the\n+ * License, or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\n+ * USA\n+ */\n+%{\n+#include <stdio.h>\n+#include <inttypes.h>\n+\n+#include \"dtc.h\"\n+#include \"srcpos.h\"\n+\n+extern int yylex(void);\n+extern void yyerror(char const *s);\n+#define ERROR(loc, ...) \\\n+\tdo { \\\n+\t\tsrcpos_error((loc), \"Error\", __VA_ARGS__); \\\n+\t\ttreesource_error = true; \\\n+\t} while (0)\n+\n+extern struct dt_info *parser_output;\n+extern bool treesource_error;\n+%}\n+\n+%union {\n+\tchar *propnodename;\n+\tchar *labelref;\n+\tuint8_t byte;\n+\tstruct data data;\n+\n+\tstruct {\n+\t\tstruct data\tdata;\n+\t\tint\t\tbits;\n+\t} array;\n+\n+\tstruct property *prop;\n+\tstruct property *proplist;\n+\tstruct node *node;\n+\tstruct node *nodelist;\n+\tstruct reserve_info *re;\n+\tuint64_t integer;\n+\tunsigned int flags;\n+}\n+\n+%token DT_V1\n+%token DT_PLUGIN\n+%token DT_MEMRESERVE\n+%token DT_LSHIFT DT_RSHIFT DT_LE DT_GE DT_EQ DT_NE DT_AND DT_OR\n+%token DT_BITS\n+%token DT_DEL_PROP\n+%token DT_DEL_NODE\n+%token <propnodename> DT_PROPNODENAME\n+%token <integer> DT_LITERAL\n+%token <integer> DT_CHAR_LITERAL\n+%token <byte> DT_BYTE\n+%token <data> DT_STRING\n+%token <labelref> DT_LABEL\n+%token <labelref> DT_REF\n+%token DT_INCBIN\n+\n+%type <data> propdata\n+%type <data> propdataprefix\n+%type <flags> header\n+%type <flags> headers\n+%type <re> memreserve\n+%type <re> memreserves\n+%type <array> arrayprefix\n+%type <data> bytestring\n+%type <prop> propdef\n+%type <proplist> proplist\n+\n+%type <node> devicetree\n+%type <node> nodedef\n+%type <node> subnode\n+%type <nodelist> subnodes\n+\n+%type <integer> integer_prim\n+%type <integer> integer_unary\n+%type <integer> integer_mul\n+%type <integer> integer_add\n+%type <integer> integer_shift\n+%type <integer> integer_rela\n+%type <integer> integer_eq\n+%type <integer> integer_bitand\n+%type <integer> integer_bitxor\n+%type <integer> integer_bitor\n+%type <integer> integer_and\n+%type <integer> integer_or\n+%type <integer> integer_trinary\n+%type <integer> integer_expr\n+\n+%%\n+\n+sourcefile:\n+\t headers memreserves devicetree\n+\t\t{\n+\t\t\tparser_output = build_dt_info($1, $2, $3,\n+\t\t\t guess_boot_cpuid($3));\n+\t\t}\n+\t;\n+\n+header:\n+\t DT_V1 ';'\n+\t\t{\n+\t\t\t$$ = DTSF_V1;\n+\t\t}\n+\t| DT_V1 ';' DT_PLUGIN ';'\n+\t\t{\n+\t\t\t$$ = DTSF_V1 | DTSF_PLUGIN;\n+\t\t}\n+\t;\n+\n+headers:\n+\t header\n+\t| header headers\n+\t\t{\n+\t\t\tif ($2 != $1)\n+\t\t\t\tERROR(&@2, \"Header flags don't match earlier ones\");\n+\t\t\t$$ = $1;\n+\t\t}\n+\t;\n+\n+memreserves:\n+\t /* empty */\n+\t\t{\n+\t\t\t$$ = NULL;\n+\t\t}\n+\t| memreserve memreserves\n+\t\t{\n+\t\t\t$$ = chain_reserve_entry($1, $2);\n+\t\t}\n+\t;\n+\n+memreserve:\n+\t DT_MEMRESERVE integer_prim integer_prim ';'\n+\t\t{\n+\t\t\t$$ = build_reserve_entry($2, $3);\n+\t\t}\n+\t| DT_LABEL memreserve\n+\t\t{\n+\t\t\tadd_label(&$2->labels, $1);\n+\t\t\t$$ = $2;\n+\t\t}\n+\t;\n+\n+devicetree:\n+\t '/' nodedef\n+\t\t{\n+\t\t\t$$ = name_node($2, \"\");\n+\t\t}\n+\t| devicetree '/' nodedef\n+\t\t{\n+\t\t\t$$ = merge_nodes($1, $3);\n+\t\t}\n+\n+\t| devicetree DT_LABEL DT_REF nodedef\n+\t\t{\n+\t\t\tstruct node *target = get_node_by_ref($1, $3);\n+\n+\t\t\tif (target) {\n+\t\t\t\tadd_label(&target->labels, $2);\n+\t\t\t\tmerge_nodes(target, $4);\n+\t\t\t} else\n+\t\t\t\tERROR(&@3, \"Label or path %s not found\", $3);\n+\t\t\t$$ = $1;\n+\t\t}\n+\t| devicetree DT_REF nodedef\n+\t\t{\n+\t\t\tstruct node *target = get_node_by_ref($1, $2);\n+\n+\t\t\tif (target)\n+\t\t\t\tmerge_nodes(target, $3);\n+\t\t\telse\n+\t\t\t\tERROR(&@2, \"Label or path %s not found\", $2);\n+\t\t\t$$ = $1;\n+\t\t}\n+\t| devicetree DT_DEL_NODE DT_REF ';'\n+\t\t{\n+\t\t\tstruct node *target = get_node_by_ref($1, $3);\n+\n+\t\t\tif (target)\n+\t\t\t\tdelete_node(target);\n+\t\t\telse\n+\t\t\t\tERROR(&@3, \"Label or path %s not found\", $3);\n+\n+\n+\t\t\t$$ = $1;\n+\t\t}\n+\t;\n+\n+nodedef:\n+\t '{' proplist subnodes '}' ';'\n+\t\t{\n+\t\t\t$$ = build_node($2, $3);\n+\t\t}\n+\t;\n+\n+proplist:\n+\t /* empty */\n+\t\t{\n+\t\t\t$$ = NULL;\n+\t\t}\n+\t| proplist propdef\n+\t\t{\n+\t\t\t$$ = chain_property($2, $1);\n+\t\t}\n+\t;\n+\n+propdef:\n+\t DT_PROPNODENAME '=' propdata ';'\n+\t\t{\n+\t\t\t$$ = build_property($1, $3);\n+\t\t}\n+\t| DT_PROPNODENAME ';'\n+\t\t{\n+\t\t\t$$ = build_property($1, empty_data);\n+\t\t}\n+\t| DT_DEL_PROP DT_PROPNODENAME ';'\n+\t\t{\n+\t\t\t$$ = build_property_delete($2);\n+\t\t}\n+\t| DT_LABEL propdef\n+\t\t{\n+\t\t\tadd_label(&$2->labels, $1);\n+\t\t\t$$ = $2;\n+\t\t}\n+\t;\n+\n+propdata:\n+\t propdataprefix DT_STRING\n+\t\t{\n+\t\t\t$$ = data_merge($1, $2);\n+\t\t}\n+\t| propdataprefix arrayprefix '>'\n+\t\t{\n+\t\t\t$$ = data_merge($1, $2.data);\n+\t\t}\n+\t| propdataprefix '[' bytestring ']'\n+\t\t{\n+\t\t\t$$ = data_merge($1, $3);\n+\t\t}\n+\t| propdataprefix DT_REF\n+\t\t{\n+\t\t\t$$ = data_add_marker($1, REF_PATH, $2);\n+\t\t}\n+\t| propdataprefix DT_INCBIN '(' DT_STRING ',' integer_prim ',' integer_prim ')'\n+\t\t{\n+\t\t\tFILE *f = srcfile_relative_open($4.val, NULL);\n+\t\t\tstruct data d;\n+\n+\t\t\tif ($6 != 0)\n+\t\t\t\tif (fseek(f, $6, SEEK_SET) != 0)\n+\t\t\t\t\tdie(\"Couldn't seek to offset %llu in \\\"%s\\\": %s\",\n+\t\t\t\t\t (unsigned long long)$6, $4.val,\n+\t\t\t\t\t strerror(errno));\n+\n+\t\t\td = data_copy_file(f, $8);\n+\n+\t\t\t$$ = data_merge($1, d);\n+\t\t\tfclose(f);\n+\t\t}\n+\t| propdataprefix DT_INCBIN '(' DT_STRING ')'\n+\t\t{\n+\t\t\tFILE *f = srcfile_relative_open($4.val, NULL);\n+\t\t\tstruct data d = empty_data;\n+\n+\t\t\td = data_copy_file(f, -1);\n+\n+\t\t\t$$ = data_merge($1, d);\n+\t\t\tfclose(f);\n+\t\t}\n+\t| propdata DT_LABEL\n+\t\t{\n+\t\t\t$$ = data_add_marker($1, LABEL, $2);\n+\t\t}\n+\t;\n+\n+propdataprefix:\n+\t /* empty */\n+\t\t{\n+\t\t\t$$ = empty_data;\n+\t\t}\n+\t| propdata ','\n+\t\t{\n+\t\t\t$$ = $1;\n+\t\t}\n+\t| propdataprefix DT_LABEL\n+\t\t{\n+\t\t\t$$ = data_add_marker($1, LABEL, $2);\n+\t\t}\n+\t;\n+\n+arrayprefix:\n+\tDT_BITS DT_LITERAL '<'\n+\t\t{\n+\t\t\tunsigned long long bits;\n+\n+\t\t\tbits = $2;\n+\n+\t\t\tif ((bits != 8) && (bits != 16) &&\n+\t\t\t (bits != 32) && (bits != 64)) {\n+\t\t\t\tERROR(&@2, \"Array elements must be\"\n+\t\t\t\t \" 8, 16, 32 or 64-bits\");\n+\t\t\t\tbits = 32;\n+\t\t\t}\n+\n+\t\t\t$$.data = empty_data;\n+\t\t\t$$.bits = bits;\n+\t\t}\n+\t| '<'\n+\t\t{\n+\t\t\t$$.data = empty_data;\n+\t\t\t$$.bits = 32;\n+\t\t}\n+\t| arrayprefix integer_prim\n+\t\t{\n+\t\t\tif ($1.bits < 64) {\n+\t\t\t\tuint64_t mask = (1ULL << $1.bits) - 1;\n+\t\t\t\t/*\n+\t\t\t\t * Bits above mask must either be all zero\n+\t\t\t\t * (positive within range of mask) or all one\n+\t\t\t\t * (negative and sign-extended). The second\n+\t\t\t\t * condition is true if when we set all bits\n+\t\t\t\t * within the mask to one (i.e. | in the\n+\t\t\t\t * mask), all bits are one.\n+\t\t\t\t */\n+\t\t\t\tif (($2 > mask) && (($2 | mask) != -1ULL))\n+\t\t\t\t\tERROR(&@2, \"Value out of range for\"\n+\t\t\t\t\t \" %d-bit array element\", $1.bits);\n+\t\t\t}\n+\n+\t\t\t$$.data = data_append_integer($1.data, $2, $1.bits);\n+\t\t}\n+\t| arrayprefix DT_REF\n+\t\t{\n+\t\t\tuint64_t val = ~0ULL >> (64 - $1.bits);\n+\n+\t\t\tif ($1.bits == 32)\n+\t\t\t\t$1.data = data_add_marker($1.data,\n+\t\t\t\t\t\t\t REF_PHANDLE,\n+\t\t\t\t\t\t\t $2);\n+\t\t\telse\n+\t\t\t\tERROR(&@2, \"References are only allowed in \"\n+\t\t\t\t\t \"arrays with 32-bit elements.\");\n+\n+\t\t\t$$.data = data_append_integer($1.data, val, $1.bits);\n+\t\t}\n+\t| arrayprefix DT_LABEL\n+\t\t{\n+\t\t\t$$.data = data_add_marker($1.data, LABEL, $2);\n+\t\t}\n+\t;\n+\n+integer_prim:\n+\t DT_LITERAL\n+\t| DT_CHAR_LITERAL\n+\t| '(' integer_expr ')'\n+\t\t{\n+\t\t\t$$ = $2;\n+\t\t}\n+\t;\n+\n+integer_expr:\n+\tinteger_trinary\n+\t;\n+\n+integer_trinary:\n+\t integer_or\n+\t| integer_or '?' integer_expr ':' integer_trinary { $$ = $1 ? $3 : $5; }\n+\t;\n+\n+integer_or:\n+\t integer_and\n+\t| integer_or DT_OR integer_and { $$ = $1 || $3; }\n+\t;\n+\n+integer_and:\n+\t integer_bitor\n+\t| integer_and DT_AND integer_bitor { $$ = $1 && $3; }\n+\t;\n+\n+integer_bitor:\n+\t integer_bitxor\n+\t| integer_bitor '|' integer_bitxor { $$ = $1 | $3; }\n+\t;\n+\n+integer_bitxor:\n+\t integer_bitand\n+\t| integer_bitxor '^' integer_bitand { $$ = $1 ^ $3; }\n+\t;\n+\n+integer_bitand:\n+\t integer_eq\n+\t| integer_bitand '&' integer_eq { $$ = $1 & $3; }\n+\t;\n+\n+integer_eq:\n+\t integer_rela\n+\t| integer_eq DT_EQ integer_rela { $$ = $1 == $3; }\n+\t| integer_eq DT_NE integer_rela { $$ = $1 != $3; }\n+\t;\n+\n+integer_rela:\n+\t integer_shift\n+\t| integer_rela '<' integer_shift { $$ = $1 < $3; }\n+\t| integer_rela '>' integer_shift { $$ = $1 > $3; }\n+\t| integer_rela DT_LE integer_shift { $$ = $1 <= $3; }\n+\t| integer_rela DT_GE integer_shift { $$ = $1 >= $3; }\n+\t;\n+\n+integer_shift:\n+\t integer_shift DT_LSHIFT integer_add { $$ = $1 << $3; }\n+\t| integer_shift DT_RSHIFT integer_add { $$ = $1 >> $3; }\n+\t| integer_add\n+\t;\n+\n+integer_add:\n+\t integer_add '+' integer_mul { $$ = $1 + $3; }\n+\t| integer_add '-' integer_mul { $$ = $1 - $3; }\n+\t| integer_mul\n+\t;\n+\n+integer_mul:\n+\t integer_mul '*' integer_unary { $$ = $1 * $3; }\n+\t| integer_mul '/' integer_unary\n+\t\t{\n+\t\t\tif ($3 != 0) {\n+\t\t\t\t$$ = $1 / $3;\n+\t\t\t} else {\n+\t\t\t\tERROR(&@$, \"Division by zero\");\n+\t\t\t\t$$ = 0;\n+\t\t\t}\n+\t\t}\n+\t| integer_mul '%' integer_unary\n+\t\t{\n+\t\t\tif ($3 != 0) {\n+\t\t\t\t$$ = $1 % $3;\n+\t\t\t} else {\n+\t\t\t\tERROR(&@$, \"Division by zero\");\n+\t\t\t\t$$ = 0;\n+\t\t\t}\n+\t\t}\n+\t| integer_unary\n+\t;\n+\n+integer_unary:\n+\t integer_prim\n+\t| '-' integer_unary { $$ = -$2; }\n+\t| '~' integer_unary { $$ = ~$2; }\n+\t| '!' integer_unary { $$ = !$2; }\n+\t;\n+\n+bytestring:\n+\t /* empty */\n+\t\t{\n+\t\t\t$$ = empty_data;\n+\t\t}\n+\t| bytestring DT_BYTE\n+\t\t{\n+\t\t\t$$ = data_append_byte($1, $2);\n+\t\t}\n+\t| bytestring DT_LABEL\n+\t\t{\n+\t\t\t$$ = data_add_marker($1, LABEL, $2);\n+\t\t}\n+\t;\n+\n+subnodes:\n+\t /* empty */\n+\t\t{\n+\t\t\t$$ = NULL;\n+\t\t}\n+\t| subnode subnodes\n+\t\t{\n+\t\t\t$$ = chain_node($1, $2);\n+\t\t}\n+\t| subnode propdef\n+\t\t{\n+\t\t\tERROR(&@2, \"Properties must precede subnodes\");\n+\t\t\tYYERROR;\n+\t\t}\n+\t;\n+\n+subnode:\n+\t DT_PROPNODENAME nodedef\n+\t\t{\n+\t\t\t$$ = name_node($2, $1);\n+\t\t}\n+\t| DT_DEL_NODE DT_PROPNODENAME ';'\n+\t\t{\n+\t\t\t$$ = name_node(build_node_delete(), $2);\n+\t\t}\n+\t| DT_LABEL subnode\n+\t\t{\n+\t\t\tadd_label(&$2->labels, $1);\n+\t\t\t$$ = $2;\n+\t\t}\n+\t;\n+\n+%%\n+\n+void yyerror(char const *s)\n+{\n+\tERROR(&yylloc, \"%s\", s);\n+}\ndiff --git a/scripts/dtc/dtc.c b/scripts/dtc/dtc.c\nnew file mode 100644\nindex 000000000000..bb1e52b3181c\n--- /dev/null\n+++ b/scripts/dtc/dtc.c\n@@ -0,0 +1,366 @@\n+/*\n+ * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.\n+ *\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License as\n+ * published by the Free Software Foundation; either version 2 of the\n+ * License, or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\n+ * USA\n+ */\n+\n+#include <sys/stat.h>\n+\n+#include \"dtc.h\"\n+#include \"srcpos.h\"\n+\n+/*\n+ * Command line options\n+ */\n+int quiet;\t\t/* Level of quietness */\n+int reservenum;\t\t/* Number of memory reservation slots */\n+int minsize;\t\t/* Minimum blob size */\n+int padsize;\t\t/* Additional padding to blob */\n+int alignsize;\t\t/* Additional padding to blob accroding to the alignsize */\n+int phandle_format = PHANDLE_BOTH;\t/* Use linux,phandle or phandle properties */\n+int generate_symbols;\t/* enable symbols & fixup support */\n+int generate_fixups;\t\t/* suppress generation of fixups on symbol support */\n+int auto_label_aliases;\t\t/* auto generate labels -> aliases */\n+\n+static int is_power_of_2(int x)\n+{\n+\treturn (x > 0) && ((x & (x - 1)) == 0);\n+}\n+\n+static void fill_fullpaths(struct node *tree, const char *prefix)\n+{\n+\tstruct node *child;\n+\tconst char *unit;\n+\n+\ttree->fullpath = join_path(prefix, tree->name);\n+\n+\tunit = strchr(tree->name, '@');\n+\tif (unit)\n+\t\ttree->basenamelen = unit - tree->name;\n+\telse\n+\t\ttree->basenamelen = strlen(tree->name);\n+\n+\tfor_each_child(tree, child)\n+\t\tfill_fullpaths(child, tree->fullpath);\n+}\n+\n+/* Usage related data. */\n+#define FDT_VERSION(version)\t_FDT_VERSION(version)\n+#define _FDT_VERSION(version)\t#version\n+static const char usage_synopsis[] = \"dtc [options] <input file>\";\n+static const char usage_short_opts[] = \"qI:O:o:V:d:R:S:p:a:fb:i:H:sW:E:@Ahv\";\n+static struct option const usage_long_opts[] = {\n+\t{\"quiet\", no_argument, NULL, 'q'},\n+\t{\"in-format\", a_argument, NULL, 'I'},\n+\t{\"out\", a_argument, NULL, 'o'},\n+\t{\"out-format\", a_argument, NULL, 'O'},\n+\t{\"out-version\", a_argument, NULL, 'V'},\n+\t{\"out-dependency\", a_argument, NULL, 'd'},\n+\t{\"reserve\", a_argument, NULL, 'R'},\n+\t{\"space\", a_argument, NULL, 'S'},\n+\t{\"pad\", a_argument, NULL, 'p'},\n+\t{\"align\", a_argument, NULL, 'a'},\n+\t{\"boot-cpu\", a_argument, NULL, 'b'},\n+\t{\"force\", no_argument, NULL, 'f'},\n+\t{\"include\", a_argument, NULL, 'i'},\n+\t{\"sort\", no_argument, NULL, 's'},\n+\t{\"phandle\", a_argument, NULL, 'H'},\n+\t{\"warning\", a_argument, NULL, 'W'},\n+\t{\"error\", a_argument, NULL, 'E'},\n+\t{\"symbols\",\t no_argument, NULL, '@'},\n+\t{\"auto-alias\", no_argument, NULL, 'A'},\n+\t{\"help\", no_argument, NULL, 'h'},\n+\t{\"version\", no_argument, NULL, 'v'},\n+\t{NULL, no_argument, NULL, 0x0},\n+};\n+static const char * const usage_opts_help[] = {\n+\t\"\\n\\tQuiet: -q suppress warnings, -qq errors, -qqq all\",\n+\t\"\\n\\tInput formats are:\\n\"\n+\t \"\\t\\tdts - device tree source text\\n\"\n+\t \"\\t\\tdtb - device tree blob\\n\"\n+\t \"\\t\\tfs - /proc/device-tree style directory\",\n+\t\"\\n\\tOutput file\",\n+\t\"\\n\\tOutput formats are:\\n\"\n+\t \"\\t\\tdts - device tree source text\\n\"\n+\t \"\\t\\tdtb - device tree blob\\n\"\n+\t \"\\t\\tasm - assembler source\",\n+\t\"\\n\\tBlob version to produce, defaults to \"FDT_VERSION(DEFAULT_FDT_VERSION)\" (for dtb and asm output)\",\n+\t\"\\n\\tOutput dependency file\",\n+\t\"\\n\\tMake space for <number> reserve map entries (for dtb and asm output)\",\n+\t\"\\n\\tMake the blob at least <bytes> long (extra space)\",\n+\t\"\\n\\tAdd padding to the blob of <bytes> long (extra space)\",\n+\t\"\\n\\tMake the blob align to the <bytes> (extra space)\",\n+\t\"\\n\\tSet the physical boot cpu\",\n+\t\"\\n\\tTry to produce output even if the input tree has errors\",\n+\t\"\\n\\tAdd a path to search for include files\",\n+\t\"\\n\\tSort nodes and properties before outputting (useful for comparing trees)\",\n+\t\"\\n\\tValid phandle formats are:\\n\"\n+\t \"\\t\\tlegacy - \\\"linux,phandle\\\" properties only\\n\"\n+\t \"\\t\\tepapr - \\\"phandle\\\" properties only\\n\"\n+\t \"\\t\\tboth - Both \\\"linux,phandle\\\" and \\\"phandle\\\" properties\",\n+\t\"\\n\\tEnable/disable warnings (prefix with \\\"no-\\\")\",\n+\t\"\\n\\tEnable/disable errors (prefix with \\\"no-\\\")\",\n+\t\"\\n\\tEnable generation of symbols\",\n+\t\"\\n\\tEnable auto-alias of labels\",\n+\t\"\\n\\tPrint this help and exit\",\n+\t\"\\n\\tPrint version and exit\",\n+\tNULL,\n+};\n+\n+static const char *guess_type_by_name(const char *fname, const char *fallback)\n+{\n+\tconst char *s;\n+\n+\ts = strrchr(fname, '.');\n+\tif (s == NULL)\n+\t\treturn fallback;\n+\tif (!strcasecmp(s, \".dts\"))\n+\t\treturn \"dts\";\n+\tif (!strcasecmp(s, \".dtb\"))\n+\t\treturn \"dtb\";\n+\treturn fallback;\n+}\n+\n+static const char *guess_input_format(const char *fname, const char *fallback)\n+{\n+\tstruct stat statbuf;\n+\tuint32_t magic;\n+\tFILE *f;\n+\n+\tif (stat(fname, &statbuf) != 0)\n+\t\treturn fallback;\n+\n+\tif (S_ISDIR(statbuf.st_mode))\n+\t\treturn \"fs\";\n+\n+\tif (!S_ISREG(statbuf.st_mode))\n+\t\treturn fallback;\n+\n+\tf = fopen(fname, \"r\");\n+\tif (f == NULL)\n+\t\treturn fallback;\n+\tif (fread(&magic, 4, 1, f) != 1) {\n+\t\tfclose(f);\n+\t\treturn fallback;\n+\t}\n+\tfclose(f);\n+\n+\tmagic = fdt32_to_cpu(magic);\n+\tif (magic == FDT_MAGIC)\n+\t\treturn \"dtb\";\n+\n+\treturn guess_type_by_name(fname, fallback);\n+}\n+\n+int main(int argc, char *argv[])\n+{\n+\tstruct dt_info *dti;\n+\tconst char *inform = NULL;\n+\tconst char *outform = NULL;\n+\tconst char *outname = \"-\";\n+\tconst char *depname = NULL;\n+\tbool force = false, sort = false;\n+\tconst char *arg;\n+\tint opt;\n+\tFILE *outf = NULL;\n+\tint outversion = DEFAULT_FDT_VERSION;\n+\tlong long cmdline_boot_cpuid = -1;\n+\n+\tquiet = 0;\n+\treservenum = 0;\n+\tminsize = 0;\n+\tpadsize = 0;\n+\talignsize = 0;\n+\n+\twhile ((opt = util_getopt_long()) != EOF) {\n+\t\tswitch (opt) {\n+\t\tcase 'I':\n+\t\t\tinform = optarg;\n+\t\t\tbreak;\n+\t\tcase 'O':\n+\t\t\toutform = optarg;\n+\t\t\tbreak;\n+\t\tcase 'o':\n+\t\t\toutname = optarg;\n+\t\t\tbreak;\n+\t\tcase 'V':\n+\t\t\toutversion = strtol(optarg, NULL, 0);\n+\t\t\tbreak;\n+\t\tcase 'd':\n+\t\t\tdepname = optarg;\n+\t\t\tbreak;\n+\t\tcase 'R':\n+\t\t\treservenum = strtol(optarg, NULL, 0);\n+\t\t\tbreak;\n+\t\tcase 'S':\n+\t\t\tminsize = strtol(optarg, NULL, 0);\n+\t\t\tbreak;\n+\t\tcase 'p':\n+\t\t\tpadsize = strtol(optarg, NULL, 0);\n+\t\t\tbreak;\n+\t\tcase 'a':\n+\t\t\talignsize = strtol(optarg, NULL, 0);\n+\t\t\tif (!is_power_of_2(alignsize))\n+\t\t\t\tdie(\"Invalid argument \\\"%d\\\" to -a option\\n\",\n+\t\t\t\t alignsize);\n+\t\t\tbreak;\n+\t\tcase 'f':\n+\t\t\tforce = true;\n+\t\t\tbreak;\n+\t\tcase 'q':\n+\t\t\tquiet++;\n+\t\t\tbreak;\n+\t\tcase 'b':\n+\t\t\tcmdline_boot_cpuid = strtoll(optarg, NULL, 0);\n+\t\t\tbreak;\n+\t\tcase 'i':\n+\t\t\tsrcfile_add_search_path(optarg);\n+\t\t\tbreak;\n+\t\tcase 'v':\n+\t\t\tutil_version();\n+\t\tcase 'H':\n+\t\t\tif (streq(optarg, \"legacy\"))\n+\t\t\t\tphandle_format = PHANDLE_LEGACY;\n+\t\t\telse if (streq(optarg, \"epapr\"))\n+\t\t\t\tphandle_format = PHANDLE_EPAPR;\n+\t\t\telse if (streq(optarg, \"both\"))\n+\t\t\t\tphandle_format = PHANDLE_BOTH;\n+\t\t\telse\n+\t\t\t\tdie(\"Invalid argument \\\"%s\\\" to -H option\\n\",\n+\t\t\t\t optarg);\n+\t\t\tbreak;\n+\n+\t\tcase 's':\n+\t\t\tsort = true;\n+\t\t\tbreak;\n+\n+\t\tcase 'W':\n+\t\t\tparse_checks_option(true, false, optarg);\n+\t\t\tbreak;\n+\n+\t\tcase 'E':\n+\t\t\tparse_checks_option(false, true, optarg);\n+\t\t\tbreak;\n+\n+\t\tcase '@':\n+\t\t\tgenerate_symbols = 1;\n+\t\t\tbreak;\n+\t\tcase 'A':\n+\t\t\tauto_label_aliases = 1;\n+\t\t\tbreak;\n+\n+\t\tcase 'h':\n+\t\t\tusage(NULL);\n+\t\tdefault:\n+\t\t\tusage(\"unknown option\");\n+\t\t}\n+\t}\n+\n+\tif (argc > (optind+1))\n+\t\tusage(\"missing files\");\n+\telse if (argc < (optind+1))\n+\t\targ = \"-\";\n+\telse\n+\t\targ = argv[optind];\n+\n+\t/* minsize and padsize are mutually exclusive */\n+\tif (minsize && padsize)\n+\t\tdie(\"Can't set both -p and -S\\n\");\n+\n+\tif (depname) {\n+\t\tdepfile = fopen(depname, \"w\");\n+\t\tif (!depfile)\n+\t\t\tdie(\"Couldn't open dependency file %s: %s\\n\", depname,\n+\t\t\t strerror(errno));\n+\t\tfprintf(depfile, \"%s:\", outname);\n+\t}\n+\n+\tif (inform == NULL)\n+\t\tinform = guess_input_format(arg, \"dts\");\n+\tif (outform == NULL) {\n+\t\toutform = guess_type_by_name(outname, NULL);\n+\t\tif (outform == NULL) {\n+\t\t\tif (streq(inform, \"dts\"))\n+\t\t\t\toutform = \"dtb\";\n+\t\t\telse\n+\t\t\t\toutform = \"dts\";\n+\t\t}\n+\t}\n+\tif (streq(inform, \"dts\"))\n+\t\tdti = dt_from_source(arg);\n+\telse if (streq(inform, \"fs\"))\n+\t\tdti = dt_from_fs(arg);\n+\telse if(streq(inform, \"dtb\"))\n+\t\tdti = dt_from_blob(arg);\n+\telse\n+\t\tdie(\"Unknown input format \\\"%s\\\"\\n\", inform);\n+\n+\tdti->outname = outname;\n+\n+\tif (depfile) {\n+\t\tfputc('\\n', depfile);\n+\t\tfclose(depfile);\n+\t}\n+\n+\tif (cmdline_boot_cpuid != -1)\n+\t\tdti->boot_cpuid_phys = cmdline_boot_cpuid;\n+\n+\tfill_fullpaths(dti->dt, \"\");\n+\tprocess_checks(force, dti);\n+\n+\t/* on a plugin, generate by default */\n+\tif (dti->dtsflags & DTSF_PLUGIN) {\n+\t\tgenerate_fixups = 1;\n+\t}\n+\n+\tif (auto_label_aliases)\n+\t\tgenerate_label_tree(dti, \"aliases\", false);\n+\n+\tif (generate_symbols)\n+\t\tgenerate_label_tree(dti, \"__symbols__\", true);\n+\n+\tif (generate_fixups) {\n+\t\tgenerate_fixups_tree(dti, \"__fixups__\");\n+\t\tgenerate_local_fixups_tree(dti, \"__local_fixups__\");\n+\t}\n+\n+\tif (sort)\n+\t\tsort_tree(dti);\n+\n+\tif (streq(outname, \"-\")) {\n+\t\toutf = stdout;\n+\t} else {\n+\t\toutf = fopen(outname, \"wb\");\n+\t\tif (! outf)\n+\t\t\tdie(\"Couldn't open output file %s: %s\\n\",\n+\t\t\t outname, strerror(errno));\n+\t}\n+\n+\tif (streq(outform, \"dts\")) {\n+\t\tdt_to_source(outf, dti);\n+\t} else if (streq(outform, \"dtb\")) {\n+\t\tdt_to_blob(outf, dti, outversion);\n+\t} else if (streq(outform, \"asm\")) {\n+\t\tdt_to_asm(outf, dti, outversion);\n+\t} else if (streq(outform, \"null\")) {\n+\t\t/* do nothing */\n+\t} else {\n+\t\tdie(\"Unknown output format \\\"%s\\\"\\n\", outform);\n+\t}\n+\n+\texit(0);\n+}\ndiff --git a/scripts/dtc/dtc.h b/scripts/dtc/dtc.h\nnew file mode 100644\nindex 000000000000..1ac2a1e3a4a5\n--- /dev/null\n+++ b/scripts/dtc/dtc.h\n@@ -0,0 +1,285 @@\n+#ifndef _DTC_H\n+#define _DTC_H\n+\n+/*\n+ * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.\n+ *\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License as\n+ * published by the Free Software Foundation; either version 2 of the\n+ * License, or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\n+ * USA\n+ */\n+\n+#include <stdio.h>\n+#include <string.h>\n+#include <stdlib.h>\n+#include <stdint.h>\n+#include <stdbool.h>\n+#include <stdarg.h>\n+#include <assert.h>\n+#include <ctype.h>\n+#include <errno.h>\n+#include <unistd.h>\n+\n+#include <libfdt_env.h>\n+#include <fdt.h>\n+\n+#include \"util.h\"\n+\n+#ifdef DEBUG\n+#define debug(...)\tprintf(__VA_ARGS__)\n+#else\n+#define debug(...)\n+#endif\n+\n+\n+#define DEFAULT_FDT_VERSION\t17\n+\n+/*\n+ * Command line options\n+ */\n+extern int quiet;\t\t/* Level of quietness */\n+extern int reservenum;\t\t/* Number of memory reservation slots */\n+extern int minsize;\t\t/* Minimum blob size */\n+extern int padsize;\t\t/* Additional padding to blob */\n+extern int alignsize;\t\t/* Additional padding to blob accroding to the alignsize */\n+extern int phandle_format;\t/* Use linux,phandle or phandle properties */\n+extern int generate_symbols;\t/* generate symbols for nodes with labels */\n+extern int generate_fixups;\t/* generate fixups */\n+extern int auto_label_aliases;\t/* auto generate labels -> aliases */\n+\n+#define PHANDLE_LEGACY\t0x1\n+#define PHANDLE_EPAPR\t0x2\n+#define PHANDLE_BOTH\t0x3\n+\n+typedef uint32_t cell_t;\n+\n+\n+#define streq(a, b)\t(strcmp((a), (b)) == 0)\n+#define strneq(a, b, n)\t(strncmp((a), (b), (n)) == 0)\n+\n+#define ALIGN(x, a)\t(((x) + (a) - 1) & ~((a) - 1))\n+\n+/* Data blobs */\n+enum markertype {\n+\tREF_PHANDLE,\n+\tREF_PATH,\n+\tLABEL,\n+};\n+\n+struct marker {\n+\tenum markertype type;\n+\tint offset;\n+\tchar *ref;\n+\tstruct marker *next;\n+};\n+\n+struct data {\n+\tint len;\n+\tchar *val;\n+\tstruct marker *markers;\n+};\n+\n+\n+#define empty_data ((struct data){ 0 /* all .members = 0 or NULL */ })\n+\n+#define for_each_marker(m) \\\n+\tfor (; (m); (m) = (m)->next)\n+#define for_each_marker_of_type(m, t) \\\n+\tfor_each_marker(m) \\\n+\t\tif ((m)->type == (t))\n+\n+void data_free(struct data d);\n+\n+struct data data_grow_for(struct data d, int xlen);\n+\n+struct data data_copy_mem(const char *mem, int len);\n+struct data data_copy_escape_string(const char *s, int len);\n+struct data data_copy_file(FILE *f, size_t len);\n+\n+struct data data_append_data(struct data d, const void *p, int len);\n+struct data data_insert_at_marker(struct data d, struct marker *m,\n+\t\t\t\t const void *p, int len);\n+struct data data_merge(struct data d1, struct data d2);\n+struct data data_append_cell(struct data d, cell_t word);\n+struct data data_append_integer(struct data d, uint64_t word, int bits);\n+struct data data_append_re(struct data d, const struct fdt_reserve_entry *re);\n+struct data data_append_addr(struct data d, uint64_t addr);\n+struct data data_append_byte(struct data d, uint8_t byte);\n+struct data data_append_zeroes(struct data d, int len);\n+struct data data_append_align(struct data d, int align);\n+\n+struct data data_add_marker(struct data d, enum markertype type, char *ref);\n+\n+bool data_is_one_string(struct data d);\n+\n+/* DT constraints */\n+\n+#define MAX_PROPNAME_LEN\t31\n+#define MAX_NODENAME_LEN\t31\n+\n+/* Live trees */\n+struct label {\n+\tbool deleted;\n+\tchar *label;\n+\tstruct label *next;\n+};\n+\n+struct property {\n+\tbool deleted;\n+\tchar *name;\n+\tstruct data val;\n+\n+\tstruct property *next;\n+\n+\tstruct label *labels;\n+};\n+\n+struct node {\n+\tbool deleted;\n+\tchar *name;\n+\tstruct property *proplist;\n+\tstruct node *children;\n+\n+\tstruct node *parent;\n+\tstruct node *next_sibling;\n+\n+\tchar *fullpath;\n+\tint basenamelen;\n+\n+\tcell_t phandle;\n+\tint addr_cells, size_cells;\n+\n+\tstruct label *labels;\n+};\n+\n+#define for_each_label_withdel(l0, l) \\\n+\tfor ((l) = (l0); (l); (l) = (l)->next)\n+\n+#define for_each_label(l0, l) \\\n+\tfor_each_label_withdel(l0, l) \\\n+\t\tif (!(l)->deleted)\n+\n+#define for_each_property_withdel(n, p) \\\n+\tfor ((p) = (n)->proplist; (p); (p) = (p)->next)\n+\n+#define for_each_property(n, p) \\\n+\tfor_each_property_withdel(n, p) \\\n+\t\tif (!(p)->deleted)\n+\n+#define for_each_child_withdel(n, c) \\\n+\tfor ((c) = (n)->children; (c); (c) = (c)->next_sibling)\n+\n+#define for_each_child(n, c) \\\n+\tfor_each_child_withdel(n, c) \\\n+\t\tif (!(c)->deleted)\n+\n+void add_label(struct label **labels, char *label);\n+void delete_labels(struct label **labels);\n+\n+struct property *build_property(char *name, struct data val);\n+struct property *build_property_delete(char *name);\n+struct property *chain_property(struct property *first, struct property *list);\n+struct property *reverse_properties(struct property *first);\n+\n+struct node *build_node(struct property *proplist, struct node *children);\n+struct node *build_node_delete(void);\n+struct node *name_node(struct node *node, char *name);\n+struct node *chain_node(struct node *first, struct node *list);\n+struct node *merge_nodes(struct node *old_node, struct node *new_node);\n+\n+void add_property(struct node *node, struct property *prop);\n+void delete_property_by_name(struct node *node, char *name);\n+void delete_property(struct property *prop);\n+void add_child(struct node *parent, struct node *child);\n+void delete_node_by_name(struct node *parent, char *name);\n+void delete_node(struct node *node);\n+void append_to_property(struct node *node,\n+\t\t\tchar *name, const void *data, int len);\n+\n+const char *get_unitname(struct node *node);\n+struct property *get_property(struct node *node, const char *propname);\n+cell_t propval_cell(struct property *prop);\n+struct property *get_property_by_label(struct node *tree, const char *label,\n+\t\t\t\t struct node **node);\n+struct marker *get_marker_label(struct node *tree, const char *label,\n+\t\t\t\tstruct node **node, struct property **prop);\n+struct node *get_subnode(struct node *node, const char *nodename);\n+struct node *get_node_by_path(struct node *tree, const char *path);\n+struct node *get_node_by_label(struct node *tree, const char *label);\n+struct node *get_node_by_phandle(struct node *tree, cell_t phandle);\n+struct node *get_node_by_ref(struct node *tree, const char *ref);\n+cell_t get_node_phandle(struct node *root, struct node *node);\n+\n+uint32_t guess_boot_cpuid(struct node *tree);\n+\n+/* Boot info (tree plus memreserve information */\n+\n+struct reserve_info {\n+\tstruct fdt_reserve_entry re;\n+\n+\tstruct reserve_info *next;\n+\n+\tstruct label *labels;\n+};\n+\n+struct reserve_info *build_reserve_entry(uint64_t start, uint64_t len);\n+struct reserve_info *chain_reserve_entry(struct reserve_info *first,\n+\t\t\t\t\t struct reserve_info *list);\n+struct reserve_info *add_reserve_entry(struct reserve_info *list,\n+\t\t\t\t struct reserve_info *new);\n+\n+\n+struct dt_info {\n+\tunsigned int dtsflags;\n+\tstruct reserve_info *reservelist;\n+\tuint32_t boot_cpuid_phys;\n+\tstruct node *dt;\t\t/* the device tree */\n+\tconst char *outname;\t\t/* filename being written to, \"-\" for stdout */\n+};\n+\n+/* DTS version flags definitions */\n+#define DTSF_V1\t\t0x0001\t/* /dts-v1/ */\n+#define DTSF_PLUGIN\t0x0002\t/* /plugin/ */\n+\n+struct dt_info *build_dt_info(unsigned int dtsflags,\n+\t\t\t struct reserve_info *reservelist,\n+\t\t\t struct node *tree, uint32_t boot_cpuid_phys);\n+void sort_tree(struct dt_info *dti);\n+void generate_label_tree(struct dt_info *dti, char *name, bool allocph);\n+void generate_fixups_tree(struct dt_info *dti, char *name);\n+void generate_local_fixups_tree(struct dt_info *dti, char *name);\n+\n+/* Checks */\n+\n+void parse_checks_option(bool warn, bool error, const char *arg);\n+void process_checks(bool force, struct dt_info *dti);\n+\n+/* Flattened trees */\n+\n+void dt_to_blob(FILE *f, struct dt_info *dti, int version);\n+void dt_to_asm(FILE *f, struct dt_info *dti, int version);\n+\n+struct dt_info *dt_from_blob(const char *fname);\n+\n+/* Tree source */\n+\n+void dt_to_source(FILE *f, struct dt_info *dti);\n+struct dt_info *dt_from_source(const char *f);\n+\n+/* FS trees */\n+\n+struct dt_info *dt_from_fs(const char *dirname);\n+\n+#endif /* _DTC_H */\ndiff --git a/scripts/dtc/flattree.c b/scripts/dtc/flattree.c\nnew file mode 100644\nindex 000000000000..ebac548b3fa8\n--- /dev/null\n+++ b/scripts/dtc/flattree.c\n@@ -0,0 +1,946 @@\n+/*\n+ * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.\n+ *\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License as\n+ * published by the Free Software Foundation; either version 2 of the\n+ * License, or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\n+ * USA\n+ */\n+\n+#include \"dtc.h\"\n+#include \"srcpos.h\"\n+\n+#define FTF_FULLPATH\t0x1\n+#define FTF_VARALIGN\t0x2\n+#define FTF_NAMEPROPS\t0x4\n+#define FTF_BOOTCPUID\t0x8\n+#define FTF_STRTABSIZE\t0x10\n+#define FTF_STRUCTSIZE\t0x20\n+#define FTF_NOPS\t0x40\n+\n+static struct version_info {\n+\tint version;\n+\tint last_comp_version;\n+\tint hdr_size;\n+\tint flags;\n+} version_table[] = {\n+\t{1, 1, FDT_V1_SIZE,\n+\t FTF_FULLPATH|FTF_VARALIGN|FTF_NAMEPROPS},\n+\t{2, 1, FDT_V2_SIZE,\n+\t FTF_FULLPATH|FTF_VARALIGN|FTF_NAMEPROPS|FTF_BOOTCPUID},\n+\t{3, 1, FDT_V3_SIZE,\n+\t FTF_FULLPATH|FTF_VARALIGN|FTF_NAMEPROPS|FTF_BOOTCPUID|FTF_STRTABSIZE},\n+\t{16, 16, FDT_V3_SIZE,\n+\t FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_NOPS},\n+\t{17, 16, FDT_V17_SIZE,\n+\t FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_STRUCTSIZE|FTF_NOPS},\n+};\n+\n+struct emitter {\n+\tvoid (*cell)(void *, cell_t);\n+\tvoid (*string)(void *, char *, int);\n+\tvoid (*align)(void *, int);\n+\tvoid (*data)(void *, struct data);\n+\tvoid (*beginnode)(void *, struct label *labels);\n+\tvoid (*endnode)(void *, struct label *labels);\n+\tvoid (*property)(void *, struct label *labels);\n+};\n+\n+static void bin_emit_cell(void *e, cell_t val)\n+{\n+\tstruct data *dtbuf = e;\n+\n+\t*dtbuf = data_append_cell(*dtbuf, val);\n+}\n+\n+static void bin_emit_string(void *e, char *str, int len)\n+{\n+\tstruct data *dtbuf = e;\n+\n+\tif (len == 0)\n+\t\tlen = strlen(str);\n+\n+\t*dtbuf = data_append_data(*dtbuf, str, len);\n+\t*dtbuf = data_append_byte(*dtbuf, '\\0');\n+}\n+\n+static void bin_emit_align(void *e, int a)\n+{\n+\tstruct data *dtbuf = e;\n+\n+\t*dtbuf = data_append_align(*dtbuf, a);\n+}\n+\n+static void bin_emit_data(void *e, struct data d)\n+{\n+\tstruct data *dtbuf = e;\n+\n+\t*dtbuf = data_append_data(*dtbuf, d.val, d.len);\n+}\n+\n+static void bin_emit_beginnode(void *e, struct label *labels)\n+{\n+\tbin_emit_cell(e, FDT_BEGIN_NODE);\n+}\n+\n+static void bin_emit_endnode(void *e, struct label *labels)\n+{\n+\tbin_emit_cell(e, FDT_END_NODE);\n+}\n+\n+static void bin_emit_property(void *e, struct label *labels)\n+{\n+\tbin_emit_cell(e, FDT_PROP);\n+}\n+\n+static struct emitter bin_emitter = {\n+\t.cell = bin_emit_cell,\n+\t.string = bin_emit_string,\n+\t.align = bin_emit_align,\n+\t.data = bin_emit_data,\n+\t.beginnode = bin_emit_beginnode,\n+\t.endnode = bin_emit_endnode,\n+\t.property = bin_emit_property,\n+};\n+\n+static void emit_label(FILE *f, const char *prefix, const char *label)\n+{\n+\tfprintf(f, \"\\t.globl\\t%s_%s\\n\", prefix, label);\n+\tfprintf(f, \"%s_%s:\\n\", prefix, label);\n+\tfprintf(f, \"_%s_%s:\\n\", prefix, label);\n+}\n+\n+static void emit_offset_label(FILE *f, const char *label, int offset)\n+{\n+\tfprintf(f, \"\\t.globl\\t%s\\n\", label);\n+\tfprintf(f, \"%s\\t= . + %d\\n\", label, offset);\n+}\n+\n+#define ASM_EMIT_BELONG(f, fmt, ...) \\\n+\t{ \\\n+\t\tfprintf((f), \"\\t.byte\\t((\" fmt \") >> 24) & 0xff\\n\", __VA_ARGS__); \\\n+\t\tfprintf((f), \"\\t.byte\\t((\" fmt \") >> 16) & 0xff\\n\", __VA_ARGS__); \\\n+\t\tfprintf((f), \"\\t.byte\\t((\" fmt \") >> 8) & 0xff\\n\", __VA_ARGS__); \\\n+\t\tfprintf((f), \"\\t.byte\\t(\" fmt \") & 0xff\\n\", __VA_ARGS__); \\\n+\t}\n+\n+static void asm_emit_cell(void *e, cell_t val)\n+{\n+\tFILE *f = e;\n+\n+\tfprintf(f, \"\\t.byte 0x%02x; .byte 0x%02x; .byte 0x%02x; .byte 0x%02x\\n\",\n+\t\t(val >> 24) & 0xff, (val >> 16) & 0xff,\n+\t\t(val >> 8) & 0xff, val & 0xff);\n+}\n+\n+static void asm_emit_string(void *e, char *str, int len)\n+{\n+\tFILE *f = e;\n+\tchar c = 0;\n+\n+\tif (len != 0) {\n+\t\t/* XXX: ewww */\n+\t\tc = str[len];\n+\t\tstr[len] = '\\0';\n+\t}\n+\n+\tfprintf(f, \"\\t.string\\t\\\"%s\\\"\\n\", str);\n+\n+\tif (len != 0) {\n+\t\tstr[len] = c;\n+\t}\n+}\n+\n+static void asm_emit_align(void *e, int a)\n+{\n+\tFILE *f = e;\n+\n+\tfprintf(f, \"\\t.balign\\t%d, 0\\n\", a);\n+}\n+\n+static void asm_emit_data(void *e, struct data d)\n+{\n+\tFILE *f = e;\n+\tint off = 0;\n+\tstruct marker *m = d.markers;\n+\n+\tfor_each_marker_of_type(m, LABEL)\n+\t\temit_offset_label(f, m->ref, m->offset);\n+\n+\twhile ((d.len - off) >= sizeof(uint32_t)) {\n+\t\tasm_emit_cell(e, fdt32_to_cpu(*((uint32_t *)(d.val+off))));\n+\t\toff += sizeof(uint32_t);\n+\t}\n+\n+\twhile ((d.len - off) >= 1) {\n+\t\tfprintf(f, \"\\t.byte\\t0x%hhx\\n\", d.val[off]);\n+\t\toff += 1;\n+\t}\n+\n+\tassert(off == d.len);\n+}\n+\n+static void asm_emit_beginnode(void *e, struct label *labels)\n+{\n+\tFILE *f = e;\n+\tstruct label *l;\n+\n+\tfor_each_label(labels, l) {\n+\t\tfprintf(f, \"\\t.globl\\t%s\\n\", l->label);\n+\t\tfprintf(f, \"%s:\\n\", l->label);\n+\t}\n+\tfprintf(f, \"\\t/* FDT_BEGIN_NODE */\\n\");\n+\tasm_emit_cell(e, FDT_BEGIN_NODE);\n+}\n+\n+static void asm_emit_endnode(void *e, struct label *labels)\n+{\n+\tFILE *f = e;\n+\tstruct label *l;\n+\n+\tfprintf(f, \"\\t/* FDT_END_NODE */\\n\");\n+\tasm_emit_cell(e, FDT_END_NODE);\n+\tfor_each_label(labels, l) {\n+\t\tfprintf(f, \"\\t.globl\\t%s_end\\n\", l->label);\n+\t\tfprintf(f, \"%s_end:\\n\", l->label);\n+\t}\n+}\n+\n+static void asm_emit_property(void *e, struct label *labels)\n+{\n+\tFILE *f = e;\n+\tstruct label *l;\n+\n+\tfor_each_label(labels, l) {\n+\t\tfprintf(f, \"\\t.globl\\t%s\\n\", l->label);\n+\t\tfprintf(f, \"%s:\\n\", l->label);\n+\t}\n+\tfprintf(f, \"\\t/* FDT_PROP */\\n\");\n+\tasm_emit_cell(e, FDT_PROP);\n+}\n+\n+static struct emitter asm_emitter = {\n+\t.cell = asm_emit_cell,\n+\t.string = asm_emit_string,\n+\t.align = asm_emit_align,\n+\t.data = asm_emit_data,\n+\t.beginnode = asm_emit_beginnode,\n+\t.endnode = asm_emit_endnode,\n+\t.property = asm_emit_property,\n+};\n+\n+static int stringtable_insert(struct data *d, const char *str)\n+{\n+\tint i;\n+\n+\t/* FIXME: do this more efficiently? */\n+\n+\tfor (i = 0; i < d->len; i++) {\n+\t\tif (streq(str, d->val + i))\n+\t\t\treturn i;\n+\t}\n+\n+\t*d = data_append_data(*d, str, strlen(str)+1);\n+\treturn i;\n+}\n+\n+static void flatten_tree(struct node *tree, struct emitter *emit,\n+\t\t\t void *etarget, struct data *strbuf,\n+\t\t\t struct version_info *vi)\n+{\n+\tstruct property *prop;\n+\tstruct node *child;\n+\tbool seen_name_prop = false;\n+\n+\tif (tree->deleted)\n+\t\treturn;\n+\n+\temit->beginnode(etarget, tree->labels);\n+\n+\tif (vi->flags & FTF_FULLPATH)\n+\t\temit->string(etarget, tree->fullpath, 0);\n+\telse\n+\t\temit->string(etarget, tree->name, 0);\n+\n+\temit->align(etarget, sizeof(cell_t));\n+\n+\tfor_each_property(tree, prop) {\n+\t\tint nameoff;\n+\n+\t\tif (streq(prop->name, \"name\"))\n+\t\t\tseen_name_prop = true;\n+\n+\t\tnameoff = stringtable_insert(strbuf, prop->name);\n+\n+\t\temit->property(etarget, prop->labels);\n+\t\temit->cell(etarget, prop->val.len);\n+\t\temit->cell(etarget, nameoff);\n+\n+\t\tif ((vi->flags & FTF_VARALIGN) && (prop->val.len >= 8))\n+\t\t\temit->align(etarget, 8);\n+\n+\t\temit->data(etarget, prop->val);\n+\t\temit->align(etarget, sizeof(cell_t));\n+\t}\n+\n+\tif ((vi->flags & FTF_NAMEPROPS) && !seen_name_prop) {\n+\t\temit->property(etarget, NULL);\n+\t\temit->cell(etarget, tree->basenamelen+1);\n+\t\temit->cell(etarget, stringtable_insert(strbuf, \"name\"));\n+\n+\t\tif ((vi->flags & FTF_VARALIGN) && ((tree->basenamelen+1) >= 8))\n+\t\t\temit->align(etarget, 8);\n+\n+\t\temit->string(etarget, tree->name, tree->basenamelen);\n+\t\temit->align(etarget, sizeof(cell_t));\n+\t}\n+\n+\tfor_each_child(tree, child) {\n+\t\tflatten_tree(child, emit, etarget, strbuf, vi);\n+\t}\n+\n+\temit->endnode(etarget, tree->labels);\n+}\n+\n+static struct data flatten_reserve_list(struct reserve_info *reservelist,\n+\t\t\t\t struct version_info *vi)\n+{\n+\tstruct reserve_info *re;\n+\tstruct data d = empty_data;\n+\tstatic struct fdt_reserve_entry null_re = {0,0};\n+\tint j;\n+\n+\tfor (re = reservelist; re; re = re->next) {\n+\t\td = data_append_re(d, &re->re);\n+\t}\n+\t/*\n+\t * Add additional reserved slots if the user asked for them.\n+\t */\n+\tfor (j = 0; j < reservenum; j++) {\n+\t\td = data_append_re(d, &null_re);\n+\t}\n+\n+\treturn d;\n+}\n+\n+static void make_fdt_header(struct fdt_header *fdt,\n+\t\t\t struct version_info *vi,\n+\t\t\t int reservesize, int dtsize, int strsize,\n+\t\t\t int boot_cpuid_phys)\n+{\n+\tint reserve_off;\n+\n+\treservesize += sizeof(struct fdt_reserve_entry);\n+\n+\tmemset(fdt, 0xff, sizeof(*fdt));\n+\n+\tfdt->magic = cpu_to_fdt32(FDT_MAGIC);\n+\tfdt->version = cpu_to_fdt32(vi->version);\n+\tfdt->last_comp_version = cpu_to_fdt32(vi->last_comp_version);\n+\n+\t/* Reserve map should be doubleword aligned */\n+\treserve_off = ALIGN(vi->hdr_size, 8);\n+\n+\tfdt->off_mem_rsvmap = cpu_to_fdt32(reserve_off);\n+\tfdt->off_dt_struct = cpu_to_fdt32(reserve_off + reservesize);\n+\tfdt->off_dt_strings = cpu_to_fdt32(reserve_off + reservesize\n+\t\t\t\t\t + dtsize);\n+\tfdt->totalsize = cpu_to_fdt32(reserve_off + reservesize + dtsize + strsize);\n+\n+\tif (vi->flags & FTF_BOOTCPUID)\n+\t\tfdt->boot_cpuid_phys = cpu_to_fdt32(boot_cpuid_phys);\n+\tif (vi->flags & FTF_STRTABSIZE)\n+\t\tfdt->size_dt_strings = cpu_to_fdt32(strsize);\n+\tif (vi->flags & FTF_STRUCTSIZE)\n+\t\tfdt->size_dt_struct = cpu_to_fdt32(dtsize);\n+}\n+\n+void dt_to_blob(FILE *f, struct dt_info *dti, int version)\n+{\n+\tstruct version_info *vi = NULL;\n+\tint i;\n+\tstruct data blob = empty_data;\n+\tstruct data reservebuf = empty_data;\n+\tstruct data dtbuf = empty_data;\n+\tstruct data strbuf = empty_data;\n+\tstruct fdt_header fdt;\n+\tint padlen = 0;\n+\n+\tfor (i = 0; i < ARRAY_SIZE(version_table); i++) {\n+\t\tif (version_table[i].version == version)\n+\t\t\tvi = &version_table[i];\n+\t}\n+\tif (!vi)\n+\t\tdie(\"Unknown device tree blob version %d\\n\", version);\n+\n+\tflatten_tree(dti->dt, &bin_emitter, &dtbuf, &strbuf, vi);\n+\tbin_emit_cell(&dtbuf, FDT_END);\n+\n+\treservebuf = flatten_reserve_list(dti->reservelist, vi);\n+\n+\t/* Make header */\n+\tmake_fdt_header(&fdt, vi, reservebuf.len, dtbuf.len, strbuf.len,\n+\t\t\tdti->boot_cpuid_phys);\n+\n+\t/*\n+\t * If the user asked for more space than is used, adjust the totalsize.\n+\t */\n+\tif (minsize > 0) {\n+\t\tpadlen = minsize - fdt32_to_cpu(fdt.totalsize);\n+\t\tif (padlen < 0) {\n+\t\t\tpadlen = 0;\n+\t\t\tif (quiet < 1)\n+\t\t\t\tfprintf(stderr,\n+\t\t\t\t\t\"Warning: blob size %d >= minimum size %d\\n\",\n+\t\t\t\t\tfdt32_to_cpu(fdt.totalsize), minsize);\n+\t\t}\n+\t}\n+\n+\tif (padsize > 0)\n+\t\tpadlen = padsize;\n+\n+\tif (alignsize > 0)\n+\t\tpadlen = ALIGN(fdt32_to_cpu(fdt.totalsize) + padlen, alignsize)\n+\t\t\t- fdt32_to_cpu(fdt.totalsize);\n+\n+\tif (padlen > 0) {\n+\t\tint tsize = fdt32_to_cpu(fdt.totalsize);\n+\t\ttsize += padlen;\n+\t\tfdt.totalsize = cpu_to_fdt32(tsize);\n+\t}\n+\n+\t/*\n+\t * Assemble the blob: start with the header, add with alignment\n+\t * the reserve buffer, add the reserve map terminating zeroes,\n+\t * the device tree itself, and finally the strings.\n+\t */\n+\tblob = data_append_data(blob, &fdt, vi->hdr_size);\n+\tblob = data_append_align(blob, 8);\n+\tblob = data_merge(blob, reservebuf);\n+\tblob = data_append_zeroes(blob, sizeof(struct fdt_reserve_entry));\n+\tblob = data_merge(blob, dtbuf);\n+\tblob = data_merge(blob, strbuf);\n+\n+\t/*\n+\t * If the user asked for more space than is used, pad out the blob.\n+\t */\n+\tif (padlen > 0)\n+\t\tblob = data_append_zeroes(blob, padlen);\n+\n+\tif (fwrite(blob.val, blob.len, 1, f) != 1) {\n+\t\tif (ferror(f))\n+\t\t\tdie(\"Error writing device tree blob: %s\\n\",\n+\t\t\t strerror(errno));\n+\t\telse\n+\t\t\tdie(\"Short write on device tree blob\\n\");\n+\t}\n+\n+\t/*\n+\t * data_merge() frees the right-hand element so only the blob\n+\t * remains to be freed.\n+\t */\n+\tdata_free(blob);\n+}\n+\n+static void dump_stringtable_asm(FILE *f, struct data strbuf)\n+{\n+\tconst char *p;\n+\tint len;\n+\n+\tp = strbuf.val;\n+\n+\twhile (p < (strbuf.val + strbuf.len)) {\n+\t\tlen = strlen(p);\n+\t\tfprintf(f, \"\\t.string \\\"%s\\\"\\n\", p);\n+\t\tp += len+1;\n+\t}\n+}\n+\n+void dt_to_asm(FILE *f, struct dt_info *dti, int version)\n+{\n+\tstruct version_info *vi = NULL;\n+\tint i;\n+\tstruct data strbuf = empty_data;\n+\tstruct reserve_info *re;\n+\tconst char *symprefix = \"dt\";\n+\n+\tfor (i = 0; i < ARRAY_SIZE(version_table); i++) {\n+\t\tif (version_table[i].version == version)\n+\t\t\tvi = &version_table[i];\n+\t}\n+\tif (!vi)\n+\t\tdie(\"Unknown device tree blob version %d\\n\", version);\n+\n+\tfprintf(f, \"/* autogenerated by dtc, do not edit */\\n\\n\");\n+\n+\temit_label(f, symprefix, \"blob_start\");\n+\temit_label(f, symprefix, \"header\");\n+\tfprintf(f, \"\\t/* magic */\\n\");\n+\tasm_emit_cell(f, FDT_MAGIC);\n+\tfprintf(f, \"\\t/* totalsize */\\n\");\n+\tASM_EMIT_BELONG(f, \"_%s_blob_abs_end - _%s_blob_start\",\n+\t\t\tsymprefix, symprefix);\n+\tfprintf(f, \"\\t/* off_dt_struct */\\n\");\n+\tASM_EMIT_BELONG(f, \"_%s_struct_start - _%s_blob_start\",\n+\t\tsymprefix, symprefix);\n+\tfprintf(f, \"\\t/* off_dt_strings */\\n\");\n+\tASM_EMIT_BELONG(f, \"_%s_strings_start - _%s_blob_start\",\n+\t\tsymprefix, symprefix);\n+\tfprintf(f, \"\\t/* off_mem_rsvmap */\\n\");\n+\tASM_EMIT_BELONG(f, \"_%s_reserve_map - _%s_blob_start\",\n+\t\tsymprefix, symprefix);\n+\tfprintf(f, \"\\t/* version */\\n\");\n+\tasm_emit_cell(f, vi->version);\n+\tfprintf(f, \"\\t/* last_comp_version */\\n\");\n+\tasm_emit_cell(f, vi->last_comp_version);\n+\n+\tif (vi->flags & FTF_BOOTCPUID) {\n+\t\tfprintf(f, \"\\t/* boot_cpuid_phys */\\n\");\n+\t\tasm_emit_cell(f, dti->boot_cpuid_phys);\n+\t}\n+\n+\tif (vi->flags & FTF_STRTABSIZE) {\n+\t\tfprintf(f, \"\\t/* size_dt_strings */\\n\");\n+\t\tASM_EMIT_BELONG(f, \"_%s_strings_end - _%s_strings_start\",\n+\t\t\t\tsymprefix, symprefix);\n+\t}\n+\n+\tif (vi->flags & FTF_STRUCTSIZE) {\n+\t\tfprintf(f, \"\\t/* size_dt_struct */\\n\");\n+\t\tASM_EMIT_BELONG(f, \"_%s_struct_end - _%s_struct_start\",\n+\t\t\tsymprefix, symprefix);\n+\t}\n+\n+\t/*\n+\t * Reserve map entries.\n+\t * Align the reserve map to a doubleword boundary.\n+\t * Each entry is an (address, size) pair of u64 values.\n+\t * Always supply a zero-sized temination entry.\n+\t */\n+\tasm_emit_align(f, 8);\n+\temit_label(f, symprefix, \"reserve_map\");\n+\n+\tfprintf(f, \"/* Memory reserve map from source file */\\n\");\n+\n+\t/*\n+\t * Use .long on high and low halfs of u64s to avoid .quad\n+\t * as it appears .quad isn't available in some assemblers.\n+\t */\n+\tfor (re = dti->reservelist; re; re = re->next) {\n+\t\tstruct label *l;\n+\n+\t\tfor_each_label(re->labels, l) {\n+\t\t\tfprintf(f, \"\\t.globl\\t%s\\n\", l->label);\n+\t\t\tfprintf(f, \"%s:\\n\", l->label);\n+\t\t}\n+\t\tASM_EMIT_BELONG(f, \"0x%08x\", (unsigned int)(re->re.address >> 32));\n+\t\tASM_EMIT_BELONG(f, \"0x%08x\",\n+\t\t\t\t(unsigned int)(re->re.address & 0xffffffff));\n+\t\tASM_EMIT_BELONG(f, \"0x%08x\", (unsigned int)(re->re.size >> 32));\n+\t\tASM_EMIT_BELONG(f, \"0x%08x\", (unsigned int)(re->re.size & 0xffffffff));\n+\t}\n+\tfor (i = 0; i < reservenum; i++) {\n+\t\tfprintf(f, \"\\t.long\\t0, 0\\n\\t.long\\t0, 0\\n\");\n+\t}\n+\n+\tfprintf(f, \"\\t.long\\t0, 0\\n\\t.long\\t0, 0\\n\");\n+\n+\temit_label(f, symprefix, \"struct_start\");\n+\tflatten_tree(dti->dt, &asm_emitter, f, &strbuf, vi);\n+\n+\tfprintf(f, \"\\t/* FDT_END */\\n\");\n+\tasm_emit_cell(f, FDT_END);\n+\temit_label(f, symprefix, \"struct_end\");\n+\n+\temit_label(f, symprefix, \"strings_start\");\n+\tdump_stringtable_asm(f, strbuf);\n+\temit_label(f, symprefix, \"strings_end\");\n+\n+\temit_label(f, symprefix, \"blob_end\");\n+\n+\t/*\n+\t * If the user asked for more space than is used, pad it out.\n+\t */\n+\tif (minsize > 0) {\n+\t\tfprintf(f, \"\\t.space\\t%d - (_%s_blob_end - _%s_blob_start), 0\\n\",\n+\t\t\tminsize, symprefix, symprefix);\n+\t}\n+\tif (padsize > 0) {\n+\t\tfprintf(f, \"\\t.space\\t%d, 0\\n\", padsize);\n+\t}\n+\tif (alignsize > 0)\n+\t\tasm_emit_align(f, alignsize);\n+\temit_label(f, symprefix, \"blob_abs_end\");\n+\n+\tdata_free(strbuf);\n+}\n+\n+struct inbuf {\n+\tchar *base, *limit, *ptr;\n+};\n+\n+static void inbuf_init(struct inbuf *inb, void *base, void *limit)\n+{\n+\tinb->base = base;\n+\tinb->limit = limit;\n+\tinb->ptr = inb->base;\n+}\n+\n+static void flat_read_chunk(struct inbuf *inb, void *p, int len)\n+{\n+\tif ((inb->ptr + len) > inb->limit)\n+\t\tdie(\"Premature end of data parsing flat device tree\\n\");\n+\n+\tmemcpy(p, inb->ptr, len);\n+\n+\tinb->ptr += len;\n+}\n+\n+static uint32_t flat_read_word(struct inbuf *inb)\n+{\n+\tuint32_t val;\n+\n+\tassert(((inb->ptr - inb->base) % sizeof(val)) == 0);\n+\n+\tflat_read_chunk(inb, &val, sizeof(val));\n+\n+\treturn fdt32_to_cpu(val);\n+}\n+\n+static void flat_realign(struct inbuf *inb, int align)\n+{\n+\tint off = inb->ptr - inb->base;\n+\n+\tinb->ptr = inb->base + ALIGN(off, align);\n+\tif (inb->ptr > inb->limit)\n+\t\tdie(\"Premature end of data parsing flat device tree\\n\");\n+}\n+\n+static char *flat_read_string(struct inbuf *inb)\n+{\n+\tint len = 0;\n+\tconst char *p = inb->ptr;\n+\tchar *str;\n+\n+\tdo {\n+\t\tif (p >= inb->limit)\n+\t\t\tdie(\"Premature end of data parsing flat device tree\\n\");\n+\t\tlen++;\n+\t} while ((*p++) != '\\0');\n+\n+\tstr = xstrdup(inb->ptr);\n+\n+\tinb->ptr += len;\n+\n+\tflat_realign(inb, sizeof(uint32_t));\n+\n+\treturn str;\n+}\n+\n+static struct data flat_read_data(struct inbuf *inb, int len)\n+{\n+\tstruct data d = empty_data;\n+\n+\tif (len == 0)\n+\t\treturn empty_data;\n+\n+\td = data_grow_for(d, len);\n+\td.len = len;\n+\n+\tflat_read_chunk(inb, d.val, len);\n+\n+\tflat_realign(inb, sizeof(uint32_t));\n+\n+\treturn d;\n+}\n+\n+static char *flat_read_stringtable(struct inbuf *inb, int offset)\n+{\n+\tconst char *p;\n+\n+\tp = inb->base + offset;\n+\twhile (1) {\n+\t\tif (p >= inb->limit || p < inb->base)\n+\t\t\tdie(\"String offset %d overruns string table\\n\",\n+\t\t\t offset);\n+\n+\t\tif (*p == '\\0')\n+\t\t\tbreak;\n+\n+\t\tp++;\n+\t}\n+\n+\treturn xstrdup(inb->base + offset);\n+}\n+\n+static struct property *flat_read_property(struct inbuf *dtbuf,\n+\t\t\t\t\t struct inbuf *strbuf, int flags)\n+{\n+\tuint32_t proplen, stroff;\n+\tchar *name;\n+\tstruct data val;\n+\n+\tproplen = flat_read_word(dtbuf);\n+\tstroff = flat_read_word(dtbuf);\n+\n+\tname = flat_read_stringtable(strbuf, stroff);\n+\n+\tif ((flags & FTF_VARALIGN) && (proplen >= 8))\n+\t\tflat_realign(dtbuf, 8);\n+\n+\tval = flat_read_data(dtbuf, proplen);\n+\n+\treturn build_property(name, val);\n+}\n+\n+\n+static struct reserve_info *flat_read_mem_reserve(struct inbuf *inb)\n+{\n+\tstruct reserve_info *reservelist = NULL;\n+\tstruct reserve_info *new;\n+\tstruct fdt_reserve_entry re;\n+\n+\t/*\n+\t * Each entry is a pair of u64 (addr, size) values for 4 cell_t's.\n+\t * List terminates at an entry with size equal to zero.\n+\t *\n+\t * First pass, count entries.\n+\t */\n+\twhile (1) {\n+\t\tflat_read_chunk(inb, &re, sizeof(re));\n+\t\tre.address = fdt64_to_cpu(re.address);\n+\t\tre.size = fdt64_to_cpu(re.size);\n+\t\tif (re.size == 0)\n+\t\t\tbreak;\n+\n+\t\tnew = build_reserve_entry(re.address, re.size);\n+\t\treservelist = add_reserve_entry(reservelist, new);\n+\t}\n+\n+\treturn reservelist;\n+}\n+\n+\n+static char *nodename_from_path(const char *ppath, const char *cpath)\n+{\n+\tint plen;\n+\n+\tplen = strlen(ppath);\n+\n+\tif (!strneq(ppath, cpath, plen))\n+\t\tdie(\"Path \\\"%s\\\" is not valid as a child of \\\"%s\\\"\\n\",\n+\t\t cpath, ppath);\n+\n+\t/* root node is a special case */\n+\tif (!streq(ppath, \"/\"))\n+\t\tplen++;\n+\n+\treturn xstrdup(cpath + plen);\n+}\n+\n+static struct node *unflatten_tree(struct inbuf *dtbuf,\n+\t\t\t\t struct inbuf *strbuf,\n+\t\t\t\t const char *parent_flatname, int flags)\n+{\n+\tstruct node *node;\n+\tchar *flatname;\n+\tuint32_t val;\n+\n+\tnode = build_node(NULL, NULL);\n+\n+\tflatname = flat_read_string(dtbuf);\n+\n+\tif (flags & FTF_FULLPATH)\n+\t\tnode->name = nodename_from_path(parent_flatname, flatname);\n+\telse\n+\t\tnode->name = flatname;\n+\n+\tdo {\n+\t\tstruct property *prop;\n+\t\tstruct node *child;\n+\n+\t\tval = flat_read_word(dtbuf);\n+\t\tswitch (val) {\n+\t\tcase FDT_PROP:\n+\t\t\tif (node->children)\n+\t\t\t\tfprintf(stderr, \"Warning: Flat tree input has \"\n+\t\t\t\t\t\"subnodes preceding a property.\\n\");\n+\t\t\tprop = flat_read_property(dtbuf, strbuf, flags);\n+\t\t\tadd_property(node, prop);\n+\t\t\tbreak;\n+\n+\t\tcase FDT_BEGIN_NODE:\n+\t\t\tchild = unflatten_tree(dtbuf,strbuf, flatname, flags);\n+\t\t\tadd_child(node, child);\n+\t\t\tbreak;\n+\n+\t\tcase FDT_END_NODE:\n+\t\t\tbreak;\n+\n+\t\tcase FDT_END:\n+\t\t\tdie(\"Premature FDT_END in device tree blob\\n\");\n+\t\t\tbreak;\n+\n+\t\tcase FDT_NOP:\n+\t\t\tif (!(flags & FTF_NOPS))\n+\t\t\t\tfprintf(stderr, \"Warning: NOP tag found in flat tree\"\n+\t\t\t\t\t\" version <16\\n\");\n+\n+\t\t\t/* Ignore */\n+\t\t\tbreak;\n+\n+\t\tdefault:\n+\t\t\tdie(\"Invalid opcode word %08x in device tree blob\\n\",\n+\t\t\t val);\n+\t\t}\n+\t} while (val != FDT_END_NODE);\n+\n+\tif (node->name != flatname) {\n+\t\tfree(flatname);\n+\t}\n+\n+\treturn node;\n+}\n+\n+\n+struct dt_info *dt_from_blob(const char *fname)\n+{\n+\tFILE *f;\n+\tuint32_t magic, totalsize, version, size_dt, boot_cpuid_phys;\n+\tuint32_t off_dt, off_str, off_mem_rsvmap;\n+\tint rc;\n+\tchar *blob;\n+\tstruct fdt_header *fdt;\n+\tchar *p;\n+\tstruct inbuf dtbuf, strbuf;\n+\tstruct inbuf memresvbuf;\n+\tint sizeleft;\n+\tstruct reserve_info *reservelist;\n+\tstruct node *tree;\n+\tuint32_t val;\n+\tint flags = 0;\n+\n+\tf = srcfile_relative_open(fname, NULL);\n+\n+\trc = fread(&magic, sizeof(magic), 1, f);\n+\tif (ferror(f))\n+\t\tdie(\"Error reading DT blob magic number: %s\\n\",\n+\t\t strerror(errno));\n+\tif (rc < 1) {\n+\t\tif (feof(f))\n+\t\t\tdie(\"EOF reading DT blob magic number\\n\");\n+\t\telse\n+\t\t\tdie(\"Mysterious short read reading magic number\\n\");\n+\t}\n+\n+\tmagic = fdt32_to_cpu(magic);\n+\tif (magic != FDT_MAGIC)\n+\t\tdie(\"Blob has incorrect magic number\\n\");\n+\n+\trc = fread(&totalsize, sizeof(totalsize), 1, f);\n+\tif (ferror(f))\n+\t\tdie(\"Error reading DT blob size: %s\\n\", strerror(errno));\n+\tif (rc < 1) {\n+\t\tif (feof(f))\n+\t\t\tdie(\"EOF reading DT blob size\\n\");\n+\t\telse\n+\t\t\tdie(\"Mysterious short read reading blob size\\n\");\n+\t}\n+\n+\ttotalsize = fdt32_to_cpu(totalsize);\n+\tif (totalsize < FDT_V1_SIZE)\n+\t\tdie(\"DT blob size (%d) is too small\\n\", totalsize);\n+\n+\tblob = xmalloc(totalsize);\n+\n+\tfdt = (struct fdt_header *)blob;\n+\tfdt->magic = cpu_to_fdt32(magic);\n+\tfdt->totalsize = cpu_to_fdt32(totalsize);\n+\n+\tsizeleft = totalsize - sizeof(magic) - sizeof(totalsize);\n+\tp = blob + sizeof(magic) + sizeof(totalsize);\n+\n+\twhile (sizeleft) {\n+\t\tif (feof(f))\n+\t\t\tdie(\"EOF before reading %d bytes of DT blob\\n\",\n+\t\t\t totalsize);\n+\n+\t\trc = fread(p, 1, sizeleft, f);\n+\t\tif (ferror(f))\n+\t\t\tdie(\"Error reading DT blob: %s\\n\",\n+\t\t\t strerror(errno));\n+\n+\t\tsizeleft -= rc;\n+\t\tp += rc;\n+\t}\n+\n+\toff_dt = fdt32_to_cpu(fdt->off_dt_struct);\n+\toff_str = fdt32_to_cpu(fdt->off_dt_strings);\n+\toff_mem_rsvmap = fdt32_to_cpu(fdt->off_mem_rsvmap);\n+\tversion = fdt32_to_cpu(fdt->version);\n+\tboot_cpuid_phys = fdt32_to_cpu(fdt->boot_cpuid_phys);\n+\n+\tif (off_mem_rsvmap >= totalsize)\n+\t\tdie(\"Mem Reserve structure offset exceeds total size\\n\");\n+\n+\tif (off_dt >= totalsize)\n+\t\tdie(\"DT structure offset exceeds total size\\n\");\n+\n+\tif (off_str > totalsize)\n+\t\tdie(\"String table offset exceeds total size\\n\");\n+\n+\tif (version >= 3) {\n+\t\tuint32_t size_str = fdt32_to_cpu(fdt->size_dt_strings);\n+\t\tif ((off_str+size_str < off_str) || (off_str+size_str > totalsize))\n+\t\t\tdie(\"String table extends past total size\\n\");\n+\t\tinbuf_init(&strbuf, blob + off_str, blob + off_str + size_str);\n+\t} else {\n+\t\tinbuf_init(&strbuf, blob + off_str, blob + totalsize);\n+\t}\n+\n+\tif (version >= 17) {\n+\t\tsize_dt = fdt32_to_cpu(fdt->size_dt_struct);\n+\t\tif ((off_dt+size_dt < off_dt) || (off_dt+size_dt > totalsize))\n+\t\t\tdie(\"Structure block extends past total size\\n\");\n+\t}\n+\n+\tif (version < 16) {\n+\t\tflags |= FTF_FULLPATH | FTF_NAMEPROPS | FTF_VARALIGN;\n+\t} else {\n+\t\tflags |= FTF_NOPS;\n+\t}\n+\n+\tinbuf_init(&memresvbuf,\n+\t\t blob + off_mem_rsvmap, blob + totalsize);\n+\tinbuf_init(&dtbuf, blob + off_dt, blob + totalsize);\n+\n+\treservelist = flat_read_mem_reserve(&memresvbuf);\n+\n+\tval = flat_read_word(&dtbuf);\n+\n+\tif (val != FDT_BEGIN_NODE)\n+\t\tdie(\"Device tree blob doesn't begin with FDT_BEGIN_NODE (begins with 0x%08x)\\n\", val);\n+\n+\ttree = unflatten_tree(&dtbuf, &strbuf, \"\", flags);\n+\n+\tval = flat_read_word(&dtbuf);\n+\tif (val != FDT_END)\n+\t\tdie(\"Device tree blob doesn't end with FDT_END\\n\");\n+\n+\tfree(blob);\n+\n+\tfclose(f);\n+\n+\treturn build_dt_info(DTSF_V1, reservelist, tree, boot_cpuid_phys);\n+}\ndiff --git a/scripts/dtc/fstree.c b/scripts/dtc/fstree.c\nnew file mode 100644\nindex 000000000000..ae7d06c3c492\n--- /dev/null\n+++ b/scripts/dtc/fstree.c\n@@ -0,0 +1,90 @@\n+/*\n+ * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.\n+ *\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License as\n+ * published by the Free Software Foundation; either version 2 of the\n+ * License, or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\n+ * USA\n+ */\n+\n+#include \"dtc.h\"\n+\n+#include <dirent.h>\n+#include <sys/stat.h>\n+\n+static struct node *read_fstree(const char *dirname)\n+{\n+\tDIR *d;\n+\tstruct dirent *de;\n+\tstruct stat st;\n+\tstruct node *tree;\n+\n+\td = opendir(dirname);\n+\tif (!d)\n+\t\tdie(\"Couldn't opendir() \\\"%s\\\": %s\\n\", dirname, strerror(errno));\n+\n+\ttree = build_node(NULL, NULL);\n+\n+\twhile ((de = readdir(d)) != NULL) {\n+\t\tchar *tmpname;\n+\n+\t\tif (streq(de->d_name, \".\")\n+\t\t || streq(de->d_name, \"..\"))\n+\t\t\tcontinue;\n+\n+\t\ttmpname = join_path(dirname, de->d_name);\n+\n+\t\tif (lstat(tmpname, &st) < 0)\n+\t\t\tdie(\"stat(%s): %s\\n\", tmpname, strerror(errno));\n+\n+\t\tif (S_ISREG(st.st_mode)) {\n+\t\t\tstruct property *prop;\n+\t\t\tFILE *pfile;\n+\n+\t\t\tpfile = fopen(tmpname, \"rb\");\n+\t\t\tif (! pfile) {\n+\t\t\t\tfprintf(stderr,\n+\t\t\t\t\t\"WARNING: Cannot open %s: %s\\n\",\n+\t\t\t\t\ttmpname, strerror(errno));\n+\t\t\t} else {\n+\t\t\t\tprop = build_property(xstrdup(de->d_name),\n+\t\t\t\t\t\t data_copy_file(pfile,\n+\t\t\t\t\t\t\t\t st.st_size));\n+\t\t\t\tadd_property(tree, prop);\n+\t\t\t\tfclose(pfile);\n+\t\t\t}\n+\t\t} else if (S_ISDIR(st.st_mode)) {\n+\t\t\tstruct node *newchild;\n+\n+\t\t\tnewchild = read_fstree(tmpname);\n+\t\t\tnewchild = name_node(newchild, xstrdup(de->d_name));\n+\t\t\tadd_child(tree, newchild);\n+\t\t}\n+\n+\t\tfree(tmpname);\n+\t}\n+\n+\tclosedir(d);\n+\treturn tree;\n+}\n+\n+struct dt_info *dt_from_fs(const char *dirname)\n+{\n+\tstruct node *tree;\n+\n+\ttree = read_fstree(dirname);\n+\ttree = name_node(tree, \"\");\n+\n+\treturn build_dt_info(DTSF_V1, NULL, tree, guess_boot_cpuid(tree));\n+}\ndiff --git a/scripts/dtc/libfdt/Makefile.libfdt b/scripts/dtc/libfdt/Makefile.libfdt\nnew file mode 100644\nindex 000000000000..098b3f36e668\n--- /dev/null\n+++ b/scripts/dtc/libfdt/Makefile.libfdt\n@@ -0,0 +1,11 @@\n+# Makefile.libfdt\n+#\n+# This is not a complete Makefile of itself. Instead, it is designed to\n+# be easily embeddable into other systems of Makefiles.\n+#\n+LIBFDT_soname = libfdt.$(SHAREDLIB_EXT).1\n+LIBFDT_INCLUDES = fdt.h libfdt.h libfdt_env.h\n+LIBFDT_VERSION = version.lds\n+LIBFDT_SRCS = fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c fdt_empty_tree.c \\\n+\tfdt_addresses.c fdt_overlay.c\n+LIBFDT_OBJS = $(LIBFDT_SRCS:%.c=%.o)\ndiff --git a/scripts/dtc/libfdt/fdt.c b/scripts/dtc/libfdt/fdt.c\nnew file mode 100644\nindex 000000000000..22286a1aaeaf\n--- /dev/null\n+++ b/scripts/dtc/libfdt/fdt.c\n@@ -0,0 +1,251 @@\n+/*\n+ * libfdt - Flat Device Tree manipulation\n+ * Copyright (C) 2006 David Gibson, IBM Corporation.\n+ *\n+ * libfdt is dual licensed: you can use it either under the terms of\n+ * the GPL, or the BSD license, at your option.\n+ *\n+ * a) This library is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License as\n+ * published by the Free Software Foundation; either version 2 of the\n+ * License, or (at your option) any later version.\n+ *\n+ * This library is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public\n+ * License along with this library; if not, write to the Free\n+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,\n+ * MA 02110-1301 USA\n+ *\n+ * Alternatively,\n+ *\n+ * b) Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * 1. Redistributions of source code must retain the above\n+ * copyright notice, this list of conditions and the following\n+ * disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above\n+ * copyright notice, this list of conditions and the following\n+ * disclaimer in the documentation and/or other materials\n+ * provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\n+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\n+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+#include \"libfdt_env.h\"\n+\n+#include <fdt.h>\n+#include <libfdt.h>\n+\n+#include \"libfdt_internal.h\"\n+\n+int fdt_check_header(const void *fdt)\n+{\n+\tif (fdt_magic(fdt) == FDT_MAGIC) {\n+\t\t/* Complete tree */\n+\t\tif (fdt_version(fdt) < FDT_FIRST_SUPPORTED_VERSION)\n+\t\t\treturn -FDT_ERR_BADVERSION;\n+\t\tif (fdt_last_comp_version(fdt) > FDT_LAST_SUPPORTED_VERSION)\n+\t\t\treturn -FDT_ERR_BADVERSION;\n+\t} else if (fdt_magic(fdt) == FDT_SW_MAGIC) {\n+\t\t/* Unfinished sequential-write blob */\n+\t\tif (fdt_size_dt_struct(fdt) == 0)\n+\t\t\treturn -FDT_ERR_BADSTATE;\n+\t} else {\n+\t\treturn -FDT_ERR_BADMAGIC;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len)\n+{\n+\tunsigned absoffset = offset + fdt_off_dt_struct(fdt);\n+\n+\tif ((absoffset < offset)\n+\t || ((absoffset + len) < absoffset)\n+\t || (absoffset + len) > fdt_totalsize(fdt))\n+\t\treturn NULL;\n+\n+\tif (fdt_version(fdt) >= 0x11)\n+\t\tif (((offset + len) < offset)\n+\t\t || ((offset + len) > fdt_size_dt_struct(fdt)))\n+\t\t\treturn NULL;\n+\n+\treturn _fdt_offset_ptr(fdt, offset);\n+}\n+\n+uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)\n+{\n+\tconst fdt32_t *tagp, *lenp;\n+\tuint32_t tag;\n+\tint offset = startoffset;\n+\tconst char *p;\n+\n+\t*nextoffset = -FDT_ERR_TRUNCATED;\n+\ttagp = fdt_offset_ptr(fdt, offset, FDT_TAGSIZE);\n+\tif (!tagp)\n+\t\treturn FDT_END; /* premature end */\n+\ttag = fdt32_to_cpu(*tagp);\n+\toffset += FDT_TAGSIZE;\n+\n+\t*nextoffset = -FDT_ERR_BADSTRUCTURE;\n+\tswitch (tag) {\n+\tcase FDT_BEGIN_NODE:\n+\t\t/* skip name */\n+\t\tdo {\n+\t\t\tp = fdt_offset_ptr(fdt, offset++, 1);\n+\t\t} while (p && (*p != '\\0'));\n+\t\tif (!p)\n+\t\t\treturn FDT_END; /* premature end */\n+\t\tbreak;\n+\n+\tcase FDT_PROP:\n+\t\tlenp = fdt_offset_ptr(fdt, offset, sizeof(*lenp));\n+\t\tif (!lenp)\n+\t\t\treturn FDT_END; /* premature end */\n+\t\t/* skip-name offset, length and value */\n+\t\toffset += sizeof(struct fdt_property) - FDT_TAGSIZE\n+\t\t\t+ fdt32_to_cpu(*lenp);\n+\t\tbreak;\n+\n+\tcase FDT_END:\n+\tcase FDT_END_NODE:\n+\tcase FDT_NOP:\n+\t\tbreak;\n+\n+\tdefault:\n+\t\treturn FDT_END;\n+\t}\n+\n+\tif (!fdt_offset_ptr(fdt, startoffset, offset - startoffset))\n+\t\treturn FDT_END; /* premature end */\n+\n+\t*nextoffset = FDT_TAGALIGN(offset);\n+\treturn tag;\n+}\n+\n+int _fdt_check_node_offset(const void *fdt, int offset)\n+{\n+\tif ((offset < 0) || (offset % FDT_TAGSIZE)\n+\t || (fdt_next_tag(fdt, offset, &offset) != FDT_BEGIN_NODE))\n+\t\treturn -FDT_ERR_BADOFFSET;\n+\n+\treturn offset;\n+}\n+\n+int _fdt_check_prop_offset(const void *fdt, int offset)\n+{\n+\tif ((offset < 0) || (offset % FDT_TAGSIZE)\n+\t || (fdt_next_tag(fdt, offset, &offset) != FDT_PROP))\n+\t\treturn -FDT_ERR_BADOFFSET;\n+\n+\treturn offset;\n+}\n+\n+int fdt_next_node(const void *fdt, int offset, int *depth)\n+{\n+\tint nextoffset = 0;\n+\tuint32_t tag;\n+\n+\tif (offset >= 0)\n+\t\tif ((nextoffset = _fdt_check_node_offset(fdt, offset)) < 0)\n+\t\t\treturn nextoffset;\n+\n+\tdo {\n+\t\toffset = nextoffset;\n+\t\ttag = fdt_next_tag(fdt, offset, &nextoffset);\n+\n+\t\tswitch (tag) {\n+\t\tcase FDT_PROP:\n+\t\tcase FDT_NOP:\n+\t\t\tbreak;\n+\n+\t\tcase FDT_BEGIN_NODE:\n+\t\t\tif (depth)\n+\t\t\t\t(*depth)++;\n+\t\t\tbreak;\n+\n+\t\tcase FDT_END_NODE:\n+\t\t\tif (depth && ((--(*depth)) < 0))\n+\t\t\t\treturn nextoffset;\n+\t\t\tbreak;\n+\n+\t\tcase FDT_END:\n+\t\t\tif ((nextoffset >= 0)\n+\t\t\t || ((nextoffset == -FDT_ERR_TRUNCATED) && !depth))\n+\t\t\t\treturn -FDT_ERR_NOTFOUND;\n+\t\t\telse\n+\t\t\t\treturn nextoffset;\n+\t\t}\n+\t} while (tag != FDT_BEGIN_NODE);\n+\n+\treturn offset;\n+}\n+\n+int fdt_first_subnode(const void *fdt, int offset)\n+{\n+\tint depth = 0;\n+\n+\toffset = fdt_next_node(fdt, offset, &depth);\n+\tif (offset < 0 || depth != 1)\n+\t\treturn -FDT_ERR_NOTFOUND;\n+\n+\treturn offset;\n+}\n+\n+int fdt_next_subnode(const void *fdt, int offset)\n+{\n+\tint depth = 1;\n+\n+\t/*\n+\t * With respect to the parent, the depth of the next subnode will be\n+\t * the same as the last.\n+\t */\n+\tdo {\n+\t\toffset = fdt_next_node(fdt, offset, &depth);\n+\t\tif (offset < 0 || depth < 1)\n+\t\t\treturn -FDT_ERR_NOTFOUND;\n+\t} while (depth > 1);\n+\n+\treturn offset;\n+}\n+\n+const char *_fdt_find_string(const char *strtab, int tabsize, const char *s)\n+{\n+\tint len = strlen(s) + 1;\n+\tconst char *last = strtab + tabsize - len;\n+\tconst char *p;\n+\n+\tfor (p = strtab; p <= last; p++)\n+\t\tif (memcmp(p, s, len) == 0)\n+\t\t\treturn p;\n+\treturn NULL;\n+}\n+\n+int fdt_move(const void *fdt, void *buf, int bufsize)\n+{\n+\tFDT_CHECK_HEADER(fdt);\n+\n+\tif (fdt_totalsize(fdt) > bufsize)\n+\t\treturn -FDT_ERR_NOSPACE;\n+\n+\tmemmove(buf, fdt, fdt_totalsize(fdt));\n+\treturn 0;\n+}\ndiff --git a/scripts/dtc/libfdt/fdt.h b/scripts/dtc/libfdt/fdt.h\nnew file mode 100644\nindex 000000000000..526aedb51556\n--- /dev/null\n+++ b/scripts/dtc/libfdt/fdt.h\n@@ -0,0 +1,111 @@\n+#ifndef _FDT_H\n+#define _FDT_H\n+/*\n+ * libfdt - Flat Device Tree manipulation\n+ * Copyright (C) 2006 David Gibson, IBM Corporation.\n+ * Copyright 2012 Kim Phillips, Freescale Semiconductor.\n+ *\n+ * libfdt is dual licensed: you can use it either under the terms of\n+ * the GPL, or the BSD license, at your option.\n+ *\n+ * a) This library is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License as\n+ * published by the Free Software Foundation; either version 2 of the\n+ * License, or (at your option) any later version.\n+ *\n+ * This library is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public\n+ * License along with this library; if not, write to the Free\n+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,\n+ * MA 02110-1301 USA\n+ *\n+ * Alternatively,\n+ *\n+ * b) Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * 1. Redistributions of source code must retain the above\n+ * copyright notice, this list of conditions and the following\n+ * disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above\n+ * copyright notice, this list of conditions and the following\n+ * disclaimer in the documentation and/or other materials\n+ * provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\n+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\n+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+#ifndef __ASSEMBLY__\n+\n+struct fdt_header {\n+\tfdt32_t magic;\t\t\t /* magic word FDT_MAGIC */\n+\tfdt32_t totalsize;\t\t /* total size of DT block */\n+\tfdt32_t off_dt_struct;\t\t /* offset to structure */\n+\tfdt32_t off_dt_strings;\t\t /* offset to strings */\n+\tfdt32_t off_mem_rsvmap;\t\t /* offset to memory reserve map */\n+\tfdt32_t version;\t\t /* format version */\n+\tfdt32_t last_comp_version;\t /* last compatible version */\n+\n+\t/* version 2 fields below */\n+\tfdt32_t boot_cpuid_phys;\t /* Which physical CPU id we're\n+\t\t\t\t\t booting on */\n+\t/* version 3 fields below */\n+\tfdt32_t size_dt_strings;\t /* size of the strings block */\n+\n+\t/* version 17 fields below */\n+\tfdt32_t size_dt_struct;\t\t /* size of the structure block */\n+};\n+\n+struct fdt_reserve_entry {\n+\tfdt64_t address;\n+\tfdt64_t size;\n+};\n+\n+struct fdt_node_header {\n+\tfdt32_t tag;\n+\tchar name[0];\n+};\n+\n+struct fdt_property {\n+\tfdt32_t tag;\n+\tfdt32_t len;\n+\tfdt32_t nameoff;\n+\tchar data[0];\n+};\n+\n+#endif /* !__ASSEMBLY */\n+\n+#define FDT_MAGIC\t0xd00dfeed\t/* 4: version, 4: total size */\n+#define FDT_TAGSIZE\tsizeof(fdt32_t)\n+\n+#define FDT_BEGIN_NODE\t0x1\t\t/* Start node: full name */\n+#define FDT_END_NODE\t0x2\t\t/* End node */\n+#define FDT_PROP\t0x3\t\t/* Property: name off,\n+\t\t\t\t\t size, content */\n+#define FDT_NOP\t\t0x4\t\t/* nop */\n+#define FDT_END\t\t0x9\n+\n+#define FDT_V1_SIZE\t(7*sizeof(fdt32_t))\n+#define FDT_V2_SIZE\t(FDT_V1_SIZE + sizeof(fdt32_t))\n+#define FDT_V3_SIZE\t(FDT_V2_SIZE + sizeof(fdt32_t))\n+#define FDT_V16_SIZE\tFDT_V3_SIZE\n+#define FDT_V17_SIZE\t(FDT_V16_SIZE + sizeof(fdt32_t))\n+\n+#endif /* _FDT_H */\ndiff --git a/scripts/dtc/libfdt/fdt_empty_tree.c b/scripts/dtc/libfdt/fdt_empty_tree.c\nnew file mode 100644\nindex 000000000000..f72d13b1d19c\n--- /dev/null\n+++ b/scripts/dtc/libfdt/fdt_empty_tree.c\n@@ -0,0 +1,84 @@\n+/*\n+ * libfdt - Flat Device Tree manipulation\n+ * Copyright (C) 2012 David Gibson, IBM Corporation.\n+ *\n+ * libfdt is dual licensed: you can use it either under the terms of\n+ * the GPL, or the BSD license, at your option.\n+ *\n+ * a) This library is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License as\n+ * published by the Free Software Foundation; either version 2 of the\n+ * License, or (at your option) any later version.\n+ *\n+ * This library is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public\n+ * License along with this library; if not, write to the Free\n+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,\n+ * MA 02110-1301 USA\n+ *\n+ * Alternatively,\n+ *\n+ * b) Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * 1. Redistributions of source code must retain the above\n+ * copyright notice, this list of conditions and the following\n+ * disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above\n+ * copyright notice, this list of conditions and the following\n+ * disclaimer in the documentation and/or other materials\n+ * provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\n+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\n+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+#include \"libfdt_env.h\"\n+\n+#include <fdt.h>\n+#include <libfdt.h>\n+\n+#include \"libfdt_internal.h\"\n+\n+int fdt_create_empty_tree(void *buf, int bufsize)\n+{\n+\tint err;\n+\n+\terr = fdt_create(buf, bufsize);\n+\tif (err)\n+\t\treturn err;\n+\n+\terr = fdt_finish_reservemap(buf);\n+\tif (err)\n+\t\treturn err;\n+\n+\terr = fdt_begin_node(buf, \"\");\n+\tif (err)\n+\t\treturn err;\n+\n+\terr = fdt_end_node(buf);\n+\tif (err)\n+\t\treturn err;\n+\n+\terr = fdt_finish(buf);\n+\tif (err)\n+\t\treturn err;\n+\n+\treturn fdt_open_into(buf, buf, bufsize);\n+}\n+\ndiff --git a/scripts/dtc/libfdt/fdt_ro.c b/scripts/dtc/libfdt/fdt_ro.c\nnew file mode 100644\nindex 000000000000..3d00d2eee0e3\n--- /dev/null\n+++ b/scripts/dtc/libfdt/fdt_ro.c\n@@ -0,0 +1,703 @@\n+/*\n+ * libfdt - Flat Device Tree manipulation\n+ * Copyright (C) 2006 David Gibson, IBM Corporation.\n+ *\n+ * libfdt is dual licensed: you can use it either under the terms of\n+ * the GPL, or the BSD license, at your option.\n+ *\n+ * a) This library is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License as\n+ * published by the Free Software Foundation; either version 2 of the\n+ * License, or (at your option) any later version.\n+ *\n+ * This library is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public\n+ * License along with this library; if not, write to the Free\n+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,\n+ * MA 02110-1301 USA\n+ *\n+ * Alternatively,\n+ *\n+ * b) Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * 1. Redistributions of source code must retain the above\n+ * copyright notice, this list of conditions and the following\n+ * disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above\n+ * copyright notice, this list of conditions and the following\n+ * disclaimer in the documentation and/or other materials\n+ * provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\n+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\n+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+#include \"libfdt_env.h\"\n+\n+#include <fdt.h>\n+#include <libfdt.h>\n+\n+#include \"libfdt_internal.h\"\n+\n+static int _fdt_nodename_eq(const void *fdt, int offset,\n+\t\t\t const char *s, int len)\n+{\n+\tconst char *p = fdt_offset_ptr(fdt, offset + FDT_TAGSIZE, len+1);\n+\n+\tif (! p)\n+\t\t/* short match */\n+\t\treturn 0;\n+\n+\tif (memcmp(p, s, len) != 0)\n+\t\treturn 0;\n+\n+\tif (p[len] == '\\0')\n+\t\treturn 1;\n+\telse if (!memchr(s, '@', len) && (p[len] == '@'))\n+\t\treturn 1;\n+\telse\n+\t\treturn 0;\n+}\n+\n+const char *fdt_string(const void *fdt, int stroffset)\n+{\n+\treturn (const char *)fdt + fdt_off_dt_strings(fdt) + stroffset;\n+}\n+\n+static int _fdt_string_eq(const void *fdt, int stroffset,\n+\t\t\t const char *s, int len)\n+{\n+\tconst char *p = fdt_string(fdt, stroffset);\n+\n+\treturn (strlen(p) == len) && (memcmp(p, s, len) == 0);\n+}\n+\n+uint32_t fdt_get_max_phandle(const void *fdt)\n+{\n+\tuint32_t max_phandle = 0;\n+\tint offset;\n+\n+\tfor (offset = fdt_next_node(fdt, -1, NULL);;\n+\t offset = fdt_next_node(fdt, offset, NULL)) {\n+\t\tuint32_t phandle;\n+\n+\t\tif (offset == -FDT_ERR_NOTFOUND)\n+\t\t\treturn max_phandle;\n+\n+\t\tif (offset < 0)\n+\t\t\treturn (uint32_t)-1;\n+\n+\t\tphandle = fdt_get_phandle(fdt, offset);\n+\t\tif (phandle == (uint32_t)-1)\n+\t\t\tcontinue;\n+\n+\t\tif (phandle > max_phandle)\n+\t\t\tmax_phandle = phandle;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size)\n+{\n+\tFDT_CHECK_HEADER(fdt);\n+\t*address = fdt64_to_cpu(_fdt_mem_rsv(fdt, n)->address);\n+\t*size = fdt64_to_cpu(_fdt_mem_rsv(fdt, n)->size);\n+\treturn 0;\n+}\n+\n+int fdt_num_mem_rsv(const void *fdt)\n+{\n+\tint i = 0;\n+\n+\twhile (fdt64_to_cpu(_fdt_mem_rsv(fdt, i)->size) != 0)\n+\t\ti++;\n+\treturn i;\n+}\n+\n+static int _nextprop(const void *fdt, int offset)\n+{\n+\tuint32_t tag;\n+\tint nextoffset;\n+\n+\tdo {\n+\t\ttag = fdt_next_tag(fdt, offset, &nextoffset);\n+\n+\t\tswitch (tag) {\n+\t\tcase FDT_END:\n+\t\t\tif (nextoffset >= 0)\n+\t\t\t\treturn -FDT_ERR_BADSTRUCTURE;\n+\t\t\telse\n+\t\t\t\treturn nextoffset;\n+\n+\t\tcase FDT_PROP:\n+\t\t\treturn offset;\n+\t\t}\n+\t\toffset = nextoffset;\n+\t} while (tag == FDT_NOP);\n+\n+\treturn -FDT_ERR_NOTFOUND;\n+}\n+\n+int fdt_subnode_offset_namelen(const void *fdt, int offset,\n+\t\t\t const char *name, int namelen)\n+{\n+\tint depth;\n+\n+\tFDT_CHECK_HEADER(fdt);\n+\n+\tfor (depth = 0;\n+\t (offset >= 0) && (depth >= 0);\n+\t offset = fdt_next_node(fdt, offset, &depth))\n+\t\tif ((depth == 1)\n+\t\t && _fdt_nodename_eq(fdt, offset, name, namelen))\n+\t\t\treturn offset;\n+\n+\tif (depth < 0)\n+\t\treturn -FDT_ERR_NOTFOUND;\n+\treturn offset; /* error */\n+}\n+\n+int fdt_subnode_offset(const void *fdt, int parentoffset,\n+\t\t const char *name)\n+{\n+\treturn fdt_subnode_offset_namelen(fdt, parentoffset, name, strlen(name));\n+}\n+\n+int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen)\n+{\n+\tconst char *end = path + namelen;\n+\tconst char *p = path;\n+\tint offset = 0;\n+\n+\tFDT_CHECK_HEADER(fdt);\n+\n+\t/* see if we have an alias */\n+\tif (*path != '/') {\n+\t\tconst char *q = memchr(path, '/', end - p);\n+\n+\t\tif (!q)\n+\t\t\tq = end;\n+\n+\t\tp = fdt_get_alias_namelen(fdt, p, q - p);\n+\t\tif (!p)\n+\t\t\treturn -FDT_ERR_BADPATH;\n+\t\toffset = fdt_path_offset(fdt, p);\n+\n+\t\tp = q;\n+\t}\n+\n+\twhile (p < end) {\n+\t\tconst char *q;\n+\n+\t\twhile (*p == '/') {\n+\t\t\tp++;\n+\t\t\tif (p == end)\n+\t\t\t\treturn offset;\n+\t\t}\n+\t\tq = memchr(p, '/', end - p);\n+\t\tif (! q)\n+\t\t\tq = end;\n+\n+\t\toffset = fdt_subnode_offset_namelen(fdt, offset, p, q-p);\n+\t\tif (offset < 0)\n+\t\t\treturn offset;\n+\n+\t\tp = q;\n+\t}\n+\n+\treturn offset;\n+}\n+\n+int fdt_path_offset(const void *fdt, const char *path)\n+{\n+\treturn fdt_path_offset_namelen(fdt, path, strlen(path));\n+}\n+\n+const char *fdt_get_name(const void *fdt, int nodeoffset, int *len)\n+{\n+\tconst struct fdt_node_header *nh = _fdt_offset_ptr(fdt, nodeoffset);\n+\tint err;\n+\n+\tif (((err = fdt_check_header(fdt)) != 0)\n+\t || ((err = _fdt_check_node_offset(fdt, nodeoffset)) < 0))\n+\t\t\tgoto fail;\n+\n+\tif (len)\n+\t\t*len = strlen(nh->name);\n+\n+\treturn nh->name;\n+\n+ fail:\n+\tif (len)\n+\t\t*len = err;\n+\treturn NULL;\n+}\n+\n+int fdt_first_property_offset(const void *fdt, int nodeoffset)\n+{\n+\tint offset;\n+\n+\tif ((offset = _fdt_check_node_offset(fdt, nodeoffset)) < 0)\n+\t\treturn offset;\n+\n+\treturn _nextprop(fdt, offset);\n+}\n+\n+int fdt_next_property_offset(const void *fdt, int offset)\n+{\n+\tif ((offset = _fdt_check_prop_offset(fdt, offset)) < 0)\n+\t\treturn offset;\n+\n+\treturn _nextprop(fdt, offset);\n+}\n+\n+const struct fdt_property *fdt_get_property_by_offset(const void *fdt,\n+\t\t\t\t\t\t int offset,\n+\t\t\t\t\t\t int *lenp)\n+{\n+\tint err;\n+\tconst struct fdt_property *prop;\n+\n+\tif ((err = _fdt_check_prop_offset(fdt, offset)) < 0) {\n+\t\tif (lenp)\n+\t\t\t*lenp = err;\n+\t\treturn NULL;\n+\t}\n+\n+\tprop = _fdt_offset_ptr(fdt, offset);\n+\n+\tif (lenp)\n+\t\t*lenp = fdt32_to_cpu(prop->len);\n+\n+\treturn prop;\n+}\n+\n+const struct fdt_property *fdt_get_property_namelen(const void *fdt,\n+\t\t\t\t\t\t int offset,\n+\t\t\t\t\t\t const char *name,\n+\t\t\t\t\t\t int namelen, int *lenp)\n+{\n+\tfor (offset = fdt_first_property_offset(fdt, offset);\n+\t (offset >= 0);\n+\t (offset = fdt_next_property_offset(fdt, offset))) {\n+\t\tconst struct fdt_property *prop;\n+\n+\t\tif (!(prop = fdt_get_property_by_offset(fdt, offset, lenp))) {\n+\t\t\toffset = -FDT_ERR_INTERNAL;\n+\t\t\tbreak;\n+\t\t}\n+\t\tif (_fdt_string_eq(fdt, fdt32_to_cpu(prop->nameoff),\n+\t\t\t\t name, namelen))\n+\t\t\treturn prop;\n+\t}\n+\n+\tif (lenp)\n+\t\t*lenp = offset;\n+\treturn NULL;\n+}\n+\n+const struct fdt_property *fdt_get_property(const void *fdt,\n+\t\t\t\t\t int nodeoffset,\n+\t\t\t\t\t const char *name, int *lenp)\n+{\n+\treturn fdt_get_property_namelen(fdt, nodeoffset, name,\n+\t\t\t\t\tstrlen(name), lenp);\n+}\n+\n+const void *fdt_getprop_namelen(const void *fdt, int nodeoffset,\n+\t\t\t\tconst char *name, int namelen, int *lenp)\n+{\n+\tconst struct fdt_property *prop;\n+\n+\tprop = fdt_get_property_namelen(fdt, nodeoffset, name, namelen, lenp);\n+\tif (! prop)\n+\t\treturn NULL;\n+\n+\treturn prop->data;\n+}\n+\n+const void *fdt_getprop_by_offset(const void *fdt, int offset,\n+\t\t\t\t const char **namep, int *lenp)\n+{\n+\tconst struct fdt_property *prop;\n+\n+\tprop = fdt_get_property_by_offset(fdt, offset, lenp);\n+\tif (!prop)\n+\t\treturn NULL;\n+\tif (namep)\n+\t\t*namep = fdt_string(fdt, fdt32_to_cpu(prop->nameoff));\n+\treturn prop->data;\n+}\n+\n+const void *fdt_getprop(const void *fdt, int nodeoffset,\n+\t\t\tconst char *name, int *lenp)\n+{\n+\treturn fdt_getprop_namelen(fdt, nodeoffset, name, strlen(name), lenp);\n+}\n+\n+uint32_t fdt_get_phandle(const void *fdt, int nodeoffset)\n+{\n+\tconst fdt32_t *php;\n+\tint len;\n+\n+\t/* FIXME: This is a bit sub-optimal, since we potentially scan\n+\t * over all the properties twice. */\n+\tphp = fdt_getprop(fdt, nodeoffset, \"phandle\", &len);\n+\tif (!php || (len != sizeof(*php))) {\n+\t\tphp = fdt_getprop(fdt, nodeoffset, \"linux,phandle\", &len);\n+\t\tif (!php || (len != sizeof(*php)))\n+\t\t\treturn 0;\n+\t}\n+\n+\treturn fdt32_to_cpu(*php);\n+}\n+\n+const char *fdt_get_alias_namelen(const void *fdt,\n+\t\t\t\t const char *name, int namelen)\n+{\n+\tint aliasoffset;\n+\n+\taliasoffset = fdt_path_offset(fdt, \"/aliases\");\n+\tif (aliasoffset < 0)\n+\t\treturn NULL;\n+\n+\treturn fdt_getprop_namelen(fdt, aliasoffset, name, namelen, NULL);\n+}\n+\n+const char *fdt_get_alias(const void *fdt, const char *name)\n+{\n+\treturn fdt_get_alias_namelen(fdt, name, strlen(name));\n+}\n+\n+int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen)\n+{\n+\tint pdepth = 0, p = 0;\n+\tint offset, depth, namelen;\n+\tconst char *name;\n+\n+\tFDT_CHECK_HEADER(fdt);\n+\n+\tif (buflen < 2)\n+\t\treturn -FDT_ERR_NOSPACE;\n+\n+\tfor (offset = 0, depth = 0;\n+\t (offset >= 0) && (offset <= nodeoffset);\n+\t offset = fdt_next_node(fdt, offset, &depth)) {\n+\t\twhile (pdepth > depth) {\n+\t\t\tdo {\n+\t\t\t\tp--;\n+\t\t\t} while (buf[p-1] != '/');\n+\t\t\tpdepth--;\n+\t\t}\n+\n+\t\tif (pdepth >= depth) {\n+\t\t\tname = fdt_get_name(fdt, offset, &namelen);\n+\t\t\tif (!name)\n+\t\t\t\treturn namelen;\n+\t\t\tif ((p + namelen + 1) <= buflen) {\n+\t\t\t\tmemcpy(buf + p, name, namelen);\n+\t\t\t\tp += namelen;\n+\t\t\t\tbuf[p++] = '/';\n+\t\t\t\tpdepth++;\n+\t\t\t}\n+\t\t}\n+\n+\t\tif (offset == nodeoffset) {\n+\t\t\tif (pdepth < (depth + 1))\n+\t\t\t\treturn -FDT_ERR_NOSPACE;\n+\n+\t\t\tif (p > 1) /* special case so that root path is \"/\", not \"\" */\n+\t\t\t\tp--;\n+\t\t\tbuf[p] = '\\0';\n+\t\t\treturn 0;\n+\t\t}\n+\t}\n+\n+\tif ((offset == -FDT_ERR_NOTFOUND) || (offset >= 0))\n+\t\treturn -FDT_ERR_BADOFFSET;\n+\telse if (offset == -FDT_ERR_BADOFFSET)\n+\t\treturn -FDT_ERR_BADSTRUCTURE;\n+\n+\treturn offset; /* error from fdt_next_node() */\n+}\n+\n+int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset,\n+\t\t\t\t int supernodedepth, int *nodedepth)\n+{\n+\tint offset, depth;\n+\tint supernodeoffset = -FDT_ERR_INTERNAL;\n+\n+\tFDT_CHECK_HEADER(fdt);\n+\n+\tif (supernodedepth < 0)\n+\t\treturn -FDT_ERR_NOTFOUND;\n+\n+\tfor (offset = 0, depth = 0;\n+\t (offset >= 0) && (offset <= nodeoffset);\n+\t offset = fdt_next_node(fdt, offset, &depth)) {\n+\t\tif (depth == supernodedepth)\n+\t\t\tsupernodeoffset = offset;\n+\n+\t\tif (offset == nodeoffset) {\n+\t\t\tif (nodedepth)\n+\t\t\t\t*nodedepth = depth;\n+\n+\t\t\tif (supernodedepth > depth)\n+\t\t\t\treturn -FDT_ERR_NOTFOUND;\n+\t\t\telse\n+\t\t\t\treturn supernodeoffset;\n+\t\t}\n+\t}\n+\n+\tif ((offset == -FDT_ERR_NOTFOUND) || (offset >= 0))\n+\t\treturn -FDT_ERR_BADOFFSET;\n+\telse if (offset == -FDT_ERR_BADOFFSET)\n+\t\treturn -FDT_ERR_BADSTRUCTURE;\n+\n+\treturn offset; /* error from fdt_next_node() */\n+}\n+\n+int fdt_node_depth(const void *fdt, int nodeoffset)\n+{\n+\tint nodedepth;\n+\tint err;\n+\n+\terr = fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, &nodedepth);\n+\tif (err)\n+\t\treturn (err < 0) ? err : -FDT_ERR_INTERNAL;\n+\treturn nodedepth;\n+}\n+\n+int fdt_parent_offset(const void *fdt, int nodeoffset)\n+{\n+\tint nodedepth = fdt_node_depth(fdt, nodeoffset);\n+\n+\tif (nodedepth < 0)\n+\t\treturn nodedepth;\n+\treturn fdt_supernode_atdepth_offset(fdt, nodeoffset,\n+\t\t\t\t\t nodedepth - 1, NULL);\n+}\n+\n+int fdt_node_offset_by_prop_value(const void *fdt, int startoffset,\n+\t\t\t\t const char *propname,\n+\t\t\t\t const void *propval, int proplen)\n+{\n+\tint offset;\n+\tconst void *val;\n+\tint len;\n+\n+\tFDT_CHECK_HEADER(fdt);\n+\n+\t/* FIXME: The algorithm here is pretty horrible: we scan each\n+\t * property of a node in fdt_getprop(), then if that didn't\n+\t * find what we want, we scan over them again making our way\n+\t * to the next node. Still it's the easiest to implement\n+\t * approach; performance can come later. */\n+\tfor (offset = fdt_next_node(fdt, startoffset, NULL);\n+\t offset >= 0;\n+\t offset = fdt_next_node(fdt, offset, NULL)) {\n+\t\tval = fdt_getprop(fdt, offset, propname, &len);\n+\t\tif (val && (len == proplen)\n+\t\t && (memcmp(val, propval, len) == 0))\n+\t\t\treturn offset;\n+\t}\n+\n+\treturn offset; /* error from fdt_next_node() */\n+}\n+\n+int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle)\n+{\n+\tint offset;\n+\n+\tif ((phandle == 0) || (phandle == -1))\n+\t\treturn -FDT_ERR_BADPHANDLE;\n+\n+\tFDT_CHECK_HEADER(fdt);\n+\n+\t/* FIXME: The algorithm here is pretty horrible: we\n+\t * potentially scan each property of a node in\n+\t * fdt_get_phandle(), then if that didn't find what\n+\t * we want, we scan over them again making our way to the next\n+\t * node. Still it's the easiest to implement approach;\n+\t * performance can come later. */\n+\tfor (offset = fdt_next_node(fdt, -1, NULL);\n+\t offset >= 0;\n+\t offset = fdt_next_node(fdt, offset, NULL)) {\n+\t\tif (fdt_get_phandle(fdt, offset) == phandle)\n+\t\t\treturn offset;\n+\t}\n+\n+\treturn offset; /* error from fdt_next_node() */\n+}\n+\n+int fdt_stringlist_contains(const char *strlist, int listlen, const char *str)\n+{\n+\tint len = strlen(str);\n+\tconst char *p;\n+\n+\twhile (listlen >= len) {\n+\t\tif (memcmp(str, strlist, len+1) == 0)\n+\t\t\treturn 1;\n+\t\tp = memchr(strlist, '\\0', listlen);\n+\t\tif (!p)\n+\t\t\treturn 0; /* malformed strlist.. */\n+\t\tlistlen -= (p-strlist) + 1;\n+\t\tstrlist = p + 1;\n+\t}\n+\treturn 0;\n+}\n+\n+int fdt_stringlist_count(const void *fdt, int nodeoffset, const char *property)\n+{\n+\tconst char *list, *end;\n+\tint length, count = 0;\n+\n+\tlist = fdt_getprop(fdt, nodeoffset, property, &length);\n+\tif (!list)\n+\t\treturn length;\n+\n+\tend = list + length;\n+\n+\twhile (list < end) {\n+\t\tlength = strnlen(list, end - list) + 1;\n+\n+\t\t/* Abort if the last string isn't properly NUL-terminated. */\n+\t\tif (list + length > end)\n+\t\t\treturn -FDT_ERR_BADVALUE;\n+\n+\t\tlist += length;\n+\t\tcount++;\n+\t}\n+\n+\treturn count;\n+}\n+\n+int fdt_stringlist_search(const void *fdt, int nodeoffset, const char *property,\n+\t\t\t const char *string)\n+{\n+\tint length, len, idx = 0;\n+\tconst char *list, *end;\n+\n+\tlist = fdt_getprop(fdt, nodeoffset, property, &length);\n+\tif (!list)\n+\t\treturn length;\n+\n+\tlen = strlen(string) + 1;\n+\tend = list + length;\n+\n+\twhile (list < end) {\n+\t\tlength = strnlen(list, end - list) + 1;\n+\n+\t\t/* Abort if the last string isn't properly NUL-terminated. */\n+\t\tif (list + length > end)\n+\t\t\treturn -FDT_ERR_BADVALUE;\n+\n+\t\tif (length == len && memcmp(list, string, length) == 0)\n+\t\t\treturn idx;\n+\n+\t\tlist += length;\n+\t\tidx++;\n+\t}\n+\n+\treturn -FDT_ERR_NOTFOUND;\n+}\n+\n+const char *fdt_stringlist_get(const void *fdt, int nodeoffset,\n+\t\t\t const char *property, int idx,\n+\t\t\t int *lenp)\n+{\n+\tconst char *list, *end;\n+\tint length;\n+\n+\tlist = fdt_getprop(fdt, nodeoffset, property, &length);\n+\tif (!list) {\n+\t\tif (lenp)\n+\t\t\t*lenp = length;\n+\n+\t\treturn NULL;\n+\t}\n+\n+\tend = list + length;\n+\n+\twhile (list < end) {\n+\t\tlength = strnlen(list, end - list) + 1;\n+\n+\t\t/* Abort if the last string isn't properly NUL-terminated. */\n+\t\tif (list + length > end) {\n+\t\t\tif (lenp)\n+\t\t\t\t*lenp = -FDT_ERR_BADVALUE;\n+\n+\t\t\treturn NULL;\n+\t\t}\n+\n+\t\tif (idx == 0) {\n+\t\t\tif (lenp)\n+\t\t\t\t*lenp = length - 1;\n+\n+\t\t\treturn list;\n+\t\t}\n+\n+\t\tlist += length;\n+\t\tidx--;\n+\t}\n+\n+\tif (lenp)\n+\t\t*lenp = -FDT_ERR_NOTFOUND;\n+\n+\treturn NULL;\n+}\n+\n+int fdt_node_check_compatible(const void *fdt, int nodeoffset,\n+\t\t\t const char *compatible)\n+{\n+\tconst void *prop;\n+\tint len;\n+\n+\tprop = fdt_getprop(fdt, nodeoffset, \"compatible\", &len);\n+\tif (!prop)\n+\t\treturn len;\n+\n+\treturn !fdt_stringlist_contains(prop, len, compatible);\n+}\n+\n+int fdt_node_offset_by_compatible(const void *fdt, int startoffset,\n+\t\t\t\t const char *compatible)\n+{\n+\tint offset, err;\n+\n+\tFDT_CHECK_HEADER(fdt);\n+\n+\t/* FIXME: The algorithm here is pretty horrible: we scan each\n+\t * property of a node in fdt_node_check_compatible(), then if\n+\t * that didn't find what we want, we scan over them again\n+\t * making our way to the next node. Still it's the easiest to\n+\t * implement approach; performance can come later. */\n+\tfor (offset = fdt_next_node(fdt, startoffset, NULL);\n+\t offset >= 0;\n+\t offset = fdt_next_node(fdt, offset, NULL)) {\n+\t\terr = fdt_node_check_compatible(fdt, offset, compatible);\n+\t\tif ((err < 0) && (err != -FDT_ERR_NOTFOUND))\n+\t\t\treturn err;\n+\t\telse if (err == 0)\n+\t\t\treturn offset;\n+\t}\n+\n+\treturn offset; /* error from fdt_next_node() */\n+}\ndiff --git a/scripts/dtc/libfdt/fdt_rw.c b/scripts/dtc/libfdt/fdt_rw.c\nnew file mode 100644\nindex 000000000000..3fd5847377c9\n--- /dev/null\n+++ b/scripts/dtc/libfdt/fdt_rw.c\n@@ -0,0 +1,491 @@\n+/*\n+ * libfdt - Flat Device Tree manipulation\n+ * Copyright (C) 2006 David Gibson, IBM Corporation.\n+ *\n+ * libfdt is dual licensed: you can use it either under the terms of\n+ * the GPL, or the BSD license, at your option.\n+ *\n+ * a) This library is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License as\n+ * published by the Free Software Foundation; either version 2 of the\n+ * License, or (at your option) any later version.\n+ *\n+ * This library is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public\n+ * License along with this library; if not, write to the Free\n+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,\n+ * MA 02110-1301 USA\n+ *\n+ * Alternatively,\n+ *\n+ * b) Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * 1. Redistributions of source code must retain the above\n+ * copyright notice, this list of conditions and the following\n+ * disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above\n+ * copyright notice, this list of conditions and the following\n+ * disclaimer in the documentation and/or other materials\n+ * provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\n+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\n+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+#include \"libfdt_env.h\"\n+\n+#include <fdt.h>\n+#include <libfdt.h>\n+\n+#include \"libfdt_internal.h\"\n+\n+static int _fdt_blocks_misordered(const void *fdt,\n+\t\t\t int mem_rsv_size, int struct_size)\n+{\n+\treturn (fdt_off_mem_rsvmap(fdt) < FDT_ALIGN(sizeof(struct fdt_header), 8))\n+\t\t|| (fdt_off_dt_struct(fdt) <\n+\t\t (fdt_off_mem_rsvmap(fdt) + mem_rsv_size))\n+\t\t|| (fdt_off_dt_strings(fdt) <\n+\t\t (fdt_off_dt_struct(fdt) + struct_size))\n+\t\t|| (fdt_totalsize(fdt) <\n+\t\t (fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt)));\n+}\n+\n+static int _fdt_rw_check_header(void *fdt)\n+{\n+\tFDT_CHECK_HEADER(fdt);\n+\n+\tif (fdt_version(fdt) < 17)\n+\t\treturn -FDT_ERR_BADVERSION;\n+\tif (_fdt_blocks_misordered(fdt, sizeof(struct fdt_reserve_entry),\n+\t\t\t\t fdt_size_dt_struct(fdt)))\n+\t\treturn -FDT_ERR_BADLAYOUT;\n+\tif (fdt_version(fdt) > 17)\n+\t\tfdt_set_version(fdt, 17);\n+\n+\treturn 0;\n+}\n+\n+#define FDT_RW_CHECK_HEADER(fdt) \\\n+\t{ \\\n+\t\tint __err; \\\n+\t\tif ((__err = _fdt_rw_check_header(fdt)) != 0) \\\n+\t\t\treturn __err; \\\n+\t}\n+\n+static inline int _fdt_data_size(void *fdt)\n+{\n+\treturn fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt);\n+}\n+\n+static int _fdt_splice(void *fdt, void *splicepoint, int oldlen, int newlen)\n+{\n+\tchar *p = splicepoint;\n+\tchar *end = (char *)fdt + _fdt_data_size(fdt);\n+\n+\tif (((p + oldlen) < p) || ((p + oldlen) > end))\n+\t\treturn -FDT_ERR_BADOFFSET;\n+\tif ((p < (char *)fdt) || ((end - oldlen + newlen) < (char *)fdt))\n+\t\treturn -FDT_ERR_BADOFFSET;\n+\tif ((end - oldlen + newlen) > ((char *)fdt + fdt_totalsize(fdt)))\n+\t\treturn -FDT_ERR_NOSPACE;\n+\tmemmove(p + newlen, p + oldlen, end - p - oldlen);\n+\treturn 0;\n+}\n+\n+static int _fdt_splice_mem_rsv(void *fdt, struct fdt_reserve_entry *p,\n+\t\t\t int oldn, int newn)\n+{\n+\tint delta = (newn - oldn) * sizeof(*p);\n+\tint err;\n+\terr = _fdt_splice(fdt, p, oldn * sizeof(*p), newn * sizeof(*p));\n+\tif (err)\n+\t\treturn err;\n+\tfdt_set_off_dt_struct(fdt, fdt_off_dt_struct(fdt) + delta);\n+\tfdt_set_off_dt_strings(fdt, fdt_off_dt_strings(fdt) + delta);\n+\treturn 0;\n+}\n+\n+static int _fdt_splice_struct(void *fdt, void *p,\n+\t\t\t int oldlen, int newlen)\n+{\n+\tint delta = newlen - oldlen;\n+\tint err;\n+\n+\tif ((err = _fdt_splice(fdt, p, oldlen, newlen)))\n+\t\treturn err;\n+\n+\tfdt_set_size_dt_struct(fdt, fdt_size_dt_struct(fdt) + delta);\n+\tfdt_set_off_dt_strings(fdt, fdt_off_dt_strings(fdt) + delta);\n+\treturn 0;\n+}\n+\n+static int _fdt_splice_string(void *fdt, int newlen)\n+{\n+\tvoid *p = (char *)fdt\n+\t\t+ fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt);\n+\tint err;\n+\n+\tif ((err = _fdt_splice(fdt, p, 0, newlen)))\n+\t\treturn err;\n+\n+\tfdt_set_size_dt_strings(fdt, fdt_size_dt_strings(fdt) + newlen);\n+\treturn 0;\n+}\n+\n+static int _fdt_find_add_string(void *fdt, const char *s)\n+{\n+\tchar *strtab = (char *)fdt + fdt_off_dt_strings(fdt);\n+\tconst char *p;\n+\tchar *new;\n+\tint len = strlen(s) + 1;\n+\tint err;\n+\n+\tp = _fdt_find_string(strtab, fdt_size_dt_strings(fdt), s);\n+\tif (p)\n+\t\t/* found it */\n+\t\treturn (p - strtab);\n+\n+\tnew = strtab + fdt_size_dt_strings(fdt);\n+\terr = _fdt_splice_string(fdt, len);\n+\tif (err)\n+\t\treturn err;\n+\n+\tmemcpy(new, s, len);\n+\treturn (new - strtab);\n+}\n+\n+int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size)\n+{\n+\tstruct fdt_reserve_entry *re;\n+\tint err;\n+\n+\tFDT_RW_CHECK_HEADER(fdt);\n+\n+\tre = _fdt_mem_rsv_w(fdt, fdt_num_mem_rsv(fdt));\n+\terr = _fdt_splice_mem_rsv(fdt, re, 0, 1);\n+\tif (err)\n+\t\treturn err;\n+\n+\tre->address = cpu_to_fdt64(address);\n+\tre->size = cpu_to_fdt64(size);\n+\treturn 0;\n+}\n+\n+int fdt_del_mem_rsv(void *fdt, int n)\n+{\n+\tstruct fdt_reserve_entry *re = _fdt_mem_rsv_w(fdt, n);\n+\n+\tFDT_RW_CHECK_HEADER(fdt);\n+\n+\tif (n >= fdt_num_mem_rsv(fdt))\n+\t\treturn -FDT_ERR_NOTFOUND;\n+\n+\treturn _fdt_splice_mem_rsv(fdt, re, 1, 0);\n+}\n+\n+static int _fdt_resize_property(void *fdt, int nodeoffset, const char *name,\n+\t\t\t\tint len, struct fdt_property **prop)\n+{\n+\tint oldlen;\n+\tint err;\n+\n+\t*prop = fdt_get_property_w(fdt, nodeoffset, name, &oldlen);\n+\tif (! (*prop))\n+\t\treturn oldlen;\n+\n+\tif ((err = _fdt_splice_struct(fdt, (*prop)->data, FDT_TAGALIGN(oldlen),\n+\t\t\t\t FDT_TAGALIGN(len))))\n+\t\treturn err;\n+\n+\t(*prop)->len = cpu_to_fdt32(len);\n+\treturn 0;\n+}\n+\n+static int _fdt_add_property(void *fdt, int nodeoffset, const char *name,\n+\t\t\t int len, struct fdt_property **prop)\n+{\n+\tint proplen;\n+\tint nextoffset;\n+\tint namestroff;\n+\tint err;\n+\n+\tif ((nextoffset = _fdt_check_node_offset(fdt, nodeoffset)) < 0)\n+\t\treturn nextoffset;\n+\n+\tnamestroff = _fdt_find_add_string(fdt, name);\n+\tif (namestroff < 0)\n+\t\treturn namestroff;\n+\n+\t*prop = _fdt_offset_ptr_w(fdt, nextoffset);\n+\tproplen = sizeof(**prop) + FDT_TAGALIGN(len);\n+\n+\terr = _fdt_splice_struct(fdt, *prop, 0, proplen);\n+\tif (err)\n+\t\treturn err;\n+\n+\t(*prop)->tag = cpu_to_fdt32(FDT_PROP);\n+\t(*prop)->nameoff = cpu_to_fdt32(namestroff);\n+\t(*prop)->len = cpu_to_fdt32(len);\n+\treturn 0;\n+}\n+\n+int fdt_set_name(void *fdt, int nodeoffset, const char *name)\n+{\n+\tchar *namep;\n+\tint oldlen, newlen;\n+\tint err;\n+\n+\tFDT_RW_CHECK_HEADER(fdt);\n+\n+\tnamep = (char *)(uintptr_t)fdt_get_name(fdt, nodeoffset, &oldlen);\n+\tif (!namep)\n+\t\treturn oldlen;\n+\n+\tnewlen = strlen(name);\n+\n+\terr = _fdt_splice_struct(fdt, namep, FDT_TAGALIGN(oldlen+1),\n+\t\t\t\t FDT_TAGALIGN(newlen+1));\n+\tif (err)\n+\t\treturn err;\n+\n+\tmemcpy(namep, name, newlen+1);\n+\treturn 0;\n+}\n+\n+int fdt_setprop(void *fdt, int nodeoffset, const char *name,\n+\t\tconst void *val, int len)\n+{\n+\tstruct fdt_property *prop;\n+\tint err;\n+\n+\tFDT_RW_CHECK_HEADER(fdt);\n+\n+\terr = _fdt_resize_property(fdt, nodeoffset, name, len, &prop);\n+\tif (err == -FDT_ERR_NOTFOUND)\n+\t\terr = _fdt_add_property(fdt, nodeoffset, name, len, &prop);\n+\tif (err)\n+\t\treturn err;\n+\n+\tif (len)\n+\t\tmemcpy(prop->data, val, len);\n+\treturn 0;\n+}\n+\n+int fdt_appendprop(void *fdt, int nodeoffset, const char *name,\n+\t\t const void *val, int len)\n+{\n+\tstruct fdt_property *prop;\n+\tint err, oldlen, newlen;\n+\n+\tFDT_RW_CHECK_HEADER(fdt);\n+\n+\tprop = fdt_get_property_w(fdt, nodeoffset, name, &oldlen);\n+\tif (prop) {\n+\t\tnewlen = len + oldlen;\n+\t\terr = _fdt_splice_struct(fdt, prop->data,\n+\t\t\t\t\t FDT_TAGALIGN(oldlen),\n+\t\t\t\t\t FDT_TAGALIGN(newlen));\n+\t\tif (err)\n+\t\t\treturn err;\n+\t\tprop->len = cpu_to_fdt32(newlen);\n+\t\tmemcpy(prop->data + oldlen, val, len);\n+\t} else {\n+\t\terr = _fdt_add_property(fdt, nodeoffset, name, len, &prop);\n+\t\tif (err)\n+\t\t\treturn err;\n+\t\tmemcpy(prop->data, val, len);\n+\t}\n+\treturn 0;\n+}\n+\n+int fdt_delprop(void *fdt, int nodeoffset, const char *name)\n+{\n+\tstruct fdt_property *prop;\n+\tint len, proplen;\n+\n+\tFDT_RW_CHECK_HEADER(fdt);\n+\n+\tprop = fdt_get_property_w(fdt, nodeoffset, name, &len);\n+\tif (! prop)\n+\t\treturn len;\n+\n+\tproplen = sizeof(*prop) + FDT_TAGALIGN(len);\n+\treturn _fdt_splice_struct(fdt, prop, proplen, 0);\n+}\n+\n+int fdt_add_subnode_namelen(void *fdt, int parentoffset,\n+\t\t\t const char *name, int namelen)\n+{\n+\tstruct fdt_node_header *nh;\n+\tint offset, nextoffset;\n+\tint nodelen;\n+\tint err;\n+\tuint32_t tag;\n+\tfdt32_t *endtag;\n+\n+\tFDT_RW_CHECK_HEADER(fdt);\n+\n+\toffset = fdt_subnode_offset_namelen(fdt, parentoffset, name, namelen);\n+\tif (offset >= 0)\n+\t\treturn -FDT_ERR_EXISTS;\n+\telse if (offset != -FDT_ERR_NOTFOUND)\n+\t\treturn offset;\n+\n+\t/* Try to place the new node after the parent's properties */\n+\tfdt_next_tag(fdt, parentoffset, &nextoffset); /* skip the BEGIN_NODE */\n+\tdo {\n+\t\toffset = nextoffset;\n+\t\ttag = fdt_next_tag(fdt, offset, &nextoffset);\n+\t} while ((tag == FDT_PROP) || (tag == FDT_NOP));\n+\n+\tnh = _fdt_offset_ptr_w(fdt, offset);\n+\tnodelen = sizeof(*nh) + FDT_TAGALIGN(namelen+1) + FDT_TAGSIZE;\n+\n+\terr = _fdt_splice_struct(fdt, nh, 0, nodelen);\n+\tif (err)\n+\t\treturn err;\n+\n+\tnh->tag = cpu_to_fdt32(FDT_BEGIN_NODE);\n+\tmemset(nh->name, 0, FDT_TAGALIGN(namelen+1));\n+\tmemcpy(nh->name, name, namelen);\n+\tendtag = (fdt32_t *)((char *)nh + nodelen - FDT_TAGSIZE);\n+\t*endtag = cpu_to_fdt32(FDT_END_NODE);\n+\n+\treturn offset;\n+}\n+\n+int fdt_add_subnode(void *fdt, int parentoffset, const char *name)\n+{\n+\treturn fdt_add_subnode_namelen(fdt, parentoffset, name, strlen(name));\n+}\n+\n+int fdt_del_node(void *fdt, int nodeoffset)\n+{\n+\tint endoffset;\n+\n+\tFDT_RW_CHECK_HEADER(fdt);\n+\n+\tendoffset = _fdt_node_end_offset(fdt, nodeoffset);\n+\tif (endoffset < 0)\n+\t\treturn endoffset;\n+\n+\treturn _fdt_splice_struct(fdt, _fdt_offset_ptr_w(fdt, nodeoffset),\n+\t\t\t\t endoffset - nodeoffset, 0);\n+}\n+\n+static void _fdt_packblocks(const char *old, char *new,\n+\t\t\t int mem_rsv_size, int struct_size)\n+{\n+\tint mem_rsv_off, struct_off, strings_off;\n+\n+\tmem_rsv_off = FDT_ALIGN(sizeof(struct fdt_header), 8);\n+\tstruct_off = mem_rsv_off + mem_rsv_size;\n+\tstrings_off = struct_off + struct_size;\n+\n+\tmemmove(new + mem_rsv_off, old + fdt_off_mem_rsvmap(old), mem_rsv_size);\n+\tfdt_set_off_mem_rsvmap(new, mem_rsv_off);\n+\n+\tmemmove(new + struct_off, old + fdt_off_dt_struct(old), struct_size);\n+\tfdt_set_off_dt_struct(new, struct_off);\n+\tfdt_set_size_dt_struct(new, struct_size);\n+\n+\tmemmove(new + strings_off, old + fdt_off_dt_strings(old),\n+\t\tfdt_size_dt_strings(old));\n+\tfdt_set_off_dt_strings(new, strings_off);\n+\tfdt_set_size_dt_strings(new, fdt_size_dt_strings(old));\n+}\n+\n+int fdt_open_into(const void *fdt, void *buf, int bufsize)\n+{\n+\tint err;\n+\tint mem_rsv_size, struct_size;\n+\tint newsize;\n+\tconst char *fdtstart = fdt;\n+\tconst char *fdtend = fdtstart + fdt_totalsize(fdt);\n+\tchar *tmp;\n+\n+\tFDT_CHECK_HEADER(fdt);\n+\n+\tmem_rsv_size = (fdt_num_mem_rsv(fdt)+1)\n+\t\t* sizeof(struct fdt_reserve_entry);\n+\n+\tif (fdt_version(fdt) >= 17) {\n+\t\tstruct_size = fdt_size_dt_struct(fdt);\n+\t} else {\n+\t\tstruct_size = 0;\n+\t\twhile (fdt_next_tag(fdt, struct_size, &struct_size) != FDT_END)\n+\t\t\t;\n+\t\tif (struct_size < 0)\n+\t\t\treturn struct_size;\n+\t}\n+\n+\tif (!_fdt_blocks_misordered(fdt, mem_rsv_size, struct_size)) {\n+\t\t/* no further work necessary */\n+\t\terr = fdt_move(fdt, buf, bufsize);\n+\t\tif (err)\n+\t\t\treturn err;\n+\t\tfdt_set_version(buf, 17);\n+\t\tfdt_set_size_dt_struct(buf, struct_size);\n+\t\tfdt_set_totalsize(buf, bufsize);\n+\t\treturn 0;\n+\t}\n+\n+\t/* Need to reorder */\n+\tnewsize = FDT_ALIGN(sizeof(struct fdt_header), 8) + mem_rsv_size\n+\t\t+ struct_size + fdt_size_dt_strings(fdt);\n+\n+\tif (bufsize < newsize)\n+\t\treturn -FDT_ERR_NOSPACE;\n+\n+\t/* First attempt to build converted tree at beginning of buffer */\n+\ttmp = buf;\n+\t/* But if that overlaps with the old tree... */\n+\tif (((tmp + newsize) > fdtstart) && (tmp < fdtend)) {\n+\t\t/* Try right after the old tree instead */\n+\t\ttmp = (char *)(uintptr_t)fdtend;\n+\t\tif ((tmp + newsize) > ((char *)buf + bufsize))\n+\t\t\treturn -FDT_ERR_NOSPACE;\n+\t}\n+\n+\t_fdt_packblocks(fdt, tmp, mem_rsv_size, struct_size);\n+\tmemmove(buf, tmp, newsize);\n+\n+\tfdt_set_magic(buf, FDT_MAGIC);\n+\tfdt_set_totalsize(buf, bufsize);\n+\tfdt_set_version(buf, 17);\n+\tfdt_set_last_comp_version(buf, 16);\n+\tfdt_set_boot_cpuid_phys(buf, fdt_boot_cpuid_phys(fdt));\n+\n+\treturn 0;\n+}\n+\n+int fdt_pack(void *fdt)\n+{\n+\tint mem_rsv_size;\n+\n+\tFDT_RW_CHECK_HEADER(fdt);\n+\n+\tmem_rsv_size = (fdt_num_mem_rsv(fdt)+1)\n+\t\t* sizeof(struct fdt_reserve_entry);\n+\t_fdt_packblocks(fdt, fdt, mem_rsv_size, fdt_size_dt_struct(fdt));\n+\tfdt_set_totalsize(fdt, _fdt_data_size(fdt));\n+\n+\treturn 0;\n+}\ndiff --git a/scripts/dtc/libfdt/fdt_strerror.c b/scripts/dtc/libfdt/fdt_strerror.c\nnew file mode 100644\nindex 000000000000..9677a1887e57\n--- /dev/null\n+++ b/scripts/dtc/libfdt/fdt_strerror.c\n@@ -0,0 +1,102 @@\n+/*\n+ * libfdt - Flat Device Tree manipulation\n+ * Copyright (C) 2006 David Gibson, IBM Corporation.\n+ *\n+ * libfdt is dual licensed: you can use it either under the terms of\n+ * the GPL, or the BSD license, at your option.\n+ *\n+ * a) This library is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License as\n+ * published by the Free Software Foundation; either version 2 of the\n+ * License, or (at your option) any later version.\n+ *\n+ * This library is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public\n+ * License along with this library; if not, write to the Free\n+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,\n+ * MA 02110-1301 USA\n+ *\n+ * Alternatively,\n+ *\n+ * b) Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * 1. Redistributions of source code must retain the above\n+ * copyright notice, this list of conditions and the following\n+ * disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above\n+ * copyright notice, this list of conditions and the following\n+ * disclaimer in the documentation and/or other materials\n+ * provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\n+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\n+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+#include \"libfdt_env.h\"\n+\n+#include <fdt.h>\n+#include <libfdt.h>\n+\n+#include \"libfdt_internal.h\"\n+\n+struct fdt_errtabent {\n+\tconst char *str;\n+};\n+\n+#define FDT_ERRTABENT(val) \\\n+\t[(val)] = { .str = #val, }\n+\n+static struct fdt_errtabent fdt_errtable[] = {\n+\tFDT_ERRTABENT(FDT_ERR_NOTFOUND),\n+\tFDT_ERRTABENT(FDT_ERR_EXISTS),\n+\tFDT_ERRTABENT(FDT_ERR_NOSPACE),\n+\n+\tFDT_ERRTABENT(FDT_ERR_BADOFFSET),\n+\tFDT_ERRTABENT(FDT_ERR_BADPATH),\n+\tFDT_ERRTABENT(FDT_ERR_BADPHANDLE),\n+\tFDT_ERRTABENT(FDT_ERR_BADSTATE),\n+\n+\tFDT_ERRTABENT(FDT_ERR_TRUNCATED),\n+\tFDT_ERRTABENT(FDT_ERR_BADMAGIC),\n+\tFDT_ERRTABENT(FDT_ERR_BADVERSION),\n+\tFDT_ERRTABENT(FDT_ERR_BADSTRUCTURE),\n+\tFDT_ERRTABENT(FDT_ERR_BADLAYOUT),\n+\tFDT_ERRTABENT(FDT_ERR_INTERNAL),\n+\tFDT_ERRTABENT(FDT_ERR_BADNCELLS),\n+\tFDT_ERRTABENT(FDT_ERR_BADVALUE),\n+\tFDT_ERRTABENT(FDT_ERR_BADOVERLAY),\n+\tFDT_ERRTABENT(FDT_ERR_NOPHANDLES),\n+};\n+#define FDT_ERRTABSIZE\t(sizeof(fdt_errtable) / sizeof(fdt_errtable[0]))\n+\n+const char *fdt_strerror(int errval)\n+{\n+\tif (errval > 0)\n+\t\treturn \"<valid offset/length>\";\n+\telse if (errval == 0)\n+\t\treturn \"<no error>\";\n+\telse if (errval > -FDT_ERRTABSIZE) {\n+\t\tconst char *s = fdt_errtable[-errval].str;\n+\n+\t\tif (s)\n+\t\t\treturn s;\n+\t}\n+\n+\treturn \"<unknown error>\";\n+}\ndiff --git a/scripts/dtc/libfdt/fdt_sw.c b/scripts/dtc/libfdt/fdt_sw.c\nnew file mode 100644\nindex 000000000000..6a804859fd0c\n--- /dev/null\n+++ b/scripts/dtc/libfdt/fdt_sw.c\n@@ -0,0 +1,288 @@\n+/*\n+ * libfdt - Flat Device Tree manipulation\n+ * Copyright (C) 2006 David Gibson, IBM Corporation.\n+ *\n+ * libfdt is dual licensed: you can use it either under the terms of\n+ * the GPL, or the BSD license, at your option.\n+ *\n+ * a) This library is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License as\n+ * published by the Free Software Foundation; either version 2 of the\n+ * License, or (at your option) any later version.\n+ *\n+ * This library is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public\n+ * License along with this library; if not, write to the Free\n+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,\n+ * MA 02110-1301 USA\n+ *\n+ * Alternatively,\n+ *\n+ * b) Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * 1. Redistributions of source code must retain the above\n+ * copyright notice, this list of conditions and the following\n+ * disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above\n+ * copyright notice, this list of conditions and the following\n+ * disclaimer in the documentation and/or other materials\n+ * provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\n+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\n+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+#include \"libfdt_env.h\"\n+\n+#include <fdt.h>\n+#include <libfdt.h>\n+\n+#include \"libfdt_internal.h\"\n+\n+static int _fdt_sw_check_header(void *fdt)\n+{\n+\tif (fdt_magic(fdt) != FDT_SW_MAGIC)\n+\t\treturn -FDT_ERR_BADMAGIC;\n+\t/* FIXME: should check more details about the header state */\n+\treturn 0;\n+}\n+\n+#define FDT_SW_CHECK_HEADER(fdt) \\\n+\t{ \\\n+\t\tint err; \\\n+\t\tif ((err = _fdt_sw_check_header(fdt)) != 0) \\\n+\t\t\treturn err; \\\n+\t}\n+\n+static void *_fdt_grab_space(void *fdt, size_t len)\n+{\n+\tint offset = fdt_size_dt_struct(fdt);\n+\tint spaceleft;\n+\n+\tspaceleft = fdt_totalsize(fdt) - fdt_off_dt_struct(fdt)\n+\t\t- fdt_size_dt_strings(fdt);\n+\n+\tif ((offset + len < offset) || (offset + len > spaceleft))\n+\t\treturn NULL;\n+\n+\tfdt_set_size_dt_struct(fdt, offset + len);\n+\treturn _fdt_offset_ptr_w(fdt, offset);\n+}\n+\n+int fdt_create(void *buf, int bufsize)\n+{\n+\tvoid *fdt = buf;\n+\n+\tif (bufsize < sizeof(struct fdt_header))\n+\t\treturn -FDT_ERR_NOSPACE;\n+\n+\tmemset(buf, 0, bufsize);\n+\n+\tfdt_set_magic(fdt, FDT_SW_MAGIC);\n+\tfdt_set_version(fdt, FDT_LAST_SUPPORTED_VERSION);\n+\tfdt_set_last_comp_version(fdt, FDT_FIRST_SUPPORTED_VERSION);\n+\tfdt_set_totalsize(fdt, bufsize);\n+\n+\tfdt_set_off_mem_rsvmap(fdt, FDT_ALIGN(sizeof(struct fdt_header),\n+\t\t\t\t\t sizeof(struct fdt_reserve_entry)));\n+\tfdt_set_off_dt_struct(fdt, fdt_off_mem_rsvmap(fdt));\n+\tfdt_set_off_dt_strings(fdt, bufsize);\n+\n+\treturn 0;\n+}\n+\n+int fdt_resize(void *fdt, void *buf, int bufsize)\n+{\n+\tsize_t headsize, tailsize;\n+\tchar *oldtail, *newtail;\n+\n+\tFDT_SW_CHECK_HEADER(fdt);\n+\n+\theadsize = fdt_off_dt_struct(fdt);\n+\ttailsize = fdt_size_dt_strings(fdt);\n+\n+\tif ((headsize + tailsize) > bufsize)\n+\t\treturn -FDT_ERR_NOSPACE;\n+\n+\toldtail = (char *)fdt + fdt_totalsize(fdt) - tailsize;\n+\tnewtail = (char *)buf + bufsize - tailsize;\n+\n+\t/* Two cases to avoid clobbering data if the old and new\n+\t * buffers partially overlap */\n+\tif (buf <= fdt) {\n+\t\tmemmove(buf, fdt, headsize);\n+\t\tmemmove(newtail, oldtail, tailsize);\n+\t} else {\n+\t\tmemmove(newtail, oldtail, tailsize);\n+\t\tmemmove(buf, fdt, headsize);\n+\t}\n+\n+\tfdt_set_off_dt_strings(buf, bufsize);\n+\tfdt_set_totalsize(buf, bufsize);\n+\n+\treturn 0;\n+}\n+\n+int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size)\n+{\n+\tstruct fdt_reserve_entry *re;\n+\tint offset;\n+\n+\tFDT_SW_CHECK_HEADER(fdt);\n+\n+\tif (fdt_size_dt_struct(fdt))\n+\t\treturn -FDT_ERR_BADSTATE;\n+\n+\toffset = fdt_off_dt_struct(fdt);\n+\tif ((offset + sizeof(*re)) > fdt_totalsize(fdt))\n+\t\treturn -FDT_ERR_NOSPACE;\n+\n+\tre = (struct fdt_reserve_entry *)((char *)fdt + offset);\n+\tre->address = cpu_to_fdt64(addr);\n+\tre->size = cpu_to_fdt64(size);\n+\n+\tfdt_set_off_dt_struct(fdt, offset + sizeof(*re));\n+\n+\treturn 0;\n+}\n+\n+int fdt_finish_reservemap(void *fdt)\n+{\n+\treturn fdt_add_reservemap_entry(fdt, 0, 0);\n+}\n+\n+int fdt_begin_node(void *fdt, const char *name)\n+{\n+\tstruct fdt_node_header *nh;\n+\tint namelen = strlen(name) + 1;\n+\n+\tFDT_SW_CHECK_HEADER(fdt);\n+\n+\tnh = _fdt_grab_space(fdt, sizeof(*nh) + FDT_TAGALIGN(namelen));\n+\tif (! nh)\n+\t\treturn -FDT_ERR_NOSPACE;\n+\n+\tnh->tag = cpu_to_fdt32(FDT_BEGIN_NODE);\n+\tmemcpy(nh->name, name, namelen);\n+\treturn 0;\n+}\n+\n+int fdt_end_node(void *fdt)\n+{\n+\tfdt32_t *en;\n+\n+\tFDT_SW_CHECK_HEADER(fdt);\n+\n+\ten = _fdt_grab_space(fdt, FDT_TAGSIZE);\n+\tif (! en)\n+\t\treturn -FDT_ERR_NOSPACE;\n+\n+\t*en = cpu_to_fdt32(FDT_END_NODE);\n+\treturn 0;\n+}\n+\n+static int _fdt_find_add_string(void *fdt, const char *s)\n+{\n+\tchar *strtab = (char *)fdt + fdt_totalsize(fdt);\n+\tconst char *p;\n+\tint strtabsize = fdt_size_dt_strings(fdt);\n+\tint len = strlen(s) + 1;\n+\tint struct_top, offset;\n+\n+\tp = _fdt_find_string(strtab - strtabsize, strtabsize, s);\n+\tif (p)\n+\t\treturn p - strtab;\n+\n+\t/* Add it */\n+\toffset = -strtabsize - len;\n+\tstruct_top = fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt);\n+\tif (fdt_totalsize(fdt) + offset < struct_top)\n+\t\treturn 0; /* no more room :( */\n+\n+\tmemcpy(strtab + offset, s, len);\n+\tfdt_set_size_dt_strings(fdt, strtabsize + len);\n+\treturn offset;\n+}\n+\n+int fdt_property(void *fdt, const char *name, const void *val, int len)\n+{\n+\tstruct fdt_property *prop;\n+\tint nameoff;\n+\n+\tFDT_SW_CHECK_HEADER(fdt);\n+\n+\tnameoff = _fdt_find_add_string(fdt, name);\n+\tif (nameoff == 0)\n+\t\treturn -FDT_ERR_NOSPACE;\n+\n+\tprop = _fdt_grab_space(fdt, sizeof(*prop) + FDT_TAGALIGN(len));\n+\tif (! prop)\n+\t\treturn -FDT_ERR_NOSPACE;\n+\n+\tprop->tag = cpu_to_fdt32(FDT_PROP);\n+\tprop->nameoff = cpu_to_fdt32(nameoff);\n+\tprop->len = cpu_to_fdt32(len);\n+\tmemcpy(prop->data, val, len);\n+\treturn 0;\n+}\n+\n+int fdt_finish(void *fdt)\n+{\n+\tchar *p = (char *)fdt;\n+\tfdt32_t *end;\n+\tint oldstroffset, newstroffset;\n+\tuint32_t tag;\n+\tint offset, nextoffset;\n+\n+\tFDT_SW_CHECK_HEADER(fdt);\n+\n+\t/* Add terminator */\n+\tend = _fdt_grab_space(fdt, sizeof(*end));\n+\tif (! end)\n+\t\treturn -FDT_ERR_NOSPACE;\n+\t*end = cpu_to_fdt32(FDT_END);\n+\n+\t/* Relocate the string table */\n+\toldstroffset = fdt_totalsize(fdt) - fdt_size_dt_strings(fdt);\n+\tnewstroffset = fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt);\n+\tmemmove(p + newstroffset, p + oldstroffset, fdt_size_dt_strings(fdt));\n+\tfdt_set_off_dt_strings(fdt, newstroffset);\n+\n+\t/* Walk the structure, correcting string offsets */\n+\toffset = 0;\n+\twhile ((tag = fdt_next_tag(fdt, offset, &nextoffset)) != FDT_END) {\n+\t\tif (tag == FDT_PROP) {\n+\t\t\tstruct fdt_property *prop =\n+\t\t\t\t_fdt_offset_ptr_w(fdt, offset);\n+\t\t\tint nameoff;\n+\n+\t\t\tnameoff = fdt32_to_cpu(prop->nameoff);\n+\t\t\tnameoff += fdt_size_dt_strings(fdt);\n+\t\t\tprop->nameoff = cpu_to_fdt32(nameoff);\n+\t\t}\n+\t\toffset = nextoffset;\n+\t}\n+\tif (nextoffset < 0)\n+\t\treturn nextoffset;\n+\n+\t/* Finally, adjust the header */\n+\tfdt_set_totalsize(fdt, newstroffset + fdt_size_dt_strings(fdt));\n+\tfdt_set_magic(fdt, FDT_MAGIC);\n+\treturn 0;\n+}\ndiff --git a/scripts/dtc/libfdt/fdt_wip.c b/scripts/dtc/libfdt/fdt_wip.c\nnew file mode 100644\nindex 000000000000..6aaab399929c\n--- /dev/null\n+++ b/scripts/dtc/libfdt/fdt_wip.c\n@@ -0,0 +1,139 @@\n+/*\n+ * libfdt - Flat Device Tree manipulation\n+ * Copyright (C) 2006 David Gibson, IBM Corporation.\n+ *\n+ * libfdt is dual licensed: you can use it either under the terms of\n+ * the GPL, or the BSD license, at your option.\n+ *\n+ * a) This library is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License as\n+ * published by the Free Software Foundation; either version 2 of the\n+ * License, or (at your option) any later version.\n+ *\n+ * This library is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public\n+ * License along with this library; if not, write to the Free\n+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,\n+ * MA 02110-1301 USA\n+ *\n+ * Alternatively,\n+ *\n+ * b) Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * 1. Redistributions of source code must retain the above\n+ * copyright notice, this list of conditions and the following\n+ * disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above\n+ * copyright notice, this list of conditions and the following\n+ * disclaimer in the documentation and/or other materials\n+ * provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\n+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\n+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+#include \"libfdt_env.h\"\n+\n+#include <fdt.h>\n+#include <libfdt.h>\n+\n+#include \"libfdt_internal.h\"\n+\n+int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset,\n+\t\t\t\t\tconst char *name, int namelen,\n+\t\t\t\t\tuint32_t idx, const void *val,\n+\t\t\t\t\tint len)\n+{\n+\tvoid *propval;\n+\tint proplen;\n+\n+\tpropval = fdt_getprop_namelen_w(fdt, nodeoffset, name, namelen,\n+\t\t\t\t\t&proplen);\n+\tif (!propval)\n+\t\treturn proplen;\n+\n+\tif (proplen < (len + idx))\n+\t\treturn -FDT_ERR_NOSPACE;\n+\n+\tmemcpy((char *)propval + idx, val, len);\n+\treturn 0;\n+}\n+\n+int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,\n+\t\t\tconst void *val, int len)\n+{\n+\tconst void *propval;\n+\tint proplen;\n+\n+\tpropval = fdt_getprop(fdt, nodeoffset, name, &proplen);\n+\tif (! propval)\n+\t\treturn proplen;\n+\n+\tif (proplen != len)\n+\t\treturn -FDT_ERR_NOSPACE;\n+\n+\treturn fdt_setprop_inplace_namelen_partial(fdt, nodeoffset, name,\n+\t\t\t\t\t\t strlen(name), 0,\n+\t\t\t\t\t\t val, len);\n+}\n+\n+static void _fdt_nop_region(void *start, int len)\n+{\n+\tfdt32_t *p;\n+\n+\tfor (p = start; (char *)p < ((char *)start + len); p++)\n+\t\t*p = cpu_to_fdt32(FDT_NOP);\n+}\n+\n+int fdt_nop_property(void *fdt, int nodeoffset, const char *name)\n+{\n+\tstruct fdt_property *prop;\n+\tint len;\n+\n+\tprop = fdt_get_property_w(fdt, nodeoffset, name, &len);\n+\tif (! prop)\n+\t\treturn len;\n+\n+\t_fdt_nop_region(prop, len + sizeof(*prop));\n+\n+\treturn 0;\n+}\n+\n+int _fdt_node_end_offset(void *fdt, int offset)\n+{\n+\tint depth = 0;\n+\n+\twhile ((offset >= 0) && (depth >= 0))\n+\t\toffset = fdt_next_node(fdt, offset, &depth);\n+\n+\treturn offset;\n+}\n+\n+int fdt_nop_node(void *fdt, int nodeoffset)\n+{\n+\tint endoffset;\n+\n+\tendoffset = _fdt_node_end_offset(fdt, nodeoffset);\n+\tif (endoffset < 0)\n+\t\treturn endoffset;\n+\n+\t_fdt_nop_region(fdt_offset_ptr_w(fdt, nodeoffset, 0),\n+\t\t\tendoffset - nodeoffset);\n+\treturn 0;\n+}\ndiff --git a/scripts/dtc/libfdt/libfdt.h b/scripts/dtc/libfdt/libfdt.h\nnew file mode 100644\nindex 000000000000..9e71bb9e03a7\n--- /dev/null\n+++ b/scripts/dtc/libfdt/libfdt.h\n@@ -0,0 +1,1833 @@\n+#ifndef _LIBFDT_H\n+#define _LIBFDT_H\n+/*\n+ * libfdt - Flat Device Tree manipulation\n+ * Copyright (C) 2006 David Gibson, IBM Corporation.\n+ *\n+ * libfdt is dual licensed: you can use it either under the terms of\n+ * the GPL, or the BSD license, at your option.\n+ *\n+ * a) This library is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License as\n+ * published by the Free Software Foundation; either version 2 of the\n+ * License, or (at your option) any later version.\n+ *\n+ * This library is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public\n+ * License along with this library; if not, write to the Free\n+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,\n+ * MA 02110-1301 USA\n+ *\n+ * Alternatively,\n+ *\n+ * b) Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * 1. Redistributions of source code must retain the above\n+ * copyright notice, this list of conditions and the following\n+ * disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above\n+ * copyright notice, this list of conditions and the following\n+ * disclaimer in the documentation and/or other materials\n+ * provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\n+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\n+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+#include \"libfdt_env.h\"\n+#include \"fdt.h\"\n+\n+#define FDT_FIRST_SUPPORTED_VERSION\t0x10\n+#define FDT_LAST_SUPPORTED_VERSION\t0x11\n+\n+/* Error codes: informative error codes */\n+#define FDT_ERR_NOTFOUND\t1\n+\t/* FDT_ERR_NOTFOUND: The requested node or property does not exist */\n+#define FDT_ERR_EXISTS\t\t2\n+\t/* FDT_ERR_EXISTS: Attempted to create a node or property which\n+\t * already exists */\n+#define FDT_ERR_NOSPACE\t\t3\n+\t/* FDT_ERR_NOSPACE: Operation needed to expand the device\n+\t * tree, but its buffer did not have sufficient space to\n+\t * contain the expanded tree. Use fdt_open_into() to move the\n+\t * device tree to a buffer with more space. */\n+\n+/* Error codes: codes for bad parameters */\n+#define FDT_ERR_BADOFFSET\t4\n+\t/* FDT_ERR_BADOFFSET: Function was passed a structure block\n+\t * offset which is out-of-bounds, or which points to an\n+\t * unsuitable part of the structure for the operation. */\n+#define FDT_ERR_BADPATH\t\t5\n+\t/* FDT_ERR_BADPATH: Function was passed a badly formatted path\n+\t * (e.g. missing a leading / for a function which requires an\n+\t * absolute path) */\n+#define FDT_ERR_BADPHANDLE\t6\n+\t/* FDT_ERR_BADPHANDLE: Function was passed an invalid phandle.\n+\t * This can be caused either by an invalid phandle property\n+\t * length, or the phandle value was either 0 or -1, which are\n+\t * not permitted. */\n+#define FDT_ERR_BADSTATE\t7\n+\t/* FDT_ERR_BADSTATE: Function was passed an incomplete device\n+\t * tree created by the sequential-write functions, which is\n+\t * not sufficiently complete for the requested operation. */\n+\n+/* Error codes: codes for bad device tree blobs */\n+#define FDT_ERR_TRUNCATED\t8\n+\t/* FDT_ERR_TRUNCATED: Structure block of the given device tree\n+\t * ends without an FDT_END tag. */\n+#define FDT_ERR_BADMAGIC\t9\n+\t/* FDT_ERR_BADMAGIC: Given \"device tree\" appears not to be a\n+\t * device tree at all - it is missing the flattened device\n+\t * tree magic number. */\n+#define FDT_ERR_BADVERSION\t10\n+\t/* FDT_ERR_BADVERSION: Given device tree has a version which\n+\t * can't be handled by the requested operation. For\n+\t * read-write functions, this may mean that fdt_open_into() is\n+\t * required to convert the tree to the expected version. */\n+#define FDT_ERR_BADSTRUCTURE\t11\n+\t/* FDT_ERR_BADSTRUCTURE: Given device tree has a corrupt\n+\t * structure block or other serious error (e.g. misnested\n+\t * nodes, or subnodes preceding properties). */\n+#define FDT_ERR_BADLAYOUT\t12\n+\t/* FDT_ERR_BADLAYOUT: For read-write functions, the given\n+\t * device tree has it's sub-blocks in an order that the\n+\t * function can't handle (memory reserve map, then structure,\n+\t * then strings). Use fdt_open_into() to reorganize the tree\n+\t * into a form suitable for the read-write operations. */\n+\n+/* \"Can't happen\" error indicating a bug in libfdt */\n+#define FDT_ERR_INTERNAL\t13\n+\t/* FDT_ERR_INTERNAL: libfdt has failed an internal assertion.\n+\t * Should never be returned, if it is, it indicates a bug in\n+\t * libfdt itself. */\n+\n+/* Errors in device tree content */\n+#define FDT_ERR_BADNCELLS\t14\n+\t/* FDT_ERR_BADNCELLS: Device tree has a #address-cells, #size-cells\n+\t * or similar property with a bad format or value */\n+\n+#define FDT_ERR_BADVALUE\t15\n+\t/* FDT_ERR_BADVALUE: Device tree has a property with an unexpected\n+\t * value. For example: a property expected to contain a string list\n+\t * is not NUL-terminated within the length of its value. */\n+\n+#define FDT_ERR_BADOVERLAY\t16\n+\t/* FDT_ERR_BADOVERLAY: The device tree overlay, while\n+\t * correctly structured, cannot be applied due to some\n+\t * unexpected or missing value, property or node. */\n+\n+#define FDT_ERR_NOPHANDLES\t17\n+\t/* FDT_ERR_NOPHANDLES: The device tree doesn't have any\n+\t * phandle available anymore without causing an overflow */\n+\n+#define FDT_ERR_MAX\t\t17\n+\n+/**********************************************************************/\n+/* Low-level functions (you probably don't need these) */\n+/**********************************************************************/\n+\n+const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen);\n+static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen)\n+{\n+\treturn (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen);\n+}\n+\n+uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset);\n+\n+/**********************************************************************/\n+/* Traversal functions */\n+/**********************************************************************/\n+\n+int fdt_next_node(const void *fdt, int offset, int *depth);\n+\n+/**\n+ * fdt_first_subnode() - get offset of first direct subnode\n+ *\n+ * @fdt:\tFDT blob\n+ * @offset:\tOffset of node to check\n+ * @return offset of first subnode, or -FDT_ERR_NOTFOUND if there is none\n+ */\n+int fdt_first_subnode(const void *fdt, int offset);\n+\n+/**\n+ * fdt_next_subnode() - get offset of next direct subnode\n+ *\n+ * After first calling fdt_first_subnode(), call this function repeatedly to\n+ * get direct subnodes of a parent node.\n+ *\n+ * @fdt:\tFDT blob\n+ * @offset:\tOffset of previous subnode\n+ * @return offset of next subnode, or -FDT_ERR_NOTFOUND if there are no more\n+ * subnodes\n+ */\n+int fdt_next_subnode(const void *fdt, int offset);\n+\n+/**\n+ * fdt_for_each_subnode - iterate over all subnodes of a parent\n+ *\n+ * @node:\tchild node (int, lvalue)\n+ * @fdt:\tFDT blob (const void *)\n+ * @parent:\tparent node (int)\n+ *\n+ * This is actually a wrapper around a for loop and would be used like so:\n+ *\n+ *\tfdt_for_each_subnode(node, fdt, parent) {\n+ *\t\tUse node\n+ *\t\t...\n+ *\t}\n+ *\n+ *\tif ((node < 0) && (node != -FDT_ERR_NOT_FOUND)) {\n+ *\t\tError handling\n+ *\t}\n+ *\n+ * Note that this is implemented as a macro and @node is used as\n+ * iterator in the loop. The parent variable be constant or even a\n+ * literal.\n+ *\n+ */\n+#define fdt_for_each_subnode(node, fdt, parent)\t\t\\\n+\tfor (node = fdt_first_subnode(fdt, parent);\t\\\n+\t node >= 0;\t\t\t\t\t\\\n+\t node = fdt_next_subnode(fdt, node))\n+\n+/**********************************************************************/\n+/* General functions */\n+/**********************************************************************/\n+\n+#define fdt_get_header(fdt, field) \\\n+\t(fdt32_to_cpu(((const struct fdt_header *)(fdt))->field))\n+#define fdt_magic(fdt)\t\t\t(fdt_get_header(fdt, magic))\n+#define fdt_totalsize(fdt)\t\t(fdt_get_header(fdt, totalsize))\n+#define fdt_off_dt_struct(fdt)\t\t(fdt_get_header(fdt, off_dt_struct))\n+#define fdt_off_dt_strings(fdt)\t\t(fdt_get_header(fdt, off_dt_strings))\n+#define fdt_off_mem_rsvmap(fdt)\t\t(fdt_get_header(fdt, off_mem_rsvmap))\n+#define fdt_version(fdt)\t\t(fdt_get_header(fdt, version))\n+#define fdt_last_comp_version(fdt)\t(fdt_get_header(fdt, last_comp_version))\n+#define fdt_boot_cpuid_phys(fdt)\t(fdt_get_header(fdt, boot_cpuid_phys))\n+#define fdt_size_dt_strings(fdt)\t(fdt_get_header(fdt, size_dt_strings))\n+#define fdt_size_dt_struct(fdt)\t\t(fdt_get_header(fdt, size_dt_struct))\n+\n+#define __fdt_set_hdr(name) \\\n+\tstatic inline void fdt_set_##name(void *fdt, uint32_t val) \\\n+\t{ \\\n+\t\tstruct fdt_header *fdth = (struct fdt_header *)fdt; \\\n+\t\tfdth->name = cpu_to_fdt32(val); \\\n+\t}\n+__fdt_set_hdr(magic);\n+__fdt_set_hdr(totalsize);\n+__fdt_set_hdr(off_dt_struct);\n+__fdt_set_hdr(off_dt_strings);\n+__fdt_set_hdr(off_mem_rsvmap);\n+__fdt_set_hdr(version);\n+__fdt_set_hdr(last_comp_version);\n+__fdt_set_hdr(boot_cpuid_phys);\n+__fdt_set_hdr(size_dt_strings);\n+__fdt_set_hdr(size_dt_struct);\n+#undef __fdt_set_hdr\n+\n+/**\n+ * fdt_check_header - sanity check a device tree or possible device tree\n+ * @fdt: pointer to data which might be a flattened device tree\n+ *\n+ * fdt_check_header() checks that the given buffer contains what\n+ * appears to be a flattened device tree with sane information in its\n+ * header.\n+ *\n+ * returns:\n+ * 0, if the buffer appears to contain a valid device tree\n+ * -FDT_ERR_BADMAGIC,\n+ * -FDT_ERR_BADVERSION,\n+ * -FDT_ERR_BADSTATE, standard meanings, as above\n+ */\n+int fdt_check_header(const void *fdt);\n+\n+/**\n+ * fdt_move - move a device tree around in memory\n+ * @fdt: pointer to the device tree to move\n+ * @buf: pointer to memory where the device is to be moved\n+ * @bufsize: size of the memory space at buf\n+ *\n+ * fdt_move() relocates, if possible, the device tree blob located at\n+ * fdt to the buffer at buf of size bufsize. The buffer may overlap\n+ * with the existing device tree blob at fdt. Therefore,\n+ * fdt_move(fdt, fdt, fdt_totalsize(fdt))\n+ * should always succeed.\n+ *\n+ * returns:\n+ * 0, on success\n+ * -FDT_ERR_NOSPACE, bufsize is insufficient to contain the device tree\n+ * -FDT_ERR_BADMAGIC,\n+ * -FDT_ERR_BADVERSION,\n+ * -FDT_ERR_BADSTATE, standard meanings\n+ */\n+int fdt_move(const void *fdt, void *buf, int bufsize);\n+\n+/**********************************************************************/\n+/* Read-only functions */\n+/**********************************************************************/\n+\n+/**\n+ * fdt_string - retrieve a string from the strings block of a device tree\n+ * @fdt: pointer to the device tree blob\n+ * @stroffset: offset of the string within the strings block (native endian)\n+ *\n+ * fdt_string() retrieves a pointer to a single string from the\n+ * strings block of the device tree blob at fdt.\n+ *\n+ * returns:\n+ * a pointer to the string, on success\n+ * NULL, if stroffset is out of bounds\n+ */\n+const char *fdt_string(const void *fdt, int stroffset);\n+\n+/**\n+ * fdt_get_max_phandle - retrieves the highest phandle in a tree\n+ * @fdt: pointer to the device tree blob\n+ *\n+ * fdt_get_max_phandle retrieves the highest phandle in the given\n+ * device tree. This will ignore badly formatted phandles, or phandles\n+ * with a value of 0 or -1.\n+ *\n+ * returns:\n+ * the highest phandle on success\n+ * 0, if no phandle was found in the device tree\n+ * -1, if an error occurred\n+ */\n+uint32_t fdt_get_max_phandle(const void *fdt);\n+\n+/**\n+ * fdt_num_mem_rsv - retrieve the number of memory reserve map entries\n+ * @fdt: pointer to the device tree blob\n+ *\n+ * Returns the number of entries in the device tree blob's memory\n+ * reservation map. This does not include the terminating 0,0 entry\n+ * or any other (0,0) entries reserved for expansion.\n+ *\n+ * returns:\n+ * the number of entries\n+ */\n+int fdt_num_mem_rsv(const void *fdt);\n+\n+/**\n+ * fdt_get_mem_rsv - retrieve one memory reserve map entry\n+ * @fdt: pointer to the device tree blob\n+ * @address, @size: pointers to 64-bit variables\n+ *\n+ * On success, *address and *size will contain the address and size of\n+ * the n-th reserve map entry from the device tree blob, in\n+ * native-endian format.\n+ *\n+ * returns:\n+ * 0, on success\n+ * -FDT_ERR_BADMAGIC,\n+ * -FDT_ERR_BADVERSION,\n+ * -FDT_ERR_BADSTATE, standard meanings\n+ */\n+int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size);\n+\n+/**\n+ * fdt_subnode_offset_namelen - find a subnode based on substring\n+ * @fdt: pointer to the device tree blob\n+ * @parentoffset: structure block offset of a node\n+ * @name: name of the subnode to locate\n+ * @namelen: number of characters of name to consider\n+ *\n+ * Identical to fdt_subnode_offset(), but only examine the first\n+ * namelen characters of name for matching the subnode name. This is\n+ * useful for finding subnodes based on a portion of a larger string,\n+ * such as a full path.\n+ */\n+int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,\n+\t\t\t const char *name, int namelen);\n+/**\n+ * fdt_subnode_offset - find a subnode of a given node\n+ * @fdt: pointer to the device tree blob\n+ * @parentoffset: structure block offset of a node\n+ * @name: name of the subnode to locate\n+ *\n+ * fdt_subnode_offset() finds a subnode of the node at structure block\n+ * offset parentoffset with the given name. name may include a unit\n+ * address, in which case fdt_subnode_offset() will find the subnode\n+ * with that unit address, or the unit address may be omitted, in\n+ * which case fdt_subnode_offset() will find an arbitrary subnode\n+ * whose name excluding unit address matches the given name.\n+ *\n+ * returns:\n+ *\tstructure block offset of the requested subnode (>=0), on success\n+ *\t-FDT_ERR_NOTFOUND, if the requested subnode does not exist\n+ *\t-FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE\n+ *\t\ttag\n+ *\t-FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTATE,\n+ *\t-FDT_ERR_BADSTRUCTURE,\n+ *\t-FDT_ERR_TRUNCATED, standard meanings.\n+ */\n+int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name);\n+\n+/**\n+ * fdt_path_offset_namelen - find a tree node by its full path\n+ * @fdt: pointer to the device tree blob\n+ * @path: full path of the node to locate\n+ * @namelen: number of characters of path to consider\n+ *\n+ * Identical to fdt_path_offset(), but only consider the first namelen\n+ * characters of path as the path name.\n+ */\n+int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen);\n+\n+/**\n+ * fdt_path_offset - find a tree node by its full path\n+ * @fdt: pointer to the device tree blob\n+ * @path: full path of the node to locate\n+ *\n+ * fdt_path_offset() finds a node of a given path in the device tree.\n+ * Each path component may omit the unit address portion, but the\n+ * results of this are undefined if any such path component is\n+ * ambiguous (that is if there are multiple nodes at the relevant\n+ * level matching the given component, differentiated only by unit\n+ * address).\n+ *\n+ * returns:\n+ *\tstructure block offset of the node with the requested path (>=0), on\n+ *\t\tsuccess\n+ *\t-FDT_ERR_BADPATH, given path does not begin with '/' or is invalid\n+ *\t-FDT_ERR_NOTFOUND, if the requested node does not exist\n+ * -FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTATE,\n+ *\t-FDT_ERR_BADSTRUCTURE,\n+ *\t-FDT_ERR_TRUNCATED, standard meanings.\n+ */\n+int fdt_path_offset(const void *fdt, const char *path);\n+\n+/**\n+ * fdt_get_name - retrieve the name of a given node\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: structure block offset of the starting node\n+ * @lenp: pointer to an integer variable (will be overwritten) or NULL\n+ *\n+ * fdt_get_name() retrieves the name (including unit address) of the\n+ * device tree node at structure block offset nodeoffset. If lenp is\n+ * non-NULL, the length of this name is also returned, in the integer\n+ * pointed to by lenp.\n+ *\n+ * returns:\n+ *\tpointer to the node's name, on success\n+ *\t\tIf lenp is non-NULL, *lenp contains the length of that name\n+ *\t\t\t(>=0)\n+ *\tNULL, on error\n+ *\t\tif lenp is non-NULL *lenp contains an error code (<0):\n+ *\t\t-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE\n+ *\t\t\ttag\n+ *\t\t-FDT_ERR_BADMAGIC,\n+ *\t\t-FDT_ERR_BADVERSION,\n+ *\t\t-FDT_ERR_BADSTATE, standard meanings\n+ */\n+const char *fdt_get_name(const void *fdt, int nodeoffset, int *lenp);\n+\n+/**\n+ * fdt_first_property_offset - find the offset of a node's first property\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: structure block offset of a node\n+ *\n+ * fdt_first_property_offset() finds the first property of the node at\n+ * the given structure block offset.\n+ *\n+ * returns:\n+ *\tstructure block offset of the property (>=0), on success\n+ *\t-FDT_ERR_NOTFOUND, if the requested node has no properties\n+ *\t-FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_BEGIN_NODE tag\n+ * -FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTATE,\n+ *\t-FDT_ERR_BADSTRUCTURE,\n+ *\t-FDT_ERR_TRUNCATED, standard meanings.\n+ */\n+int fdt_first_property_offset(const void *fdt, int nodeoffset);\n+\n+/**\n+ * fdt_next_property_offset - step through a node's properties\n+ * @fdt: pointer to the device tree blob\n+ * @offset: structure block offset of a property\n+ *\n+ * fdt_next_property_offset() finds the property immediately after the\n+ * one at the given structure block offset. This will be a property\n+ * of the same node as the given property.\n+ *\n+ * returns:\n+ *\tstructure block offset of the next property (>=0), on success\n+ *\t-FDT_ERR_NOTFOUND, if the given property is the last in its node\n+ *\t-FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_PROP tag\n+ * -FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTATE,\n+ *\t-FDT_ERR_BADSTRUCTURE,\n+ *\t-FDT_ERR_TRUNCATED, standard meanings.\n+ */\n+int fdt_next_property_offset(const void *fdt, int offset);\n+\n+/**\n+ * fdt_for_each_property_offset - iterate over all properties of a node\n+ *\n+ * @property_offset:\tproperty offset (int, lvalue)\n+ * @fdt:\t\tFDT blob (const void *)\n+ * @node:\t\tnode offset (int)\n+ *\n+ * This is actually a wrapper around a for loop and would be used like so:\n+ *\n+ *\tfdt_for_each_property_offset(property, fdt, node) {\n+ *\t\tUse property\n+ *\t\t...\n+ *\t}\n+ *\n+ *\tif ((property < 0) && (property != -FDT_ERR_NOT_FOUND)) {\n+ *\t\tError handling\n+ *\t}\n+ *\n+ * Note that this is implemented as a macro and property is used as\n+ * iterator in the loop. The node variable can be constant or even a\n+ * literal.\n+ */\n+#define fdt_for_each_property_offset(property, fdt, node)\t\\\n+\tfor (property = fdt_first_property_offset(fdt, node);\t\\\n+\t property >= 0;\t\t\t\t\t\\\n+\t property = fdt_next_property_offset(fdt, property))\n+\n+/**\n+ * fdt_get_property_by_offset - retrieve the property at a given offset\n+ * @fdt: pointer to the device tree blob\n+ * @offset: offset of the property to retrieve\n+ * @lenp: pointer to an integer variable (will be overwritten) or NULL\n+ *\n+ * fdt_get_property_by_offset() retrieves a pointer to the\n+ * fdt_property structure within the device tree blob at the given\n+ * offset. If lenp is non-NULL, the length of the property value is\n+ * also returned, in the integer pointed to by lenp.\n+ *\n+ * returns:\n+ *\tpointer to the structure representing the property\n+ *\t\tif lenp is non-NULL, *lenp contains the length of the property\n+ *\t\tvalue (>=0)\n+ *\tNULL, on error\n+ *\t\tif lenp is non-NULL, *lenp contains an error code (<0):\n+ *\t\t-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag\n+ *\t\t-FDT_ERR_BADMAGIC,\n+ *\t\t-FDT_ERR_BADVERSION,\n+ *\t\t-FDT_ERR_BADSTATE,\n+ *\t\t-FDT_ERR_BADSTRUCTURE,\n+ *\t\t-FDT_ERR_TRUNCATED, standard meanings\n+ */\n+const struct fdt_property *fdt_get_property_by_offset(const void *fdt,\n+\t\t\t\t\t\t int offset,\n+\t\t\t\t\t\t int *lenp);\n+\n+/**\n+ * fdt_get_property_namelen - find a property based on substring\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: offset of the node whose property to find\n+ * @name: name of the property to find\n+ * @namelen: number of characters of name to consider\n+ * @lenp: pointer to an integer variable (will be overwritten) or NULL\n+ *\n+ * Identical to fdt_get_property(), but only examine the first namelen\n+ * characters of name for matching the property name.\n+ */\n+const struct fdt_property *fdt_get_property_namelen(const void *fdt,\n+\t\t\t\t\t\t int nodeoffset,\n+\t\t\t\t\t\t const char *name,\n+\t\t\t\t\t\t int namelen, int *lenp);\n+\n+/**\n+ * fdt_get_property - find a given property in a given node\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: offset of the node whose property to find\n+ * @name: name of the property to find\n+ * @lenp: pointer to an integer variable (will be overwritten) or NULL\n+ *\n+ * fdt_get_property() retrieves a pointer to the fdt_property\n+ * structure within the device tree blob corresponding to the property\n+ * named 'name' of the node at offset nodeoffset. If lenp is\n+ * non-NULL, the length of the property value is also returned, in the\n+ * integer pointed to by lenp.\n+ *\n+ * returns:\n+ *\tpointer to the structure representing the property\n+ *\t\tif lenp is non-NULL, *lenp contains the length of the property\n+ *\t\tvalue (>=0)\n+ *\tNULL, on error\n+ *\t\tif lenp is non-NULL, *lenp contains an error code (<0):\n+ *\t\t-FDT_ERR_NOTFOUND, node does not have named property\n+ *\t\t-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE\n+ *\t\t\ttag\n+ *\t\t-FDT_ERR_BADMAGIC,\n+ *\t\t-FDT_ERR_BADVERSION,\n+ *\t\t-FDT_ERR_BADSTATE,\n+ *\t\t-FDT_ERR_BADSTRUCTURE,\n+ *\t\t-FDT_ERR_TRUNCATED, standard meanings\n+ */\n+const struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset,\n+\t\t\t\t\t const char *name, int *lenp);\n+static inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset,\n+\t\t\t\t\t\t const char *name,\n+\t\t\t\t\t\t int *lenp)\n+{\n+\treturn (struct fdt_property *)(uintptr_t)\n+\t\tfdt_get_property(fdt, nodeoffset, name, lenp);\n+}\n+\n+/**\n+ * fdt_getprop_by_offset - retrieve the value of a property at a given offset\n+ * @fdt: pointer to the device tree blob\n+ * @ffset: offset of the property to read\n+ * @namep: pointer to a string variable (will be overwritten) or NULL\n+ * @lenp: pointer to an integer variable (will be overwritten) or NULL\n+ *\n+ * fdt_getprop_by_offset() retrieves a pointer to the value of the\n+ * property at structure block offset 'offset' (this will be a pointer\n+ * to within the device blob itself, not a copy of the value). If\n+ * lenp is non-NULL, the length of the property value is also\n+ * returned, in the integer pointed to by lenp. If namep is non-NULL,\n+ * the property's namne will also be returned in the char * pointed to\n+ * by namep (this will be a pointer to within the device tree's string\n+ * block, not a new copy of the name).\n+ *\n+ * returns:\n+ *\tpointer to the property's value\n+ *\t\tif lenp is non-NULL, *lenp contains the length of the property\n+ *\t\tvalue (>=0)\n+ *\t\tif namep is non-NULL *namep contiains a pointer to the property\n+ *\t\tname.\n+ *\tNULL, on error\n+ *\t\tif lenp is non-NULL, *lenp contains an error code (<0):\n+ *\t\t-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag\n+ *\t\t-FDT_ERR_BADMAGIC,\n+ *\t\t-FDT_ERR_BADVERSION,\n+ *\t\t-FDT_ERR_BADSTATE,\n+ *\t\t-FDT_ERR_BADSTRUCTURE,\n+ *\t\t-FDT_ERR_TRUNCATED, standard meanings\n+ */\n+const void *fdt_getprop_by_offset(const void *fdt, int offset,\n+\t\t\t\t const char **namep, int *lenp);\n+\n+/**\n+ * fdt_getprop_namelen - get property value based on substring\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: offset of the node whose property to find\n+ * @name: name of the property to find\n+ * @namelen: number of characters of name to consider\n+ * @lenp: pointer to an integer variable (will be overwritten) or NULL\n+ *\n+ * Identical to fdt_getprop(), but only examine the first namelen\n+ * characters of name for matching the property name.\n+ */\n+const void *fdt_getprop_namelen(const void *fdt, int nodeoffset,\n+\t\t\t\tconst char *name, int namelen, int *lenp);\n+static inline void *fdt_getprop_namelen_w(void *fdt, int nodeoffset,\n+\t\t\t\t\t const char *name, int namelen,\n+\t\t\t\t\t int *lenp)\n+{\n+\treturn (void *)(uintptr_t)fdt_getprop_namelen(fdt, nodeoffset, name,\n+\t\t\t\t\t\t namelen, lenp);\n+}\n+\n+/**\n+ * fdt_getprop - retrieve the value of a given property\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: offset of the node whose property to find\n+ * @name: name of the property to find\n+ * @lenp: pointer to an integer variable (will be overwritten) or NULL\n+ *\n+ * fdt_getprop() retrieves a pointer to the value of the property\n+ * named 'name' of the node at offset nodeoffset (this will be a\n+ * pointer to within the device blob itself, not a copy of the value).\n+ * If lenp is non-NULL, the length of the property value is also\n+ * returned, in the integer pointed to by lenp.\n+ *\n+ * returns:\n+ *\tpointer to the property's value\n+ *\t\tif lenp is non-NULL, *lenp contains the length of the property\n+ *\t\tvalue (>=0)\n+ *\tNULL, on error\n+ *\t\tif lenp is non-NULL, *lenp contains an error code (<0):\n+ *\t\t-FDT_ERR_NOTFOUND, node does not have named property\n+ *\t\t-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE\n+ *\t\t\ttag\n+ *\t\t-FDT_ERR_BADMAGIC,\n+ *\t\t-FDT_ERR_BADVERSION,\n+ *\t\t-FDT_ERR_BADSTATE,\n+ *\t\t-FDT_ERR_BADSTRUCTURE,\n+ *\t\t-FDT_ERR_TRUNCATED, standard meanings\n+ */\n+const void *fdt_getprop(const void *fdt, int nodeoffset,\n+\t\t\tconst char *name, int *lenp);\n+static inline void *fdt_getprop_w(void *fdt, int nodeoffset,\n+\t\t\t\t const char *name, int *lenp)\n+{\n+\treturn (void *)(uintptr_t)fdt_getprop(fdt, nodeoffset, name, lenp);\n+}\n+\n+/**\n+ * fdt_get_phandle - retrieve the phandle of a given node\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: structure block offset of the node\n+ *\n+ * fdt_get_phandle() retrieves the phandle of the device tree node at\n+ * structure block offset nodeoffset.\n+ *\n+ * returns:\n+ *\tthe phandle of the node at nodeoffset, on success (!= 0, != -1)\n+ *\t0, if the node has no phandle, or another error occurs\n+ */\n+uint32_t fdt_get_phandle(const void *fdt, int nodeoffset);\n+\n+/**\n+ * fdt_get_alias_namelen - get alias based on substring\n+ * @fdt: pointer to the device tree blob\n+ * @name: name of the alias th look up\n+ * @namelen: number of characters of name to consider\n+ *\n+ * Identical to fdt_get_alias(), but only examine the first namelen\n+ * characters of name for matching the alias name.\n+ */\n+const char *fdt_get_alias_namelen(const void *fdt,\n+\t\t\t\t const char *name, int namelen);\n+\n+/**\n+ * fdt_get_alias - retrieve the path referenced by a given alias\n+ * @fdt: pointer to the device tree blob\n+ * @name: name of the alias th look up\n+ *\n+ * fdt_get_alias() retrieves the value of a given alias. That is, the\n+ * value of the property named 'name' in the node /aliases.\n+ *\n+ * returns:\n+ *\ta pointer to the expansion of the alias named 'name', if it exists\n+ *\tNULL, if the given alias or the /aliases node does not exist\n+ */\n+const char *fdt_get_alias(const void *fdt, const char *name);\n+\n+/**\n+ * fdt_get_path - determine the full path of a node\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: offset of the node whose path to find\n+ * @buf: character buffer to contain the returned path (will be overwritten)\n+ * @buflen: size of the character buffer at buf\n+ *\n+ * fdt_get_path() computes the full path of the node at offset\n+ * nodeoffset, and records that path in the buffer at buf.\n+ *\n+ * NOTE: This function is expensive, as it must scan the device tree\n+ * structure from the start to nodeoffset.\n+ *\n+ * returns:\n+ *\t0, on success\n+ *\t\tbuf contains the absolute path of the node at\n+ *\t\tnodeoffset, as a NUL-terminated string.\n+ *\t-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag\n+ *\t-FDT_ERR_NOSPACE, the path of the given node is longer than (bufsize-1)\n+ *\t\tcharacters and will not fit in the given buffer.\n+ *\t-FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTATE,\n+ *\t-FDT_ERR_BADSTRUCTURE, standard meanings\n+ */\n+int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen);\n+\n+/**\n+ * fdt_supernode_atdepth_offset - find a specific ancestor of a node\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: offset of the node whose parent to find\n+ * @supernodedepth: depth of the ancestor to find\n+ * @nodedepth: pointer to an integer variable (will be overwritten) or NULL\n+ *\n+ * fdt_supernode_atdepth_offset() finds an ancestor of the given node\n+ * at a specific depth from the root (where the root itself has depth\n+ * 0, its immediate subnodes depth 1 and so forth). So\n+ *\tfdt_supernode_atdepth_offset(fdt, nodeoffset, 0, NULL);\n+ * will always return 0, the offset of the root node. If the node at\n+ * nodeoffset has depth D, then:\n+ *\tfdt_supernode_atdepth_offset(fdt, nodeoffset, D, NULL);\n+ * will return nodeoffset itself.\n+ *\n+ * NOTE: This function is expensive, as it must scan the device tree\n+ * structure from the start to nodeoffset.\n+ *\n+ * returns:\n+ *\tstructure block offset of the node at node offset's ancestor\n+ *\t\tof depth supernodedepth (>=0), on success\n+ *\t-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag\n+ *\t-FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of\n+ *\t\tnodeoffset\n+ *\t-FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTATE,\n+ *\t-FDT_ERR_BADSTRUCTURE, standard meanings\n+ */\n+int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset,\n+\t\t\t\t int supernodedepth, int *nodedepth);\n+\n+/**\n+ * fdt_node_depth - find the depth of a given node\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: offset of the node whose parent to find\n+ *\n+ * fdt_node_depth() finds the depth of a given node. The root node\n+ * has depth 0, its immediate subnodes depth 1 and so forth.\n+ *\n+ * NOTE: This function is expensive, as it must scan the device tree\n+ * structure from the start to nodeoffset.\n+ *\n+ * returns:\n+ *\tdepth of the node at nodeoffset (>=0), on success\n+ *\t-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag\n+ *\t-FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTATE,\n+ *\t-FDT_ERR_BADSTRUCTURE, standard meanings\n+ */\n+int fdt_node_depth(const void *fdt, int nodeoffset);\n+\n+/**\n+ * fdt_parent_offset - find the parent of a given node\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: offset of the node whose parent to find\n+ *\n+ * fdt_parent_offset() locates the parent node of a given node (that\n+ * is, it finds the offset of the node which contains the node at\n+ * nodeoffset as a subnode).\n+ *\n+ * NOTE: This function is expensive, as it must scan the device tree\n+ * structure from the start to nodeoffset, *twice*.\n+ *\n+ * returns:\n+ *\tstructure block offset of the parent of the node at nodeoffset\n+ *\t\t(>=0), on success\n+ *\t-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag\n+ *\t-FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTATE,\n+ *\t-FDT_ERR_BADSTRUCTURE, standard meanings\n+ */\n+int fdt_parent_offset(const void *fdt, int nodeoffset);\n+\n+/**\n+ * fdt_node_offset_by_prop_value - find nodes with a given property value\n+ * @fdt: pointer to the device tree blob\n+ * @startoffset: only find nodes after this offset\n+ * @propname: property name to check\n+ * @propval: property value to search for\n+ * @proplen: length of the value in propval\n+ *\n+ * fdt_node_offset_by_prop_value() returns the offset of the first\n+ * node after startoffset, which has a property named propname whose\n+ * value is of length proplen and has value equal to propval; or if\n+ * startoffset is -1, the very first such node in the tree.\n+ *\n+ * To iterate through all nodes matching the criterion, the following\n+ * idiom can be used:\n+ *\toffset = fdt_node_offset_by_prop_value(fdt, -1, propname,\n+ *\t\t\t\t\t propval, proplen);\n+ *\twhile (offset != -FDT_ERR_NOTFOUND) {\n+ *\t\t// other code here\n+ *\t\toffset = fdt_node_offset_by_prop_value(fdt, offset, propname,\n+ *\t\t\t\t\t\t propval, proplen);\n+ *\t}\n+ *\n+ * Note the -1 in the first call to the function, if 0 is used here\n+ * instead, the function will never locate the root node, even if it\n+ * matches the criterion.\n+ *\n+ * returns:\n+ *\tstructure block offset of the located node (>= 0, >startoffset),\n+ *\t\t on success\n+ *\t-FDT_ERR_NOTFOUND, no node matching the criterion exists in the\n+ *\t\ttree after startoffset\n+ *\t-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag\n+ *\t-FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTATE,\n+ *\t-FDT_ERR_BADSTRUCTURE, standard meanings\n+ */\n+int fdt_node_offset_by_prop_value(const void *fdt, int startoffset,\n+\t\t\t\t const char *propname,\n+\t\t\t\t const void *propval, int proplen);\n+\n+/**\n+ * fdt_node_offset_by_phandle - find the node with a given phandle\n+ * @fdt: pointer to the device tree blob\n+ * @phandle: phandle value\n+ *\n+ * fdt_node_offset_by_phandle() returns the offset of the node\n+ * which has the given phandle value. If there is more than one node\n+ * in the tree with the given phandle (an invalid tree), results are\n+ * undefined.\n+ *\n+ * returns:\n+ *\tstructure block offset of the located node (>= 0), on success\n+ *\t-FDT_ERR_NOTFOUND, no node with that phandle exists\n+ *\t-FDT_ERR_BADPHANDLE, given phandle value was invalid (0 or -1)\n+ *\t-FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTATE,\n+ *\t-FDT_ERR_BADSTRUCTURE, standard meanings\n+ */\n+int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle);\n+\n+/**\n+ * fdt_node_check_compatible: check a node's compatible property\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: offset of a tree node\n+ * @compatible: string to match against\n+ *\n+ *\n+ * fdt_node_check_compatible() returns 0 if the given node contains a\n+ * 'compatible' property with the given string as one of its elements,\n+ * it returns non-zero otherwise, or on error.\n+ *\n+ * returns:\n+ *\t0, if the node has a 'compatible' property listing the given string\n+ *\t1, if the node has a 'compatible' property, but it does not list\n+ *\t\tthe given string\n+ *\t-FDT_ERR_NOTFOUND, if the given node has no 'compatible' property\n+ *\t-FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag\n+ *\t-FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTATE,\n+ *\t-FDT_ERR_BADSTRUCTURE, standard meanings\n+ */\n+int fdt_node_check_compatible(const void *fdt, int nodeoffset,\n+\t\t\t const char *compatible);\n+\n+/**\n+ * fdt_node_offset_by_compatible - find nodes with a given 'compatible' value\n+ * @fdt: pointer to the device tree blob\n+ * @startoffset: only find nodes after this offset\n+ * @compatible: 'compatible' string to match against\n+ *\n+ * fdt_node_offset_by_compatible() returns the offset of the first\n+ * node after startoffset, which has a 'compatible' property which\n+ * lists the given compatible string; or if startoffset is -1, the\n+ * very first such node in the tree.\n+ *\n+ * To iterate through all nodes matching the criterion, the following\n+ * idiom can be used:\n+ *\toffset = fdt_node_offset_by_compatible(fdt, -1, compatible);\n+ *\twhile (offset != -FDT_ERR_NOTFOUND) {\n+ *\t\t// other code here\n+ *\t\toffset = fdt_node_offset_by_compatible(fdt, offset, compatible);\n+ *\t}\n+ *\n+ * Note the -1 in the first call to the function, if 0 is used here\n+ * instead, the function will never locate the root node, even if it\n+ * matches the criterion.\n+ *\n+ * returns:\n+ *\tstructure block offset of the located node (>= 0, >startoffset),\n+ *\t\t on success\n+ *\t-FDT_ERR_NOTFOUND, no node matching the criterion exists in the\n+ *\t\ttree after startoffset\n+ *\t-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag\n+ *\t-FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTATE,\n+ *\t-FDT_ERR_BADSTRUCTURE, standard meanings\n+ */\n+int fdt_node_offset_by_compatible(const void *fdt, int startoffset,\n+\t\t\t\t const char *compatible);\n+\n+/**\n+ * fdt_stringlist_contains - check a string list property for a string\n+ * @strlist: Property containing a list of strings to check\n+ * @listlen: Length of property\n+ * @str: String to search for\n+ *\n+ * This is a utility function provided for convenience. The list contains\n+ * one or more strings, each terminated by \\0, as is found in a device tree\n+ * \"compatible\" property.\n+ *\n+ * @return: 1 if the string is found in the list, 0 not found, or invalid list\n+ */\n+int fdt_stringlist_contains(const char *strlist, int listlen, const char *str);\n+\n+/**\n+ * fdt_stringlist_count - count the number of strings in a string list\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: offset of a tree node\n+ * @property: name of the property containing the string list\n+ * @return:\n+ * the number of strings in the given property\n+ * -FDT_ERR_BADVALUE if the property value is not NUL-terminated\n+ * -FDT_ERR_NOTFOUND if the property does not exist\n+ */\n+int fdt_stringlist_count(const void *fdt, int nodeoffset, const char *property);\n+\n+/**\n+ * fdt_stringlist_search - find a string in a string list and return its index\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: offset of a tree node\n+ * @property: name of the property containing the string list\n+ * @string: string to look up in the string list\n+ *\n+ * Note that it is possible for this function to succeed on property values\n+ * that are not NUL-terminated. That's because the function will stop after\n+ * finding the first occurrence of @string. This can for example happen with\n+ * small-valued cell properties, such as #address-cells, when searching for\n+ * the empty string.\n+ *\n+ * @return:\n+ * the index of the string in the list of strings\n+ * -FDT_ERR_BADVALUE if the property value is not NUL-terminated\n+ * -FDT_ERR_NOTFOUND if the property does not exist or does not contain\n+ * the given string\n+ */\n+int fdt_stringlist_search(const void *fdt, int nodeoffset, const char *property,\n+\t\t\t const char *string);\n+\n+/**\n+ * fdt_stringlist_get() - obtain the string at a given index in a string list\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: offset of a tree node\n+ * @property: name of the property containing the string list\n+ * @index: index of the string to return\n+ * @lenp: return location for the string length or an error code on failure\n+ *\n+ * Note that this will successfully extract strings from properties with\n+ * non-NUL-terminated values. For example on small-valued cell properties\n+ * this function will return the empty string.\n+ *\n+ * If non-NULL, the length of the string (on success) or a negative error-code\n+ * (on failure) will be stored in the integer pointer to by lenp.\n+ *\n+ * @return:\n+ * A pointer to the string at the given index in the string list or NULL on\n+ * failure. On success the length of the string will be stored in the memory\n+ * location pointed to by the lenp parameter, if non-NULL. On failure one of\n+ * the following negative error codes will be returned in the lenp parameter\n+ * (if non-NULL):\n+ * -FDT_ERR_BADVALUE if the property value is not NUL-terminated\n+ * -FDT_ERR_NOTFOUND if the property does not exist\n+ */\n+const char *fdt_stringlist_get(const void *fdt, int nodeoffset,\n+\t\t\t const char *property, int index,\n+\t\t\t int *lenp);\n+\n+/**********************************************************************/\n+/* Read-only functions (addressing related) */\n+/**********************************************************************/\n+\n+/**\n+ * FDT_MAX_NCELLS - maximum value for #address-cells and #size-cells\n+ *\n+ * This is the maximum value for #address-cells, #size-cells and\n+ * similar properties that will be processed by libfdt. IEE1275\n+ * requires that OF implementations handle values up to 4.\n+ * Implementations may support larger values, but in practice higher\n+ * values aren't used.\n+ */\n+#define FDT_MAX_NCELLS\t\t4\n+\n+/**\n+ * fdt_address_cells - retrieve address size for a bus represented in the tree\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: offset of the node to find the address size for\n+ *\n+ * When the node has a valid #address-cells property, returns its value.\n+ *\n+ * returns:\n+ *\t0 <= n < FDT_MAX_NCELLS, on success\n+ * 2, if the node has no #address-cells property\n+ * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid\n+ *\t\t#address-cells property\n+ *\t-FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTATE,\n+ *\t-FDT_ERR_BADSTRUCTURE,\n+ *\t-FDT_ERR_TRUNCATED, standard meanings\n+ */\n+int fdt_address_cells(const void *fdt, int nodeoffset);\n+\n+/**\n+ * fdt_size_cells - retrieve address range size for a bus represented in the\n+ * tree\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: offset of the node to find the address range size for\n+ *\n+ * When the node has a valid #size-cells property, returns its value.\n+ *\n+ * returns:\n+ *\t0 <= n < FDT_MAX_NCELLS, on success\n+ * 2, if the node has no #address-cells property\n+ * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid\n+ *\t\t#size-cells property\n+ *\t-FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTATE,\n+ *\t-FDT_ERR_BADSTRUCTURE,\n+ *\t-FDT_ERR_TRUNCATED, standard meanings\n+ */\n+int fdt_size_cells(const void *fdt, int nodeoffset);\n+\n+\n+/**********************************************************************/\n+/* Write-in-place functions */\n+/**********************************************************************/\n+\n+/**\n+ * fdt_setprop_inplace_namelen_partial - change a property's value,\n+ * but not its size\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: offset of the node whose property to change\n+ * @name: name of the property to change\n+ * @namelen: number of characters of name to consider\n+ * @idx: index of the property to change in the array\n+ * @val: pointer to data to replace the property value with\n+ * @len: length of the property value\n+ *\n+ * Identical to fdt_setprop_inplace(), but modifies the given property\n+ * starting from the given index, and using only the first characters\n+ * of the name. It is useful when you want to manipulate only one value of\n+ * an array and you have a string that doesn't end with \\0.\n+ */\n+int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset,\n+\t\t\t\t\tconst char *name, int namelen,\n+\t\t\t\t\tuint32_t idx, const void *val,\n+\t\t\t\t\tint len);\n+\n+/**\n+ * fdt_setprop_inplace - change a property's value, but not its size\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: offset of the node whose property to change\n+ * @name: name of the property to change\n+ * @val: pointer to data to replace the property value with\n+ * @len: length of the property value\n+ *\n+ * fdt_setprop_inplace() replaces the value of a given property with\n+ * the data in val, of length len. This function cannot change the\n+ * size of a property, and so will only work if len is equal to the\n+ * current length of the property.\n+ *\n+ * This function will alter only the bytes in the blob which contain\n+ * the given property value, and will not alter or move any other part\n+ * of the tree.\n+ *\n+ * returns:\n+ *\t0, on success\n+ *\t-FDT_ERR_NOSPACE, if len is not equal to the property's current length\n+ *\t-FDT_ERR_NOTFOUND, node does not have the named property\n+ *\t-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\n+ *\t-FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTATE,\n+ *\t-FDT_ERR_BADSTRUCTURE,\n+ *\t-FDT_ERR_TRUNCATED, standard meanings\n+ */\n+int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,\n+\t\t\tconst void *val, int len);\n+\n+/**\n+ * fdt_setprop_inplace_u32 - change the value of a 32-bit integer property\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: offset of the node whose property to change\n+ * @name: name of the property to change\n+ * @val: 32-bit integer value to replace the property with\n+ *\n+ * fdt_setprop_inplace_u32() replaces the value of a given property\n+ * with the 32-bit integer value in val, converting val to big-endian\n+ * if necessary. This function cannot change the size of a property,\n+ * and so will only work if the property already exists and has length\n+ * 4.\n+ *\n+ * This function will alter only the bytes in the blob which contain\n+ * the given property value, and will not alter or move any other part\n+ * of the tree.\n+ *\n+ * returns:\n+ *\t0, on success\n+ *\t-FDT_ERR_NOSPACE, if the property's length is not equal to 4\n+ *\t-FDT_ERR_NOTFOUND, node does not have the named property\n+ *\t-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\n+ *\t-FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTATE,\n+ *\t-FDT_ERR_BADSTRUCTURE,\n+ *\t-FDT_ERR_TRUNCATED, standard meanings\n+ */\n+static inline int fdt_setprop_inplace_u32(void *fdt, int nodeoffset,\n+\t\t\t\t\t const char *name, uint32_t val)\n+{\n+\tfdt32_t tmp = cpu_to_fdt32(val);\n+\treturn fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));\n+}\n+\n+/**\n+ * fdt_setprop_inplace_u64 - change the value of a 64-bit integer property\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: offset of the node whose property to change\n+ * @name: name of the property to change\n+ * @val: 64-bit integer value to replace the property with\n+ *\n+ * fdt_setprop_inplace_u64() replaces the value of a given property\n+ * with the 64-bit integer value in val, converting val to big-endian\n+ * if necessary. This function cannot change the size of a property,\n+ * and so will only work if the property already exists and has length\n+ * 8.\n+ *\n+ * This function will alter only the bytes in the blob which contain\n+ * the given property value, and will not alter or move any other part\n+ * of the tree.\n+ *\n+ * returns:\n+ *\t0, on success\n+ *\t-FDT_ERR_NOSPACE, if the property's length is not equal to 8\n+ *\t-FDT_ERR_NOTFOUND, node does not have the named property\n+ *\t-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\n+ *\t-FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTATE,\n+ *\t-FDT_ERR_BADSTRUCTURE,\n+ *\t-FDT_ERR_TRUNCATED, standard meanings\n+ */\n+static inline int fdt_setprop_inplace_u64(void *fdt, int nodeoffset,\n+\t\t\t\t\t const char *name, uint64_t val)\n+{\n+\tfdt64_t tmp = cpu_to_fdt64(val);\n+\treturn fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));\n+}\n+\n+/**\n+ * fdt_setprop_inplace_cell - change the value of a single-cell property\n+ *\n+ * This is an alternative name for fdt_setprop_inplace_u32()\n+ */\n+static inline int fdt_setprop_inplace_cell(void *fdt, int nodeoffset,\n+\t\t\t\t\t const char *name, uint32_t val)\n+{\n+\treturn fdt_setprop_inplace_u32(fdt, nodeoffset, name, val);\n+}\n+\n+/**\n+ * fdt_nop_property - replace a property with nop tags\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: offset of the node whose property to nop\n+ * @name: name of the property to nop\n+ *\n+ * fdt_nop_property() will replace a given property's representation\n+ * in the blob with FDT_NOP tags, effectively removing it from the\n+ * tree.\n+ *\n+ * This function will alter only the bytes in the blob which contain\n+ * the property, and will not alter or move any other part of the\n+ * tree.\n+ *\n+ * returns:\n+ *\t0, on success\n+ *\t-FDT_ERR_NOTFOUND, node does not have the named property\n+ *\t-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\n+ *\t-FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTATE,\n+ *\t-FDT_ERR_BADSTRUCTURE,\n+ *\t-FDT_ERR_TRUNCATED, standard meanings\n+ */\n+int fdt_nop_property(void *fdt, int nodeoffset, const char *name);\n+\n+/**\n+ * fdt_nop_node - replace a node (subtree) with nop tags\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: offset of the node to nop\n+ *\n+ * fdt_nop_node() will replace a given node's representation in the\n+ * blob, including all its subnodes, if any, with FDT_NOP tags,\n+ * effectively removing it from the tree.\n+ *\n+ * This function will alter only the bytes in the blob which contain\n+ * the node and its properties and subnodes, and will not alter or\n+ * move any other part of the tree.\n+ *\n+ * returns:\n+ *\t0, on success\n+ *\t-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\n+ *\t-FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTATE,\n+ *\t-FDT_ERR_BADSTRUCTURE,\n+ *\t-FDT_ERR_TRUNCATED, standard meanings\n+ */\n+int fdt_nop_node(void *fdt, int nodeoffset);\n+\n+/**********************************************************************/\n+/* Sequential write functions */\n+/**********************************************************************/\n+\n+int fdt_create(void *buf, int bufsize);\n+int fdt_resize(void *fdt, void *buf, int bufsize);\n+int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size);\n+int fdt_finish_reservemap(void *fdt);\n+int fdt_begin_node(void *fdt, const char *name);\n+int fdt_property(void *fdt, const char *name, const void *val, int len);\n+static inline int fdt_property_u32(void *fdt, const char *name, uint32_t val)\n+{\n+\tfdt32_t tmp = cpu_to_fdt32(val);\n+\treturn fdt_property(fdt, name, &tmp, sizeof(tmp));\n+}\n+static inline int fdt_property_u64(void *fdt, const char *name, uint64_t val)\n+{\n+\tfdt64_t tmp = cpu_to_fdt64(val);\n+\treturn fdt_property(fdt, name, &tmp, sizeof(tmp));\n+}\n+static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val)\n+{\n+\treturn fdt_property_u32(fdt, name, val);\n+}\n+#define fdt_property_string(fdt, name, str) \\\n+\tfdt_property(fdt, name, str, strlen(str)+1)\n+int fdt_end_node(void *fdt);\n+int fdt_finish(void *fdt);\n+\n+/**********************************************************************/\n+/* Read-write functions */\n+/**********************************************************************/\n+\n+int fdt_create_empty_tree(void *buf, int bufsize);\n+int fdt_open_into(const void *fdt, void *buf, int bufsize);\n+int fdt_pack(void *fdt);\n+\n+/**\n+ * fdt_add_mem_rsv - add one memory reserve map entry\n+ * @fdt: pointer to the device tree blob\n+ * @address, @size: 64-bit values (native endian)\n+ *\n+ * Adds a reserve map entry to the given blob reserving a region at\n+ * address address of length size.\n+ *\n+ * This function will insert data into the reserve map and will\n+ * therefore change the indexes of some entries in the table.\n+ *\n+ * returns:\n+ *\t0, on success\n+ *\t-FDT_ERR_NOSPACE, there is insufficient free space in the blob to\n+ *\t\tcontain the new reservation entry\n+ *\t-FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTATE,\n+ *\t-FDT_ERR_BADSTRUCTURE,\n+ *\t-FDT_ERR_BADLAYOUT,\n+ *\t-FDT_ERR_TRUNCATED, standard meanings\n+ */\n+int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size);\n+\n+/**\n+ * fdt_del_mem_rsv - remove a memory reserve map entry\n+ * @fdt: pointer to the device tree blob\n+ * @n: entry to remove\n+ *\n+ * fdt_del_mem_rsv() removes the n-th memory reserve map entry from\n+ * the blob.\n+ *\n+ * This function will delete data from the reservation table and will\n+ * therefore change the indexes of some entries in the table.\n+ *\n+ * returns:\n+ *\t0, on success\n+ *\t-FDT_ERR_NOTFOUND, there is no entry of the given index (i.e. there\n+ *\t\tare less than n+1 reserve map entries)\n+ *\t-FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTATE,\n+ *\t-FDT_ERR_BADSTRUCTURE,\n+ *\t-FDT_ERR_BADLAYOUT,\n+ *\t-FDT_ERR_TRUNCATED, standard meanings\n+ */\n+int fdt_del_mem_rsv(void *fdt, int n);\n+\n+/**\n+ * fdt_set_name - change the name of a given node\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: structure block offset of a node\n+ * @name: name to give the node\n+ *\n+ * fdt_set_name() replaces the name (including unit address, if any)\n+ * of the given node with the given string. NOTE: this function can't\n+ * efficiently check if the new name is unique amongst the given\n+ * node's siblings; results are undefined if this function is invoked\n+ * with a name equal to one of the given node's siblings.\n+ *\n+ * This function may insert or delete data from the blob, and will\n+ * therefore change the offsets of some existing nodes.\n+ *\n+ * returns:\n+ *\t0, on success\n+ *\t-FDT_ERR_NOSPACE, there is insufficient free space in the blob\n+ *\t\tto contain the new name\n+ *\t-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\n+ *\t-FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTATE, standard meanings\n+ */\n+int fdt_set_name(void *fdt, int nodeoffset, const char *name);\n+\n+/**\n+ * fdt_setprop - create or change a property\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: offset of the node whose property to change\n+ * @name: name of the property to change\n+ * @val: pointer to data to set the property value to\n+ * @len: length of the property value\n+ *\n+ * fdt_setprop() sets the value of the named property in the given\n+ * node to the given value and length, creating the property if it\n+ * does not already exist.\n+ *\n+ * This function may insert or delete data from the blob, and will\n+ * therefore change the offsets of some existing nodes.\n+ *\n+ * returns:\n+ *\t0, on success\n+ *\t-FDT_ERR_NOSPACE, there is insufficient free space in the blob to\n+ *\t\tcontain the new property value\n+ *\t-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\n+ *\t-FDT_ERR_BADLAYOUT,\n+ *\t-FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTATE,\n+ *\t-FDT_ERR_BADSTRUCTURE,\n+ *\t-FDT_ERR_BADLAYOUT,\n+ *\t-FDT_ERR_TRUNCATED, standard meanings\n+ */\n+int fdt_setprop(void *fdt, int nodeoffset, const char *name,\n+\t\tconst void *val, int len);\n+\n+/**\n+ * fdt_setprop_u32 - set a property to a 32-bit integer\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: offset of the node whose property to change\n+ * @name: name of the property to change\n+ * @val: 32-bit integer value for the property (native endian)\n+ *\n+ * fdt_setprop_u32() sets the value of the named property in the given\n+ * node to the given 32-bit integer value (converting to big-endian if\n+ * necessary), or creates a new property with that value if it does\n+ * not already exist.\n+ *\n+ * This function may insert or delete data from the blob, and will\n+ * therefore change the offsets of some existing nodes.\n+ *\n+ * returns:\n+ *\t0, on success\n+ *\t-FDT_ERR_NOSPACE, there is insufficient free space in the blob to\n+ *\t\tcontain the new property value\n+ *\t-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\n+ *\t-FDT_ERR_BADLAYOUT,\n+ *\t-FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTATE,\n+ *\t-FDT_ERR_BADSTRUCTURE,\n+ *\t-FDT_ERR_BADLAYOUT,\n+ *\t-FDT_ERR_TRUNCATED, standard meanings\n+ */\n+static inline int fdt_setprop_u32(void *fdt, int nodeoffset, const char *name,\n+\t\t\t\t uint32_t val)\n+{\n+\tfdt32_t tmp = cpu_to_fdt32(val);\n+\treturn fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));\n+}\n+\n+/**\n+ * fdt_setprop_u64 - set a property to a 64-bit integer\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: offset of the node whose property to change\n+ * @name: name of the property to change\n+ * @val: 64-bit integer value for the property (native endian)\n+ *\n+ * fdt_setprop_u64() sets the value of the named property in the given\n+ * node to the given 64-bit integer value (converting to big-endian if\n+ * necessary), or creates a new property with that value if it does\n+ * not already exist.\n+ *\n+ * This function may insert or delete data from the blob, and will\n+ * therefore change the offsets of some existing nodes.\n+ *\n+ * returns:\n+ *\t0, on success\n+ *\t-FDT_ERR_NOSPACE, there is insufficient free space in the blob to\n+ *\t\tcontain the new property value\n+ *\t-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\n+ *\t-FDT_ERR_BADLAYOUT,\n+ *\t-FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTATE,\n+ *\t-FDT_ERR_BADSTRUCTURE,\n+ *\t-FDT_ERR_BADLAYOUT,\n+ *\t-FDT_ERR_TRUNCATED, standard meanings\n+ */\n+static inline int fdt_setprop_u64(void *fdt, int nodeoffset, const char *name,\n+\t\t\t\t uint64_t val)\n+{\n+\tfdt64_t tmp = cpu_to_fdt64(val);\n+\treturn fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));\n+}\n+\n+/**\n+ * fdt_setprop_cell - set a property to a single cell value\n+ *\n+ * This is an alternative name for fdt_setprop_u32()\n+ */\n+static inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name,\n+\t\t\t\t uint32_t val)\n+{\n+\treturn fdt_setprop_u32(fdt, nodeoffset, name, val);\n+}\n+\n+/**\n+ * fdt_setprop_string - set a property to a string value\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: offset of the node whose property to change\n+ * @name: name of the property to change\n+ * @str: string value for the property\n+ *\n+ * fdt_setprop_string() sets the value of the named property in the\n+ * given node to the given string value (using the length of the\n+ * string to determine the new length of the property), or creates a\n+ * new property with that value if it does not already exist.\n+ *\n+ * This function may insert or delete data from the blob, and will\n+ * therefore change the offsets of some existing nodes.\n+ *\n+ * returns:\n+ *\t0, on success\n+ *\t-FDT_ERR_NOSPACE, there is insufficient free space in the blob to\n+ *\t\tcontain the new property value\n+ *\t-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\n+ *\t-FDT_ERR_BADLAYOUT,\n+ *\t-FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTATE,\n+ *\t-FDT_ERR_BADSTRUCTURE,\n+ *\t-FDT_ERR_BADLAYOUT,\n+ *\t-FDT_ERR_TRUNCATED, standard meanings\n+ */\n+#define fdt_setprop_string(fdt, nodeoffset, name, str) \\\n+\tfdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)\n+\n+\n+/**\n+ * fdt_setprop_empty - set a property to an empty value\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: offset of the node whose property to change\n+ * @name: name of the property to change\n+ *\n+ * fdt_setprop_empty() sets the value of the named property in the\n+ * given node to an empty (zero length) value, or creates a new empty\n+ * property if it does not already exist.\n+ *\n+ * This function may insert or delete data from the blob, and will\n+ * therefore change the offsets of some existing nodes.\n+ *\n+ * returns:\n+ *\t0, on success\n+ *\t-FDT_ERR_NOSPACE, there is insufficient free space in the blob to\n+ *\t\tcontain the new property value\n+ *\t-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\n+ *\t-FDT_ERR_BADLAYOUT,\n+ *\t-FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTATE,\n+ *\t-FDT_ERR_BADSTRUCTURE,\n+ *\t-FDT_ERR_BADLAYOUT,\n+ *\t-FDT_ERR_TRUNCATED, standard meanings\n+ */\n+#define fdt_setprop_empty(fdt, nodeoffset, name) \\\n+\tfdt_setprop((fdt), (nodeoffset), (name), NULL, 0)\n+\n+/**\n+ * fdt_appendprop - append to or create a property\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: offset of the node whose property to change\n+ * @name: name of the property to append to\n+ * @val: pointer to data to append to the property value\n+ * @len: length of the data to append to the property value\n+ *\n+ * fdt_appendprop() appends the value to the named property in the\n+ * given node, creating the property if it does not already exist.\n+ *\n+ * This function may insert data into the blob, and will therefore\n+ * change the offsets of some existing nodes.\n+ *\n+ * returns:\n+ *\t0, on success\n+ *\t-FDT_ERR_NOSPACE, there is insufficient free space in the blob to\n+ *\t\tcontain the new property value\n+ *\t-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\n+ *\t-FDT_ERR_BADLAYOUT,\n+ *\t-FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTATE,\n+ *\t-FDT_ERR_BADSTRUCTURE,\n+ *\t-FDT_ERR_BADLAYOUT,\n+ *\t-FDT_ERR_TRUNCATED, standard meanings\n+ */\n+int fdt_appendprop(void *fdt, int nodeoffset, const char *name,\n+\t\t const void *val, int len);\n+\n+/**\n+ * fdt_appendprop_u32 - append a 32-bit integer value to a property\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: offset of the node whose property to change\n+ * @name: name of the property to change\n+ * @val: 32-bit integer value to append to the property (native endian)\n+ *\n+ * fdt_appendprop_u32() appends the given 32-bit integer value\n+ * (converting to big-endian if necessary) to the value of the named\n+ * property in the given node, or creates a new property with that\n+ * value if it does not already exist.\n+ *\n+ * This function may insert data into the blob, and will therefore\n+ * change the offsets of some existing nodes.\n+ *\n+ * returns:\n+ *\t0, on success\n+ *\t-FDT_ERR_NOSPACE, there is insufficient free space in the blob to\n+ *\t\tcontain the new property value\n+ *\t-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\n+ *\t-FDT_ERR_BADLAYOUT,\n+ *\t-FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTATE,\n+ *\t-FDT_ERR_BADSTRUCTURE,\n+ *\t-FDT_ERR_BADLAYOUT,\n+ *\t-FDT_ERR_TRUNCATED, standard meanings\n+ */\n+static inline int fdt_appendprop_u32(void *fdt, int nodeoffset,\n+\t\t\t\t const char *name, uint32_t val)\n+{\n+\tfdt32_t tmp = cpu_to_fdt32(val);\n+\treturn fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));\n+}\n+\n+/**\n+ * fdt_appendprop_u64 - append a 64-bit integer value to a property\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: offset of the node whose property to change\n+ * @name: name of the property to change\n+ * @val: 64-bit integer value to append to the property (native endian)\n+ *\n+ * fdt_appendprop_u64() appends the given 64-bit integer value\n+ * (converting to big-endian if necessary) to the value of the named\n+ * property in the given node, or creates a new property with that\n+ * value if it does not already exist.\n+ *\n+ * This function may insert data into the blob, and will therefore\n+ * change the offsets of some existing nodes.\n+ *\n+ * returns:\n+ *\t0, on success\n+ *\t-FDT_ERR_NOSPACE, there is insufficient free space in the blob to\n+ *\t\tcontain the new property value\n+ *\t-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\n+ *\t-FDT_ERR_BADLAYOUT,\n+ *\t-FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTATE,\n+ *\t-FDT_ERR_BADSTRUCTURE,\n+ *\t-FDT_ERR_BADLAYOUT,\n+ *\t-FDT_ERR_TRUNCATED, standard meanings\n+ */\n+static inline int fdt_appendprop_u64(void *fdt, int nodeoffset,\n+\t\t\t\t const char *name, uint64_t val)\n+{\n+\tfdt64_t tmp = cpu_to_fdt64(val);\n+\treturn fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));\n+}\n+\n+/**\n+ * fdt_appendprop_cell - append a single cell value to a property\n+ *\n+ * This is an alternative name for fdt_appendprop_u32()\n+ */\n+static inline int fdt_appendprop_cell(void *fdt, int nodeoffset,\n+\t\t\t\t const char *name, uint32_t val)\n+{\n+\treturn fdt_appendprop_u32(fdt, nodeoffset, name, val);\n+}\n+\n+/**\n+ * fdt_appendprop_string - append a string to a property\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: offset of the node whose property to change\n+ * @name: name of the property to change\n+ * @str: string value to append to the property\n+ *\n+ * fdt_appendprop_string() appends the given string to the value of\n+ * the named property in the given node, or creates a new property\n+ * with that value if it does not already exist.\n+ *\n+ * This function may insert data into the blob, and will therefore\n+ * change the offsets of some existing nodes.\n+ *\n+ * returns:\n+ *\t0, on success\n+ *\t-FDT_ERR_NOSPACE, there is insufficient free space in the blob to\n+ *\t\tcontain the new property value\n+ *\t-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\n+ *\t-FDT_ERR_BADLAYOUT,\n+ *\t-FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTATE,\n+ *\t-FDT_ERR_BADSTRUCTURE,\n+ *\t-FDT_ERR_BADLAYOUT,\n+ *\t-FDT_ERR_TRUNCATED, standard meanings\n+ */\n+#define fdt_appendprop_string(fdt, nodeoffset, name, str) \\\n+\tfdt_appendprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)\n+\n+/**\n+ * fdt_delprop - delete a property\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: offset of the node whose property to nop\n+ * @name: name of the property to nop\n+ *\n+ * fdt_del_property() will delete the given property.\n+ *\n+ * This function will delete data from the blob, and will therefore\n+ * change the offsets of some existing nodes.\n+ *\n+ * returns:\n+ *\t0, on success\n+ *\t-FDT_ERR_NOTFOUND, node does not have the named property\n+ *\t-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\n+ *\t-FDT_ERR_BADLAYOUT,\n+ *\t-FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTATE,\n+ *\t-FDT_ERR_BADSTRUCTURE,\n+ *\t-FDT_ERR_TRUNCATED, standard meanings\n+ */\n+int fdt_delprop(void *fdt, int nodeoffset, const char *name);\n+\n+/**\n+ * fdt_add_subnode_namelen - creates a new node based on substring\n+ * @fdt: pointer to the device tree blob\n+ * @parentoffset: structure block offset of a node\n+ * @name: name of the subnode to locate\n+ * @namelen: number of characters of name to consider\n+ *\n+ * Identical to fdt_add_subnode(), but use only the first namelen\n+ * characters of name as the name of the new node. This is useful for\n+ * creating subnodes based on a portion of a larger string, such as a\n+ * full path.\n+ */\n+int fdt_add_subnode_namelen(void *fdt, int parentoffset,\n+\t\t\t const char *name, int namelen);\n+\n+/**\n+ * fdt_add_subnode - creates a new node\n+ * @fdt: pointer to the device tree blob\n+ * @parentoffset: structure block offset of a node\n+ * @name: name of the subnode to locate\n+ *\n+ * fdt_add_subnode() creates a new node as a subnode of the node at\n+ * structure block offset parentoffset, with the given name (which\n+ * should include the unit address, if any).\n+ *\n+ * This function will insert data into the blob, and will therefore\n+ * change the offsets of some existing nodes.\n+\n+ * returns:\n+ *\tstructure block offset of the created nodeequested subnode (>=0), on\n+ *\t\tsuccess\n+ *\t-FDT_ERR_NOTFOUND, if the requested subnode does not exist\n+ *\t-FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE\n+ *\t\ttag\n+ *\t-FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of\n+ *\t\tthe given name\n+ *\t-FDT_ERR_NOSPACE, if there is insufficient free space in the\n+ *\t\tblob to contain the new node\n+ *\t-FDT_ERR_NOSPACE\n+ *\t-FDT_ERR_BADLAYOUT\n+ * -FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTATE,\n+ *\t-FDT_ERR_BADSTRUCTURE,\n+ *\t-FDT_ERR_TRUNCATED, standard meanings.\n+ */\n+int fdt_add_subnode(void *fdt, int parentoffset, const char *name);\n+\n+/**\n+ * fdt_del_node - delete a node (subtree)\n+ * @fdt: pointer to the device tree blob\n+ * @nodeoffset: offset of the node to nop\n+ *\n+ * fdt_del_node() will remove the given node, including all its\n+ * subnodes if any, from the blob.\n+ *\n+ * This function will delete data from the blob, and will therefore\n+ * change the offsets of some existing nodes.\n+ *\n+ * returns:\n+ *\t0, on success\n+ *\t-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\n+ *\t-FDT_ERR_BADLAYOUT,\n+ *\t-FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTATE,\n+ *\t-FDT_ERR_BADSTRUCTURE,\n+ *\t-FDT_ERR_TRUNCATED, standard meanings\n+ */\n+int fdt_del_node(void *fdt, int nodeoffset);\n+\n+/**\n+ * fdt_overlay_apply - Applies a DT overlay on a base DT\n+ * @fdt: pointer to the base device tree blob\n+ * @fdto: pointer to the device tree overlay blob\n+ *\n+ * fdt_overlay_apply() will apply the given device tree overlay on the\n+ * given base device tree.\n+ *\n+ * Expect the base device tree to be modified, even if the function\n+ * returns an error.\n+ *\n+ * returns:\n+ *\t0, on success\n+ *\t-FDT_ERR_NOSPACE, there's not enough space in the base device tree\n+ *\t-FDT_ERR_NOTFOUND, the overlay points to some inexistant nodes or\n+ *\t\tproperties in the base DT\n+ *\t-FDT_ERR_BADPHANDLE,\n+ *\t-FDT_ERR_BADOVERLAY,\n+ *\t-FDT_ERR_NOPHANDLES,\n+ *\t-FDT_ERR_INTERNAL,\n+ *\t-FDT_ERR_BADLAYOUT,\n+ *\t-FDT_ERR_BADMAGIC,\n+ *\t-FDT_ERR_BADOFFSET,\n+ *\t-FDT_ERR_BADPATH,\n+ *\t-FDT_ERR_BADVERSION,\n+ *\t-FDT_ERR_BADSTRUCTURE,\n+ *\t-FDT_ERR_BADSTATE,\n+ *\t-FDT_ERR_TRUNCATED, standard meanings\n+ */\n+int fdt_overlay_apply(void *fdt, void *fdto);\n+\n+/**********************************************************************/\n+/* Debugging / informational functions */\n+/**********************************************************************/\n+\n+const char *fdt_strerror(int errval);\n+\n+#endif /* _LIBFDT_H */\ndiff --git a/scripts/dtc/libfdt/libfdt_env.h b/scripts/dtc/libfdt/libfdt_env.h\nnew file mode 100644\nindex 000000000000..99f936dacc60\n--- /dev/null\n+++ b/scripts/dtc/libfdt/libfdt_env.h\n@@ -0,0 +1,112 @@\n+#ifndef _LIBFDT_ENV_H\n+#define _LIBFDT_ENV_H\n+/*\n+ * libfdt - Flat Device Tree manipulation\n+ * Copyright (C) 2006 David Gibson, IBM Corporation.\n+ * Copyright 2012 Kim Phillips, Freescale Semiconductor.\n+ *\n+ * libfdt is dual licensed: you can use it either under the terms of\n+ * the GPL, or the BSD license, at your option.\n+ *\n+ * a) This library is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License as\n+ * published by the Free Software Foundation; either version 2 of the\n+ * License, or (at your option) any later version.\n+ *\n+ * This library is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public\n+ * License along with this library; if not, write to the Free\n+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,\n+ * MA 02110-1301 USA\n+ *\n+ * Alternatively,\n+ *\n+ * b) Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * 1. Redistributions of source code must retain the above\n+ * copyright notice, this list of conditions and the following\n+ * disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above\n+ * copyright notice, this list of conditions and the following\n+ * disclaimer in the documentation and/or other materials\n+ * provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\n+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\n+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+#include <stddef.h>\n+#include <stdint.h>\n+#include <stdlib.h>\n+#include <string.h>\n+\n+#ifdef __CHECKER__\n+#define __force __attribute__((force))\n+#define __bitwise __attribute__((bitwise))\n+#else\n+#define __force\n+#define __bitwise\n+#endif\n+\n+typedef uint16_t __bitwise fdt16_t;\n+typedef uint32_t __bitwise fdt32_t;\n+typedef uint64_t __bitwise fdt64_t;\n+\n+#define EXTRACT_BYTE(x, n)\t((unsigned long long)((uint8_t *)&x)[n])\n+#define CPU_TO_FDT16(x) ((EXTRACT_BYTE(x, 0) << 8) | EXTRACT_BYTE(x, 1))\n+#define CPU_TO_FDT32(x) ((EXTRACT_BYTE(x, 0) << 24) | (EXTRACT_BYTE(x, 1) << 16) | \\\n+\t\t\t (EXTRACT_BYTE(x, 2) << 8) | EXTRACT_BYTE(x, 3))\n+#define CPU_TO_FDT64(x) ((EXTRACT_BYTE(x, 0) << 56) | (EXTRACT_BYTE(x, 1) << 48) | \\\n+\t\t\t (EXTRACT_BYTE(x, 2) << 40) | (EXTRACT_BYTE(x, 3) << 32) | \\\n+\t\t\t (EXTRACT_BYTE(x, 4) << 24) | (EXTRACT_BYTE(x, 5) << 16) | \\\n+\t\t\t (EXTRACT_BYTE(x, 6) << 8) | EXTRACT_BYTE(x, 7))\n+\n+static inline uint16_t fdt16_to_cpu(fdt16_t x)\n+{\n+\treturn (__force uint16_t)CPU_TO_FDT16(x);\n+}\n+static inline fdt16_t cpu_to_fdt16(uint16_t x)\n+{\n+\treturn (__force fdt16_t)CPU_TO_FDT16(x);\n+}\n+\n+static inline uint32_t fdt32_to_cpu(fdt32_t x)\n+{\n+\treturn (__force uint32_t)CPU_TO_FDT32(x);\n+}\n+static inline fdt32_t cpu_to_fdt32(uint32_t x)\n+{\n+\treturn (__force fdt32_t)CPU_TO_FDT32(x);\n+}\n+\n+static inline uint64_t fdt64_to_cpu(fdt64_t x)\n+{\n+\treturn (__force uint64_t)CPU_TO_FDT64(x);\n+}\n+static inline fdt64_t cpu_to_fdt64(uint64_t x)\n+{\n+\treturn (__force fdt64_t)CPU_TO_FDT64(x);\n+}\n+#undef CPU_TO_FDT64\n+#undef CPU_TO_FDT32\n+#undef CPU_TO_FDT16\n+#undef EXTRACT_BYTE\n+\n+#endif /* _LIBFDT_ENV_H */\ndiff --git a/scripts/dtc/libfdt/libfdt_internal.h b/scripts/dtc/libfdt/libfdt_internal.h\nnew file mode 100644\nindex 000000000000..02cfa6fb612d\n--- /dev/null\n+++ b/scripts/dtc/libfdt/libfdt_internal.h\n@@ -0,0 +1,95 @@\n+#ifndef _LIBFDT_INTERNAL_H\n+#define _LIBFDT_INTERNAL_H\n+/*\n+ * libfdt - Flat Device Tree manipulation\n+ * Copyright (C) 2006 David Gibson, IBM Corporation.\n+ *\n+ * libfdt is dual licensed: you can use it either under the terms of\n+ * the GPL, or the BSD license, at your option.\n+ *\n+ * a) This library is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License as\n+ * published by the Free Software Foundation; either version 2 of the\n+ * License, or (at your option) any later version.\n+ *\n+ * This library is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public\n+ * License along with this library; if not, write to the Free\n+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,\n+ * MA 02110-1301 USA\n+ *\n+ * Alternatively,\n+ *\n+ * b) Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * 1. Redistributions of source code must retain the above\n+ * copyright notice, this list of conditions and the following\n+ * disclaimer.\n+ * 2. Redistributions in binary form must reproduce the above\n+ * copyright notice, this list of conditions and the following\n+ * disclaimer in the documentation and/or other materials\n+ * provided with the distribution.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\n+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\n+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+#include <fdt.h>\n+\n+#define FDT_ALIGN(x, a)\t\t(((x) + (a) - 1) & ~((a) - 1))\n+#define FDT_TAGALIGN(x)\t\t(FDT_ALIGN((x), FDT_TAGSIZE))\n+\n+#define FDT_CHECK_HEADER(fdt) \\\n+\t{ \\\n+\t\tint __err; \\\n+\t\tif ((__err = fdt_check_header(fdt)) != 0) \\\n+\t\t\treturn __err; \\\n+\t}\n+\n+int _fdt_check_node_offset(const void *fdt, int offset);\n+int _fdt_check_prop_offset(const void *fdt, int offset);\n+const char *_fdt_find_string(const char *strtab, int tabsize, const char *s);\n+int _fdt_node_end_offset(void *fdt, int nodeoffset);\n+\n+static inline const void *_fdt_offset_ptr(const void *fdt, int offset)\n+{\n+\treturn (const char *)fdt + fdt_off_dt_struct(fdt) + offset;\n+}\n+\n+static inline void *_fdt_offset_ptr_w(void *fdt, int offset)\n+{\n+\treturn (void *)(uintptr_t)_fdt_offset_ptr(fdt, offset);\n+}\n+\n+static inline const struct fdt_reserve_entry *_fdt_mem_rsv(const void *fdt, int n)\n+{\n+\tconst struct fdt_reserve_entry *rsv_table =\n+\t\t(const struct fdt_reserve_entry *)\n+\t\t((const char *)fdt + fdt_off_mem_rsvmap(fdt));\n+\n+\treturn rsv_table + n;\n+}\n+static inline struct fdt_reserve_entry *_fdt_mem_rsv_w(void *fdt, int n)\n+{\n+\treturn (void *)(uintptr_t)_fdt_mem_rsv(fdt, n);\n+}\n+\n+#define FDT_SW_MAGIC\t\t(~FDT_MAGIC)\n+\n+#endif /* _LIBFDT_INTERNAL_H */\ndiff --git a/scripts/dtc/livetree.c b/scripts/dtc/livetree.c\nnew file mode 100644\nindex 000000000000..36be9afefd53\n--- /dev/null\n+++ b/scripts/dtc/livetree.c\n@@ -0,0 +1,980 @@\n+/*\n+ * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.\n+ *\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License as\n+ * published by the Free Software Foundation; either version 2 of the\n+ * License, or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\n+ * USA\n+ */\n+\n+#include \"dtc.h\"\n+\n+/*\n+ * Tree building functions\n+ */\n+\n+void add_label(struct label **labels, char *label)\n+{\n+\tstruct label *new;\n+\n+\t/* Make sure the label isn't already there */\n+\tfor_each_label_withdel(*labels, new)\n+\t\tif (streq(new->label, label)) {\n+\t\t\tnew->deleted = 0;\n+\t\t\treturn;\n+\t\t}\n+\n+\tnew = xmalloc(sizeof(*new));\n+\tmemset(new, 0, sizeof(*new));\n+\tnew->label = label;\n+\tnew->next = *labels;\n+\t*labels = new;\n+}\n+\n+void delete_labels(struct label **labels)\n+{\n+\tstruct label *label;\n+\n+\tfor_each_label(*labels, label)\n+\t\tlabel->deleted = 1;\n+}\n+\n+struct property *build_property(char *name, struct data val)\n+{\n+\tstruct property *new = xmalloc(sizeof(*new));\n+\n+\tmemset(new, 0, sizeof(*new));\n+\n+\tnew->name = name;\n+\tnew->val = val;\n+\n+\treturn new;\n+}\n+\n+struct property *build_property_delete(char *name)\n+{\n+\tstruct property *new = xmalloc(sizeof(*new));\n+\n+\tmemset(new, 0, sizeof(*new));\n+\n+\tnew->name = name;\n+\tnew->deleted = 1;\n+\n+\treturn new;\n+}\n+\n+struct property *chain_property(struct property *first, struct property *list)\n+{\n+\tassert(first->next == NULL);\n+\n+\tfirst->next = list;\n+\treturn first;\n+}\n+\n+struct property *reverse_properties(struct property *first)\n+{\n+\tstruct property *p = first;\n+\tstruct property *head = NULL;\n+\tstruct property *next;\n+\n+\twhile (p) {\n+\t\tnext = p->next;\n+\t\tp->next = head;\n+\t\thead = p;\n+\t\tp = next;\n+\t}\n+\treturn head;\n+}\n+\n+struct node *build_node(struct property *proplist, struct node *children)\n+{\n+\tstruct node *new = xmalloc(sizeof(*new));\n+\tstruct node *child;\n+\n+\tmemset(new, 0, sizeof(*new));\n+\n+\tnew->proplist = reverse_properties(proplist);\n+\tnew->children = children;\n+\n+\tfor_each_child(new, child) {\n+\t\tchild->parent = new;\n+\t}\n+\n+\treturn new;\n+}\n+\n+struct node *build_node_delete(void)\n+{\n+\tstruct node *new = xmalloc(sizeof(*new));\n+\n+\tmemset(new, 0, sizeof(*new));\n+\n+\tnew->deleted = 1;\n+\n+\treturn new;\n+}\n+\n+struct node *name_node(struct node *node, char *name)\n+{\n+\tassert(node->name == NULL);\n+\n+\tnode->name = name;\n+\n+\treturn node;\n+}\n+\n+struct node *merge_nodes(struct node *old_node, struct node *new_node)\n+{\n+\tstruct property *new_prop, *old_prop;\n+\tstruct node *new_child, *old_child;\n+\tstruct label *l;\n+\n+\told_node->deleted = 0;\n+\n+\t/* Add new node labels to old node */\n+\tfor_each_label_withdel(new_node->labels, l)\n+\t\tadd_label(&old_node->labels, l->label);\n+\n+\t/* Move properties from the new node to the old node. If there\n+\t * is a collision, replace the old value with the new */\n+\twhile (new_node->proplist) {\n+\t\t/* Pop the property off the list */\n+\t\tnew_prop = new_node->proplist;\n+\t\tnew_node->proplist = new_prop->next;\n+\t\tnew_prop->next = NULL;\n+\n+\t\tif (new_prop->deleted) {\n+\t\t\tdelete_property_by_name(old_node, new_prop->name);\n+\t\t\tfree(new_prop);\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\t/* Look for a collision, set new value if there is */\n+\t\tfor_each_property_withdel(old_node, old_prop) {\n+\t\t\tif (streq(old_prop->name, new_prop->name)) {\n+\t\t\t\t/* Add new labels to old property */\n+\t\t\t\tfor_each_label_withdel(new_prop->labels, l)\n+\t\t\t\t\tadd_label(&old_prop->labels, l->label);\n+\n+\t\t\t\told_prop->val = new_prop->val;\n+\t\t\t\told_prop->deleted = 0;\n+\t\t\t\tfree(new_prop);\n+\t\t\t\tnew_prop = NULL;\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t}\n+\n+\t\t/* if no collision occurred, add property to the old node. */\n+\t\tif (new_prop)\n+\t\t\tadd_property(old_node, new_prop);\n+\t}\n+\n+\t/* Move the override child nodes into the primary node. If\n+\t * there is a collision, then merge the nodes. */\n+\twhile (new_node->children) {\n+\t\t/* Pop the child node off the list */\n+\t\tnew_child = new_node->children;\n+\t\tnew_node->children = new_child->next_sibling;\n+\t\tnew_child->parent = NULL;\n+\t\tnew_child->next_sibling = NULL;\n+\n+\t\tif (new_child->deleted) {\n+\t\t\tdelete_node_by_name(old_node, new_child->name);\n+\t\t\tfree(new_child);\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\t/* Search for a collision. Merge if there is */\n+\t\tfor_each_child_withdel(old_node, old_child) {\n+\t\t\tif (streq(old_child->name, new_child->name)) {\n+\t\t\t\tmerge_nodes(old_child, new_child);\n+\t\t\t\tnew_child = NULL;\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t}\n+\n+\t\t/* if no collision occurred, add child to the old node. */\n+\t\tif (new_child)\n+\t\t\tadd_child(old_node, new_child);\n+\t}\n+\n+\t/* The new node contents are now merged into the old node. Free\n+\t * the new node. */\n+\tfree(new_node);\n+\n+\treturn old_node;\n+}\n+\n+struct node *chain_node(struct node *first, struct node *list)\n+{\n+\tassert(first->next_sibling == NULL);\n+\n+\tfirst->next_sibling = list;\n+\treturn first;\n+}\n+\n+void add_property(struct node *node, struct property *prop)\n+{\n+\tstruct property **p;\n+\n+\tprop->next = NULL;\n+\n+\tp = &node->proplist;\n+\twhile (*p)\n+\t\tp = &((*p)->next);\n+\n+\t*p = prop;\n+}\n+\n+void delete_property_by_name(struct node *node, char *name)\n+{\n+\tstruct property *prop = node->proplist;\n+\n+\twhile (prop) {\n+\t\tif (streq(prop->name, name)) {\n+\t\t\tdelete_property(prop);\n+\t\t\treturn;\n+\t\t}\n+\t\tprop = prop->next;\n+\t}\n+}\n+\n+void delete_property(struct property *prop)\n+{\n+\tprop->deleted = 1;\n+\tdelete_labels(&prop->labels);\n+}\n+\n+void add_child(struct node *parent, struct node *child)\n+{\n+\tstruct node **p;\n+\n+\tchild->next_sibling = NULL;\n+\tchild->parent = parent;\n+\n+\tp = &parent->children;\n+\twhile (*p)\n+\t\tp = &((*p)->next_sibling);\n+\n+\t*p = child;\n+}\n+\n+void delete_node_by_name(struct node *parent, char *name)\n+{\n+\tstruct node *node = parent->children;\n+\n+\twhile (node) {\n+\t\tif (streq(node->name, name)) {\n+\t\t\tdelete_node(node);\n+\t\t\treturn;\n+\t\t}\n+\t\tnode = node->next_sibling;\n+\t}\n+}\n+\n+void delete_node(struct node *node)\n+{\n+\tstruct property *prop;\n+\tstruct node *child;\n+\n+\tnode->deleted = 1;\n+\tfor_each_child(node, child)\n+\t\tdelete_node(child);\n+\tfor_each_property(node, prop)\n+\t\tdelete_property(prop);\n+\tdelete_labels(&node->labels);\n+}\n+\n+void append_to_property(struct node *node,\n+\t\t\t\t char *name, const void *data, int len)\n+{\n+\tstruct data d;\n+\tstruct property *p;\n+\n+\tp = get_property(node, name);\n+\tif (p) {\n+\t\td = data_append_data(p->val, data, len);\n+\t\tp->val = d;\n+\t} else {\n+\t\td = data_append_data(empty_data, data, len);\n+\t\tp = build_property(name, d);\n+\t\tadd_property(node, p);\n+\t}\n+}\n+\n+struct reserve_info *build_reserve_entry(uint64_t address, uint64_t size)\n+{\n+\tstruct reserve_info *new = xmalloc(sizeof(*new));\n+\n+\tmemset(new, 0, sizeof(*new));\n+\n+\tnew->re.address = address;\n+\tnew->re.size = size;\n+\n+\treturn new;\n+}\n+\n+struct reserve_info *chain_reserve_entry(struct reserve_info *first,\n+\t\t\t\t\tstruct reserve_info *list)\n+{\n+\tassert(first->next == NULL);\n+\n+\tfirst->next = list;\n+\treturn first;\n+}\n+\n+struct reserve_info *add_reserve_entry(struct reserve_info *list,\n+\t\t\t\t struct reserve_info *new)\n+{\n+\tstruct reserve_info *last;\n+\n+\tnew->next = NULL;\n+\n+\tif (! list)\n+\t\treturn new;\n+\n+\tfor (last = list; last->next; last = last->next)\n+\t\t;\n+\n+\tlast->next = new;\n+\n+\treturn list;\n+}\n+\n+struct dt_info *build_dt_info(unsigned int dtsflags,\n+\t\t\t struct reserve_info *reservelist,\n+\t\t\t struct node *tree, uint32_t boot_cpuid_phys)\n+{\n+\tstruct dt_info *dti;\n+\n+\tdti = xmalloc(sizeof(*dti));\n+\tdti->dtsflags = dtsflags;\n+\tdti->reservelist = reservelist;\n+\tdti->dt = tree;\n+\tdti->boot_cpuid_phys = boot_cpuid_phys;\n+\n+\treturn dti;\n+}\n+\n+/*\n+ * Tree accessor functions\n+ */\n+\n+const char *get_unitname(struct node *node)\n+{\n+\tif (node->name[node->basenamelen] == '\\0')\n+\t\treturn \"\";\n+\telse\n+\t\treturn node->name + node->basenamelen + 1;\n+}\n+\n+struct property *get_property(struct node *node, const char *propname)\n+{\n+\tstruct property *prop;\n+\n+\tfor_each_property(node, prop)\n+\t\tif (streq(prop->name, propname))\n+\t\t\treturn prop;\n+\n+\treturn NULL;\n+}\n+\n+cell_t propval_cell(struct property *prop)\n+{\n+\tassert(prop->val.len == sizeof(cell_t));\n+\treturn fdt32_to_cpu(*((cell_t *)prop->val.val));\n+}\n+\n+struct property *get_property_by_label(struct node *tree, const char *label,\n+\t\t\t\t struct node **node)\n+{\n+\tstruct property *prop;\n+\tstruct node *c;\n+\n+\t*node = tree;\n+\n+\tfor_each_property(tree, prop) {\n+\t\tstruct label *l;\n+\n+\t\tfor_each_label(prop->labels, l)\n+\t\t\tif (streq(l->label, label))\n+\t\t\t\treturn prop;\n+\t}\n+\n+\tfor_each_child(tree, c) {\n+\t\tprop = get_property_by_label(c, label, node);\n+\t\tif (prop)\n+\t\t\treturn prop;\n+\t}\n+\n+\t*node = NULL;\n+\treturn NULL;\n+}\n+\n+struct marker *get_marker_label(struct node *tree, const char *label,\n+\t\t\t\tstruct node **node, struct property **prop)\n+{\n+\tstruct marker *m;\n+\tstruct property *p;\n+\tstruct node *c;\n+\n+\t*node = tree;\n+\n+\tfor_each_property(tree, p) {\n+\t\t*prop = p;\n+\t\tm = p->val.markers;\n+\t\tfor_each_marker_of_type(m, LABEL)\n+\t\t\tif (streq(m->ref, label))\n+\t\t\t\treturn m;\n+\t}\n+\n+\tfor_each_child(tree, c) {\n+\t\tm = get_marker_label(c, label, node, prop);\n+\t\tif (m)\n+\t\t\treturn m;\n+\t}\n+\n+\t*prop = NULL;\n+\t*node = NULL;\n+\treturn NULL;\n+}\n+\n+struct node *get_subnode(struct node *node, const char *nodename)\n+{\n+\tstruct node *child;\n+\n+\tfor_each_child(node, child)\n+\t\tif (streq(child->name, nodename))\n+\t\t\treturn child;\n+\n+\treturn NULL;\n+}\n+\n+struct node *get_node_by_path(struct node *tree, const char *path)\n+{\n+\tconst char *p;\n+\tstruct node *child;\n+\n+\tif (!path || ! (*path)) {\n+\t\tif (tree->deleted)\n+\t\t\treturn NULL;\n+\t\treturn tree;\n+\t}\n+\n+\twhile (path[0] == '/')\n+\t\tpath++;\n+\n+\tp = strchr(path, '/');\n+\n+\tfor_each_child(tree, child) {\n+\t\tif (p && strneq(path, child->name, p-path))\n+\t\t\treturn get_node_by_path(child, p+1);\n+\t\telse if (!p && streq(path, child->name))\n+\t\t\treturn child;\n+\t}\n+\n+\treturn NULL;\n+}\n+\n+struct node *get_node_by_label(struct node *tree, const char *label)\n+{\n+\tstruct node *child, *node;\n+\tstruct label *l;\n+\n+\tassert(label && (strlen(label) > 0));\n+\n+\tfor_each_label(tree->labels, l)\n+\t\tif (streq(l->label, label))\n+\t\t\treturn tree;\n+\n+\tfor_each_child(tree, child) {\n+\t\tnode = get_node_by_label(child, label);\n+\t\tif (node)\n+\t\t\treturn node;\n+\t}\n+\n+\treturn NULL;\n+}\n+\n+struct node *get_node_by_phandle(struct node *tree, cell_t phandle)\n+{\n+\tstruct node *child, *node;\n+\n+\tassert((phandle != 0) && (phandle != -1));\n+\n+\tif (tree->phandle == phandle) {\n+\t\tif (tree->deleted)\n+\t\t\treturn NULL;\n+\t\treturn tree;\n+\t}\n+\n+\tfor_each_child(tree, child) {\n+\t\tnode = get_node_by_phandle(child, phandle);\n+\t\tif (node)\n+\t\t\treturn node;\n+\t}\n+\n+\treturn NULL;\n+}\n+\n+struct node *get_node_by_ref(struct node *tree, const char *ref)\n+{\n+\tif (streq(ref, \"/\"))\n+\t\treturn tree;\n+\telse if (ref[0] == '/')\n+\t\treturn get_node_by_path(tree, ref);\n+\telse\n+\t\treturn get_node_by_label(tree, ref);\n+}\n+\n+cell_t get_node_phandle(struct node *root, struct node *node)\n+{\n+\tstatic cell_t phandle = 1; /* FIXME: ick, static local */\n+\n+\tif ((node->phandle != 0) && (node->phandle != -1))\n+\t\treturn node->phandle;\n+\n+\twhile (get_node_by_phandle(root, phandle))\n+\t\tphandle++;\n+\n+\tnode->phandle = phandle;\n+\n+\tif (!get_property(node, \"linux,phandle\")\n+\t && (phandle_format & PHANDLE_LEGACY))\n+\t\tadd_property(node,\n+\t\t\t build_property(\"linux,phandle\",\n+\t\t\t\t\t data_append_cell(empty_data, phandle)));\n+\n+\tif (!get_property(node, \"phandle\")\n+\t && (phandle_format & PHANDLE_EPAPR))\n+\t\tadd_property(node,\n+\t\t\t build_property(\"phandle\",\n+\t\t\t\t\t data_append_cell(empty_data, phandle)));\n+\n+\t/* If the node *does* have a phandle property, we must\n+\t * be dealing with a self-referencing phandle, which will be\n+\t * fixed up momentarily in the caller */\n+\n+\treturn node->phandle;\n+}\n+\n+uint32_t guess_boot_cpuid(struct node *tree)\n+{\n+\tstruct node *cpus, *bootcpu;\n+\tstruct property *reg;\n+\n+\tcpus = get_node_by_path(tree, \"/cpus\");\n+\tif (!cpus)\n+\t\treturn 0;\n+\n+\n+\tbootcpu = cpus->children;\n+\tif (!bootcpu)\n+\t\treturn 0;\n+\n+\treg = get_property(bootcpu, \"reg\");\n+\tif (!reg || (reg->val.len != sizeof(uint32_t)))\n+\t\treturn 0;\n+\n+\t/* FIXME: Sanity check node? */\n+\n+\treturn propval_cell(reg);\n+}\n+\n+static int cmp_reserve_info(const void *ax, const void *bx)\n+{\n+\tconst struct reserve_info *a, *b;\n+\n+\ta = *((const struct reserve_info * const *)ax);\n+\tb = *((const struct reserve_info * const *)bx);\n+\n+\tif (a->re.address < b->re.address)\n+\t\treturn -1;\n+\telse if (a->re.address > b->re.address)\n+\t\treturn 1;\n+\telse if (a->re.size < b->re.size)\n+\t\treturn -1;\n+\telse if (a->re.size > b->re.size)\n+\t\treturn 1;\n+\telse\n+\t\treturn 0;\n+}\n+\n+static void sort_reserve_entries(struct dt_info *dti)\n+{\n+\tstruct reserve_info *ri, **tbl;\n+\tint n = 0, i = 0;\n+\n+\tfor (ri = dti->reservelist;\n+\t ri;\n+\t ri = ri->next)\n+\t\tn++;\n+\n+\tif (n == 0)\n+\t\treturn;\n+\n+\ttbl = xmalloc(n * sizeof(*tbl));\n+\n+\tfor (ri = dti->reservelist;\n+\t ri;\n+\t ri = ri->next)\n+\t\ttbl[i++] = ri;\n+\n+\tqsort(tbl, n, sizeof(*tbl), cmp_reserve_info);\n+\n+\tdti->reservelist = tbl[0];\n+\tfor (i = 0; i < (n-1); i++)\n+\t\ttbl[i]->next = tbl[i+1];\n+\ttbl[n-1]->next = NULL;\n+\n+\tfree(tbl);\n+}\n+\n+static int cmp_prop(const void *ax, const void *bx)\n+{\n+\tconst struct property *a, *b;\n+\n+\ta = *((const struct property * const *)ax);\n+\tb = *((const struct property * const *)bx);\n+\n+\treturn strcmp(a->name, b->name);\n+}\n+\n+static void sort_properties(struct node *node)\n+{\n+\tint n = 0, i = 0;\n+\tstruct property *prop, **tbl;\n+\n+\tfor_each_property_withdel(node, prop)\n+\t\tn++;\n+\n+\tif (n == 0)\n+\t\treturn;\n+\n+\ttbl = xmalloc(n * sizeof(*tbl));\n+\n+\tfor_each_property_withdel(node, prop)\n+\t\ttbl[i++] = prop;\n+\n+\tqsort(tbl, n, sizeof(*tbl), cmp_prop);\n+\n+\tnode->proplist = tbl[0];\n+\tfor (i = 0; i < (n-1); i++)\n+\t\ttbl[i]->next = tbl[i+1];\n+\ttbl[n-1]->next = NULL;\n+\n+\tfree(tbl);\n+}\n+\n+static int cmp_subnode(const void *ax, const void *bx)\n+{\n+\tconst struct node *a, *b;\n+\n+\ta = *((const struct node * const *)ax);\n+\tb = *((const struct node * const *)bx);\n+\n+\treturn strcmp(a->name, b->name);\n+}\n+\n+static void sort_subnodes(struct node *node)\n+{\n+\tint n = 0, i = 0;\n+\tstruct node *subnode, **tbl;\n+\n+\tfor_each_child_withdel(node, subnode)\n+\t\tn++;\n+\n+\tif (n == 0)\n+\t\treturn;\n+\n+\ttbl = xmalloc(n * sizeof(*tbl));\n+\n+\tfor_each_child_withdel(node, subnode)\n+\t\ttbl[i++] = subnode;\n+\n+\tqsort(tbl, n, sizeof(*tbl), cmp_subnode);\n+\n+\tnode->children = tbl[0];\n+\tfor (i = 0; i < (n-1); i++)\n+\t\ttbl[i]->next_sibling = tbl[i+1];\n+\ttbl[n-1]->next_sibling = NULL;\n+\n+\tfree(tbl);\n+}\n+\n+static void sort_node(struct node *node)\n+{\n+\tstruct node *c;\n+\n+\tsort_properties(node);\n+\tsort_subnodes(node);\n+\tfor_each_child_withdel(node, c)\n+\t\tsort_node(c);\n+}\n+\n+void sort_tree(struct dt_info *dti)\n+{\n+\tsort_reserve_entries(dti);\n+\tsort_node(dti->dt);\n+}\n+\n+/* utility helper to avoid code duplication */\n+static struct node *build_and_name_child_node(struct node *parent, char *name)\n+{\n+\tstruct node *node;\n+\n+\tnode = build_node(NULL, NULL);\n+\tname_node(node, xstrdup(name));\n+\tadd_child(parent, node);\n+\n+\treturn node;\n+}\n+\n+static struct node *build_root_node(struct node *dt, char *name)\n+{\n+\tstruct node *an;\n+\n+\tan = get_subnode(dt, name);\n+\tif (!an)\n+\t\tan = build_and_name_child_node(dt, name);\n+\n+\tif (!an)\n+\t\tdie(\"Could not build root node /%s\\n\", name);\n+\n+\treturn an;\n+}\n+\n+static bool any_label_tree(struct dt_info *dti, struct node *node)\n+{\n+\tstruct node *c;\n+\n+\tif (node->labels)\n+\t\treturn true;\n+\n+\tfor_each_child(node, c)\n+\t\tif (any_label_tree(dti, c))\n+\t\t\treturn true;\n+\n+\treturn false;\n+}\n+\n+static void generate_label_tree_internal(struct dt_info *dti,\n+\t\t\t\t\t struct node *an, struct node *node,\n+\t\t\t\t\t bool allocph)\n+{\n+\tstruct node *dt = dti->dt;\n+\tstruct node *c;\n+\tstruct property *p;\n+\tstruct label *l;\n+\n+\t/* if there are labels */\n+\tif (node->labels) {\n+\n+\t\t/* now add the label in the node */\n+\t\tfor_each_label(node->labels, l) {\n+\n+\t\t\t/* check whether the label already exists */\n+\t\t\tp = get_property(an, l->label);\n+\t\t\tif (p) {\n+\t\t\t\tfprintf(stderr, \"WARNING: label %s already\"\n+\t\t\t\t\t\" exists in /%s\", l->label,\n+\t\t\t\t\tan->name);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\t/* insert it */\n+\t\t\tp = build_property(l->label,\n+\t\t\t\tdata_copy_mem(node->fullpath,\n+\t\t\t\t\t\tstrlen(node->fullpath) + 1));\n+\t\t\tadd_property(an, p);\n+\t\t}\n+\n+\t\t/* force allocation of a phandle for this node */\n+\t\tif (allocph)\n+\t\t\t(void)get_node_phandle(dt, node);\n+\t}\n+\n+\tfor_each_child(node, c)\n+\t\tgenerate_label_tree_internal(dti, an, c, allocph);\n+}\n+\n+static bool any_fixup_tree(struct dt_info *dti, struct node *node)\n+{\n+\tstruct node *c;\n+\tstruct property *prop;\n+\tstruct marker *m;\n+\n+\tfor_each_property(node, prop) {\n+\t\tm = prop->val.markers;\n+\t\tfor_each_marker_of_type(m, REF_PHANDLE) {\n+\t\t\tif (!get_node_by_ref(dti->dt, m->ref))\n+\t\t\t\treturn true;\n+\t\t}\n+\t}\n+\n+\tfor_each_child(node, c) {\n+\t\tif (any_fixup_tree(dti, c))\n+\t\t\treturn true;\n+\t}\n+\n+\treturn false;\n+}\n+\n+static void add_fixup_entry(struct dt_info *dti, struct node *fn,\n+\t\t\t struct node *node, struct property *prop,\n+\t\t\t struct marker *m)\n+{\n+\tchar *entry;\n+\n+\t/* m->ref can only be a REF_PHANDLE, but check anyway */\n+\tassert(m->type == REF_PHANDLE);\n+\n+\t/* there shouldn't be any ':' in the arguments */\n+\tif (strchr(node->fullpath, ':') || strchr(prop->name, ':'))\n+\t\tdie(\"arguments should not contain ':'\\n\");\n+\n+\txasprintf(&entry, \"%s:%s:%u\",\n+\t\t\tnode->fullpath, prop->name, m->offset);\n+\tappend_to_property(fn, m->ref, entry, strlen(entry) + 1);\n+\n+\tfree(entry);\n+}\n+\n+static void generate_fixups_tree_internal(struct dt_info *dti,\n+\t\t\t\t\t struct node *fn,\n+\t\t\t\t\t struct node *node)\n+{\n+\tstruct node *dt = dti->dt;\n+\tstruct node *c;\n+\tstruct property *prop;\n+\tstruct marker *m;\n+\tstruct node *refnode;\n+\n+\tfor_each_property(node, prop) {\n+\t\tm = prop->val.markers;\n+\t\tfor_each_marker_of_type(m, REF_PHANDLE) {\n+\t\t\trefnode = get_node_by_ref(dt, m->ref);\n+\t\t\tif (!refnode)\n+\t\t\t\tadd_fixup_entry(dti, fn, node, prop, m);\n+\t\t}\n+\t}\n+\n+\tfor_each_child(node, c)\n+\t\tgenerate_fixups_tree_internal(dti, fn, c);\n+}\n+\n+static bool any_local_fixup_tree(struct dt_info *dti, struct node *node)\n+{\n+\tstruct node *c;\n+\tstruct property *prop;\n+\tstruct marker *m;\n+\n+\tfor_each_property(node, prop) {\n+\t\tm = prop->val.markers;\n+\t\tfor_each_marker_of_type(m, REF_PHANDLE) {\n+\t\t\tif (get_node_by_ref(dti->dt, m->ref))\n+\t\t\t\treturn true;\n+\t\t}\n+\t}\n+\n+\tfor_each_child(node, c) {\n+\t\tif (any_local_fixup_tree(dti, c))\n+\t\t\treturn true;\n+\t}\n+\n+\treturn false;\n+}\n+\n+static void add_local_fixup_entry(struct dt_info *dti,\n+\t\tstruct node *lfn, struct node *node,\n+\t\tstruct property *prop, struct marker *m,\n+\t\tstruct node *refnode)\n+{\n+\tstruct node *wn, *nwn;\t/* local fixup node, walk node, new */\n+\tuint32_t value_32;\n+\tchar **compp;\n+\tint i, depth;\n+\n+\t/* walk back retreiving depth */\n+\tdepth = 0;\n+\tfor (wn = node; wn; wn = wn->parent)\n+\t\tdepth++;\n+\n+\t/* allocate name array */\n+\tcompp = xmalloc(sizeof(*compp) * depth);\n+\n+\t/* store names in the array */\n+\tfor (wn = node, i = depth - 1; wn; wn = wn->parent, i--)\n+\t\tcompp[i] = wn->name;\n+\n+\t/* walk the path components creating nodes if they don't exist */\n+\tfor (wn = lfn, i = 1; i < depth; i++, wn = nwn) {\n+\t\t/* if no node exists, create it */\n+\t\tnwn = get_subnode(wn, compp[i]);\n+\t\tif (!nwn)\n+\t\t\tnwn = build_and_name_child_node(wn, compp[i]);\n+\t}\n+\n+\tfree(compp);\n+\n+\tvalue_32 = cpu_to_fdt32(m->offset);\n+\tappend_to_property(wn, prop->name, &value_32, sizeof(value_32));\n+}\n+\n+static void generate_local_fixups_tree_internal(struct dt_info *dti,\n+\t\t\t\t\t\tstruct node *lfn,\n+\t\t\t\t\t\tstruct node *node)\n+{\n+\tstruct node *dt = dti->dt;\n+\tstruct node *c;\n+\tstruct property *prop;\n+\tstruct marker *m;\n+\tstruct node *refnode;\n+\n+\tfor_each_property(node, prop) {\n+\t\tm = prop->val.markers;\n+\t\tfor_each_marker_of_type(m, REF_PHANDLE) {\n+\t\t\trefnode = get_node_by_ref(dt, m->ref);\n+\t\t\tif (refnode)\n+\t\t\t\tadd_local_fixup_entry(dti, lfn, node, prop, m, refnode);\n+\t\t}\n+\t}\n+\n+\tfor_each_child(node, c)\n+\t\tgenerate_local_fixups_tree_internal(dti, lfn, c);\n+}\n+\n+void generate_label_tree(struct dt_info *dti, char *name, bool allocph)\n+{\n+\tif (!any_label_tree(dti, dti->dt))\n+\t\treturn;\n+\tgenerate_label_tree_internal(dti, build_root_node(dti->dt, name),\n+\t\t\t\t dti->dt, allocph);\n+}\n+\n+void generate_fixups_tree(struct dt_info *dti, char *name)\n+{\n+\tif (!any_fixup_tree(dti, dti->dt))\n+\t\treturn;\n+\tgenerate_fixups_tree_internal(dti, build_root_node(dti->dt, name),\n+\t\t\t\t dti->dt);\n+}\n+\n+void generate_local_fixups_tree(struct dt_info *dti, char *name)\n+{\n+\tif (!any_local_fixup_tree(dti, dti->dt))\n+\t\treturn;\n+\tgenerate_local_fixups_tree_internal(dti, build_root_node(dti->dt, name),\n+\t\t\t\t\t dti->dt);\n+}\ndiff --git a/scripts/dtc/srcpos.c b/scripts/dtc/srcpos.c\nnew file mode 100644\nindex 000000000000..9d38459902f3\n--- /dev/null\n+++ b/scripts/dtc/srcpos.c\n@@ -0,0 +1,302 @@\n+/*\n+ * Copyright 2007 Jon Loeliger, Freescale Semiconductor, Inc.\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License as\n+ * published by the Free Software Foundation; either version 2 of the\n+ * License, or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\n+ * USA\n+ */\n+\n+#define _GNU_SOURCE\n+\n+#include <stdio.h>\n+\n+#include \"dtc.h\"\n+#include \"srcpos.h\"\n+\n+/* A node in our list of directories to search for source/include files */\n+struct search_path {\n+\tstruct search_path *next;\t/* next node in list, NULL for end */\n+\tconst char *dirname;\t\t/* name of directory to search */\n+};\n+\n+/* This is the list of directories that we search for source files */\n+static struct search_path *search_path_head, **search_path_tail;\n+\n+\n+static char *get_dirname(const char *path)\n+{\n+\tconst char *slash = strrchr(path, '/');\n+\n+\tif (slash) {\n+\t\tint len = slash - path;\n+\t\tchar *dir = xmalloc(len + 1);\n+\n+\t\tmemcpy(dir, path, len);\n+\t\tdir[len] = '\\0';\n+\t\treturn dir;\n+\t}\n+\treturn NULL;\n+}\n+\n+FILE *depfile; /* = NULL */\n+struct srcfile_state *current_srcfile; /* = NULL */\n+\n+/* Detect infinite include recursion. */\n+#define MAX_SRCFILE_DEPTH (100)\n+static int srcfile_depth; /* = 0 */\n+\n+\n+/**\n+ * Try to open a file in a given directory.\n+ *\n+ * If the filename is an absolute path, then dirname is ignored. If it is a\n+ * relative path, then we look in that directory for the file.\n+ *\n+ * @param dirname\tDirectory to look in, or NULL for none\n+ * @param fname\t\tFilename to look for\n+ * @param fp\t\tSet to NULL if file did not open\n+ * @return allocated filename on success (caller must free), NULL on failure\n+ */\n+static char *try_open(const char *dirname, const char *fname, FILE **fp)\n+{\n+\tchar *fullname;\n+\n+\tif (!dirname || fname[0] == '/')\n+\t\tfullname = xstrdup(fname);\n+\telse\n+\t\tfullname = join_path(dirname, fname);\n+\n+\t*fp = fopen(fullname, \"rb\");\n+\tif (!*fp) {\n+\t\tfree(fullname);\n+\t\tfullname = NULL;\n+\t}\n+\n+\treturn fullname;\n+}\n+\n+/**\n+ * Open a file for read access\n+ *\n+ * If it is a relative filename, we search the full search path for it.\n+ *\n+ * @param fname\tFilename to open\n+ * @param fp\tReturns pointer to opened FILE, or NULL on failure\n+ * @return pointer to allocated filename, which caller must free\n+ */\n+static char *fopen_any_on_path(const char *fname, FILE **fp)\n+{\n+\tconst char *cur_dir = NULL;\n+\tstruct search_path *node;\n+\tchar *fullname;\n+\n+\t/* Try current directory first */\n+\tassert(fp);\n+\tif (current_srcfile)\n+\t\tcur_dir = current_srcfile->dir;\n+\tfullname = try_open(cur_dir, fname, fp);\n+\n+\t/* Failing that, try each search path in turn */\n+\tfor (node = search_path_head; !*fp && node; node = node->next)\n+\t\tfullname = try_open(node->dirname, fname, fp);\n+\n+\treturn fullname;\n+}\n+\n+FILE *srcfile_relative_open(const char *fname, char **fullnamep)\n+{\n+\tFILE *f;\n+\tchar *fullname;\n+\n+\tif (streq(fname, \"-\")) {\n+\t\tf = stdin;\n+\t\tfullname = xstrdup(\"<stdin>\");\n+\t} else {\n+\t\tfullname = fopen_any_on_path(fname, &f);\n+\t\tif (!f)\n+\t\t\tdie(\"Couldn't open \\\"%s\\\": %s\\n\", fname,\n+\t\t\t strerror(errno));\n+\t}\n+\n+\tif (depfile)\n+\t\tfprintf(depfile, \" %s\", fullname);\n+\n+\tif (fullnamep)\n+\t\t*fullnamep = fullname;\n+\telse\n+\t\tfree(fullname);\n+\n+\treturn f;\n+}\n+\n+void srcfile_push(const char *fname)\n+{\n+\tstruct srcfile_state *srcfile;\n+\n+\tif (srcfile_depth++ >= MAX_SRCFILE_DEPTH)\n+\t\tdie(\"Includes nested too deeply\");\n+\n+\tsrcfile = xmalloc(sizeof(*srcfile));\n+\n+\tsrcfile->f = srcfile_relative_open(fname, &srcfile->name);\n+\tsrcfile->dir = get_dirname(srcfile->name);\n+\tsrcfile->prev = current_srcfile;\n+\n+\tsrcfile->lineno = 1;\n+\tsrcfile->colno = 1;\n+\n+\tcurrent_srcfile = srcfile;\n+}\n+\n+bool srcfile_pop(void)\n+{\n+\tstruct srcfile_state *srcfile = current_srcfile;\n+\n+\tassert(srcfile);\n+\n+\tcurrent_srcfile = srcfile->prev;\n+\n+\tif (fclose(srcfile->f))\n+\t\tdie(\"Error closing \\\"%s\\\": %s\\n\", srcfile->name,\n+\t\t strerror(errno));\n+\n+\t/* FIXME: We allow the srcfile_state structure to leak,\n+\t * because it could still be referenced from a location\n+\t * variable being carried through the parser somewhere. To\n+\t * fix this we could either allocate all the files from a\n+\t * table, or use a pool allocator. */\n+\n+\treturn current_srcfile ? true : false;\n+}\n+\n+void srcfile_add_search_path(const char *dirname)\n+{\n+\tstruct search_path *node;\n+\n+\t/* Create the node */\n+\tnode = xmalloc(sizeof(*node));\n+\tnode->next = NULL;\n+\tnode->dirname = xstrdup(dirname);\n+\n+\t/* Add to the end of our list */\n+\tif (search_path_tail)\n+\t\t*search_path_tail = node;\n+\telse\n+\t\tsearch_path_head = node;\n+\tsearch_path_tail = &node->next;\n+}\n+\n+/*\n+ * The empty source position.\n+ */\n+\n+struct srcpos srcpos_empty = {\n+\t.first_line = 0,\n+\t.first_column = 0,\n+\t.last_line = 0,\n+\t.last_column = 0,\n+\t.file = NULL,\n+};\n+\n+#define TAB_SIZE 8\n+\n+void srcpos_update(struct srcpos *pos, const char *text, int len)\n+{\n+\tint i;\n+\n+\tpos->file = current_srcfile;\n+\n+\tpos->first_line = current_srcfile->lineno;\n+\tpos->first_column = current_srcfile->colno;\n+\n+\tfor (i = 0; i < len; i++)\n+\t\tif (text[i] == '\\n') {\n+\t\t\tcurrent_srcfile->lineno++;\n+\t\t\tcurrent_srcfile->colno = 1;\n+\t\t} else if (text[i] == '\\t') {\n+\t\t\tcurrent_srcfile->colno =\n+\t\t\t\tALIGN(current_srcfile->colno, TAB_SIZE);\n+\t\t} else {\n+\t\t\tcurrent_srcfile->colno++;\n+\t\t}\n+\n+\tpos->last_line = current_srcfile->lineno;\n+\tpos->last_column = current_srcfile->colno;\n+}\n+\n+struct srcpos *\n+srcpos_copy(struct srcpos *pos)\n+{\n+\tstruct srcpos *pos_new;\n+\n+\tpos_new = xmalloc(sizeof(struct srcpos));\n+\tmemcpy(pos_new, pos, sizeof(struct srcpos));\n+\n+\treturn pos_new;\n+}\n+\n+char *\n+srcpos_string(struct srcpos *pos)\n+{\n+\tconst char *fname = \"<no-file>\";\n+\tchar *pos_str;\n+\n+\tif (pos->file && pos->file->name)\n+\t\tfname = pos->file->name;\n+\n+\n+\tif (pos->first_line != pos->last_line)\n+\t\txasprintf(&pos_str, \"%s:%d.%d-%d.%d\", fname,\n+\t\t\t pos->first_line, pos->first_column,\n+\t\t\t pos->last_line, pos->last_column);\n+\telse if (pos->first_column != pos->last_column)\n+\t\txasprintf(&pos_str, \"%s:%d.%d-%d\", fname,\n+\t\t\t pos->first_line, pos->first_column,\n+\t\t\t pos->last_column);\n+\telse\n+\t\txasprintf(&pos_str, \"%s:%d.%d\", fname,\n+\t\t\t pos->first_line, pos->first_column);\n+\n+\treturn pos_str;\n+}\n+\n+void srcpos_verror(struct srcpos *pos, const char *prefix,\n+\t\t const char *fmt, va_list va)\n+{\n+\tchar *srcstr;\n+\n+\tsrcstr = srcpos_string(pos);\n+\n+\tfprintf(stderr, \"%s: %s \", prefix, srcstr);\n+\tvfprintf(stderr, fmt, va);\n+\tfprintf(stderr, \"\\n\");\n+\n+\tfree(srcstr);\n+}\n+\n+void srcpos_error(struct srcpos *pos, const char *prefix,\n+\t\t const char *fmt, ...)\n+{\n+\tva_list va;\n+\n+\tva_start(va, fmt);\n+\tsrcpos_verror(pos, prefix, fmt, va);\n+\tva_end(va);\n+}\n+\n+void srcpos_set_line(char *f, int l)\n+{\n+\tcurrent_srcfile->name = f;\n+\tcurrent_srcfile->lineno = l;\n+}\ndiff --git a/scripts/dtc/srcpos.h b/scripts/dtc/srcpos.h\nnew file mode 100644\nindex 000000000000..2cdfcd82e95e\n--- /dev/null\n+++ b/scripts/dtc/srcpos.h\n@@ -0,0 +1,118 @@\n+/*\n+ * Copyright 2007 Jon Loeliger, Freescale Semiconductor, Inc.\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License as\n+ * published by the Free Software Foundation; either version 2 of the\n+ * License, or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\n+ * USA\n+ */\n+\n+#ifndef _SRCPOS_H_\n+#define _SRCPOS_H_\n+\n+#include <stdio.h>\n+#include <stdbool.h>\n+\n+struct srcfile_state {\n+\tFILE *f;\n+\tchar *name;\n+\tchar *dir;\n+\tint lineno, colno;\n+\tstruct srcfile_state *prev;\n+};\n+\n+extern FILE *depfile; /* = NULL */\n+extern struct srcfile_state *current_srcfile; /* = NULL */\n+\n+/**\n+ * Open a source file.\n+ *\n+ * If the source file is a relative pathname, then it is searched for in the\n+ * current directory (the directory of the last source file read) and after\n+ * that in the search path.\n+ *\n+ * We work through the search path in order from the first path specified to\n+ * the last.\n+ *\n+ * If the file is not found, then this function does not return, but calls\n+ * die().\n+ *\n+ * @param fname\t\tFilename to search\n+ * @param fullnamep\tIf non-NULL, it is set to the allocated filename of the\n+ *\t\t\tfile that was opened. The caller is then responsible\n+ *\t\t\tfor freeing the pointer.\n+ * @return pointer to opened FILE\n+ */\n+FILE *srcfile_relative_open(const char *fname, char **fullnamep);\n+\n+void srcfile_push(const char *fname);\n+bool srcfile_pop(void);\n+\n+/**\n+ * Add a new directory to the search path for input files\n+ *\n+ * The new path is added at the end of the list.\n+ *\n+ * @param dirname\tDirectory to add\n+ */\n+void srcfile_add_search_path(const char *dirname);\n+\n+struct srcpos {\n+ int first_line;\n+ int first_column;\n+ int last_line;\n+ int last_column;\n+ struct srcfile_state *file;\n+};\n+\n+#define YYLTYPE struct srcpos\n+\n+#define YYLLOC_DEFAULT(Current, Rhs, N)\t\t\t\t\t\t\\\n+\tdo {\t\t\t\t\t\t\t\t\t\\\n+\t\tif (N) {\t\t\t\t\t\t\t\\\n+\t\t\t(Current).first_line = YYRHSLOC(Rhs, 1).first_line;\t\\\n+\t\t\t(Current).first_column = YYRHSLOC(Rhs, 1).first_column;\t\\\n+\t\t\t(Current).last_line = YYRHSLOC(Rhs, N).last_line;\t\\\n+\t\t\t(Current).last_column = YYRHSLOC (Rhs, N).last_column;\t\\\n+\t\t\t(Current).file = YYRHSLOC(Rhs, N).file;\t\t\t\\\n+\t\t} else {\t\t\t\t\t\t\t\\\n+\t\t\t(Current).first_line = (Current).last_line =\t\t\\\n+\t\t\t\tYYRHSLOC(Rhs, 0).last_line;\t\t\t\\\n+\t\t\t(Current).first_column = (Current).last_column =\t\\\n+\t\t\t\tYYRHSLOC(Rhs, 0).last_column;\t\t\t\\\n+\t\t\t(Current).file = YYRHSLOC (Rhs, 0).file;\t\t\\\n+\t\t}\t\t\t\t\t\t\t\t\\\n+\t} while (0)\n+\n+\n+/*\n+ * Fictional source position used for IR nodes that are\n+ * created without otherwise knowing a true source position.\n+ * For example,constant definitions from the command line.\n+ */\n+extern struct srcpos srcpos_empty;\n+\n+extern void srcpos_update(struct srcpos *pos, const char *text, int len);\n+extern struct srcpos *srcpos_copy(struct srcpos *pos);\n+extern char *srcpos_string(struct srcpos *pos);\n+\n+extern void srcpos_verror(struct srcpos *pos, const char *prefix,\n+\t\t\t const char *fmt, va_list va)\n+\t__attribute__((format(printf, 3, 0)));\n+extern void srcpos_error(struct srcpos *pos, const char *prefix,\n+\t\t\t const char *fmt, ...)\n+\t__attribute__((format(printf, 3, 4)));\n+\n+extern void srcpos_set_line(char *f, int l);\n+\n+#endif /* _SRCPOS_H_ */\ndiff --git a/scripts/dtc/treesource.c b/scripts/dtc/treesource.c\nnew file mode 100644\nindex 000000000000..c9d8967969f9\n--- /dev/null\n+++ b/scripts/dtc/treesource.c\n@@ -0,0 +1,284 @@\n+/*\n+ * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.\n+ *\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License as\n+ * published by the Free Software Foundation; either version 2 of the\n+ * License, or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\n+ * USA\n+ */\n+\n+#include \"dtc.h\"\n+#include \"srcpos.h\"\n+\n+extern FILE *yyin;\n+extern int yyparse(void);\n+extern YYLTYPE yylloc;\n+\n+struct dt_info *parser_output;\n+bool treesource_error;\n+\n+struct dt_info *dt_from_source(const char *fname)\n+{\n+\tparser_output = NULL;\n+\ttreesource_error = false;\n+\n+\tsrcfile_push(fname);\n+\tyyin = current_srcfile->f;\n+\tyylloc.file = current_srcfile;\n+\n+\tif (yyparse() != 0)\n+\t\tdie(\"Unable to parse input tree\\n\");\n+\n+\tif (treesource_error)\n+\t\tdie(\"Syntax error parsing input tree\\n\");\n+\n+\treturn parser_output;\n+}\n+\n+static void write_prefix(FILE *f, int level)\n+{\n+\tint i;\n+\n+\tfor (i = 0; i < level; i++)\n+\t\tfputc('\\t', f);\n+}\n+\n+static bool isstring(char c)\n+{\n+\treturn (isprint((unsigned char)c)\n+\t\t|| (c == '\\0')\n+\t\t|| strchr(\"\\a\\b\\t\\n\\v\\f\\r\", c));\n+}\n+\n+static void write_propval_string(FILE *f, struct data val)\n+{\n+\tconst char *str = val.val;\n+\tint i;\n+\tstruct marker *m = val.markers;\n+\n+\tassert(str[val.len-1] == '\\0');\n+\n+\twhile (m && (m->offset == 0)) {\n+\t\tif (m->type == LABEL)\n+\t\t\tfprintf(f, \"%s: \", m->ref);\n+\t\tm = m->next;\n+\t}\n+\tfprintf(f, \"\\\"\");\n+\n+\tfor (i = 0; i < (val.len-1); i++) {\n+\t\tchar c = str[i];\n+\n+\t\tswitch (c) {\n+\t\tcase '\\a':\n+\t\t\tfprintf(f, \"\\\\a\");\n+\t\t\tbreak;\n+\t\tcase '\\b':\n+\t\t\tfprintf(f, \"\\\\b\");\n+\t\t\tbreak;\n+\t\tcase '\\t':\n+\t\t\tfprintf(f, \"\\\\t\");\n+\t\t\tbreak;\n+\t\tcase '\\n':\n+\t\t\tfprintf(f, \"\\\\n\");\n+\t\t\tbreak;\n+\t\tcase '\\v':\n+\t\t\tfprintf(f, \"\\\\v\");\n+\t\t\tbreak;\n+\t\tcase '\\f':\n+\t\t\tfprintf(f, \"\\\\f\");\n+\t\t\tbreak;\n+\t\tcase '\\r':\n+\t\t\tfprintf(f, \"\\\\r\");\n+\t\t\tbreak;\n+\t\tcase '\\\\':\n+\t\t\tfprintf(f, \"\\\\\\\\\");\n+\t\t\tbreak;\n+\t\tcase '\\\"':\n+\t\t\tfprintf(f, \"\\\\\\\"\");\n+\t\t\tbreak;\n+\t\tcase '\\0':\n+\t\t\tfprintf(f, \"\\\", \");\n+\t\t\twhile (m && (m->offset <= (i + 1))) {\n+\t\t\t\tif (m->type == LABEL) {\n+\t\t\t\t\tassert(m->offset == (i+1));\n+\t\t\t\t\tfprintf(f, \"%s: \", m->ref);\n+\t\t\t\t}\n+\t\t\t\tm = m->next;\n+\t\t\t}\n+\t\t\tfprintf(f, \"\\\"\");\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\tif (isprint((unsigned char)c))\n+\t\t\t\tfprintf(f, \"%c\", c);\n+\t\t\telse\n+\t\t\t\tfprintf(f, \"\\\\x%02hhx\", c);\n+\t\t}\n+\t}\n+\tfprintf(f, \"\\\"\");\n+\n+\t/* Wrap up any labels at the end of the value */\n+\tfor_each_marker_of_type(m, LABEL) {\n+\t\tassert (m->offset == val.len);\n+\t\tfprintf(f, \" %s:\", m->ref);\n+\t}\n+}\n+\n+static void write_propval_cells(FILE *f, struct data val)\n+{\n+\tvoid *propend = val.val + val.len;\n+\tcell_t *cp = (cell_t *)val.val;\n+\tstruct marker *m = val.markers;\n+\n+\tfprintf(f, \"<\");\n+\tfor (;;) {\n+\t\twhile (m && (m->offset <= ((char *)cp - val.val))) {\n+\t\t\tif (m->type == LABEL) {\n+\t\t\t\tassert(m->offset == ((char *)cp - val.val));\n+\t\t\t\tfprintf(f, \"%s: \", m->ref);\n+\t\t\t}\n+\t\t\tm = m->next;\n+\t\t}\n+\n+\t\tfprintf(f, \"0x%x\", fdt32_to_cpu(*cp++));\n+\t\tif ((void *)cp >= propend)\n+\t\t\tbreak;\n+\t\tfprintf(f, \" \");\n+\t}\n+\n+\t/* Wrap up any labels at the end of the value */\n+\tfor_each_marker_of_type(m, LABEL) {\n+\t\tassert (m->offset == val.len);\n+\t\tfprintf(f, \" %s:\", m->ref);\n+\t}\n+\tfprintf(f, \">\");\n+}\n+\n+static void write_propval_bytes(FILE *f, struct data val)\n+{\n+\tvoid *propend = val.val + val.len;\n+\tconst char *bp = val.val;\n+\tstruct marker *m = val.markers;\n+\n+\tfprintf(f, \"[\");\n+\tfor (;;) {\n+\t\twhile (m && (m->offset == (bp-val.val))) {\n+\t\t\tif (m->type == LABEL)\n+\t\t\t\tfprintf(f, \"%s: \", m->ref);\n+\t\t\tm = m->next;\n+\t\t}\n+\n+\t\tfprintf(f, \"%02hhx\", (unsigned char)(*bp++));\n+\t\tif ((const void *)bp >= propend)\n+\t\t\tbreak;\n+\t\tfprintf(f, \" \");\n+\t}\n+\n+\t/* Wrap up any labels at the end of the value */\n+\tfor_each_marker_of_type(m, LABEL) {\n+\t\tassert (m->offset == val.len);\n+\t\tfprintf(f, \" %s:\", m->ref);\n+\t}\n+\tfprintf(f, \"]\");\n+}\n+\n+static void write_propval(FILE *f, struct property *prop)\n+{\n+\tint len = prop->val.len;\n+\tconst char *p = prop->val.val;\n+\tstruct marker *m = prop->val.markers;\n+\tint nnotstring = 0, nnul = 0;\n+\tint nnotstringlbl = 0, nnotcelllbl = 0;\n+\tint i;\n+\n+\tif (len == 0) {\n+\t\tfprintf(f, \";\\n\");\n+\t\treturn;\n+\t}\n+\n+\tfor (i = 0; i < len; i++) {\n+\t\tif (! isstring(p[i]))\n+\t\t\tnnotstring++;\n+\t\tif (p[i] == '\\0')\n+\t\t\tnnul++;\n+\t}\n+\n+\tfor_each_marker_of_type(m, LABEL) {\n+\t\tif ((m->offset > 0) && (prop->val.val[m->offset - 1] != '\\0'))\n+\t\t\tnnotstringlbl++;\n+\t\tif ((m->offset % sizeof(cell_t)) != 0)\n+\t\t\tnnotcelllbl++;\n+\t}\n+\n+\tfprintf(f, \" = \");\n+\tif ((p[len-1] == '\\0') && (nnotstring == 0) && (nnul < (len-nnul))\n+\t && (nnotstringlbl == 0)) {\n+\t\twrite_propval_string(f, prop->val);\n+\t} else if (((len % sizeof(cell_t)) == 0) && (nnotcelllbl == 0)) {\n+\t\twrite_propval_cells(f, prop->val);\n+\t} else {\n+\t\twrite_propval_bytes(f, prop->val);\n+\t}\n+\n+\tfprintf(f, \";\\n\");\n+}\n+\n+static void write_tree_source_node(FILE *f, struct node *tree, int level)\n+{\n+\tstruct property *prop;\n+\tstruct node *child;\n+\tstruct label *l;\n+\n+\twrite_prefix(f, level);\n+\tfor_each_label(tree->labels, l)\n+\t\tfprintf(f, \"%s: \", l->label);\n+\tif (tree->name && (*tree->name))\n+\t\tfprintf(f, \"%s {\\n\", tree->name);\n+\telse\n+\t\tfprintf(f, \"/ {\\n\");\n+\n+\tfor_each_property(tree, prop) {\n+\t\twrite_prefix(f, level+1);\n+\t\tfor_each_label(prop->labels, l)\n+\t\t\tfprintf(f, \"%s: \", l->label);\n+\t\tfprintf(f, \"%s\", prop->name);\n+\t\twrite_propval(f, prop);\n+\t}\n+\tfor_each_child(tree, child) {\n+\t\tfprintf(f, \"\\n\");\n+\t\twrite_tree_source_node(f, child, level+1);\n+\t}\n+\twrite_prefix(f, level);\n+\tfprintf(f, \"};\\n\");\n+}\n+\n+\n+void dt_to_source(FILE *f, struct dt_info *dti)\n+{\n+\tstruct reserve_info *re;\n+\n+\tfprintf(f, \"/dts-v1/;\\n\\n\");\n+\n+\tfor (re = dti->reservelist; re; re = re->next) {\n+\t\tstruct label *l;\n+\n+\t\tfor_each_label(re->labels, l)\n+\t\t\tfprintf(f, \"%s: \", l->label);\n+\t\tfprintf(f, \"/memreserve/\\t0x%016llx 0x%016llx;\\n\",\n+\t\t\t(unsigned long long)re->re.address,\n+\t\t\t(unsigned long long)re->re.size);\n+\t}\n+\n+\twrite_tree_source_node(f, dti->dt, 0);\n+}\n+\ndiff --git a/scripts/dtc/update-dtc-source.sh b/scripts/dtc/update-dtc-source.sh\nnew file mode 100755\nindex 000000000000..b8ebcc6722d2\n--- /dev/null\n+++ b/scripts/dtc/update-dtc-source.sh\n@@ -0,0 +1,81 @@\n+#!/bin/sh\n+# Simple script to update the version of DTC carried by the Linux kernel\n+#\n+# This script assumes that the dtc and the linux git trees are in the\n+# same directory. After building dtc in the dtc directory, it copies the\n+# source files and generated source files into the scripts/dtc directory\n+# in the kernel and creates a git commit updating them to the new\n+# version.\n+#\n+# Usage: from the top level Linux source tree, run:\n+# $ ./scripts/dtc/update-dtc-source.sh\n+#\n+# The script will change into the dtc tree, build and test dtc, copy the\n+# relevant files into the kernel tree and create a git commit. The commit\n+# message will need to be modified to reflect the version of DTC being\n+# imported\n+#\n+# TODO:\n+# This script is pretty basic, but it is seldom used so a few manual tasks\n+# aren't a big deal. If anyone is interested in making it more robust, the\n+# the following would be nice:\n+# * Actually fail to complete if any testcase fails.\n+# - The dtc \"make check\" target needs to return a failure\n+# * Extract the version number from the dtc repo for the commit message\n+# * Build dtc in the kernel tree\n+# * run 'make check\" on dtc built from the kernel tree\n+\n+set -ev\n+\n+DTC_UPSTREAM_PATH=`pwd`/../dtc\n+DTC_LINUX_PATH=`pwd`/scripts/dtc\n+\n+DTC_SOURCE=\"checks.c data.c dtc.c dtc.h flattree.c fstree.c livetree.c srcpos.c \\\n+\t\tsrcpos.h treesource.c util.c util.h version_gen.h Makefile.dtc \\\n+\t\tdtc-lexer.l dtc-parser.y\"\n+DTC_GENERATED=\"dtc-lexer.lex.c dtc-parser.tab.c dtc-parser.tab.h\"\n+LIBFDT_SOURCE=\"Makefile.libfdt fdt.c fdt.h fdt_empty_tree.c fdt_ro.c fdt_rw.c fdt_strerror.c fdt_sw.c fdt_wip.c libfdt.h libfdt_env.h libfdt_internal.h\"\n+\n+get_last_dtc_version() {\n+\tgit log --oneline scripts/dtc/ | grep 'upstream' | head -1 | sed -e 's/^.* \\(.*\\)/\\1/'\n+}\n+\n+last_dtc_ver=$(get_last_dtc_version)\n+\n+# Build DTC\n+cd $DTC_UPSTREAM_PATH\n+make clean\n+make check\n+dtc_version=$(git describe HEAD)\n+dtc_log=$(git log --oneline ${last_dtc_ver}..)\n+\n+\n+# Copy the files into the Linux tree\n+cd $DTC_LINUX_PATH\n+for f in $DTC_SOURCE; do\n+\tcp ${DTC_UPSTREAM_PATH}/${f} ${f}\n+\tgit add ${f}\n+done\n+for f in $DTC_GENERATED; do\n+\tcp ${DTC_UPSTREAM_PATH}/$f ${f}_shipped\n+\tgit add ${f}_shipped\n+done\n+for f in $LIBFDT_SOURCE; do\n+ cp ${DTC_UPSTREAM_PATH}/libfdt/${f} libfdt/${f}\n+ git add libfdt/${f}\n+done\n+\n+sed -i -- 's/#include <libfdt_env.h>/#include \"libfdt_env.h\"/g' ./libfdt/libfdt.h\n+sed -i -- 's/#include <fdt.h>/#include \"fdt.h\"/g' ./libfdt/libfdt.h\n+git add ./libfdt/libfdt.h\n+\n+commit_msg=$(cat << EOF\n+scripts/dtc: Update to upstream version ${dtc_version}\n+\n+This adds the following commits from upstream:\n+\n+${dtc_log}\n+EOF\n+)\n+\n+git commit -e -v -s -m \"${commit_msg}\"\ndiff --git a/scripts/dtc/util.c b/scripts/dtc/util.c\nnew file mode 100644\nindex 000000000000..3550f86bd6df\n--- /dev/null\n+++ b/scripts/dtc/util.c\n@@ -0,0 +1,473 @@\n+/*\n+ * Copyright 2011 The Chromium Authors, All Rights Reserved.\n+ * Copyright 2008 Jon Loeliger, Freescale Semiconductor, Inc.\n+ *\n+ * util_is_printable_string contributed by\n+ *\tPantelis Antoniou <pantelis.antoniou AT gmail.com>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License as\n+ * published by the Free Software Foundation; either version 2 of the\n+ * License, or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\n+ * USA\n+ */\n+\n+#include <ctype.h>\n+#include <stdio.h>\n+#include <stdlib.h>\n+#include <stdarg.h>\n+#include <string.h>\n+#include <assert.h>\n+\n+#include <errno.h>\n+#include <fcntl.h>\n+#include <unistd.h>\n+\n+#include \"libfdt.h\"\n+#include \"util.h\"\n+#include \"version_gen.h\"\n+\n+char *xstrdup(const char *s)\n+{\n+\tint len = strlen(s) + 1;\n+\tchar *d = xmalloc(len);\n+\n+\tmemcpy(d, s, len);\n+\n+\treturn d;\n+}\n+\n+/* based in part from (3) vsnprintf */\n+int xasprintf(char **strp, const char *fmt, ...)\n+{\n+\tint n, size = 128;\t/* start with 128 bytes */\n+\tchar *p;\n+\tva_list ap;\n+\n+\t/* initial pointer is NULL making the fist realloc to be malloc */\n+\tp = NULL;\n+\twhile (1) {\n+\t\tp = xrealloc(p, size);\n+\n+\t\t/* Try to print in the allocated space. */\n+\t\tva_start(ap, fmt);\n+\t\tn = vsnprintf(p, size, fmt, ap);\n+\t\tva_end(ap);\n+\n+\t\t/* If that worked, return the string. */\n+\t\tif (n > -1 && n < size)\n+\t\t\tbreak;\n+\t\t/* Else try again with more space. */\n+\t\tif (n > -1)\t/* glibc 2.1 */\n+\t\t\tsize = n + 1; /* precisely what is needed */\n+\t\telse\t\t/* glibc 2.0 */\n+\t\t\tsize *= 2; /* twice the old size */\n+\t}\n+\t*strp = p;\n+\treturn strlen(p);\n+}\n+\n+char *join_path(const char *path, const char *name)\n+{\n+\tint lenp = strlen(path);\n+\tint lenn = strlen(name);\n+\tint len;\n+\tint needslash = 1;\n+\tchar *str;\n+\n+\tlen = lenp + lenn + 2;\n+\tif ((lenp > 0) && (path[lenp-1] == '/')) {\n+\t\tneedslash = 0;\n+\t\tlen--;\n+\t}\n+\n+\tstr = xmalloc(len);\n+\tmemcpy(str, path, lenp);\n+\tif (needslash) {\n+\t\tstr[lenp] = '/';\n+\t\tlenp++;\n+\t}\n+\tmemcpy(str+lenp, name, lenn+1);\n+\treturn str;\n+}\n+\n+bool util_is_printable_string(const void *data, int len)\n+{\n+\tconst char *s = data;\n+\tconst char *ss, *se;\n+\n+\t/* zero length is not */\n+\tif (len == 0)\n+\t\treturn 0;\n+\n+\t/* must terminate with zero */\n+\tif (s[len - 1] != '\\0')\n+\t\treturn 0;\n+\n+\tse = s + len;\n+\n+\twhile (s < se) {\n+\t\tss = s;\n+\t\twhile (s < se && *s && isprint((unsigned char)*s))\n+\t\t\ts++;\n+\n+\t\t/* not zero, or not done yet */\n+\t\tif (*s != '\\0' || s == ss)\n+\t\t\treturn 0;\n+\n+\t\ts++;\n+\t}\n+\n+\treturn 1;\n+}\n+\n+/*\n+ * Parse a octal encoded character starting at index i in string s. The\n+ * resulting character will be returned and the index i will be updated to\n+ * point at the character directly after the end of the encoding, this may be\n+ * the '\\0' terminator of the string.\n+ */\n+static char get_oct_char(const char *s, int *i)\n+{\n+\tchar x[4];\n+\tchar *endx;\n+\tlong val;\n+\n+\tx[3] = '\\0';\n+\tstrncpy(x, s + *i, 3);\n+\n+\tval = strtol(x, &endx, 8);\n+\n+\tassert(endx > x);\n+\n+\t(*i) += endx - x;\n+\treturn val;\n+}\n+\n+/*\n+ * Parse a hexadecimal encoded character starting at index i in string s. The\n+ * resulting character will be returned and the index i will be updated to\n+ * point at the character directly after the end of the encoding, this may be\n+ * the '\\0' terminator of the string.\n+ */\n+static char get_hex_char(const char *s, int *i)\n+{\n+\tchar x[3];\n+\tchar *endx;\n+\tlong val;\n+\n+\tx[2] = '\\0';\n+\tstrncpy(x, s + *i, 2);\n+\n+\tval = strtol(x, &endx, 16);\n+\tif (!(endx > x))\n+\t\tdie(\"\\\\x used with no following hex digits\\n\");\n+\n+\t(*i) += endx - x;\n+\treturn val;\n+}\n+\n+char get_escape_char(const char *s, int *i)\n+{\n+\tchar\tc = s[*i];\n+\tint\tj = *i + 1;\n+\tchar\tval;\n+\n+\tswitch (c) {\n+\tcase 'a':\n+\t\tval = '\\a';\n+\t\tbreak;\n+\tcase 'b':\n+\t\tval = '\\b';\n+\t\tbreak;\n+\tcase 't':\n+\t\tval = '\\t';\n+\t\tbreak;\n+\tcase 'n':\n+\t\tval = '\\n';\n+\t\tbreak;\n+\tcase 'v':\n+\t\tval = '\\v';\n+\t\tbreak;\n+\tcase 'f':\n+\t\tval = '\\f';\n+\t\tbreak;\n+\tcase 'r':\n+\t\tval = '\\r';\n+\t\tbreak;\n+\tcase '0':\n+\tcase '1':\n+\tcase '2':\n+\tcase '3':\n+\tcase '4':\n+\tcase '5':\n+\tcase '6':\n+\tcase '7':\n+\t\tj--; /* need to re-read the first digit as\n+\t\t * part of the octal value */\n+\t\tval = get_oct_char(s, &j);\n+\t\tbreak;\n+\tcase 'x':\n+\t\tval = get_hex_char(s, &j);\n+\t\tbreak;\n+\tdefault:\n+\t\tval = c;\n+\t}\n+\n+\t(*i) = j;\n+\treturn val;\n+}\n+\n+int utilfdt_read_err_len(const char *filename, char **buffp, off_t *len)\n+{\n+\tint fd = 0;\t/* assume stdin */\n+\tchar *buf = NULL;\n+\toff_t bufsize = 1024, offset = 0;\n+\tint ret = 0;\n+\n+\t*buffp = NULL;\n+\tif (strcmp(filename, \"-\") != 0) {\n+\t\tfd = open(filename, O_RDONLY);\n+\t\tif (fd < 0)\n+\t\t\treturn errno;\n+\t}\n+\n+\t/* Loop until we have read everything */\n+\tbuf = xmalloc(bufsize);\n+\tdo {\n+\t\t/* Expand the buffer to hold the next chunk */\n+\t\tif (offset == bufsize) {\n+\t\t\tbufsize *= 2;\n+\t\t\tbuf = xrealloc(buf, bufsize);\n+\t\t}\n+\n+\t\tret = read(fd, &buf[offset], bufsize - offset);\n+\t\tif (ret < 0) {\n+\t\t\tret = errno;\n+\t\t\tbreak;\n+\t\t}\n+\t\toffset += ret;\n+\t} while (ret != 0);\n+\n+\t/* Clean up, including closing stdin; return errno on error */\n+\tclose(fd);\n+\tif (ret)\n+\t\tfree(buf);\n+\telse\n+\t\t*buffp = buf;\n+\t*len = bufsize;\n+\treturn ret;\n+}\n+\n+int utilfdt_read_err(const char *filename, char **buffp)\n+{\n+\toff_t len;\n+\treturn utilfdt_read_err_len(filename, buffp, &len);\n+}\n+\n+char *utilfdt_read_len(const char *filename, off_t *len)\n+{\n+\tchar *buff;\n+\tint ret = utilfdt_read_err_len(filename, &buff, len);\n+\n+\tif (ret) {\n+\t\tfprintf(stderr, \"Couldn't open blob from '%s': %s\\n\", filename,\n+\t\t\tstrerror(ret));\n+\t\treturn NULL;\n+\t}\n+\t/* Successful read */\n+\treturn buff;\n+}\n+\n+char *utilfdt_read(const char *filename)\n+{\n+\toff_t len;\n+\treturn utilfdt_read_len(filename, &len);\n+}\n+\n+int utilfdt_write_err(const char *filename, const void *blob)\n+{\n+\tint fd = 1;\t/* assume stdout */\n+\tint totalsize;\n+\tint offset;\n+\tint ret = 0;\n+\tconst char *ptr = blob;\n+\n+\tif (strcmp(filename, \"-\") != 0) {\n+\t\tfd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);\n+\t\tif (fd < 0)\n+\t\t\treturn errno;\n+\t}\n+\n+\ttotalsize = fdt_totalsize(blob);\n+\toffset = 0;\n+\n+\twhile (offset < totalsize) {\n+\t\tret = write(fd, ptr + offset, totalsize - offset);\n+\t\tif (ret < 0) {\n+\t\t\tret = -errno;\n+\t\t\tbreak;\n+\t\t}\n+\t\toffset += ret;\n+\t}\n+\t/* Close the file/stdin; return errno on error */\n+\tif (fd != 1)\n+\t\tclose(fd);\n+\treturn ret < 0 ? -ret : 0;\n+}\n+\n+\n+int utilfdt_write(const char *filename, const void *blob)\n+{\n+\tint ret = utilfdt_write_err(filename, blob);\n+\n+\tif (ret) {\n+\t\tfprintf(stderr, \"Couldn't write blob to '%s': %s\\n\", filename,\n+\t\t\tstrerror(ret));\n+\t}\n+\treturn ret ? -1 : 0;\n+}\n+\n+int utilfdt_decode_type(const char *fmt, int *type, int *size)\n+{\n+\tint qualifier = 0;\n+\n+\tif (!*fmt)\n+\t\treturn -1;\n+\n+\t/* get the conversion qualifier */\n+\t*size = -1;\n+\tif (strchr(\"hlLb\", *fmt)) {\n+\t\tqualifier = *fmt++;\n+\t\tif (qualifier == *fmt) {\n+\t\t\tswitch (*fmt++) {\n+/* TODO:\t\tcase 'l': qualifier = 'L'; break;*/\n+\t\t\tcase 'h':\n+\t\t\t\tqualifier = 'b';\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+\t/* we should now have a type */\n+\tif ((*fmt == '\\0') || !strchr(\"iuxs\", *fmt))\n+\t\treturn -1;\n+\n+\t/* convert qualifier (bhL) to byte size */\n+\tif (*fmt != 's')\n+\t\t*size = qualifier == 'b' ? 1 :\n+\t\t\t\tqualifier == 'h' ? 2 :\n+\t\t\t\tqualifier == 'l' ? 4 : -1;\n+\t*type = *fmt++;\n+\n+\t/* that should be it! */\n+\tif (*fmt)\n+\t\treturn -1;\n+\treturn 0;\n+}\n+\n+void utilfdt_print_data(const char *data, int len)\n+{\n+\tint i;\n+\tconst char *s;\n+\n+\t/* no data, don't print */\n+\tif (len == 0)\n+\t\treturn;\n+\n+\tif (util_is_printable_string(data, len)) {\n+\t\tprintf(\" = \");\n+\n+\t\ts = data;\n+\t\tdo {\n+\t\t\tprintf(\"\\\"%s\\\"\", s);\n+\t\t\ts += strlen(s) + 1;\n+\t\t\tif (s < data + len)\n+\t\t\t\tprintf(\", \");\n+\t\t} while (s < data + len);\n+\n+\t} else if ((len % 4) == 0) {\n+\t\tconst uint32_t *cell = (const uint32_t *)data;\n+\n+\t\tprintf(\" = <\");\n+\t\tfor (i = 0, len /= 4; i < len; i++)\n+\t\t\tprintf(\"0x%08x%s\", fdt32_to_cpu(cell[i]),\n+\t\t\t i < (len - 1) ? \" \" : \"\");\n+\t\tprintf(\">\");\n+\t} else {\n+\t\tconst unsigned char *p = (const unsigned char *)data;\n+\t\tprintf(\" = [\");\n+\t\tfor (i = 0; i < len; i++)\n+\t\t\tprintf(\"%02x%s\", *p++, i < len - 1 ? \" \" : \"\");\n+\t\tprintf(\"]\");\n+\t}\n+}\n+\n+void util_version(void)\n+{\n+\tprintf(\"Version: %s\\n\", DTC_VERSION);\n+\texit(0);\n+}\n+\n+void util_usage(const char *errmsg, const char *synopsis,\n+\t\tconst char *short_opts, struct option const long_opts[],\n+\t\tconst char * const opts_help[])\n+{\n+\tFILE *fp = errmsg ? stderr : stdout;\n+\tconst char a_arg[] = \"<arg>\";\n+\tsize_t a_arg_len = strlen(a_arg) + 1;\n+\tsize_t i;\n+\tint optlen;\n+\n+\tfprintf(fp,\n+\t\t\"Usage: %s\\n\"\n+\t\t\"\\n\"\n+\t\t\"Options: -[%s]\\n\", synopsis, short_opts);\n+\n+\t/* prescan the --long opt length to auto-align */\n+\toptlen = 0;\n+\tfor (i = 0; long_opts[i].name; ++i) {\n+\t\t/* +1 is for space between --opt and help text */\n+\t\tint l = strlen(long_opts[i].name) + 1;\n+\t\tif (long_opts[i].has_arg == a_argument)\n+\t\t\tl += a_arg_len;\n+\t\tif (optlen < l)\n+\t\t\toptlen = l;\n+\t}\n+\n+\tfor (i = 0; long_opts[i].name; ++i) {\n+\t\t/* helps when adding new applets or options */\n+\t\tassert(opts_help[i] != NULL);\n+\n+\t\t/* first output the short flag if it has one */\n+\t\tif (long_opts[i].val > '~')\n+\t\t\tfprintf(fp, \" \");\n+\t\telse\n+\t\t\tfprintf(fp, \" -%c, \", long_opts[i].val);\n+\n+\t\t/* then the long flag */\n+\t\tif (long_opts[i].has_arg == no_argument)\n+\t\t\tfprintf(fp, \"--%-*s\", optlen, long_opts[i].name);\n+\t\telse\n+\t\t\tfprintf(fp, \"--%s %s%*s\", long_opts[i].name, a_arg,\n+\t\t\t\t(int)(optlen - strlen(long_opts[i].name) - a_arg_len), \"\");\n+\n+\t\t/* finally the help text */\n+\t\tfprintf(fp, \"%s\\n\", opts_help[i]);\n+\t}\n+\n+\tif (errmsg) {\n+\t\tfprintf(fp, \"\\nError: %s\\n\", errmsg);\n+\t\texit(EXIT_FAILURE);\n+\t} else\n+\t\texit(EXIT_SUCCESS);\n+}\ndiff --git a/scripts/dtc/util.h b/scripts/dtc/util.h\nnew file mode 100644\nindex 000000000000..bc3d223fa6e3\n--- /dev/null\n+++ b/scripts/dtc/util.h\n@@ -0,0 +1,265 @@\n+#ifndef _UTIL_H\n+#define _UTIL_H\n+\n+#include <stdarg.h>\n+#include <stdbool.h>\n+#include <getopt.h>\n+\n+/*\n+ * Copyright 2011 The Chromium Authors, All Rights Reserved.\n+ * Copyright 2008 Jon Loeliger, Freescale Semiconductor, Inc.\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License as\n+ * published by the Free Software Foundation; either version 2 of the\n+ * License, or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\n+ * USA\n+ */\n+\n+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))\n+\n+#ifdef __GNUC__\n+static inline void\n+__attribute__((noreturn)) __attribute__((format (printf, 1, 2)))\n+die(const char *str, ...)\n+#else\n+static inline void die(const char *str, ...)\n+#endif\n+{\n+\tva_list ap;\n+\n+\tva_start(ap, str);\n+\tfprintf(stderr, \"FATAL ERROR: \");\n+\tvfprintf(stderr, str, ap);\n+\tva_end(ap);\n+\texit(1);\n+}\n+\n+static inline void *xmalloc(size_t len)\n+{\n+\tvoid *new = malloc(len);\n+\n+\tif (!new)\n+\t\tdie(\"malloc() failed\\n\");\n+\n+\treturn new;\n+}\n+\n+static inline void *xrealloc(void *p, size_t len)\n+{\n+\tvoid *new = realloc(p, len);\n+\n+\tif (!new)\n+\t\tdie(\"realloc() failed (len=%zd)\\n\", len);\n+\n+\treturn new;\n+}\n+\n+extern char *xstrdup(const char *s);\n+\n+#ifdef __GNUC__\n+extern int __attribute__((format (printf, 2, 3)))\n+xasprintf(char **strp, const char *fmt, ...);\n+#else\n+extern int xasprintf(char **strp, const char *fmt, ...);\n+#endif\n+extern char *join_path(const char *path, const char *name);\n+\n+/**\n+ * Check a property of a given length to see if it is all printable and\n+ * has a valid terminator. The property can contain either a single string,\n+ * or multiple strings each of non-zero length.\n+ *\n+ * @param data\tThe string to check\n+ * @param len\tThe string length including terminator\n+ * @return 1 if a valid printable string, 0 if not\n+ */\n+bool util_is_printable_string(const void *data, int len);\n+\n+/*\n+ * Parse an escaped character starting at index i in string s. The resulting\n+ * character will be returned and the index i will be updated to point at the\n+ * character directly after the end of the encoding, this may be the '\\0'\n+ * terminator of the string.\n+ */\n+char get_escape_char(const char *s, int *i);\n+\n+/**\n+ * Read a device tree file into a buffer. This will report any errors on\n+ * stderr.\n+ *\n+ * @param filename\tThe filename to read, or - for stdin\n+ * @return Pointer to allocated buffer containing fdt, or NULL on error\n+ */\n+char *utilfdt_read(const char *filename);\n+\n+/**\n+ * Like utilfdt_read(), but also passes back the size of the file read.\n+ *\n+ * @param len\t\tIf non-NULL, the amount of data we managed to read\n+ */\n+char *utilfdt_read_len(const char *filename, off_t *len);\n+\n+/**\n+ * Read a device tree file into a buffer. Does not report errors, but only\n+ * returns them. The value returned can be passed to strerror() to obtain\n+ * an error message for the user.\n+ *\n+ * @param filename\tThe filename to read, or - for stdin\n+ * @param buffp\t\tReturns pointer to buffer containing fdt\n+ * @return 0 if ok, else an errno value representing the error\n+ */\n+int utilfdt_read_err(const char *filename, char **buffp);\n+\n+/**\n+ * Like utilfdt_read_err(), but also passes back the size of the file read.\n+ *\n+ * @param len\t\tIf non-NULL, the amount of data we managed to read\n+ */\n+int utilfdt_read_err_len(const char *filename, char **buffp, off_t *len);\n+\n+/**\n+ * Write a device tree buffer to a file. This will report any errors on\n+ * stderr.\n+ *\n+ * @param filename\tThe filename to write, or - for stdout\n+ * @param blob\t\tPoiner to buffer containing fdt\n+ * @return 0 if ok, -1 on error\n+ */\n+int utilfdt_write(const char *filename, const void *blob);\n+\n+/**\n+ * Write a device tree buffer to a file. Does not report errors, but only\n+ * returns them. The value returned can be passed to strerror() to obtain\n+ * an error message for the user.\n+ *\n+ * @param filename\tThe filename to write, or - for stdout\n+ * @param blob\t\tPoiner to buffer containing fdt\n+ * @return 0 if ok, else an errno value representing the error\n+ */\n+int utilfdt_write_err(const char *filename, const void *blob);\n+\n+/**\n+ * Decode a data type string. The purpose of this string\n+ *\n+ * The string consists of an optional character followed by the type:\n+ *\tModifier characters:\n+ *\t\thh or b\t1 byte\n+ *\t\th\t2 byte\n+ *\t\tl\t4 byte, default\n+ *\n+ *\tType character:\n+ *\t\ts\tstring\n+ *\t\ti\tsigned integer\n+ *\t\tu\tunsigned integer\n+ *\t\tx\thex\n+ *\n+ * TODO: Implement ll modifier (8 bytes)\n+ * TODO: Implement o type (octal)\n+ *\n+ * @param fmt\t\tFormat string to process\n+ * @param type\t\tReturns type found(s/d/u/x), or 0 if none\n+ * @param size\t\tReturns size found(1,2,4,8) or 4 if none\n+ * @return 0 if ok, -1 on error (no type given, or other invalid format)\n+ */\n+int utilfdt_decode_type(const char *fmt, int *type, int *size);\n+\n+/*\n+ * This is a usage message fragment for the -t option. It is the format\n+ * supported by utilfdt_decode_type.\n+ */\n+\n+#define USAGE_TYPE_MSG \\\n+\t\"<type>\\ts=string, i=int, u=unsigned, x=hex\\n\" \\\n+\t\"\\tOptional modifier prefix:\\n\" \\\n+\t\"\\t\\thh or b=byte, h=2 byte, l=4 byte (default)\";\n+\n+/**\n+ * Print property data in a readable format to stdout\n+ *\n+ * Properties that look like strings will be printed as strings. Otherwise\n+ * the data will be displayed either as cells (if len is a multiple of 4\n+ * bytes) or bytes.\n+ *\n+ * If len is 0 then this function does nothing.\n+ *\n+ * @param data\tPointers to property data\n+ * @param len\tLength of property data\n+ */\n+void utilfdt_print_data(const char *data, int len);\n+\n+/**\n+ * Show source version and exit\n+ */\n+void util_version(void) __attribute__((noreturn));\n+\n+/**\n+ * Show usage and exit\n+ *\n+ * This helps standardize the output of various utils. You most likely want\n+ * to use the usage() helper below rather than call this.\n+ *\n+ * @param errmsg\tIf non-NULL, an error message to display\n+ * @param synopsis\tThe initial example usage text (and possible examples)\n+ * @param short_opts\tThe string of short options\n+ * @param long_opts\tThe structure of long options\n+ * @param opts_help\tAn array of help strings (should align with long_opts)\n+ */\n+void util_usage(const char *errmsg, const char *synopsis,\n+\t\tconst char *short_opts, struct option const long_opts[],\n+\t\tconst char * const opts_help[]) __attribute__((noreturn));\n+\n+/**\n+ * Show usage and exit\n+ *\n+ * If you name all your usage variables with usage_xxx, then you can call this\n+ * help macro rather than expanding all arguments yourself.\n+ *\n+ * @param errmsg\tIf non-NULL, an error message to display\n+ */\n+#define usage(errmsg) \\\n+\tutil_usage(errmsg, usage_synopsis, usage_short_opts, \\\n+\t\t usage_long_opts, usage_opts_help)\n+\n+/**\n+ * Call getopt_long() with standard options\n+ *\n+ * Since all util code runs getopt in the same way, provide a helper.\n+ */\n+#define util_getopt_long() getopt_long(argc, argv, usage_short_opts, \\\n+\t\t\t\t usage_long_opts, NULL)\n+\n+/* Helper for aligning long_opts array */\n+#define a_argument required_argument\n+\n+/* Helper for usage_short_opts string constant */\n+#define USAGE_COMMON_SHORT_OPTS \"hV\"\n+\n+/* Helper for usage_long_opts option array */\n+#define USAGE_COMMON_LONG_OPTS \\\n+\t{\"help\", no_argument, NULL, 'h'}, \\\n+\t{\"version\", no_argument, NULL, 'V'}, \\\n+\t{NULL, no_argument, NULL, 0x0}\n+\n+/* Helper for usage_opts_help array */\n+#define USAGE_COMMON_OPTS_HELP \\\n+\t\"Print this help and exit\", \\\n+\t\"Print version and exit\", \\\n+\tNULL\n+\n+/* Helper for getopt case statements */\n+#define case_USAGE_COMMON_FLAGS \\\n+\tcase 'h': usage(NULL); \\\n+\tcase 'V': util_version(); \\\n+\tcase '?': usage(\"unknown option\");\n+\n+#endif /* _UTIL_H */\ndiff --git a/scripts/dtc/version_gen.h b/scripts/dtc/version_gen.h\nnew file mode 100644\nindex 000000000000..bbbd96b1dca3\n--- /dev/null\n+++ b/scripts/dtc/version_gen.h\n@@ -0,0 +1 @@\n+#define DTC_VERSION \"DTC 1.4.3\"\n", "prefixes": [ "U-Boot", "1/5" ] }