January 15, 2023

Kyu networking -- H3 network PHY, NetBSD experiments

I fetch an image of NetBSD 9.3 for the Orange Pi and boot it up on my Orange Pi PC plus. I see that my network switch believes we are now at 100 Mbit.

02:81:b3:9c:e0:c9 is the MAC address. How does NetBSD get this?

Then I transfer a 1 megabyte file (using scp) and the transfer takes 0.8 seconds. No doubt scp adds some overhead.

Peeking at the transfer using wireshark is interesting. I see linux sending packets 15,980 bytes in size and NetBSD advertising a 32,576 byte TCP window.

Let's calculate some naive times to send a 1,000,000 byte file. This would be 8,000,000 bits and at 10 megabits should go at 0.8 seconds. With a 100 megabit network it should go at 0.08 seconds. How can we do an experiment without the overhead of ssh? What about netcat? I can start a listening server on netbsd with this command:

nc -l 4444 >file
Then I can send my 1M test file from linux via this command:
[tom@trona tom]$ time ncat netbsd 4444 < mega
real	0m0.134s
user	0m0.038s
sys	0m0.006s
Aha! Now the transfer takes 0.134 second, which is clearly faster than the 0.8 second 10 mbit time, and a bit slower than the 0.08 second ideal 100 mbit time.

What about this new 2018 vintage U-boot

The NetBSD install instructions say you need to use a version of U-boot that is 2018 or newer. I have been using a 2016 vintage U-boot for all of my Orange Pi experiments and I know it has bugs and hands the emac to me in 10 mbit mode. Now, as I watch the lights on my Netgear switch as I reboot, I see U-boot gets the interface running at 100 Mbit as it should, so apparently these bugs got fixed.

Also I will note that the fancy new (albeit 4 year old at this point) U-boot tells me:

## Starting EFI application at 42000000 ...
This is a bit of a surprise. I have only heard of EFI (in particular UEFI) in connection with the BIOS on desktop computers. EFI is "extensible firmware interface" and is some kind of standard. It involves a dedicated boot partition. See this:

More about this 2018 U-boot and network speed

So, I ask myself if U-boot is really initializing the network. I halt and reset my Orange Pi board running U-boot and type on the keyboard. Indeed this interrupts the normal U-boot sequence and gets me the U-boot console. The LED on my netgear switch were off once I hit reset and simply came on at 100M once I was running U-boot. This all seems correct.
I see these messages:
U-Boot 2018.11 (Jul 02 2022 - 01:48:14 +0000) Allwinner Technology
CPU:   Allwinner H3 (SUN8I 1680)
Model: Xunlong Orange Pi PC
DRAM:  1 GiB
MMC:   SUNXI SD/MMC: 0
Net:   phy interface0
eth0: ethernet@1c30000
Now I pull the SD card out and click my reset button, again typing on the keyboard. This time I see the LED on the network swith go out when I hit reset, but the now come up showing 10M. So indeed this old version of U-boot has a PHY related bug just as I thought.
U-Boot SPL 2016.11-g29e0cfb-dirty (Jan 09 2017 - 11:19:55)
CPU:   Allwinner H3 (SUN8I 1680)
Model: Xunlong Orange Pi PC Plus
DRAM:  1 GiB
MMC:   SUNXI SD/MMC: 1, SUNXI SD/MMC: 0
Net:   phy interface0
eth0: ethernet@1c30000

Can the new 2018 U-boot do a saveenv?

In short, yes it can!

As an experiment I do this:

setenv zzz fish
saveenv
Saving Environment to FAT... OK
Then I reset the board and once I again get to the U-boot prompt type:
=> printenv zzz
zzz=fish
This is exciting because it means it will be easy to persuade this copy of U-boot to network boot Kyu if I want to do that (and easily switch back to booting NetBSD).

Let's examing this SD card

All this talk about EFI booting and saving environment to FAT makes me curious. I extract the card and put it into my flash card reader. I see:
su
fdisk /dev/sdg
p
Device     Boot  Start      End  Sectors  Size Id Type
/dev/sdg1  *     32768   196607   163840   80M  c W95 FAT32 (LBA)
/dev/sdg2       196608 31116287 30919680 14.7G a9 NetBSD
Linux will happily mount the FAT partition for me. It has many files, mostly ".dtb" files for other systems.

The file "uboot.env" contains the saved environment variables, including my "zzz=fish". This is not a plain text file though, it is a binary image with all the envionment variables joined together will null bytes between them.

There are 2 big files of almost identical size:

-rw-r--r-- 1 tom tom 8887632 Aug  4 12:04 kernel7.img
-rw-r--r-- 1 tom tom 8887640 Aug  4 12:04 netbsd-GENERIC.ub
And the file boot.ini references the second one of these:
etenv bootargs "awge0.mac-address=${ethaddr}"
setenv bootcmd "fatload mmc 0:1 0x21000000 netbsd-GENERIC.ub; fatload mmc 0:1 0x20000000 dtb/meson8b-odroidc1.dtb; bootm 0x21000000 - 0x20000000"
run bootcmd
There is also the file "boot.cmd" as follows:
setenv boot_scripts
setenv boot_script_dhcp
run distro_bootcmd
All this is interesting, but we need to get back to the main thing.


Have any comments? Questions? Drop me a line!

Kyu / [email protected]