qemu-stable
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-stable] [PATCH 1/3] hw/core/loader: implement load_uboot_image_hea


From: Max Filippov
Subject: [Qemu-stable] [PATCH 1/3] hw/core/loader: implement load_uboot_image_header
Date: Tue, 12 Aug 2014 08:22:20 +0400

Extract uImage header loader and allow using it from the rest of the
code.

Cc: address@hidden
Signed-off-by: Max Filippov <address@hidden>
---
 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]