Author: imp
Date: Tue Jul 24 16:29:33 2012
New Revision: 238742
URL: http://svn.freebsd.org/changeset/base/238742

Log:
  Update to latest git version of dtc to get new dtsv2 support,
  including the include directive.
  
  Fix minor build issue corrected by converting yypush_buffer_state and
  yypop_buffer_state to yy_set_buffer_state and a hard-coded 100-deep
  stack.  It was easier to fix it here than to import that support into
  our flex.
  
  The new tools and test hardness remain unsupported at the moment.

Added:
  head/contrib/dtc/dtdiff
     - copied unchanged from r238738, vendor/dtc/dist/dtdiff
  head/contrib/dtc/fdtdump.c
     - copied unchanged from r238738, vendor/dtc/dist/fdtdump.c
  head/contrib/dtc/fdtget.c
     - copied unchanged from r238738, vendor/dtc/dist/fdtget.c
  head/contrib/dtc/fdtput.c
     - copied unchanged from r238738, vendor/dtc/dist/fdtput.c
  head/contrib/dtc/libfdt/fdt_empty_tree.c
     - copied unchanged from r238738, vendor/dtc/dist/libfdt/fdt_empty_tree.c
  head/sys/contrib/libfdt/fdt_empty_tree.c
     - copied unchanged from r238738, vendor/dtc/dist/libfdt/fdt_empty_tree.c
Modified:
  head/contrib/dtc/Documentation/dts-format.txt
  head/contrib/dtc/Documentation/manual.txt
  head/contrib/dtc/Makefile
  head/contrib/dtc/checks.c
  head/contrib/dtc/convert-dtsv0-lexer.l
  head/contrib/dtc/data.c
  head/contrib/dtc/dtc-lexer.l
  head/contrib/dtc/dtc-parser.y
  head/contrib/dtc/dtc.c
  head/contrib/dtc/dtc.h
  head/contrib/dtc/flattree.c
  head/contrib/dtc/fstree.c
  head/contrib/dtc/libfdt/Makefile.libfdt
  head/contrib/dtc/libfdt/fdt.c
  head/contrib/dtc/libfdt/fdt_ro.c
  head/contrib/dtc/libfdt/fdt_rw.c
  head/contrib/dtc/libfdt/libfdt.h
  head/contrib/dtc/libfdt/libfdt_env.h
  head/contrib/dtc/libfdt/libfdt_internal.h
  head/contrib/dtc/livetree.c
  head/contrib/dtc/srcpos.c
  head/contrib/dtc/srcpos.h
  head/contrib/dtc/treesource.c
  head/contrib/dtc/util.c
  head/contrib/dtc/util.h
  head/sys/contrib/libfdt/fdt.c
  head/sys/contrib/libfdt/fdt_ro.c
  head/sys/contrib/libfdt/fdt_rw.c
  head/sys/contrib/libfdt/libfdt.h
  head/sys/contrib/libfdt/libfdt_env.h
  head/sys/contrib/libfdt/libfdt_internal.h
Directory Properties:
  head/contrib/dtc/   (props changed)
  head/sys/contrib/libfdt/   (props changed)

Modified: head/contrib/dtc/Documentation/dts-format.txt
==============================================================================
--- head/contrib/dtc/Documentation/dts-format.txt       Tue Jul 24 16:03:28 
2012        (r238741)
+++ head/contrib/dtc/Documentation/dts-format.txt       Tue Jul 24 16:29:33 
2012        (r238742)
@@ -29,18 +29,28 @@ except for properties with empty (zero l
 form:
        [label:] property-name;
 
-Property values may be defined as an array of 32-bit integer cells, as
-NUL-terminated strings, as bytestrings or a combination of these.
+Property values may be defined as an array of 8, 16, 32, or 64-bit integer
+elements, as NUL-terminated strings, as bytestrings or a combination of these.
 
-* Arrays of cells are represented by angle brackets surrounding a
-  space separated list of C-style integers
+* Arrays are represented by angle brackets surrounding a space separated list
+  of C-style integers or character literals.  Array elements default to 32-bits
+  in size.  An array of 32-bit elements is also known as a cell list or a list
+  of cells.  A cell being an unsigned 32-bit integer.
 
        e.g. interrupts = <17 0xc>;
 
-* A 64-bit value is represented with two 32-bit cells.
+* A 64-bit value can be represented with two 32-bit elements.
 
        e.g. clock-frequency = <0x00000001 0x00000000>;
 
+* The storage size of an element can be changed using the /bits/ prefix.  The
+  /bits/ prefix allows for the creation of 8, 16, 32, and 64-bit elements.
+  The resulting array will not be padded to a multiple of the default 32-bit
+  element size.
+
+       e.g. interrupts = /bits/ 8 <17 0xc>;
+       e.g. clock-frequency = /bits/ 64 <0x0000000100000000>;
+
 * A NUL-terminated string value is represented using double quotes
   (the property value is considered to include the terminating NUL
   character).
@@ -59,19 +69,20 @@ NUL-terminated strings, as bytestrings o
        e.g. compatible = "ns16550", "ns8250";
             example = <0xf00f0000 19>, "a strange property format";
 
-* In a cell array a reference to another node will be expanded to that
-  node's phandle.  References may by '&' followed by a node's label:
+* In an array a reference to another node will be expanded to that node's
+  phandle.  References may by '&' followed by a node's label:
        e.g. interrupt-parent = < &mpic >;
   or they may be '&' followed by a node's full path in braces:
        e.g. interrupt-parent = < &{/soc/interrupt-controller@40000} >;
+  References are only permitted in arrays that have an element size of
+  32-bits.
 
-* Outside a cell array, a reference to another node will be expanded
-  to that node's full path.
+* Outside an array, a reference to another node will be expanded to that
+  node's full path.
        e.g. ethernet0 = &EMAC0;
 
 * Labels may also appear before or after any component of a property
-  value, or between cells of a cell array, or between bytes of a
-  bytestring.
+  value, or between elements of an array, or between bytes of a bytestring.
        e.g. reg = reglabel: <0 sizelabel: 0x1000000>;
        e.g. prop = [ab cd ef byte4: 00 ff fe];
        e.g. str = start: "string value" end: ;
@@ -108,3 +119,4 @@ Version 1 DTS files have the overall lay
 
        -- David Gibson <da...@gibson.dropbear.id.au>
        -- Yoder Stuart <stuart.yo...@freescale.com>
+       -- Anton Staaf <robot...@chromium.org>

Modified: head/contrib/dtc/Documentation/manual.txt
==============================================================================
--- head/contrib/dtc/Documentation/manual.txt   Tue Jul 24 16:03:28 2012        
(r238741)
+++ head/contrib/dtc/Documentation/manual.txt   Tue Jul 24 16:29:33 2012        
(r238742)
@@ -21,7 +21,7 @@ III - libfdt
 
 IV - Utility Tools
     1) convert-dtsv0 -- Conversion to Version 1
-    1) ftdump
+    1) fdtdump
 
 
 I - "dtc", the device tree compiler
@@ -106,6 +106,9 @@ Options:
     -O <output_format>
        The generated output format, as listed above.
 
+    -d <dependency_filename>
+       Generate a dependency file during compilation.
+
     -q
        Quiet: -q suppress warnings, -qq errors, -qqq all
 
@@ -643,10 +646,10 @@ a new file with a "v1" appended the file
 Comments, empty lines, etc. are preserved.
 
 
-2) ftdump -- Flat Tree dumping utility
+2) fdtdump -- Flat Device Tree dumping utility
 
-The ftdump program prints a readable version of a flat device tree file.
+The fdtdump program prints a readable version of a flat device tree file.
 
-The syntax of the ftdump command line is:
+The syntax of the fdtdump command line is:
 
-    ftdump <DTB-file-name>
+    fdtdump <DTB-file-name>

Modified: head/contrib/dtc/Makefile
==============================================================================
--- head/contrib/dtc/Makefile   Tue Jul 24 16:03:28 2012        (r238741)
+++ head/contrib/dtc/Makefile   Tue Jul 24 16:29:33 2012        (r238742)
@@ -9,14 +9,16 @@
 # CONFIG_LOCALVERSION from some future config system.
 #
 VERSION = 1
-PATCHLEVEL = 2
+PATCHLEVEL = 3
 SUBLEVEL = 0
 EXTRAVERSION =
 LOCAL_VERSION =
 CONFIG_LOCALVERSION =
 
-CPPFLAGS = -I libfdt
-CFLAGS = -Wall -g -Os -fPIC -Wpointer-arith -Wcast-qual
+CPPFLAGS = -I libfdt -I .
+WARNINGS = -Werror -Wall -Wpointer-arith -Wcast-qual -Wnested-externs \
+       -Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls
+CFLAGS = -g -Os -fPIC -Werror $(WARNINGS)
 
 BISON = bison
 LEX = flex
@@ -103,12 +105,15 @@ endef
 
 include Makefile.convert-dtsv0
 include Makefile.dtc
-include Makefile.ftdump
+include Makefile.utils
 
 BIN += convert-dtsv0
 BIN += dtc
-BIN += ftdump
+BIN += fdtdump
+BIN += fdtget
+BIN += fdtput
 
+SCRIPTS = dtdiff
 
 all: $(BIN) libfdt
 
@@ -116,7 +121,9 @@ all: $(BIN) libfdt
 ifneq ($(DEPTARGETS),)
 -include $(DTC_OBJS:%.o=%.d)
 -include $(CONVERT_OBJS:%.o=%.d)
--include $(FTDUMP_OBJS:%.o=%.d)
+-include $(FDTDUMP_OBJS:%.o=%.d)
+-include $(FDTGET_OBJS:%.o=%.d)
+-include $(FDTPUT_OBJS:%.o=%.d)
 endif
 
 
@@ -127,7 +134,7 @@ endif
 LIBFDT_objdir = libfdt
 LIBFDT_srcdir = libfdt
 LIBFDT_archive = $(LIBFDT_objdir)/libfdt.a
-LIBFDT_lib = $(LIBFDT_objdir)/libfdt.$(SHAREDLIB_EXT)
+LIBFDT_lib = $(LIBFDT_objdir)/libfdt-$(DTC_VERSION).$(SHAREDLIB_EXT)
 LIBFDT_include = $(addprefix $(LIBFDT_srcdir)/,$(LIBFDT_INCLUDES))
 LIBFDT_version = $(addprefix $(LIBFDT_srcdir)/,$(LIBFDT_VERSION))
 
@@ -153,12 +160,14 @@ endif
 # intermediate target and building them again "for real"
 .SECONDARY: $(DTC_GEN_SRCS) $(CONVERT_GEN_SRCS)
 
-install: all
+install: all $(SCRIPTS)
        @$(VECHO) INSTALL
        $(INSTALL) -d $(DESTDIR)$(BINDIR)
-       $(INSTALL) $(BIN) $(DESTDIR)$(BINDIR)
+       $(INSTALL) $(BIN) $(SCRIPTS) $(DESTDIR)$(BINDIR)
        $(INSTALL) -d $(DESTDIR)$(LIBDIR)
        $(INSTALL) $(LIBFDT_lib) $(DESTDIR)$(LIBDIR)
+       ln -sf $(notdir $(LIBFDT_lib)) $(DESTDIR)$(LIBDIR)/$(LIBFDT_soname)
+       ln -sf $(LIBFDT_soname) $(DESTDIR)$(LIBDIR)/libfdt.$(SHAREDLIB_EXT)
        $(INSTALL) -m 644 $(LIBFDT_archive) $(DESTDIR)$(LIBDIR)
        $(INSTALL) -d $(DESTDIR)$(INCLUDEDIR)
        $(INSTALL) -m 644 $(LIBFDT_include) $(DESTDIR)$(INCLUDEDIR)
@@ -173,19 +182,29 @@ convert-dtsv0: $(CONVERT_OBJS)
        @$(VECHO) LD $@
        $(LINK.c) -o $@ $^
 
-ftdump:        $(FTDUMP_OBJS)
+fdtdump:       $(FDTDUMP_OBJS)
+
+fdtget:        $(FDTGET_OBJS) $(LIBFDT_archive)
+
+fdtput:        $(FDTPUT_OBJS) $(LIBFDT_archive)
 
 
 #
 # Testsuite rules
 #
 TESTS_PREFIX=tests/
+
+TESTS_BIN += dtc
+TESTS_BIN += convert-dtsv0
+TESTS_BIN += fdtput
+TESTS_BIN += fdtget
+
 include tests/Makefile.tests
 
 #
 # Clean rules
 #
-STD_CLEANFILES = *~ *.o *.so *.d *.a *.i *.s core a.out vgcore.* \
+STD_CLEANFILES = *~ *.o *.$(SHAREDLIB_EXT) *.d *.a *.i *.s core a.out vgcore.* 
\
        *.tab.[ch] *.lex.c *.output
 
 clean: libfdt_clean tests_clean
@@ -231,8 +250,7 @@ clean: libfdt_clean tests_clean
 
 $(LIBFDT_lib):
        @$(VECHO) LD $@
-       $(CC) $(LDFLAGS) -fPIC $(SHAREDLIB_LINK_OPTIONS)$(notdir $@) -o 
$(LIBFDT_objdir)/libfdt-$(DTC_VERSION).$(SHAREDLIB_EXT) $^
-       ln -sf libfdt-$(DTC_VERSION).$(SHAREDLIB_EXT) 
$(LIBFDT_objdir)/libfdt.$(SHAREDLIB_EXT)
+       $(CC) $(LDFLAGS) -fPIC $(SHAREDLIB_LINK_OPTIONS)$(LIBFDT_soname) -o 
$(LIBFDT_lib) $^
 
 %.lex.c: %.l
        @$(VECHO) LEX $@

Modified: head/contrib/dtc/checks.c
==============================================================================
--- head/contrib/dtc/checks.c   Tue Jul 24 16:03:28 2012        (r238741)
+++ head/contrib/dtc/checks.c   Tue Jul 24 16:29:33 2012        (r238742)
@@ -31,12 +31,6 @@
 #define TRACE(c, fmt, ...)     do { } while (0)
 #endif
 
-enum checklevel {
-       IGNORE = 0,
-       WARN = 1,
-       ERROR = 2,
-};
-
 enum checkstatus {
        UNCHECKED = 0,
        PREREQ,
@@ -57,14 +51,14 @@ struct check {
        node_check_fn node_fn;
        prop_check_fn prop_fn;
        void *data;
-       enum checklevel level;
+       bool warn, error;
        enum checkstatus status;
        int inprogress;
        int num_prereqs;
        struct check **prereq;
 };
 
-#define CHECK(nm, tfn, nfn, pfn, d, lvl, ...) \
+#define CHECK_ENTRY(nm, tfn, nfn, pfn, d, w, e, ...)          \
        static struct check *nm##_prereqs[] = { __VA_ARGS__ }; \
        static struct check nm = { \
                .name = #nm, \
@@ -72,20 +66,37 @@ struct check {
                .node_fn = (nfn), \
                .prop_fn = (pfn), \
                .data = (d), \
-               .level = (lvl), \
+               .warn = (w), \
+               .error = (e), \
                .status = UNCHECKED, \
                .num_prereqs = ARRAY_SIZE(nm##_prereqs), \
                .prereq = nm##_prereqs, \
        };
-
-#define TREE_CHECK(nm, d, lvl, ...) \
-       CHECK(nm, check_##nm, NULL, NULL, d, lvl, __VA_ARGS__)
-#define NODE_CHECK(nm, d, lvl, ...) \
-       CHECK(nm, NULL, check_##nm, NULL, d, lvl, __VA_ARGS__)
-#define PROP_CHECK(nm, d, lvl, ...) \
-       CHECK(nm, NULL, NULL, check_##nm, d, lvl, __VA_ARGS__)
-#define BATCH_CHECK(nm, lvl, ...) \
-       CHECK(nm, NULL, NULL, NULL, NULL, lvl, __VA_ARGS__)
+#define WARNING(nm, tfn, nfn, pfn, d, ...) \
+       CHECK_ENTRY(nm, tfn, nfn, pfn, d, true, false, __VA_ARGS__)
+#define ERROR(nm, tfn, nfn, pfn, d, ...) \
+       CHECK_ENTRY(nm, tfn, nfn, pfn, d, false, true, __VA_ARGS__)
+#define CHECK(nm, tfn, nfn, pfn, d, ...) \
+       CHECK_ENTRY(nm, tfn, nfn, pfn, d, false, false, __VA_ARGS__)
+
+#define TREE_WARNING(nm, d, ...) \
+       WARNING(nm, check_##nm, NULL, NULL, d, __VA_ARGS__)
+#define TREE_ERROR(nm, d, ...) \
+       ERROR(nm, check_##nm, NULL, NULL, d, __VA_ARGS__)
+#define TREE_CHECK(nm, d, ...) \
+       CHECK(nm, check_##nm, NULL, NULL, d, __VA_ARGS__)
+#define NODE_WARNING(nm, d, ...) \
+       WARNING(nm, NULL, check_##nm, NULL, d,  __VA_ARGS__)
+#define NODE_ERROR(nm, d, ...) \
+       ERROR(nm, NULL, check_##nm, NULL, d, __VA_ARGS__)
+#define NODE_CHECK(nm, d, ...) \
+       CHECK(nm, NULL, check_##nm, NULL, d, __VA_ARGS__)
+#define PROP_WARNING(nm, d, ...) \
+       WARNING(nm, NULL, NULL, check_##nm, d, __VA_ARGS__)
+#define PROP_ERROR(nm, d, ...) \
+       ERROR(nm, NULL, NULL, check_##nm, d, __VA_ARGS__)
+#define PROP_CHECK(nm, d, ...) \
+       CHECK(nm, NULL, NULL, check_##nm, d, __VA_ARGS__)
 
 #ifdef __GNUC__
 static inline void check_msg(struct check *c, const char *fmt, ...) 
__attribute__((format (printf, 2, 3)));
@@ -95,13 +106,13 @@ static inline void check_msg(struct chec
        va_list ap;
        va_start(ap, fmt);
 
-       if ((c->level < WARN) || (c->level <= quiet))
-               return; /* Suppress message */
-
-       fprintf(stderr, "%s (%s): ",
-               (c->level == ERROR) ? "ERROR" : "Warning", c->name);
-       vfprintf(stderr, fmt, ap);
-       fprintf(stderr, "\n");
+       if ((c->warn && (quiet < 1))
+           || (c->error && (quiet < 2))) {
+               fprintf(stderr, "%s (%s): ",
+                       (c->error) ? "ERROR" : "Warning", c->name);
+               vfprintf(stderr, fmt, ap);
+               fprintf(stderr, "\n");
+       }
 }
 
 #define FAIL(c, ...) \
@@ -167,7 +178,7 @@ static int run_check(struct check *c, st
 
 out:
        c->inprogress = 0;
-       if ((c->status != PASSED) && (c->level == ERROR))
+       if ((c->status != PASSED) && (c->error))
                error = 1;
        return error;
 }
@@ -176,6 +187,13 @@ out:
  * Utility check functions
  */
 
+/* A check which always fails, for testing purposes only */
+static inline void check_always_fail(struct check *c, struct node *dt)
+{
+       FAIL(c, "always_fail check");
+}
+TREE_CHECK(always_fail, NULL);
+
 static void check_is_string(struct check *c, struct node *root,
                            struct node *node)
 {
@@ -190,8 +208,10 @@ static void check_is_string(struct check
                FAIL(c, "\"%s\" property in %s is not a string",
                     propname, node->fullpath);
 }
-#define CHECK_IS_STRING(nm, propname, lvl) \
-       CHECK(nm, NULL, check_is_string, NULL, (propname), (lvl))
+#define WARNING_IF_NOT_STRING(nm, propname) \
+       WARNING(nm, NULL, check_is_string, NULL, (propname))
+#define ERROR_IF_NOT_STRING(nm, propname) \
+       ERROR(nm, NULL, check_is_string, NULL, (propname))
 
 static void check_is_cell(struct check *c, struct node *root,
                          struct node *node)
@@ -207,8 +227,10 @@ static void check_is_cell(struct check *
                FAIL(c, "\"%s\" property in %s is not a single cell",
                     propname, node->fullpath);
 }
-#define CHECK_IS_CELL(nm, propname, lvl) \
-       CHECK(nm, NULL, check_is_cell, NULL, (propname), (lvl))
+#define WARNING_IF_NOT_CELL(nm, propname) \
+       WARNING(nm, NULL, check_is_cell, NULL, (propname))
+#define ERROR_IF_NOT_CELL(nm, propname) \
+       ERROR(nm, NULL, check_is_cell, NULL, (propname))
 
 /*
  * Structural check functions
@@ -227,7 +249,7 @@ static void check_duplicate_node_names(s
                                FAIL(c, "Duplicate node name %s",
                                     child->fullpath);
 }
-NODE_CHECK(duplicate_node_names, NULL, ERROR);
+NODE_ERROR(duplicate_node_names, NULL);
 
 static void check_duplicate_property_names(struct check *c, struct node *dt,
                                           struct node *node)
@@ -240,7 +262,7 @@ static void check_duplicate_property_nam
                                FAIL(c, "Duplicate property name %s in %s",
                                     prop->name, node->fullpath);
 }
-NODE_CHECK(duplicate_property_names, NULL, ERROR);
+NODE_ERROR(duplicate_property_names, NULL);
 
 #define LOWERCASE      "abcdefghijklmnopqrstuvwxyz"
 #define UPPERCASE      "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
@@ -256,7 +278,7 @@ static void check_node_name_chars(struct
                FAIL(c, "Bad character '%c' in node %s",
                     node->name[n], node->fullpath);
 }
-NODE_CHECK(node_name_chars, PROPNODECHARS "@", ERROR);
+NODE_ERROR(node_name_chars, PROPNODECHARS "@");
 
 static void check_node_name_format(struct check *c, struct node *dt,
                                   struct node *node)
@@ -265,7 +287,7 @@ static void check_node_name_format(struc
                FAIL(c, "Node %s has multiple '@' characters in name",
                     node->fullpath);
 }
-NODE_CHECK(node_name_format, NULL, ERROR, &node_name_chars);
+NODE_ERROR(node_name_format, NULL, &node_name_chars);
 
 static void check_property_name_chars(struct check *c, struct node *dt,
                                      struct node *node, struct property *prop)
@@ -276,7 +298,63 @@ static void check_property_name_chars(st
                FAIL(c, "Bad character '%c' in property name \"%s\", node %s",
                     prop->name[n], prop->name, node->fullpath);
 }
-PROP_CHECK(property_name_chars, PROPNODECHARS, ERROR);
+PROP_ERROR(property_name_chars, PROPNODECHARS);
+
+#define DESCLABEL_FMT  "%s%s%s%s%s"
+#define DESCLABEL_ARGS(node,prop,mark)         \
+       ((mark) ? "value of " : ""),            \
+       ((prop) ? "'" : ""), \
+       ((prop) ? (prop)->name : ""), \
+       ((prop) ? "' in " : ""), (node)->fullpath
+
+static void check_duplicate_label(struct check *c, struct node *dt,
+                                 const char *label, struct node *node,
+                                 struct property *prop, struct marker *mark)
+{
+       struct node *othernode = NULL;
+       struct property *otherprop = NULL;
+       struct marker *othermark = NULL;
+
+       othernode = get_node_by_label(dt, label);
+
+       if (!othernode)
+               otherprop = get_property_by_label(dt, label, &othernode);
+       if (!othernode)
+               othermark = get_marker_label(dt, label, &othernode,
+                                              &otherprop);
+
+       if (!othernode)
+               return;
+
+       if ((othernode != node) || (otherprop != prop) || (othermark != mark))
+               FAIL(c, "Duplicate label '%s' on " DESCLABEL_FMT
+                    " and " DESCLABEL_FMT,
+                    label, DESCLABEL_ARGS(node, prop, mark),
+                    DESCLABEL_ARGS(othernode, otherprop, othermark));
+}
+
+static void check_duplicate_label_node(struct check *c, struct node *dt,
+                                      struct node *node)
+{
+       struct label *l;
+
+       for_each_label(node->labels, l)
+               check_duplicate_label(c, dt, l->label, node, NULL, NULL);
+}
+static void check_duplicate_label_prop(struct check *c, struct node *dt,
+                                      struct node *node, struct property *prop)
+{
+       struct marker *m = prop->val.markers;
+       struct label *l;
+
+       for_each_label(prop->labels, l)
+               check_duplicate_label(c, dt, l->label, node, prop, NULL);
+
+       for_each_marker_of_type(m, LABEL)
+               check_duplicate_label(c, dt, m->ref, node, prop, m);
+}
+ERROR(duplicate_label, NULL, check_duplicate_label_node,
+      check_duplicate_label_prop, NULL);
 
 static void check_explicit_phandles(struct check *c, struct node *root,
                                    struct node *node, struct property *prop)
@@ -335,7 +413,7 @@ static void check_explicit_phandles(stru
 
        node->phandle = phandle;
 }
-PROP_CHECK(explicit_phandles, NULL, ERROR);
+PROP_ERROR(explicit_phandles, NULL);
 
 static void check_name_properties(struct check *c, struct node *root,
                                  struct node *node)
@@ -364,8 +442,8 @@ static void check_name_properties(struct
                free(prop);
        }
 }
-CHECK_IS_STRING(name_is_string, "name", ERROR);
-NODE_CHECK(name_properties, NULL, ERROR, &name_is_string);
+ERROR_IF_NOT_STRING(name_is_string, "name");
+NODE_ERROR(name_properties, NULL, &name_is_string);
 
 /*
  * Reference fixup functions
@@ -392,7 +470,7 @@ static void fixup_phandle_references(str
                *((cell_t *)(prop->val.val + m->offset)) = 
cpu_to_fdt32(phandle);
        }
 }
-CHECK(phandle_references, NULL, NULL, fixup_phandle_references, NULL, ERROR,
+ERROR(phandle_references, NULL, NULL, fixup_phandle_references, NULL,
       &duplicate_node_names, &explicit_phandles);
 
 static void fixup_path_references(struct check *c, struct node *dt,
@@ -417,19 +495,19 @@ static void fixup_path_references(struct
                                                  strlen(path) + 1);
        }
 }
-CHECK(path_references, NULL, NULL, fixup_path_references, NULL, ERROR,
+ERROR(path_references, NULL, NULL, fixup_path_references, NULL,
       &duplicate_node_names);
 
 /*
  * Semantic checks
  */
-CHECK_IS_CELL(address_cells_is_cell, "#address-cells", WARN);
-CHECK_IS_CELL(size_cells_is_cell, "#size-cells", WARN);
-CHECK_IS_CELL(interrupt_cells_is_cell, "#interrupt-cells", WARN);
-
-CHECK_IS_STRING(device_type_is_string, "device_type", WARN);
-CHECK_IS_STRING(model_is_string, "model", WARN);
-CHECK_IS_STRING(status_is_string, "status", WARN);
+WARNING_IF_NOT_CELL(address_cells_is_cell, "#address-cells");
+WARNING_IF_NOT_CELL(size_cells_is_cell, "#size-cells");
+WARNING_IF_NOT_CELL(interrupt_cells_is_cell, "#interrupt-cells");
+
+WARNING_IF_NOT_STRING(device_type_is_string, "device_type");
+WARNING_IF_NOT_STRING(model_is_string, "model");
+WARNING_IF_NOT_STRING(status_is_string, "status");
 
 static void fixup_addr_size_cells(struct check *c, struct node *dt,
                                  struct node *node)
@@ -447,8 +525,8 @@ static void fixup_addr_size_cells(struct
        if (prop)
                node->size_cells = propval_cell(prop);
 }
-CHECK(addr_size_cells, NULL, fixup_addr_size_cells, NULL, NULL, WARN,
-      &address_cells_is_cell, &size_cells_is_cell);
+WARNING(addr_size_cells, NULL, fixup_addr_size_cells, NULL, NULL,
+       &address_cells_is_cell, &size_cells_is_cell);
 
 #define node_addr_cells(n) \
        (((n)->addr_cells == -1) ? 2 : (n)->addr_cells)
@@ -482,7 +560,7 @@ static void check_reg_format(struct chec
                     "(#address-cells == %d, #size-cells == %d)",
                     node->fullpath, prop->val.len, addr_cells, size_cells);
 }
-NODE_CHECK(reg_format, NULL, WARN, &addr_size_cells);
+NODE_WARNING(reg_format, NULL, &addr_size_cells);
 
 static void check_ranges_format(struct check *c, struct node *dt,
                                struct node *node)
@@ -523,7 +601,7 @@ static void check_ranges_format(struct c
                     p_addr_cells, c_addr_cells, c_size_cells);
        }
 }
-NODE_CHECK(ranges_format, NULL, WARN, &addr_size_cells);
+NODE_WARNING(ranges_format, NULL, &addr_size_cells);
 
 /*
  * Style checks
@@ -550,7 +628,7 @@ static void check_avoid_default_addr_siz
                FAIL(c, "Relying on default #size-cells value for %s",
                     node->fullpath);
 }
-NODE_CHECK(avoid_default_addr_size, NULL, WARN, &addr_size_cells);
+NODE_WARNING(avoid_default_addr_size, NULL, &addr_size_cells);
 
 static void check_obsolete_chosen_interrupt_controller(struct check *c,
                                                       struct node *dt)
@@ -567,12 +645,15 @@ static void check_obsolete_chosen_interr
                FAIL(c, "/chosen has obsolete \"interrupt-controller\" "
                     "property");
 }
-TREE_CHECK(obsolete_chosen_interrupt_controller, NULL, WARN);
+TREE_WARNING(obsolete_chosen_interrupt_controller, NULL);
 
 static struct check *check_table[] = {
        &duplicate_node_names, &duplicate_property_names,
        &node_name_chars, &node_name_format, &property_name_chars,
        &name_is_string, &name_properties,
+
+       &duplicate_label,
+
        &explicit_phandles,
        &phandle_references, &path_references,
 
@@ -583,8 +664,71 @@ static struct check *check_table[] = {
 
        &avoid_default_addr_size,
        &obsolete_chosen_interrupt_controller,
+
+       &always_fail,
 };
 
+static void enable_warning_error(struct check *c, bool warn, bool error)
+{
+       int i;
+
+       /* Raising level, also raise it for prereqs */
+       if ((warn && !c->warn) || (error && !c->error))
+               for (i = 0; i < c->num_prereqs; i++)
+                       enable_warning_error(c->prereq[i], warn, error);
+
+       c->warn = c->warn || warn;
+       c->error = c->error || error;
+}
+
+static void disable_warning_error(struct check *c, bool warn, bool error)
+{
+       int i;
+
+       /* Lowering level, also lower it for things this is the prereq
+        * for */
+       if ((warn && c->warn) || (error && c->error)) {
+               for (i = 0; i < ARRAY_SIZE(check_table); i++) {
+                       struct check *cc = check_table[i];
+                       int j;
+
+                       for (j = 0; j < cc->num_prereqs; j++)
+                               if (cc->prereq[j] == c)
+                                       disable_warning_error(cc, warn, error);
+               }
+       }
+
+       c->warn = c->warn && !warn;
+       c->error = c->error && !error;
+}
+
+void parse_checks_option(bool warn, bool error, const char *optarg)
+{
+       int i;
+       const char *name = optarg;
+       bool enable = true;
+
+       if ((strncmp(optarg, "no-", 3) == 0)
+           || (strncmp(optarg, "no_", 3) == 0)) {
+               name = optarg + 3;
+               enable = false;
+       }
+
+       for (i = 0; i < ARRAY_SIZE(check_table); i++) {
+               struct check *c = check_table[i];
+
+               if (streq(c->name, name)) {
+                       if (enable)
+                               enable_warning_error(c, warn, error);
+                       else
+                               disable_warning_error(c, warn, error);
+                       return;
+               }
+       }
+
+       die("Unrecognized check name \"%s\"\n", name);
+}
+
 void process_checks(int force, struct boot_info *bi)
 {
        struct node *dt = bi->dt;
@@ -594,7 +738,7 @@ void process_checks(int force, struct bo
        for (i = 0; i < ARRAY_SIZE(check_table); i++) {
                struct check *c = check_table[i];
 
-               if (c->level != IGNORE)
+               if (c->warn || c->error)
                        error = error || run_check(c, dt);
        }
 

Modified: head/contrib/dtc/convert-dtsv0-lexer.l
==============================================================================
--- head/contrib/dtc/convert-dtsv0-lexer.l      Tue Jul 24 16:03:28 2012        
(r238741)
+++ head/contrib/dtc/convert-dtsv0-lexer.l      Tue Jul 24 16:29:33 2012        
(r238742)
@@ -17,7 +17,7 @@
  *                                                                   USA
  */
 
-%option noyywrap nounput noinput
+%option noyywrap nounput noinput never-interactive
 
 %x INCLUDE
 %x BYTESTRING
@@ -210,8 +210,10 @@ static void convert_file(const char *fna
        memcpy(newname, fname, len);
        memcpy(newname + len, suffix, sizeof(suffix));
 
-       srcpos_file = dtc_open_file(fname, NULL);
-       yyin = srcpos_file->file;
+       yyin = fopen(fname, "r");
+       if (!yyin)
+               die("Couldn't open input file %s: %s\n",
+                   fname, strerror(errno));
 
        yyout = fopen(newname, "w");
        if (!yyout)

Modified: head/contrib/dtc/data.c
==============================================================================
--- head/contrib/dtc/data.c     Tue Jul 24 16:03:28 2012        (r238741)
+++ head/contrib/dtc/data.c     Tue Jul 24 16:29:33 2012        (r238742)
@@ -68,40 +68,6 @@ struct data data_copy_mem(const char *me
        return d;
 }
 
-static char get_oct_char(const char *s, int *i)
-{
-       char x[4];
-       char *endx;
-       long val;
-
-       x[3] = '\0';
-       strncpy(x, s + *i, 3);
-
-       val = strtol(x, &endx, 8);
-
-       assert(endx > x);
-
-       (*i) += endx - x;
-       return val;
-}
-
-static char get_hex_char(const char *s, int *i)
-{
-       char x[3];
-       char *endx;
-       long val;
-
-       x[2] = '\0';
-       strncpy(x, s + *i, 2);
-
-       val = strtol(x, &endx, 16);
-       if (!(endx  > x))
-               die("\\x used with no following hex digits\n");
-
-       (*i) += endx - x;
-       return val;
-}
-
 struct data data_copy_escape_string(const char *s, int len)
 {
        int i = 0;
@@ -114,53 +80,10 @@ struct data data_copy_escape_string(cons
        while (i < len) {
                char c = s[i++];
 
-               if (c != '\\') {
-                       q[d.len++] = c;
-                       continue;
-               }
-
-               c = s[i++];
-               assert(c);
-               switch (c) {
-               case 'a':
-                       q[d.len++] = '\a';
-                       break;
-               case 'b':
-                       q[d.len++] = '\b';
-                       break;
-               case 't':
-                       q[d.len++] = '\t';
-                       break;
-               case 'n':
-                       q[d.len++] = '\n';
-                       break;
-               case 'v':
-                       q[d.len++] = '\v';
-                       break;
-               case 'f':
-                       q[d.len++] = '\f';
-                       break;
-               case 'r':
-                       q[d.len++] = '\r';
-                       break;
-               case '0':
-               case '1':
-               case '2':
-               case '3':
-               case '4':
-               case '5':
-               case '6':
-               case '7':
-                       i--; /* need to re-read the first digit as
-                             * part of the octal value */
-                       q[d.len++] = get_oct_char(s, &i);
-                       break;
-               case 'x':
-                       q[d.len++] = get_hex_char(s, &i);
-                       break;
-               default:
-                       q[d.len++] = c;
-               }
+               if (c == '\\')
+                       c = get_escape_char(s, &i);
+
+               q[d.len++] = c;
        }
 
        q[d.len++] = '\0';
@@ -245,11 +168,33 @@ struct data data_merge(struct data d1, s
        return d;
 }
 
-struct data data_append_cell(struct data d, cell_t word)
+struct data data_append_integer(struct data d, uint64_t value, int bits)
 {
-       cell_t beword = cpu_to_fdt32(word);
+       uint8_t value_8;
+       uint16_t value_16;
+       uint32_t value_32;
+       uint64_t value_64;
+
+       switch (bits) {
+       case 8:
+               value_8 = value;
+               return data_append_data(d, &value_8, 1);
+
+       case 16:
+               value_16 = cpu_to_fdt16(value);
+               return data_append_data(d, &value_16, 2);
+
+       case 32:
+               value_32 = cpu_to_fdt32(value);
+               return data_append_data(d, &value_32, 4);
+
+       case 64:
+               value_64 = cpu_to_fdt64(value);
+               return data_append_data(d, &value_64, 8);
 
-       return data_append_data(d, &beword, sizeof(beword));
+       default:
+               die("Invalid literal size (%d)\n", bits);
+       }
 }
 
 struct data data_append_re(struct data d, const struct fdt_reserve_entry *re)
@@ -262,11 +207,14 @@ struct data data_append_re(struct data d
        return data_append_data(d, &bere, sizeof(bere));
 }
 
-struct data data_append_addr(struct data d, uint64_t addr)
+struct data data_append_cell(struct data d, cell_t word)
 {
-       uint64_t beaddr = cpu_to_fdt64(addr);
+       return data_append_integer(d, word, sizeof(word) * 8);
+}
 
-       return data_append_data(d, &beaddr, sizeof(beaddr));
+struct data data_append_addr(struct data d, uint64_t addr)
+{
+       return data_append_integer(d, addr, sizeof(addr) * 8);
 }
 
 struct data data_append_byte(struct data d, uint8_t byte)

Modified: head/contrib/dtc/dtc-lexer.l
==============================================================================
--- head/contrib/dtc/dtc-lexer.l        Tue Jul 24 16:03:28 2012        
(r238741)
+++ head/contrib/dtc/dtc-lexer.l        Tue Jul 24 16:29:33 2012        
(r238742)
@@ -18,7 +18,7 @@
  *                                                                   USA
  */
 
-%option noyywrap nounput noinput yylineno
+%option noyywrap nounput noinput never-interactive
 
 %x INCLUDE
 %x BYTESTRING
@@ -29,6 +29,7 @@ PROPNODECHAR  [a-zA-Z0-9,._+*#?@-]
 PATHCHAR       ({PROPNODECHAR}|[/])
 LABEL          [a-zA-Z_][a-zA-Z0-9_]*
 STRING         \"([^\\"]|\\.)*\"
+CHAR_LITERAL   '([^']|\\')*'
 WS             [[:space:]]
 COMMENT                "/*"([^*]|\*+[^*/])*\*+"/"
 LINECOMMENT    "//".*\n
@@ -38,12 +39,16 @@ LINECOMMENT "//".*\n
 #include "srcpos.h"
 #include "dtc-parser.tab.h"
 
+#define MAX_INCLUDE_NESTING 100
+YY_BUFFER_STATE include_stack[MAX_INCLUDE_NESTING];
+int include_stack_pointer = 0;
+
 YYLTYPE yylloc;
 
+/* CAUTION: this will stop working if we ever use yyless() or yyunput() */
 #define        YY_USER_ACTION \
        { \
-               yylloc.file = srcpos_file; \
-               yylloc.first_line = yylineno; \
+               srcpos_update(&yylloc, yytext, yyleng); \
        }
 
 /*#define LEXDEBUG     1*/
@@ -96,6 +101,12 @@ static int pop_input_file(void);
                        return DT_MEMRESERVE;
                }
 
+<*>"/bits/"    {
+                       DPRINT("Keyword: /bits/\n");
+                       BEGIN_DEFAULT();
+                       return DT_BITS;
+               }
+
 <*>{LABEL}:    {
                        DPRINT("Label: %s\n", yytext);
                        yylval.labelref = xstrdup(yytext);
@@ -103,19 +114,26 @@ static int pop_input_file(void);
                        return DT_LABEL;
                }
 
-<V1>[0-9]+|0[xX][0-9a-fA-F]+      {
+<V1>([0-9]+|0[xX][0-9a-fA-F]+)(U|L|UL|LL|ULL)? {
                        yylval.literal = xstrdup(yytext);
                        DPRINT("Literal: '%s'\n", yylval.literal);
                        return DT_LITERAL;
                }
 
-\&{LABEL}      {       /* label reference */
+<*>{CHAR_LITERAL}      {
+                       yytext[yyleng-1] = '\0';
+                       yylval.literal = xstrdup(yytext+1);
+                       DPRINT("Character literal: %s\n", yylval.literal);
+                       return DT_CHAR_LITERAL;
+               }
+
+<*>\&{LABEL}   {       /* label reference */
                        DPRINT("Ref: %s\n", yytext+1);
                        yylval.labelref = xstrdup(yytext+1);
                        return DT_REF;
                }
 
-"&{/"{PATHCHAR}+\}     {       /* new-style path reference */
+<*>"&{/"{PATHCHAR}+\}  {       /* new-style path reference */
                        yytext[yyleng-1] = '\0';
                        DPRINT("Ref: %s\n", yytext+2);
                        yylval.labelref = xstrdup(yytext+2);
@@ -150,6 +168,15 @@ static int pop_input_file(void);
 <*>{COMMENT}+  /* eat C-style comments */
 <*>{LINECOMMENT}+ /* eat C++-style comments */
 
+<*>"<<"                { return DT_LSHIFT; };
+<*>">>"                { return DT_RSHIFT; };
+<*>"<="                { return DT_LE; };
+<*>">="                { return DT_GE; };
+<*>"=="                { return DT_EQ; };
+<*>"!="                { return DT_NE; };
+<*>"&&"                { return DT_AND; };
+<*>"||"                { return DT_OR; };
+
 <*>.           {
                        DPRINT("Char: %c (\\x%02x)\n", yytext[0],
                                (unsigned)yytext[0]);
@@ -167,100 +194,34 @@ static int pop_input_file(void);
 
 %%
 
-
-/*
- * Stack of nested include file contexts.
- */
-
-struct incl_file {
-       struct dtc_file *file;
-       YY_BUFFER_STATE yy_prev_buf;
-       int yy_prev_lineno;
-       struct incl_file *prev;
-};
-
-static struct incl_file *incl_file_stack;
-
-
-/*
- * Detect infinite include recursion.
- */
-#define MAX_INCLUDE_DEPTH      (100)
-
-static int incl_depth = 0;
-
-
 static void push_input_file(const char *filename)
 {
-       struct incl_file *incl_file;
-       struct dtc_file *newfile;
-       struct search_path search, *searchptr = NULL;
-
        assert(filename);
 
-       if (incl_depth++ >= MAX_INCLUDE_DEPTH)
-               die("Includes nested too deeply");
+       assert(include_stack_pointer >= MAX_INCLUDE_NESTING);
 
-       if (srcpos_file) {
-               search.dir = srcpos_file->dir;
-               search.next = NULL;
-               search.prev = NULL;
-               searchptr = &search;
-       }
+       srcfile_push(filename);
 
-       newfile = dtc_open_file(filename, searchptr);
+       yyin = current_srcfile->f;
 
-       incl_file = xmalloc(sizeof(struct incl_file));
+       include_stack[include_stack_pointer++] = YY_CURRENT_BUFFER;
 
-       /*
-        * Save current context.
-        */

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to