Skip to contentSkip to conversation

m68k: Add support for QEMU virt machine

PATCH Superseded Kuan-Wei Chiu 5 participants 18 messages Dec 30, 2025 – Dec 31, 2025

Subsystems (2)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v3 cover m68k: Add support for QEMU virt machine

Add support for the QEMU 'virt' machine on the m68k architecture. The QEMU virt machine models a generic system utilizing Goldfish virtual peripherals and is capable of emulating various classic 68k CPUs.

Currently, U-Boot's m68k architecture support focuses on ColdFire variants. Expand this to include the classic M680x0 architecture, implementing the necessary exception vectors, startup code, and a bootinfo parser compatible with the QEMU interface. A driver for the Goldfish TTY is also added to enable serial console output.

The implementation has been verified on QEMU targeting the M68040 CPU, confirming successful hardware initialization and boot to the U-Boot command shell. Additionally, the CI configuration was verified locally using gitlab-ci-local "qemu_m68k_virt test.py", resulting in PASS qemu_m68k_virt test.py.
---
Changes in v3:
- Add Goldfish timer driver.
- Update Goldfish RTC driver to support non-DT probing.
- Enable Goldfish RTC and Timer support in board configuration.
- Add safety loop limit to bootinfo parsing in dram_init.
- Remove dummy timer functions from architecture code.
- Remove unnecessary type casts in Goldfish TTY driver.
- Remove TEST_PY_ID from CI job definitions.
- Update documentation to include new RTC support.

Changes in v2:
- Refactor Goldfish TTY driver to use priv data for the RX buffer and ensure single-byte reads.
- Rename arch/m68k/cpu/m68040 to arch/m68k/cpu/m680x0 to separate the architecture family from the specific CPU model.
- Introduce M680x0 Kconfig symbol and separate MAINTAINERS entries for the architecture and the board.
- Regenerate qemu-m68k_defconfig using make savedefconfig and add the board to the documentation index.
- Add a new patch to enable CI testing on GitLab and Azure Pipelines.
- Update SPDX identifiers to GPL-2.0-or-later.
- Sort headers alphabetically.
- Fix tabs vs spaces.

v2: https://lore.kernel.org/u-boot/[email protected]/
v1: https://lore.kernel.org/u-boot/[email protected]/

Kuan-Wei Chiu (6):
serial: Add Goldfish TTY driver
timer: Add Goldfish timer driver
rtc: goldfish: Support platform data for non-DT probing
m68k: Add support for M68040 CPU
board: Add QEMU m68k virt board support
CI: Add test jobs for QEMU m68k virt machine

 .azure-pipelines.yml                  |   3 +
 .gitlab-ci.yml                        |   6 ++
 MAINTAINERS                           |  18 ++++
 arch/m68k/Kconfig                     |  24 ++++++
 arch/m68k/Makefile                    |   1 +
 arch/m68k/config.mk                   |  10 ++-
 arch/m68k/cpu/m680x0/Makefile         |   6 ++
 arch/m68k/cpu/m680x0/cpu.c            |  72 ++++++++++++++++
 arch/m68k/cpu/m680x0/start.S          |  73 ++++++++++++++++
 arch/m68k/cpu/m680x0/u-boot.lds       |  47 +++++++++++
 arch/m68k/include/asm/bootinfo.h      |  31 +++++++
 arch/m68k/lib/Makefile                |   9 +-
 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 | 115 ++++++++++++++++++++++++++
 configs/qemu-m68k_defconfig           |  16 ++++
 doc/board/emulation/index.rst         |   1 +
 doc/board/emulation/qemu-m68k.rst     |  39 +++++++++
 drivers/rtc/goldfish_rtc.c            |  10 ++-
 drivers/serial/Kconfig                |   8 ++
 drivers/serial/Makefile               |   1 +
 drivers/serial/serial_goldfish.c      | 102 +++++++++++++++++++++++
 drivers/timer/Kconfig                 |   8 ++
 drivers/timer/Makefile                |   1 +
 drivers/timer/goldfish_timer.c        |  60 ++++++++++++++
 include/configs/qemu-m68k.h           |  18 ++++
 include/goldfish_rtc.h                |  15 ++++
 include/goldfish_timer.h              |  13 +++
 include/goldfish_tty.h                |  18 ++++
 30 files changed, 740 insertions(+), 10 deletions(-)
 create mode 100644 arch/m68k/cpu/m680x0/Makefile
 create mode 100644 arch/m68k/cpu/m680x0/cpu.c
 create mode 100644 arch/m68k/cpu/m680x0/start.S
 create mode 100644 arch/m68k/cpu/m680x0/u-boot.lds
 create mode 100644 arch/m68k/include/asm/bootinfo.h
 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 drivers/serial/serial_goldfish.c
 create mode 100644 drivers/timer/goldfish_timer.c
 create mode 100644 include/configs/qemu-m68k.h
 create mode 100644 include/goldfish_rtc.h
 create mode 100644 include/goldfish_timer.h
 create mode 100644 include/goldfish_tty.h
Signature · 1 line
2.52.0.358.g0dd7633a29-goog
#1 lore raw

PATCH v3 1/6 serial: Add Goldfish TTY driver

Add support for the Google Goldfish TTY serial device. This virtual device is commonly used in QEMU virtual machines (such as the m68k virt machine) and Android emulators.

The driver implements basic console output and input polling using the Goldfish MMIO interface.

---
Changes in v3:
- Remove unnecessary type casts for MMIO register access.

 MAINTAINERS                      |   6 ++
 drivers/serial/Kconfig           |   8 +++
 drivers/serial/Makefile          |   1 +
 drivers/serial/serial_goldfish.c | 102 +++++++++++++++++++++++++++++++
 include/goldfish_tty.h           |  18 ++++++
 5 files changed, 135 insertions(+)
 create mode 100644 drivers/serial/serial_goldfish.c
 create mode 100644 include/goldfish_tty.h
MAINTAINERS +6 -0
index 6ce0bbce13d..da4a6e4d518 100644
@@ -1259,6 +1259,12 @@ S:	Maintained
 F:	drivers/misc/gsc.c
 F:	include/gsc.h
 
+GOLDFISH SERIAL DRIVER
+M:	Kuan-Wei Chiu <[email protected]>
+S:	Maintained
+F:	drivers/serial/serial_goldfish.c
+F:	include/goldfish_tty.h
+
 I2C
 M:	Heiko Schocher <[email protected]>
 S:	Maintained
drivers/serial/Kconfig +8 -0
index 371d7aa5bba..b84cb9ec781 100644
@@ -1193,4 +1193,12 @@ config SYS_SDMR
 	depends on MPC8XX_CONS
 	default 0x0
 
+config SERIAL_GOLDFISH
+	bool "Goldfish TTY support"
+	depends on DM_SERIAL
+	help
+	  Select this to enable support for the Goldfish TTY serial port.
+	  This virtual device is commonly used by QEMU virtual machines
+	  (e.g. m68k virt) for console output.
+
 endif
drivers/serial/Makefile +1 -0
index 8eaae62b0fc..fe8d23be512 100644
@@ -63,3 +63,4 @@ obj-$(CONFIG_XTENSA_SEMIHOSTING_SERIAL) += serial_xtensa_semihosting.o
 obj-$(CONFIG_S5P4418_PL011_SERIAL) += serial_s5p4418_pl011.o
 
 obj-$(CONFIG_UART4_SERIAL) += serial_adi_uart4.o
+obj-$(CONFIG_SERIAL_GOLDFISH) += serial_goldfish.o
drivers/serial/serial_goldfish.c new file +102 -0

102 lines not on this page · raw message

include/goldfish_tty.h new file +18 -0
new file mode 100644
index 00000000000..8777da4942d
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2025, Kuan-Wei Chiu <[email protected]>
+ */
+
+#ifndef _GOLDFISH_TTY_H_
+#define _GOLDFISH_TTY_H_
+
+#include <linux/types.h>
+
+/* Platform data for the Goldfish TTY driver
+ * Used to pass hardware base address from Board to Driver
+ */
+struct goldfish_tty_plat {
+	void __iomem *base;
+};
+
+#endif /* _GOLDFISH_TTY_H_ */
Signature · 1 line
2.52.0.358.g0dd7633a29-goog
Reviewed-by on v3 1/6
#2 lore raw

Re: [PATCH v3 1/6] serial: Add Goldfish TTY driver

Quoted 12 lines · Kuan-Wei Chiu

Add support for the Google Goldfish TTY serial device. This virtual device is commonly used in QEMU virtual machines (such as the m68k virt machine) and Android emulators.

The driver implements basic console output and input polling using the Goldfish MMIO interface.

---
Changes in v3:
- Remove unnecessary type casts for MMIO register access.

Quoted 8 lines
 MAINTAINERS                      |   6 ++
 drivers/serial/Kconfig           |   8 +++
 drivers/serial/Makefile          |   1 +
 drivers/serial/serial_goldfish.c | 102 +++++++++++++++++++++++++++++++
 include/goldfish_tty.h           |  18 ++++++
 5 files changed, 135 insertions(+)
 create mode 100644 drivers/serial/serial_goldfish.c
 create mode 100644 include/goldfish_tty.h

This version looks good to me,

Tested-by on v3 1/6
#3 lore raw

Re: [PATCH v3 1/6] serial: Add Goldfish TTY driver

In reply to Kuan-Wei Chiu

Hi Kuan-Wei,

Quoted 9 lines · Kuan-Wei Chiu

Add support for the Google Goldfish TTY serial device. This virtual device is commonly used in QEMU virtual machines (such as the m68k virt machine) and Android emulators.

The driver implements basic console output and input polling using the Goldfish MMIO interface.

Tested that this works as expected for the console.

#4 lore raw

Re: [PATCH v3 1/6] serial: Add Goldfish TTY driver

In reply to Kuan-Wei Chiu
Quoted 138 lines · Kuan-Wei Chiu

Add support for the Google Goldfish TTY serial device. This virtual device is commonly used in QEMU virtual machines (such as the m68k virt machine) and Android emulators.

The driver implements basic console output and input polling using the Goldfish MMIO interface.

---
Changes in v3:
- Remove unnecessary type casts for MMIO register access.

  MAINTAINERS                      |   6 ++
  drivers/serial/Kconfig           |   8 +++
  drivers/serial/Makefile          |   1 +
  drivers/serial/serial_goldfish.c | 102 +++++++++++++++++++++++++++++++
  include/goldfish_tty.h           |  18 ++++++
  5 files changed, 135 insertions(+)

create mode 100644 drivers/serial/serial_goldfish.c create mode 100644 include/goldfish_tty.h

MAINTAINERS +6 -0
index 6ce0bbce13d..da4a6e4d518 100644
@@ -1259,6 +1259,12 @@ S:	Maintained
  F:	drivers/misc/gsc.c
  F:	include/gsc.h
 
+GOLDFISH SERIAL DRIVER
+M:	Kuan-Wei Chiu <[email protected]>
+S:	Maintained
+F:	drivers/serial/serial_goldfish.c
+F:	include/goldfish_tty.h
+
  I2C
  M:	Heiko Schocher <[email protected]>
  S:	Maintained
drivers/serial/Kconfig +8 -0
index 371d7aa5bba..b84cb9ec781 100644
@@ -1193,4 +1193,12 @@ config SYS_SDMR
  	depends on MPC8XX_CONS
  	default 0x0
 
+config SERIAL_GOLDFISH
+	bool "Goldfish TTY support"
+	depends on DM_SERIAL
+	help
+	  Select this to enable support for the Goldfish TTY serial port.
+	  This virtual device is commonly used by QEMU virtual machines
+	  (e.g. m68k virt) for console output.
+
  endif
drivers/serial/Makefile +1 -0
index 8eaae62b0fc..fe8d23be512 100644
@@ -63,3 +63,4 @@ obj-$(CONFIG_XTENSA_SEMIHOSTING_SERIAL) += serial_xtensa_semihosting.o
  obj-$(CONFIG_S5P4418_PL011_SERIAL) += serial_s5p4418_pl011.o
 
  obj-$(CONFIG_UART4_SERIAL) += serial_adi_uart4.o
+obj-$(CONFIG_SERIAL_GOLDFISH) += serial_goldfish.o
drivers/serial/serial_goldfish.c new file +68 -0
new file mode 100644
index 00000000000..1d2977d809d
@@ -0,0 +1,102 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2025, Kuan-Wei Chiu <[email protected]>
+ * Goldfish TTY driver for U-Boot
+ */
+
+#include <asm/io.h>
+#include <dm.h>
+#include <goldfish_tty.h>
+#include <linux/types.h>
+#include <serial.h>
+
+/* Goldfish TTY Register Offsets */
+#define GOLDFISH_TTY_PUT_CHAR       0x00
+#define GOLDFISH_TTY_BYTES_READY    0x04
+#define GOLDFISH_TTY_CMD            0x08
+#define GOLDFISH_TTY_DATA_PTR       0x10
+#define GOLDFISH_TTY_DATA_LEN       0x14
+#define GOLDFISH_TTY_DATA_PTR_HIGH  0x18
+#define GOLDFISH_TTY_VERSION        0x20
+
+/* Commands */
+#define CMD_WRITE_BUFFER   2
+#define CMD_READ_BUFFER    3
+
+struct goldfish_tty_priv {
+	void __iomem *base;
+	u8 rx_buf;
+};
+
+static int goldfish_serial_getc(struct udevice *dev)
+{
+	struct goldfish_tty_priv *priv = dev_get_priv(dev);
+	unsigned long paddr;
+	u32 count;
+
+	count = __raw_readl(priv->base + GOLDFISH_TTY_BYTES_READY);
+	if (count == 0)
+		return -EAGAIN;
+
+	paddr = virt_to_phys((void *)&priv->rx_buf);
+
+	__raw_writel(0, priv->base + GOLDFISH_TTY_DATA_PTR_HIGH);
+	__raw_writel(paddr, priv->base + GOLDFISH_TTY_DATA_PTR);
+	__raw_writel(1, priv->base + GOLDFISH_TTY_DATA_LEN);
+	__raw_writel(CMD_READ_BUFFER, priv->base + GOLDFISH_TTY_CMD);
+
+	return priv->rx_buf;
+}
+
+static int goldfish_serial_putc(struct udevice *dev, const char ch)
+{
+	struct goldfish_tty_priv *priv = dev_get_priv(dev);
+
+	__raw_writel(ch, priv->base + GOLDFISH_TTY_PUT_CHAR);
+
+	return 0;
+}
+
+static int goldfish_serial_pending(struct udevice *dev, bool input)
+{
+	struct goldfish_tty_priv *priv = dev_get_priv(dev);
+
+	if (input)
+		return __raw_readl(priv->base + GOLDFISH_TTY_BYTES_READY);
+
+	return 0;
+}

drivers/serial/serial_goldfish.c line 78

Quoted 10 lines
drivers/serial/serial_goldfish.c new file +10 -0
+
+static int goldfish_serial_probe(struct udevice *dev)
+{
+	struct goldfish_tty_priv *priv = dev_get_priv(dev);
+	struct goldfish_tty_plat *plat = dev_get_plat(dev);
+
+	if (!plat)
+		return -EINVAL;
+
+	priv->base = plat->base;

The Linux binding documentation in Documentation/devicetree/bindings/goldfish/tty.txt has this example:

        goldfish_tty@1f004000 {
                compatible = "google,goldfish-tty";
                reg = <0x1f004000 0x1000>;
                interrupts = <0xc>;
        };

The driver should take the reg value as address and use plat->base only as fallback for devices that don't provide a proper device-tree.

We already do this for the RTC driver. Please, apply the same logic to all Goldfish drivers.

Best regards

Heinrich

Quoted 48 lines
drivers/serial/serial_goldfish.c new file +24 -0
+
+	return 0;
+}
+
+static const struct dm_serial_ops goldfish_serial_ops = {
+	.putc = goldfish_serial_putc,
+	.pending = goldfish_serial_pending,
+	.getc = goldfish_serial_getc,
+};
+
+static const struct udevice_id goldfish_serial_ids[] = {
+	{ .compatible = "google,goldfish-tty" },
+	{ }
+};
+
+U_BOOT_DRIVER(serial_goldfish) = {
+	.name	= "serial_goldfish",
+	.id	= UCLASS_SERIAL,
+	.of_match = goldfish_serial_ids,
+	.probe	= goldfish_serial_probe,
+	.ops	= &goldfish_serial_ops,
+	.priv_auto = sizeof(struct goldfish_tty_priv),
+	.flags	= DM_FLAG_PRE_RELOC,
+};
include/goldfish_tty.h new file +18 -0
new file mode 100644
index 00000000000..8777da4942d
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2025, Kuan-Wei Chiu <[email protected]>
+ */
+
+#ifndef _GOLDFISH_TTY_H_
+#define _GOLDFISH_TTY_H_
+
+#include <linux/types.h>
+
+/* Platform data for the Goldfish TTY driver
+ * Used to pass hardware base address from Board to Driver
+ */
+struct goldfish_tty_plat {
+	void __iomem *base;
+};
+
+#endif /* _GOLDFISH_TTY_H_ */
#5 lore raw

Re: [PATCH v3 1/6] serial: Add Goldfish TTY driver

Hi Heinrich,

Quoted 156 lines · Heinrich Schuchardt
Quoted 135 lines · Kuan-Wei Chiu

Add support for the Google Goldfish TTY serial device. This virtual device is commonly used in QEMU virtual machines (such as the m68k virt machine) and Android emulators.

The driver implements basic console output and input polling using the Goldfish MMIO interface.

---
Changes in v3:
- Remove unnecessary type casts for MMIO register access.

  MAINTAINERS                      |   6 ++
  drivers/serial/Kconfig           |   8 +++
  drivers/serial/Makefile          |   1 +
  drivers/serial/serial_goldfish.c | 102 +++++++++++++++++++++++++++++++
  include/goldfish_tty.h           |  18 ++++++
  5 files changed, 135 insertions(+)

create mode 100644 drivers/serial/serial_goldfish.c create mode 100644 include/goldfish_tty.h

MAINTAINERS +6 -0
index 6ce0bbce13d..da4a6e4d518 100644
@@ -1259,6 +1259,12 @@ S:	Maintained
  F:	drivers/misc/gsc.c
  F:	include/gsc.h
+GOLDFISH SERIAL DRIVER
+M:	Kuan-Wei Chiu <[email protected]>
+S:	Maintained
+F:	drivers/serial/serial_goldfish.c
+F:	include/goldfish_tty.h
+
  I2C
  M:	Heiko Schocher <[email protected]>
  S:	Maintained
drivers/serial/Kconfig +8 -0
index 371d7aa5bba..b84cb9ec781 100644
@@ -1193,4 +1193,12 @@ config SYS_SDMR
  	depends on MPC8XX_CONS
  	default 0x0
+config SERIAL_GOLDFISH
+	bool "Goldfish TTY support"
+	depends on DM_SERIAL
+	help
+	  Select this to enable support for the Goldfish TTY serial port.
+	  This virtual device is commonly used by QEMU virtual machines
+	  (e.g. m68k virt) for console output.
+
  endif
drivers/serial/Makefile +1 -0
index 8eaae62b0fc..fe8d23be512 100644
@@ -63,3 +63,4 @@ obj-$(CONFIG_XTENSA_SEMIHOSTING_SERIAL) += serial_xtensa_semihosting.o
  obj-$(CONFIG_S5P4418_PL011_SERIAL) += serial_s5p4418_pl011.o
  obj-$(CONFIG_UART4_SERIAL) += serial_adi_uart4.o
+obj-$(CONFIG_SERIAL_GOLDFISH) += serial_goldfish.o
drivers/serial/serial_goldfish.c new file +68 -0
new file mode 100644
index 00000000000..1d2977d809d
@@ -0,0 +1,102 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2025, Kuan-Wei Chiu <[email protected]>
+ * Goldfish TTY driver for U-Boot
+ */
+
+#include <asm/io.h>
+#include <dm.h>
+#include <goldfish_tty.h>
+#include <linux/types.h>
+#include <serial.h>
+
+/* Goldfish TTY Register Offsets */
+#define GOLDFISH_TTY_PUT_CHAR       0x00
+#define GOLDFISH_TTY_BYTES_READY    0x04
+#define GOLDFISH_TTY_CMD            0x08
+#define GOLDFISH_TTY_DATA_PTR       0x10
+#define GOLDFISH_TTY_DATA_LEN       0x14
+#define GOLDFISH_TTY_DATA_PTR_HIGH  0x18
+#define GOLDFISH_TTY_VERSION        0x20
+
+/* Commands */
+#define CMD_WRITE_BUFFER   2
+#define CMD_READ_BUFFER    3
+
+struct goldfish_tty_priv {
+	void __iomem *base;
+	u8 rx_buf;
+};
+
+static int goldfish_serial_getc(struct udevice *dev)
+{
+	struct goldfish_tty_priv *priv = dev_get_priv(dev);
+	unsigned long paddr;
+	u32 count;
+
+	count = __raw_readl(priv->base + GOLDFISH_TTY_BYTES_READY);
+	if (count == 0)
+		return -EAGAIN;
+
+	paddr = virt_to_phys((void *)&priv->rx_buf);
+
+	__raw_writel(0, priv->base + GOLDFISH_TTY_DATA_PTR_HIGH);
+	__raw_writel(paddr, priv->base + GOLDFISH_TTY_DATA_PTR);
+	__raw_writel(1, priv->base + GOLDFISH_TTY_DATA_LEN);
+	__raw_writel(CMD_READ_BUFFER, priv->base + GOLDFISH_TTY_CMD);
+
+	return priv->rx_buf;
+}
+
+static int goldfish_serial_putc(struct udevice *dev, const char ch)
+{
+	struct goldfish_tty_priv *priv = dev_get_priv(dev);
+
+	__raw_writel(ch, priv->base + GOLDFISH_TTY_PUT_CHAR);
+
+	return 0;
+}
+
+static int goldfish_serial_pending(struct udevice *dev, bool input)
+{
+	struct goldfish_tty_priv *priv = dev_get_priv(dev);
+
+	if (input)
+		return __raw_readl(priv->base + GOLDFISH_TTY_BYTES_READY);
+
+	return 0;
+}

drivers/serial/serial_goldfish.c line 78

Quoted 10 lines
drivers/serial/serial_goldfish.c new file +10 -0
+
+static int goldfish_serial_probe(struct udevice *dev)
+{
+	struct goldfish_tty_priv *priv = dev_get_priv(dev);
+	struct goldfish_tty_plat *plat = dev_get_plat(dev);
+
+	if (!plat)
+		return -EINVAL;
+
+	priv->base = plat->base;

The Linux binding documentation in Documentation/devicetree/bindings/goldfish/tty.txt has this example:

        goldfish_tty@1f004000 {
                compatible = "google,goldfish-tty";
                reg = <0x1f004000 0x1000>;
                interrupts = <0xc>;
        };
Quoted 5 lines

The driver should take the reg value as address and use plat->base only as fallback for devices that don't provide a proper device-tree.

We already do this for the RTC driver. Please, apply the same logic to all Goldfish drivers.

Agreed.
Will do this for both tty and timer drivers in the next version.

Regards,
Kuan-Wei

#6 lore raw

PATCH v3 2/6 timer: Add Goldfish timer driver

In reply to Kuan-Wei Chiu

Add support for the Goldfish timer driver. This driver utilizes the Goldfish RTC hardware to provide a nanosecond-resolution timer. This virtual device is commonly found in QEMU virtual machines (such as the m68k virt machine) and Android emulators.

The driver implements the standard U-Boot timer UCLASS interface, exposing a 64-bit monotonically increasing counter with a 1GHz clock rate derived from the RTC registers.

---
Changes in v3:
- New patch.

The link provided by Daniel [1] returned a 404 error. Since the implementation is straightforward, I wrote this driver from scratch.

[1]: https://github.com/fifteenhex/u-boot/blob/mc68000/drivers/rtc/goldfish_timer.c

 MAINTAINERS                    |  6 ++++
 drivers/timer/Kconfig          |  8 +++++
 drivers/timer/Makefile         |  1 +
 drivers/timer/goldfish_timer.c | 60 ++++++++++++++++++++++++++++++++++
 include/goldfish_timer.h       | 13 ++++++++
 5 files changed, 88 insertions(+)
 create mode 100644 drivers/timer/goldfish_timer.c
 create mode 100644 include/goldfish_timer.h
MAINTAINERS +6 -0
index da4a6e4d518..fcc437a53ce 100644
@@ -1265,6 +1265,12 @@ S:	Maintained
 F:	drivers/serial/serial_goldfish.c
 F:	include/goldfish_tty.h
 
+GOLDFISH TIMER DRIVER
+M:	Kuan-Wei Chiu <[email protected]>
+S:	Maintained
+F:	drivers/timer/goldfish_timer.c
+F:	include/goldfish_timer.h
+
 I2C
 M:	Heiko Schocher <[email protected]>
 S:	Maintained
drivers/timer/Kconfig +8 -0
index f9511503b02..a84a0dc0539 100644
@@ -340,4 +340,12 @@ config STARFIVE_TIMER
 	  Select this to enable support for the timer found on
 	  Starfive SoC.
 
+config GOLDFISH_TIMER
+	bool "Goldfish Timer support"
+	depends on TIMER
+	help
+	  Select this to enable support for the Goldfish Timer.
+	  It uses the Goldfish RTC hardware to provide a nanosecond-resolution
+	  timer, commonly found in QEMU virt machines.
+
 endmenu
drivers/timer/Makefile +1 -0
index a72e411fb2f..d8b3f2b65d4 100644
@@ -36,3 +36,4 @@ obj-$(CONFIG_MCHP_PIT64B_TIMER)	+= mchp-pit64b-timer.o
 obj-$(CONFIG_IMX_GPT_TIMER)	+= imx-gpt-timer.o
 obj-$(CONFIG_XILINX_TIMER)	+= xilinx-timer.o
 obj-$(CONFIG_STARFIVE_TIMER)	+= starfive-timer.o
+obj-$(CONFIG_GOLDFISH_TIMER)	+= goldfish_timer.o
drivers/timer/goldfish_timer.c new file +60 -0

60 lines not on this page · raw message

include/goldfish_timer.h new file +13 -0
new file mode 100644
index 00000000000..2ea28170759
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2025, Kuan-Wei Chiu <[email protected]>
+ */
+
+#ifndef _GOLDFISH_TIMER_H_
+#define _GOLDFISH_TIMER_H_
+
+struct goldfish_timer_plat {
+	void __iomem *base;
+};
+
+#endif /* _GOLDFISH_TIMER_H_ */
Signature · 1 line
2.52.0.358.g0dd7633a29-goog
Tested-by on v3 2/6
#7 lore raw

Re: [PATCH v3 2/6] timer: Add Goldfish timer driver

Hi Kuan-Wei,

Quoted 10 lines · Kuan-Wei Chiu

Add support for the Goldfish timer driver. This driver utilizes the Goldfish RTC hardware to provide a nanosecond-resolution timer. This virtual device is commonly found in QEMU virtual machines (such as the m68k virt machine) and Android emulators.

The driver implements the standard U-Boot timer UCLASS interface, exposing a 64-bit monotonically increasing counter with a 1GHz clock rate derived from the RTC registers.

Quoted 6 lines

The link provided by Daniel [1] returned a 404 error.
Since the implementation is straightforward, I wrote this driver from scratch.
[1]: https://github.com/fifteenhex/u-boot/blob/mc68000/drivers/rtc/goldfish_timer.c

Oops, I moved it and force pushed. Sorry about that.

Works as expected.

Reviewed-by on v3 2/6
#8 lore raw

Re: [PATCH v3 2/6] timer: Add Goldfish timer driver

In reply to Kuan-Wei Chiu
Quoted 19 lines · Kuan-Wei Chiu

Add support for the Goldfish timer driver. This driver utilizes the Goldfish RTC hardware to provide a nanosecond-resolution timer. This virtual device is commonly found in QEMU virtual machines (such as the m68k virt machine) and Android emulators.

The driver implements the standard U-Boot timer UCLASS interface, exposing a 64-bit monotonically increasing counter with a 1GHz clock rate derived from the RTC registers.

---
Changes in v3:
- New patch.

The link provided by Daniel [1] returned a 404 error. Since the implementation is straightforward, I wrote this driver from scratch.

[1]: https://github.com/fifteenhex/u-boot/blob/mc68000/drivers/rtc/goldfish_timer.c

...

Quoted 8 lines
drivers/timer/goldfish_timer.c new file +2 -0
new file mode 100644
index 00000000000..8205ac77853
@@ -0,0 +1,60 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*

drivers/timer/goldfish_timer.c line 12

Quoted 10 lines
drivers/timer/goldfish_timer.c new file +10 -0
+ * Copyright (C) 2025, Kuan-Wei Chiu <[email protected]>
+ *
+ * Goldfish Timer driver
+ */
+
+#include <dm.h>
+#include <timer.h>
+#include <asm/io.h>
+#include <linux/errno.h>
+#include <goldfish_timer.h>

Sort the headers?

Quoted 6 lines
drivers/timer/goldfish_timer.c new file +6 -0
+/* Goldfish RTC registers used as Timer */
+#define TIMER_TIME_LOW	0x00
+#define TIMER_TIME_HIGH	0x04
+
+static u64 goldfish_timer_get_count(struct udevice *dev)
+{

drivers/timer/goldfish_timer.c line 29

Quoted 10 lines
drivers/timer/goldfish_timer.c new file +10 -0
+	struct goldfish_timer_plat *plat = dev_get_plat(dev);
+	u32 low, high;
+	u64 time;
+
+	/*
+	 * Goldfish RTC provides time in nanoseconds.
+	 * We read the high 32-bits and low 32-bits to construct the 64-bit value.
+	 */
+	low = readl(plat->base + TIMER_TIME_LOW);
+	high = readl(plat->base + TIMER_TIME_HIGH);

It may be worth a comment to point out that the value of TIMER_TIME_HIGH only updates when TIMER_TIME_LOW is read, so it's impossible to read out teared values (higher half has been updated after lower half is read).

drivers/timer/goldfish_timer.c line 34

Quoted 4 lines
drivers/timer/goldfish_timer.c new file +4 -0
+	time = ((u64)high << 32) | low;
+
+	return time;
+}

With the header sorted,

Regards,
Yao Zi

#9 lore raw

Re: [PATCH v3 2/6] timer: Add Goldfish timer driver

Hi Yao,

Quoted 35 lines · Yao Zi
Quoted 19 lines · Kuan-Wei Chiu

Add support for the Goldfish timer driver. This driver utilizes the Goldfish RTC hardware to provide a nanosecond-resolution timer. This virtual device is commonly found in QEMU virtual machines (such as the m68k virt machine) and Android emulators.

The driver implements the standard U-Boot timer UCLASS interface, exposing a 64-bit monotonically increasing counter with a 1GHz clock rate derived from the RTC registers.

---
Changes in v3:
- New patch.

The link provided by Daniel [1] returned a 404 error. Since the implementation is straightforward, I wrote this driver from scratch.

[1]: https://github.com/fifteenhex/u-boot/blob/mc68000/drivers/rtc/goldfish_timer.c

...

Quoted 12 lines
drivers/timer/goldfish_timer.c new file +6 -0
new file mode 100644
index 00000000000..8205ac77853
@@ -0,0 +1,60 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2025, Kuan-Wei Chiu <[email protected]>
+ *
+ * Goldfish Timer driver
+ */
Quoted 8 lines

drivers/timer/goldfish_timer.c line 12

Quoted 6 lines
drivers/timer/goldfish_timer.c new file +6 -0
+
+#include <dm.h>
+#include <timer.h>
+#include <asm/io.h>
+#include <linux/errno.h>
+#include <goldfish_timer.h>

Sort the headers?

My apologies, I should have remembered that.
I will sort the headers in the next version.

Quoted 13 lines
Quoted 13 lines
drivers/timer/goldfish_timer.c new file +12 -0
+/* Goldfish RTC registers used as Timer */
+#define TIMER_TIME_LOW	0x00
+#define TIMER_TIME_HIGH	0x04
+
+static u64 goldfish_timer_get_count(struct udevice *dev)
+{
+	struct goldfish_timer_plat *plat = dev_get_plat(dev);
+	u32 low, high;
+	u64 time;
+
+	/*
+	 * Goldfish RTC provides time in nanoseconds.
Quoted 8 lines

drivers/timer/goldfish_timer.c line 29

Quoted 4 lines
drivers/timer/goldfish_timer.c new file +4 -0
+	 * We read the high 32-bits and low 32-bits to construct the 64-bit value.
+	 */
+	low = readl(plat->base + TIMER_TIME_LOW);
+	high = readl(plat->base + TIMER_TIME_HIGH);

It may be worth a comment to point out that the value of TIMER_TIME_HIGH only updates when TIMER_TIME_LOW is read, so it's impossible to read out teared values (higher half has been updated after lower half is read).

Agreed.
I will add a comment explaining this.

Quoted 9 lines

drivers/timer/goldfish_timer.c line 34

Quoted 5 lines
drivers/timer/goldfish_timer.c new file +4 -0
+	time = ((u64)high << 32) | low;
+
+	return time;
+}

With the header sorted,

Thanks for the review!

Regards,
Kuan-Wei

#10 lore raw

PATCH v3 3/6 rtc: goldfish: Support platform data for non-DT probing

In reply to Kuan-Wei Chiu

Currently, the Goldfish RTC driver exclusively relies on device tree to retrieve the base address, failing immediately if dev_read_addr() returns FDT_ADDR_T_NONE. This restriction prevents the driver from being used on platforms that instantiate devices via U_BOOT_DRVINFO() instead of device tree, such as the QEMU m68k virt machine.

Add support for platform data to address this limitation. Update the probe function to fall back to retrieving the base address from struct goldfish_rtc_plat if the device tree address is unavailable. Introduce a new header file include/goldfish_rtc.h to define the platform data structure.

---
Changes in v3:
- New patch.

It appears there is no specific maintainer listed for this driver?

 drivers/rtc/goldfish_rtc.c | 10 ++++++++--
 include/goldfish_rtc.h     | 15 +++++++++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)
 create mode 100644 include/goldfish_rtc.h
drivers/rtc/goldfish_rtc.c +8 -2
index e63a2766c76..900daabccb9 100644
@@ -9,6 +9,7 @@
 
 #include <div64.h>
 #include <dm.h>
+#include <goldfish_rtc.h>
 #include <mapmem.h>
 #include <rtc.h>
 #include <linux/io.h>
@@ -77,11 +78,16 @@ static int goldfish_rtc_set(struct udevice *dev, const struct rtc_time *time)
 static int goldfish_rtc_probe(struct udevice *dev)
 {
 	struct goldfish_rtc *priv = dev_get_priv(dev);
+	struct goldfish_rtc_plat *plat;
 	fdt_addr_t addr;
 
 	addr = dev_read_addr(dev);
-	if (addr == FDT_ADDR_T_NONE)
-		return -EINVAL;
+	if (addr == FDT_ADDR_T_NONE) {
+		plat = dev_get_plat(dev);
+		if (!plat)
+			return -EINVAL;
+		addr = (fdt_addr_t)plat->base;
+	}
 	priv->base = map_sysmem(addr, 0x20);
 
 	return 0;
include/goldfish_rtc.h new file +15 -0
new file mode 100644
index 00000000000..bb113a0bd79
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2025, Kuan-Wei Chiu <[email protected]>
+ */
+
+#ifndef _GOLDFISH_RTC_H_
+#define _GOLDFISH_RTC_H_
+
+#include <linux/types.h>
+
+struct goldfish_rtc_plat {
+	void __iomem *base;
+};
+
+#endif /* _GOLDFISH_RTC_H_ */
Signature · 1 line
2.52.0.358.g0dd7633a29-goog
#11 lore raw

Re: [PATCH v3 3/6] rtc: goldfish: Support platform data for non-DT probing

Quoted 41 lines · Kuan-Wei Chiu

Currently, the Goldfish RTC driver exclusively relies on device tree to retrieve the base address, failing immediately if dev_read_addr() returns FDT_ADDR_T_NONE. This restriction prevents the driver from being used on platforms that instantiate devices via U_BOOT_DRVINFO() instead of device tree, such as the QEMU m68k virt machine.

Add support for platform data to address this limitation. Update the probe function to fall back to retrieving the base address from struct goldfish_rtc_plat if the device tree address is unavailable. Introduce a new header file include/goldfish_rtc.h to define the platform data structure.

---
Changes in v3:
- New patch.

It appears there is no specific maintainer listed for this driver?

  drivers/rtc/goldfish_rtc.c | 10 ++++++++--
  include/goldfish_rtc.h     | 15 +++++++++++++++
  2 files changed, 23 insertions(+), 2 deletions(-)

create mode 100644 include/goldfish_rtc.h

drivers/rtc/goldfish_rtc.c +2 -0
index e63a2766c76..900daabccb9 100644
@@ -9,6 +9,7 @@
 
  #include <div64.h>
  #include <dm.h>
+#include <goldfish_rtc.h>
  #include <mapmem.h>
  #include <rtc.h>
  #include <linux/io.h>
@@ -77,11 +78,16 @@ static int goldfish_rtc_set(struct udevice *dev, const struct rtc_time *time)
  static int goldfish_rtc_probe(struct udevice *dev)
  {
  	struct goldfish_rtc *priv = dev_get_priv(dev);
+	struct goldfish_rtc_plat *plat;

drivers/rtc/goldfish_rtc.c static int goldfish_rtc_set(struct udevice *dev, const struct rtc_time *time) · line 89

Quoted 10 lines
drivers/rtc/goldfish_rtc.c +5 -2
  	fdt_addr_t addr;
 
  	addr = dev_read_addr(dev);
-	if (addr == FDT_ADDR_T_NONE)
-		return -EINVAL;
+	if (addr == FDT_ADDR_T_NONE) {
+		plat = dev_get_plat(dev);
+		if (!plat)
+			return -EINVAL;
+		addr = (fdt_addr_t)plat->base;

addr is not a pointer, it is an address in the sandbox virtual memory address space. This is why map_sysmem() is used below.

The suggested code fails to build on sandbox_defconfig with the driver enabled:

drivers/rtc/goldfish_rtc.c: In function ‘goldfish_rtc_probe’:
drivers/rtc/goldfish_rtc.c:89:24: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]

   89 |                 addr = (fdt_addr_t)plat->base;
      |

Please, use

	priv->base = plat->base;

If plat->base is NULL, please, throw -EINVAL.

Best regards

Heinrich

Quoted 25 lines
drivers/rtc/goldfish_rtc.c +1 -0
+	}
  	priv->base = map_sysmem(addr, 0x20);
 
  	return 0;
include/goldfish_rtc.h new file +15 -0
new file mode 100644
index 00000000000..bb113a0bd79
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2025, Kuan-Wei Chiu <[email protected]>
+ */
+
+#ifndef _GOLDFISH_RTC_H_
+#define _GOLDFISH_RTC_H_
+
+#include <linux/types.h>
+
+struct goldfish_rtc_plat {
+	void __iomem *base;
+};
+
+#endif /* _GOLDFISH_RTC_H_ */
#12 lore raw

Re: [PATCH v3 3/6] rtc: goldfish: Support platform data for non-DT probing

Hi Heinrich,

Quoted 60 lines · Heinrich Schuchardt
Quoted 39 lines · Kuan-Wei Chiu

Currently, the Goldfish RTC driver exclusively relies on device tree to retrieve the base address, failing immediately if dev_read_addr() returns FDT_ADDR_T_NONE. This restriction prevents the driver from being used on platforms that instantiate devices via U_BOOT_DRVINFO() instead of device tree, such as the QEMU m68k virt machine.

Add support for platform data to address this limitation. Update the probe function to fall back to retrieving the base address from struct goldfish_rtc_plat if the device tree address is unavailable. Introduce a new header file include/goldfish_rtc.h to define the platform data structure.

---
Changes in v3:
- New patch.

It appears there is no specific maintainer listed for this driver?

  drivers/rtc/goldfish_rtc.c | 10 ++++++++--
  include/goldfish_rtc.h     | 15 +++++++++++++++
  2 files changed, 23 insertions(+), 2 deletions(-)

create mode 100644 include/goldfish_rtc.h

drivers/rtc/goldfish_rtc.c +1 -0
index e63a2766c76..900daabccb9 100644
@@ -9,6 +9,7 @@
  #include <div64.h>
  #include <dm.h>
+#include <goldfish_rtc.h>
  #include <mapmem.h>
  #include <rtc.h>
  #include <linux/io.h>
@@ -77,11 +78,16 @@ static int goldfish_rtc_set(struct udevice *dev, const struct rtc_time *time)
  static int goldfish_rtc_probe(struct udevice *dev)
  {
  	struct goldfish_rtc *priv = dev_get_priv(dev);

drivers/rtc/goldfish_rtc.c static int goldfish_rtc_set(struct udevice *dev, const struct rtc_time *time) · line 88

Quoted 10 lines
drivers/rtc/goldfish_rtc.c +6 -2
+	struct goldfish_rtc_plat *plat;
  	fdt_addr_t addr;
  	addr = dev_read_addr(dev);
-	if (addr == FDT_ADDR_T_NONE)
-		return -EINVAL;
+	if (addr == FDT_ADDR_T_NONE) {
+		plat = dev_get_plat(dev);
+		if (!plat)
+			return -EINVAL;
+		addr = (fdt_addr_t)plat->base;

addr is not a pointer, it is an address in the sandbox virtual memory address space. This is why map_sysmem() is used below.

The suggested code fails to build on sandbox_defconfig with the driver enabled:

drivers/rtc/goldfish_rtc.c: In function ‘goldfish_rtc_probe’:
drivers/rtc/goldfish_rtc.c:89:24: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]

Quoted 8 lines
   89 |                 addr = (fdt_addr_t)plat->base;
      |

Please, use

	priv->base = plat->base;

If plat->base is NULL, please, throw -EINVAL.

My apologies for the oversight.
I agree with your suggestion.

I will update the code to assign plat->base directly to priv->base in the next version. I will also verify the build with sandbox_defconfig to ensure there are no issues.

Regards,
Kuan-Wei

#13 lore raw

PATCH v3 4/6 m68k: Add support for M68040 CPU

In reply to Kuan-Wei Chiu

Add support for the Motorola 68040 architecture. Currently, m68k support in U-Boot is primarily focused on ColdFire variants. Introduce the necessary infrastructure to support the classic M680x0 series, specifically targeting the M68040 as emulated by QEMU.

The implementation includes exception vectors, early startup code, and minimal CPU initialization and relocation stubs. It also defines the standard m68k boot information structure used for passing hardware information to the operating system. To ensure compatibility, ColdFire- specific library objects such as cache and interrupt handling are excluded from the build when M68040 is selected.

Additionally, apply a specific workaround during the early memory reservation stage. Use a manual loop to clear global data instead of the standard memset() function, as utilizing memset() at this point was observed to cause a hang on the QEMU platform.

---
Changes in v3:
- Remove dummy timer functions.

 MAINTAINERS                      |  6 +++
 arch/m68k/Kconfig                | 16 +++++++
 arch/m68k/Makefile               |  1 +
 arch/m68k/config.mk              | 10 ++++-
 arch/m68k/cpu/m680x0/Makefile    |  6 +++
 arch/m68k/cpu/m680x0/cpu.c       | 72 +++++++++++++++++++++++++++++++
 arch/m68k/cpu/m680x0/start.S     | 73 ++++++++++++++++++++++++++++++++
 arch/m68k/cpu/m680x0/u-boot.lds  | 47 ++++++++++++++++++++
 arch/m68k/include/asm/bootinfo.h | 31 ++++++++++++++
 arch/m68k/lib/Makefile           |  9 ++--
 10 files changed, 263 insertions(+), 8 deletions(-)
 create mode 100644 arch/m68k/cpu/m680x0/Makefile
 create mode 100644 arch/m68k/cpu/m680x0/cpu.c
 create mode 100644 arch/m68k/cpu/m680x0/start.S
 create mode 100644 arch/m68k/cpu/m680x0/u-boot.lds
 create mode 100644 arch/m68k/include/asm/bootinfo.h
MAINTAINERS +6 -0
index fcc437a53ce..bfb24fa7bd3 100644
@@ -1312,6 +1312,12 @@ F:	lib/getopt.c
 F:	test/log/
 F:	test/py/tests/test_log.py
 
+M680X0 ARCHITECTURE
+M:	Kuan-Wei Chiu <[email protected]>
+S:	Maintained
+F:	arch/m68k/cpu/m680x0/
+F:	arch/m68k/include/asm/bootinfo.h
+
 MALI DISPLAY PROCESSORS
 M:	Liviu Dudau <[email protected]>
 S:	Supported
arch/m68k/Kconfig +16 -0
index 8ade6f7b9d1..de7c673c376 100644
@@ -56,6 +56,9 @@ config MCF5441x
         select DM_SERIAL
 	bool
 
+config M680x0
+	bool
+
 # processor type
 config M5208
 	bool
@@ -110,6 +113,10 @@ config M54418
 	bool
 	select MCF5441x
 
+config M68040
+	bool
+	select M680x0
+
 # peripherals
 config CF_DSPI
 	bool
@@ -178,6 +185,15 @@ config TARGET_STMARK2
 
 endchoice
 
+config SYS_CPU
+	string
+	default "mcf52x2" if MCF52x2
+	default "mcf523x" if MCF523x
+	default "mcf530x" if MCF530x
+	default "mcf532x" if MCF532x
+	default "mcf5445x" if MCF5445x
+	default "m680x0" if M680x0
+
 source "board/BuS/eb_cpu5282/Kconfig"
 source "board/cobra5272/Kconfig"
 source "board/freescale/m5208evbe/Kconfig"
arch/m68k/Makefile +1 -0
index 4a7960bbeb4..bb57cf9ac63 100644
@@ -17,6 +17,7 @@ cpuflags-$(CONFIG_M5307)	:= -mcpu=5307
 cpuflags-$(CONFIG_MCF5301x)	:= -mcpu=53015 -fPIC
 cpuflags-$(CONFIG_MCF532x)	:= -mcpu=5329 -fPIC
 cpuflags-$(CONFIG_MCF5441x)	:= -mcpu=54418 -fPIC
+cpuflags-$(CONFIG_M68040)	:= -mcpu=68040 -fno-pic
 
 PLATFORM_CPPFLAGS += $(cpuflags-y)
 
arch/m68k/config.mk +8 -2
index 643b7d1d35d..458953f9712 100644
@@ -3,8 +3,14 @@
 # (C) Copyright 2000-2002
 # Wolfgang Denk, DENX Software Engineering, [email protected].
 
-PLATFORM_CPPFLAGS += -D__M68K__ -fPIC
+PLATFORM_CPPFLAGS += -D__M68K__
+ifneq ($(CONFIG_M680x0),y)
+PLATFORM_CPPFLAGS += -fPIC
+endif
 KBUILD_LDFLAGS    += -n -pie
 PLATFORM_RELFLAGS += -ffunction-sections -fdata-sections
-PLATFORM_RELFLAGS += -ffixed-d7 -msep-data
+PLATFORM_RELFLAGS += -ffixed-d7
+ifneq ($(CONFIG_M680x0),y)
+PLATFORM_RELFLAGS += -msep-data
+endif
 LDFLAGS_FINAL     += --gc-sections -pie
arch/m68k/cpu/m680x0/Makefile new file +6 -0
new file mode 100644
index 00000000000..f6e0c9a46c0
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# Copyright (C) 2025, Kuan-Wei Chiu <[email protected]>
+
+extra-y += start.o
+obj-y += cpu.o
arch/m68k/cpu/m680x0/cpu.c new file +72 -0

72 lines not on this page · raw message

arch/m68k/cpu/m680x0/start.S new file +73 -0

73 lines not on this page · raw message

arch/m68k/cpu/m680x0/u-boot.lds new file +47 -0

47 lines not on this page · raw message

arch/m68k/include/asm/bootinfo.h new file +31 -0
new file mode 100644
index 00000000000..3d2ec818257
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2025, Kuan-Wei Chiu <[email protected]>
+ *
+ * Definitions for the m68k bootinfo interface.
+ */
+
+#ifndef _ASM_M68K_BOOTINFO_H
+#define _ASM_M68K_BOOTINFO_H
+
+#ifndef __ASSEMBLY__
+
+struct bi_record {
+	unsigned short tag;        /* tag ID */
+	unsigned short size;       /* size of record (in bytes) */
+	unsigned long data[0];     /* data */
+};
+
+#endif /* __ASSEMBLY__ */
+
+/* Bootinfo Tag IDs */
+#define BI_LAST            0x0000
+#define BI_MACHTYPE        0x0001
+#define BI_CPUTYPE         0x0002
+#define BI_FPUTYPE         0x0003
+#define BI_MMUTYPE         0x0004
+#define BI_MEMCHUNK        0x0005
+#define BI_RAMDISK         0x0006
+#define BI_COMMAND_LINE    0x0007
+
+#endif /* _ASM_M68K_BOOTINFO_H */
arch/m68k/lib/Makefile +3 -6
index 6e1fd938f52..e62de51f260 100644
@@ -7,10 +7,7 @@
 ## if the user asked for it
 lib-$(CONFIG_USE_PRIVATE_LIBGCC) += lshrdi3.o muldi3.o ashldi3.o ashrdi3.o
 
-obj-y	+= bdinfo.o
 obj-$(CONFIG_CMD_BOOTM) += bootm.o
-obj-y	+= cache.o
-obj-y	+= interrupts.o
-obj-y	+= time.o
-obj-y	+= traps.o
-obj-y   += fec.o
+ifndef CONFIG_M680x0
+obj-y += cache.o interrupts.o time.o traps.o bdinfo.o fec.o
+endif
Signature · 1 line
2.52.0.358.g0dd7633a29-goog
#14 lore raw

PATCH v3 5/6 board: Add QEMU m68k virt board support

In reply to Kuan-Wei Chiu

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 for serial console output. Additionally, enable Goldfish RTC and timer drivers to support real-time clock functionality and nanosecond-resolution delays. Include comprehensive documentation covering build instructions and usage examples.

---
Changes in v3:
- Enable Goldfish RTC and timer support.
- Add safety loop limit to dram_init bootinfo parsing.
- Use ALIGN() macro for address alignment.
- Update documentation.

 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 | 115 ++++++++++++++++++++++++++
 configs/qemu-m68k_defconfig           |  16 ++++
 doc/board/emulation/index.rst         |   1 +
 doc/board/emulation/qemu-m68k.rst     |  39 +++++++++
 include/configs/qemu-m68k.h           |  18 ++++
 9 files changed, 222 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
arch/m68k/Kconfig +8 -0
index de7c673c376..605ae5ec20c 100644
@@ -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"
board/emulation/qemu-m68k/Kconfig new file +12 -0
new file mode 100644
index 00000000000..aae6dfe400f
@@ -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
board/emulation/qemu-m68k/MAINTAINERS new file +8 -0
new file mode 100644
index 00000000000..90414c58465
@@ -0,0 +1,8 @@
+QEMU M68K VIRT BOARD
+M:	Kuan-Wei Chiu <[email protected]>
+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
board/emulation/qemu-m68k/Makefile new file +5 -0
new file mode 100644
index 00000000000..5cb2886ff5a
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# Copyright (C) 2025, Kuan-Wei Chiu <[email protected]>
+
+obj-y += qemu-m68k.o
board/emulation/qemu-m68k/qemu-m68k.c new file +115 -0

115 lines not on this page · raw message

configs/qemu-m68k_defconfig new file +16 -0
new file mode 100644
index 00000000000..f9294218429
@@ -0,0 +1,16 @@
+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_RTC=y
+CONFIG_RTC_GOLDFISH=y
+CONFIG_DM_SERIAL=y
+CONFIG_SERIAL_GOLDFISH=y
+CONFIG_TIMER=y
+CONFIG_GOLDFISH_TIMER=y
doc/board/emulation/index.rst +1 -0
index f8908166276..4f7c812d493 100644
@@ -15,6 +15,7 @@ Emulation
    qemu-sbsa
    qemu-x86
    qemu-xtensa
+   qemu-m68k
 
 Also see
 
doc/board/emulation/qemu-m68k.rst new file +39 -0
new file mode 100644
index 00000000000..6c4de54cf6a
@@ -0,0 +1,39 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+.. Copyright (C) 2025, Kuan-Wei Chiu <[email protected]>
+
+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)
+* Goldfish RTC (Real Time Clock)
include/configs/qemu-m68k.h new file +18 -0
new file mode 100644
index 00000000000..1d8aa92fe80
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2025, Kuan-Wei Chiu <[email protected]>
+ */
+
+#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 */
Signature · 1 line
2.52.0.358.g0dd7633a29-goog
Tested-by on v3 5/6
#15 lore raw

Re: [PATCH v3 5/6] board: Add QEMU m68k virt board support

Hi Kuan-Wei,

Quoted 10 lines · Kuan-Wei Chiu

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.

Quoted 6 lines

Enable the Goldfish TTY driver for serial console output. Additionally, enable Goldfish RTC and timer drivers to support real-time clock functionality and nanosecond-resolution delays. Include comprehensive documentation covering build instructions and usage examples.

I have roughly tested this in QEMU and everything seems to work as expected.

If/When this gets merged it'd be nice to get the virtio mmio part integrated next so we can access disk/network.
I think virtio mmio has endian issues in QEMU or u-boot as I had to add code to swap everything to make it work in my version of this. :D

Thanks,

Daniel

#16 lore raw

PATCH v3 6/6 CI: Add test jobs for QEMU m68k virt machine

In reply to Kuan-Wei Chiu

Enable CI testing for the newly introduced QEMU m68k 'virt' board on both GitLab CI and Azure Pipelines. This ensures the new M68040 architecture support is built and booted correctly in the emulated environment.

---
Changes in v3:
- Remove TEST_PY_ID

 .azure-pipelines.yml | 3 +++
 .gitlab-ci.yml       | 6 ++++++
 2 files changed, 9 insertions(+)
.azure-pipelines.yml +3 -0
index e4695f1c55b..f563878b021 100644
@@ -518,6 +518,9 @@ stages:
           TEST_PY_ID: "--id qemu"
           TEST_PY_TEST_SPEC: "not sleep and not efi"
           OVERRIDE: "-a CONFIG_M68K_QEMU=y -a ~CONFIG_MCFTMR"
+        qemu_m68k_virt:
+          TEST_PY_BD: "qemu-m68k"
+          TEST_PY_TEST_SPEC: "not sleep"
         qemu_malta:
           TEST_PY_BD: "malta"
           TEST_PY_ID: "--id qemu"
.gitlab-ci.yml +6 -0
index e7234e003ea..1fc4d1e656d 100644
@@ -408,6 +408,12 @@ qemu_m68k test.py:
     OVERRIDE: "-a CONFIG_M68K_QEMU=y -a ~CONFIG_MCFTMR"
   <<: *buildman_and_testpy_dfn
 
+qemu_m68k_virt test.py:
+  variables:
+    TEST_PY_BD: "qemu-m68k"
+    TEST_PY_TEST_SPEC: "not sleep"
+  <<: *buildman_and_testpy_dfn
+
 qemu_malta test.py:
   variables:
     TEST_PY_BD: "malta"
Signature · 1 line
2.52.0.358.g0dd7633a29-goog
Reviewed-by on v3 6/6
#17 lore raw

Re: [PATCH v3 6/6] CI: Add test jobs for QEMU m68k virt machine

Quoted 6 lines · Kuan-Wei Chiu

Enable CI testing for the newly introduced QEMU m68k 'virt' board on both GitLab CI and Azure Pipelines. This ensures the new M68040 architecture support is built and booted correctly in the emulated environment.

Signature · 1 line
Tom