From: Max Filippov <jcmvbkbc@gmail.com>
To: qemu-devel@nongnu.org
Cc: Max Filippov <jcmvbkbc@gmail.com>,
Waldemar Brodkorb <mail@waldemar-brodkorb.de>,
qemu-stable@nongnu.org
Subject: [Qemu-devel] [PATCH 1/3] hw/core/loader: implement load_uboot_image_header
Date: Tue, 12 Aug 2014 08:22:20 +0400 [thread overview]
Message-ID: <1407817342-1373-2-git-send-email-jcmvbkbc@gmail.com> (raw)
In-Reply-To: <1407817342-1373-1-git-send-email-jcmvbkbc@gmail.com>
Extract uImage header loader and allow using it from the rest of the
code.
Cc: qemu-stable@nongnu.org
Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
---
hw/core/loader.c | 37 +++++++++++++++++++++++++++++--------
include/hw/loader.h | 2 ++
2 files changed, 31 insertions(+), 8 deletions(-)
diff --git a/hw/core/loader.c b/hw/core/loader.c
index 2bf6b8f..5bf7f9b 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -454,12 +454,25 @@ static ssize_t gunzip(void *dst, size_t dstlen, uint8_t *src,
return dstbytes;
}
+static int load_uboot_image_header_fd(int fd, uboot_image_header_t *hdr)
+{
+ int size = read(fd, hdr, sizeof(uboot_image_header_t));
+
+ if (size < 0) {
+ return -1;
+ }
+ bswap_uboot_header(hdr);
+ if (hdr->ih_magic != IH_MAGIC) {
+ return -1;
+ }
+ return 0;
+}
+
/* Load a U-Boot image. */
static int load_uboot_image(const char *filename, hwaddr *ep, hwaddr *loadaddr,
int *is_linux, uint8_t image_type)
{
int fd;
- int size;
hwaddr address;
uboot_image_header_t h;
uboot_image_header_t *hdr = &h;
@@ -471,14 +484,9 @@ static int load_uboot_image(const char *filename, hwaddr *ep, hwaddr *loadaddr,
if (fd < 0)
return -1;
- size = read(fd, hdr, sizeof(uboot_image_header_t));
- if (size < 0)
- goto out;
-
- bswap_uboot_header(hdr);
-
- if (hdr->ih_magic != IH_MAGIC)
+ if (load_uboot_image_header_fd(fd, hdr) < 0) {
goto out;
+ }
if (hdr->ih_type != image_type) {
fprintf(stderr, "Wrong image type %d, expected %d\n", hdr->ih_type,
@@ -565,6 +573,19 @@ out:
return ret;
}
+int load_uboot_image_header(const char *filename, uboot_image_header_t *hdr)
+{
+ int rc;
+ int fd = open(filename, O_RDONLY | O_BINARY);
+
+ if (fd < 0) {
+ return -1;
+ }
+ rc = load_uboot_image_header_fd(fd, hdr);
+ close(fd);
+ return rc;
+}
+
int load_uimage(const char *filename, hwaddr *ep, hwaddr *loadaddr,
int *is_linux)
{
diff --git a/include/hw/loader.h b/include/hw/loader.h
index 796cbf9..a8cd0cf 100644
--- a/include/hw/loader.h
+++ b/include/hw/loader.h
@@ -1,6 +1,7 @@
#ifndef LOADER_H
#define LOADER_H
#include "qapi/qmp/qdict.h"
+#include "hw/core/uboot_image.h"
#include "hw/nvram/fw_cfg.h"
/* loader.c */
@@ -27,6 +28,7 @@ int load_elf(const char *filename, uint64_t (*translate_fn)(void *, uint64_t),
int clear_lsb);
int load_aout(const char *filename, hwaddr addr, int max_sz,
int bswap_needed, hwaddr target_page_size);
+int load_uboot_image_header(const char *filename, uboot_image_header_t *hdr);
int load_uimage(const char *filename, hwaddr *ep,
hwaddr *loadaddr, int *is_linux);
--
1.8.1.4
next prev parent reply other threads:[~2014-08-12 4:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-12 4:22 [Qemu-devel] [PATCH 0/3] target-xtensa: fix loading uImage kernels on MMUv2 cores Max Filippov
2014-08-12 4:22 ` Max Filippov [this message]
2014-08-12 4:22 ` [Qemu-devel] [PATCH 2/3] hw/core/loader: implement load_uimage_at Max Filippov
2014-08-21 9:16 ` Alexander Graf
2014-08-21 20:56 ` Max Filippov
2014-08-21 21:21 ` Alexander Graf
2014-08-12 4:22 ` [Qemu-devel] [PATCH 3/3] target-xtensa: treat uImage load address as virtual Max Filippov
2014-08-16 1:30 ` [Qemu-devel] [PATCH 0/3] target-xtensa: fix loading uImage kernels on MMUv2 cores Max Filippov
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=1407817342-1373-2-git-send-email-jcmvbkbc@gmail.com \
--to=jcmvbkbc@gmail.com \
--cc=mail@waldemar-brodkorb.de \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.