[PATCH v2 3/4] board: Add QEMU m68k virt board support
Kuan-Wei Chiu
visitorckw at gmail.com
Fri Dec 26 18:53:59 CET 2025
Add support for the QEMU 'virt' machine on the m68k architecture. This
board emulates a generic machine based on the Motorola 68040 CPU
equipped with Goldfish virtual peripherals.
Introduce the necessary board configuration and initialization
infrastructure. The implementation includes logic to parse the QEMU
bootinfo interface, enabling dynamic detection of system RAM size to
adapt to the virtual machine's configuration.
Enable the Goldfish TTY driver to provide a serial console, which
facilitates interaction when running QEMU with the -nographic option.
Additionally, include comprehensive documentation covering build
instructions and usage examples to guide users in deploying U-Boot
within the virtualization environment.
Signed-off-by: Kuan-Wei Chiu <visitorckw at gmail.com>
---
Changes in v2:
- Update SPDX license identifier to GPL-2.0-or-later.
- Sort header inclusions alphabetically.
- Fix tabs vs spaces in MAINTAINERS.
- Add qemu-m68k entry to doc/board/emulation/index.rst.
- Regenerate defconfig using make savedefconfig.
arch/m68k/Kconfig | 8 +++
board/emulation/qemu-m68k/Kconfig | 12 ++++
board/emulation/qemu-m68k/MAINTAINERS | 8 +++
board/emulation/qemu-m68k/Makefile | 5 ++
board/emulation/qemu-m68k/qemu-m68k.c | 84 +++++++++++++++++++++++++++
configs/qemu-m68k_defconfig | 12 ++++
doc/board/emulation/index.rst | 1 +
doc/board/emulation/qemu-m68k.rst | 38 ++++++++++++
include/configs/qemu-m68k.h | 18 ++++++
9 files changed, 186 insertions(+)
create mode 100644 board/emulation/qemu-m68k/Kconfig
create mode 100644 board/emulation/qemu-m68k/MAINTAINERS
create mode 100644 board/emulation/qemu-m68k/Makefile
create mode 100644 board/emulation/qemu-m68k/qemu-m68k.c
create mode 100644 configs/qemu-m68k_defconfig
create mode 100644 doc/board/emulation/qemu-m68k.rst
create mode 100644 include/configs/qemu-m68k.h
diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig
index de7c673c376..605ae5ec20c 100644
--- a/arch/m68k/Kconfig
+++ b/arch/m68k/Kconfig
@@ -183,6 +183,13 @@ config TARGET_STMARK2
select CF_DSPI
select M54418
+config TARGET_QEMU_M68K
+ bool "Support QEMU m68k virt"
+ select M68040
+ help
+ This target supports the QEMU m68k virtual machine (-M virt).
+ It simulates a Motorola 68040 CPU with Goldfish peripherals.
+
endchoice
config SYS_CPU
@@ -208,6 +215,7 @@ source "board/freescale/m5329evb/Kconfig"
source "board/freescale/m5373evb/Kconfig"
source "board/sysam/amcore/Kconfig"
source "board/sysam/stmark2/Kconfig"
+source "board/emulation/qemu-m68k/Kconfig"
config M68K_QEMU
bool "Build with workarounds for incomplete QEMU emulation"
diff --git a/board/emulation/qemu-m68k/Kconfig b/board/emulation/qemu-m68k/Kconfig
new file mode 100644
index 00000000000..aae6dfe400f
--- /dev/null
+++ b/board/emulation/qemu-m68k/Kconfig
@@ -0,0 +1,12 @@
+if TARGET_QEMU_M68K
+
+config SYS_BOARD
+ default "qemu-m68k"
+
+config SYS_VENDOR
+ default "emulation"
+
+config SYS_CONFIG_NAME
+ default "qemu-m68k"
+
+endif
diff --git a/board/emulation/qemu-m68k/MAINTAINERS b/board/emulation/qemu-m68k/MAINTAINERS
new file mode 100644
index 00000000000..90414c58465
--- /dev/null
+++ b/board/emulation/qemu-m68k/MAINTAINERS
@@ -0,0 +1,8 @@
+QEMU M68K VIRT BOARD
+M: Kuan-Wei Chiu <visitorckw at gmail.com>
+S: Maintained
+F: board/emulation/qemu-m68k/
+F: board/emulation/common/
+F: include/configs/qemu-m68k.h
+F: configs/qemu-m68k_defconfig
+F: doc/board/emulation/qemu-m68k.rst
diff --git a/board/emulation/qemu-m68k/Makefile b/board/emulation/qemu-m68k/Makefile
new file mode 100644
index 00000000000..5cb2886ff5a
--- /dev/null
+++ b/board/emulation/qemu-m68k/Makefile
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# Copyright (C) 2025, Kuan-Wei Chiu <visitorckw at gmail.com>
+
+obj-y += qemu-m68k.o
diff --git a/board/emulation/qemu-m68k/qemu-m68k.c b/board/emulation/qemu-m68k/qemu-m68k.c
new file mode 100644
index 00000000000..89e66050bb9
--- /dev/null
+++ b/board/emulation/qemu-m68k/qemu-m68k.c
@@ -0,0 +1,84 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2025, Kuan-Wei Chiu <visitorckw at gmail.com>
+ */
+
+#include <asm-generic/sections.h>
+#include <asm/bootinfo.h>
+#include <asm/global_data.h>
+#include <asm/io.h>
+#include <config.h>
+#include <dm/platdata.h>
+#include <goldfish_tty.h>
+#include <init.h>
+#include <linux/errno.h>
+#include <serial.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/* QEMU Virt Machine Hardware Map */
+#define VIRT_GF_TTY_MMIO_BASE 0xff008000
+#define VIRT_CTRL_MMIO_BASE 0xff009000
+#define VIRT_CTRL_RESET 0x01
+
+int board_early_init_f(void)
+{
+ return 0;
+}
+
+int checkboard(void)
+{
+ puts("Board: QEMU m68k virt\n");
+ return 0;
+}
+
+int dram_init(void)
+{
+ struct bi_record *record;
+ ulong addr;
+
+ /* Default: 16MB */
+ gd->ram_size = 0x01000000;
+
+ /* QEMU places bootinfo after _end, aligned to 2 bytes */
+ addr = (ulong)&_end;
+ if (addr & 1)
+ addr++;
+
+ record = (struct bi_record *)addr;
+
+ if (record->tag != BI_MACHTYPE)
+ return 0;
+
+ while (record->tag != BI_LAST) {
+ if (record->tag == BI_MEMCHUNK) {
+ gd->ram_size = record->data[1];
+ break;
+ }
+ record = (struct bi_record *)((ulong)record + record->size);
+ }
+
+ return 0;
+}
+
+void reset_cpu(unsigned long addr)
+{
+ writel(VIRT_CTRL_RESET, VIRT_CTRL_MMIO_BASE);
+ while (1)
+ ;
+}
+
+int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+{
+ reset_cpu(0);
+ return 0;
+}
+
+static const struct goldfish_tty_plat serial_plat = {
+ .base = (void __iomem *)VIRT_GF_TTY_MMIO_BASE,
+};
+
+U_BOOT_DRVINFO(goldfish_serial) = {
+ .name = "serial_goldfish",
+ .plat = &serial_plat,
+};
diff --git a/configs/qemu-m68k_defconfig b/configs/qemu-m68k_defconfig
new file mode 100644
index 00000000000..db6c9b1c771
--- /dev/null
+++ b/configs/qemu-m68k_defconfig
@@ -0,0 +1,12 @@
+CONFIG_M68K=y
+CONFIG_TEXT_BASE=0x00000000
+CONFIG_SYS_MALLOC_LEN=0x20000
+CONFIG_SYS_MALLOC_F_LEN=0x2000
+CONFIG_SYS_MONITOR_LEN=262144
+CONFIG_SYS_BOOTM_LEN=0x1000000
+CONFIG_SYS_LOAD_ADDR=0x00000000
+CONFIG_TARGET_QEMU_M68K=y
+# CONFIG_DISPLAY_BOARDINFO is not set
+CONFIG_BOARD_EARLY_INIT_F=y
+CONFIG_DM_SERIAL=y
+CONFIG_SERIAL_GOLDFISH=y
diff --git a/doc/board/emulation/index.rst b/doc/board/emulation/index.rst
index f8908166276..4f7c812d493 100644
--- a/doc/board/emulation/index.rst
+++ b/doc/board/emulation/index.rst
@@ -15,6 +15,7 @@ Emulation
qemu-sbsa
qemu-x86
qemu-xtensa
+ qemu-m68k
Also see
diff --git a/doc/board/emulation/qemu-m68k.rst b/doc/board/emulation/qemu-m68k.rst
new file mode 100644
index 00000000000..36e51e8107f
--- /dev/null
+++ b/doc/board/emulation/qemu-m68k.rst
@@ -0,0 +1,38 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+.. Copyright (C) 2025, Kuan-Wei Chiu <visitorckw at gmail.com>
+
+QEMU m68k
+=========
+
+QEMU for m68k supports a special 'virt' machine designed for emulation and
+virtualization purposes. This document describes how to run U-Boot under it.
+
+The QEMU virt machine models a generic m68k virtual machine with Goldfish
+interfaces. It supports the Motorola 68040 CPU architecture.
+
+Building U-Boot
+---------------
+Set the CROSS_COMPILE environment variable to your m68k toolchain, and run:
+
+.. code-block:: bash
+
+ export CROSS_COMPILE=m68k-linux-gnu-
+ make qemu-m68k_defconfig
+ make
+
+Running U-Boot
+--------------
+The minimal QEMU command line to get U-Boot up and running is:
+
+.. code-block:: bash
+
+ qemu-system-m68k -M virt -cpu m68040 -nographic -kernel u-boot
+
+Note that the `-nographic` option is used to redirect the console to stdio,
+which connects to the emulated Goldfish TTY device.
+
+Hardware Support
+----------------
+The following QEMU virt peripherals are supported in U-Boot:
+
+* Goldfish TTY (Serial Console)
diff --git a/include/configs/qemu-m68k.h b/include/configs/qemu-m68k.h
new file mode 100644
index 00000000000..1d8aa92fe80
--- /dev/null
+++ b/include/configs/qemu-m68k.h
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2025, Kuan-Wei Chiu <visitorckw at gmail.com>
+ */
+
+#ifndef __QEMU_M68K_H
+#define __QEMU_M68K_H
+
+/* Memory Configuration */
+#define CFG_SYS_SDRAM_BASE 0x00000000
+
+/*
+ * Initial Stack Pointer:
+ * Place the stack at 4MB offset to avoid overwriting U-Boot code/data.
+ */
+#define CFG_SYS_INIT_SP_ADDR (CFG_SYS_SDRAM_BASE + 0x400000)
+
+#endif /* __QEMU_M68K_H */
--
2.52.0.358.g0dd7633a29-goog
More information about the U-Boot
mailing list