From: David Gibson <david@gibson.dropbear.id.au>
To: Jon Loeliger <jdl@freescale.com>
Cc: linuxppc-dev@ozlabs.org
Subject: dtc: Make dt_from_blob() open its own file
Date: Tue, 4 Mar 2008 16:10:39 +1100 [thread overview]
Message-ID: <20080304051039.GC2757@localhost.localdomain> (raw)
dt_from_source() and dt_from_fs() both take a filename (or directory
name) argument and open files as necessary themselves.
dt_from_blob(), however, expects the caller to open a file and pass it
in.
This patch makes dt_from_blob() take a filename and open its own
files, removing the inconsistency. In addition, dt_from_blob() now
correctly uses dtc_close_file() to close the file opened with
dtc_open_file(), rather than directly calling fclose() on the
contained FILE *.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
dtc.c | 11 +----------
dtc.h | 4 ++--
flattree.c | 10 +++++++++-
3 files changed, 12 insertions(+), 13 deletions(-)
Index: dtc/dtc.c
===================================================================
--- dtc.orig/dtc.c 2008-03-04 15:58:49.000000000 +1100
+++ dtc/dtc.c 2008-03-04 16:02:12.000000000 +1100
@@ -118,7 +118,6 @@ int main(int argc, char *argv[])
int force = 0, check = 0;
const char *arg;
int opt;
- struct dtc_file *inf = NULL;
FILE *outf = NULL;
int outversion = DEFAULT_FDT_VERSION;
int boot_cpuid_phys = 0xfeedbeef;
@@ -192,19 +191,11 @@ int main(int argc, char *argv[])
} else if (streq(inform, "fs")) {
bi = dt_from_fs(arg);
} else if(streq(inform, "dtb")) {
- inf = dtc_open_file(arg, NULL);
- if (!inf)
- die("Couldn't open \"%s\": %s\n", arg,
- strerror(errno));
-
- bi = dt_from_blob(inf->file);
+ bi = dt_from_blob(arg);
} else {
die("Unknown input format \"%s\"\n", inform);
}
- if (inf && inf->file != stdin)
- fclose(inf->file);
-
if (! bi || ! bi->dt || bi->error)
die("Couldn't read input tree\n");
Index: dtc/flattree.c
===================================================================
--- dtc.orig/flattree.c 2008-03-04 15:59:53.000000000 +1100
+++ dtc/flattree.c 2008-03-04 16:06:55.000000000 +1100
@@ -19,6 +19,7 @@
*/
#include "dtc.h"
+#include "srcpos.h"
#define FTF_FULLPATH 0x1
#define FTF_VARALIGN 0x2
@@ -780,8 +781,10 @@ static struct node *unflatten_tree(struc
}
-struct boot_info *dt_from_blob(FILE *f)
+struct boot_info *dt_from_blob(const char *fname)
{
+ struct dtc_file *dtcf;
+ FILE *f;
u32 magic, totalsize, version, size_dt;
u32 off_dt, off_str, off_mem_rsvmap;
int rc;
@@ -796,6 +799,9 @@ struct boot_info *dt_from_blob(FILE *f)
u32 val;
int flags = 0;
+ dtcf = dtc_open_file(fname, NULL);
+ f = dtcf->file;
+
rc = fread(&magic, sizeof(magic), 1, f);
if (ferror(f))
die("Error reading DT blob magic number: %s\n",
@@ -902,5 +908,7 @@ struct boot_info *dt_from_blob(FILE *f)
free(blob);
+ dtc_close_file(dtcf);
+
return build_boot_info(reservelist, tree);
}
Index: dtc/dtc.h
===================================================================
--- dtc.orig/dtc.h 2008-03-04 16:01:22.000000000 +1100
+++ dtc/dtc.h 2008-03-04 16:01:43.000000000 +1100
@@ -250,12 +250,12 @@ void dt_to_blob(FILE *f, struct boot_inf
void dt_to_asm(FILE *f, struct boot_info *bi, int version,
int boot_cpuid_phys);
-struct boot_info *dt_from_blob(FILE *f);
+struct boot_info *dt_from_blob(const char *fname);
/* Tree source */
void dt_to_source(FILE *f, struct boot_info *bi);
-struct boot_info *dt_from_source(const char *f);
+struct boot_info *dt_from_source(const char *fname);
/* FS trees */
--
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
next reply other threads:[~2008-03-04 5:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-04 5:10 David Gibson [this message]
2008-03-04 5:15 ` dtc: Make dt_from_blob() open its own file 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=20080304051039.GC2757@localhost.localdomain \
--to=david@gibson.dropbear.id.au \
--cc=jdl@freescale.com \
--cc=linuxppc-dev@ozlabs.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).