Port-arm archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Raspberry Pi 4 support on 32 bit earmv7hf GENERIC kernel



> > https://github.com/tsutsui/netbsd-src/commit/8af7f6d20a4490e1205a63684d6970790737dace
> > 
> > ---
> > bcm2711: patch cpus "enable-method" in dts and use it on initialization
> > 
> > The upstream bcm2711.dtsi returns "brcm,bcm2836-smp" as "enable-method" on
> > /cpus node but bcm2711 requires different addresses from bcm2836.
> > 
> > Fixes early panic on Raspberry Pi 4B with MULITIPROCESSOR kernel:

:

> LGTM

Thanks.

> >> A custom "start4.elf" binary with patched strings from the original
> >> "simple_bus" to "simple-bus" makes ofctl(8) return "simple-bus":
> >>
> >> ---
> >> armv7# strings /boot/start4.elf.orig | grep simple
> >> simple_bus
> >> simple-framebuffer
> >> simple_mode
> >> simple_gpio_flash
> >> simple
> >> armv7# strings /boot/start4.elf | grep simple
> >> simple-bus
> >> simple-framebuffer
> >> simple_mode
> >> simple_gpio_flash
> >> simple
> >> armv7# ofctl -p /chosen name compatible
> >> [Caching 258 nodes and 1436 properties]
> >> name                    63686f73 656e00.. ........ ........   "chosen"
> >> compatible              73696d70 6c652d62 757300.. ........   "simple-bus"
> >> armv7#
> >> ---
> >>
> >> (not sure how this should be handled)
> > 
> > No idea how this should be handled.
> 
> I'm lost on this one.
> 
> Why do you think "simple_bus" needs to be allowed?

On Raspberry Pi 4, it looks the firmware (start4.elf) dynamically
populates /chosen node, puts "simple-framebuffer" under it, and
then gives /chosen the non-standard compatible string "simple_bus".
(see quoted "strings(1)" output above)

The compatible string "simple_bus" is necessary only on /chosen
on (for now at least) Raspberry Pi 4B, so I've adjusted diffs
for this:

https://github.com/tsutsui/netbsd-src/commit/8d680e0d7b993a09afb7234286cf48554f824e24

---
fdtbus: handle /chosen compatible "simple_bus" for Raspberry Pi 4

Raspberry Pi 4 firmware (start4.elf) may populate /chosen node
dynamically and set a non-standard compatible string "simple_bus".

fdt_match() already special-cases /chosen when the node has no
compatible property, so extend that special case to cover /chosen
with compatible with the "simple_bus" string.

This avoids treating "simple_bus" as a generic simplebus compatible
string, while allowing firmware-populated /chosen children such as
simple-framebuffer to be enumerated on Raspberry Pi systems.

---

diff --git a/sys/dev/fdt/fdtbus.c b/sys/dev/fdt/fdtbus.c
index e557b0c6479a..828b673353a8 100644
--- a/sys/dev/fdt/fdtbus.c
+++ b/sys/dev/fdt/fdtbus.c
@@ -93,6 +93,11 @@ static const struct device_compatible_entry compat_data[] = {
 	DEVICE_COMPAT_EOL
 };
 
+static const struct device_compatible_entry chosen_compat_data[] = {
+	{ .compat = "simple_bus" },
+	DEVICE_COMPAT_EOL
+};
+
 CFATTACH_DECL2_NEW(simplebus, sizeof(struct fdt_softc),
     fdt_match, fdt_attach, NULL, NULL, fdt_rescan, fdt_childdet);
 
@@ -116,6 +121,15 @@ fdt_match(device_t parent, cfdata_t cf, void *aux)
 			return 1;
 	}
 
+	/*
+	 * Raspberry Pi 4 firmware (start4.elf) may populate /chosen node
+	 * dynamically and set a non-standard compatible string "simple_bus".
+	 * Treat that case like the existing /chosen special case above.
+	 */
+	if (OF_finddevice("/chosen") == phandle &&
+	    of_compatible_match(phandle, chosen_compat_data))
+		return 1;
+
 	/* Always match the root node */
 	return OF_finddevice("/") == phandle;
 }

---

> > https://github.com/tsutsui/netbsd-src/commit/50c26ba1ec7e2001752647e5ef3531d994668273
> > 
> > ---
> > bcmgenet: fix build errors on ILP32 targets
> > 
> > Use BUS_ADDR_LO32() and BUS_ADDR_HI32() to handle 40 bit DMA addresses.
> > genet(4) on Raspberry Pi 4B just works even on earmv7hf kernels.
> > 
> > ---

:

> LGTM

Thanks.

Note one more fix is necessary for "genfb as simplefb" on Pi 4B
to handle "incorrectly swapped red and blue" due to unintentional
"is_bgr" genfb property in rpi_fb_init() during device_register:

https://github.com/tsutsui/netbsd-src/commit/22761c80debcbed1c4d9e033acbbd923bae907dc

---
bcm283x: skip bcmgenfb specific initialization in !bcmgenfb case

Fixes wrong BGR colors on Raspberry Pi 4 which has own initialization
by simplefb with FDT properties.

---
diff --git a/sys/arch/arm/broadcom/bcm283x_platform.c b/sys/arch/arm/broadcom/bcm283x_platform.c
index 8751d3af1236..e52e271ec517 100644
--- a/sys/arch/arm/broadcom/bcm283x_platform.c
+++ b/sys/arch/arm/broadcom/bcm283x_platform.c
@@ -1420,6 +1420,18 @@ bcm2711_platform_early_putchar(char c)
 	bcm283x_aux_platform_early_putchar(va, pa, c);
 }
 
+static bool
+rpi_genfb_is_bcmgenfb(device_t dev, void *aux)
+{
+	static const struct device_compatible_entry compat_data[] = {
+		{ .compat = "brcm,bcm2835-fb" },
+		DEVICE_COMPAT_EOL
+	};
+	struct fdt_attach_args *faa = aux;
+
+	return of_compatible_match(faa->faa_phandle, compat_data) != 0;
+}
+
 #define	BCM283x_REF_FREQ	19200000
 
 static void
@@ -1458,13 +1470,15 @@ bcm283x_platform_device_register(device_t dev, void *aux)
 	if (device_is_a(dev, "genfb")) {
 		char *ptr;
 
-		bcmgenfb_set_console_dev(dev);
-		bcmgenfb_set_ioctl(&rpi_ioctl);
+		if (rpi_genfb_is_bcmgenfb(dev, aux)) {
+			bcmgenfb_set_console_dev(dev);
+			bcmgenfb_set_ioctl(&rpi_ioctl);
 #ifdef DDB
-		db_trap_callback = bcmgenfb_ddb_trap_callback;
+			db_trap_callback = bcmgenfb_ddb_trap_callback;
 #endif
-		if (rpi_fb_init(dict, aux) == false)
-			return;
+			if (rpi_fb_init(dict, aux) == false)
+				return;
+		}
 		if (get_bootconf_option(boot_args, "console",
 		    BOOTOPT_TYPE_STRING, &ptr) && strncmp(ptr, "fb", 2) == 0) {
 			device_setprop_bool(dev, "is_console", true);

---
Izumi Tsutsui


Home | Main Index | Thread Index | Old Index