Raspberrypi 4: meta-raspberrypi/dunfell - in 3 days from no network in U-Boot to dhcp/tftp

Introduction

This work is sponsored by Reliable Embedded Systems. You can find more information about our training/consulting services here.

Objectives

My favorite development setup is to have the boot loader load kernel/device tree over tftp and mount the rootfs over NFS. The first part does not work out of the box on a Raspberrypi 4 with meta-raspberrypi/dunfell since the default U-Boot (2020.01) does not yet support it.

What to do in such a case?


Interact with the community

Report your problem

I opened this issue at the meta-raspberrypi repo with that content:

U-Boot does not seem to support networking on the Raspberry Pi 4 - 64 Bit

Steps to reproduce the issue:

U-Boot> setenv autoload no
U-Boot> dhcp
No ethernet found.
U-Boot> ping 192.168.42.1
No ethernet found.
ping failed; host 192.168.42.1 is not alive
U-Boot> 

Describe the results you received:

No ethernet found.

Describe the results you expected:

pong

Additional information you deem important (e.g. issue happens only occasionally):
Happens always

Additional details (revisions used, host distro, etc.):
Are there any plans to fix this?
If so what's the time frame?

Try some things

As it's not unusual with some communities I was pretty quickly put in touch with the right contact person and tried what was suggested.

Upgrade U-Boot Version

Network support is available in a more recent U-Boot version.

I found a newer U-Boot recipe (2020.07) at poky/master, but I work with poky/dunfell. Hmm let's see if/how we can back-port this.

It turned out that U-Boot 2020.07 requires some function which was introduced in a class which is not present in poky/dunfell. Now what? Back-porting!

poky: new cml1.bbclass required by new U-Boot recipe

Brave as I am I took the cml1.bbclass from poky/master and updated poky/dunfell as you can see here. As far as I can tell it did not break things so far, but I need more testing.

meta-raspberrypi-ml-bsp: new U-Boot recipe + patches

Initially I just copied over the U-Boot 2020.07 recipe from poky/master to my meta-raspberrypi-ml-bsp/dunfell branch as you can see here. Then it was necessary to add a few patches to make network work which I did via this bbappend.

meta-raspberrypi: hack for U-Boot

Finally I added a hack in my meta-raspberrypi fork in order to automatically get the kernel/device tree via tftp. I turned boot.cmd.in into a symlink which either points to boot.cmd.in.sdcard or boot.cmd.in.tftp now.

My boot.cmd.in.tftp to boot with kernel/device tree over tftp instead of sd card looks like this:

fdt addr ${fdt_addr} && fdt get value bootargs /chosen bootargs
setenv autoload no && dhcp && setenv serverip @@SERVERIP@@
setenv kernel @@KERNEL_IMAGETYPE@@ && setenv bootfile ${hostname}/${kernel}
setenv kernel_netload tftp ${kernel_addr_r} ${bootfile}
setenv fdt bcm2711-rpi-4-b.dtb && setenv myfdtfile ${hostname}/${fdt}
setenv fdt_netload tftp ${fdt_addr_r} ${myfdtfile}
run kernel_netload && run fdt_netload
@@KERNEL_BOOTCMD@@ ${kernel_addr_r} - ${fdt_addr}

as you can see here.

local.conf: kernel command line

In order to have U-Boot load the kernel/device tree over tftp instead of sd card you need to adjust the symlink above and this in local.conf:

# boot with rootfs on SD card:
# CMDLINE = "dwc_otg.lpm_enable=0 ${SERIAL} root=/dev/mmcblk1p2 rootfstype=ext4 rootwait"
# boot with rootfs over nfs:
SERVERIP="192.168.42.108"
CMDLINE = "dwc_otg.lpm_enable=0 ${SERIAL} root=/dev/nfs rootfstype=nfs nfsroot=${SERVERIP}:/opt/poky/raspi-4-rootfs,v3,tcp ip=dhcp rootwait"

Conclusion

Did you ever try to get a fix from your board/chip manufacturer? How was your experience with that? 

That's another example of the power of "the Open Source community". It took (only) 3 days (and I am responsible for at least 1 day delay) to get the network  in U-Boot to work on the raspberrypi 4. 

Wow - simply wow! 

Thank you community and especially Andrei and Matthias and please keep up the hard work.

Comments

Popular posts from this blog

Yocto: BitBake and Dependencies - e.g. One recipe to use output of another recipe

Yocto: kernel modules not showing up in the rootfs

Yocto/Qt5: hello-qt part2 - Licensing