mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 5/7] uimage: Use is_tftp_fs() and cache_file() to ease TFTP workaround
Date: Wed, 24 Jan 2018 08:45:32 +0100	[thread overview]
Message-ID: <20180124074534.7966-6-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20180124074534.7966-1-s.hauer@pengutronix.de>

We have helper functions now to ease file caching when a file
is on TFTP. Use them.

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

diff --git a/common/uimage.c b/common/uimage.c
index b6f0f109ca..18bc2e5d7b 100644
--- a/common/uimage.c
+++ b/common/uimage.c
@@ -85,8 +85,6 @@ ssize_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
@@ -99,32 +97,26 @@ struct uimage_handle *uimage_open(const char *filename)
 	struct image_header *header;
 	int i;
 	int ret;
-	struct stat s;
+	char *copy = NULL;
+
+	if (is_tftp_fs(filename)) {
+		ret = cache_file(filename, &copy);
+		if (ret)
+			return NULL;
+		filename = copy;
+	}
 
-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
-	 * and copy the file to ram if it fails
-	 */
-	if (IS_BUILTIN(CONFIG_FS_TFTP) && !can_lseek_backward(fd)) {
-		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;
 
+	handle->copy = copy;
+
 	if (read(fd, header, sizeof(*header)) < 0) {
 		printf("could not read: %s\n", errno_str());
 		goto err_out;
@@ -202,9 +194,13 @@ again:
 	return handle;
 err_out:
 	close(fd);
+
+	if (handle->copy) {
+		unlink(handle->copy);
+		free(handle->copy);
+	}
 	free(handle);
-	if (IS_BUILTIN(CONFIG_FS_TFTP) && !stat(uimage_tmp, &s))
-		unlink(uimage_tmp);
+
 	return NULL;
 }
 EXPORT_SYMBOL(uimage_open);
@@ -214,14 +210,15 @@ EXPORT_SYMBOL(uimage_open);
  */
 void uimage_close(struct uimage_handle *handle)
 {
-	struct stat s;
-
 	close(handle->fd);
+
+	if (handle->copy) {
+		unlink(handle->copy);
+		free(handle->copy);
+	}
+
 	free(handle->name);
 	free(handle);
-
-	if (IS_BUILTIN(CONFIG_FS_TFTP) && !stat(uimage_tmp, &s))
-		unlink(uimage_tmp);
 }
 EXPORT_SYMBOL(uimage_close);
 
diff --git a/include/image.h b/include/image.h
index 3e75d49b88..add9c85874 100644
--- a/include/image.h
+++ b/include/image.h
@@ -246,6 +246,7 @@ struct resource *file_to_sdram(const char *filename, unsigned long adr);
 struct uimage_handle {
 	struct image_header header;
 	char *name;
+	char *copy;
 	struct uimage_handle_data ihd[MAX_MULTI_IMAGE_COUNT];
 	int nb_data_entries;
 	size_t data_offset;
-- 
2.11.0


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

  parent reply	other threads:[~2018-01-24  7:45 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-24  7:45 [PATCH 0/7] Make TFTP detection more convenient Sascha Hauer
2018-01-24  7:45 ` [PATCH 1/7] startup: create /tmp Sascha Hauer
2018-01-24  7:45 ` [PATCH 2/7] fs: implement is_tftp_fs() Sascha Hauer
2018-01-24 19:12   ` Stefan Lengfeld
2018-01-25  7:46     ` Sascha Hauer
2018-01-24  7:45 ` [PATCH 3/7] libfile: implement make_temp Sascha Hauer
2018-01-24  7:45 ` [PATCH 4/7] libfile: implement a function to cache a file Sascha Hauer
2018-01-24 19:23   ` Stefan Lengfeld
2018-01-24  7:45 ` Sascha Hauer [this message]
2018-01-24 19:39   ` [PATCH 5/7] uimage: Use is_tftp_fs() and cache_file() to ease TFTP workaround Stefan Lengfeld
2018-01-24  7:45 ` [PATCH 6/7] fs/uimagefs: " Sascha Hauer
2018-01-24 19:56   ` Stefan Lengfeld
2018-01-24  7:45 ` [PATCH 7/7] fs: remove now unused function can_lseek_backward() 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=20180124074534.7966-6-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