From: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
To: Devicetree Discuss
<devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org>
Subject: [PATCH v5 2/5] Make testutils use utilfdt
Date: Thu, 22 Sep 2011 10:11:03 -0700 [thread overview]
Message-ID: <1316711466-14199-3-git-send-email-sjg@chromium.org> (raw)
In-Reply-To: <1316711466-14199-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
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>
Acked-by: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
---
Changes in v3:
- Make testutils.c use utilfdt for load/save blobs
tests/Makefile.tests | 5 ++-
tests/testutils.c | 59 +++++++++----------------------------------------
2 files changed, 14 insertions(+), 50 deletions(-)
diff --git a/tests/Makefile.tests b/tests/Makefile.tests
index 41695df..cae8390 100644
--- a/tests/Makefile.tests
+++ b/tests/Makefile.tests
@@ -45,11 +45,12 @@ tests: $(TESTS) $(TESTS_TREES)
$(LIB_TESTS): %: $(TESTS_PREFIX)testutils.o util.o $(LIBFDT_archive)
-$(DL_LIB_TESTS): %: %.o $(TESTS_PREFIX)testutils.o $(LIBFDT_archive)
+$(DL_LIB_TESTS): %: %.o $(TESTS_PREFIX)testutils.o util.o $(LIBFDT_archive)
@$(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 \
+ util.o $(LIBFDT_archive)
$(TESTS_PREFIX)dumptrees: $(TESTS_PREFIX)trees.o
diff --git a/tests/testutils.c b/tests/testutils.c
index b0a2230..f185133 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -159,33 +159,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 +177,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
next prev parent reply other threads:[~2011-09-22 17:11 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-22 17:11 [PATCH v5 0/5] Add fdtget and fdtput for access to fdt from build system Simon Glass
[not found] ` <1316711466-14199-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2011-09-22 17:11 ` [PATCH v5 1/5] Add fdt read/write utility functions Simon Glass
[not found] ` <1316711466-14199-2-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2011-09-22 18:54 ` Jon Loeliger
[not found] ` <E1R6oQ2-00016C-DY-CYoMK+44s/E@public.gmane.org>
2011-09-22 19:07 ` Simon Glass
2011-09-22 17:11 ` Simon Glass [this message]
[not found] ` <1316711466-14199-3-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2011-09-22 18:55 ` [PATCH v5 2/5] Make testutils use utilfdt Jon Loeliger
2011-09-22 17:11 ` [PATCH v5 3/5] ftdump: use utilfdt to read blob Simon Glass
[not found] ` <1316711466-14199-4-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2011-09-22 18:55 ` Jon Loeliger
2011-09-22 17:11 ` [PATCH v5 4/5] Add fdtget utility to read property values from a device tree Simon Glass
[not found] ` <1316711466-14199-5-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2011-09-23 1:20 ` David Gibson
[not found] ` <20110923012007.GG12286-787xzQ0H9iQXU02nzanrWNbf9cGiqdzd@public.gmane.org>
2011-12-16 1:37 ` Simon Glass
[not found] ` <CAPnjgZ0Na+zAX2cj=b1HbyGW5iNLGLn2rAeQEfZ9LwBLDW6a1w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-12-20 12:01 ` David Gibson
[not found] ` <20111220120148.GB5133-MK4v0fQdeXQXU02nzanrWNbf9cGiqdzd@public.gmane.org>
2011-12-22 6:47 ` Simon Glass
[not found] ` <CAPnjgZ3Y897hEQ2+qLO711Cuv9BvkQvcxusG1XQAyiG3UZ-M0g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-12-22 14:17 ` Jon Loeliger
[not found] ` <E1RdjSE-0007a8-86-CYoMK+44s/E@public.gmane.org>
2012-01-04 0:44 ` Simon Glass
2011-09-22 17:11 ` [PATCH v5 5/5] Add fdtput utility to write property values to " Simon Glass
[not found] ` <1316711466-14199-6-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2011-09-23 1:20 ` David Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1316711466-14199-3-git-send-email-sjg@chromium.org \
--to=sjg-f7+t8e8rja9g9huczpvpmw@public.gmane.org \
--cc=devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).