NetBSD Problem Report #57498

From dtyson@samsung.anduin.org.uk  Mon Jul  3 17:07:11 2023
Return-Path: <dtyson@samsung.anduin.org.uk>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id CB6261A923D
	for <gnats-bugs@gnats.NetBSD.org>; Mon,  3 Jul 2023 17:07:11 +0000 (UTC)
Message-Id: <20230703170706.938A1144794@samsung.anduin.org.uk>
Date: Mon,  3 Jul 2023 18:07:06 +0100 (BST)
From: dtyson@anduin.org.uk
Reply-To: dtyson@anduin.org.uk
To: gnats-bugs@NetBSD.org
Subject: Raspberry PI zero 2 w support lacking + rpi support for camera
X-Send-Pr-Version: 3.95

>Number:         57498
>Category:       kern
>Synopsis:       Raspberry PI zero 2 w support lacking + rpi support for camera
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    kern-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Mon Jul 03 17:10:00 +0000 2023
>Originator:     Dave Tyson <dtyson@anduin.org.uk>
>Release:        NetBSD 10.99.4
>Organization:
anduin
>Environment:


System: NetBSD 10.99.4 (GENERIC) #0: Sun Jul  2 23:51:01 BST 2023
 root@cruncher.anduin.org.uk:/usr/obj/arm7/sys/arch/evbarm/compile/GENERIC
Architecture: earmv7hf
Machine: evbarm
>Description:
There is no native dtb for the Raspberry Pi Zero 2 w provided in current/NetBSD 10. Users have to copy the dtb used by the Raspberry Pi 3. In addition the rpi02w needs later firmware files then exist in current/NetBSD 10. The firmware files shipped with NetBSD do not include the start*x.elf and fixup*x.dat varients needed to rpi camera. 	
>How-To-Repeat:
Build an armv7 image and burn it to an sdcard. Insert into an rpi02w and note the image does not boot. Add a dtb entry and update the firmware files. Note it now boots but there is no wifi.	
>Fix:

Download:
https://github.com/torvalds/linux/blob/master/arch/arm/boot/dts/bcm2837-rpi-zero-2-w.dts
https://github.com/torvalds/linux/blob/master/arch/arm/boot/dts/bcm283x-rpi-wifi-bt.dtsi
https://github.com/torvalds/linux/blob/master/arch/arm/boot/dts/bcm283x-rpi-led-deprecated.dtsi
saving files into
/usr/src/sys/external/gpl2/dts/dist/arch/arm/boot/dts

Hook to build bcm2837-rpi-zero-2-w.dtb:

--- sys/external/gpl2/dts/dist/arch/arm/boot/dts/Makefile.orig	2021-11-07 16:50:04.000000000 +0000
+++ sys/external/gpl2/dts/dist/arch/arm/boot/dts/Makefile	2023-06-01 22:22:06.584198168 +0100
@@ -90,6 +90,7 @@
 	bcm2837-rpi-3-b.dtb \
 	bcm2837-rpi-3-b-plus.dtb \
 	bcm2837-rpi-cm3-io3.dtb \
+	bcm2837-rpi-zero-2-w.dtb \
 	bcm2711-rpi-400.dtb \
 	bcm2711-rpi-4-b.dtb \
 	bcm2835-rpi-zero.dtb \


Update the boot firmware pulling in the *_x.* files needed if you want to use the rpi camera

Download:
https://github.com/raspberrypi/firmware/blob/master/boot/bootcode.bin
https://github.com/raspberrypi/firmware/blob/master/boot/fixup.dat
https://github.com/raspberrypi/firmware/blob/master/boot/fixup_cd.dat
https://github.com/raspberrypi/firmware/blob/master/boot/fixup_x.dat
https://github.com/raspberrypi/firmware/blob/master/boot/fixup4.dat
https://github.com/raspberrypi/firmware/blob/master/boot/fixup4x.dat
https://github.com/raspberrypi/firmware/blob/master/boot/fixup4cd.dat
https://github.com/raspberrypi/firmware/blob/master/boot/start.elf
https://github.com/raspberrypi/firmware/blob/master/boot/start_cd.elf
https://github.com/raspberrypi/firmware/blob/master/boot/start_x.elf
https://github.com/raspberrypi/firmware/blob/master/boot/start4.elf
https://github.com/raspberrypi/firmware/blob/master/boot/start4x.elf
https://github.com/raspberrypi/firmware/blob/master/boot/start4cd.elf
saving files into
/usr/src/external/broadcom/rpi-firmware/dist

Hook the extra *_x.* files into the firmware release lists

--- distrib/utils/embedded/conf/rpi.conf.orig	2022-11-19 09:19:27.000000000 +0000
+++ distrib/utils/embedded/conf/rpi.conf	2023-06-02 21:20:00.122564028 +0100
@@ -10,7 +10,7 @@
 . ${DIR}/conf/evbarm.conf

 firmwaredir=$src/external/broadcom/rpi-firmware/dist
-firmwarefiles="LICENCE.broadcom bootcode.bin fixup.dat fixup_cd.dat start.elf start_cd.elf"
+firmwarefiles="LICENCE.broadcom bootcode.bin fixup.dat fixup_cd.dat fixup_x.dat start.elf start_cd.elf start_x.elf"

 make_fstab() {
 	make_fstab_evbarm

--- distrib/utils/embedded/conf/rpi_inst.conf.orig	2022-11-19 09:19:27.000000000 +0000
+++ distrib/utils/embedded/conf/rpi_inst.conf	2023-06-02 21:20:19.826723347 +0100
@@ -32,7 +32,7 @@
 }

 firmwaredir=$src/external/broadcom/rpi-firmware/dist
-firmwarefiles="LICENCE.broadcom bootcode.bin fixup.dat fixup_cd.dat start.elf start_cd.elf"
+firmwarefiles="LICENCE.broadcom bootcode.bin fixup.dat fixup_cd.dat fixup_x.dat start.elf start_cd.elf start_x.elf"

 populate() {
 	cat > ${mnt}/boot/cmdline.txt << EOF


--- distrib/utils/embedded/conf/armv7.conf.orig	2023-04-19 19:39:18.000000000 +0100
+++ distrib/utils/embedded/conf/armv7.conf	2023-06-02 22:38:05.851366635 +0100
@@ -50,7 +50,7 @@

 populate_rpi() {
 	firmwaredir="${src}/external/broadcom/rpi-firmware/dist"
-	firmwarefiles="LICENCE.broadcom bootcode.bin fixup.dat fixup_cd.dat start.elf start_cd.elf"
+	firmwarefiles="LICENCE.broadcom bootcode.bin fixup.dat fixup_cd.dat fixup_x.dat start.elf start_cd.elf start_x.elf"

 	# The GENERIC .img kernel img is used for RPI2
 	if [ -f "${mnt}/boot/netbsd-GENERIC.img" ]; then


--- distrib/utils/embedded/conf/arm64.conf.orig	2022-10-15 19:32:30.000000000 +0100
+++ distrib/utils/embedded/conf/arm64.conf	2023-06-02 21:22:20.128754451 +0100
@@ -59,7 +59,7 @@

 populate_rpi() {
 	firmwaredir="${src}/external/broadcom/rpi-firmware/dist"
-	firmwarefiles="LICENCE.broadcom bootcode.bin fixup4cd.dat fixup4.dat fixup_cd.dat fixup.dat start4cd.elf start4.elf start_cd.elf start.elf"
+	firmwarefiles="LICENCE.broadcom bootcode.bin fixup4cd.dat fixup4.dat fixup4x.dat fixup_cd.dat fixup.dat fixup_x.dat start4cd.elf start4.elf start4x.elf start_cd.elf start.elf start_x.elf"

 	cat > "${mnt}/boot/cmdline.txt" << EOF
 root=NAME=${gpt_label_ffs} console=${console}


--- distrib/utils/embedded/conf/arm64mbr.conf.orig	2021-07-01 18:31:21.000000000 +0100
+++ distrib/utils/embedded/conf/arm64mbr.conf	2023-06-02 21:23:43.386056160 +0100
@@ -44,7 +44,7 @@

 populate_rpi() {
 	firmwaredir="${src}/external/broadcom/rpi-firmware/dist"
-	firmwarefiles="LICENCE.broadcom bootcode.bin fixup4cd.dat fixup4.dat fixup_cd.dat fixup.dat start4cd.elf start4.elf start_cd.elf start.elf"
+	firmwarefiles="LICENCE.broadcom bootcode.bin fixup4cd.dat fixup4.dat fixup4x.dat fixup_cd.dat fixup.dat fixup_x.dat start4cd.elf start4.elf start4x.elf start_cd.elf start.elf start_x.elf"

 	cat > "${mnt}/boot/cmdline.txt" << EOF
 root=ld0a console=${console}


finally run make update-sets in /usr/src/sys/dtb to update the dtb lists


With this fix the correct dtb for the rpi02w is build and installed togther with the Broadcom firmware needed to boot. The firmware for all the rpi models now includes the 'x' varient needed to use the rpi camera.

Note although the wifi is detected for the rpi02w, it fails to load the correct firmware and so doesn't yet work. The device needs the brcmfmac43436 firmware and some mods to the brfm device driver to correctly identify the chip on the board. Testing has shown that loading that firmware does enable the wifi to work, but it is falky under heavy load. I will submit another pr once I have investigated the problem fully.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2023 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.