* [RESEND PATCH v3 0/7] Add fdtget and fdtput for access to fdt from build system
@ 2011-09-19 20:21 Simon Glass
[not found] ` <1316463668-976-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
0 siblings, 1 reply; 14+ messages in thread
From: Simon Glass @ 2011-09-19 20:21 UTC (permalink / raw)
To: Devicetree Discuss
This patch set adds two new utilities:
fdtget for reading properties from a device tree binary file
fdtput for updating the device tree binary file
These are useful in scripts where configuration or other information must be
passed to the running system from the build system or vice versa. For
example, fdtget can be used to obtain the LCD screen width/height for use
with preparing custom bitmap images for display on the screen. Going the
other way, fdtput can be used to set configuration parameters known only to
the build or manufacturing test system, for example a hardware ID or the
particular type of boot EEPROM used on this PCB.
It is desirable to use these utilities rather than parsing or updating the
device tree source file, since this parsing is already implemented in dtc and
it makes no sense to reimplement it in a script. It also means that the build
system and the run-time environment see the same device tree values, so that
parsing or updating bugs do not creap in.
I believe that these utilities belong with dtc rather than libfdt since they
are more useful in the build system context rather than at run-time. At
run-time it is easier and better to use the provided library rather than
these utiltiies. But for build scripts and production automation, these
uitilites are better.
Some effort has been made to add tests and the parameter format has been
revised after previous feedback.
Changes in v2:
- Separate arguments for node and property
- Remove limits on data size of property writting to fdt
- Remove use of getopt_long()
- Adjust tests for new fdtput arguments
- Add test for multiple strings
- Add test for exhausting fdt space
- Merge two related commits into this one
- Use structure for storing display options
- Adjust tests for new fdtget arguments
- Remove util_decode_key
- Add utilfdt_decode_type to be used by fdtget/put
- Remove limits on device tree binary size
Changes in v3:
- Squash fdtput tests into fdtput commit
- Squash fdtget test commit into fdtget
- Add a few more tests for 1- and 2-byte formats
- Change format of -t argument to be more like printf
- Change help string and make part of it common
- Add error checking for the property not being a multiple of value size
- Make testutils.c use utilfdt for load/save blobs
- Add tests for utilfdt
- Move utilfdt into its own directory and make it a library
- Use code closer to testutils.c implementation
- Use open/close instead of fopen/fclose
- Use Makefile.utils instead of separate Makefiles
Simon Glass (7):
Create Makefile.utils and move ftdump into it
Add utilfdt for common functions
Add utilfdt tests
Make testutils use utilfdt
ftdump: use utilfdt to read blob
Add fdtget utility to read property values from a device tree
Add fdtput utility to write property values to a device tree
.gitignore | 2 +
Makefile | 43 ++++++++-
Makefile.ftdump | 13 ---
Makefile.utils | 24 +++++
fdtget.c | 227 ++++++++++++++++++++++++++++++++++++++++++++
fdtput.c | 236 ++++++++++++++++++++++++++++++++++++++++++++++
ftdump.c | 33 +------
tests/Makefile.tests | 9 +-
tests/fdtget-runtest.sh | 35 +++++++
tests/fdtput-runtest.sh | 55 +++++++++++
tests/run_tests.sh | 121 +++++++++++++++++++++++-
tests/tests.sh | 2 +
tests/testutils.c | 60 +++----------
tests/utilfdt_test.c | 128 +++++++++++++++++++++++++
utilfdt/Makefile.utilfdt | 9 ++
utilfdt/utilfdt.c | 167 ++++++++++++++++++++++++++++++++
utilfdt/utilfdt.h | 101 ++++++++++++++++++++
17 files changed, 1168 insertions(+), 97 deletions(-)
delete mode 100644 Makefile.ftdump
create mode 100644 Makefile.utils
create mode 100644 fdtget.c
create mode 100644 fdtput.c
create mode 100755 tests/fdtget-runtest.sh
create mode 100644 tests/fdtput-runtest.sh
create mode 100644 tests/utilfdt_test.c
create mode 100644 utilfdt/Makefile.utilfdt
create mode 100644 utilfdt/utilfdt.c
create mode 100644 utilfdt/utilfdt.h
--
1.7.3.1
^ permalink raw reply [flat|nested] 14+ messages in thread
* [RESEND PATCH v3 1/7] Create Makefile.utils and move ftdump into it
[not found] ` <1316463668-976-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
@ 2011-09-19 20:21 ` Simon Glass
[not found] ` <1316463668-976-2-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2011-09-19 20:21 ` [RESEND PATCH v3 2/7] Add utilfdt for common functions Simon Glass
` (5 subsequent siblings)
6 siblings, 1 reply; 14+ messages in thread
From: Simon Glass @ 2011-09-19 20:21 UTC (permalink / raw)
To: Devicetree Discuss
We want to avoid a separate Makefile include for each utility, so this sets
up a general one for utilities.
Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
---
Changes in v3:
- Use Makefile.utils instead of separate Makefiles
Makefile | 2 +-
Makefile.ftdump | 13 -------------
Makefile.utils | 10 ++++++++++
3 files changed, 11 insertions(+), 14 deletions(-)
delete mode 100644 Makefile.ftdump
create mode 100644 Makefile.utils
diff --git a/Makefile b/Makefile
index 2172d9a..380a705 100644
--- a/Makefile
+++ b/Makefile
@@ -105,7 +105,7 @@ endef
include Makefile.convert-dtsv0
include Makefile.dtc
-include Makefile.ftdump
+include Makefile.utils
BIN += convert-dtsv0
BIN += dtc
diff --git a/Makefile.ftdump b/Makefile.ftdump
deleted file mode 100644
index 2744a18..0000000
--- a/Makefile.ftdump
+++ /dev/null
@@ -1,13 +0,0 @@
-#
-# This is not a complete Makefile of itself.
-# Instead, it is designed to be easily embeddable
-# into other systems of Makefiles.
-#
-
-FTDUMP_SRCS = \
- ftdump.c \
- util.c
-
-FTDUMP_GEN_SRCS =
-
-FTDUMP_OBJS = $(FTDUMP_SRCS:%.c=%.o) $(FTDUMP_GEN_SRCS:%.c=%.o)
diff --git a/Makefile.utils b/Makefile.utils
new file mode 100644
index 0000000..0ed9297
--- /dev/null
+++ b/Makefile.utils
@@ -0,0 +1,10 @@
+#
+# This is not a complete Makefile of itself. Instead, it is designed to
+# be easily embeddable into other systems of Makefiles.
+#
+
+FTDUMP_SRCS = \
+ ftdump.c \
+ util.c
+
+FTDUMP_OBJS = $(FTDUMP_SRCS:%.c=%.o)
--
1.7.3.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [RESEND PATCH v3 2/7] Add utilfdt for common functions
[not found] ` <1316463668-976-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2011-09-19 20:21 ` [RESEND PATCH v3 1/7] Create Makefile.utils and move ftdump into it Simon Glass
@ 2011-09-19 20:21 ` Simon Glass
[not found] ` <1316463668-976-3-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2011-09-19 20:21 ` [RESEND PATCH v3 3/7] Add utilfdt tests Simon Glass
` (4 subsequent siblings)
6 siblings, 1 reply; 14+ messages in thread
From: Simon Glass @ 2011-09-19 20:21 UTC (permalink / raw)
To: Devicetree Discuss
This adds a new utility library for performing libfdt operations.
This is a separate library from libfdt because it performs OS operations,
like open/close/read/write, while libfdt is OS-neutral. These utility
functions are useful within the dtc package, and could potentially even
be generally useful, but should not be part of libfdt.
Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
---
Changes in v2:
- Remove util_decode_key
- Add utilfdt_decode_type to be used by fdtget/put
- Remove limits on device tree binary size
Changes in v3:
- Change format of -t argument to be more like printf
- Move utilfdt into its own directory and make it a library
- Use code closer to testutils.c implementation
- Use open/close instead of fopen/fclose
Makefile | 31 ++++++++-
utilfdt/Makefile.utilfdt | 9 +++
utilfdt/utilfdt.c | 167 ++++++++++++++++++++++++++++++++++++++++++++++
utilfdt/utilfdt.h | 91 +++++++++++++++++++++++++
4 files changed, 297 insertions(+), 1 deletions(-)
create mode 100644 utilfdt/Makefile.utilfdt
create mode 100644 utilfdt/utilfdt.c
create mode 100644 utilfdt/utilfdt.h
diff --git a/Makefile b/Makefile
index 380a705..4f5ccdd 100644
--- a/Makefile
+++ b/Makefile
@@ -15,7 +15,7 @@ EXTRAVERSION =
LOCAL_VERSION =
CONFIG_LOCALVERSION =
-CPPFLAGS = -I libfdt
+CPPFLAGS = -I libfdt -I utilfdt
WARNINGS = -Werror -Wall -Wpointer-arith -Wcast-qual -Wnested-externs \
-Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls
CFLAGS = -g -Os -fPIC -Werror $(WARNINGS)
@@ -151,6 +151,35 @@ ifneq ($(DEPTARGETS),)
-include $(LIBFDT_OBJS:%.o=$(LIBFDT_objdir)/%.d)
endif
+#
+# Rules for utilfdt
+#
+UTILFDT_objdir = utilfdt
+UTILFDT_srcdir = utilfdt
+UTILFDT_archive = $(UTILFDT_objdir)/libutilfdt.a
+UTILFDT_lib = $(UTILFDT_objdir)/libutilfdt-$(DTC_VERSION).$(SHAREDLIB_EXT)
+UTILFDT_include = $(addprefix $(UTILFDT_srcdir)/,$(UTILFDT_INCLUDES))
+
+include $(UTILFDT_srcdir)/Makefile.utilfdt
+
+.PHONY: utilfdt
+utilfdt: $(UTILFDT_archive) $(UTILFDT_lib)
+
+$(UTILFDT_archive): $(addprefix $(UTILFDT_objdir)/,$(UTILFDT_OBJS))
+$(UTILFDT_lib): $(addprefix $(UTILFDT_objdir)/,$(UTILFDT_OBJS))
+
+utilfdt_clean:
+ @$(VECHO) CLEAN "(utilfdt)"
+ rm -f $(addprefix $(UTILFDT_objdir)/,$(STD_CLEANFILES))
+ rm -f $(UTILFDT_objdir)/*.so
+
+ifneq ($(DEPTARGETS),)
+-include $(UTILFDT_OBJS:%.o=$(UTILFDT_objdir)/%.d)
+endif
+
+# Libraries we need to link our tools with
+ALL_LIBS = $(LIBFDT_archive) $(UTILFDT_archive)
+
# This stops make from generating the lex and bison output during
# auto-dependency computation, but throwing them away as an
# intermediate target and building them again "for real"
diff --git a/utilfdt/Makefile.utilfdt b/utilfdt/Makefile.utilfdt
new file mode 100644
index 0000000..e157ad8
--- /dev/null
+++ b/utilfdt/Makefile.utilfdt
@@ -0,0 +1,9 @@
+# Makefile.utilfdt
+#
+# This is not a complete Makefile of itself. Instead, it is designed to
+# be easily embeddable into other systems of Makefiles.
+#
+UTILFDT_soname = libutilfdt.$(SHAREDLIB_EXT).1
+UTILFDT_VERSION = version.lds
+UTILFDT_SRCS = utilfdt.c
+UTILFDT_OBJS = $(UTILFDT_SRCS:%.c=%.o)
diff --git a/utilfdt/utilfdt.c b/utilfdt/utilfdt.c
new file mode 100644
index 0000000..9870844
--- /dev/null
+++ b/utilfdt/utilfdt.c
@@ -0,0 +1,167 @@
+/*
+ * Copyright 2011 The Chromium Authors, All Rights Reserved.
+ * Copyright (C) 2006 David Gibson, IBM Corporation.
+ *
+ * Portions inspired by vsprintf.c -- Lars Wirzenius & Linus Torvalds.
+ *
+ * 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 <stdlib.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "libfdt.h"
+#include "utilfdt.h"
+
+int utilfdt_read_err(const char *filename, char **buffp)
+{
+ int fd = 0; /* assume stdin */
+ char *buf = NULL;
+ off_t bufsize = 1024, offset = 0;
+ int ret = 0;
+
+ *buffp = NULL;
+ if (strcmp(filename, "-") != 0) {
+ fd = open(filename, O_RDONLY);
+ if (fd < 0)
+ return errno;
+ }
+
+ /* Loop until we have read everything */
+ buf = malloc(bufsize);
+ do {
+ /* Expand the buffer to hold the next chunk */
+ if (offset == bufsize) {
+ bufsize *= 2;
+ buf = realloc(buf, bufsize);
+ if (!buf) {
+ ret = ENOMEM;
+ break;
+ }
+ }
+
+ ret = read(fd, &buf[offset], bufsize - offset);
+ if (ret < 0) {
+ ret = errno;
+ break;
+ }
+ offset += ret;
+ } while (ret != 0);
+
+ /* Clean up, including closing stdin; return errno on error */
+ close(fd);
+ if (ret)
+ free(buf);
+ else
+ *buffp = buf;
+ return ret;
+}
+
+char *utilfdt_read(const char *filename)
+{
+ char *buff;
+ int ret = utilfdt_read_err(filename, &buff);
+
+ if (ret) {
+ fprintf(stderr, "Couldn't open blob from '%s': %s\n", filename,
+ strerror(ret));
+ return NULL;
+ }
+ /* Successful read */
+ return buff;
+}
+
+int utilfdt_write_err(const char *filename, const void *blob)
+{
+ int fd = 1; /* assume stdout */
+ int totalsize;
+ int offset;
+ int ret = 0;
+ const char *ptr = blob;
+
+ if (strcmp(filename, "-") != 0) {
+ fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
+ if (fd < 0)
+ return errno;
+ }
+
+ totalsize = fdt_totalsize(blob);
+ offset = 0;
+
+ while (offset < totalsize) {
+ ret = write(fd, ptr + offset, totalsize - offset);
+ if (ret < 0) {
+ ret = -errno;
+ break;
+ }
+ offset += ret;
+ }
+ /* Close the file/stdin; return errno on error */
+ if (fd != 1)
+ close(fd);
+ return ret < 0 ? -ret : 0;
+}
+
+
+int utilfdt_write(const char *filename, const void *blob)
+{
+ int ret = utilfdt_write_err(filename, blob);
+
+ if (ret) {
+ fprintf(stderr, "Couldn't write blob to '%s': %s\n", filename,
+ strerror(ret));
+ }
+ return ret ? -1 : 0;
+}
+
+int utilfdt_decode_type(const char *fmt, int *type, int *size)
+{
+ int qualifier = 0;
+
+ /* get the conversion qualifier */
+ *size = -1;
+ if (strchr("hlLb", *fmt)) {
+ qualifier = *fmt++;
+ if (qualifier == *fmt) {
+ switch (*fmt++) {
+/* TODO: case 'l': qualifier = 'L'; break;*/
+ case 'h':
+ qualifier = 'b';
+ break;
+ }
+ }
+ }
+
+ /* we should now have a type */
+ if (!strchr("iuxs", *fmt))
+ return -1;
+
+ /* convert qualifier (bhL) to byte size */
+ if (*fmt != 's')
+ *size = qualifier == 'b' ? 1 :
+ qualifier == 'h' ? 2 :
+ qualifier == 'l' ? 4 : -1;
+ *type = *fmt++;
+
+ /* that should be it! */
+ if (*fmt)
+ return -1;
+ return 0;
+}
diff --git a/utilfdt/utilfdt.h b/utilfdt/utilfdt.h
new file mode 100644
index 0000000..fd6dc9d
--- /dev/null
+++ b/utilfdt/utilfdt.h
@@ -0,0 +1,91 @@
+#ifndef _UTILFDT_H
+#define _UTILFDT_H
+
+/*
+ * Copyright 2011 The Chromium Authors, All Rights Reserved.
+ *
+ * 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
+ */
+
+/**
+ * Read a device tree file into a buffer. This will report any errors on
+ * stderr.
+ *
+ * @param filename The filename to read, or - for stdin
+ * @return Pointer to allocated buffer containing fdt, or NULL on error
+ */
+char *utilfdt_read(const char *filename);
+
+/**
+ * Read a device tree file into a buffer. Does not report errors, but only
+ * returns them. The value returned can be passed to strerror() to obtain
+ * an error message for the user.
+ *
+ * @param filename The filename to read, or - for stdin
+ * @param buffp Returns pointer to buffer containing fdt
+ * @return 0 if ok, else an errno value representing the error
+ */
+int utilfdt_read_err(const char *filename, char **buffp);
+
+
+/**
+ * Write a device tree buffer to a file. This will report any errors on
+ * stderr.
+ *
+ * @param filename The filename to write, or - for stdout
+ * @param blob Poiner to buffer containing fdt
+ * @return 0 if ok, -1 on error
+ */
+int utilfdt_write(const char *filename, const void *blob);
+
+/**
+ * Write a device tree buffer to a file. Does not report errors, but only
+ * returns them. The value returned can be passed to strerror() to obtain
+ * an error message for the user.
+ *
+ * @param filename The filename to write, or - for stdout
+ * @param blob Poiner to buffer containing fdt
+ * @return 0 if ok, else an errno value representing the error
+ */
+int utilfdt_write_err(const char *filename, const void *blob);
+
+
+/**
+ * Decode a data type string. The purpose of this string
+ *
+ * The string consists of an optional character followed by the type:
+ * Modifier characters:
+ * hh or b 1 byte
+ * h 2 byte
+ * l 4 byte, default
+ *
+ * Type character:
+ * s string
+ * i signed integer
+ * u unsigned integer
+ * x hex
+ *
+ * TODO: Implement ll modifier (8 bytes)
+ * TODO: Implement o type (octal)
+ *
+ * @param fmt Format string to process
+ * @param type Returns type found(s/d/u/x), or 0 if none
+ * @param size Returns size found(1,2,4,8) or 4 if none
+ * @return 0 if ok, -1 on error (no type given, or other invalid format)
+ */
+int utilfdt_decode_type(const char *fmt, int *type, int *size);
+
+#endif /* _UTILFDT_H */
--
1.7.3.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [RESEND PATCH v3 3/7] Add utilfdt tests
[not found] ` <1316463668-976-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2011-09-19 20:21 ` [RESEND PATCH v3 1/7] Create Makefile.utils and move ftdump into it Simon Glass
2011-09-19 20:21 ` [RESEND PATCH v3 2/7] Add utilfdt for common functions Simon Glass
@ 2011-09-19 20:21 ` Simon Glass
[not found] ` <1316463668-976-4-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2011-09-19 20:21 ` [RESEND PATCH v3 4/7] Make testutils use utilfdt Simon Glass
` (3 subsequent siblings)
6 siblings, 1 reply; 14+ messages in thread
From: Simon Glass @ 2011-09-19 20:21 UTC (permalink / raw)
To: Devicetree Discuss
This adds a few tests for the simple type argument supported by
utilfdt_decode_type.
I assume this will be squashed in with utilfdt, but I have left it out
for easier review here.
Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
---
Changes in v3:
- Add tests for utilfdt
tests/Makefile.tests | 3 +-
tests/run_tests.sh | 9 +++-
tests/utilfdt_test.c | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 138 insertions(+), 2 deletions(-)
create mode 100644 tests/utilfdt_test.c
diff --git a/tests/Makefile.tests b/tests/Makefile.tests
index c564e72..2bc57d6 100644
--- a/tests/Makefile.tests
+++ b/tests/Makefile.tests
@@ -15,7 +15,8 @@ LIB_TESTS_L = get_mem_rsv \
extra-terminating-null \
dtbs_equal_ordered \
dtb_reverse dtbs_equal_unordered \
- add_subnode_with_nops path_offset_aliases
+ add_subnode_with_nops path_offset_aliases \
+ utilfdt_test
LIB_TESTS = $(LIB_TESTS_L:%=$(TESTS_PREFIX)%)
LIBTREE_TESTS_L = truncated_property
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index 72dda32..486ceae 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -388,6 +388,10 @@ dtbs_equal_tests () {
cmp_tests test_tree1.dtb $WRONG_TREE1
}
+utilfdt_tests () {
+ run_test utilfdt_test
+}
+
while getopts "vt:m" ARG ; do
case $ARG in
"v")
@@ -403,7 +407,7 @@ while getopts "vt:m" ARG ; do
done
if [ -z "$TESTSETS" ]; then
- TESTSETS="libfdt dtc dtbs_equal"
+ TESTSETS="libfdt utilfdt dtc dtbs_equal"
fi
# Make sure we don't have stale blobs lying around
@@ -414,6 +418,9 @@ for set in $TESTSETS; do
"libfdt")
libfdt_tests
;;
+ "utilfdt")
+ utilfdt_tests
+ ;;
"dtc")
dtc_tests
;;
diff --git a/tests/utilfdt_test.c b/tests/utilfdt_test.c
new file mode 100644
index 0000000..5c09e6f
--- /dev/null
+++ b/tests/utilfdt_test.c
@@ -0,0 +1,128 @@
+/*
+ * Copyright 2011 The Chromium Authors, All Rights Reserved.
+ *
+ * utilfdt_test - Tests for utilfdt library
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include <assert.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include <stdarg.h>
+
+#include <fdt.h>
+#include <libfdt.h>
+#include <utilfdt.h>
+
+#include "tests.h"
+#include "testdata.h"
+
+static void check(const char *fmt, int expect_type, int expect_size)
+{
+ int type;
+ int size;
+
+ if (utilfdt_decode_type(fmt, &type, &size))
+ FAIL("format '%s': valid format string returned failure", fmt);
+ if (expect_type != type)
+ FAIL("format '%s': expected type='%c', got type='%c'", fmt,
+ expect_type, type);
+ if (expect_size != size)
+ FAIL("format '%s': expected size=%d, got size=%d", fmt,
+ expect_size, size);
+}
+
+static void checkfail(const char *fmt)
+{
+ int type;
+ int size;
+
+ if (!utilfdt_decode_type(fmt, &type, &size))
+ FAIL("format '%s': invalid format string returned success",
+ fmt);
+}
+
+/**
+ * Add the given modifier to each of the valid sizes, and check that we get
+ * correct values.
+ *
+ * \param modifier Modifer string to use as a prefix
+ * \param expected_size The size (in bytes) that we expect (ignored for
+ * strings)
+ */
+static void check_sizes(char *modifier, int expected_size)
+{
+ char fmt[10], *ptr;
+
+ /* set up a string with a hole in it for the format character */
+ if (strlen(modifier) + 2 >= sizeof(fmt))
+ FAIL("modifier string '%s' too long", modifier);
+ strcpy(fmt, modifier);
+ ptr = fmt + strlen(fmt);
+ ptr[1] = '\0';
+
+ /* now try each format character in turn */
+ *ptr = 'i';
+ check(fmt, 'i', expected_size);
+
+ *ptr = 'u';
+ check(fmt, 'u', expected_size);
+
+ *ptr = 'x';
+ check(fmt, 'x', expected_size);
+
+ *ptr = 's';
+ check(fmt, 's', -1);
+}
+
+static void test_utilfdt_decode_type(void)
+{
+ char fmt[10];
+ int ch;
+
+ /* check all the valid modifiers and sizes */
+ check_sizes("", -1);
+ check_sizes("b", 1);
+ check_sizes("hh", 1);
+ check_sizes("h", 2);
+ check_sizes("l", 4);
+
+ /* try every other character */
+ checkfail("");
+ for (ch = ' '; ch < 127; ch++) {
+ if (!strchr("iuxs", ch)) {
+ *fmt = ch;
+ fmt[1] = '\0';
+ checkfail(fmt);
+ }
+ }
+
+ /* try a few modifiers at the end */
+ checkfail("sx");
+ checkfail("ihh");
+ checkfail("xb");
+
+ /* and one for the doomsday archives */
+ checkfail("He has all the virtues I dislike and none of the vices "
+ "I admire.");
+}
+
+int main(int argc, char *argv[])
+{
+ test_utilfdt_decode_type();
+ PASS();
+}
--
1.7.3.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [RESEND PATCH v3 4/7] Make testutils use utilfdt
[not found] ` <1316463668-976-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
` (2 preceding siblings ...)
2011-09-19 20:21 ` [RESEND PATCH v3 3/7] Add utilfdt tests Simon Glass
@ 2011-09-19 20:21 ` Simon Glass
2011-09-19 20:21 ` [RESEND PATCH v3 5/7] ftdump: use utilfdt to read blob Simon Glass
` (2 subsequent siblings)
6 siblings, 0 replies; 14+ messages in thread
From: Simon Glass @ 2011-09-19 20:21 UTC (permalink / raw)
To: Devicetree Discuss
The load_blob() and save_blob() functions are very similar to the utilfdt
versions. This removes the duplicated code.
Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
---
Changes in v3:
- Make testutils.c use utilfdt for load/save blobs
tests/Makefile.tests | 6 ++--
tests/testutils.c | 60 ++++++++++----------------------------------------
2 files changed, 15 insertions(+), 51 deletions(-)
diff --git a/tests/Makefile.tests b/tests/Makefile.tests
index 2bc57d6..315779c 100644
--- a/tests/Makefile.tests
+++ b/tests/Makefile.tests
@@ -42,13 +42,13 @@ TESTS_CLEANFILES = $(TESTS) $(TESTS_CLEANFILES_L:%=$(TESTS_PREFIX)%)
.PHONY: tests
tests: $(TESTS) $(TESTS_TREES)
-$(LIB_TESTS): %: $(TESTS_PREFIX)testutils.o $(LIBFDT_archive)
+$(LIB_TESTS): %: $(TESTS_PREFIX)testutils.o $(ALL_LIBS)
-$(DL_LIB_TESTS): %: %.o $(TESTS_PREFIX)testutils.o $(LIBFDT_archive)
+$(DL_LIB_TESTS): %: %.o $(TESTS_PREFIX)testutils.o $(ALL_LIBS)
@$(VECHO) LD [libdl] $@
$(LINK.c) -o $@ $^ -ldl
-$(LIBTREE_TESTS): %: $(TESTS_PREFIX)testutils.o $(TESTS_PREFIX)trees.o $(LIBFDT_archive)
+$(LIBTREE_TESTS): %: $(TESTS_PREFIX)testutils.o $(TESTS_PREFIX)trees.o $(ALL_LIBS)
$(TESTS_PREFIX)dumptrees: $(TESTS_PREFIX)trees.o
diff --git a/tests/testutils.c b/tests/testutils.c
index b0a2230..2d72244 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -31,6 +31,7 @@
#include <fcntl.h>
#include <libfdt.h>
+#include <utilfdt.h>
#include "tests.h"
@@ -159,33 +160,13 @@ int nodename_eq(const char *s1, const char *s2)
void *load_blob(const char *filename)
{
- int fd;
- int offset = 0;
- int bufsize = 1024;
- char *p = NULL;
- int ret;
-
- fd = open(filename, O_RDONLY);
- if (fd < 0)
- CONFIG("Couldn't open blob from \"%s\": %s", filename,
- strerror(errno));
-
- p = xmalloc(bufsize);
- do {
- if (offset == bufsize) {
- bufsize *= 2;
- p = xrealloc(p, bufsize);
- }
-
- ret = read(fd, &p[offset], bufsize - offset);
- if (ret < 0)
- CONFIG("Couldn't read from \"%s\": %s", filename,
- strerror(errno));
-
- offset += ret;
- } while (ret != 0);
+ char *blob;
+ int ret = utilfdt_read_err(filename, &blob);
- return p;
+ if (ret)
+ CONFIG("Couldn't open blob from \"%s\": %s", filename,
+ strerror(ret));
+ return blob;
}
void *load_blob_arg(int argc, char *argv[])
@@ -197,28 +178,11 @@ void *load_blob_arg(int argc, char *argv[])
void save_blob(const char *filename, void *fdt)
{
- int fd;
- int totalsize;
- int offset;
- char *p;
- int ret;
-
- fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
- if (fd < 0)
- CONFIG("Couldn't open \"%s\" to write blob: %s", filename,
- strerror(errno));
-
- totalsize = fdt_totalsize(fdt);
- offset = 0;
- p = fdt;
-
- while (offset < totalsize) {
- ret = write(fd, p + offset, totalsize - offset);
- if (ret < 0)
- CONFIG("Couldn't write to \"%s\": %s", filename,
- strerror(errno));
- offset += ret;
- }
+ int ret = utilfdt_write_err(filename, fdt);
+
+ if (ret)
+ CONFIG("Couldn't write blob to \"%s\": %s", filename,
+ strerror(ret));
}
void *open_blob_rw(void *blob)
--
1.7.3.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [RESEND PATCH v3 5/7] ftdump: use utilfdt to read blob
[not found] ` <1316463668-976-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
` (3 preceding siblings ...)
2011-09-19 20:21 ` [RESEND PATCH v3 4/7] Make testutils use utilfdt Simon Glass
@ 2011-09-19 20:21 ` Simon Glass
2011-09-19 20:21 ` [RESEND PATCH v3 6/7] Add fdtget utility to read property values from a device tree Simon Glass
2011-09-19 20:21 ` [RESEND PATCH v3 7/7] Add fdtput utility to write property values to " Simon Glass
6 siblings, 0 replies; 14+ messages in thread
From: Simon Glass @ 2011-09-19 20:21 UTC (permalink / raw)
To: Devicetree Discuss
Now that we have utilfdt_read(), ftdump should use it too.
Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
---
Makefile | 2 +-
ftdump.c | 33 +++++----------------------------
2 files changed, 6 insertions(+), 29 deletions(-)
diff --git a/Makefile b/Makefile
index 4f5ccdd..6238541 100644
--- a/Makefile
+++ b/Makefile
@@ -207,7 +207,7 @@ convert-dtsv0: $(CONVERT_OBJS)
@$(VECHO) LD $@
$(LINK.c) -o $@ $^
-ftdump: $(FTDUMP_OBJS)
+ftdump: $(FTDUMP_OBJS) $(ALL_LIBS)
#
diff --git a/ftdump.c b/ftdump.c
index db932e3..d1e3b08 100644
--- a/ftdump.c
+++ b/ftdump.c
@@ -12,8 +12,7 @@
#include <libfdt_env.h>
#include "util.h"
-
-#define FTDUMP_BUF_SIZE 65536
+#include "utilfdt.h"
#define ALIGN(x, a) (((x) + ((a) - 1)) & ~((a) - 1))
#define PALIGN(p, a) ((void *)(ALIGN((unsigned long)(p), (a))))
@@ -147,40 +146,18 @@ static void dump_blob(void *blob)
int main(int argc, char *argv[])
{
- FILE *fp;
char *buf;
- int size;
if (argc < 2) {
fprintf(stderr, "supply input filename\n");
return 5;
}
- if (strcmp(argv[1], "-") == 0) {
- fp = stdin;
- } else {
- fp = fopen(argv[1], "rb");
- if (fp == NULL) {
- fprintf(stderr, "unable to open %s\n", argv[1]);
- return 10;
- }
- }
-
- buf = malloc(FTDUMP_BUF_SIZE);
- if (!buf) {
- fprintf(stderr, "Couldn't allocate %d byte buffer\n", FTDUMP_BUF_SIZE);
+ buf = utilfdt_read(argv[1]);
+ if (buf)
+ dump_blob(buf);
+ else
return 10;
- }
-
- size = fread(buf, 1, FTDUMP_BUF_SIZE, fp);
- if (size == FTDUMP_BUF_SIZE) {
- fprintf(stderr, "file too large (maximum is %d bytes)\n", FTDUMP_BUF_SIZE);
- return 10;
- }
-
- dump_blob(buf);
-
- fclose(fp);
return 0;
}
--
1.7.3.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [RESEND PATCH v3 6/7] Add fdtget utility to read property values from a device tree
[not found] ` <1316463668-976-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
` (4 preceding siblings ...)
2011-09-19 20:21 ` [RESEND PATCH v3 5/7] ftdump: use utilfdt to read blob Simon Glass
@ 2011-09-19 20:21 ` Simon Glass
2011-09-19 20:21 ` [RESEND PATCH v3 7/7] Add fdtput utility to write property values to " Simon Glass
6 siblings, 0 replies; 14+ messages in thread
From: Simon Glass @ 2011-09-19 20:21 UTC (permalink / raw)
To: Devicetree Discuss
This simply utility makes it easy for scripts to read values from the device
tree. It is written in C and uses the same libfdt as the rest of the dtc
package.
What is it for:
- Reading fdt values from scripts
- Extracting fdt information within build systems
- Looking at particular values without having to dump the entire tree
To use it, specify the fdt binary file on command line followed by a list of
node, property pairs. The utility then looks up each node, finds the property
and displays the value.
Each value is printed on a new line.
fdtget tries to guess the type of each property based on its contents. This
is not always reliable, so you can use the -t option to force fdtget to decode
the value as a string, or byte, etc.
To read from stdin, use - as the file.
Usage:
fdtget <options> <dt file> [<node> <property>]...
Options:
-t <type> Type of data
-h Print this help
<type> s=string, i=int, u=unsigned, x=hex
Optional modifier prefix:
hh or b=byte, h=2 byte, l=4 byte (default)
Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
---
Changes in v2:
- Separate arguments for node and property
- Merge two related commits into this one
- Use structure for storing display options
- Remove use of getopt_long()
- Adjust tests for new fdtget arguments
Changes in v3:
- Squash fdtget test commit into fdtget
- Add a few more tests for 1- and 2-byte formats
- Change format of -t argument to be more like printf
- Change help string and make part of it common
- Add error checking for the property not being a multiple of value size
.gitignore | 1 +
Makefile | 3 +
Makefile.utils | 7 ++
fdtget.c | 227 +++++++++++++++++++++++++++++++++++++++++++++++
tests/fdtget-runtest.sh | 35 +++++++
tests/run_tests.sh | 43 +++++++++-
tests/tests.sh | 1 +
utilfdt/utilfdt.h | 10 ++
8 files changed, 326 insertions(+), 1 deletions(-)
create mode 100644 fdtget.c
create mode 100755 tests/fdtget-runtest.sh
diff --git a/.gitignore b/.gitignore
index ae7a46a..9f27f34 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,3 +10,4 @@ lex.yy.c
/ftdump
/convert-dtsv0
/version_gen.h
+/fdtget
diff --git a/Makefile b/Makefile
index 6238541..2fadb10 100644
--- a/Makefile
+++ b/Makefile
@@ -110,6 +110,7 @@ include Makefile.utils
BIN += convert-dtsv0
BIN += dtc
BIN += ftdump
+BIN += fdtget
SCRIPTS = dtdiff
@@ -120,6 +121,7 @@ ifneq ($(DEPTARGETS),)
-include $(DTC_OBJS:%.o=%.d)
-include $(CONVERT_OBJS:%.o=%.d)
-include $(FTDUMP_OBJS:%.o=%.d)
+-include $(FDTGET_OBJS:%.o=%.d)
endif
@@ -209,6 +211,7 @@ convert-dtsv0: $(CONVERT_OBJS)
ftdump: $(FTDUMP_OBJS) $(ALL_LIBS)
+fdtget: $(FDTGET_OBJS) $(ALL_LIBS)
#
# Testsuite rules
diff --git a/Makefile.utils b/Makefile.utils
index 0ed9297..095cacd 100644
--- a/Makefile.utils
+++ b/Makefile.utils
@@ -8,3 +8,10 @@ FTDUMP_SRCS = \
util.c
FTDUMP_OBJS = $(FTDUMP_SRCS:%.c=%.o)
+
+
+FDTGET_SRCS = \
+ fdtget.c \
+ util.c
+
+FDTGET_OBJS = $(FDTGET_SRCS:%.c=%.o)
diff --git a/fdtget.c b/fdtget.c
new file mode 100644
index 0000000..5389529
--- /dev/null
+++ b/fdtget.c
@@ -0,0 +1,227 @@
+/*
+ * Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+ *
+ * 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 <ctype.h>
+#include <getopt.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <libfdt.h>
+
+#include "util.h"
+#include "utilfdt.h"
+
+/* Holds information which controls our output and options */
+struct display_info {
+ int type; /* data type (s/i/u/x or 0 for default) */
+ int size; /* data size (1/2/4) */
+};
+
+static void report_error(const char *where, int err)
+{
+ fprintf(stderr, "Error at '%s': %s\n", where, fdt_strerror(err));
+}
+
+/**
+ * Displays data of a given length according to selected options
+ *
+ * If a specific data type is provided in disp, then this is used. Otherwise
+ * we try to guess the data type / size from the contents.
+ *
+ * @param disp Display information / options
+ * @param data Data to display
+ * @param len Maximum length of buffer
+ * @return 0 if ok, -1 if data does not match format
+ */
+static int show_data(struct display_info *disp, const char *data, int len)
+{
+ int i, size;
+ const uint8_t *p = (const uint8_t *)data;
+ const char *s;
+ int value;
+ int is_string;
+ char fmt[3];
+
+ /* no data, don't print */
+ if (len == 0)
+ return 0;
+
+ is_string = (disp->type) == 's' ||
+ (!disp->type && util_is_printable_string(data, len));
+ if (is_string) {
+ if (data[len - 1] != '\0') {
+ fprintf(stderr, "Unterminated string\n");
+ return -1;
+ }
+ for (s = data; s - data < len; s += strlen(s) + 1) {
+ if (s != data)
+ printf(" ");
+ printf("%s", (const char *)s);
+ }
+ return 0;
+ }
+ size = disp->size;
+ if (size == -1)
+ size = (len % 4) == 0 ? 4 : 1;
+ else if (len % size) {
+ fprintf(stderr, "Property length must be a multiple of "
+ "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;
+}
+
+/**
+ * Show the data for a given node (and perhaps property) according to the
+ * display option provided.
+ *
+ * @param blob FDT blob
+ * @param disp Display information / options
+ * @param node Node to display
+ * @param property Name of property to display, or NULL if none
+ * @return 0 if ok, -ve on error
+ */
+static int show_data_for_item(const void *blob, struct display_info *disp,
+ int node, const char *property)
+{
+ const void *value = NULL;
+ int len, err = 0;
+
+ value = fdt_getprop(blob, node, property, &len);
+ if (value) {
+ if (show_data(disp, value, len))
+ err = -1;
+ else
+ printf("\n");
+ } else {
+ report_error(property, len);
+ err = -1;
+ }
+ return err;
+}
+
+/**
+ * Run the main fdtget operation, given a filename and valid arguments
+ *
+ * @param disp Display information / options
+ * @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
+ */
+static int do_fdtget(struct display_info *disp, const char *filename,
+ char **arg, int arg_count)
+{
+ char *blob;
+ int i, node;
+
+ blob = utilfdt_read(filename);
+ if (!blob)
+ return -1;
+
+ for (i = 0; i + 2 <= arg_count; i += 2) {
+ node = fdt_path_offset(blob, arg[0]);
+ if (node < 0) {
+ report_error(arg[0], node);
+ return -1;
+ }
+
+ if (show_data_for_item(blob, disp, node, arg[1]))
+ return -1;
+ }
+ 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"
+ " fdtget <options> <dt file> [<node> <property>]...\n"
+ "Options:\n"
+ "\t-t <type>\tType of data\n"
+ "\t-h\t\tPrint this help\n\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);
+}
+
+int main(int argc, char *argv[])
+{
+ char *filename = NULL;
+ struct display_info disp;
+
+ /* set defaults */
+ memset(&disp, '\0', sizeof(disp));
+ disp.size = -1;
+ for (;;) {
+ int c = getopt(argc, argv, "ht:");
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 'h':
+ case '?':
+ usage(NULL);
+
+ case 't':
+ if (utilfdt_decode_type(optarg, &disp.type,
+ &disp.size))
+ usage("Invalid type string");
+ break;
+ }
+ }
+
+ if (optind < argc)
+ filename = argv[optind++];
+ if (!filename)
+ usage("Missing filename");
+
+ argv += optind;
+ argc -= optind;
+
+ /* Allow no arguments, and silently succeed */
+ if (!argc)
+ return 0;
+
+ /* Check for node, property arguments */
+ if (argc % 2)
+ usage("Must have an even number of arguments");
+
+ if (do_fdtget(&disp, filename, argv, argc))
+ return 1;
+ return 0;
+}
diff --git a/tests/fdtget-runtest.sh b/tests/fdtget-runtest.sh
new file mode 100755
index 0000000..f38184f
--- /dev/null
+++ b/tests/fdtget-runtest.sh
@@ -0,0 +1,35 @@
+#! /bin/sh
+
+. ./tests.sh
+
+LOG="tmp.log.$$"
+EXPECT="tmp.expect.$$"
+
+rm -f $TMPFILE $LOG
+
+expect="$1"
+echo "$expect" >$EXPECT
+shift
+
+verbose_run_log "$LOG" $VALGRIND "$DTGET" "$@"
+ret="$?"
+
+if [ "$ret" -ne 0 -a "$expect" = "ERR" ]; then
+ PASS
+fi
+
+if [ "$ret" -gt 127 ]; then
+ signame=$(kill -l $[ret - 128])
+ FAIL "Killed by SIG$signame"
+fi
+
+diff $EXPECT $LOG
+ret="$?"
+
+rm -f $LOG $EXPECT
+
+if [ "$ret" -eq 0 ]; then
+ PASS
+else
+ FAIL
+fi
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index 486ceae..e63c5c7 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -83,6 +83,13 @@ asm_to_so_test () {
run_wrap_test asm_to_so "$@"
}
+run_fdtget_test () {
+ # run_fdtget_test name expected_output dtb_file args...
+ echo -n "$1: "
+ shift
+ base_run_test sh fdtget-runtest.sh "$@"
+}
+
tree1_tests () {
TREE=$1
@@ -388,6 +395,37 @@ dtbs_equal_tests () {
cmp_tests test_tree1.dtb $WRONG_TREE1
}
+fdtget_tests () {
+ file=label01.dtb
+ $DTC -O dtb -o $file ${file%.dtb}.dts 2>/dev/null
+
+ # run_fdtget_test <test-name> <expected-result> <args>...
+ run_fdtget_test "Simple string" "MyBoardName" $file / model
+ run_fdtget_test "Multiple string i" "77 121 66 111 \
+97 114 100 78 97 109 101 0 77 121 66 111 97 114 100 70 97 109 105 \
+108 121 78 97 109 101 0" $file / compatible
+ run_fdtget_test "Multiple string s" "MyBoardName MyBoardFamilyName" \
+ -t s $file / compatible
+ run_fdtget_test "Integer" "32768" $file /cpus/PowerPC,970@1 d-cache-size
+ run_fdtget_test "Integer hex" "8000" -tx $file \
+ /cpus/PowerPC,970@1 d-cache-size
+ run_fdtget_test "Integer list" "61 62 63 0" -tbx $file \
+ /randomnode tricky1
+ run_fdtget_test "Byte list short" "a b c d de ea ad be ef" -tbx \
+ $file /randomnode blob
+
+ # Here the property size is not a multiple of 4 bytes, so it should fail
+ run_fdtget_test "Integer list invalid" ERR -tlx \
+ $file /randomnode mixed
+ run_fdtget_test "Integer list halfword" "6162 6300 1234 0 a 0 b 0 c" -thx \
+ $file /randomnode mixed
+ run_fdtget_test "Integer list byte" \
+ "61 62 63 0 12 34 0 0 0 a 0 0 0 b 0 0 0 c" -thhx \
+ $file /randomnode mixed
+ run_fdtget_test "Missing property" ERR -ts \
+ $file /randomnode doctor-who
+}
+
utilfdt_tests () {
run_test utilfdt_test
}
@@ -407,7 +445,7 @@ while getopts "vt:m" ARG ; do
done
if [ -z "$TESTSETS" ]; then
- TESTSETS="libfdt utilfdt dtc dtbs_equal"
+ TESTSETS="libfdt utilfdt dtc dtbs_equal fdtget"
fi
# Make sure we don't have stale blobs lying around
@@ -427,6 +465,9 @@ for set in $TESTSETS; do
"dtbs_equal")
dtbs_equal_tests
;;
+ "fdtget")
+ fdtget_tests
+ ;;
esac
done
diff --git a/tests/tests.sh b/tests/tests.sh
index 30ffead..d9a0524 100644
--- a/tests/tests.sh
+++ b/tests/tests.sh
@@ -11,6 +11,7 @@ FAIL () {
}
DTC=../dtc
+DTGET=../fdtget
verbose_run () {
if [ -z "$QUIET_TEST" ]; then
diff --git a/utilfdt/utilfdt.h b/utilfdt/utilfdt.h
index fd6dc9d..2606179 100644
--- a/utilfdt/utilfdt.h
+++ b/utilfdt/utilfdt.h
@@ -88,4 +88,14 @@ int utilfdt_write_err(const char *filename, const void *blob);
*/
int utilfdt_decode_type(const char *fmt, int *type, int *size);
+/*
+ * This is a usage message fragment for the -t option. It is the format
+ * supported by utilfdt_decode_type.
+ */
+
+#define USAGE_TYPE_MSG \
+ "<type>\ts=string, i=int, u=unsigned, x=hex\n" \
+ "\tOptional modifier prefix:\n" \
+ "\t\thh or b=byte, h=2 byte, l=4 byte (default)\n";
+
#endif /* _UTILFDT_H */
--
1.7.3.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [RESEND PATCH v3 7/7] Add fdtput utility to write property values to a device tree
[not found] ` <1316463668-976-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
` (5 preceding siblings ...)
2011-09-19 20:21 ` [RESEND PATCH v3 6/7] Add fdtget utility to read property values from a device tree Simon Glass
@ 2011-09-19 20:21 ` Simon Glass
6 siblings, 0 replies; 14+ messages in thread
From: Simon Glass @ 2011-09-19 20:21 UTC (permalink / raw)
To: Devicetree Discuss
This simple utility allows writing of values into a device tree from the
command line. It aimes to be the opposite of fdtget.
What is it for:
- Updating fdt values when a binary blob already exists
(even though source may be available it might be easier to use this
utility rather than sed, etc.)
- Writing machine-specific fdt values within a build system
To use it, specify the fdt binary file on command line followed by the node
and property to set. Then, provide a list of values to put into that
property. Often there will be just one, but fdtput also supports arrays and
string lists.
fdtput does not try to guess the type of the property based on looking at
the arguments. Instead it always assumes that an integer is provided. To
indicate that you want to write a string, use -ts. You can also provide
hex values with -tx.
The command line arguments are joined together into a single value. For
strings, a nul terminator is placed between each string when it is packed
into the property. To avoid this, pass the string as a single argument.
Usage:
fdtput <options> <dt file> <<node> <property> [<value>...]
Options:
-t <type> Type of data
-v Verbose: display each value decoded from command line
-h Print this help
<type> s=string, i=int, u=unsigned, x=hex
Optional modifier prefix:
hh or b=byte, h=2 byte, l=4 byte (default)
To read from stdin and write to stdout, use - as the file. So you can do:
cat somefile.dtb | fdtput -ts - /node prop "My string value" > newfile.dtb
This commit also adds basic tests to verify the major features.
Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
---
Changes in v2:
- Separate arguments for node and property
- Remove limits on data size of property writting to fdt
- Remove use of getopt_long()
- Adjust tests for new fdtput arguments
- Add test for multiple strings
- Add test for exhausting fdt space
Changes in v3:
- Squash fdtput tests into fdtput commit
.gitignore | 1 +
Makefile | 5 +
Makefile.utils | 7 ++
fdtput.c | 236 +++++++++++++++++++++++++++++++++++++++++++++++
tests/fdtput-runtest.sh | 55 +++++++++++
tests/run_tests.sh | 73 ++++++++++++++-
tests/tests.sh | 1 +
7 files changed, 377 insertions(+), 1 deletions(-)
create mode 100644 fdtput.c
create mode 100644 tests/fdtput-runtest.sh
diff --git a/.gitignore b/.gitignore
index 9f27f34..2c9a64e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,3 +11,4 @@ lex.yy.c
/convert-dtsv0
/version_gen.h
/fdtget
+/fdtput
diff --git a/Makefile b/Makefile
index 2fadb10..85ac04c 100644
--- a/Makefile
+++ b/Makefile
@@ -111,6 +111,7 @@ BIN += convert-dtsv0
BIN += dtc
BIN += ftdump
BIN += fdtget
+BIN += fdtput
SCRIPTS = dtdiff
@@ -122,6 +123,7 @@ ifneq ($(DEPTARGETS),)
-include $(CONVERT_OBJS:%.o=%.d)
-include $(FTDUMP_OBJS:%.o=%.d)
-include $(FDTGET_OBJS:%.o=%.d)
+-include $(FDTPUT_OBJS:%.o=%.d)
endif
@@ -213,6 +215,9 @@ ftdump: $(FTDUMP_OBJS) $(ALL_LIBS)
fdtget: $(FDTGET_OBJS) $(ALL_LIBS)
+fdtput: $(FDTPUT_OBJS) $(ALL_LIBS)
+
+
#
# Testsuite rules
#
diff --git a/Makefile.utils b/Makefile.utils
index 095cacd..df1d6fc 100644
--- a/Makefile.utils
+++ b/Makefile.utils
@@ -15,3 +15,10 @@ FDTGET_SRCS = \
util.c
FDTGET_OBJS = $(FDTGET_SRCS:%.c=%.o)
+
+
+FDTPUT_SRCS = \
+ fdtput.c \
+ util.c
+
+FDTPUT_OBJS = $(FDTPUT_SRCS:%.c=%.o)
diff --git a/fdtput.c b/fdtput.c
new file mode 100644
index 0000000..64ccd02
--- /dev/null
+++ b/fdtput.c
@@ -0,0 +1,236 @@
+/*
+ * Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+ *
+ * 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 <assert.h>
+#include <ctype.h>
+#include <getopt.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <libfdt.h>
+
+#include "util.h"
+#include "utilfdt.h"
+
+struct display_info {
+ int type; /* data type (s/i/u/x or 0 for default) */
+ int size; /* data size (1/2/4) */
+ int verbose; /* verbose output */
+};
+
+static void report_error(const char *where, int err)
+{
+ fprintf(stderr, "Error at '%s': %s\n", where, fdt_strerror(err));
+}
+
+/**
+ * Encode a series of arguments in a property value.
+ *
+ * @param disp Display information / options
+ * @param arg List of arguments from command line
+ * @param arg_count Number of arguments (may be 0)
+ * @param valuep Returns buffer containing value
+ * @param *value_len Returns length of value encoded
+ */
+static int encode_value(struct display_info *disp, char **arg, int arg_count,
+ char **valuep, int *value_len)
+{
+ char *value = NULL; /* holding area for value */
+ int value_size = 0; /* size of holding area */
+ char *ptr; /* pointer to current value position */
+ int len; /* length of this cell/string/byte */
+ int ival;
+ int upto; /* the number of bytes we have written to buf */
+ char fmt[3];
+
+ upto = 0;
+
+ if (disp->verbose)
+ fprintf(stderr, "Decoding value:\n");
+
+ fmt[0] = '%';
+ fmt[1] = disp->type ? disp->type : 'd';
+ fmt[2] = '\0';
+ for (; arg_count > 0; arg++, arg_count--, upto += len) {
+ /* assume integer unless told otherwise */
+ if (disp->type == 's')
+ len = strlen(*arg) + 1;
+ else
+ len = disp->size == -1 ? 4 : disp->size;
+
+ /* enlarge our value buffer by a suitable margin if needed */
+ if (upto + len > value_size) {
+ value_size = (upto + len) + 500;
+ value = realloc(value, value_size);
+ if (!value) {
+ fprintf(stderr, "Out of mmory: cannot alloc "
+ "%d bytes\n", value_size);
+ return -1;
+ }
+ }
+
+ ptr = value + upto;
+ if (disp->type == 's') {
+ memcpy(ptr, *arg, len);
+ if (disp->verbose)
+ fprintf(stderr, "\tstring: '%s'\n", ptr);
+ } else {
+ int *iptr = (int *)ptr;
+ sscanf(*arg, fmt, &ival);
+ if (len == 4)
+ *iptr = cpu_to_fdt32(ival);
+ else
+ *ptr = (uint8_t)ival;
+ if (disp->verbose) {
+ fprintf(stderr, "\t%s: %d\n",
+ disp->size == 1 ? "byte" :
+ disp->size == 2 ? "short" : "int",
+ ival);
+ }
+ }
+ }
+ *value_len = upto;
+ *valuep = value;
+ if (disp->verbose)
+ fprintf(stderr, "Value size %d\n", upto);
+ return 0;
+}
+
+static int store_key_value(void *blob, const char *node_name,
+ const char *property, const char *buf, int len)
+{
+ int node;
+ int err;
+
+ node = fdt_path_offset(blob, node_name);
+ if (node < 0) {
+ report_error(node_name, node);
+ return -1;
+ }
+
+ err = fdt_setprop(blob, node, property, buf, len);
+ if (err) {
+ report_error(property, err);
+ return -1;
+ }
+ return 0;
+}
+
+static int do_fdtput(struct display_info *disp, const char *filename,
+ char **arg, int arg_count)
+{
+ char *value;
+ char *blob;
+ int len, ret = 0;
+
+ blob = utilfdt_read(filename);
+ if (!blob)
+ return -1;
+
+ /* convert the arguments into a single binary value, then store */
+ assert(arg_count >= 2);
+ if (encode_value(disp, arg + 2, arg_count - 2, &value, &len) ||
+ store_key_value(blob, *arg, arg[1], value, len))
+ ret = -1;
+
+ if (!ret)
+ ret = utilfdt_write(filename, blob);
+
+ free(blob);
+ return ret;
+}
+
+static const char *usage_msg =
+ "fdtput - write a property value to a device tree\n"
+ "\n"
+ "The command line arguments are joined together into a single value.\n"
+ "\n"
+ "Usage:\n"
+ " fdtput <options> <dt file> <<node> <property> [<value>...]\n"
+ "Options:\n"
+ "\t-t <type>\tType of data\n"
+ "\t-v\t\tVerbose: display each value decoded from command line\n"
+ "\t-h\t\tPrint this help\n\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);
+}
+
+int main(int argc, char *argv[])
+{
+ struct display_info disp;
+ char *filename = NULL;
+
+ memset(&disp, '\0', sizeof(disp));
+ disp.size = -1;
+ for (;;) {
+ int c = getopt(argc, argv, "ht:v");
+ if (c == -1)
+ break;
+
+ /*
+ * TODO: add options to:
+ * - delete property
+ * - delete node (optionally recursively)
+ * - rename node
+ * - pack fdt before writing
+ * - set amount of free space when writing
+ * - expand fdt if value doesn't fit
+ */
+ switch (c) {
+ case 'h':
+ case '?':
+ usage(NULL);
+
+ case 't':
+ if (utilfdt_decode_type(optarg, &disp.type,
+ &disp.size))
+ usage("Invalid type string");
+ break;
+
+ case 'v':
+ disp.verbose = 1;
+ break;
+ }
+ }
+
+ if (optind < argc)
+ filename = argv[optind++];
+ if (!filename)
+ usage("Missing filename");
+
+ argv += optind;
+ argc -= optind;
+
+ if (argc < 1)
+ usage("Missing node");
+ if (argc < 2)
+ usage("Missing property");
+
+ if (do_fdtput(&disp, filename, argv, argc))
+ return 1;
+ return 0;
+}
diff --git a/tests/fdtput-runtest.sh b/tests/fdtput-runtest.sh
new file mode 100644
index 0000000..ea51569
--- /dev/null
+++ b/tests/fdtput-runtest.sh
@@ -0,0 +1,55 @@
+#! /bin/sh
+
+# Run script for fdtput tests
+# We run fdtput to update the device tree, thn fdtget to check it
+
+# Usage
+# fdtput-runtest.sh name expected_output dtb_file node property flags value
+
+. ./tests.sh
+
+LOG="tmp.log.$$"
+EXPECT="tmp.expect.$$"
+
+rm -f $TMPFILE $LOG
+
+expect="$1"
+echo "$expect" >$EXPECT
+dtb="$2"
+node="$3"
+property="$4"
+flags="$5"
+shift 5
+value="$@"
+
+# First run fdtput
+verbose_run $VALGRIND "$DTPUT" "$dtb" "$node" "$property" $value $flags
+ret="$?"
+
+if [ "$ret" -ne 0 -a "$expect" = "ERR" ]; then
+ PASS
+fi
+if [ "$ret" -gt 127 ]; then
+ signame=$(kill -l $[ret - 128])
+ FAIL "Killed by SIG$signame"
+fi
+
+# Now fdtget to read the value
+verbose_run_log "$LOG" $VALGRIND "$DTGET" "$dtb" "$node" "$property" $flags
+ret="$?"
+
+if [ "$ret" -gt 127 ]; then
+ signame=$(kill -l $[ret - 128])
+ FAIL "Killed by SIG$signame"
+fi
+
+diff $EXPECT $LOG
+ret="$?"
+
+rm -f $LOG $EXPECT
+
+if [ "$ret" -eq 0 ]; then
+ PASS
+else
+ FAIL
+fi
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index e63c5c7..05970e8 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -90,6 +90,21 @@ run_fdtget_test () {
base_run_test sh fdtget-runtest.sh "$@"
}
+run_fdtput_test () {
+ # run_fdtput_test name expected_output dtb_file node property flags value...
+ echo -n "$1: "
+ shift
+ output="$1"
+ dtb="$2"
+ node="$3"
+ property="$4"
+ flags="$5"
+ shift 5
+ base_run_test sh fdtput-runtest.sh "$output" "$dtb" "$node" "$property" \
+ "$flags" $@
+# base_run_test sh fdtput-runtest.sh "$@"
+}
+
tree1_tests () {
TREE=$1
@@ -426,6 +441,59 @@ fdtget_tests () {
$file /randomnode doctor-who
}
+fdtput_tests () {
+ file=label01.dtb
+ src=label01.dts
+
+ # Create some test files containing useful strings
+ base=tmp.test0
+ file1=tmp.test1
+ file2=tmp.test2
+ bigfile1=tmp.test3
+ bigfile2=tmp.test4
+
+ # Filter out anything the shell might not like
+ cat $src | tr -d "'\"\n\;/\.\*{}\-" | tr -s "[:blank:]" " " >$base
+
+ # Make two small files
+ head -5 $base >$file1
+ cat $file1 | tr a-z A-Z | cut -c10-30 | sort -r >$file2
+
+ # and two larger ones
+ cat $base > $bigfile1
+ tac $base | tr a-z A-Z | sort -r >$bigfile2
+
+ # Allow just enough space for both file1 and file2
+ (( space = $(stat -c %s $file1) + $(stat -c %s $file2) ))
+ $DTC -O dtb -p $space -o $file ${file%.dtb}.dts 2>/dev/null
+
+ # run_fdtput_test <test-name> <expected-result> <file> <key> <flags>
+ # <args>...
+ run_fdtput_test "Simple string" "a_model" $file / model -ts "a_model"
+ run_fdtput_test "Multiple string s" "board1 board2" \
+ $file / compatible -ts board1 board2
+ run_fdtput_test "Single string with spaces" "board1 board2" \
+ $file / compatible -ts "board1 board2"
+ run_fdtput_test "Integer" "32768" \
+ $file /cpus/PowerPC,970@1 d-cache-size "" "32768"
+ run_fdtput_test "Integer hex" "8001" \
+ $file /cpus/PowerPC,970@1 d-cache-size -tx 0x8001
+ run_fdtput_test "Integer list" "2 3 12" \
+ $file /randomnode tricky1 -tbi "02 003 12"
+ run_fdtput_test "Byte list short" "a b c ea ad be ef" \
+ $file /randomnode blob -tbx "a b c ea ad be ef"
+ run_fdtput_test "Integer list short" "a0b0c0d deeaae ef000000" \
+ $file /randomnode blob -tx "a0b0c0d deeaae ef000000"
+ run_fdtput_test "Large string list" "`cat $file1 $file2`" \
+ $file /randomnode blob -ts "`cat $file1`" "`cat $file2`"
+
+ # This should be larger than available space in the fdt ($space)
+ run_fdtput_test "Enormous string list" ERR \
+ $file /randomnode blob -ts "`cat $bigfile1`" "`cat $bigfile2`"
+
+ # TODO: Add tests for verbose mode?
+}
+
utilfdt_tests () {
run_test utilfdt_test
}
@@ -445,7 +513,7 @@ while getopts "vt:m" ARG ; do
done
if [ -z "$TESTSETS" ]; then
- TESTSETS="libfdt utilfdt dtc dtbs_equal fdtget"
+ TESTSETS="libfdt utilfdt dtc dtbs_equal fdtget fdtput"
fi
# Make sure we don't have stale blobs lying around
@@ -468,6 +536,9 @@ for set in $TESTSETS; do
"fdtget")
fdtget_tests
;;
+ "fdtput")
+ fdtput_tests
+ ;;
esac
done
diff --git a/tests/tests.sh b/tests/tests.sh
index d9a0524..6e5e76a 100644
--- a/tests/tests.sh
+++ b/tests/tests.sh
@@ -12,6 +12,7 @@ FAIL () {
DTC=../dtc
DTGET=../fdtget
+DTPUT=../fdtput
verbose_run () {
if [ -z "$QUIET_TEST" ]; then
--
1.7.3.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [RESEND PATCH v3 1/7] Create Makefile.utils and move ftdump into it
[not found] ` <1316463668-976-2-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
@ 2011-09-20 1:02 ` David Gibson
0 siblings, 0 replies; 14+ messages in thread
From: David Gibson @ 2011-09-20 1:02 UTC (permalink / raw)
To: Simon Glass; +Cc: Devicetree Discuss
On Mon, Sep 19, 2011 at 01:21:02PM -0700, Simon Glass wrote:
> We want to avoid a separate Makefile include for each utility, so this sets
> up a general one for utilities.
>
> Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
Acked-by: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [RESEND PATCH v3 2/7] Add utilfdt for common functions
[not found] ` <1316463668-976-3-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
@ 2011-09-20 1:08 ` David Gibson
[not found] ` <20110920010859.GE29197-787xzQ0H9iQXU02nzanrWNbf9cGiqdzd@public.gmane.org>
0 siblings, 1 reply; 14+ messages in thread
From: David Gibson @ 2011-09-20 1:08 UTC (permalink / raw)
To: Simon Glass; +Cc: Devicetree Discuss
On Mon, Sep 19, 2011 at 01:21:03PM -0700, Simon Glass wrote:
> This adds a new utility library for performing libfdt operations.
>
> This is a separate library from libfdt because it performs OS operations,
> like open/close/read/write, while libfdt is OS-neutral. These utility
> functions are useful within the dtc package, and could potentially even
> be generally useful, but should not be part of libfdt.
>
> Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
> ---
> Changes in v2:
> - Remove util_decode_key
> - Add utilfdt_decode_type to be used by fdtget/put
> - Remove limits on device tree binary size
>
> Changes in v3:
> - Change format of -t argument to be more like printf
> - Move utilfdt into its own directory and make it a library
> - Use code closer to testutils.c implementation
> - Use open/close instead of fopen/fclose
[snip]
> diff --git a/Makefile b/Makefile
> index 380a705..4f5ccdd 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -15,7 +15,7 @@ EXTRAVERSION =
> LOCAL_VERSION =
> CONFIG_LOCALVERSION =
>
> -CPPFLAGS = -I libfdt
> +CPPFLAGS = -I libfdt -I utilfdt
> WARNINGS = -Werror -Wall -Wpointer-arith -Wcast-qual -Wnested-externs \
> -Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls
> CFLAGS = -g -Os -fPIC -Werror $(WARNINGS)
> @@ -151,6 +151,35 @@ ifneq ($(DEPTARGETS),)
> -include $(LIBFDT_OBJS:%.o=$(LIBFDT_objdir)/%.d)
> endif
>
> +#
> +# Rules for utilfdt
> +#
> +UTILFDT_objdir = utilfdt
> +UTILFDT_srcdir = utilfdt
> +UTILFDT_archive = $(UTILFDT_objdir)/libutilfdt.a
> +UTILFDT_lib = $(UTILFDT_objdir)/libutilfdt-$(DTC_VERSION).$(SHAREDLIB_EXT)
> +UTILFDT_include = $(addprefix $(UTILFDT_srcdir)/,$(UTILFDT_INCLUDES))
> +
> +include $(UTILFDT_srcdir)/Makefile.utilfdt
> +
> +.PHONY: utilfdt
> +utilfdt: $(UTILFDT_archive) $(UTILFDT_lib)
> +
> +$(UTILFDT_archive): $(addprefix $(UTILFDT_objdir)/,$(UTILFDT_OBJS))
> +$(UTILFDT_lib): $(addprefix $(UTILFDT_objdir)/,$(UTILFDT_OBJS))
Building a shared library out of this is complete overkill. In fact,
so is building a .a of it. This is not an exported library for
general use, but just an internal mini-"library" for use by the fdtget
and fdtput functions. Just have them both link with utilfdt.o.
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [RESEND PATCH v3 3/7] Add utilfdt tests
[not found] ` <1316463668-976-4-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
@ 2011-09-20 1:11 ` David Gibson
[not found] ` <20110920011147.GF29197-787xzQ0H9iQXU02nzanrWNbf9cGiqdzd@public.gmane.org>
0 siblings, 1 reply; 14+ messages in thread
From: David Gibson @ 2011-09-20 1:11 UTC (permalink / raw)
To: Simon Glass; +Cc: Devicetree Discuss
On Mon, Sep 19, 2011 at 01:21:04PM -0700, Simon Glass wrote:
> This adds a few tests for the simple type argument supported by
> utilfdt_decode_type.
>
> I assume this will be squashed in with utilfdt, but I have left it out
> for easier review here.
Yes, it should be squashed in. Fwiw, in my experience, folding the
tests in from day 1 does not significantly impair review, since the
tests patch usually touches essentially disjoint files from the rest.
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [RESEND PATCH v3 2/7] Add utilfdt for common functions
[not found] ` <20110920010859.GE29197-787xzQ0H9iQXU02nzanrWNbf9cGiqdzd@public.gmane.org>
@ 2011-09-20 3:54 ` Simon Glass
[not found] ` <CAPnjgZ0U_gYkQQR14UNZ0tAOT8jYxzwi_mEYXsT134m14m=8Bg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
0 siblings, 1 reply; 14+ messages in thread
From: Simon Glass @ 2011-09-20 3:54 UTC (permalink / raw)
To: David Gibson; +Cc: Devicetree Discuss
Hi David,
On Mon, Sep 19, 2011 at 6:08 PM, David Gibson
<david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org> wrote:
> On Mon, Sep 19, 2011 at 01:21:03PM -0700, Simon Glass wrote:
>> This adds a new utility library for performing libfdt operations.
>>
>> This is a separate library from libfdt because it performs OS operations,
>> like open/close/read/write, while libfdt is OS-neutral. These utility
>> functions are useful within the dtc package, and could potentially even
>> be generally useful, but should not be part of libfdt.
>>
>> Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
>> ---
>> Changes in v2:
>> - Remove util_decode_key
>> - Add utilfdt_decode_type to be used by fdtget/put
>> - Remove limits on device tree binary size
>>
>> Changes in v3:
>> - Change format of -t argument to be more like printf
>> - Move utilfdt into its own directory and make it a library
>> - Use code closer to testutils.c implementation
>> - Use open/close instead of fopen/fclose
>
> [snip]
>> diff --git a/Makefile b/Makefile
>> index 380a705..4f5ccdd 100644
>> --- a/Makefile
>> +++ b/Makefile
>> @@ -15,7 +15,7 @@ EXTRAVERSION =
>> LOCAL_VERSION =
>> CONFIG_LOCALVERSION =
>>
>> -CPPFLAGS = -I libfdt
>> +CPPFLAGS = -I libfdt -I utilfdt
>> WARNINGS = -Werror -Wall -Wpointer-arith -Wcast-qual -Wnested-externs \
>> -Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls
>> CFLAGS = -g -Os -fPIC -Werror $(WARNINGS)
>> @@ -151,6 +151,35 @@ ifneq ($(DEPTARGETS),)
>> -include $(LIBFDT_OBJS:%.o=$(LIBFDT_objdir)/%.d)
>> endif
>>
>> +#
>> +# Rules for utilfdt
>> +#
>> +UTILFDT_objdir = utilfdt
>> +UTILFDT_srcdir = utilfdt
>> +UTILFDT_archive = $(UTILFDT_objdir)/libutilfdt.a
>> +UTILFDT_lib = $(UTILFDT_objdir)/libutilfdt-$(DTC_VERSION).$(SHAREDLIB_EXT)
>> +UTILFDT_include = $(addprefix $(UTILFDT_srcdir)/,$(UTILFDT_INCLUDES))
>> +
>> +include $(UTILFDT_srcdir)/Makefile.utilfdt
>> +
>> +.PHONY: utilfdt
>> +utilfdt: $(UTILFDT_archive) $(UTILFDT_lib)
>> +
>> +$(UTILFDT_archive): $(addprefix $(UTILFDT_objdir)/,$(UTILFDT_OBJS))
>> +$(UTILFDT_lib): $(addprefix $(UTILFDT_objdir)/,$(UTILFDT_OBJS))
>
> Building a shared library out of this is complete overkill. In fact,
> so is building a .a of it. This is not an exported library for
> general use, but just an internal mini-"library" for use by the fdtget
> and fdtput functions. Just have them both link with utilfdt.o.
I guess I misunderstood your comment on this patch in v2, referring I
thought to the function to read an fdt:
> Yes, you'll need to fix that for a general library version. It
> should indeed return an error rather than dying.
I took that to me it should be in a library, and of course it couldn't
be in libfdt due to the OS use...
It is used by the tests, ftdump, fdtget and fdtput. I didn't really
want the tests to have to have -I.. and linking ../utilfdt.o.
So should I just make in an object file in the root that everything
except dtc links with?
Regards,
Simon
>
> --
> David Gibson | I'll have my music baroque, and my code
> david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
> | _way_ _around_!
> http://www.ozlabs.org/~dgibson
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [RESEND PATCH v3 2/7] Add utilfdt for common functions
[not found] ` <CAPnjgZ0U_gYkQQR14UNZ0tAOT8jYxzwi_mEYXsT134m14m=8Bg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2011-09-20 8:12 ` David Gibson
0 siblings, 0 replies; 14+ messages in thread
From: David Gibson @ 2011-09-20 8:12 UTC (permalink / raw)
To: Simon Glass; +Cc: Devicetree Discuss
On Mon, Sep 19, 2011 at 08:54:02PM -0700, Simon Glass wrote:
> Hi David,
[snip]
> > Building a shared library out of this is complete overkill. In fact,
> > so is building a .a of it. This is not an exported library for
> > general use, but just an internal mini-"library" for use by the fdtget
> > and fdtput functions. Just have them both link with utilfdt.o.
>
> I guess I misunderstood your comment on this patch in v2, referring I
> thought to the function to read an fdt:
Yeah, sorry, I don't think I was very clear.
> > Yes, you'll need to fix that for a general library version. It
> > should indeed return an error rather than dying.
>
> I took that to me it should be in a library, and of course it couldn't
> be in libfdt due to the OS use...
Well, I've contemplated adding such things to libfdt. It should be
workable as long as they're in a separate module which could be left
out when building for constrained environments. But I'd be much
pickier about the details of the interface in that case, I don't think
we're quite ready for this yet.
> It is used by the tests, ftdump, fdtget and fdtput. I didn't really
> want the tests to have to have -I.. and linking ../utilfdt.o.
>
> So should I just make in an object file in the root that everything
> except dtc links with?
You know what. On further consideration, just drop it into util.c,
which already has random handy but not exported functions shared
between dtc and ftdump.
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [RESEND PATCH v3 3/7] Add utilfdt tests
[not found] ` <20110920011147.GF29197-787xzQ0H9iQXU02nzanrWNbf9cGiqdzd@public.gmane.org>
@ 2011-09-21 20:28 ` Simon Glass
0 siblings, 0 replies; 14+ messages in thread
From: Simon Glass @ 2011-09-21 20:28 UTC (permalink / raw)
To: David Gibson; +Cc: Devicetree Discuss
Hi David,
On Mon, Sep 19, 2011 at 6:11 PM, David Gibson
<david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org> wrote:
> On Mon, Sep 19, 2011 at 01:21:04PM -0700, Simon Glass wrote:
>> This adds a few tests for the simple type argument supported by
>> utilfdt_decode_type.
>>
>> I assume this will be squashed in with utilfdt, but I have left it out
>> for easier review here.
>
> Yes, it should be squashed in. Fwiw, in my experience, folding the
> tests in from day 1 does not significantly impair review, since the
> tests patch usually touches essentially disjoint files from the rest.
Well yes but it makes the commits big, and I've had to touch the
Makefile here again. Anyway, I have done this and will resend the
patch set.
Regards,
Simon
>
> --
> David Gibson | I'll have my music baroque, and my code
> david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
> | _way_ _around_!
> http://www.ozlabs.org/~dgibson
>
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2011-09-21 20:28 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-19 20:21 [RESEND PATCH v3 0/7] Add fdtget and fdtput for access to fdt from build system Simon Glass
[not found] ` <1316463668-976-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2011-09-19 20:21 ` [RESEND PATCH v3 1/7] Create Makefile.utils and move ftdump into it Simon Glass
[not found] ` <1316463668-976-2-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2011-09-20 1:02 ` David Gibson
2011-09-19 20:21 ` [RESEND PATCH v3 2/7] Add utilfdt for common functions Simon Glass
[not found] ` <1316463668-976-3-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2011-09-20 1:08 ` David Gibson
[not found] ` <20110920010859.GE29197-787xzQ0H9iQXU02nzanrWNbf9cGiqdzd@public.gmane.org>
2011-09-20 3:54 ` Simon Glass
[not found] ` <CAPnjgZ0U_gYkQQR14UNZ0tAOT8jYxzwi_mEYXsT134m14m=8Bg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-09-20 8:12 ` David Gibson
2011-09-19 20:21 ` [RESEND PATCH v3 3/7] Add utilfdt tests Simon Glass
[not found] ` <1316463668-976-4-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2011-09-20 1:11 ` David Gibson
[not found] ` <20110920011147.GF29197-787xzQ0H9iQXU02nzanrWNbf9cGiqdzd@public.gmane.org>
2011-09-21 20:28 ` Simon Glass
2011-09-19 20:21 ` [RESEND PATCH v3 4/7] Make testutils use utilfdt Simon Glass
2011-09-19 20:21 ` [RESEND PATCH v3 5/7] ftdump: use utilfdt to read blob Simon Glass
2011-09-19 20:21 ` [RESEND PATCH v3 6/7] Add fdtget utility to read property values from a device tree Simon Glass
2011-09-19 20:21 ` [RESEND PATCH v3 7/7] Add fdtput utility to write property values to " Simon Glass
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).