qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Vivier <laurent@vivier.eu>
To: qemu-devel@nongnu.org
Cc: Laurent Vivier <laurent@vivier.eu>
Subject: [PATCH 2/3] m68k: virt: add a bootstrap ROM
Date: Wed,  2 Feb 2022 23:35:27 +0100	[thread overview]
Message-ID: <20220202223528.1260154-3-laurent@vivier.eu> (raw)
In-Reply-To: <20220202223528.1260154-1-laurent@vivier.eu>

This ROM will be started by QEMU and will load the firmware.
The firware will be based on Petit Boot, the aim of the bootstrap
is to ask QEMU to load the kernel and initramfs to the RAM.

It also builds the bootinfo structure to pass to the kernel the
same way QEMU does when it loads directly the kernel.

To build the bootstrap:
$ git submodule init roms/m68k-virt
$ git submodule updage roms/m68k-virt
$ make -C roms m68k-virt-bootrom

Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 hw/m68k/virt.c      | 32 ++++++++++++++++++++++++++++++++
 .gitmodules         |  3 +++
 pc-bios/meson.build |  1 +
 roms/Makefile       |  7 +++++++
 roms/m68k-virt      |  1 +
 5 files changed, 44 insertions(+)
 create mode 160000 roms/m68k-virt

diff --git a/hw/m68k/virt.c b/hw/m68k/virt.c
index bbaf630bbf20..11aff6d93865 100644
--- a/hw/m68k/virt.c
+++ b/hw/m68k/virt.c
@@ -10,6 +10,7 @@
 #include "qemu/osdep.h"
 #include "qemu/units.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "sysemu/sysemu.h"
 #include "cpu.h"
 #include "hw/boards.h"
@@ -85,6 +86,13 @@
 #define VIRT_VIRTIO_MMIO_BASE 0xff010000     /* MMIO: 0xff010000 - 0xff01ffff */
 #define VIRT_VIRTIO_IRQ_BASE  PIC_IRQ(2, 1)  /* PIC: 2, 3, 4, 5, IRQ: ALL */
 
+/*
+ * At the end of the memory address space we have a 1 MB ROM
+ */
+#define VIRT_ROM_ADDR 0xfff00000
+#define VIRT_ROM_SIZE 0x00100000
+#define VIRT_ROM_NAME "m68k-virt.rom"
+
 typedef struct {
     M68kCPU *cpu;
     hwaddr initial_pc;
@@ -113,12 +121,16 @@ static void virt_init(MachineState *machine)
     const char *kernel_filename = machine->kernel_filename;
     const char *initrd_filename = machine->initrd_filename;
     const char *kernel_cmdline = machine->kernel_cmdline;
+    const char *bios_name = machine->firmware ?: VIRT_ROM_NAME;
     hwaddr parameters_base;
     DeviceState *dev;
     DeviceState *irqc_dev;
     DeviceState *pic_dev[VIRT_GF_PIC_NB];
     SysBusDevice *sysbus;
     hwaddr io_base;
+    MemoryRegion *rom;
+    int bios_size;
+    char *filename;
     int i;
     ResetInfo *reset_info;
 
@@ -207,6 +219,19 @@ static void virt_init(MachineState *machine)
         io_base += 0x200;
     }
 
+    /* Load ROM */
+    filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
+    if (filename) {
+        rom = g_malloc(sizeof(*rom));
+        memory_region_init_rom(rom, NULL, "m68k-virt.rom", VIRT_ROM_SIZE,
+                           &error_abort);
+        memory_region_add_subregion(get_system_memory(), VIRT_ROM_ADDR, rom);
+        bios_size = load_image_targphys(filename, VIRT_ROM_ADDR, VIRT_ROM_SIZE);
+    } else {
+        bios_size = -1;
+    }
+
+    /* Load kernel if needed */
     if (kernel_filename) {
         CPUState *cs = CPU(cpu);
         uint64_t high;
@@ -265,6 +290,13 @@ static void virt_init(MachineState *machine)
             initrd_size = 0;
         }
         BOOTINFO0(cs->as, parameters_base, BI_LAST);
+    } else {
+        if (bios_size != VIRT_ROM_SIZE) {
+            error_report("ROM not found (%s) and no kernel provided",
+                         bios_name);
+            exit(EXIT_FAILURE);
+        }
+        reset_info->initial_pc = VIRT_ROM_ADDR;
     }
 }
 
diff --git a/.gitmodules b/.gitmodules
index 84425d87e28a..315d597d057a 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -67,3 +67,6 @@
 [submodule "tests/lcitool/libvirt-ci"]
 	path = tests/lcitool/libvirt-ci
 	url = http://gitlab.com/libvirt/libvirt-ci
+[submodule "roms/m68k-virt"]
+	path = roms/m68k-virt
+	url = https://github.com/vivier/m68k-virt-bootstrap.git
diff --git a/pc-bios/meson.build b/pc-bios/meson.build
index 4ac7a5509b69..ffec6decdc4c 100644
--- a/pc-bios/meson.build
+++ b/pc-bios/meson.build
@@ -81,6 +81,7 @@ blobs = files(
   'opensbi-riscv32-generic-fw_dynamic.bin',
   'opensbi-riscv64-generic-fw_dynamic.bin',
   'npcm7xx_bootrom.bin',
+  'm68k-virt.rom',
 )
 
 if get_option('install_blobs')
diff --git a/roms/Makefile b/roms/Makefile
index 5e44d9789001..f9f84e8efb1b 100644
--- a/roms/Makefile
+++ b/roms/Makefile
@@ -40,6 +40,7 @@ powerpc_cross_prefix := $(call find-cross-prefix,powerpc)
 x86_64_cross_prefix := $(call find-cross-prefix,x86_64)
 riscv32_cross_prefix := $(call find-cross-prefix,riscv32)
 riscv64_cross_prefix := $(call find-cross-prefix,riscv64)
+m68k_cross_prefix := $(call find-cross-prefix,m68k)
 
 # tag our seabios builds
 SEABIOS_EXTRAVERSION="-prebuilt.qemu.org"
@@ -69,6 +70,7 @@ default help:
 	@echo "  opensbi32-generic  -- update OpenSBI for 32-bit generic machine"
 	@echo "  opensbi64-generic  -- update OpenSBI for 64-bit generic machine"
 	@echo "  qboot              -- update qboot"
+	@echo "  m68k-virt-bootrom  -- update m68k-virt bootrom"
 	@echo "  clean              -- delete the files generated by the previous" \
 	                              "build targets"
 
@@ -197,6 +199,10 @@ npcm7xx_bootrom:
 	$(MAKE) -C vbootrom CROSS_COMPILE=$(arm_cross_prefix)
 	cp vbootrom/npcm7xx_bootrom.bin ../pc-bios/npcm7xx_bootrom.bin
 
+m68k-virt-bootrom:
+	$(MAKE) -C m68k-virt CROSS_COMPILE=$(m68k_cross_prefix)
+	cp m68k-virt/rom.bin ../pc-bios/m68k-virt.rom
+
 clean:
 	rm -rf seabios/.config seabios/out seabios/builds
 	$(MAKE) -C sgabios clean
@@ -211,3 +217,4 @@ clean:
 	$(MAKE) -C opensbi clean
 	$(MAKE) -C qboot clean
 	$(MAKE) -C vbootrom clean
+	$(MAKE) -C m68k-virt clean
diff --git a/roms/m68k-virt b/roms/m68k-virt
new file mode 160000
index 000000000000..f2a4daa7cd11
--- /dev/null
+++ b/roms/m68k-virt
@@ -0,0 +1 @@
+Subproject commit f2a4daa7cd11d35fa48236653211897b50977144
-- 
2.34.1



  parent reply	other threads:[~2022-02-02 22:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-02 22:35 [PATCH 0/3] m68k: virt: add a firmware to the virt machine (petit boot) Laurent Vivier
2022-02-02 22:35 ` [PATCH 1/3] m68k: bootinfo entry size must be aligned on 4 bytes Laurent Vivier
2022-02-02 22:35 ` Laurent Vivier [this message]
2022-02-02 23:27   ` [PATCH 2/3] m68k: virt: add a bootstrap ROM Philippe Mathieu-Daudé via
2022-02-02 22:35 ` [PATCH 3/3] m68k: virt: add a firmware (petitboot) Laurent Vivier

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=20220202223528.1260154-3-laurent@vivier.eu \
    --to=laurent@vivier.eu \
    --cc=qemu-devel@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).