diff mbox series

[RFC,1/4] scripts/dtc: update fdtget.c to upstream version v1.4.7-57-gf267e674d145

Message ID 20200130124233.4006-1-l.stelmach@samsung.com (mailing list archive)
State New, archived
Headers show
Series [RFC,1/4] scripts/dtc: update fdtget.c to upstream version v1.4.7-57-gf267e674d145 | expand

Commit Message

Lukasz Stelmach Jan. 30, 2020, 12:42 p.m. UTC
Build and fdtget and add fdtget.c to the list of update source files.

Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
---
 scripts/dtc/.gitignore           |   4 +
 scripts/dtc/Makefile             |   5 ++
 scripts/dtc/fdtget.c             | 125 ++++++++++++++++++-------------
 scripts/dtc/update-dtc-source.sh |   4 +-
 4 files changed, 82 insertions(+), 56 deletions(-)

Comments

Russell King (Oracle) Jan. 30, 2020, 12:47 p.m. UTC | #1
On Thu, Jan 30, 2020 at 01:42:30PM +0100, Łukasz Stelmach wrote:
> Build and fdtget and add fdtget.c to the list of update source files.
> 
> Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
> ---
>  scripts/dtc/.gitignore           |   4 +
>  scripts/dtc/Makefile             |   5 ++
>  scripts/dtc/fdtget.c             | 125 ++++++++++++++++++-------------
>  scripts/dtc/update-dtc-source.sh |   4 +-
>  4 files changed, 82 insertions(+), 56 deletions(-)
> 
> diff --git scripts/dtc/.gitignore scripts/dtc/.gitignore
> index 2e6e60d64ede..80f6b50fdf77 100644
> --- scripts/dtc/.gitignore
> +++ scripts/dtc/.gitignore
> @@ -1 +1,5 @@
>  dtc
> +dtc-lexer.lex.c
> +dtc-parser.tab.c
> +dtc-parser.tab.h
> +fdtget
> diff --git scripts/dtc/Makefile scripts/dtc/Makefile
> index b5a5b1c548c9..74322d8dac25 100644
> --- scripts/dtc/Makefile
> +++ scripts/dtc/Makefile
> @@ -2,12 +2,15 @@
>  # scripts/dtc makefile
>  
>  hostprogs-$(CONFIG_DTC) := dtc
> +hostprogs-$(CONFIG_DTC) += fdtget
>  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
>  
> +fdtget-objs     := fdtget.o util.o
> +
>  # Source files need to get at the userspace version of libfdt_env.h to compile
>  HOST_EXTRACFLAGS := -I $(srctree)/$(src)/libfdt
>  
> @@ -26,5 +29,7 @@ endif
>  HOSTCFLAGS_dtc-lexer.lex.o := -I $(srctree)/$(src)
>  HOSTCFLAGS_dtc-parser.tab.o := -I $(srctree)/$(src)
>  
> +HOSTLDLIBS_fdtget := -L$(obj)/libfdt -lfdt -Wl,-rpath='$$ORIGIN/libfdt'
> +
>  # dependencies on generated files need to be listed explicitly
>  $(obj)/dtc-lexer.lex.o: $(obj)/dtc-parser.tab.h
> diff --git scripts/dtc/fdtget.c scripts/dtc/fdtget.c
> index c922f82246c6..777582e2d45f 100644
> --- scripts/dtc/fdtget.c
> +++ scripts/dtc/fdtget.c
> @@ -39,6 +39,37 @@ static void report_error(const char *where, int err)
>  	fprintf(stderr, "Error at '%s': %s\n", where, fdt_strerror(err));
>  }
>  
> +/**
> + * Shows a list of cells in the requested format
> + *
> + * @param disp		Display information / options
> + * @param data		Data to display
> + * @param len		Maximum length of buffer
> + * @param size		Data size to use for display (e.g. 4 for 32-bit)
> + * @return 0 if ok, -1 on error
> + */
> +static int show_cell_list(struct display_info *disp, const char *data, int len,
> +			  int size)
> +{
> +	const uint8_t *p = (const uint8_t *)data;
> +	char fmt[3];
> +	int value;
> +	int i;
> +
> +	fmt[0] = '%';
> +	fmt[1] = disp->type ? disp->type : 'd';
> +	fmt[2] = '\0';
> +	for (i = 0; i < len; i += size, p += size) {
> +		if (i)
> +			printf(" ");
> +		value = size == 4 ? fdt32_ld((const fdt32_t *)p) :
> +			size == 2 ? (*p << 8) | p[1] : *p;
> +		printf(fmt, value);
> +	}
> +
> +	return 0;
> +}
> +
>  /**
>   * Displays data of a given length according to selected options
>   *
> @@ -52,12 +83,9 @@ static void report_error(const char *where, int err)
>   */
>  static int show_data(struct display_info *disp, const char *data, int len)
>  {
> -	int i, size;
> -	const uint8_t *p = (const uint8_t *)data;
> +	int size;
>  	const char *s;
> -	int value;
>  	int is_string;
> -	char fmt[3];
>  
>  	/* no data, don't print */
>  	if (len == 0)
> @@ -85,17 +113,8 @@ static int show_data(struct display_info *disp, const char *data, int len)
>  				"selected data size\n");
>  		return -1;
>  	}
> -	fmt[0] = '%';
> -	fmt[1] = disp->type ? disp->type : 'd';
> -	fmt[2] = '\0';
> -	for (i = 0; i < len; i += size, p += size) {
> -		if (i)
> -			printf(" ");
> -		value = size == 4 ? fdt32_to_cpu(*(const uint32_t *)p) :
> -			size == 2 ? (*p << 8) | p[1] : *p;
> -		printf(fmt, value);
> -	}
> -	return 0;
> +
> +	return show_cell_list(disp, data, len, size);
>  }
>  
>  /**
> @@ -107,7 +126,6 @@ static int show_data(struct display_info *disp, const char *data, int len)
>   */
>  static int list_properties(const void *blob, int node)
>  {
> -	const struct fdt_property *data;
>  	const char *name;
>  	int prop;
>  
> @@ -116,8 +134,7 @@ static int list_properties(const void *blob, int node)
>  		/* Stop silently when there are no more properties */
>  		if (prop < 0)
>  			return prop == -FDT_ERR_NOTFOUND ? 0 : prop;
> -		data = fdt_get_property_by_offset(blob, prop, NULL);
> -		name = fdt_string(blob, fdt32_to_cpu(data->nameoff));
> +		fdt_getprop_by_offset(blob, prop, &name, NULL);
>  		if (name)
>  			puts(name);
>  		prop = fdt_next_property_offset(blob, prop);
> @@ -231,7 +248,7 @@ static int show_data_for_item(const void *blob, struct display_info *disp,
>   * @param filename	Filename of blob file
>   * @param arg		List of arguments to process
>   * @param arg_count	Number of arguments
> - * @param return 0 if ok, -ve on error
> + * @return 0 if ok, -ve on error
>   */
>  static int do_fdtget(struct display_info *disp, const char *filename,
>  		     char **arg, int arg_count, int args_per_step)
> @@ -240,7 +257,7 @@ static int do_fdtget(struct display_info *disp, const char *filename,
>  	const char *prop;
>  	int i, node;
>  
> -	blob = utilfdt_read(filename);
> +	blob = utilfdt_read(filename, NULL);
>  	if (!blob)
>  		return -1;
>  
> @@ -252,44 +269,50 @@ static int do_fdtget(struct display_info *disp, const char *filename,
>  				continue;
>  			} else {
>  				report_error(arg[i], node);
> +				free(blob);
>  				return -1;
>  			}
>  		}
>  		prop = args_per_step == 1 ? NULL : arg[i + 1];
>  
> -		if (show_data_for_item(blob, disp, node, prop))
> +		if (show_data_for_item(blob, disp, node, prop)) {
> +			free(blob);
>  			return -1;
> +		}
>  	}
> +
> +	free(blob);
> +
>  	return 0;
>  }
>  
> -static const char *usage_msg =
> -	"fdtget - read values from device tree\n"
> -	"\n"
> -	"Each value is printed on a new line.\n\n"
> -	"Usage:\n"
> +/* Usage related data. */
> +static const char usage_synopsis[] =
> +	"read values from device tree\n"
>  	"	fdtget <options> <dt file> [<node> <property>]...\n"
>  	"	fdtget -p <options> <dt file> [<node> ]...\n"
> -	"Options:\n"
> -	"\t-t <type>\tType of data\n"
> -	"\t-p\t\tList properties for each node\n"
> -	"\t-l\t\tList subnodes for each node\n"
> -	"\t-d\t\tDefault value to display when the property is "
> -			"missing\n"
> -	"\t-h\t\tPrint this help\n\n"
> +	"\n"
> +	"Each value is printed on a new line.\n"
>  	USAGE_TYPE_MSG;
> -
> -static void usage(const char *msg)
> -{
> -	if (msg)
> -		fprintf(stderr, "Error: %s\n\n", msg);
> -
> -	fprintf(stderr, "%s", usage_msg);
> -	exit(2);
> -}
> +static const char usage_short_opts[] = "t:pld:" USAGE_COMMON_SHORT_OPTS;
> +static struct option const usage_long_opts[] = {
> +	{"type",              a_argument, NULL, 't'},
> +	{"properties",       no_argument, NULL, 'p'},
> +	{"list",             no_argument, NULL, 'l'},
> +	{"default",           a_argument, NULL, 'd'},
> +	USAGE_COMMON_LONG_OPTS,
> +};
> +static const char * const usage_opts_help[] = {
> +	"Type of data",
> +	"List properties for each node",
> +	"List subnodes for each node",
> +	"Default value to display when the property is missing",
> +	USAGE_COMMON_OPTS_HELP
> +};
>  
>  int main(int argc, char *argv[])
>  {
> +	int opt;
>  	char *filename = NULL;
>  	struct display_info disp;
>  	int args_per_step = 2;
> @@ -298,20 +321,14 @@ int main(int argc, char *argv[])
>  	memset(&disp, '\0', sizeof(disp));
>  	disp.size = -1;
>  	disp.mode = MODE_SHOW_VALUE;
> -	for (;;) {
> -		int c = getopt(argc, argv, "d:hlpt:");
> -		if (c == -1)
> -			break;
> -
> -		switch (c) {
> -		case 'h':
> -		case '?':
> -			usage(NULL);
> +	while ((opt = util_getopt_long()) != EOF) {
> +		switch (opt) {
> +		case_USAGE_COMMON_FLAGS
>  
>  		case 't':
>  			if (utilfdt_decode_type(optarg, &disp.type,
>  					&disp.size))
> -				usage("Invalid type string");
> +				usage("invalid type string");
>  			break;
>  
>  		case 'p':
> @@ -333,7 +350,7 @@ int main(int argc, char *argv[])
>  	if (optind < argc)
>  		filename = argv[optind++];
>  	if (!filename)
> -		usage("Missing filename");
> +		usage("missing filename");
>  
>  	argv += optind;
>  	argc -= optind;
> @@ -344,7 +361,7 @@ int main(int argc, char *argv[])
>  
>  	/* Check for node, property arguments */
>  	if (args_per_step == 2 && (argc % 2))
> -		usage("Must have an even number of arguments");
> +		usage("must have an even number of arguments");
>  
>  	if (do_fdtget(&disp, filename, argv, argc, args_per_step))
>  		return 1;
> diff --git scripts/dtc/update-dtc-source.sh scripts/dtc/update-dtc-source.sh
> index 7dd29a0362b8..8db277546785 100755
> --- scripts/dtc/update-dtc-source.sh
> +++ scripts/dtc/update-dtc-source.sh
> @@ -31,8 +31,8 @@ set -ev
>  DTC_UPSTREAM_PATH=`pwd`/../dtc
>  DTC_LINUX_PATH=`pwd`/scripts/dtc
>  
> -DTC_SOURCE="checks.c data.c dtc.c dtc.h flattree.c fstree.c livetree.c srcpos.c \
> -		srcpos.h treesource.c util.c util.h version_gen.h yamltree.c Makefile.dtc \
> +DTC_SOURCE="checks.c data.c dtc.c dtc.h fdtget.c flattree.c fstree.c livetree.c
> +		srcpos.c srcpos.h treesource.c util.c util.h version_gen.h Makefile.dtc \

This looks like you're dropping yamltree.c.  Is that intentional?

>  		dtc-lexer.l dtc-parser.y"
>  LIBFDT_SOURCE="Makefile.libfdt fdt.c fdt.h fdt_addresses.c fdt_empty_tree.c \
>  		fdt_overlay.c fdt_ro.c fdt_rw.c fdt_strerror.c fdt_sw.c \
> -- 
> 2.20.1
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Lukasz Stelmach Jan. 30, 2020, 12:55 p.m. UTC | #2
It was <2020-01-30 czw 12:47>, when Russell King - ARM Linux admin wrote:
> On Thu, Jan 30, 2020 at 01:42:30PM +0100, Łukasz Stelmach wrote:
>> Build and fdtget and add fdtget.c to the list of update source files.
>> 
>> Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
>> ---
>>  scripts/dtc/.gitignore           |   4 +
>>  scripts/dtc/Makefile             |   5 ++
>>  scripts/dtc/fdtget.c             | 125 ++++++++++++++++++-------------
>>  scripts/dtc/update-dtc-source.sh |   4 +-
>>  4 files changed, 82 insertions(+), 56 deletions(-)
>> 

[...]

>> diff --git scripts/dtc/update-dtc-source.sh scripts/dtc/update-dtc-source.sh
>> index 7dd29a0362b8..8db277546785 100755
>> --- scripts/dtc/update-dtc-source.sh
>> +++ scripts/dtc/update-dtc-source.sh
>> @@ -31,8 +31,8 @@ set -ev
>>  DTC_UPSTREAM_PATH=`pwd`/../dtc
>>  DTC_LINUX_PATH=`pwd`/scripts/dtc
>>  
>> -DTC_SOURCE="checks.c data.c dtc.c dtc.h flattree.c fstree.c livetree.c srcpos.c \
>> -		srcpos.h treesource.c util.c util.h version_gen.h yamltree.c Makefile.dtc \
>> +DTC_SOURCE="checks.c data.c dtc.c dtc.h fdtget.c flattree.c fstree.c livetree.c
>> +		srcpos.c srcpos.h treesource.c util.c util.h version_gen.h Makefile.dtc \
>
> This looks like you're dropping yamltree.c.  Is that intentional?
>

Not it isn't. Thanks. Fixed.

>>  		dtc-lexer.l dtc-parser.y"
>>  LIBFDT_SOURCE="Makefile.libfdt fdt.c fdt.h fdt_addresses.c fdt_empty_tree.c \
>>  		fdt_overlay.c fdt_ro.c fdt_rw.c fdt_strerror.c fdt_sw.c \
>> -- 
>> 2.20.1
>> 
>> 
>> _______________________________________________
>> linux-arm-kernel mailing list
>> linux-arm-kernel@lists.infradead.org
>> https://protect2.fireeye.com/url?k=c03cfed5-9df03751-c03d759a-0cc47aa8f5ba-45d60c6701b8fc7a&u=http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Rob Herring (Arm) Jan. 30, 2020, 2:16 p.m. UTC | #3
On Thu, Jan 30, 2020 at 6:42 AM Łukasz Stelmach <l.stelmach@samsung.com> wrote:
>
> Build and fdtget and add fdtget.c to the list of update source files.

Why does the kernel need fdtget and why not use the version from your distro?

Please Cc the DT list next time.

> Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
> ---
>  scripts/dtc/.gitignore           |   4 +
>  scripts/dtc/Makefile             |   5 ++
>  scripts/dtc/fdtget.c             | 125 ++++++++++++++++++-------------
>  scripts/dtc/update-dtc-source.sh |   4 +-

Separate changes by updates to this script, running the script (to get
fdtget.c), and updates to kernel files.

>  4 files changed, 82 insertions(+), 56 deletions(-)
>
> diff --git scripts/dtc/.gitignore scripts/dtc/.gitignore
> index 2e6e60d64ede..80f6b50fdf77 100644
> --- scripts/dtc/.gitignore
> +++ scripts/dtc/.gitignore
> @@ -1 +1,5 @@
>  dtc
> +dtc-lexer.lex.c
> +dtc-parser.tab.c
> +dtc-parser.tab.h

These are needed regardless. Probably a treewide rule for *.lex.c,
*.tab.c, *.tab.h would be better.

> +fdtget
> diff --git scripts/dtc/Makefile scripts/dtc/Makefile
> index b5a5b1c548c9..74322d8dac25 100644
> --- scripts/dtc/Makefile
> +++ scripts/dtc/Makefile
> @@ -2,12 +2,15 @@
>  # scripts/dtc makefile
>
>  hostprogs-$(CONFIG_DTC) := dtc
> +hostprogs-$(CONFIG_DTC) += fdtget
>  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
>
> +fdtget-objs     := fdtget.o util.o
> +
>  # Source files need to get at the userspace version of libfdt_env.h to compile
>  HOST_EXTRACFLAGS := -I $(srctree)/$(src)/libfdt
>
> @@ -26,5 +29,7 @@ endif
>  HOSTCFLAGS_dtc-lexer.lex.o := -I $(srctree)/$(src)
>  HOSTCFLAGS_dtc-parser.tab.o := -I $(srctree)/$(src)
>
> +HOSTLDLIBS_fdtget := -L$(obj)/libfdt -lfdt -Wl,-rpath='$$ORIGIN/libfdt'
> +

We never build libfdt as a library, so how does this work unless it
pulls in the distro copy?

Rob
Lukasz Stelmach Feb. 6, 2020, 1:17 p.m. UTC | #4
It was <2020-01-30 czw 08:16>, when Rob Herring wrote:
> On Thu, Jan 30, 2020 at 6:42 AM Łukasz Stelmach <l.stelmach@samsung.com> wrote:
>>
>> Build and fdtget and add fdtget.c to the list of update source files.
>
> Why does the kernel need fdtget and why not use the version from your
> distro?

get_console_base.pl introduced in one of later patches uses fdtget. The
script is required to build bootImage. So fdtget is required to build
the kernel the same way dtc is.

>> Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
>> ---
>>  scripts/dtc/.gitignore           |   4 +
>>  scripts/dtc/Makefile             |   5 ++
>>  scripts/dtc/fdtget.c             | 125 ++++++++++++++++++-------------
>>  scripts/dtc/update-dtc-source.sh |   4 +-
>
> Separate changes by updates to this script, running the script (to get
> fdtget.c), and updates to kernel files.

OK.

>>  4 files changed, 82 insertions(+), 56 deletions(-)
>>
>> diff --git scripts/dtc/.gitignore scripts/dtc/.gitignore
>> index 2e6e60d64ede..80f6b50fdf77 100644
>> --- scripts/dtc/.gitignore
>> +++ scripts/dtc/.gitignore
>> @@ -1 +1,5 @@
>>  dtc
>> +dtc-lexer.lex.c
>> +dtc-parser.tab.c
>> +dtc-parser.tab.h
>
> These are needed regardless. Probably a treewide rule for *.lex.c,
> *.tab.c, *.tab.h would be better.

Indeed, there are appropriate entris in the global .gitignore already.

>> +fdtget
>> diff --git scripts/dtc/Makefile scripts/dtc/Makefile
>> index b5a5b1c548c9..74322d8dac25 100644
>> --- scripts/dtc/Makefile
>> +++ scripts/dtc/Makefile
>> @@ -2,12 +2,15 @@
>>  # scripts/dtc makefile
>>
>>  hostprogs-$(CONFIG_DTC) := dtc
>> +hostprogs-$(CONFIG_DTC) += fdtget
>>  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
>>
>> +fdtget-objs     := fdtget.o util.o
>> +
>>  # Source files need to get at the userspace version of libfdt_env.h to compile
>>  HOST_EXTRACFLAGS := -I $(srctree)/$(src)/libfdt
>>
>> @@ -26,5 +29,7 @@ endif
>>  HOSTCFLAGS_dtc-lexer.lex.o := -I $(srctree)/$(src)
>>  HOSTCFLAGS_dtc-parser.tab.o := -I $(srctree)/$(src)
>>
>> +HOSTLDLIBS_fdtget := -L$(obj)/libfdt -lfdt -Wl,-rpath='$$ORIGIN/libfdt'
>> +
>
> We never build libfdt as a library, so how does this work unless it
> pulls in the distro copy?

It is my mistake. I haven't included my scrpits/dtc/libfdt/Makefile in
the patch. I lost it when I was rebasing the patchset.
diff mbox series

Patch

diff --git scripts/dtc/.gitignore scripts/dtc/.gitignore
index 2e6e60d64ede..80f6b50fdf77 100644
--- scripts/dtc/.gitignore
+++ scripts/dtc/.gitignore
@@ -1 +1,5 @@ 
 dtc
+dtc-lexer.lex.c
+dtc-parser.tab.c
+dtc-parser.tab.h
+fdtget
diff --git scripts/dtc/Makefile scripts/dtc/Makefile
index b5a5b1c548c9..74322d8dac25 100644
--- scripts/dtc/Makefile
+++ scripts/dtc/Makefile
@@ -2,12 +2,15 @@ 
 # scripts/dtc makefile
 
 hostprogs-$(CONFIG_DTC) := dtc
+hostprogs-$(CONFIG_DTC) += fdtget
 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
 
+fdtget-objs     := fdtget.o util.o
+
 # Source files need to get at the userspace version of libfdt_env.h to compile
 HOST_EXTRACFLAGS := -I $(srctree)/$(src)/libfdt
 
@@ -26,5 +29,7 @@  endif
 HOSTCFLAGS_dtc-lexer.lex.o := -I $(srctree)/$(src)
 HOSTCFLAGS_dtc-parser.tab.o := -I $(srctree)/$(src)
 
+HOSTLDLIBS_fdtget := -L$(obj)/libfdt -lfdt -Wl,-rpath='$$ORIGIN/libfdt'
+
 # dependencies on generated files need to be listed explicitly
 $(obj)/dtc-lexer.lex.o: $(obj)/dtc-parser.tab.h
diff --git scripts/dtc/fdtget.c scripts/dtc/fdtget.c
index c922f82246c6..777582e2d45f 100644
--- scripts/dtc/fdtget.c
+++ scripts/dtc/fdtget.c
@@ -39,6 +39,37 @@  static void report_error(const char *where, int err)
 	fprintf(stderr, "Error at '%s': %s\n", where, fdt_strerror(err));
 }
 
+/**
+ * Shows a list of cells in the requested format
+ *
+ * @param disp		Display information / options
+ * @param data		Data to display
+ * @param len		Maximum length of buffer
+ * @param size		Data size to use for display (e.g. 4 for 32-bit)
+ * @return 0 if ok, -1 on error
+ */
+static int show_cell_list(struct display_info *disp, const char *data, int len,
+			  int size)
+{
+	const uint8_t *p = (const uint8_t *)data;
+	char fmt[3];
+	int value;
+	int i;
+
+	fmt[0] = '%';
+	fmt[1] = disp->type ? disp->type : 'd';
+	fmt[2] = '\0';
+	for (i = 0; i < len; i += size, p += size) {
+		if (i)
+			printf(" ");
+		value = size == 4 ? fdt32_ld((const fdt32_t *)p) :
+			size == 2 ? (*p << 8) | p[1] : *p;
+		printf(fmt, value);
+	}
+
+	return 0;
+}
+
 /**
  * Displays data of a given length according to selected options
  *
@@ -52,12 +83,9 @@  static void report_error(const char *where, int err)
  */
 static int show_data(struct display_info *disp, const char *data, int len)
 {
-	int i, size;
-	const uint8_t *p = (const uint8_t *)data;
+	int size;
 	const char *s;
-	int value;
 	int is_string;
-	char fmt[3];
 
 	/* no data, don't print */
 	if (len == 0)
@@ -85,17 +113,8 @@  static int show_data(struct display_info *disp, const char *data, int len)
 				"selected data size\n");
 		return -1;
 	}
-	fmt[0] = '%';
-	fmt[1] = disp->type ? disp->type : 'd';
-	fmt[2] = '\0';
-	for (i = 0; i < len; i += size, p += size) {
-		if (i)
-			printf(" ");
-		value = size == 4 ? fdt32_to_cpu(*(const uint32_t *)p) :
-			size == 2 ? (*p << 8) | p[1] : *p;
-		printf(fmt, value);
-	}
-	return 0;
+
+	return show_cell_list(disp, data, len, size);
 }
 
 /**
@@ -107,7 +126,6 @@  static int show_data(struct display_info *disp, const char *data, int len)
  */
 static int list_properties(const void *blob, int node)
 {
-	const struct fdt_property *data;
 	const char *name;
 	int prop;
 
@@ -116,8 +134,7 @@  static int list_properties(const void *blob, int node)
 		/* Stop silently when there are no more properties */
 		if (prop < 0)
 			return prop == -FDT_ERR_NOTFOUND ? 0 : prop;
-		data = fdt_get_property_by_offset(blob, prop, NULL);
-		name = fdt_string(blob, fdt32_to_cpu(data->nameoff));
+		fdt_getprop_by_offset(blob, prop, &name, NULL);
 		if (name)
 			puts(name);
 		prop = fdt_next_property_offset(blob, prop);
@@ -231,7 +248,7 @@  static int show_data_for_item(const void *blob, struct display_info *disp,
  * @param filename	Filename of blob file
  * @param arg		List of arguments to process
  * @param arg_count	Number of arguments
- * @param return 0 if ok, -ve on error
+ * @return 0 if ok, -ve on error
  */
 static int do_fdtget(struct display_info *disp, const char *filename,
 		     char **arg, int arg_count, int args_per_step)
@@ -240,7 +257,7 @@  static int do_fdtget(struct display_info *disp, const char *filename,
 	const char *prop;
 	int i, node;
 
-	blob = utilfdt_read(filename);
+	blob = utilfdt_read(filename, NULL);
 	if (!blob)
 		return -1;
 
@@ -252,44 +269,50 @@  static int do_fdtget(struct display_info *disp, const char *filename,
 				continue;
 			} else {
 				report_error(arg[i], node);
+				free(blob);
 				return -1;
 			}
 		}
 		prop = args_per_step == 1 ? NULL : arg[i + 1];
 
-		if (show_data_for_item(blob, disp, node, prop))
+		if (show_data_for_item(blob, disp, node, prop)) {
+			free(blob);
 			return -1;
+		}
 	}
+
+	free(blob);
+
 	return 0;
 }
 
-static const char *usage_msg =
-	"fdtget - read values from device tree\n"
-	"\n"
-	"Each value is printed on a new line.\n\n"
-	"Usage:\n"
+/* Usage related data. */
+static const char usage_synopsis[] =
+	"read values from device tree\n"
 	"	fdtget <options> <dt file> [<node> <property>]...\n"
 	"	fdtget -p <options> <dt file> [<node> ]...\n"
-	"Options:\n"
-	"\t-t <type>\tType of data\n"
-	"\t-p\t\tList properties for each node\n"
-	"\t-l\t\tList subnodes for each node\n"
-	"\t-d\t\tDefault value to display when the property is "
-			"missing\n"
-	"\t-h\t\tPrint this help\n\n"
+	"\n"
+	"Each value is printed on a new line.\n"
 	USAGE_TYPE_MSG;
-
-static void usage(const char *msg)
-{
-	if (msg)
-		fprintf(stderr, "Error: %s\n\n", msg);
-
-	fprintf(stderr, "%s", usage_msg);
-	exit(2);
-}
+static const char usage_short_opts[] = "t:pld:" USAGE_COMMON_SHORT_OPTS;
+static struct option const usage_long_opts[] = {
+	{"type",              a_argument, NULL, 't'},
+	{"properties",       no_argument, NULL, 'p'},
+	{"list",             no_argument, NULL, 'l'},
+	{"default",           a_argument, NULL, 'd'},
+	USAGE_COMMON_LONG_OPTS,
+};
+static const char * const usage_opts_help[] = {
+	"Type of data",
+	"List properties for each node",
+	"List subnodes for each node",
+	"Default value to display when the property is missing",
+	USAGE_COMMON_OPTS_HELP
+};
 
 int main(int argc, char *argv[])
 {
+	int opt;
 	char *filename = NULL;
 	struct display_info disp;
 	int args_per_step = 2;
@@ -298,20 +321,14 @@  int main(int argc, char *argv[])
 	memset(&disp, '\0', sizeof(disp));
 	disp.size = -1;
 	disp.mode = MODE_SHOW_VALUE;
-	for (;;) {
-		int c = getopt(argc, argv, "d:hlpt:");
-		if (c == -1)
-			break;
-
-		switch (c) {
-		case 'h':
-		case '?':
-			usage(NULL);
+	while ((opt = util_getopt_long()) != EOF) {
+		switch (opt) {
+		case_USAGE_COMMON_FLAGS
 
 		case 't':
 			if (utilfdt_decode_type(optarg, &disp.type,
 					&disp.size))
-				usage("Invalid type string");
+				usage("invalid type string");
 			break;
 
 		case 'p':
@@ -333,7 +350,7 @@  int main(int argc, char *argv[])
 	if (optind < argc)
 		filename = argv[optind++];
 	if (!filename)
-		usage("Missing filename");
+		usage("missing filename");
 
 	argv += optind;
 	argc -= optind;
@@ -344,7 +361,7 @@  int main(int argc, char *argv[])
 
 	/* Check for node, property arguments */
 	if (args_per_step == 2 && (argc % 2))
-		usage("Must have an even number of arguments");
+		usage("must have an even number of arguments");
 
 	if (do_fdtget(&disp, filename, argv, argc, args_per_step))
 		return 1;
diff --git scripts/dtc/update-dtc-source.sh scripts/dtc/update-dtc-source.sh
index 7dd29a0362b8..8db277546785 100755
--- scripts/dtc/update-dtc-source.sh
+++ scripts/dtc/update-dtc-source.sh
@@ -31,8 +31,8 @@  set -ev
 DTC_UPSTREAM_PATH=`pwd`/../dtc
 DTC_LINUX_PATH=`pwd`/scripts/dtc
 
-DTC_SOURCE="checks.c data.c dtc.c dtc.h flattree.c fstree.c livetree.c srcpos.c \
-		srcpos.h treesource.c util.c util.h version_gen.h yamltree.c Makefile.dtc \
+DTC_SOURCE="checks.c data.c dtc.c dtc.h fdtget.c flattree.c fstree.c livetree.c
+		srcpos.c srcpos.h treesource.c util.c util.h version_gen.h Makefile.dtc \
 		dtc-lexer.l dtc-parser.y"
 LIBFDT_SOURCE="Makefile.libfdt fdt.c fdt.h fdt_addresses.c fdt_empty_tree.c \
 		fdt_overlay.c fdt_ro.c fdt_rw.c fdt_strerror.c fdt_sw.c \