diff options
| author | 2018-12-28 20:08:34 -0800 | |
|---|---|---|
| committer | 2018-12-28 20:08:34 -0800 | |
| commit | 030672aea826adf3dee9100ee8ac303b62c8fe7f (patch) | |
| tree | c9815fcd276e4c61b864790e81e5cbca16b80142 /scripts/dtc/treesource.c | |
| parent | Merge tag 'gpio-v4.21-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio (diff) | |
| parent | of: __of_detach_node() - remove node from phandle cache (diff) | |
| download | linux-dev-030672aea826adf3dee9100ee8ac303b62c8fe7f.tar.xz linux-dev-030672aea826adf3dee9100ee8ac303b62c8fe7f.zip  | |
Merge tag 'devicetree-for-4.21' of git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux
Pull Devicetree updates from Rob Herring:
 "The biggest highlight here is the start of using json-schema for DT
  bindings. Being able to validate bindings has been discussed for years
  with little progress.
   - Initial support for DT bindings using json-schema language. This is
     the start of converting DT bindings from free-form text to a
     structured format.
   - Reworking of initrd address initialization. This moves to using the
     phys address instead of virt addr in the DT parsing code. This
     rework was motivated by CONFIG_DEV_BLK_INITRD causing unnecessary
     rebuilding of lots of files.
   - Fix stale phandle entries in phandle cache
   - DT overlay validation improvements. This exposed several memory
     leak bugs which have been fixed.
   - Use node name and device_type helper functions in DT code
   - Last remaining conversions to using %pOFn printk specifier instead
     of device_node.name directly
   - Create new common RTC binding doc and move all trivial RTC devices
     out of trivial-devices.txt.
   - New bindings for Freescale MAG3110 magnetometer, Cadence Sierra
     PHY, and Xen shared memory
   - Update dtc to upstream version v1.4.7-57-gf267e674d145"
* tag 'devicetree-for-4.21' of git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux: (68 commits)
  of: __of_detach_node() - remove node from phandle cache
  of: of_node_get()/of_node_put() nodes held in phandle cache
  gpio-omap.txt: add reg and interrupts properties
  dt-bindings: mrvl,intc: fix a trivial typo
  dt-bindings: iio: magnetometer: add dt-bindings for freescale mag3110
  dt-bindings: Convert trivial-devices.txt to json-schema
  dt-bindings: arm: mrvl: amend Browstone compatible string
  dt-bindings: arm: Convert Tegra board/soc bindings to json-schema
  dt-bindings: arm: Convert ZTE board/soc bindings to json-schema
  dt-bindings: arm: Add missing Xilinx boards
  dt-bindings: arm: Convert Xilinx board/soc bindings to json-schema
  dt-bindings: arm: Convert VIA board/soc bindings to json-schema
  dt-bindings: arm: Convert ST STi board/soc bindings to json-schema
  dt-bindings: arm: Convert SPEAr board/soc bindings to json-schema
  dt-bindings: arm: Convert CSR SiRF board/soc bindings to json-schema
  dt-bindings: arm: Convert QCom board/soc bindings to json-schema
  dt-bindings: arm: Convert TI nspire board/soc bindings to json-schema
  dt-bindings: arm: Convert TI davinci board/soc bindings to json-schema
  dt-bindings: arm: Convert Calxeda board/soc bindings to json-schema
  dt-bindings: arm: Convert Altera board/soc bindings to json-schema
  ...
Diffstat (limited to 'scripts/dtc/treesource.c')
| -rw-r--r-- | scripts/dtc/treesource.c | 115 | 
1 files changed, 73 insertions, 42 deletions
diff --git a/scripts/dtc/treesource.c b/scripts/dtc/treesource.c index f2874f1d1465..1af36628b75f 100644 --- a/scripts/dtc/treesource.c +++ b/scripts/dtc/treesource.c @@ -64,6 +64,10 @@ static bool isstring(char c)  static void write_propval_string(FILE *f, const char *s, size_t len)  {  	const char *end = s + len - 1; + +	if (!len) +		return; +  	assert(*end == '\0');  	fprintf(f, "\""); @@ -118,18 +122,20 @@ static void write_propval_int(FILE *f, const char *p, size_t len, size_t width)  	for (; p < end; p += width) {  		switch (width) {  		case 1: -			fprintf(f, " %02"PRIx8, *(const uint8_t*)p); +			fprintf(f, "%02"PRIx8, *(const uint8_t*)p);  			break;  		case 2: -			fprintf(f, " 0x%02"PRIx16, fdt16_to_cpu(*(const fdt16_t*)p)); +			fprintf(f, "0x%02"PRIx16, fdt16_to_cpu(*(const fdt16_t*)p));  			break;  		case 4: -			fprintf(f, " 0x%02"PRIx32, fdt32_to_cpu(*(const fdt32_t*)p)); +			fprintf(f, "0x%02"PRIx32, fdt32_to_cpu(*(const fdt32_t*)p));  			break;  		case 8: -			fprintf(f, " 0x%02"PRIx64, fdt64_to_cpu(*(const fdt64_t*)p)); +			fprintf(f, "0x%02"PRIx64, fdt64_to_cpu(*(const fdt64_t*)p));  			break;  		} +		if (p + width < end) +			fputc(' ', f);  	}  } @@ -162,10 +168,10 @@ static const char *delim_start[] = {  	[TYPE_STRING] = "",  };  static const char *delim_end[] = { -	[TYPE_UINT8] = " ]", -	[TYPE_UINT16] = " >", -	[TYPE_UINT32] = " >", -	[TYPE_UINT64] = " >", +	[TYPE_UINT8] = "]", +	[TYPE_UINT16] = ">", +	[TYPE_UINT32] = ">", +	[TYPE_UINT64] = ">",  	[TYPE_STRING] = "",  }; @@ -208,13 +214,22 @@ static void write_propval(FILE *f, struct property *prop)  	struct marker *m = prop->val.markers;  	struct marker dummy_marker;  	enum markertype emit_type = TYPE_NONE; +	char *srcstr;  	if (len == 0) { -		fprintf(f, ";\n"); +		fprintf(f, ";"); +		if (annotate) { +			srcstr = srcpos_string_first(prop->srcpos, annotate); +			if (srcstr) { +				fprintf(f, " /* %s */", srcstr); +				free(srcstr); +			} +		} +		fprintf(f, "\n");  		return;  	} -	fprintf(f, " = "); +	fprintf(f, " =");  	if (!next_type_marker(m)) {  		/* data type information missing, need to guess */ @@ -225,32 +240,23 @@ static void write_propval(FILE *f, struct property *prop)  		m = &dummy_marker;  	} -	struct marker *m_label = prop->val.markers;  	for_each_marker(m) { -		size_t chunk_len; +		size_t chunk_len = (m->next ? m->next->offset : len) - m->offset; +		size_t data_len = type_marker_length(m) ? : len - m->offset;  		const char *p = &prop->val.val[m->offset]; -		if (!has_data_type_information(m)) -			continue; - -		chunk_len = type_marker_length(m); -		if (!chunk_len) -			chunk_len = len - m->offset; - -		if (emit_type != TYPE_NONE) -			fprintf(f, "%s, ", delim_end[emit_type]); -		emit_type = m->type; - -		for_each_marker_of_type(m_label, LABEL) { -			if (m_label->offset > m->offset) -				break; -			fprintf(f, "%s: ", m_label->ref); -		} - -		fprintf(f, "%s", delim_start[emit_type]); +		if (has_data_type_information(m)) { +			emit_type = m->type; +			fprintf(f, " %s", delim_start[emit_type]); +		} else if (m->type == LABEL) +			fprintf(f, " %s:", m->ref); +		else if (m->offset) +			fputc(' ', f); -		if (chunk_len <= 0) +		if (emit_type == TYPE_NONE) { +			assert(chunk_len == 0);  			continue; +		}  		switch(emit_type) {  		case TYPE_UINT16: @@ -268,15 +274,23 @@ static void write_propval(FILE *f, struct property *prop)  		default:  			write_propval_int(f, p, chunk_len, 1);  		} -	} -	/* Wrap up any labels at the end of the value */ -	for_each_marker_of_type(m_label, LABEL) { -		assert (m_label->offset == len); -		fprintf(f, " %s:", m_label->ref); +		if (chunk_len == data_len) { +			size_t pos = m->offset + chunk_len; +			fprintf(f, pos == len ? "%s" : "%s,", +			        delim_end[emit_type] ? : ""); +			emit_type = TYPE_NONE; +		}  	} - -	fprintf(f, "%s;\n", delim_end[emit_type] ? : ""); +	fprintf(f, ";"); +	if (annotate) { +		srcstr = srcpos_string_first(prop->srcpos, annotate); +		if (srcstr) { +			fprintf(f, " /* %s */", srcstr); +			free(srcstr); +		} +	} +	fprintf(f, "\n");  }  static void write_tree_source_node(FILE *f, struct node *tree, int level) @@ -284,14 +298,24 @@ static void write_tree_source_node(FILE *f, struct node *tree, int level)  	struct property *prop;  	struct node *child;  	struct label *l; +	char *srcstr;  	write_prefix(f, level);  	for_each_label(tree->labels, l)  		fprintf(f, "%s: ", l->label);  	if (tree->name && (*tree->name)) -		fprintf(f, "%s {\n", tree->name); +		fprintf(f, "%s {", tree->name);  	else -		fprintf(f, "/ {\n"); +		fprintf(f, "/ {"); + +	if (annotate) { +		srcstr = srcpos_string_first(tree->srcpos, annotate); +		if (srcstr) { +			fprintf(f, " /* %s */", srcstr); +			free(srcstr); +		} +	} +	fprintf(f, "\n");  	for_each_property(tree, prop) {  		write_prefix(f, level+1); @@ -305,10 +329,17 @@ static void write_tree_source_node(FILE *f, struct node *tree, int level)  		write_tree_source_node(f, child, level+1);  	}  	write_prefix(f, level); -	fprintf(f, "};\n"); +	fprintf(f, "};"); +	if (annotate) { +		srcstr = srcpos_string_last(tree->srcpos, annotate); +		if (srcstr) { +			fprintf(f, " /* %s */", srcstr); +			free(srcstr); +		} +	} +	fprintf(f, "\n");  } -  void dt_to_source(FILE *f, struct dt_info *dti)  {  	struct reserve_info *re;  | 
