Browse Source

scripts/dtc: Update to upstream version v1.4.3

Using the update-dtc-source.sh script from Linux v4.14-rc1 import the
portions of dtc that we require.  We bring in update-dtc-source.sh and
scripts/dtc/Makefile from Linux v4.14-rc1.  Rework DTC_FLAGS handling to
not require a test.

Signed-off-by: Tom Rini <trini@konsulko.com>
master
Tom Rini 3 years ago
parent
commit
c0e032e009
35 changed files with 15100 additions and 13 deletions
  1. +0
    -5
      scripts/Kbuild.include
  2. +8
    -8
      scripts/Makefile.extrawarn
  3. +31
    -0
      scripts/dtc/Makefile
  4. +18
    -0
      scripts/dtc/Makefile.dtc
  5. +849
    -0
      scripts/dtc/checks.c
  6. +269
    -0
      scripts/dtc/data.c
  7. +311
    -0
      scripts/dtc/dtc-lexer.l
  8. +2260
    -0
      scripts/dtc/dtc-lexer.lex.c_shipped
  9. +2301
    -0
      scripts/dtc/dtc-parser.tab.c_shipped
  10. +123
    -0
      scripts/dtc/dtc-parser.tab.h_shipped
  11. +519
    -0
      scripts/dtc/dtc-parser.y
  12. +366
    -0
      scripts/dtc/dtc.c
  13. +285
    -0
      scripts/dtc/dtc.h
  14. +946
    -0
      scripts/dtc/flattree.c
  15. +90
    -0
      scripts/dtc/fstree.c
  16. +11
    -0
      scripts/dtc/libfdt/Makefile.libfdt
  17. +251
    -0
      scripts/dtc/libfdt/fdt.c
  18. +111
    -0
      scripts/dtc/libfdt/fdt.h
  19. +84
    -0
      scripts/dtc/libfdt/fdt_empty_tree.c
  20. +703
    -0
      scripts/dtc/libfdt/fdt_ro.c
  21. +491
    -0
      scripts/dtc/libfdt/fdt_rw.c
  22. +102
    -0
      scripts/dtc/libfdt/fdt_strerror.c
  23. +288
    -0
      scripts/dtc/libfdt/fdt_sw.c
  24. +139
    -0
      scripts/dtc/libfdt/fdt_wip.c
  25. +1833
    -0
      scripts/dtc/libfdt/libfdt.h
  26. +112
    -0
      scripts/dtc/libfdt/libfdt_env.h
  27. +95
    -0
      scripts/dtc/libfdt/libfdt_internal.h
  28. +980
    -0
      scripts/dtc/livetree.c
  29. +302
    -0
      scripts/dtc/srcpos.c
  30. +118
    -0
      scripts/dtc/srcpos.h
  31. +284
    -0
      scripts/dtc/treesource.c
  32. +81
    -0
      scripts/dtc/update-dtc-source.sh
  33. +473
    -0
      scripts/dtc/util.c
  34. +265
    -0
      scripts/dtc/util.h
  35. +1
    -0
      scripts/dtc/version_gen.h

+ 0
- 5
scripts/Kbuild.include View File

@@ -172,11 +172,6 @@ ld-version = $(shell $(LD) --version | $(srctree)/scripts/ld-version.sh)
# Usage: $(call ld-ifversion, -ge, 22252, y)
ld-ifversion = $(shell [ $(ld-version) $(1) $(2) ] && echo $(3) || echo $(4))

# dtc-option
# Usage: DTC_FLAGS += $(call dtc-option,-Wno-unit_address_vs_reg)
dtc-option = $(call try-run,\
echo '/dts-v1/; / {};' | $(DTC) $(1),$(1),$(2))

######

###


+ 8
- 8
scripts/Makefile.extrawarn View File

@@ -58,8 +58,8 @@ endif

KBUILD_CFLAGS += $(warning)

dtc-warning-2 += $(call dtc-option,-Wnode_name_chars_strict)
dtc-warning-2 += $(call dtc-option,-Wproperty_name_chars_strict)
dtc-warning-2 += -Wnode_name_chars_strict
dtc-warning-2 += -Wproperty_name_chars_strict

dtc-warning := $(dtc-warning-$(findstring 1, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)))
dtc-warning += $(dtc-warning-$(findstring 2, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)))
@@ -70,11 +70,11 @@ DTC_FLAGS += $(dtc-warning)
else

# Disable noisy checks by default
DTC_FLAGS += $(call dtc-option,-Wno-unit_address_vs_reg)
DTC_FLAGS += $(call dtc-option,-Wno-simple_bus_reg)
DTC_FLAGS += $(call dtc-option,-Wno-unit_address_format)
DTC_FLAGS += $(call dtc-option,-Wno-pci_bridge)
DTC_FLAGS += $(call dtc-option,-Wno-pci_device_bus_num)
DTC_FLAGS += $(call dtc-option,-Wno-pci_device_reg)
DTC_FLAGS += -Wno-unit_address_vs_reg
DTC_FLAGS += -Wno-simple_bus_reg
DTC_FLAGS += -Wno-unit_address_format
DTC_FLAGS += -Wno-pci_bridge
DTC_FLAGS += -Wno-pci_device_bus_num
DTC_FLAGS += -Wno-pci_device_reg

endif

+ 31
- 0
scripts/dtc/Makefile View File

@@ -0,0 +1,31 @@
# scripts/dtc makefile

hostprogs-y := dtc
always := $(hostprogs-y)

dtc-objs := dtc.o flattree.o fstree.o data.o livetree.o treesource.o \
srcpos.o checks.o util.o
dtc-objs += dtc-lexer.lex.o dtc-parser.tab.o

# Source files need to get at the userspace version of libfdt_env.h to compile

HOSTCFLAGS_DTC := -I$(src) -I$(src)/libfdt

HOSTCFLAGS_checks.o := $(HOSTCFLAGS_DTC)
HOSTCFLAGS_data.o := $(HOSTCFLAGS_DTC)
HOSTCFLAGS_dtc.o := $(HOSTCFLAGS_DTC)
HOSTCFLAGS_flattree.o := $(HOSTCFLAGS_DTC)
HOSTCFLAGS_fstree.o := $(HOSTCFLAGS_DTC)
HOSTCFLAGS_livetree.o := $(HOSTCFLAGS_DTC)
HOSTCFLAGS_srcpos.o := $(HOSTCFLAGS_DTC)
HOSTCFLAGS_treesource.o := $(HOSTCFLAGS_DTC)
HOSTCFLAGS_util.o := $(HOSTCFLAGS_DTC)

HOSTCFLAGS_dtc-lexer.lex.o := $(HOSTCFLAGS_DTC)
HOSTCFLAGS_dtc-parser.tab.o := $(HOSTCFLAGS_DTC)

# dependencies on generated files need to be listed explicitly
$(obj)/dtc-lexer.lex.o: $(obj)/dtc-parser.tab.h

# generated files need to be cleaned explicitly
clean-files := dtc-lexer.lex.c dtc-parser.tab.c dtc-parser.tab.h

+ 18
- 0
scripts/dtc/Makefile.dtc View File

@@ -0,0 +1,18 @@
# Makefile.dtc
#
# This is not a complete Makefile of itself. Instead, it is designed to
# be easily embeddable into other systems of Makefiles.
#
DTC_SRCS = \
checks.c \
data.c \
dtc.c \
flattree.c \
fstree.c \
livetree.c \
srcpos.c \
treesource.c \
util.c

DTC_GEN_SRCS = dtc-lexer.lex.c dtc-parser.tab.c
DTC_OBJS = $(DTC_SRCS:%.c=%.o) $(DTC_GEN_SRCS:%.c=%.o)

+ 849
- 0
scripts/dtc/checks.c View File

@@ -0,0 +1,849 @@
/*
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2007.
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/

#include "dtc.h"

#ifdef TRACE_CHECKS
#define TRACE(c, ...) \
do { \
fprintf(stderr, "=== %s: ", (c)->name); \
fprintf(stderr, __VA_ARGS__); \
fprintf(stderr, "\n"); \
} while (0)
#else
#define TRACE(c, fmt, ...) do { } while (0)
#endif

enum checkstatus {
UNCHECKED = 0,
PREREQ,
PASSED,
FAILED,
};

struct check;

typedef void (*check_fn)(struct check *c, struct dt_info *dti, struct node *node);

struct check {
const char *name;
check_fn fn;
void *data;
bool warn, error;
enum checkstatus status;
bool inprogress;
int num_prereqs;
struct check **prereq;
};

#define CHECK_ENTRY(_nm, _fn, _d, _w, _e, ...) \
static struct check *_nm##_prereqs[] = { __VA_ARGS__ }; \
static struct check _nm = { \
.name = #_nm, \
.fn = (_fn), \
.data = (_d), \
.warn = (_w), \
.error = (_e), \
.status = UNCHECKED, \
.num_prereqs = ARRAY_SIZE(_nm##_prereqs), \
.prereq = _nm##_prereqs, \
};
#define WARNING(_nm, _fn, _d, ...) \
CHECK_ENTRY(_nm, _fn, _d, true, false, __VA_ARGS__)
#define ERROR(_nm, _fn, _d, ...) \
CHECK_ENTRY(_nm, _fn, _d, false, true, __VA_ARGS__)
#define CHECK(_nm, _fn, _d, ...) \
CHECK_ENTRY(_nm, _fn, _d, false, false, __VA_ARGS__)

#ifdef __GNUC__
static inline void check_msg(struct check *c, struct dt_info *dti,
const char *fmt, ...) __attribute__((format (printf, 3, 4)));
#endif
static inline void check_msg(struct check *c, struct dt_info *dti,
const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);

if ((c->warn && (quiet < 1))
|| (c->error && (quiet < 2))) {
fprintf(stderr, "%s: %s (%s): ",
strcmp(dti->outname, "-") ? dti->outname : "<stdout>",
(c->error) ? "ERROR" : "Warning", c->name);
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
}
va_end(ap);
}

#define FAIL(c, dti, ...) \
do { \
TRACE((c), "\t\tFAILED at %s:%d", __FILE__, __LINE__); \
(c)->status = FAILED; \
check_msg((c), dti, __VA_ARGS__); \
} while (0)

static void check_nodes_props(struct check *c, struct dt_info *dti, struct node *node)
{
struct node *child;

TRACE(c, "%s", node->fullpath);
if (c->fn)
c->fn(c, dti, node);

for_each_child(node, child)
check_nodes_props(c, dti, child);
}

static bool run_check(struct check *c, struct dt_info *dti)
{
struct node *dt = dti->dt;
bool error = false;
int i;

assert(!c->inprogress);

if (c->status != UNCHECKED)
goto out;

c->inprogress = true;

for (i = 0; i < c->num_prereqs; i++) {
struct check *prq = c->prereq[i];
error = error || run_check(prq, dti);
if (prq->status != PASSED) {
c->status = PREREQ;
check_msg(c, dti, "Failed prerequisite '%s'",
c->prereq[i]->name);
}
}

if (c->status != UNCHECKED)
goto out;

check_nodes_props(c, dti, dt);

if (c->status == UNCHECKED)
c->status = PASSED;

TRACE(c, "\tCompleted, status %d", c->status);

out:
c->inprogress = false;
if ((c->status != PASSED) && (c->error))
error = true;
return error;
}

/*
* Utility check functions
*/

/* A check which always fails, for testing purposes only */
static inline void check_always_fail(struct check *c, struct dt_info *dti,
struct node *node)
{
FAIL(c, dti, "always_fail check");
}
CHECK(always_fail, check_always_fail, NULL);

static void check_is_string(struct check *c, struct dt_info *dti,
struct node *node)
{
struct property *prop;
char *propname = c->data;

prop = get_property(node, propname);
if (!prop)
return; /* Not present, assumed ok */

if (!data_is_one_string(prop->val))
FAIL(c, dti, "\"%s\" property in %s is not a string",
propname, node->fullpath);
}
#define WARNING_IF_NOT_STRING(nm, propname) \
WARNING(nm, check_is_string, (propname))
#define ERROR_IF_NOT_STRING(nm, propname) \
ERROR(nm, check_is_string, (propname))

static void check_is_cell(struct check *c, struct dt_info *dti,
struct node *node)
{
struct property *prop;
char *propname = c->data;

prop = get_property(node, propname);
if (!prop)
return; /* Not present, assumed ok */

if (prop->val.len != sizeof(cell_t))
FAIL(c, dti, "\"%s\" property in %s is not a single cell",
propname, node->fullpath);
}
#define WARNING_IF_NOT_CELL(nm, propname) \
WARNING(nm, check_is_cell, (propname))
#define ERROR_IF_NOT_CELL(nm, propname) \
ERROR(nm, check_is_cell, (propname))

/*
* Structural check functions
*/

static void check_duplicate_node_names(struct check *c, struct dt_info *dti,
struct node *node)
{
struct node *child, *child2;

for_each_child(node, child)
for (child2 = child->next_sibling;
child2;
child2 = child2->next_sibling)
if (streq(child->name, child2->name))
FAIL(c, dti, "Duplicate node name %s",
child->fullpath);
}
ERROR(duplicate_node_names, check_duplicate_node_names, NULL);

static void check_duplicate_property_names(struct check *c, struct dt_info *dti,
struct node *node)
{
struct property *prop, *prop2;

for_each_property(node, prop) {
for (prop2 = prop->next; prop2; prop2 = prop2->next) {
if (prop2->deleted)
continue;
if (streq(prop->name, prop2->name))
FAIL(c, dti, "Duplicate property name %s in %s",
prop->name, node->fullpath);
}
}
}
ERROR(duplicate_property_names, check_duplicate_property_names, NULL);

#define LOWERCASE "abcdefghijklmnopqrstuvwxyz"
#define UPPERCASE "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define DIGITS "0123456789"
#define PROPNODECHARS LOWERCASE UPPERCASE DIGITS ",._+*#?-"
#define PROPNODECHARSSTRICT LOWERCASE UPPERCASE DIGITS ",-"

static void check_node_name_chars(struct check *c, struct dt_info *dti,
struct node *node)
{
int n = strspn(node->name, c->data);

if (n < strlen(node->name))
FAIL(c, dti, "Bad character '%c' in node %s",
node->name[n], node->fullpath);
}
ERROR(node_name_chars, check_node_name_chars, PROPNODECHARS "@");

static void check_node_name_chars_strict(struct check *c, struct dt_info *dti,
struct node *node)
{
int n = strspn(node->name, c->data);

if (n < node->basenamelen)
FAIL(c, dti, "Character '%c' not recommended in node %s",
node->name[n], node->fullpath);
}
CHECK(node_name_chars_strict, check_node_name_chars_strict, PROPNODECHARSSTRICT);

static void check_node_name_format(struct check *c, struct dt_info *dti,
struct node *node)
{
if (strchr(get_unitname(node), '@'))
FAIL(c, dti, "Node %s has multiple '@' characters in name",
node->fullpath);
}
ERROR(node_name_format, check_node_name_format, NULL, &node_name_chars);

static void check_unit_address_vs_reg(struct check *c, struct dt_info *dti,
struct node *node)
{
const char *unitname = get_unitname(node);
struct property *prop = get_property(node, "reg");

if (!prop) {
prop = get_property(node, "ranges");
if (prop && !prop->val.len)
prop = NULL;
}

if (prop) {
if (!unitname[0])
FAIL(c, dti, "Node %s has a reg or ranges property, but no unit name",
node->fullpath);
} else {
if (unitname[0])
FAIL(c, dti, "Node %s has a unit name, but no reg property",
node->fullpath);
}
}
WARNING(unit_address_vs_reg, check_unit_address_vs_reg, NULL);

static void check_property_name_chars(struct check *c, struct dt_info *dti,
struct node *node)
{
struct property *prop;

for_each_property(node, prop) {
int n = strspn(prop->name, c->data);

if (n < strlen(prop->name))
FAIL(c, dti, "Bad character '%c' in property name \"%s\", node %s",
prop->name[n], prop->name, node->fullpath);
}
}
ERROR(property_name_chars, check_property_name_chars, PROPNODECHARS);

static void check_property_name_chars_strict(struct check *c,
struct dt_info *dti,
struct node *node)
{
struct property *prop;

for_each_property(node, prop) {
const char *name = prop->name;
int n = strspn(name, c->data);

if (n == strlen(prop->name))
continue;

/* Certain names are whitelisted */
if (streq(name, "device_type"))
continue;

/*
* # is only allowed at the beginning of property names not counting
* the vendor prefix.
*/
if (name[n] == '#' && ((n == 0) || (name[n-1] == ','))) {
name += n + 1;
n = strspn(name, c->data);
}
if (n < strlen(name))
FAIL(c, dti, "Character '%c' not recommended in property name \"%s\", node %s",
name[n], prop->name, node->fullpath);
}
}
CHECK(property_name_chars_strict, check_property_name_chars_strict, PROPNODECHARSSTRICT);

#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 dt_info *dti,
const char *label, struct node *node,
struct property *prop, struct marker *mark)
{
struct node *dt = dti->dt;
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, dti, "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 dt_info *dti,
struct node *node)
{
struct label *l;
struct property *prop;

for_each_label(node->labels, l)
check_duplicate_label(c, dti, l->label, node, NULL, NULL);

for_each_property(node, prop) {
struct marker *m = prop->val.markers;

for_each_label(prop->labels, l)
check_duplicate_label(c, dti, l->label, node, prop, NULL);

for_each_marker_of_type(m, LABEL)
check_duplicate_label(c, dti, m->ref, node, prop, m);
}
}
ERROR(duplicate_label, check_duplicate_label_node, NULL);

static cell_t check_phandle_prop(struct check *c, struct dt_info *dti,
struct node *node, const char *propname)
{
struct node *root = dti->dt;
struct property *prop;
struct marker *m;
cell_t phandle;

prop = get_property(node, propname);
if (!prop)
return 0;

if (prop->val.len != sizeof(cell_t)) {
FAIL(c, dti, "%s has bad length (%d) %s property",
node->fullpath, prop->val.len, prop->name);
return 0;
}

m = prop->val.markers;
for_each_marker_of_type(m, REF_PHANDLE) {
assert(m->offset == 0);
if (node != get_node_by_ref(root, m->ref))
/* "Set this node's phandle equal to some
* other node's phandle". That's nonsensical
* by construction. */ {
FAIL(c, dti, "%s in %s is a reference to another node",
prop->name, node->fullpath);
}
/* But setting this node's phandle equal to its own
* phandle is allowed - that means allocate a unique
* phandle for this node, even if it's not otherwise
* referenced. The value will be filled in later, so
* we treat it as having no phandle data for now. */
return 0;
}

phandle = propval_cell(prop);

if ((phandle == 0) || (phandle == -1)) {
FAIL(c, dti, "%s has bad value (0x%x) in %s property",
node->fullpath, phandle, prop->name);
return 0;
}

return phandle;
}

static void check_explicit_phandles(struct check *c, struct dt_info *dti,
struct node *node)
{
struct node *root = dti->dt;
struct node *other;
cell_t phandle, linux_phandle;

/* Nothing should have assigned phandles yet */
assert(!node->phandle);

phandle = check_phandle_prop(c, dti, node, "phandle");

linux_phandle = check_phandle_prop(c, dti, node, "linux,phandle");

if (!phandle && !linux_phandle)
/* No valid phandles; nothing further to check */
return;

if (linux_phandle && phandle && (phandle != linux_phandle))
FAIL(c, dti, "%s has mismatching 'phandle' and 'linux,phandle'"
" properties", node->fullpath);

if (linux_phandle && !phandle)
phandle = linux_phandle;

other = get_node_by_phandle(root, phandle);
if (other && (other != node)) {
FAIL(c, dti, "%s has duplicated phandle 0x%x (seen before at %s)",
node->fullpath, phandle, other->fullpath);
return;
}

node->phandle = phandle;
}
ERROR(explicit_phandles, check_explicit_phandles, NULL);

static void check_name_properties(struct check *c, struct dt_info *dti,
struct node *node)
{
struct property **pp, *prop = NULL;

for (pp = &node->proplist; *pp; pp = &((*pp)->next))
if (streq((*pp)->name, "name")) {
prop = *pp;
break;
}

if (!prop)
return; /* No name property, that's fine */

if ((prop->val.len != node->basenamelen+1)
|| (memcmp(prop->val.val, node->name, node->basenamelen) != 0)) {
FAIL(c, dti, "\"name\" property in %s is incorrect (\"%s\" instead"
" of base node name)", node->fullpath, prop->val.val);
} else {
/* The name property is correct, and therefore redundant.
* Delete it */
*pp = prop->next;
free(prop->name);
data_free(prop->val);
free(prop);
}
}
ERROR_IF_NOT_STRING(name_is_string, "name");
ERROR(name_properties, check_name_properties, NULL, &name_is_string);

/*
* Reference fixup functions
*/

static void fixup_phandle_references(struct check *c, struct dt_info *dti,
struct node *node)
{
struct node *dt = dti->dt;
struct property *prop;

for_each_property(node, prop) {
struct marker *m = prop->val.markers;
struct node *refnode;
cell_t phandle;

for_each_marker_of_type(m, REF_PHANDLE) {
assert(m->offset + sizeof(cell_t) <= prop->val.len);

refnode = get_node_by_ref(dt, m->ref);
if (! refnode) {
if (!(dti->dtsflags & DTSF_PLUGIN))
FAIL(c, dti, "Reference to non-existent node or "
"label \"%s\"\n", m->ref);
else /* mark the entry as unresolved */
*((cell_t *)(prop->val.val + m->offset)) =
cpu_to_fdt32(0xffffffff);
continue;
}

phandle = get_node_phandle(dt, refnode);
*((cell_t *)(prop->val.val + m->offset)) = cpu_to_fdt32(phandle);
}
}
}
ERROR(phandle_references, fixup_phandle_references, NULL,
&duplicate_node_names, &explicit_phandles);

static void fixup_path_references(struct check *c, struct dt_info *dti,
struct node *node)
{
struct node *dt = dti->dt;
struct property *prop;

for_each_property(node, prop) {
struct marker *m = prop->val.markers;
struct node *refnode;
char *path;

for_each_marker_of_type(m, REF_PATH) {
assert(m->offset <= prop->val.len);

refnode = get_node_by_ref(dt, m->ref);
if (!refnode) {
FAIL(c, dti, "Reference to non-existent node or label \"%s\"\n",
m->ref);
continue;
}

path = refnode->fullpath;
prop->val = data_insert_at_marker(prop->val, m, path,
strlen(path) + 1);
}
}
}
ERROR(path_references, fixup_path_references, NULL, &duplicate_node_names);

/*
* Semantic checks
*/
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 dt_info *dti,
struct node *node)
{
struct property *prop;

node->addr_cells = -1;
node->size_cells = -1;

prop = get_property(node, "#address-cells");
if (prop)
node->addr_cells = propval_cell(prop);

prop = get_property(node, "#size-cells");
if (prop)
node->size_cells = propval_cell(prop);
}
WARNING(addr_size_cells, fixup_addr_size_cells, NULL,
&address_cells_is_cell, &size_cells_is_cell);

#define node_addr_cells(n) \
(((n)->addr_cells == -1) ? 2 : (n)->addr_cells)
#define node_size_cells(n) \
(((n)->size_cells == -1) ? 1 : (n)->size_cells)

static void check_reg_format(struct check *c, struct dt_info *dti,
struct node *node)
{
struct property *prop;
int addr_cells, size_cells, entrylen;

prop = get_property(node, "reg");
if (!prop)
return; /* No "reg", that's fine */

if (!node->parent) {
FAIL(c, dti, "Root node has a \"reg\" property");
return;
}

if (prop->val.len == 0)
FAIL(c, dti, "\"reg\" property in %s is empty", node->fullpath);

addr_cells = node_addr_cells(node->parent);
size_cells = node_size_cells(node->parent);
entrylen = (addr_cells + size_cells) * sizeof(cell_t);

if (!entrylen || (prop->val.len % entrylen) != 0)
FAIL(c, dti, "\"reg\" property in %s has invalid length (%d bytes) "
"(#address-cells == %d, #size-cells == %d)",
node->fullpath, prop->val.len, addr_cells, size_cells);
}
WARNING(reg_format, check_reg_format, NULL, &addr_size_cells);

static void check_ranges_format(struct check *c, struct dt_info *dti,
struct node *node)
{
struct property *prop;
int c_addr_cells, p_addr_cells, c_size_cells, p_size_cells, entrylen;

prop = get_property(node, "ranges");
if (!prop)
return;

if (!node->parent) {
FAIL(c, dti, "Root node has a \"ranges\" property");
return;
}

p_addr_cells = node_addr_cells(node->parent);
p_size_cells = node_size_cells(node->parent);
c_addr_cells = node_addr_cells(node);
c_size_cells = node_size_cells(node);
entrylen = (p_addr_cells + c_addr_cells + c_size_cells) * sizeof(cell_t);

if (prop->val.len == 0) {
if (p_addr_cells != c_addr_cells)
FAIL(c, dti, "%s has empty \"ranges\" property but its "
"#address-cells (%d) differs from %s (%d)",
node->fullpath, c_addr_cells, node->parent->fullpath,
p_addr_cells);
if (p_size_cells != c_size_cells)
FAIL(c, dti, "%s has empty \"ranges\" property but its "
"#size-cells (%d) differs from %s (%d)",
node->fullpath, c_size_cells, node->parent->fullpath,
p_size_cells);
} else if ((prop->val.len % entrylen) != 0) {
FAIL(c, dti, "\"ranges\" property in %s has invalid length (%d bytes) "
"(parent #address-cells == %d, child #address-cells == %d, "
"#size-cells == %d)", node->fullpath, prop->val.len,
p_addr_cells, c_addr_cells, c_size_cells);
}
}
WARNING(ranges_format, check_ranges_format, NULL, &addr_size_cells);

/*
* Style checks
*/
static void check_avoid_default_addr_size(struct check *c, struct dt_info *dti,
struct node *node)
{
struct property *reg, *ranges;

if (!node->parent)
return; /* Ignore root node */

reg = get_property(node, "reg");
ranges = get_property(node, "ranges");

if (!reg && !ranges)
return;

if (node->parent->addr_cells == -1)
FAIL(c, dti, "Relying on default #address-cells value for %s",
node->fullpath);

if (node->parent->size_cells == -1)
FAIL(c, dti, "Relying on default #size-cells value for %s",
node->fullpath);
}
WARNING(avoid_default_addr_size, check_avoid_default_addr_size, NULL,
&addr_size_cells);

static void check_obsolete_chosen_interrupt_controller(struct check *c,
struct dt_info *dti,
struct node *node)
{
struct node *dt = dti->dt;
struct node *chosen;
struct property *prop;

if (node != dt)
return;


chosen = get_node_by_path(dt, "/chosen");
if (!chosen)
return;

prop = get_property(chosen, "interrupt-controller");
if (prop)
FAIL(c, dti, "/chosen has obsolete \"interrupt-controller\" "
"property");
}
WARNING(obsolete_chosen_interrupt_controller,
check_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,

&address_cells_is_cell, &size_cells_is_cell, &interrupt_cells_is_cell,
&device_type_is_string, &model_is_string, &status_is_string,

&property_name_chars_strict,
&node_name_chars_strict,

&addr_size_cells, &reg_format, &ranges_format,

&unit_address_vs_reg,

&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 *arg)
{
int i;
const char *name = arg;
bool enable = true;

if ((strncmp(arg, "no-", 3) == 0)
|| (strncmp(arg, "no_", 3) == 0)) {
name = arg + 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(bool force, struct dt_info *dti)
{
int i;
int error = 0;

for (i = 0; i < ARRAY_SIZE(check_table); i++) {
struct check *c = check_table[i];

if (c->warn || c->error)
error = error || run_check(c, dti);
}

if (error) {
if (!force) {
fprintf(stderr, "ERROR: Input tree has errors, aborting "
"(use -f to force output)\n");
exit(2);
} else if (quiet < 3) {
fprintf(stderr, "Warning: Input tree has errors, "
"output forced\n");
}
}
}

+ 269
- 0
scripts/dtc/data.c View File

@@ -0,0 +1,269 @@
/*
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/

#include "dtc.h"

void data_free(struct data d)
{
struct marker *m, *nm;

m = d.markers;
while (m) {
nm = m->next;
free(m->ref);
free(m);
m = nm;
}

if (d.val)
free(d.val);
}

struct data data_grow_for(struct data d, int xlen)
{
struct data nd;
int newsize;

if (xlen == 0)
return d;

nd = d;

newsize = xlen;

while ((d.len + xlen) > newsize)
newsize *= 2;

nd.val = xrealloc(d.val, newsize);

return nd;
}

struct data data_copy_mem(const char *mem, int len)
{
struct data d;

d = data_grow_for(empty_data, len);

d.len = len;
memcpy(d.val, mem, len);

return d;
}

struct data data_copy_escape_string(const char *s, int len)
{
int i = 0;
struct data d;
char *q;

d = data_grow_for(empty_data, len + 1);

q = d.val;
while (i < len) {
char c = s[i++];

if (c == '\\')
c = get_escape_char(s, &i);

q[d.len++] = c;
}

q[d.len++] = '\0';
return d;
}

struct data data_copy_file(FILE *f, size_t maxlen)
{
struct data d = empty_data;

while (!feof(f) && (d.len < maxlen)) {
size_t chunksize, ret;

if (maxlen == -1)
chunksize = 4096;
else
chunksize = maxlen - d.len;

d = data_grow_for(d, chunksize);
ret = fread(d.val + d.len, 1, chunksize, f);

if (ferror(f))
die("Error reading file into data: %s", strerror(errno));

if (d.len + ret < d.len)
die("Overflow reading file into data\n");

d.len += ret;
}

return d;
}

struct data data_append_data(struct data d, const void *p, int len)
{
d = data_grow_for(d, len);
memcpy(d.val + d.len, p, len);
d.len += len;
return d;
}

struct data data_insert_at_marker(struct data d, struct marker *m,
const void *p, int len)
{
d = data_grow_for(d, len);
memmove(d.val + m->offset + len, d.val + m->offset, d.len - m->offset);
memcpy(d.val + m->offset, p, len);
d.len += len;

/* Adjust all markers after the one we're inserting at */
m = m->next;
for_each_marker(m)
m->offset += len;
return d;
}

static struct data data_append_markers(struct data d, struct marker *m)
{
struct marker **mp = &d.markers;

/* Find the end of the markerlist */
while (*mp)
mp = &((*mp)->next);
*mp = m;
return d;
}

struct data data_merge(struct data d1, struct data d2)
{
struct data d;
struct marker *m2 = d2.markers;

d = data_append_markers(data_append_data(d1, d2.val, d2.len), m2);

/* Adjust for the length of d1 */
for_each_marker(m2)
m2->offset += d1.len;

d2.markers = NULL; /* So data_free() doesn't clobber them */
data_free(d2);

return d;
}

struct data data_append_integer(struct data d, uint64_t value, int bits)
{
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);

default:
die("Invalid literal size (%d)\n", bits);
}
}

struct data data_append_re(struct data d, const struct fdt_reserve_entry *re)
{
struct fdt_reserve_entry bere;

bere.address = cpu_to_fdt64(re->address);
bere.size = cpu_to_fdt64(re->size);

return data_append_data(d, &bere, sizeof(bere));
}

struct data data_append_cell(struct data d, cell_t word)
{
return data_append_integer(d, word, sizeof(word) * 8);
}

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)
{
return data_append_data(d, &byte, 1);
}

struct data data_append_zeroes(struct data d, int len)
{
d = data_grow_for(d, len);

memset(d.val + d.len, 0, len);
d.len += len;
return d;
}

struct data data_append_align(struct data d, int align)
{
int newlen = ALIGN(d.len, align);
return data_append_zeroes(d, newlen - d.len);
}

struct data data_add_marker(struct data d, enum markertype type, char *ref)
{
struct marker *m;

m = xmalloc(sizeof(*m));
m->offset = d.len;
m->type = type;
m->ref = ref;
m->next = NULL;

return data_append_markers(d, m);
}

bool data_is_one_string(struct data d)
{
int i;
int len = d.len;

if (len == 0)
return false;

for (i = 0; i < len-1; i++)
if (d.val[i] == '\0')
return false;

if (d.val[len-1] != '\0')
return false;

return true;
}

+ 311
- 0
scripts/dtc/dtc-lexer.l View File

@@ -0,0 +1,311 @@
/*
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/

%option noyywrap nounput noinput never-interactive

%x BYTESTRING
%x PROPNODENAME
%s V1

PROPNODECHAR [a-zA-Z0-9,._+*#?@-]
PATHCHAR ({PROPNODECHAR}|[/])
LABEL [a-zA-Z_][a-zA-Z0-9_]*
STRING \"([^\\"]|\\.)*\"
CHAR_LITERAL '([^']|\\')*'
WS [[:space:]]
COMMENT "/*"([^*]|\*+[^*/])*\*+"/"
LINECOMMENT "//".*\n

%{
#include "dtc.h"
#include "srcpos.h"
#include "dtc-parser.tab.h"

YYLTYPE yylloc;
extern bool treesource_error;

/* CAUTION: this will stop working if we ever use yyless() or yyunput() */
#define YY_USER_ACTION \
{ \
srcpos_update(&yylloc, yytext, yyleng); \
}

/*#define LEXDEBUG 1*/

#ifdef LEXDEBUG
#define DPRINT(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)
#else
#define DPRINT(fmt, ...) do { } while (0)
#endif

static int dts_version = 1;

#define BEGIN_DEFAULT() DPRINT("<V1>\n"); \
BEGIN(V1); \

static void push_input_file(const char *filename);
static bool pop_input_file(void);
#ifdef __GNUC__
static void lexical_error(const char *fmt, ...)
__attribute__((format (printf, 1, 2)));
#else
static void lexical_error(const char *fmt, ...);
#endif

%}

%%
<*>"/include/"{WS}*{STRING} {
char *name = strchr(yytext, '\"') + 1;
yytext[yyleng-1] = '\0';
push_input_file(name);
}

<*>^"#"(line)?[ \t]+[0-9]+[ \t]+{STRING}([ \t]+[0-9]+)? {
char *line, *fnstart, *fnend;
struct data fn;
/* skip text before line # */
line = yytext;
while (!isdigit((unsigned char)*line))
line++;

/* regexp ensures that first and list "
* in the whole yytext are those at
* beginning and end of the filename string */
fnstart = memchr(yytext, '"', yyleng);
for (fnend = yytext + yyleng - 1;
*fnend != '"'; fnend--)
;
assert(fnstart && fnend && (fnend > fnstart));

fn = data_copy_escape_string(fnstart + 1,
fnend - fnstart - 1);

/* Don't allow nuls in filenames */
if (memchr(fn.val, '\0', fn.len - 1))
lexical_error("nul in line number directive");

/* -1 since #line is the number of the next line */
srcpos_set_line(xstrdup(fn.val), atoi(line) - 1);
data_free(fn);
}

<*><<EOF>> {
if (!pop_input_file()) {
yyterminate();
}
}

<*>{STRING} {
DPRINT("String: %s\n", yytext);
yylval.data = data_copy_escape_string(yytext+1,
yyleng-2);
return DT_STRING;
}

<*>"/dts-v1/" {
DPRINT("Keyword: /dts-v1/\n");
dts_version = 1;
BEGIN_DEFAULT();
return DT_V1;
}

<*>"/plugin/" {
DPRINT("Keyword: /plugin/\n");
return DT_PLUGIN;
}

<*>"/memreserve/" {
DPRINT("Keyword: /memreserve/\n");
BEGIN_DEFAULT();
return DT_MEMRESERVE;
}

<*>"/bits/" {
DPRINT("Keyword: /bits/\n");
BEGIN_DEFAULT();
return DT_BITS;
}

<*>"/delete-property/" {
DPRINT("Keyword: /delete-property/\n");
DPRINT("<PROPNODENAME>\n");
BEGIN(PROPNODENAME);
return DT_DEL_PROP;
}

<*>"/delete-node/" {
DPRINT("Keyword: /delete-node/\n");
DPRINT("<PROPNODENAME>\n");
BEGIN(PROPNODENAME);
return DT_DEL_NODE;
}

<*>{LABEL}: {
DPRINT("Label: %s\n", yytext);
yylval.labelref = xstrdup(yytext);
yylval.labelref[yyleng-1] = '\0';
return DT_LABEL;
}

<V1>([0-9]+|0[xX][0-9a-fA-F]+)(U|L|UL|LL|ULL)? {
char *e;
DPRINT("Integer Literal: '%s'\n", yytext);

errno = 0;
yylval.integer = strtoull(yytext, &e, 0);

if (*e && e[strspn(e, "UL")]) {
lexical_error("Bad integer literal '%s'",
yytext);
}

if (errno == ERANGE)
lexical_error("Integer literal '%s' out of range",
yytext);
else
/* ERANGE is the only strtoull error triggerable
* by strings matching the pattern */
assert(errno == 0);
return DT_LITERAL;
}

<*>{CHAR_LITERAL} {
struct data d;
DPRINT("Character literal: %s\n", yytext);

d = data_copy_escape_string(yytext+1, yyleng-2);
if (d.len == 1) {
lexical_error("Empty character literal");
yylval.integer = 0;
} else {
yylval.integer = (unsigned char)d.val[0];

if (d.len > 2)
lexical_error("Character literal has %d"
" characters instead of 1",
d.len - 1);
}

data_free(d);
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 */
yytext[yyleng-1] = '\0';
DPRINT("Ref: %s\n", yytext+2);
yylval.labelref = xstrdup(yytext+2);
return DT_REF;
}

<BYTESTRING>[0-9a-fA-F]{2} {
yylval.byte = strtol(yytext, NULL, 16);
DPRINT("Byte: %02x\n", (int)yylval.byte);
return DT_BYTE;
}

<BYTESTRING>"]" {
DPRINT("/BYTESTRING\n");
BEGIN_DEFAULT();
return ']';
}

<PROPNODENAME>\\?{PROPNODECHAR}+ {
DPRINT("PropNodeName: %s\n", yytext);
yylval.propnodename = xstrdup((yytext[0] == '\\') ?
yytext + 1 : yytext);
BEGIN_DEFAULT();
return DT_PROPNODENAME;
}

"/incbin/" {
DPRINT("Binary Include\n");
return DT_INCBIN;
}

<*>{WS}+ /* eat whitespace */
<*>{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]);
if (yytext[0] == '[') {
DPRINT("<BYTESTRING>\n");
BEGIN(BYTESTRING);
}
if ((yytext[0] == '{')
|| (yytext[0] == ';')) {
DPRINT("<PROPNODENAME>\n");
BEGIN(PROPNODENAME);
}
return yytext[0];
}

%%

static void push_input_file(const char *filename)
{
assert(filename);

srcfile_push(filename);

yyin = current_srcfile->f;

yypush_buffer_state(yy_create_buffer(yyin, YY_BUF_SIZE));
}


static bool pop_input_file(void)
{
if (srcfile_pop() == 0)
return false;

yypop_buffer_state();
yyin = current_srcfile->f;

return true;
}

static void lexical_error(const char *fmt, ...)
{
va_list ap;

va_start(ap, fmt);
srcpos_verror(&yylloc, "Lexical error", fmt, ap);
va_end(ap);

treesource_error = true;
}

+ 2260
- 0
scripts/dtc/dtc-lexer.lex.c_shipped
File diff suppressed because it is too large
View File


+ 2301
- 0
scripts/dtc/dtc-parser.tab.c_shipped
File diff suppressed because it is too large
View File


+ 123
- 0
scripts/dtc/dtc-parser.tab.h_shipped View File

@@ -0,0 +1,123 @@
/* A Bison parser, made by GNU Bison 3.0.2. */

/* Bison interface for Yacc-like parsers in C

Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */

/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.

This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */

#ifndef YY_YY_DTC_PARSER_TAB_H_INCLUDED
# define YY_YY_DTC_PARSER_TAB_H_INCLUDED
/* Debug traces. */
#ifndef YYDEBUG
# define YYDEBUG 0
#endif
#if YYDEBUG
extern int yydebug;
#endif

/* Token type. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
enum yytokentype
{
DT_V1 = 258,
DT_PLUGIN = 259,
DT_MEMRESERVE = 260,
DT_LSHIFT = 261,
DT_RSHIFT = 262,
DT_LE = 263,
DT_GE = 264,
DT_EQ = 265,
DT_NE = 266,
DT_AND = 267,
DT_OR = 268,
DT_BITS = 269,
DT_DEL_PROP = 270,
DT_DEL_NODE = 271,
DT_PROPNODENAME = 272,
DT_LITERAL = 273,
DT_CHAR_LITERAL = 274,
DT_BYTE = 275,
DT_STRING = 276,
DT_LABEL = 277,
DT_REF = 278,
DT_INCBIN = 279
};
#endif

/* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE YYSTYPE;
union YYSTYPE
{
#line 39 "dtc-parser.y" /* yacc.c:1909 */

char *propnodename;
char *labelref;
uint8_t byte;
struct data data;

struct {
struct data data;
int bits;
} array;

struct property *prop;
struct property *proplist;
struct node *node;
struct node *nodelist;
struct reserve_info *re;
uint64_t integer;
unsigned int flags;

#line 99 "dtc-parser.tab.h" /* yacc.c:1909 */
};
# define YYSTYPE_IS_TRIVIAL 1
# define YYSTYPE_IS_DECLARED 1
#endif

/* Location type. */
#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
typedef struct YYLTYPE YYLTYPE;
struct YYLTYPE
{
int first_line;
int first_column;
int last_line;
int last_column;
};
# define YYLTYPE_IS_DECLARED 1
# define YYLTYPE_IS_TRIVIAL 1
#endif


extern YYSTYPE yylval;
extern YYLTYPE yylloc;
int yyparse (void);

#endif /* !YY_YY_DTC_PARSER_TAB_H_INCLUDED */

+ 519
- 0
scripts/dtc/dtc-parser.y View File

@@ -0,0 +1,519 @@
/*
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
%{
#include <stdio.h>
#include <inttypes.h>

#include "dtc.h"
#include "srcpos.h"

extern int yylex(void);
extern void yyerror(char const *s);
#define ERROR(loc, ...) \
do { \
srcpos_error((loc), "Error", __VA_ARGS__); \
treesource_error = true; \
} while (0)

extern struct dt_info *parser_output;
extern bool treesource_error;
%}

%union {
char *propnodename;
char *labelref;
uint8_t byte;
struct data data;

struct {
struct data data;
int bits;
} array;

struct property *prop;
struct property *proplist;
struct node *node;
struct node *nodelist;
struct reserve_info *re;
uint64_t integer;
unsigned int flags;
}

%token DT_V1
%token DT_PLUGIN
%token DT_MEMRESERVE
%token DT_LSHIFT DT_RSHIFT DT_LE DT_GE DT_EQ DT_NE DT_AND DT_OR
%token DT_BITS
%token DT_DEL_PROP
%token DT_DEL_NODE
%token <propnodename> DT_PROPNODENAME
%token <integer> DT_LITERAL
%token <integer> DT_CHAR_LITERAL
%token <byte> DT_BYTE
%token <data> DT_STRING
%token <labelref> DT_LABEL
%token <labelref> DT_REF
%token DT_INCBIN

%type <data> propdata
%type <data> propdataprefix
%type <flags> header
%type <flags> headers
%type <re> memreserve
%type <re> memreserves
%type <array> arrayprefix
%type <data> bytestring
%type <prop> propdef
%type <proplist> proplist

%type <node> devicetree
%type <node> nodedef
%type <node> subnode
%type <nodelist> subnodes

%type <integer> integer_prim
%type <integer> integer_unary
%type <integer> integer_mul
%type <integer> integer_add
%type <integer> integer_shift
%type <integer> integer_rela
%type <integer> integer_eq
%type <integer> integer_bitand
%type <integer> integer_bitxor
%type <integer> integer_bitor
%type <integer> integer_and
%type <integer> integer_or
%type <integer> integer_trinary
%type <integer> integer_expr

%%

sourcefile:
headers memreserves devicetree
{
parser_output = build_dt_info($1, $2, $3,
guess_boot_cpuid($3));
}
;

header:
DT_V1 ';'
{
$$ = DTSF_V1;
}
| DT_V1 ';' DT_PLUGIN ';'
{
$$ = DTSF_V1 | DTSF_PLUGIN;
}
;

headers:
header
| header headers
{
if ($2 != $1)
ERROR(&@2, "Header flags don't match earlier ones");
$$ = $1;
}
;

memreserves:
/* empty */
{
$$ = NULL;
}
| memreserve memreserves
{
$$ = chain_reserve_entry($1, $2);
}
;

memreserve:
DT_MEMRESERVE integer_prim integer_prim ';'
{
$$ = build_reserve_entry($2, $3);
}
| DT_LABEL memreserve
{
add_label(&$2->labels, $1);
$$ = $2;
}
;

devicetree:
'/' nodedef
{
$$ = name_node($2, "");
}
| devicetree '/' nodedef
{
$$ = merge_nodes($1, $3);
}

| devicetree DT_LABEL DT_REF nodedef
{
struct node *target = get_node_by_ref($1, $3);

if (target) {
add_label(&target->labels, $2);
merge_nodes(target, $4);
} else
ERROR(&@3, "Label or path %s not found", $3);
$$ = $1;
}
| devicetree DT_REF nodedef
{
struct node *target = get_node_by_ref($1, $2);

if (target)
merge_nodes(target, $3);
else
ERROR(&@2, "Label or path %s not found", $2);
$$ = $1;
}
| devicetree DT_DEL_NODE DT_REF ';'
{
struct node *target = get_node_by_ref($1, $3);

if (target)
delete_node(target);
else
ERROR(&@3, "Label or path %s not found", $3);


$$ = $1;
}
;

nodedef:
'{' proplist subnodes '}' ';'
{
$$ = build_node($2, $3);
}
;

proplist:
/* empty */
{
$$ = NULL;
}
| proplist propdef
{
$$ = chain_property($2, $1);
}
;

propdef:
DT_PROPNODENAME '=' propdata ';'
{
$$ = build_property($1, $3);
}
| DT_PROPNODENAME ';'
{
$$ = build_property($1, empty_data);
}
| DT_DEL_PROP DT_PROPNODENAME ';'
{
$$ = build_property_delete($2);
}
| DT_LABEL propdef
{
add_label(&$2->labels, $1);
$$ = $2;
}
;

propdata:
propdataprefix DT_STRING
{
$$ = data_merge($1, $2);
}
| propdataprefix arrayprefix '>'
{
$$ = data_merge($1, $2.data);
}
| propdataprefix '[' bytestring ']'
{
$$ = data_merge($1, $3);
}
| propdataprefix DT_REF
{
$$ = data_add_marker($1, REF_PATH, $2);
}
| propdataprefix DT_INCBIN '(' DT_STRING ',' integer_prim ',' integer_prim ')'
{
FILE *f = srcfile_relative_open($4.val, NULL);
struct data d;

if ($6 != 0)
if (fseek(f, $6, SEEK_SET) != 0)
die("Couldn't seek to offset %llu in \"%s\": %s",
(unsigned long long)$6, $4.val,
strerror(errno));

d = data_copy_file(f, $8);

$$ = data_merge($1, d);
fclose(f);
}
| propdataprefix DT_INCBIN '(' DT_STRING ')'
{
FILE *f = srcfile_relative_open($4.val, NULL);
struct data d = empty_data;

d = data_copy_file(f, -1);

$$ = data_merge($1, d);
fclose(f);
}
| propdata DT_LABEL
{
$$ = data_add_marker($1, LABEL, $2);
}
;

propdataprefix:
/* empty */
{
$$ = empty_data;
}
| propdata ','
{
$$ = $1;
}
| propdataprefix DT_LABEL
{
$$ = data_add_marker($1, LABEL, $2);
}
;

arrayprefix:
DT_BITS DT_LITERAL '<'
{
unsigned long long bits;

bits = $2;

if ((bits != 8) && (bits != 16) &&
(bits != 32) && (bits != 64)) {
ERROR(&@2, "Array elements must be"
" 8, 16, 32 or 64-bits");
bits = 32;
}

$$.data = empty_data;
$$.bits = bits;
}
| '<'
{
$$.data = empty_data;
$$.bits = 32;
}
| arrayprefix integer_prim
{
if ($1.bits < 64) {
uint64_t mask = (1ULL << $1.bits) - 1;
/*
* Bits above mask must either be all zero
* (positive within range of mask) or all one
* (negative and sign-extended). The second
* condition is true if when we set all bits
* within the mask to one (i.e. | in the
* mask), all bits are one.
*/
if (($2 > mask) && (($2 | mask) != -1ULL))
ERROR(&@2, "Value out of range for"
" %d-bit array element", $1.bits);
}

$$.data = data_append_integer($1.data, $2, $1.bits);
}
| arrayprefix DT_REF
{
uint64_t val = ~0ULL >> (64 - $1.bits);

if ($1.bits == 32)
$1.data = data_add_marker($1.data,
REF_PHANDLE,
$2);
else
ERROR(&@2, "References are only allowed in "
"arrays with 32-bit elements.");

$$.data = data_append_integer($1.data, val, $1.bits);
}
| arrayprefix DT_LABEL
{
$$.data = data_add_marker($1.data, LABEL, $2);
}
;

integer_prim:
DT_LITERAL
| DT_CHAR_LITERAL
| '(' integer_expr ')'
{
$$ = $2;
}
;

integer_expr:
integer_trinary
;

integer_trinary:
integer_or
| integer_or '?' integer_expr ':' integer_trinary { $$ = $1 ? $3 : $5; }
;

integer_or:
integer_and
| integer_or DT_OR integer_and { $$ = $1 || $3; }
;

integer_and:
integer_bitor
| integer_and DT_AND integer_bitor { $$ = $1 && $3; }
;

integer_bitor:
integer_bitxor
| integer_bitor '|' integer_bitxor { $$ = $1 | $3; }
;

integer_bitxor:
integer_bitand
| integer_bitxor '^' integer_bitand { $$ = $1 ^ $3; }
;

integer_bitand:
integer_eq
| integer_bitand '&' integer_eq { $$ = $1 & $3; }
;

integer_eq:
integer_rela
| integer_eq DT_EQ integer_rela { $$ = $1 == $3; }
| integer_eq DT_NE integer_rela { $$ = $1 != $3; }
;

integer_rela:
integer_shift
| integer_rela '<' integer_shift { $$ = $1 < $3; }
| integer_rela '>' integer_shift { $$ = $1 > $3; }
| integer_rela DT_LE integer_shift { $$ = $1 <= $3; }
| integer_rela DT_GE integer_shift { $$ = $1 >= $3; }
;

integer_shift:
integer_shift DT_LSHIFT integer_add { $$ = $1 << $3; }
| integer_shift DT_RSHIFT integer_add { $$ = $1 >> $3; }
| integer_add
;

integer_add:
integer_add '+' integer_mul { $$ = $1 + $3; }
| integer_add '-' integer_mul { $$ = $1 - $3; }
| integer_mul
;

integer_mul:
integer_mul '*' integer_unary { $$ = $1 * $3; }
| integer_mul '/' integer_unary
{
if ($3 != 0) {
$$ = $1 / $3;
} else {
ERROR(&@$, "Division by zero");
$$ = 0;
}
}
| integer_mul '%' integer_unary
{
if ($3 != 0) {
$$ = $1 % $3;
} else {
ERROR(&@$, "Division by zero");
$$ = 0;
}
}
| integer_unary
;

integer_unary:
integer_prim
| '-' integer_unary { $$ = -$2; }
| '~' integer_unary { $$ = ~$2; }
| '!' integer_unary { $$ = !$2; }
;

bytestring:
/* empty */
{
$$ = empty_data;
}
| bytestring DT_BYTE
{
$$ = data_append_byte($1, $2);
}
| bytestring DT_LABEL
{
$$ = data_add_marker($1, LABEL, $2);
}
;

subnodes:
/* empty */
{
$$ = NULL;
}
| subnode subnodes
{
$$ = chain_node($1, $2);
}
| subnode propdef
{
ERROR(&@2, "Properties must precede subnodes");
YYERROR;
}
;

subnode:
DT_PROPNODENAME nodedef
{
$$ = name_node($2, $1);
}
| DT_DEL_NODE DT_PROPNODENAME ';'
{
$$ = name_node(build_node_delete(), $2);
}
| DT_LABEL subnode
{
add_label(&$2->labels, $1);
$$ = $2;
}
;

%%