Skip to contentSkip to conversation

m68k goes DT

RFC PATCH In review Daniel Palmer 6 participants 20 messages Jan 5, 2025 – Mar 5, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover m68k goes DT

Short version:
I want to start converting m68k (including nommu) to use DT for booting so I can add few cool boards I have (e.g. dual 040/060 VME board..). I need ideas, help etc. Maybe if someone converted an m68k machine they are using to DT alongside me this would have some hope of actually happening?

All of my WIP in-progress very messy code etc is here:
https://github.com/fifteenhex/m68kjunk

Longer version:

As of today I have:
- Modern (2024.07) u-boot fork that works on 000/030/040 real hardware/QEMU that supports booting a Linux ELF image. For nommu a FDT blob address is passed via a regiser, for mmu the normal bootinfo is created and the FDT is passed via a bootinfo tag. nommu never used bootinfo and doesn't need to.

- A Linux branch for nommu that removes most of the current DragonBall code, makes it into a devicetree based machine and adds a bunch of drivers etc. This works in a fork of QEMU I have and on the real hardware. The DragonBall even has a working 1bpp framebuffer. The nommu branch also works on 010 and better.

- A Linux branch for mmu that uses the crappy patches in this series and some other bits to start moving the MVME147 board over to using DT.

- A buildroot fork that can build a 000 nommu userland etc. A patch to add support for building for 030 is already in buildroot, I plan to send one for 060 later.

- A bunch of DragonBall machines, an MVME147 030 machine, an Eltec E27 dual socket VME board with one 040 at the moment but I have 060s to go in it once I work out the need jumper changes, some other 060 VME boards, Amigas...

What I'm thinking:

- We initially add passing of an FDT via bootinfo for mmu
- Add support for a generic machine that can boot almost anything so I can bring up my new (to Linux) machines.
- I will migrate MVME147 to device tree.
- Some like minded person migrates a machine they have to device tree. :)
- Maybe embed a FDT for machines that'll never get a bootloader that supports this and use the machine type to select the embedded FDT and move all of that stuff over without needing to mess with bootloaders.

Issues I have:

- The head.S code is real confusing, I'm not sure how I make this support a generic machine right now.
- The head.S code sometimes gets stuck setting up the mmu on my MVME147 when the kernel binary layout changes. I thought for a long time my new code was wrong but then discovered just making the kernel bigger by adding some printk()s also caused it.

Sorry for the wall of text.

Cheers,

Daniel

Daniel Palmer (3):
m68k: bootinfo: Add tag for FDT address
m68k: bootinfo: Add generic machine type
m68k: Add dt support (proof of concept)

 arch/m68k/Kconfig                     |  2 +
 arch/m68k/include/uapi/asm/bootinfo.h |  4 ++
 arch/m68k/kernel/setup_mm.c           | 63 ++++++++++++++++++++++++++-
 3 files changed, 68 insertions(+), 1 deletion(-)
Signature · 1 line
2.45.2
#1 lore raw

RFC PATCH 1/3 m68k: bootinfo: Add tag for FDT address

Allow bootinfo to carry a pointer to an FDT so that the bootloader can pass us one.

This allows for devicetree support without changing the boot protocol too much and breaking unmaintained bootloaders.

---
 arch/m68k/include/uapi/asm/bootinfo.h | 3 +++
 1 file changed, 3 insertions(+)
arch/m68k/include/uapi/asm/bootinfo.h +3 -0
index 024e87d7095f..326f20e82769 100644
@@ -73,6 +73,9 @@ struct mem_info {
 #define BI_RNG_SEED		0x0008
 
 
+/* Pointer to FDT if there is one */
+#define BI_FDT			0x0009
+
     /*
      *  Linux/m68k Architectures (BI_MACHTYPE)
      */
Signature · 1 line
2.45.2
#2 lore raw

RFC PATCH 2/3 m68k: bootinfo: Add generic machine type

In reply to Daniel Palmer

Add a generic machine type that will use an FDT instead of board setup code.

This will allow the bootloader to just pass the generic machine type, some memory info for the head.S code and a pointer to a FDT blob instead of a specific machine type and make adding new machines simpler.

---
 arch/m68k/include/uapi/asm/bootinfo.h | 1 +
 1 file changed, 1 insertion(+)
arch/m68k/include/uapi/asm/bootinfo.h +1 -0
index 326f20e82769..e885bbc462d3 100644
@@ -94,6 +94,7 @@ struct mem_info {
 #define MACH_M54XX		12
 #define MACH_M5441X		13
 #define MACH_VIRT		14
+#define MACH_GENERIC		15
 
 
     /*
Signature · 1 line
2.45.2
#3 lore raw

RFC PATCH 3/3 m68k: Add dt support (proof of concept)

In reply to Daniel Palmer

This is not ready for merge. This just adds enough, probably incorrect, code to get the FDT blob from the bootinfo and parse it.

This is enough to get drivers to probe using devicetree nodes instead of manually registering them but looking up interrupts etc in the DT will not work.

---
 arch/m68k/Kconfig           |  2 ++
 arch/m68k/kernel/setup_mm.c | 63 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 64 insertions(+), 1 deletion(-)
arch/m68k/Kconfig +2 -0
index 7c4f7bcc89d7..e348e6822943 100644
@@ -39,6 +39,8 @@ config M68K
 	select OLD_SIGSUSPEND3
 	select UACCESS_MEMCPY if !MMU
 	select ZONE_DMA
+	select OF
+	select OF_EARLY_FLATTREE
 
 config CPU_BIG_ENDIAN
 	def_bool y
arch/m68k/kernel/setup_mm.c +62 -1

104 lines not on this page · raw message

Signature · 1 line
2.45.2
#4 lore raw
In reply to Daniel Palmer
Quoted 9 lines · Daniel Palmer

What I'm thinking:

- We initially add passing of an FDT via bootinfo for mmu
- Add support for a generic machine that can boot almost anything so I can bring up my new (to Linux) machines.
- I will migrate MVME147 to device tree.
- Some like minded person migrates a machine they have to device tree. :)

Interesting ideas. I gather that you've already done a uboot port for MVME147, and I guess uboot could be made to work on other m68k platforms... but it may be easier to add your FDT suppor to the already-available bootloaders on those platforms (?)

Quoted 4 lines

- Maybe embed a FDT for machines that'll never get a bootloader that supports this and use the machine type to select the embedded FDT and move all of that stuff over without needing to mess with bootloaders.

I like this idea. A few weeks back I was recapping a Mac Classic II and thinking about how I could boot Linux on it.

Pengiun (the bootloader I've been using) can be expected to fail with "68020 has no MMU. Aborting boot...". However, the source code for EMILE appears to have ample support for booting a nommu Mac.

Most of the drivers for this logic board are present in Linux. Some are platform drivers, most rely on bootinfo to some extent (particularly macfb.c and misc.c). And head.S also relies on bootinfo.

Maybe the easiest approach for head.S is to neglect support for both bootinfo and FDT in the same binary, so it becomes a build-time choice. That way, a first cut could be a new head.S that supports your "generic" platform, lacks bootinfo support, but has an embedded FDT.

Then you could get to work on the drivers, and I'm guessing that may be where most of the work lies. (I may be wrong, though -- I've never brought up a new board.) I don't have much experience with FDT but I am curious about the kind of driver changes this would involve.

#5 lore raw

Hi Finn,

Quoted 14 lines · Finn Thain
Quoted 9 lines · Daniel Palmer

What I'm thinking:

- We initially add passing of an FDT via bootinfo for mmu
- Add support for a generic machine that can boot almost anything so I can bring up my new (to Linux) machines.
- I will migrate MVME147 to device tree.
- Some like minded person migrates a machine they have to device tree. :)

Quoted 3 lines

Interesting ideas. I gather that you've already done a uboot port for MVME147, and I guess uboot could be made to work on other m68k platforms...

I have u-boot working on DragonBall (68000), my MVME147, QEMU Virt etc. So the u-boot could be made to work for almost anything as long as there is a serial port and a timer driver.
On virt I take the bootinfo QEMU creates, turn that into a devicetree in u-boot and then pass the bootinfo and FDT into the kernel. :)

Quoted 2 lines

but it may be easier to add your FDT suppor to the already-available bootloaders on those platforms (?)

I think adding FDT support to some old crusty bootloader for the Amiga or something might be a lot of hassle.
Like I'm not sure if I'd even be able to setup a system that could build it if it needs some old Amiga C compiler.
That's why I think embedded FDTs might be needed in some places and leaving the bootinfo part as-is.

Quoted 11 lines
Quoted 4 lines

- Maybe embed a FDT for machines that'll never get a bootloader that supports this and use the machine type to select the embedded FDT and move all of that stuff over without needing to mess with bootloaders.

I like this idea. A few weeks back I was recapping a Mac Classic II and thinking about how I could boot Linux on it.

Pengiun (the bootloader I've been using) can be expected to fail with "68020 has no MMU. Aborting boot...". However, the source code for EMILE appears to have ample support for booting a nommu Mac.

If you can write some code that loads the u-boot binary into memory and jumps to it, getting u-boot working on the mac shouldn't be too difficult.
I might even have serial, ethernet, scsi drivers you can use. I'd rather port u-boot than fix up a bootloader unless the bootloader has some special hardware setup magic that can't be reproduced.

Quoted 3 lines

Most of the drivers for this logic board are present in Linux. Some are platform drivers, most rely on bootinfo to some extent (particularly macfb.c and misc.c). And head.S also relies on bootinfo.

The platform drivers should be easy to make work. I need to look at macfb.c but if it's anything like
the DragonBall one it'll have hardcoded addresses and stuff in there that need to be cleaned up but it's not impossible.
And if we do this the headers with the MMIO addresses can go away and a lot of junk can be removed from arch/m68k.

Quoted 4 lines

Maybe the easiest approach for head.S is to neglect support for both bootinfo and FDT in the same binary, so it becomes a build-time choice. That way, a first cut could be a new head.S that supports your "generic" platform, lacks bootinfo support, but has an embedded FDT.

mmm so have a different head.S for a generic FDT machine and just pass the FDT via a register like I'm doing on nommu.
I don't mind either way so if a maintainer decides which they'd be willing to merge I'll get that going..

Cheers,

Daniel

#6 lore raw
Quoted 7 lines · Daniel Palmer

I have u-boot working on DragonBall (68000), my MVME147, QEMU Virt etc. So the u-boot could be made to work for almost anything as long as there is a serial port and a timer driver.
On virt I take the bootinfo QEMU creates, turn that into a devicetree in u-boot and then pass the bootinfo and FDT into the kernel. :)

I suppose the benefit of integrating FDT into bootinfo is that you can have a new bootloader that's backwards compatible with existing binaries.

I think the embedded FDT option brings a similar result for old bootloaders, but can't support a multi-platform vmlinux.

So I see some benefit to keeping bootinfo support and device tree support independent. A minimal kernel build is going to omit bootinfo support. In the long run, I'm not sure you'd want the FDT stored in a bootinfo record.

Quoted 8 lines

I think adding FDT support to some old crusty bootloader for the Amiga or something might be a lot of hassle.
Like I'm not sure if I'd even be able to setup a system that could build it if it needs some old Amiga C compiler.
That's why I think embedded FDTs might be needed in some places and leaving the bootinfo part as-is.

Right. Bootloaders for old platforms are difficult code bases to contribute to. You need a lot of old hardware to test with, and a variety of operating system releases.

In the case of Penguin, you also need to know MacOS internals. In the case of EMILE, you need to deal with the early execution environment, which is not well documented AFAIK.

But these bootloaders have bugs, like any other program, and someone has to maintain them...

Quoted 8 lines

If you can write some code that loads the u-boot binary into memory and jumps to it, getting u-boot working on the mac shouldn't be too difficult.
I might even have serial, ethernet, scsi drivers you can use. I'd rather port u-boot than fix up a bootloader unless the bootloader has some special hardware setup magic that can't be reproduced.

Those hardware quirks are a given, I think, being that Penguin and EMILE need to support dozens of different Mac models. Porting u-boot is not a very attractive option.

Quoted 8 lines

The platform drivers should be easy to make work. I need to look at macfb.c but if it's anything like the DragonBall one it'll have hardcoded addresses and stuff in there that need to be cleaned up but it's not impossible.
And if we do this the headers with the MMIO addresses can go away and a lot of junk can be removed from arch/m68k.

At that point, bootinfo support can also be omitted. Maybe it's doable for a platform like MVME (?)

It seems that a multi-platform vmlinux binary would have to handle the case where some plaforms will use bootinfo and others will use the device tree.

I wonder whether there are implications for kexec support...

Quoted 6 lines

mmm so have a different head.S for a generic FDT machine and just pass the FDT via a register like I'm doing on nommu. I don't mind either way so if a maintainer decides which they'd be willing to merge I'll get that going..

Yes, I think we've touched on several questions for senior maintainers to ponder.

#7 lore raw
Quoted 4 lines · Finn Thain

In the case of Penguin, you also need to know MacOS internals.

But these bootloaders have bugs, like any other program, and someone has to maintain them…

If Penguin needs maintenance, I’m still here and I still develop for classic Mac OS. I’ve ditched CodeWarrior’s proprietary project files, though I still use the non-free Metrowerks compiler and linker (but now in MPW’s ToolServer, driven by my own build tool running in MacRelix). Lately I’ve been using custom post-linkers to improve startup code compatibility with older OS versions.

I’m not in a position to do testing on hardware or development relating to Linux bootup, but as before, I can maintain and build Mac OS programs.

Cheers,
Josh

#8 lore raw

Bootloaders, was Re: [RFC PATCH 0/3] m68k goes DT

Quoted 5 lines · Josh Juran

I'm not in a position to do testing on hardware or development relating to Linux bootup, but as before, I can maintain and build Mac OS programs.

I've entered the Penguin-19 bugs that I know of into the mac68k bug tracker on sourceforge. I didn't add feature requests, like support for the Mac LC II 12 MB RAM configuration, or support for zstd-format compressed vmlinux. (Nevermind netbsd support, or device tree support...)

Some of those bugs and missing features apply to EMILE as well. IMHO, what EMILE really needs is a MacOS GUI like Penguin. So my advice to prospective mac bootloader developers is, add a GUI to EMILE rather than try to maintain both packages.

That's easier said than done -- Penguin is a hard act to follow. But, in theory, thanks to Retro68, it could be done without resorting to proprietary tooling. Both the Linux executables and the MacOS application could be built with a modern GCC.

Consider that, without a modern GCC, it will be difficult to re-use the available code e.g. for kernel image decompression. Hence, it will be more difficult to fix the long standing Penguin bug relating to gzip decompression (which does not affect EMILE).

#9 lore raw

Re: Bootloaders, was Re: [RFC PATCH 0/3] m68k goes DT

Hi Finn,

Quoted 4 lines · Finn Thain

Some of those bugs and missing features apply to EMILE as well. IMHO, what EMILE really needs is a MacOS GUI like Penguin. So my advice to prospective mac bootloader developers is, add a GUI to EMILE rather than try to maintain both packages.

FWIW I have started to move EMILE over to using meson to build (so it's easier to build on modern systems) and fixing up some of the issues it has with building with recent GCC.
I have it working enough to boot HEAD on a LC475 and on QEMUs Q800 machine. While the penguin ui is nice EMILE seems to work well enough and it can be used to generate bootable CDs.
I have a setup now that can generate a bootable CD with the kernel and a buildroot based userland that I can drop on the SD card for my bluescsi and boot into Linux without any macos intervention.

So basically, for 68k mac I think EMILE is the way to go.

Cheers,

Daniel

#10 lore raw

Re: Bootloaders, was Re: [RFC PATCH 0/3] m68k goes DT

Quoted 3 lines · Daniel Palmer

FWIW I have started to move EMILE over to using meson to build (so it's easier to build on modern systems) and fixing up some of the issues it has with building with recent GCC.

Thanks for doing that.

Quoted 3 lines

I have it working enough to boot HEAD on a LC475 and on QEMUs Q800 machine. While the penguin ui is nice EMILE seems to work well enough and it can be used to generate bootable CDs.

That's good news -- I've long wondered whether QEMU's emulated q800 had reached a point where it could run EMILE. That will make development easier.

Quoted 4 lines

I have a setup now that can generate a bootable CD with the kernel and a buildroot based userland that I can drop on the SD card for my bluescsi and boot into Linux without any macos intervention.

I guess it's only a matter of time before someone puts EMILE into EEPROM. (Many of these systems have a ROM SIMM slot.)

Quoted 2 lines

So basically, for 68k mac I think EMILE is the way to go.

And there is a way to go...

Penguin 19 works on every 68k Mac model. That's hard to achieve and running under MacOS helps a lot. EMILE doesn't have that advantage so it isn't expected to enjoy the same level of hardware compatibility without further work.

For systems that have the standard ROM, booting MacOS is an easy first step for system recovery purposes or just experimentation. So I think EMILE needs a MacOS UI which, though it might not boot Linux, could do the bootloader installation and config (a bit like what XPostFacto did for Mac OS X) so the ROM could then boot into EMILE (and Linux).

#11 lore raw
In reply to Finn Thain
Quoted 10 lines · Finn Thain
Quoted 5 lines · Daniel Palmer

I have u-boot working on DragonBall (68000), my MVME147, QEMU Virt etc. So the u-boot could be made to work for almost anything as long as there is a serial port and a timer driver.
On virt I take the bootinfo QEMU creates, turn that into a devicetree in u-boot and then pass the bootinfo and FDT into the kernel. :)

I suppose the benefit of integrating FDT into bootinfo is that you can have a new bootloader that's backwards compatible with existing binaries.

Quoted 6 lines

I think the embedded FDT option brings a similar result for old bootloaders, but can't support a multi-platform vmlinux.

So I see some benefit to keeping bootinfo support and device tree support independent. A minimal kernel build is going to omit bootinfo support. In the long run, I'm not sure you'd want the FDT stored in a bootinfo record.

That was indeed my first thought, too: do not store a pointer to the FDT in a bootinfo record. Else you end up with a situation similar to ARM(32), which supports the can of worms of mixing FDT and ATAGS.

Instead, replace bootinfo by FDT, and differentiate by checking for the FDT magic value. That way you can have a kernel that supports both bootinfo and FDT.

Passing FDT using a register is also an option, but might be harder to
auto-detect: when using bootinfo, there may be garbage in the register, when booting FDT, there may be garbage in memory where bootinfo is usually stored.

Quoted 4 lines
Quoted 4 lines

I think adding FDT support to some old crusty bootloader for the Amiga or something might be a lot of hassle.
Like I'm not sure if I'd even be able to setup a system that could build it if it needs some old Amiga C compiler.

Yes, this complicates things.

Quoted 2 lines
Quoted 2 lines

That's why I think embedded FDTs might be needed in some places and leaving the bootinfo part as-is.

For "simple" (fixed hardware) machines, that is indeed an option, and already supported on various other architectures.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#12 lore raw
In reply to Daniel Palmer

Hi Daniel,

Quoted 5 lines · Daniel Palmer

Short version:
I want to start converting m68k (including nommu) to use DT for booting so I can add few cool boards I have (e.g. dual 040/060 VME board..). I need ideas, help etc. Maybe if someone converted an m68k machine they are using to DT alongside me this would have some hope of actually happening?

I have been thinking about this for a while for the ColdFire targets. In a few cases the drivers its uses are already devicetree enabled, since they are used on some of the NXP/Freescale ARM SoC devices. So this is interesting work to me.

Quoted 31 lines

All of my WIP in-progress very messy code etc is here:
https://github.com/fifteenhex/m68kjunk

Longer version:

As of today I have:
- Modern (2024.07) u-boot fork that works on 000/030/040 real hardware/QEMU that supports booting a Linux ELF image. For nommu a FDT blob address is passed via a regiser, for mmu the normal bootinfo is created and the FDT is passed via a bootinfo tag. nommu never used bootinfo and doesn't need to.

- A Linux branch for nommu that removes most of the current DragonBall code, makes it into a devicetree based machine and adds a bunch of drivers etc. This works in a fork of QEMU I have and on the real hardware. The DragonBall even has a working 1bpp framebuffer. The nommu branch also works on 010 and better.

- A Linux branch for mmu that uses the crappy patches in this series and some other bits to start moving the MVME147 board over to using DT.

- A buildroot fork that can build a 000 nommu userland etc. A patch to add support for building for 030 is already in buildroot, I plan to send one for 060 later.

- A bunch of DragonBall machines, an MVME147 030 machine, an Eltec E27 dual socket VME board with one 040 at the moment but I have 060s to go in it once I work out the need jumper changes, some other 060 VME boards, Amigas...

What I'm thinking:

Quoted 8 lines

- We initially add passing of an FDT via bootinfo for mmu
- Add support for a generic machine that can boot almost anything so I can bring up my new (to Linux) machines.
- I will migrate MVME147 to device tree.
- Some like minded person migrates a machine they have to device tree. :)
- Maybe embed a FDT for machines that'll never get a bootloader that supports this and use the machine type to select the embedded FDT and move all of that stuff over without needing to mess with bootloaders.

To that end that is what I have been playing with. Doing it in a similar way to what MIPS does. Example patch attached of what I did for non-MMU ColdFire. So no boot loader support required.

Regards
Greg

arch/m68k/Kconfig +2 -0
index 7c4f7bcc89d7..a4949b69e1dc 100644
@@ -39,6 +39,8 @@ config M68K
 	select OLD_SIGSUSPEND3
 	select UACCESS_MEMCPY if !MMU
 	select ZONE_DMA
+	select OF if COLDFIRE
+	select OF_EARLY_FLATTREE if COLDFIRE
 
 config CPU_BIG_ENDIAN
 	def_bool y
arch/m68k/Kconfig.devices +11 -0
index e6e3efac1840..ea0bce4db639 100644
@@ -144,3 +144,14 @@ config SERIAL_CONSOLE
 endmenu
 
 endif
+
+config EMBEDDED_DTB
+	bool "Embedded devicetree ELF section"
+	help
+	  If there is no capability for the boot loader to specify a
+	  devicetree (DTB) then this option allows for it to be embedded
+	  within the linux binary itself. Typically you can do this with
+	  something like this:
+
+		objcopy --update-section .embedded_dtb=<filename>.dtb vmlinux
+
arch/m68k/coldfire/head.S +9 -0
index c6d7fd28c602..88fd8b5b3bda 100644
@@ -133,6 +133,15 @@ _init_sp:
 .long	0
 #endif
 
+#ifdef CONFIG_EMBEDDED_DTB
+/*
+ * If embedding a DTB in the kernel ELF binary then create a place holder
+ * for that section. It will be inserted after the final kernel build/link.
+ */
+.section ".embedded_dtb","aw"
+.long 0
+#endif
+
 /*****************************************************************************/
 
 __HEAD
arch/m68k/kernel/setup_no.c +32 -0
index c926da9d5ec2..d1d79c41c6f0 100644
@@ -33,6 +33,8 @@
 #include <linux/initrd.h>
 #include <linux/root_dev.h>
 #include <linux/rtc.h>
+#include <linux/of.h>
+#include <linux/of_fdt.h>
 
 #include <asm/setup.h>
 #include <asm/bootinfo.h>
@@ -70,6 +72,31 @@ void (*mach_halt)(void);
 #define	CPU_NAME	"UNKNOWN"
 #endif
 
+#ifdef CONFIG_EMBEDDED_DTB
+static void __init m68k_setup_fdt(void)
+{
+	extern void *embedded_dtb;
+	phys_addr_t fdt = (phys_addr_t) &embedded_dtb;
+
+	pr_info("m68k generic DT machine support, FDT blob at 0x%08x\n", fdt);
+	if (!early_init_dt_verify(__va(fdt), fdt)) {
+		pr_err("FDT blob is bad?!\n");
+		return;
+	}
+	early_init_dt_scan_nodes();
+}
+
+static void __init m68k_dtb_model(void)
+{
+	const char *model;
+	model = of_flat_dt_get_machine_name();
+	if (model)
+		pr_info("DTB reports model = %s\n", model);
+	else
+		pr_warn("DTB has no model type?\n");
+}
+#endif /* CONFIG_EMBEDDED_DTB */
+
 /*
  * Different cores have different instruction execution timings.
  * The old/traditional 68000 cores are basically all the same, at 16.
@@ -166,6 +193,11 @@ void __init setup_arch(char **cmdline_p)
 	 * Get kmalloc into gear.
 	 */
 	paging_init();
+
+#ifdef CONFIG_EMBEDDED_DTB
+	m68k_setup_fdt();
+	m68k_dtb_model();
+#endif
 }
 
 /*
arch/m68k/kernel/vmlinux-nommu.lds +9 -0
index 2624fc18c131..1be3bfe31ba4 100644
@@ -70,6 +70,15 @@ SECTIONS {
 	INIT_TEXT_SECTION(PAGE_SIZE)
 	INIT_DATA_SECTION(16)
 	PERCPU_SECTION(16)
+
+#ifdef CONFIG_EMBEDDED_DTB
+	STRUCT_ALIGN();
+	.embedded_dtb : {
+		embedded_dtb = .;
+		*(.embedded_dtb)
+		KEEP(*(.embedded_dtb))
+	}
+#endif
 	.m68k_fixup : {
 		__start_fixup = .;
 		*(.m68k_fixup)
#13 lore raw

Hi Greg,

Quoted 9 lines · Greg Ungerer
Quoted 8 lines

- We initially add passing of an FDT via bootinfo for mmu
- Add support for a generic machine that can boot almost anything so I can bring up my new (to Linux) machines.
- I will migrate MVME147 to device tree.
- Some like minded person migrates a machine they have to device tree. :)
- Maybe embed a FDT for machines that'll never get a bootloader that supports this and use the machine type to select the embedded FDT and move all of that stuff over without needing to mess with bootloaders.

Quoted 3 lines

To that end that is what I have been playing with. Doing it in a similar way to what MIPS does. Example patch attached of what I did for non-MMU ColdFire. So no boot loader support required.

Based on that I've attached what I think would work for normal 68k MMU. Instead of manually embedding the DTB we embed all of them and if there is no FDT in the bootinfo we use the builtin blob. This allows booting without bootloader support and I can still pass a custom FDT from u-boot to enable hardware connected to the VME backplane.

Does this plan seem ok? If so I'll start the process of creating and sending the dt bindings etc. I hate doing that stuff so I don't want to do it if this is a no go. :)

Cheers,

Daniel

From d957da5c1a71ca91743f6b962a9adf0c7f093645 Mon Sep 17 00:00:00 2001
From: Daniel Palmer <[email protected]>
Date: Mon, 6 Jan 2025 10:35:08 +0900
Subject: [PATCH] m68k: dt embedding

---
 arch/m68k/dts/Makefile           |  2 ++
 arch/m68k/dts/embedded_dtbs.S    | 12 ++++++++++++
 arch/m68k/kernel/setup_mm.c      | 11 +++++++++++
 arch/m68k/kernel/vmlinux-std.lds |  6 ++++++
 4 files changed, 31 insertions(+)
 create mode 100644 arch/m68k/dts/embedded_dtbs.S
arch/m68k/dts/Makefile +2 -0
index ca4d64a73f49..e2cb53e6d2db 100644
@@ -1,3 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
 dtb-y += \
 	mvme147.dtb
+
+obj-y += embedded_dtbs.o
arch/m68k/dts/embedded_dtbs.S new file +12 -0
new file mode 100644
index 000000000000..139851e77b39
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#include <linux/linkage.h>
+#include <asm/page.h>
+
+        .section ".embedded_dtbs","aw"
+
+        .balign PAGE_SIZE
+
+SYM_DATA_START(mvme147_dtb)
+        .incbin "arch/m68k/dts/mvme147.dtb"
+SYM_DATA_END_LABEL(mvme147_dtb, SYM_L_GLOBAL, mvme147_dtb_end)
arch/m68k/kernel/setup_mm.c +11 -0
index 6d358124259e..a5feb561064d 100644
@@ -293,6 +293,17 @@ void __init setup_arch(char **cmdline_p)
 		}
 	}
 
+	// TODO: This is wrong, the blob is in the init section so it needs to be copied
+	// but PoC
+	if (!fdt_blob)
+	{
+		extern void *mvme147_dtb;
+
+		pr_info("FDT blob was not provided, will use embedded one if available\n");
+		if (MACH_IS_MVME147)
+			fdt_blob = mvme147_dtb;
+	}
+
 	if (fdt_blob)
 		m68k_setup_fdt();
 
arch/m68k/kernel/vmlinux-std.lds +6 -0
index 1ccdd04ae462..3e40b6cf36a4 100644
@@ -43,6 +43,12 @@ SECTIONS
   __init_begin = .;
   INIT_TEXT_SECTION(PAGE_SIZE) :data
   INIT_DATA_SECTION(16)
+  STRUCT_ALIGN();
+  .embedded_dtbs : {
+	embedded_dtbs = .;
+	*(.embedded_dtbs)
+	KEEP(*(.embedded_dtbs))
+  }
   .m68k_fixup : {
 	__start_fixup = .;
 	*(.m68k_fixup)
Signature · 1 line
2.45.2
#14 lore raw
In reply to Greg Ungerer
Quoted 11 lines · Greg Ungerer
Quoted 5 lines · Daniel Palmer

Short version:
I want to start converting m68k (including nommu) to use DT for booting so I can add few cool boards I have (e.g. dual 040/060 VME board..). I need ideas, help etc. Maybe if someone converted an m68k machine they are using to DT alongside me this would have some hope of actually happening?

I have been thinking about this for a while for the ColdFire targets. In a few cases the drivers its uses are already devicetree enabled, since they are used on some of the NXP/Freescale ARM SoC devices. So this is interesting work to me.

The m68k mac platform is similar in this due to sharing some drivers with ppc macs using Open Firmware. There are a few drivers where we could eliminate complexity and #ifdef trickery if it was all device tree based. For example, pmac_zilog.c relies on the data from OF on a powermac but is getting platform data from the tables in config.c on m68k. The code in via-cuda.c similarly looks up the hardware info from OF on a powermac but has hard-coded data on m68k.

Brad Boyer
[email protected]

#15 lore raw
Quoted 2 lines · Brad Boyer

There are a few drivers where we could eliminate complexity and #ifdef trickery if it was all device tree based.

Ideally, yes. But how would we get there from here?

Should the kernel synthesize a device tree from the bootinfo data, so that an ideal no-ifdef pmac_zilog could work? (This seems like a maximum bloat solution.)

Or should the mac platform abandon bootinfo, and require a new bootloader for all kernel releases after device tree adoption? (This seems maximally difficult, since it requires simultaneously merging many patches to many subsystems, even if the bootloader changes could be done in advance...)

I wonder whether any other architectures have attempted to retrofit device tree support (?)

#16 lore raw

Hi Finn,

Quoted 9 lines · Finn Thain
Quoted 2 lines · Brad Boyer

There are a few drivers where we could eliminate complexity and #ifdef trickery if it was all device tree based.

Ideally, yes. But how would we get there from here?

Should the kernel synthesize a device tree from the bootinfo data, so that an ideal no-ifdef pmac_zilog could work? (This seems like a maximum bloat solution.)

We can add a wrapper that starts from a basic Amiga/Atari/Mac/... FDT and extends/modifies that, based on the bootinfo. Modification can be done using libfdt, even from assembler. See e.g. arch/arm/boot/compressed/*fdt*.

Quoted 4 lines

Or should the mac platform abandon bootinfo, and require a new bootloader for all kernel releases after device tree adoption? (This seems maximally difficult, since it requires simultaneously merging many patches to many subsystems, even if the bootloader changes could be done in advance...)

Drivers can easily support both DT and non-DT, assuming they use proper platform devices. That means no more MACH_IS_* and *HW_PRESENT() checks in the drivers themselves, but proper platform data setup in arch/m68k/<mach>/*.

Quoted 2 lines

I wonder whether any other architectures have attempted to retrofit device tree support (?)

ARM is the classical example.
Until recently, there was code under drivers/staging/board/ to support mixed DT/non-DT systems, but I don't suggest going that way. Conversion of SH to DT is still WIP (except for J-Core, which is DT-only).

The largest initial step is usually irqchip, clocksource, and clock drivers and DT bindings. Existing drivers "just" need DT bindings and DT support.

For e.g. Amiga, the clock driver would be rather simple. Clocksource is much more complicated, as the timers are provided by the CIAs, which are really multi-function-devices (MFD), providing timer, gpio,spi, and irqchip functionalities.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#17 lore raw
Quoted 22 lines · Geert Uytterhoeven
Quoted 9 lines · On Mon, Jan 6, 2025,Finn Thain wrote:
Quoted 2 lines · Brad Boyer

There are a few drivers where we could eliminate complexity and #ifdef trickery if it was all device tree based.

Ideally, yes. But how would we get there from here?

Should the kernel synthesize a device tree from the bootinfo data, so that an ideal no-ifdef pmac_zilog could work? (This seems like a maximum bloat solution.)

We can add a wrapper that starts from a basic Amiga/Atari/Mac/... FDT and extends/modifies that, based on the bootinfo. Modification can be done using libfdt, even from assembler. See e.g. arch/arm/boot/compressed/*fdt*.

Quoted 5 lines

Or should the mac platform abandon bootinfo, and require a new bootloader for all kernel releases after device tree adoption? (This seems maximally difficult, since it requires simultaneously merging many patches to many subsystems, even if the bootloader changes could be done in advance...)

Quoted 5 lines

Drivers can easily support both DT and non-DT, assuming they use proper platform devices. That means no more MACH_IS_* and *HW_PRESENT() checks in the drivers themselves, but proper platform data setup in arch/m68k/<mach>/*.

In the case of pmac_zilog, we still have to avoid pmac_call_feature() and the macio_dev stuff, so many ifdefs would remain.

If DT compatibility was needed in pmac_zilog in order to port Linux/m68k to new hardware (e.g. Mac Classic II) then I'd be in favour of such a driver patch. I don't have time to write it though.

Quoted 9 lines
Quoted 2 lines

I wonder whether any other architectures have attempted to retrofit device tree support (?)

ARM is the classical example.
Until recently, there was code under drivers/staging/board/ to support mixed DT/non-DT systems, but I don't suggest going that way. Conversion of SH to DT is still WIP (except for J-Core, which is DT-only).

Quoted 9 lines

The largest initial step is usually irqchip, clocksource, and clock drivers and DT bindings. Existing drivers "just" need DT bindings and DT support.

For e.g. Amiga, the clock driver would be rather simple. Clocksource is much more complicated, as the timers are provided by the CIAs, which are really multi-function-devices (MFD), providing timer, gpio,spi, and irqchip functionalities.

That's a lot of work. The old drivers would end up being more portable when converted to DT, but is there a need for those drivers on new platforms?

MVME147 is different in that Daniel is proposing new drivers to support boards that are presently unsupported. (Not unlike the hypothetical Mac Classic II example I gave.)

Supporting new hardware is good, but any benefit from retro-fitting DT onto existing drivers is dubious, if those drivers will only end up being used on systems on which they are already being used...

#18 lore raw
In reply to Daniel Palmer

Hi Daniel,

Quoted 4 lines · Daniel Palmer

- The head.S code sometimes gets stuck setting up the mmu on my MVME147 when the kernel binary layout changes. I thought for a long time my new code was wrong but then discovered just making the kernel bigger by adding some printk()s also caused it.

What is your kernel size? Perhaps the code to map 8 or 16 MiB of the first memory chunk doesn't work on 68030?

There could also be some alignment issues. IIRC, there is code that expects the FDT to be 8-byte aligned.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#19 lore raw

Hi Geert,

Quoted 11 lines · Geert Uytterhoeven

Hi Daniel,

Quoted 4 lines · Daniel Palmer

- The head.S code sometimes gets stuck setting up the mmu on my MVME147 when the kernel binary layout changes. I thought for a long time my new code was wrong but then discovered just making the kernel bigger by adding some printk()s also caused it.

What is your kernel size? Perhaps the code to map 8 or 16 MiB of the first memory chunk doesn't work on 68030?

Kernel is 3.something MiB

Quoted 2 lines

There could also be some alignment issues. IIRC, there is code that expects the FDT to be 8-byte aligned.

I thought that too but it seems to be something else. I worked out that for some reason head.S writes values to memory but reads back the old value in some cases. The MMU code was not working correctly because it was constantly clearing the page where it was putting the data.

I then realised I wasn't disabling the I/D caches in u-boot so I added that and it started working more reliably but it only boots every time if I disable the caches before doing the stuff to load the ELF into memory. So there is something funky going on in my u-boot I think and head.S might be fine.

Anyhow,.. I have everything including the timer and interrupts setup via DT on the MVME147 now.

Cheers,

Daniel