mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 2/5] make uimages work on tftpfs
Date: Sun, 19 Feb 2012 18:58:05 +0100	[thread overview]
Message-ID: <1329674288-25583-3-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1329674288-25583-1-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/uimage.c |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/common/uimage.c b/common/uimage.c
index 28791b5..4933c40 100644
--- a/common/uimage.c
+++ b/common/uimage.c
@@ -94,6 +94,8 @@ size_t uimage_get_size(struct uimage_handle *handle, unsigned int image_no)
 }
 EXPORT_SYMBOL(uimage_get_size);
 
+static const char uimage_tmp[] = "/.uImage_tmp";
+
 /*
  * open a uimage. This will check the header contents and
  * return a handle to the uImage
@@ -106,13 +108,29 @@ struct uimage_handle *uimage_open(const char *filename)
 	struct image_header *header;
 	int i;
 	int ret;
+	struct stat s;
 
+again:
 	fd = open(filename, O_RDONLY);
 	if (fd < 0) {
 		printf("could not open: %s\n", errno_str());
 		return NULL;
 	}
 
+	/*
+	 * Hack around tftp fs. We need lseek for uImage support, but
+	 * this cannot be implemented in tftp fs, so we detect this
+	 * by doing a test lseek and copy the file to ram if it fails
+	 */
+	if (IS_BUILTIN(CONFIG_FS_TFTP) && lseek(fd, 0, SEEK_SET)) {
+		close(fd);
+		ret = copy_file(filename, uimage_tmp, 0);
+		if (ret)
+			return NULL;
+		filename = uimage_tmp;
+		goto again;
+	}
+
 	handle = xzalloc(sizeof(struct uimage_handle));
 	header = &handle->header;
 
@@ -194,6 +212,8 @@ struct uimage_handle *uimage_open(const char *filename)
 err_out:
 	close(fd);
 	free(handle);
+	if (IS_BUILTIN(CONFIG_FS_TFTP) && !stat(uimage_tmp, &s))
+		unlink(uimage_tmp);
 	return NULL;
 }
 EXPORT_SYMBOL(uimage_open);
@@ -203,9 +223,14 @@ EXPORT_SYMBOL(uimage_open);
  */
 void uimage_close(struct uimage_handle *handle)
 {
+	struct stat s;
+
 	close(handle->fd);
 	free(handle->name);
 	free(handle);
+
+	if (IS_BUILTIN(CONFIG_FS_TFTP) && !stat("/.uimage_tmp", &s))
+		unlink("/.uimage_tmp");
 }
 EXPORT_SYMBOL(uimage_close);
 
-- 
1.7.9


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2012-02-19 17:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-19 17:58 tftp filesystem support Sascha Hauer
2012-02-19 17:58 ` [PATCH 1/5] Add suport for tftp as a filesystem Sascha Hauer
2012-02-20  4:54   ` Jean-Christophe PLAGNIOL-VILLARD
2012-02-20 18:16     ` Sascha Hauer
2012-02-19 17:58 ` Sascha Hauer [this message]
2012-02-19 17:58 ` [PATCH 3/5] net: let net_udp_get_payload return void * Sascha Hauer
2012-02-19 17:58 ` [PATCH 4/5] add string for -ETIMEDOUT Sascha Hauer
2012-02-19 17:58 ` [PATCH 5/5] copy_file: limit progress bar to sensible limits Sascha Hauer

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=1329674288-25583-3-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.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