qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Graf <agraf@suse.de>
To: qemu-devel@nongnu.org
Cc: qemu-ppc@nongnu.org
Subject: [Qemu-devel] [PATCH 10/10] PPC: e500: Move to u-boot as firmware
Date: Mon, 20 Jan 2014 00:44:37 +0100	[thread overview]
Message-ID: <1390175077-5717-11-git-send-email-agraf@suse.de> (raw)
In-Reply-To: <1390175077-5717-1-git-send-email-agraf@suse.de>

Almost all platforms QEMU emulates have some sort of firmware they can load
to expose a guest environment that closely resembles the way it would look
like on real hardware.

This patch introduces such a firmware on our e500 platforms. U-boot is the
default firmware for most of these systems and as such our preferred choice.

For now, it is able to expose the same functionality to the user as the direct
-kernel option was, just that it prints some nice messages beforehand.

However, if you abort the boot (press any key) or boot without -kernel you
are actually able to modify the boot environment, execute a networked boot
through the e1000 emulation and execute u-boot payloads.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 hw/ppc/e500.c | 94 ++++++++++++++++++++++++++++++++++-------------------------
 1 file changed, 54 insertions(+), 40 deletions(-)

diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
index f8a76b7..d95c112 100644
--- a/hw/ppc/e500.c
+++ b/hw/ppc/e500.c
@@ -39,7 +39,6 @@
 
 #define EPAPR_MAGIC                (0x45504150)
 #define BINARY_DEVICE_TREE_FILE    "mpc8544ds.dtb"
-#define UIMAGE_LOAD_BASE           0
 #define DTC_LOAD_PAD               0x1800000
 #define DTC_PAD_MASK               0xFFFFF
 #define DTB_MAX_SIZE               (8 * 1024 * 1024)
@@ -618,15 +617,18 @@ void ppce500_init(QEMUMachineInitArgs *args, PPCE500Params *params)
     MemoryRegion *ram = g_new(MemoryRegion, 1);
     PCIBus *pci_bus;
     CPUPPCState *env = NULL;
-    uint64_t elf_entry;
-    uint64_t elf_lowaddr;
-    hwaddr entry=0;
-    hwaddr loadaddr=UIMAGE_LOAD_BASE;
-    target_long kernel_size=0;
-    target_ulong dt_base = 0;
-    target_ulong initrd_base = 0;
-    target_long initrd_size = 0;
-    target_ulong cur_base = 0;
+    uint64_t loadaddr;
+    hwaddr kernel_base = -1LL;
+    int kernel_size = 0;
+    hwaddr dt_base = 0;
+    hwaddr initrd_base = 0;
+    int initrd_size = 0;
+    hwaddr cur_base = 0;
+    char *filename;
+    hwaddr bios_entry = 0;
+    target_long bios_size;
+    struct boot_info *boot_info;
+    int dt_size;
     int i;
     unsigned int pci_irq_nrs[4] = {1, 2, 3, 4};
     qemu_irq **irqs, *mpic;
@@ -753,29 +755,24 @@ void ppce500_init(QEMUMachineInitArgs *args, PPCE500Params *params)
     /* Register spinning region */
     sysbus_create_simple("e500-spin", MPC8544_SPIN_BASE, NULL);
 
+    if (cur_base < (32 * 1024 * 1024)) {
+        /* u-boot occupies memory up to 32MB, so load blobs above */
+        cur_base = (32 * 1024 * 1024);
+    }
+
     /* Load kernel. */
     if (args->kernel_filename) {
-        kernel_size = load_uimage(args->kernel_filename, &entry,
-                                  &loadaddr, NULL);
-        if (kernel_size < 0) {
-            kernel_size = load_elf(args->kernel_filename, NULL, NULL,
-                                   &elf_entry, &elf_lowaddr, NULL, 1,
-                                   ELF_MACHINE, 0);
-            entry = elf_entry;
-            loadaddr = elf_lowaddr;
-        }
-        /* XXX try again as binary */
+        kernel_base = cur_base;
+        kernel_size = load_image_targphys(args->kernel_filename,
+                                          cur_base,
+                                          ram_size - cur_base);
         if (kernel_size < 0) {
             fprintf(stderr, "qemu: could not load kernel '%s'\n",
                     args->kernel_filename);
             exit(1);
         }
 
-        cur_base = loadaddr + kernel_size;
-
-        /* Reserve space for dtb */
-        dt_base = (cur_base + DTC_LOAD_PAD) & ~DTC_PAD_MASK;
-        cur_base += DTB_MAX_SIZE;
+        cur_base += kernel_size;
     }
 
     /* Load initrd. */
@@ -793,25 +790,42 @@ void ppce500_init(QEMUMachineInitArgs *args, PPCE500Params *params)
         cur_base = initrd_base + initrd_size;
     }
 
-    /* If we're loading a kernel directly, we must load the device tree too. */
-    if (args->kernel_filename) {
-        struct boot_info *boot_info;
-        int dt_size;
-
-        dt_size = ppce500_prep_device_tree(args, params, dt_base,
-                                           initrd_base, initrd_size,
-                                           loadaddr, kernel_size);
-        if (dt_size < 0) {
-            fprintf(stderr, "couldn't load device tree\n");
+    /* Load u-boot (ELF) */
+    if (bios_name == NULL) {
+        bios_name = "u-boot.e500";
+    }
+    filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
+
+    bios_size = load_elf(filename, NULL, NULL, &bios_entry, &loadaddr, NULL,
+                         1, ELF_MACHINE, 0);
+    if (bios_size < 0) {
+        /*
+         * Hrm. No ELF image? Try a uImage, maybe someone is giving us an
+         * ePAPR compliant kernel
+         */
+        kernel_size = load_uimage(filename, &bios_entry, &loadaddr, NULL);
+        if (kernel_size < 0) {
+            fprintf(stderr, "qemu: could not load firmware '%s'\n", filename);
             exit(1);
         }
-        assert(dt_size < DTB_MAX_SIZE);
+    }
 
-        boot_info = env->load_info;
-        boot_info->entry = entry;
-        boot_info->dt_base = dt_base;
-        boot_info->dt_size = dt_size;
+    /* Reserve space for dtb */
+    dt_base = (loadaddr + bios_size + DTC_LOAD_PAD) & ~DTC_PAD_MASK;
+
+    dt_size = ppce500_prep_device_tree(args, params, dt_base,
+                                       initrd_base, initrd_size,
+                                       kernel_base, kernel_size);
+    if (dt_size < 0) {
+        fprintf(stderr, "couldn't load device tree\n");
+        exit(1);
     }
+    assert(dt_size < DTB_MAX_SIZE);
+
+    boot_info = env->load_info;
+    boot_info->entry = bios_entry;
+    boot_info->dt_base = dt_base;
+    boot_info->dt_size = dt_size;
 
     if (kvm_enabled()) {
         kvmppc_init();
-- 
1.8.1.4

  parent reply	other threads:[~2014-01-19 23:44 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-19 23:44 [Qemu-devel] [PATCH 00/10] PPC: e500: Use u-boot as firmware Alexander Graf
2014-01-19 23:44 ` [Qemu-devel] [PATCH 01/10] PPC: Make all e500 CPUs SVR aware Alexander Graf
2014-01-19 23:44 ` [Qemu-devel] [PATCH 02/10] PPC: Add definitions for GIVORs Alexander Graf
2014-01-19 23:44 ` [Qemu-devel] [PATCH 03/10] PPC: Add stub emulation for HDBCR0 Alexander Graf
2014-01-19 23:44 ` [Qemu-devel] [PATCH 04/10] PPC: Add L1CFG1 SPR emulation Alexander Graf
2014-01-23  0:15   ` [Qemu-devel] [Qemu-ppc] " Scott Wood
2014-01-19 23:44 ` [Qemu-devel] [PATCH 05/10] PPC: Properly emulate L1CSR0 and L1CSR1 Alexander Graf
2014-01-19 23:44 ` [Qemu-devel] [PATCH 06/10] PPC: Add dcbtls emulation Alexander Graf
2014-01-19 23:44 ` [Qemu-devel] [PATCH 07/10] PPC: guts: Add emulation of a few more registers Alexander Graf
2014-01-23  0:08   ` [Qemu-devel] [Qemu-ppc] " Scott Wood
2014-01-23 11:34     ` Alexander Graf
2014-01-23 21:22       ` Scott Wood
2014-01-19 23:44 ` [Qemu-devel] [PATCH 08/10] PPC: e500: Expose kernel load address in dt Alexander Graf
2014-01-19 23:44 ` [Qemu-devel] [PATCH 09/10] PPC: Add u-boot firmware for e500 Alexander Graf
2014-01-20  0:17   ` Peter Maydell
2014-01-20 10:04     ` Alexander Graf
2014-01-23  0:13       ` Scott Wood
2014-01-19 23:44 ` Alexander Graf [this message]
2014-01-23  0:23   ` [Qemu-devel] [PATCH 10/10] PPC: e500: Move to u-boot as firmware Scott Wood
2014-01-23 10:40     ` Alexander Graf
2014-01-23 22:22       ` Scott Wood

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=1390175077-5717-11-git-send-email-agraf@suse.de \
    --to=agraf@suse.de \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).