summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2018-02-08 09:04:27 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2018-02-08 09:04:27 +0100
commit0dce5375d799e727bd1aa5ccdb28156d9bcd4d17 (patch)
treee1c6dd036a69ab954616219dfa0cee8312bb43f8 /common
parent6f826bfe45298721a92bbe93d32a6a0eb76d46ee (diff)
parent74cdc34323ee23b9b195866c56699e268f05841a (diff)
downloadbarebox-0dce5375d799e727bd1aa5ccdb28156d9bcd4d17.tar.gz
barebox-0dce5375d799e727bd1aa5ccdb28156d9bcd4d17.tar.xz
Merge branch 'for-next/tftp-workaround'
Diffstat (limited to 'common')
-rw-r--r--common/startup.c1
-rw-r--r--common/uimage.c49
2 files changed, 25 insertions, 25 deletions
diff --git a/common/startup.c b/common/startup.c
index 8b075422dd..8940674528 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -54,6 +54,7 @@ static int mount_root(void)
{
mount("none", "ramfs", "/", NULL);
mkdir("/dev", 0);
+ mkdir("/tmp", 0);
mount("none", "devfs", "/dev", NULL);
if (IS_ENABLED(CONFIG_FS_EFIVARFS)) {
diff --git a/common/uimage.c b/common/uimage.c
index b6f0f109ca..3273bc1871 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,27 @@ 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());
+ free(copy);
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 +195,14 @@ again:
return handle;
err_out:
close(fd);
+
+ free(handle->name);
+ 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 +212,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);