Re: Failed to execute custom kernels which where build on a RPi 4 operated by 13.1-RELEASE

From: Dr. Rolf Jansen <freebsd-rj_at_cyclaero.com>
Date: Fri, 08 Jul 2022 21:34:54 UTC
> Am 06.07.2022 um 02:01 schrieb Mark Millard <marklmi@yahoo.com>:
> 
> On 2022-Jul-5, at 08:09, Dr. Rolf Jansen <freebsd-rj@cyclaero.com> wrote:
> 
>>> . . .
>> 
>> That would be the second step. The first step would be that somebody else confirms my finding that building and running a custom kernel on a stock FreeBSD 13.1-RELEASE on RPi 4 does not work out. And actually that was my initial question.
>> 
>> (1) In case somebody raises her/his hand telling, that this worked flawlessly on their system,
>> then I would have a more in deep look, what might have gone wrong here.
>> 
>> (2) In case the issue would be confirmed, then I would submit a bug report, and the discussion
>> may continue in a more productive way on bugs.freebsd.org.
> 
> Summary of the later material:
> 
> It would appear that if building any kernels are
> broken, it is specific to some custom kernel(s)
> in question, not to building kernels in general.
> 13.1-RELEASE's install is able to build, install,
> and boot its own generic kernel on a 8GiByte
> RPi4B Rev. 1.4.

So we are talking about case (1 - works flawlessly as expected), and as I promised, I will look more in deep on what might have gone wrong here. For those who want to reproduce building of kernels completely from the scratch on the RPi 4 in the shortest possible way, I leave a transcript of the procedure at the very bottom of this message (see: *** Installing FreeBSD on a microSD card and building a (custom) kernel ****).

Results with the thus builded kernels:

13.1-GENERIC does work
13.1-GENERIC-MMCCAM does boot from the microSD, but USB does not work
13.1-GNNERIC-RPi4 stalls when booting.
cat /usr/src/sys/arm64/conf/GENERIC-RPi4
   include	GENERIC
   ident	GENERIC-RPi4
   nooptions	SOC_NVIDIA_TEGRA210

In the serial console:
   ...
   mmcsd0: Error indicated: 1 Timeout
   mountroot: waiting for device /dev/ufs/rootfs...
   bcm_dma0: DMA error 4 on CH5
   Mounting from ufs:/dev/ufs/rootfs failed with error 19.

My conclusion is that we may not completely disable NVIDIA Tegra 210. And after all, my goal was not exactly to disable the Tegra, but to mitigate the egoistic behaviour of its internal RTC driver for the MAX77620 (all i2c-addr 68 is mine). I achieved that goal by replacing in the source file /usr/src/sys/arm64/nvidia/tegra210/max77620_rtc.c (of 13.1-RELEASE) the I2C address from 0x68 to 0x7F. Nothing uses 0x7F and so the MAX77620 driver may claim it for itself without harm to other devices.

sed -e "s/#define MAX77620_RTC_I2C_ADDR.0x68/#define MAX77620_RTC_I2C_ADDR   0x7F/" \
    -i "" /usr/src/sys/arm64/nvidia/tegra210/max77620_rtc.c 

13.1-GENERIC (patched) does work, including the DS3231 RTC on i2c1 address 0x68.

   ...
   iicbus0: <OFW I2C bus> on iichb0
   iic0: <I2C generic I/O> on iicbus0
   ds32310: <Maxim DS3231 RTC> at addr 0xd0 on iicbus0
   ...
   ...
   mmcsd0: 16GB <SDHC SL16G 8.0 SN 399D0D61 MFG 09/2016 by 3 SD> at mmc1 50.0MHz/4bit/65535-block
   bcm2835_cpufreq0: ARM 1500MHz, Core 500MHz, SDRAM 400MHz, Turbo ON
   ds32310: registered as a time-of-day clock, resolution 1.000000s
   ...

Many thanks for all your inputs and efforts.

Best regards

Rolf


*** Installing FreeBSD on a microSD card and building a (custom) kernel ****

1. Fetch the image and write it to a pristine microSD card:

   # fetch https://download.freebsd.org/releases/arm64/aarch64/ISO-IMAGES/13.1/FreeBSD-13.1-RELEASE-arm64-aarch64-RPI.img.xz
   # xz -d FreeBSD-13.1-RELEASE-arm64-aarch64-RPI.img.xz
   # dd if=FreeBSD-13.1-RELEASE-arm64-aarch64-RPI.img of=/dev/da0 bs=1m conv=sync


2. Preparation before the first start which automatically would max. out the UFS partition.
   Hovever, I want to reserve space for a 2 GB swap partition
   (omit this step, in case you don't want a swap p.):

   # gpart resize -i 2 da0
   # gpart show da0 da0s2
   =>      63  31116225  da0  MBR  (15G)
           63      2016       - free -  (1.0M)
         2079    102312    1  fat32lba  [active]  (50M)
       104391  31011897    2  freebsd  (15G)

   =>       0  31011897  da0s2  BSD  (15G)
            0        57         - free -  (29K)
           57   6186880      1  freebsd-ufs  (2.9G)
      6186937  24824960         - free -  (12G)

   Calculate the base (start) of the swap partition, e.g. here: 6186937 + 24824960 - 4*1024*1024 = 26817593
   # gpart add -b 26817593 -t freebsd-swap da0s2
   # gpart show da0s2
   =>       0  31011897  da0s2  BSD  (15G)
            0        57         - free -  (29K)
           57   6186880      1  freebsd-ufs  (2.9G)
      6186937  20630656         - free -  (9.8G)
     26817593   4194304      2  freebsd-swap  (2.0G)


3. Start the RPi 4 with the SD card and enter via serial console as root:

   login: root
   Password:
   May 12 08:46:57 generic login[1206]: ROOT LOGIN (root) ON ttyu0
   FreeBSD 13.1-RELEASE releng/13.1-n250148-fc952ac2212 GENERIC

   Welcome to FreeBSD!

   Release Notes, Errata: https://www.FreeBSD.org/releases/
   Security Advisories:   https://www.FreeBSD.org/security/
   FreeBSD Handbook:      https://www.FreeBSD.org/handbook/
   FreeBSD FAQ:           https://www.FreeBSD.org/faq/
   Questions List:        https://lists.FreeBSD.org/mailman/listinfo/freebsd-questions/
   FreeBSD Forums:        https://forums.FreeBSD.org/

   Documents installed with the system are in the /usr/local/share/doc/freebsd/
   directory, or can be installed later with:  pkg install en-freebsd-doc
   For other languages, replace "en" with a language code like de or fr.

   Show the version of FreeBSD installed:  freebsd-version ; uname -a
   Please include that output and any error messages when posting questions.
   Introduction to manual pages:  man man
   FreeBSD directory layout:      man hier

   To change this login announcement, see motd(5).

   root@generic:~ # gpart show
   =>      63  31116225  mmcsd0  MBR  (15G)
           63      2016          - free -  (1.0M)
         2079    102312       1  fat32lba  [active]  (50M)
       104391  31011897       2  freebsd  (15G)

   =>       0  31011897  mmcsd0s2  BSD  (15G)
            0        57            - free -  (29K)
           57  26814464         1  freebsd-ufs  (13G)
     26814521      3072            - free -  (1.5M)
     26817593   4194304         2  freebsd-swap  (2.0G)


4. Donwload and install the sources:

   # cd /
   # fetch --no-verify-peer https://download.freebsd.org/releases/arm64/aarch64/13.1-RELEASE/src.txz
   # tar -xzf src.txz


5. Build and install the GENERIC kernel
   
   # cd /usr/src
   # make -j4 buildkernel KERNCONF=GENERIC
   # make installkernel KERNCONF=GENERIC


6. Restart the RPi 4