summaryrefslogtreecommitdiffstats
path: root/common/uimage.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/uimage.c')
-rw-r--r--common/uimage.c86
1 files changed, 47 insertions, 39 deletions
diff --git a/common/uimage.c b/common/uimage.c
index 35bfb10b06..cc9e5e510a 100644
--- a/common/uimage.c
+++ b/common/uimage.c
@@ -1,21 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0-only
/*
* uimage.c - uimage handling code
*
* Copyright (c) 2011 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
*
* partly based on U-Boot uImage code
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
*/
#include <common.h>
#include <image.h>
@@ -30,6 +19,7 @@
#include <rtc.h>
#include <filetype.h>
#include <memory.h>
+#include <zero_page.h>
static inline int uimage_is_multi_image(struct uimage_handle *handle)
{
@@ -39,17 +29,19 @@ static inline int uimage_is_multi_image(struct uimage_handle *handle)
void uimage_print_contents(struct uimage_handle *handle)
{
struct image_header *hdr = &handle->header;
-#if defined(CONFIG_TIMESTAMP)
- struct rtc_time tm;
-#endif
+
printf(" Image Name: %.*s\n", IH_NMLEN, hdr->ih_name);
-#if defined(CONFIG_TIMESTAMP)
- printf(" Created: ");
- to_tm(hdr->ih_time, &tm);
- printf("%4d-%02d-%02d %2d:%02d:%02d UTC\n",
- tm.tm_year, tm.tm_mon, tm.tm_mday,
- tm.tm_hour, tm.tm_min, tm.tm_sec);
-#endif
+
+ if (IS_ENABLED(CONFIG_TIMESTAMP)) {
+ struct rtc_time tm;
+
+ printf(" Created: ");
+ to_tm(hdr->ih_time, &tm);
+ printf("%4d-%02d-%02d %2d:%02d:%02d UTC\n",
+ tm.tm_year, tm.tm_mon, tm.tm_mday,
+ tm.tm_hour, tm.tm_min, tm.tm_sec);
+ }
+
#if defined(CONFIG_BOOTM_SHOW_TYPE)
printf(" OS: %s\n", image_get_os_name(hdr->ih_os));
printf(" Architecture: %s\n", image_get_arch_name(hdr->ih_arch));
@@ -108,7 +100,7 @@ struct uimage_handle *uimage_open(const char *filename)
fd = open(filename, O_RDONLY);
if (fd < 0) {
- printf("could not open: %s\n", errno_str());
+ printf("could not open: %m\n");
free(copy);
return NULL;
}
@@ -119,7 +111,7 @@ struct uimage_handle *uimage_open(const char *filename)
handle->copy = copy;
if (read(fd, header, sizeof(*header)) < 0) {
- printf("could not read: %s\n", errno_str());
+ printf("could not read: %m\n");
goto err_out;
}
@@ -136,7 +128,7 @@ struct uimage_handle *uimage_open(const char *filename)
goto err_out;
}
- /* convert header to cpu native endianess */
+ /* convert header to cpu native endianness */
header->ih_magic = uimage_to_cpu(header->ih_magic);
header->ih_hcrc = uimage_to_cpu(header->ih_hcrc);
header->ih_time = uimage_to_cpu(header->ih_time);
@@ -226,23 +218,23 @@ EXPORT_SYMBOL(uimage_close);
static int uimage_fd;
-static int uimage_fill(void *buf, unsigned int len)
+static long uimage_fill(void *buf, unsigned long len)
{
return read_full(uimage_fd, buf, len);
}
-static int uncompress_copy(unsigned char *inbuf_unused, int len,
- int(*fill)(void*, unsigned int),
- int(*flush)(void*, unsigned int),
+static int uncompress_copy(unsigned char *inbuf_unused, long len,
+ long(*fill)(void*, unsigned long),
+ long(*flush)(void*, unsigned long),
unsigned char *outbuf_unused,
- int *pos,
+ long *pos,
void(*error_fn)(char *x))
{
int ret;
void *buf = xmalloc(PAGE_SIZE);
while (len) {
- int now = min(len, PAGE_SIZE);
+ int now = min_t(long, len, PAGE_SIZE);
ret = fill(buf, now);
if (ret < 0)
goto err;
@@ -303,17 +295,17 @@ EXPORT_SYMBOL(uimage_verify);
* Load a uimage, flushing output to flush function
*/
int uimage_load(struct uimage_handle *handle, unsigned int image_no,
- int(*flush)(void*, unsigned int))
+ long(*flush)(void*, unsigned long))
{
image_header_t *hdr = &handle->header;
struct uimage_handle_data *iha;
int ret;
loff_t off;
- int (*uncompress_fn)(unsigned char *inbuf, int len,
- int(*fill)(void*, unsigned int),
- int(*flush)(void*, unsigned int),
+ int (*uncompress_fn)(unsigned char *inbuf, long len,
+ long(*fill)(void*, unsigned long),
+ long(*flush)(void*, unsigned long),
unsigned char *output,
- int *pos,
+ long *pos,
void(*error)(char *x));
if (image_no >= handle->nb_data_entries)
@@ -344,7 +336,7 @@ static void *uimage_buf;
static size_t uimage_size;
static struct resource *uimage_resource;
-static int uimage_sdram_flush(void *buf, unsigned int len)
+static long uimage_sdram_flush(void *buf, unsigned long len)
{
if (uimage_size + len > resource_size(uimage_resource)) {
resource_size_t start = uimage_resource->start;
@@ -362,7 +354,10 @@ static int uimage_sdram_flush(void *buf, unsigned int len)
}
}
- memcpy(uimage_buf + uimage_size, buf, len);
+ if (zero_page_contains((unsigned long)uimage_buf + uimage_size))
+ zero_page_memcpy(uimage_buf + uimage_size, buf, len);
+ else
+ memcpy(uimage_buf + uimage_size, buf, len);
uimage_size += len;
@@ -391,7 +386,20 @@ struct resource *file_to_sdram(const char *filename, unsigned long adr)
goto out;
}
- now = read_full(fd, (void *)(res->start + ofs), BUFSIZ);
+ if (zero_page_contains(res->start + ofs)) {
+ void *tmp = malloc(BUFSIZ);
+ if (!tmp)
+ now = -ENOMEM;
+ else
+ now = read_full(fd, tmp, BUFSIZ);
+
+ if (now > 0)
+ zero_page_memcpy((void *)(res->start + ofs), tmp, now);
+ free(tmp);
+ } else {
+ now = read_full(fd, (void *)(res->start + ofs), BUFSIZ);
+ }
+
if (now < 0) {
release_sdram_region(res);
res = NULL;