Skip to contentSkip to conversation

Mac99: Enable -kernel option

PATCH In review Alexander Graf 3 participants 4 messages Feb 28, 2009 – Mar 2, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Mac99: Enable -kernel option

Right now -kernel on the Mac99 (newworld) is broken.

For starters, the kernel is 1:1 mapped into to virtual machine, which is not what OpenBIOS expects - it wants a preprocessed ELF image. So I just copied over the code from oldworld.c that loads the kernel.

While this is not overly pretty, it works so far and keeps working code working. I don't feel comfortable on restructuring newworld and oldworld just yet - AFAIK newworld is not exactly is a good shape anyways.

The second issue is the NVRAM. It doesn't get initialized, so the firmware has no idea that a kernel image was actually loaded!

I first tried to use the macio nvram device that was specified there, but that didn't work out, so in order to get something working for now, I took the code from oldworld.c again, which works at least with OpenBIOS.

Using this patch I can use -kernel on the Mac99 machine.

---
 hw/ppc_newworld.c |   40 ++++++++++++++++++++++++++++++++++++++--
 1 files changed, 38 insertions(+), 2 deletions(-)
hw/ppc_newworld.c +38 -2
index 6f60e49..a086f33 100644
@@ -94,6 +94,8 @@ static void ppc_core99_init (ram_addr_t ram_size, int vga_ram_size,
     uint32_t kernel_base, kernel_size, initrd_base, initrd_size;
     PCIBus *pci_bus;
     MacIONVRAMState *nvr;
+    nvram_t nvram;
+    m48t59_t *m48t59;
     int nvram_mem_index;
     int vga_bios_size, bios_size;
     qemu_irq *dummy_irq;
@@ -166,9 +168,23 @@ static void ppc_core99_init (ram_addr_t ram_size, int vga_ram_size,
     }
 
     if (linux_boot) {
+        uint64_t lowaddr = 0;
         kernel_base = KERNEL_LOAD_ADDR;
-        /* now we can load the kernel */
-        kernel_size = load_image(kernel_filename, phys_ram_base + kernel_base);
+        /* Now we can load the kernel. The first step tries to load the kernel
+           supposing PhysAddr = 0x00000000. If that was wrong the kernel is
+           loaded again, the new PhysAddr being computed from lowaddr. */
+        kernel_size = load_elf(kernel_filename, kernel_base, NULL, &lowaddr, NULL);
+        if (kernel_size > 0 && lowaddr != KERNEL_LOAD_ADDR) {
+            kernel_size = load_elf(kernel_filename, (2 * kernel_base) - lowaddr,
+                                   NULL, 0, NULL);
+        }
+        if (kernel_size < 0)
+            kernel_size = load_aout(kernel_filename, kernel_base,
+                                    ram_size - kernel_base);
+        if (kernel_size < 0)
+            kernel_size = load_image_targphys(kernel_filename,
+                                              kernel_base,
+                                              ram_size - kernel_base);
         if (kernel_size < 0) {
             cpu_abort(env, "qemu: could not load kernel '%s'\n",
                       kernel_filename);
@@ -313,7 +329,27 @@ static void ppc_core99_init (ram_addr_t ram_size, int vga_ram_size,
     /* The NewWorld NVRAM is not located in the MacIO device */
     nvr = macio_nvram_init(&nvram_mem_index, 0x2000, 1);
     pmac_format_nvram_partition(nvr, 0x2000);
+# if 0
     macio_nvram_map(nvr, 0xFFF04000);
+
+    nvram.opaque = nvr;
+    nvram.read_fn = &macio_nvram_read;
+    nvram.write_fn = &macio_nvram_write;
+#else
+    m48t59 = m48t59_init(0, 0xFFF04000, 0x0074, NVRAM_SIZE, 59);
+    nvram.opaque = m48t59;
+    nvram.read_fn = &m48t59_read;
+    nvram.write_fn = &m48t59_write;
+#endif
+    PPC_NVRAM_set_params(&nvram, NVRAM_SIZE, "MAC99", ram_size,
+                         ppc_boot_device, kernel_base, kernel_size,
+                         kernel_cmdline,
+                         initrd_base, initrd_size,
+                         /* XXX: need an option to load a NVRAM image */
+                         0,
+                         graphic_width, graphic_height, graphic_depth);
+
+
     /* No PCI init: the BIOS will do it */
 
     fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
Signature · 1 line
1.5.3.1
#1 lore raw
Quoted 10 lines · Alexander Graf

Right now -kernel on the Mac99 (newworld) is broken.

For starters, the kernel is 1:1 mapped into to virtual machine, which is not what OpenBIOS expects - it wants a preprocessed ELF image. So I just copied over the code from oldworld.c that loads the kernel.

While this is not overly pretty, it works so far and keeps working code working. I don't feel comfortable on restructuring newworld and oldworld just yet - AFAIK newworld is not exactly is a good shape anyways.

Quoted 7 lines

The second issue is the NVRAM. It doesn't get initialized, so the firmware has no idea that a kernel image was actually loaded!

I first tried to use the macio nvram device that was specified there, but that didn't work out, so in order to get something working for now, I took the code from oldworld.c again, which works at least with OpenBIOS.

There have been some discussions to switch to using the firmware configuration device for the kernel address etc. Then the NVRAM structure would not be used. These patches (by Aurelien and myself) should do the switch.

From 882a7849423b57fb3a56f12d2e9c600e37d27f49 Mon Sep 17 00:00:00 2001
From: Aurelien Jarno <[email protected]>
Date: Mon, 19 Jan 2009 12:26:07 +0100
Subject: [PATCH] Add new entries to firmware configuration device

---
 include/openbios/fw_cfg.h |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
include/openbios/fw_cfg.h +6 -0
Index: openbios-quilt/include/openbios/fw_cfg.h
===================================================================
@@ -8,6 +8,12 @@
 #define FW_CFG_NOGRAPHIC        0x04
 #define FW_CFG_NB_CPUS          0x05
 #define FW_CFG_MACHINE_ID       0x06
+#define FW_CFG_KERNEL_ADDR      0x07
+#define FW_CFG_KERNEL_SIZE      0x08
+#define FW_CFG_KERNEL_CMDLINE   0x09
+#define FW_CFG_INITRD_ADDR      0x0a
+#define FW_CFG_INITRD_SIZE      0x0b
+#define FW_CFG_BOOT_DEVICE      0x0c
 #define FW_CFG_MAX_ENTRY        0x10
 
 #define FW_CFG_WRITE_CHANNEL    0x4000

From 5240984ea3425201cdcd4d5062524239613e929e Mon Sep 17 00:00:00 2001
From: Aurelien Jarno <[email protected]>
Date: Mon, 19 Jan 2009 12:27:28 +0100
Subject: [PATCH] PowerPC: Use firmware configuration instead of NVRAM

---
 arch/ppc/qemu/main.c |   45 ++++++++++++++-------------------------------
 1 files changed, 14 insertions(+), 31 deletions(-)
arch/ppc/qemu/main.c +15 -31

81 lines not on this page · raw message

arch/sparc64/openbios.c +15 -17
Index: openbios-quilt/arch/sparc64/openbios.c
===================================================================
@@ -15,9 +15,6 @@
 #include "openbios.h"
 #include "openbios/pci.h"
 #include "asm/pci.h"
-#include "libc/byteorder.h"
-#define cpu_to_be16(x) __cpu_to_be16(x)
-#include "openbios/firmware_abi.h"
 #include "boot.h"
 #include "../../drivers/timer.h" // XXX
 #define NO_QEMU_PROTOS
@@ -42,11 +39,9 @@
 #define NVRAM_SIZE       0x2000
 #define NVRAM_IDPROM     0x1fd8
 #define NVRAM_IDPROM_SIZE 32
-#define NVRAM_OB_START   (sizeof(ohwcfg_v3_t) + sizeof(struct sparc_arch_cfg))
+#define NVRAM_OB_START   (0)
 #define NVRAM_OB_SIZE    ((0x1fd0 - NVRAM_OB_START) & ~15)
 
-static ohwcfg_v3_t nv_info;
-
 #define OBIO_CMDLINE_MAX 256
 static char obio_cmdline[OBIO_CMDLINE_MAX];
 
@@ -275,7 +270,7 @@
 
 void arch_nvram_get(char *data)
 {
-    uint32_t size;
+    uint32_t size = 0;
     const struct cpudef *cpu;
     const char *bootpath;
     char buf[256];
@@ -284,8 +279,7 @@
     uint32_t clock_frequency;
     uint16_t machine_id;
     const char *stdin_path, *stdout_path;
-
-    nvram_read(0, (char *)&nv_info, sizeof(ohwcfg_v3_t));
+    const char *kernel_cmdline;
 
     fw_cfg_init();
 
@@ -304,16 +298,20 @@
         for(;;);
     }
 
-    kernel_image = nv_info.kernel_image;
-    kernel_size = nv_info.kernel_size;
-    size = nv_info.cmdline_size;
-    if (size > OBIO_CMDLINE_MAX - 1)
-        size = OBIO_CMDLINE_MAX - 1;
-    memcpy(&obio_cmdline, (void *)(long)nv_info.cmdline, size);
+    kernel_size = fw_cfg_read_i32(FW_CFG_KERNEL_SIZE);
+    if (kernel_size)
+        kernel_image = fw_cfg_read_i64(FW_CFG_KERNEL_ADDR);
+    kernel_cmdline = (const char *) fw_cfg_read_i64(FW_CFG_KERNEL_CMDLINE);
+    if (kernel_cmdline) {
+        size = strlen(kernel_cmdline);
+        if (size > OBIO_CMDLINE_MAX - 1)
+            size = OBIO_CMDLINE_MAX - 1;
+        memcpy(&obio_cmdline, kernel_cmdline, size);
+    }
     obio_cmdline[size] = '\0';
     qemu_cmdline = (uint64_t)obio_cmdline;
     cmdline_size = size;
-    boot_device = nv_info.boot_devices[0];
+    boot_device = fw_cfg_read_i16(FW_CFG_BOOT_DEVICE);
 
     if (kernel_size)
         printk("kernel addr %llx size %llx\n", kernel_image, kernel_size);
@@ -372,7 +370,7 @@
     push_str("/chosen");
     fword("find-device");
 
-    if (nv_info.boot_devices[0] == 'c')
+    if (boot_device == 'c')
         bootpath = "disk:a";
     else
         bootpath = "cdrom:a";
drivers/obio.c +14 -19
Index: openbios-quilt/drivers/obio.c
===================================================================
@@ -20,8 +20,6 @@
 #include "openbios/nvram.h"
 #include "ofmem.h"
 #include "obio.h"
-#define cpu_to_be16(x) __cpu_to_be16(x)
-#include "openbios/firmware_abi.h"
 #define NO_QEMU_PROTOS
 #include "openbios/fw_cfg.h"
 #include "escc.h"
@@ -157,9 +155,8 @@
 }
 
 static unsigned char *nvram;
-static ohwcfg_v3_t nv_info;
 
-#define NVRAM_OB_START   (sizeof(ohwcfg_v3_t) + sizeof(struct sparc_arch_cfg))
+#define NVRAM_OB_START   (0)
 #define NVRAM_OB_SIZE    ((NVRAM_IDPROM - NVRAM_OB_START) & ~15)
 
 void
@@ -654,14 +651,14 @@
     const char *stdin, *stdout;
     unsigned int i;
     char nographic;
-    uint32_t size;
+    uint32_t size = 0;
     uint16_t machine_id;
     const struct cpudef *cpu;
     const struct machdef *mach;
-    ohwcfg_v3_t *header;
     char buf[256];
     uint32_t temp;
     phandle_t chosen;
+    const char *kernel_cmdline;
 
     ob_new_obio_device("eeprom", NULL);
 
@@ -694,23 +691,21 @@
         for(;;);
     }
 
-    memcpy(&nv_info, nvram, sizeof(nv_info));
-    kernel_image = nv_info.kernel_image;
-    kernel_size = nv_info.kernel_size;
-    size = nv_info.cmdline_size;
-    if (size > OBIO_CMDLINE_MAX - 1)
-        size = OBIO_CMDLINE_MAX - 1;
-    memcpy(&obio_cmdline, (void *)(long)nv_info.cmdline, size);
+    kernel_size = fw_cfg_read_i32(FW_CFG_KERNEL_SIZE);
+    if (kernel_size)
+        kernel_image = fw_cfg_read_i32(FW_CFG_KERNEL_ADDR);
+    kernel_cmdline = (const char *) fw_cfg_read_i32(FW_CFG_KERNEL_CMDLINE);
+    if (kernel_cmdline) {
+        size = strlen(kernel_cmdline);
+        if (size > OBIO_CMDLINE_MAX - 1)
+            size = OBIO_CMDLINE_MAX - 1;
+        memcpy(&obio_cmdline, kernel_cmdline, size);
+    }
     obio_cmdline[size] = '\0';
     qemu_cmdline = (uint32_t) &obio_cmdline;
     cmdline_size = size;
-    header = (ohwcfg_v3_t *)nvram;
-    header->kernel_image = 0;
-    header->kernel_size = 0;
-    header->cmdline_size = 0;
-    header->crc = OHW_compute_crc(header, 0x00, 0xF8);
+    boot_device = fw_cfg_read_i16(FW_CFG_BOOT_DEVICE);
 
-    boot_device = nv_info.boot_devices[0];
     fw_cfg_read(FW_CFG_NOGRAPHIC, &nographic, 1);
     graphic_depth = fw_cfg_read_i16(FW_CFG_SUN4M_DEPTH);
 
include/openbios/firmware_abi.h +0 -127

137 lines not on this page · raw message

From 2773ba2d13501c9effeebfcec59893de5f8e613e Mon Sep 17 00:00:00 2001
From: Aurelien Jarno <[email protected]>
Date: Mon, 19 Jan 2009 12:26:50 +0100
Subject: [PATCH] Add new entries to firmware configuration device

---
 hw/fw_cfg.h |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
hw/fw_cfg.h +6 -0
Index: qemu/hw/fw_cfg.h
===================================================================
@@ -8,6 +8,12 @@
 #define FW_CFG_NOGRAPHIC        0x04
 #define FW_CFG_NB_CPUS          0x05
 #define FW_CFG_MACHINE_ID       0x06
+#define FW_CFG_KERNEL_ADDR      0x07
+#define FW_CFG_KERNEL_SIZE      0x08
+#define FW_CFG_KERNEL_CMDLINE   0x09
+#define FW_CFG_INITRD_ADDR      0x0a
+#define FW_CFG_INITRD_SIZE      0x0b
+#define FW_CFG_BOOT_DEVICE      0x0c
 #define FW_CFG_MAX_ENTRY        0x10
 
 #define FW_CFG_WRITE_CHANNEL    0x4000

From 90bfa18110cb3997a00af1673e2780272cb5ddee Mon Sep 17 00:00:00 2001
From: Aurelien Jarno <[email protected]>
Date: Mon, 19 Jan 2009 12:28:17 +0100
Subject: [PATCH] ppc_oldworld: Use firmware configuration instead of NVRAM

---
 hw/ppc_mac.h      |    1 +
 hw/ppc_oldworld.c |   26 ++++++++++++--------------
 2 files changed, 13 insertions(+), 14 deletions(-)
hw/ppc_mac.h +1 -0
Index: qemu/hw/ppc_mac.h
===================================================================
@@ -35,6 +35,7 @@
 #define PROM_ADDR         0xfff00000
 
 #define KERNEL_LOAD_ADDR 0x01000000
+#define CMDLINE_ADDR     0x017ff000
 #define INITRD_LOAD_ADDR 0x01800000
 
 #define ESCC_CLOCK 3686400
hw/ppc_oldworld.c +12 -14
Index: qemu/hw/ppc_oldworld.c
===================================================================
@@ -118,8 +118,6 @@
     CPUState *env = NULL, *envs[MAX_CPUS];
     char buf[1024];
     qemu_irq *pic, **heathrow_irqs;
-    nvram_t nvram;
-    m48t59_t *m48t59;
     int linux_boot, i;
     ram_addr_t ram_offset, vga_ram_offset, bios_offset, vga_bios_offset;
     uint32_t kernel_base, initrd_base;
@@ -129,7 +127,7 @@
     int vga_bios_size, bios_size;
     int pic_mem_index, nvram_mem_index, dbdma_mem_index, cuda_mem_index;
     int escc_mem_index, ide_mem_index[2];
-    int ppc_boot_device;
+    uint16_t ppc_boot_device;
     BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
     int index;
     void *fw_cfg;
@@ -364,23 +362,23 @@
     if (graphic_depth != 15 && graphic_depth != 32 && graphic_depth != 8)
         graphic_depth = 15;
 
-    m48t59 = m48t59_init(0, 0xFFF04000, 0x0074, NVRAM_SIZE, 59);
-    nvram.opaque = m48t59;
-    nvram.read_fn = &m48t59_read;
-    nvram.write_fn = &m48t59_write;
-    PPC_NVRAM_set_params(&nvram, NVRAM_SIZE, "HEATHROW", ram_size,
-                         ppc_boot_device, kernel_base, kernel_size,
-                         kernel_cmdline,
-                         initrd_base, initrd_size,
-                         /* XXX: need an option to load a NVRAM image */
-                         0,
-                         graphic_width, graphic_height, graphic_depth);
     /* No PCI init: the BIOS will do it */
 
     fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
     fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
     fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
     fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, ARCH_HEATHROW);
+    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, kernel_base);
+    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
+    if (kernel_cmdline) {
+        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
+        strcpy((char *)(phys_ram_base + CMDLINE_ADDR), kernel_cmdline);
+    } else {
+        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
+    }
+    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_base);
+    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size);
+    fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, ppc_boot_device);
 }
 
 QEMUMachine heathrow_machine = {
hw/sun4m.c +38 -56

134 lines not on this page · raw message

hw/sun4u.c +14 -59

101 lines not on this page · raw message

hw/firmware_abi.h +0 -127

137 lines not on this page · raw message

hw/ppc_newworld.c +11 -0
Index: qemu/hw/ppc_newworld.c
===================================================================
@@ -320,6 +320,17 @@
     fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
     fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
     fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, ARCH_MAC99);
+    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, kernel_base);
+    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
+    if (kernel_cmdline) {
+        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
+        strcpy((char *)(phys_ram_base + CMDLINE_ADDR), kernel_cmdline);
+    } else {
+        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
+    }
+    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_base);
+    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size);
+    fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, ppc_boot_device);
 }
 
 QEMUMachine core99_machine = {
#2 lore raw
Quoted 19 lines · Blue Swirl
Quoted 10 lines · Alexander Graf

Right now -kernel on the Mac99 (newworld) is broken.

For starters, the kernel is 1:1 mapped into to virtual machine, which is not what OpenBIOS expects - it wants a preprocessed ELF image. So I just copied over the code from oldworld.c that loads the kernel.

While this is not overly pretty, it works so far and keeps working code working. I don't feel comfortable on restructuring newworld and oldworld just yet - AFAIK newworld is not exactly is a good shape anyways.

Quoted 7 lines

The second issue is the NVRAM. It doesn't get initialized, so the firmware has no idea that a kernel image was actually loaded!

I first tried to use the macio nvram device that was specified there, but that didn't work out, so in order to get something working for now, I took the code from oldworld.c again, which works at least with OpenBIOS.

Quoted 4 lines

There have been some discussions to switch to using the firmware configuration device for the kernel address etc. Then the NVRAM structure would not be used. These patches (by Aurelien and myself) should do the switch.

I wanted to work a bit on those patches, but never found the time to do that. The best is to commit them as they are know, as they are already an improvement. They can be improved later.

Signature · 2 lines
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#3 lore raw
Quoted 26 lines · Aurelien Jarno
Quoted 19 lines · Blue Swirl
Quoted 10 lines · Alexander Graf

Right now -kernel on the Mac99 (newworld) is broken.

For starters, the kernel is 1:1 mapped into to virtual machine, which is not what OpenBIOS expects - it wants a preprocessed ELF image. So I just copied over the code from oldworld.c that loads the kernel.

While this is not overly pretty, it works so far and keeps working code working. I don't feel comfortable on restructuring newworld and oldworld just yet - AFAIK newworld is not exactly is a good shape anyways.

Quoted 7 lines

The second issue is the NVRAM. It doesn't get initialized, so the firmware has no idea that a kernel image was actually loaded!

I first tried to use the macio nvram device that was specified there, but that didn't work out, so in order to get something working for now, I took the code from oldworld.c again, which works at least with OpenBIOS.

Quoted 4 lines

There have been some discussions to switch to using the firmware configuration device for the kernel address etc. Then the NVRAM structure would not be used. These patches (by Aurelien and myself) should do the switch.

Quoted 3 lines

I wanted to work a bit on those patches, but never found the time to do
that. The best is to commit them as they are know, as they are already an improvement. They can be improved later.

Maybe, though I'd hate to update the OpenBIOS images just after the release.

I think there was also some doubt whether the configuration device is suitable for kernel/initrd stuff.