Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ed95d745 authored by David Gibson's avatar David Gibson Committed by Paul Mackerras
Browse files

powerpc: Update in-kernel dtc and libfdt to version 1.2.0



Some time ago, a copies of the upstream dtc and libfdt sources were
included in the kernel tree to avoid having these as external
dependencies for building the kernel.  Since then development on the
upstream dtc and libfdt has continued.  This updates the in-kernel
versions to match the recently released upstream dtc version 1.2.0.
This includes a number of bugfixes, many cleanups and a few new
features.

Signed-off-by: default avatarDavid Gibson <david@gibson.dropbear.id.au>
Signed-off-by: default avatarPaul Mackerras <paulus@samba.org>
parent 0ec27c04
Loading
Loading
Loading
Loading
+1 −17
Original line number Original line Diff line number Diff line
@@ -5,21 +5,5 @@
#
#
DTC_SRCS = dtc.c flattree.c fstree.c data.c livetree.c treesource.c srcpos.c \
DTC_SRCS = dtc.c flattree.c fstree.c data.c livetree.c treesource.c srcpos.c \
	checks.c
	checks.c
DTC_EXTRA = dtc.h srcpos.h
DTC_GEN_SRCS = dtc-lexer.lex.c dtc-parser.tab.c
DTC_LEXFILES = dtc-lexer.l
DTC_BISONFILES = dtc-parser.y

DTC_LEX_SRCS = $(DTC_LEXFILES:%.l=%.lex.c)
DTC_BISON_SRCS = $(DTC_BISONFILES:%.y=%.tab.c)
DTC_BISON_INCLUDES = $(DTC_BISONFILES:%.y=%.tab.h)

DTC_GEN_SRCS = $(DTC_LEX_SRCS) $(DTC_BISON_SRCS)
DTC_GEN_ALL = $(DTC_GEN_SRCS) $(DTC_BISON_INCLUDES)
DTC_OBJS = $(DTC_SRCS:%.c=%.o) $(DTC_GEN_SRCS:%.c=%.o)
DTC_OBJS = $(DTC_SRCS:%.c=%.o) $(DTC_GEN_SRCS:%.c=%.o)

DTC_CLEANFILES = $(DTC_GEN_ALL)

# We assume the containing Makefile system can do auto-dependencies for most
# things, but we supply the dependencies on generated header files explicitly

$(addprefix $(DTC_objdir)/,$(DTC_GEN_SRCS:%.c=%.o)): $(addprefix $(DTC_objdir)/,$(DTC_BISON_INCLUDES))
+71 −234
Original line number Original line Diff line number Diff line
@@ -242,6 +242,42 @@ static void check_duplicate_property_names(struct check *c, struct node *dt,
}
}
NODE_CHECK(duplicate_property_names, NULL, ERROR);
NODE_CHECK(duplicate_property_names, NULL, ERROR);


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

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

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

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

static void check_property_name_chars(struct check *c, struct node *dt,
				      struct node *node, struct property *prop)
{
	int n = strspn(prop->name, c->data);

	if (n < strlen(prop->name))
		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);

static void check_explicit_phandles(struct check *c, struct node *root,
static void check_explicit_phandles(struct check *c, struct node *root,
					  struct node *node)
					  struct node *node)
{
{
@@ -280,16 +316,29 @@ NODE_CHECK(explicit_phandles, NULL, ERROR);
static void check_name_properties(struct check *c, struct node *root,
static void check_name_properties(struct check *c, struct node *root,
				  struct node *node)
				  struct node *node)
{
{
	struct property *prop;
	struct property **pp, *prop = NULL;

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


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


	if ((prop->val.len != node->basenamelen+1)
	if ((prop->val.len != node->basenamelen+1)
	    || (memcmp(prop->val.val, node->name, node->basenamelen) != 0))
	    || (memcmp(prop->val.val, node->name, node->basenamelen) != 0)) {
		FAIL(c, "\"name\" property in %s is incorrect (\"%s\" instead"
		FAIL(c, "\"name\" property in %s is incorrect (\"%s\" instead"
		     " of base node name)", node->fullpath, prop->val.val);
		     " 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);
	}
}
}
CHECK_IS_STRING(name_is_string, "name", ERROR);
CHECK_IS_STRING(name_is_string, "name", ERROR);
NODE_CHECK(name_properties, NULL, ERROR, &name_is_string);
NODE_CHECK(name_properties, NULL, ERROR, &name_is_string);
@@ -316,7 +365,7 @@ static void fixup_phandle_references(struct check *c, struct node *dt,
		}
		}


		phandle = get_node_phandle(dt, refnode);
		phandle = get_node_phandle(dt, refnode);
	      *((cell_t *)(prop->val.val + m->offset)) = cpu_to_be32(phandle);
		*((cell_t *)(prop->val.val + m->offset)) = cpu_to_fdt32(phandle);
	}
	}
}
}
CHECK(phandle_references, NULL, NULL, fixup_phandle_references, NULL, ERROR,
CHECK(phandle_references, NULL, NULL, fixup_phandle_references, NULL, ERROR,
@@ -498,6 +547,7 @@ TREE_CHECK(obsolete_chosen_interrupt_controller, NULL, WARN);


static struct check *check_table[] = {
static struct check *check_table[] = {
	&duplicate_node_names, &duplicate_property_names,
	&duplicate_node_names, &duplicate_property_names,
	&node_name_chars, &node_name_format, &property_name_chars,
	&name_is_string, &name_properties,
	&name_is_string, &name_properties,
	&explicit_phandles,
	&explicit_phandles,
	&phandle_references, &path_references,
	&phandle_references, &path_references,
@@ -511,10 +561,7 @@ static struct check *check_table[] = {
	&obsolete_chosen_interrupt_controller,
	&obsolete_chosen_interrupt_controller,
};
};


int check_semantics(struct node *dt, int outversion, int boot_cpuid_phys);
void process_checks(int force, struct boot_info *bi)

void process_checks(int force, struct boot_info *bi,
		    int checkflag, int outversion, int boot_cpuid_phys)
{
{
	struct node *dt = bi->dt;
	struct node *dt = bi->dt;
	int i;
	int i;
@@ -537,214 +584,4 @@ void process_checks(int force, struct boot_info *bi,
				"output forced\n");
				"output forced\n");
		}
		}
	}
	}

	if (checkflag) {
		if (error) {
			fprintf(stderr, "Warning: Skipping semantic checks due to structural errors\n");
		} else {
			if (!check_semantics(bi->dt, outversion,
					     boot_cpuid_phys))
				fprintf(stderr, "Warning: Input tree has semantic errors\n");
		}
	}
}

/*
 * Semantic check functions
 */

#define ERRMSG(...) if (quiet < 2) fprintf(stderr, "ERROR: " __VA_ARGS__)
#define WARNMSG(...) if (quiet < 1) fprintf(stderr, "Warning: " __VA_ARGS__)

#define DO_ERR(...) do {ERRMSG(__VA_ARGS__); ok = 0; } while (0)

#define CHECK_HAVE(node, propname) \
	do { \
		if (! (prop = get_property((node), (propname)))) \
			DO_ERR("Missing \"%s\" property in %s\n", (propname), \
				(node)->fullpath); \
	} while (0);

#define CHECK_HAVE_WARN(node, propname) \
	do { \
		if (! (prop  = get_property((node), (propname)))) \
			WARNMSG("%s has no \"%s\" property\n", \
				(node)->fullpath, (propname)); \
	} while (0)

#define CHECK_HAVE_STRING(node, propname) \
	do { \
		CHECK_HAVE((node), (propname)); \
		if (prop && !data_is_one_string(prop->val)) \
			DO_ERR("\"%s\" property in %s is not a string\n", \
				(propname), (node)->fullpath); \
	} while (0)

#define CHECK_HAVE_STREQ(node, propname, value) \
	do { \
		CHECK_HAVE_STRING((node), (propname)); \
		if (prop && !streq(prop->val.val, (value))) \
			DO_ERR("%s has wrong %s, %s (should be %s\n", \
				(node)->fullpath, (propname), \
				prop->val.val, (value)); \
	} while (0)

#define CHECK_HAVE_ONECELL(node, propname) \
	do { \
		CHECK_HAVE((node), (propname)); \
		if (prop && (prop->val.len != sizeof(cell_t))) \
			DO_ERR("\"%s\" property in %s has wrong size %d (should be 1 cell)\n", (propname), (node)->fullpath, prop->val.len); \
	} while (0)

#define CHECK_HAVE_WARN_ONECELL(node, propname) \
	do { \
		CHECK_HAVE_WARN((node), (propname)); \
		if (prop && (prop->val.len != sizeof(cell_t))) \
			DO_ERR("\"%s\" property in %s has wrong size %d (should be 1 cell)\n", (propname), (node)->fullpath, prop->val.len); \
	} while (0)

#define CHECK_HAVE_WARN_PHANDLE(xnode, propname, root) \
	do { \
		struct node *ref; \
		CHECK_HAVE_WARN_ONECELL((xnode), (propname)); \
		if (prop) {\
			cell_t phandle = propval_cell(prop); \
			if ((phandle == 0) || (phandle == -1)) { \
				DO_ERR("\"%s\" property in %s contains an invalid phandle %x\n", (propname), (xnode)->fullpath, phandle); \
			} else { \
				ref = get_node_by_phandle((root), propval_cell(prop)); \
				if (! ref) \
					DO_ERR("\"%s\" property in %s refers to non-existant phandle %x\n", (propname), (xnode)->fullpath, propval_cell(prop)); \
			} \
		} \
	} while (0)

#define CHECK_HAVE_WARN_STRING(node, propname) \
	do { \
		CHECK_HAVE_WARN((node), (propname)); \
		if (prop && !data_is_one_string(prop->val)) \
			DO_ERR("\"%s\" property in %s is not a string\n", \
				(propname), (node)->fullpath); \
	} while (0)

static int check_root(struct node *root)
{
	struct property *prop;
	int ok = 1;

	CHECK_HAVE_STRING(root, "model");
	CHECK_HAVE_WARN(root, "compatible");

	return ok;
}

static int check_cpus(struct node *root, int outversion, int boot_cpuid_phys)
{
	struct node *cpus, *cpu;
	struct property *prop;
	struct node *bootcpu = NULL;
	int ok = 1;

	cpus = get_subnode(root, "cpus");
	if (! cpus) {
		ERRMSG("Missing /cpus node\n");
		return 0;
	}

	if (cpus->addr_cells != 1)
		DO_ERR("%s has bad #address-cells value %d (should be 1)\n",
		       cpus->fullpath, cpus->addr_cells);
	if (cpus->size_cells != 0)
		DO_ERR("%s has bad #size-cells value %d (should be 0)\n",
		       cpus->fullpath, cpus->size_cells);

	for_each_child(cpus, cpu) {
		CHECK_HAVE_STREQ(cpu, "device_type", "cpu");

		CHECK_HAVE_ONECELL(cpu, "reg");
		if (prop) {
			cell_t unitnum;
			char *eptr;

			unitnum = strtol(get_unitname(cpu), &eptr, 16);
			if (*eptr) {
				WARNMSG("%s has bad format unit name %s (should be CPU number\n",
					cpu->fullpath, get_unitname(cpu));
			} else if (unitnum != propval_cell(prop)) {
				WARNMSG("%s unit name \"%s\" does not match \"reg\" property <%x>\n",
				       cpu->fullpath, get_unitname(cpu),
				       propval_cell(prop));
			}
		}

/* 		CHECK_HAVE_ONECELL(cpu, "d-cache-line-size"); */
/* 		CHECK_HAVE_ONECELL(cpu, "i-cache-line-size"); */
		CHECK_HAVE_ONECELL(cpu, "d-cache-size");
		CHECK_HAVE_ONECELL(cpu, "i-cache-size");

		CHECK_HAVE_WARN_ONECELL(cpu, "clock-frequency");
		CHECK_HAVE_WARN_ONECELL(cpu, "timebase-frequency");

		prop = get_property(cpu, "linux,boot-cpu");
		if (prop) {
			if (prop->val.len)
				WARNMSG("\"linux,boot-cpu\" property in %s is non-empty\n",
					cpu->fullpath);
			if (bootcpu)
				DO_ERR("Multiple boot cpus (%s and %s)\n",
				       bootcpu->fullpath, cpu->fullpath);
			else
				bootcpu = cpu;
		}
	}

	if (outversion < 2) {
		if (! bootcpu)
			WARNMSG("No cpu has \"linux,boot-cpu\" property\n");
	} else {
		if (bootcpu)
			WARNMSG("\"linux,boot-cpu\" property is deprecated in blob version 2 or higher\n");
		if (boot_cpuid_phys == 0xfeedbeef)
			WARNMSG("physical boot CPU not set.  Use -b option to set\n");
	}

	return ok;
}

static int check_memory(struct node *root)
{
	struct node *mem;
	struct property *prop;
	int nnodes = 0;
	int ok = 1;

	for_each_child(root, mem) {
		if (! strneq(mem->name, "memory", mem->basenamelen))
			continue;

		nnodes++;

		CHECK_HAVE_STREQ(mem, "device_type", "memory");
		CHECK_HAVE(mem, "reg");
	}

	if (nnodes == 0) {
		ERRMSG("No memory nodes\n");
		return 0;
	}

	return ok;
}

int check_semantics(struct node *dt, int outversion, int boot_cpuid_phys)
{
	int ok = 1;

	ok = ok && check_root(dt);
	ok = ok && check_cpus(dt, outversion, boot_cpuid_phys);
	ok = ok && check_memory(dt);
	if (! ok)
		return 0;

	return 1;
}
}
+31 −31
Original line number Original line Diff line number Diff line
@@ -32,8 +32,6 @@ void data_free(struct data d)
		m = nm;
		m = nm;
	}
	}


	assert(!d.val || d.asize);

	if (d.val)
	if (d.val)
		free(d.val);
		free(d.val);
}
}
@@ -43,9 +41,6 @@ struct data data_grow_for(struct data d, int xlen)
	struct data nd;
	struct data nd;
	int newsize;
	int newsize;


	/* we must start with an allocated datum */
	assert(!d.val || d.asize);

	if (xlen == 0)
	if (xlen == 0)
		return d;
		return d;


@@ -56,11 +51,8 @@ struct data data_grow_for(struct data d, int xlen)
	while ((d.len + xlen) > newsize)
	while ((d.len + xlen) > newsize)
		newsize *= 2;
		newsize *= 2;


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


	assert(nd.asize >= (d.len + xlen));

	return nd;
	return nd;
}
}


@@ -83,16 +75,11 @@ static char get_oct_char(const char *s, int *i)
	long val;
	long val;


	x[3] = '\0';
	x[3] = '\0';
	x[0] = s[(*i)];
	strncpy(x, s + *i, 3);
	if (x[0]) {
		x[1] = s[(*i)+1];
		if (x[1])
			x[2] = s[(*i)+2];
	}


	val = strtol(x, &endx, 8);
	val = strtol(x, &endx, 8);
	if ((endx - x) == 0)

		fprintf(stderr, "Empty \\nnn escape\n");
	assert(endx > x);


	(*i) += endx - x;
	(*i) += endx - x;
	return val;
	return val;
@@ -105,13 +92,11 @@ static char get_hex_char(const char *s, int *i)
	long val;
	long val;


	x[2] = '\0';
	x[2] = '\0';
	x[0] = s[(*i)];
	strncpy(x, s + *i, 2);
	if (x[0])
		x[1] = s[(*i)+1];


	val = strtol(x, &endx, 16);
	val = strtol(x, &endx, 16);
	if ((endx - x) == 0)
	if (!(endx  > x))
		fprintf(stderr, "Empty \\x escape\n");
		die("\\x used with no following hex digits\n");


	(*i) += endx - x;
	(*i) += endx - x;
	return val;
	return val;
@@ -182,14 +167,29 @@ struct data data_copy_escape_string(const char *s, int len)
	return d;
	return d;
}
}


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


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


	d.len = len;
		if (maxlen == -1)
	fread(d.val, len, 1, f);
			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;
	return d;
}
}
@@ -247,7 +247,7 @@ struct data data_merge(struct data d1, struct data d2)


struct data data_append_cell(struct data d, cell_t word)
struct data data_append_cell(struct data d, cell_t word)
{
{
	cell_t beword = cpu_to_be32(word);
	cell_t beword = cpu_to_fdt32(word);


	return data_append_data(d, &beword, sizeof(beword));
	return data_append_data(d, &beword, sizeof(beword));
}
}
@@ -256,15 +256,15 @@ struct data data_append_re(struct data d, const struct fdt_reserve_entry *re)
{
{
	struct fdt_reserve_entry bere;
	struct fdt_reserve_entry bere;


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


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


struct data data_append_addr(struct data d, u64 addr)
struct data data_append_addr(struct data d, uint64_t addr)
{
{
	u64 beaddr = cpu_to_be64(addr);
	uint64_t beaddr = cpu_to_fdt64(addr);


	return data_append_data(d, &beaddr, sizeof(beaddr));
	return data_append_data(d, &beaddr, sizeof(beaddr));
}
}
+56 −64
Original line number Original line Diff line number Diff line
@@ -28,6 +28,10 @@
PROPNODECHAR	[a-zA-Z0-9,._+*#?@-]
PROPNODECHAR	[a-zA-Z0-9,._+*#?@-]
PATHCHAR	({PROPNODECHAR}|[/])
PATHCHAR	({PROPNODECHAR}|[/])
LABEL		[a-zA-Z_][a-zA-Z0-9_]*
LABEL		[a-zA-Z_][a-zA-Z0-9_]*
STRING		\"([^\\"]|\\.)*\"
WS		[[:space:]]
COMMENT		"/*"([^*]|\*+[^*/])*\*+"/"
LINECOMMENT	"//".*\n


%{
%{
#include "dtc.h"
#include "dtc.h"
@@ -52,29 +56,26 @@ static int dts_version; /* = 0 */
				DPRINT("<V1>\n"); \
				DPRINT("<V1>\n"); \
				BEGIN(V1); \
				BEGIN(V1); \
			}
			}

static void push_input_file(const char *filename);
static int pop_input_file(void);
%}
%}


%%
%%
<*>"/include/"		BEGIN(INCLUDE);
<*>"/include/"{WS}*{STRING} {

			char *name = strchr(yytext, '\"') + 1;
<INCLUDE>\"[^"\n]*\"	{
			yytext[yyleng-1] = '\0';
			yytext[strlen(yytext) - 1] = 0;
			push_input_file(name);
			if (!push_input_file(yytext + 1)) {
				/* Some unrecoverable error.*/
				exit(1);
			}
			BEGIN_DEFAULT();
		}
		}



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


<*>\"([^\\"]|\\.)*\"	{
<*>{STRING}	{
			yylloc.filenum = srcpos_filenum;
			yylloc.file = srcpos_file;
			yylloc.first_line = yylineno;
			yylloc.first_line = yylineno;
			DPRINT("String: %s\n", yytext);
			DPRINT("String: %s\n", yytext);
			yylval.data = data_copy_escape_string(yytext+1,
			yylval.data = data_copy_escape_string(yytext+1,
@@ -84,7 +85,7 @@ static int dts_version; /* = 0 */
		}
		}


<*>"/dts-v1/"	{
<*>"/dts-v1/"	{
			yylloc.filenum = srcpos_filenum;
			yylloc.file = srcpos_file;
			yylloc.first_line = yylineno;
			yylloc.first_line = yylineno;
			DPRINT("Keyword: /dts-v1/\n");
			DPRINT("Keyword: /dts-v1/\n");
			dts_version = 1;
			dts_version = 1;
@@ -93,7 +94,7 @@ static int dts_version; /* = 0 */
		}
		}


<*>"/memreserve/"	{
<*>"/memreserve/"	{
			yylloc.filenum = srcpos_filenum;
			yylloc.file = srcpos_file;
			yylloc.first_line = yylineno;
			yylloc.first_line = yylineno;
			DPRINT("Keyword: /memreserve/\n");
			DPRINT("Keyword: /memreserve/\n");
			BEGIN_DEFAULT();
			BEGIN_DEFAULT();
@@ -101,7 +102,7 @@ static int dts_version; /* = 0 */
		}
		}


<*>{LABEL}:	{
<*>{LABEL}:	{
			yylloc.filenum = srcpos_filenum;
			yylloc.file = srcpos_file;
			yylloc.first_line = yylineno;
			yylloc.first_line = yylineno;
			DPRINT("Label: %s\n", yytext);
			DPRINT("Label: %s\n", yytext);
			yylval.labelref = strdup(yytext);
			yylval.labelref = strdup(yytext);
@@ -110,7 +111,7 @@ static int dts_version; /* = 0 */
		}
		}


<INITIAL>[bodh]# {
<INITIAL>[bodh]# {
			yylloc.filenum = srcpos_filenum;
			yylloc.file = srcpos_file;
			yylloc.first_line = yylineno;
			yylloc.first_line = yylineno;
			if (*yytext == 'b')
			if (*yytext == 'b')
				yylval.cbase = 2;
				yylval.cbase = 2;
@@ -125,7 +126,7 @@ static int dts_version; /* = 0 */
		}
		}


<INITIAL>[0-9a-fA-F]+	{
<INITIAL>[0-9a-fA-F]+	{
			yylloc.filenum = srcpos_filenum;
			yylloc.file = srcpos_file;
			yylloc.first_line = yylineno;
			yylloc.first_line = yylineno;
			yylval.literal = strdup(yytext);
			yylval.literal = strdup(yytext);
			DPRINT("Literal: '%s'\n", yylval.literal);
			DPRINT("Literal: '%s'\n", yylval.literal);
@@ -133,7 +134,7 @@ static int dts_version; /* = 0 */
		}
		}


<V1>[0-9]+|0[xX][0-9a-fA-F]+      {
<V1>[0-9]+|0[xX][0-9a-fA-F]+      {
			yylloc.filenum = srcpos_filenum;
			yylloc.file = srcpos_file;
			yylloc.first_line = yylineno;
			yylloc.first_line = yylineno;
			yylval.literal = strdup(yytext);
			yylval.literal = strdup(yytext);
			DPRINT("Literal: '%s'\n", yylval.literal);
			DPRINT("Literal: '%s'\n", yylval.literal);
@@ -141,7 +142,7 @@ static int dts_version; /* = 0 */
		}
		}


\&{LABEL}	{	/* label reference */
\&{LABEL}	{	/* label reference */
			yylloc.filenum = srcpos_filenum;
			yylloc.file = srcpos_file;
			yylloc.first_line = yylineno;
			yylloc.first_line = yylineno;
			DPRINT("Ref: %s\n", yytext+1);
			DPRINT("Ref: %s\n", yytext+1);
			yylval.labelref = strdup(yytext+1);
			yylval.labelref = strdup(yytext+1);
@@ -149,7 +150,7 @@ static int dts_version; /* = 0 */
		}
		}


"&{/"{PATHCHAR}+\}	{	/* new-style path reference */
"&{/"{PATHCHAR}+\}	{	/* new-style path reference */
			yylloc.filenum = srcpos_filenum;
			yylloc.file = srcpos_file;
			yylloc.first_line = yylineno;
			yylloc.first_line = yylineno;
			yytext[yyleng-1] = '\0';
			yytext[yyleng-1] = '\0';
			DPRINT("Ref: %s\n", yytext+2);
			DPRINT("Ref: %s\n", yytext+2);
@@ -158,7 +159,7 @@ static int dts_version; /* = 0 */
		}
		}


<INITIAL>"&/"{PATHCHAR}+ {	/* old-style path reference */
<INITIAL>"&/"{PATHCHAR}+ {	/* old-style path reference */
			yylloc.filenum = srcpos_filenum;
			yylloc.file = srcpos_file;
			yylloc.first_line = yylineno;
			yylloc.first_line = yylineno;
			DPRINT("Ref: %s\n", yytext+1);
			DPRINT("Ref: %s\n", yytext+1);
			yylval.labelref = strdup(yytext+1);
			yylval.labelref = strdup(yytext+1);
@@ -166,7 +167,7 @@ static int dts_version; /* = 0 */
		}
		}


<BYTESTRING>[0-9a-fA-F]{2} {
<BYTESTRING>[0-9a-fA-F]{2} {
			yylloc.filenum = srcpos_filenum;
			yylloc.file = srcpos_file;
			yylloc.first_line = yylineno;
			yylloc.first_line = yylineno;
			yylval.byte = strtol(yytext, NULL, 16);
			yylval.byte = strtol(yytext, NULL, 16);
			DPRINT("Byte: %02x\n", (int)yylval.byte);
			DPRINT("Byte: %02x\n", (int)yylval.byte);
@@ -174,7 +175,7 @@ static int dts_version; /* = 0 */
		}
		}


<BYTESTRING>"]"	{
<BYTESTRING>"]"	{
			yylloc.filenum = srcpos_filenum;
			yylloc.file = srcpos_file;
			yylloc.first_line = yylineno;
			yylloc.first_line = yylineno;
			DPRINT("/BYTESTRING\n");
			DPRINT("/BYTESTRING\n");
			BEGIN_DEFAULT();
			BEGIN_DEFAULT();
@@ -182,7 +183,7 @@ static int dts_version; /* = 0 */
		}
		}


<PROPNODENAME>{PROPNODECHAR}+ {
<PROPNODENAME>{PROPNODECHAR}+ {
			yylloc.filenum = srcpos_filenum;
			yylloc.file = srcpos_file;
			yylloc.first_line = yylineno;
			yylloc.first_line = yylineno;
			DPRINT("PropNodeName: %s\n", yytext);
			DPRINT("PropNodeName: %s\n", yytext);
			yylval.propnodename = strdup(yytext);
			yylval.propnodename = strdup(yytext);
@@ -190,20 +191,19 @@ static int dts_version; /* = 0 */
			return DT_PROPNODENAME;
			return DT_PROPNODENAME;
		}
		}



"/incbin/"	{
<*>[[:space:]]+	/* eat whitespace */
			yylloc.file = srcpos_file;

<*>"/*"([^*]|\*+[^*/])*\*+"/"	{
			yylloc.filenum = srcpos_filenum;
			yylloc.first_line = yylineno;
			yylloc.first_line = yylineno;
			DPRINT("Comment: %s\n", yytext);
			DPRINT("Binary Include\n");
			/* eat comments */
			return DT_INCBIN;
		}
		}


<*>"//".*\n	/* eat line comments */
<*>{WS}+	/* eat whitespace */
<*>{COMMENT}+	/* eat C-style comments */
<*>{LINECOMMENT}+ /* eat C++-style comments */


<*>.		{
<*>.		{
			yylloc.filenum = srcpos_filenum;
			yylloc.file = srcpos_file;
			yylloc.first_line = yylineno;
			yylloc.first_line = yylineno;
			DPRINT("Char: %c (\\x%02x)\n", yytext[0],
			DPRINT("Char: %c (\\x%02x)\n", yytext[0],
				(unsigned)yytext[0]);
				(unsigned)yytext[0]);
@@ -227,14 +227,13 @@ static int dts_version; /* = 0 */
 */
 */


struct incl_file {
struct incl_file {
	int filenum;
	struct dtc_file *file;
	FILE *file;
	YY_BUFFER_STATE yy_prev_buf;
	YY_BUFFER_STATE yy_prev_buf;
	int yy_prev_lineno;
	int yy_prev_lineno;
	struct incl_file *prev;
	struct incl_file *prev;
};
};


struct incl_file *incl_file_stack;
static struct incl_file *incl_file_stack;




/*
/*
@@ -245,36 +244,34 @@ struct incl_file *incl_file_stack;
static int incl_depth = 0;
static int incl_depth = 0;




int push_input_file(const char *filename)
static void push_input_file(const char *filename)
{
{
	FILE *f;
	struct incl_file *incl_file;
	struct incl_file *incl_file;
	struct dtc_file *newfile;
	struct search_path search, *searchptr = NULL;


	if (!filename) {
	assert(filename);
		yyerror("No include file name given.");
		return 0;
	}


	if (incl_depth++ >= MAX_INCLUDE_DEPTH) {
	if (incl_depth++ >= MAX_INCLUDE_DEPTH)
		yyerror("Includes nested too deeply");
		die("Includes nested too deeply");
		return 0;

	if (srcpos_file) {
		search.dir = srcpos_file->dir;
		search.next = NULL;
		search.prev = NULL;
		searchptr = &search;
	}
	}


	f = dtc_open_file(filename);
	newfile = dtc_open_file(filename, searchptr);


	incl_file = malloc(sizeof(struct incl_file));
	incl_file = xmalloc(sizeof(struct incl_file));
	if (!incl_file) {
		yyerror("Can not allocate include file space.");
		return 0;
	}


	/*
	/*
	 * Save current context.
	 * Save current context.
	 */
	 */
	incl_file->yy_prev_buf = YY_CURRENT_BUFFER;
	incl_file->yy_prev_buf = YY_CURRENT_BUFFER;
	incl_file->yy_prev_lineno = yylineno;
	incl_file->yy_prev_lineno = yylineno;
	incl_file->filenum = srcpos_filenum;
	incl_file->file = srcpos_file;
	incl_file->file = yyin;
	incl_file->prev = incl_file_stack;
	incl_file->prev = incl_file_stack;


	incl_file_stack = incl_file;
	incl_file_stack = incl_file;
@@ -282,23 +279,21 @@ int push_input_file(const char *filename)
	/*
	/*
	 * Establish new context.
	 * Establish new context.
	 */
	 */
	srcpos_filenum = lookup_file_name(filename, 0);
	srcpos_file = newfile;
	yylineno = 1;
	yylineno = 1;
	yyin = f;
	yyin = newfile->file;
	yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
	yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));

	return 1;
}
}




int pop_input_file(void)
static int pop_input_file(void)
{
{
	struct incl_file *incl_file;
	struct incl_file *incl_file;


	if (incl_file_stack == 0)
	if (incl_file_stack == 0)
		return 0;
		return 0;


	fclose(yyin);
	dtc_close_file(srcpos_file);


	/*
	/*
	 * Pop.
	 * Pop.
@@ -313,16 +308,13 @@ int pop_input_file(void)
	yy_delete_buffer(YY_CURRENT_BUFFER);
	yy_delete_buffer(YY_CURRENT_BUFFER);
	yy_switch_to_buffer(incl_file->yy_prev_buf);
	yy_switch_to_buffer(incl_file->yy_prev_buf);
	yylineno = incl_file->yy_prev_lineno;
	yylineno = incl_file->yy_prev_lineno;
	srcpos_filenum = incl_file->filenum;
	srcpos_file = incl_file->file;
	yyin = incl_file->file;
	yyin = incl_file->file ? incl_file->file->file : NULL;


	/*
	/*
	 * Free old state.
	 * Free old state.
	 */
	 */
	free(incl_file);
	free(incl_file);


	if (YY_CURRENT_BUFFER == 0)
		return 0;

	return 1;
	return 1;
}
}
+229 −216

File changed.

Preview size limit exceeded, changes collapsed.

Loading