re-build buildroot to include custom device tree dts modification

509 views Asked by At

Hi I was able build a system image and successfully boot my Orange PI Zero 3 using buildroot.

In my endeavour of learning Linux Device Drivers, I now need to modify the device tree. To do this I create the file sun50i-h616-orangepi-zero3-custom.dts and include the original file in this.

Now according to this:Buildroot: how to modify device tree for custom board?

Point to that dts in the "Out of tree custom DTS" menu entry (BR2_LINUX_KERNEL_CUSTOM_DTS_PATH) in the Buildroot menuconfig.

But after I do the above edits and run make on buildroot, it only regenerates the filesystem from previous binary images. It does no compilation (including the dtb)...

How do I only re-compile the dtb into a precompiled system?

EDIT: running make clean all does trigger a complete recompilation. But uboot is now trying to load an nonexistant /boot/allwinner/sun50i-h616-orangepi-zero3.dtb while it should load (I believe) /boot/sun50i-h616-orangepi-zero3-custom.dtb

Here is the boot log:

U-Boot SPL 2021.07 (Dec 20 2023 - 15:24:56 +0000)
DRAM: 1024 MiB
Trying to boot from MMC1
NOTICE:  BL31: v2.9(release):v2.9
NOTICE:  BL31: Built : 15:21:07, Dec 20 2023
NOTICE:  BL31: Detected Allwinner H616 SoC (1823)
NOTICE:  BL31: Found U-Boot DTB at 0x4a0822d0, model: OrangePi Zero3
ERROR:   RSB: set run-time address: 0x10003


U-Boot 2021.07 (Dec 20 2023 - 15:24:56 +0000) Allwinner Technology

CPU: Allwinner H616 (SUN50I)       
Model: OrangePi Zero3                
I2C: ready                         
DRAM:  1 GiB                        
MMC:   mmc@4020000: 0                
Loading Environment from FAT... Unable to use mmc 0:1... In:    serial@5000000 Out:   serial@5000000                   
Err:   serial@5000000                
Net:   No ethernet found.            
starting USB...                      
No working controllers found          
Autoboot in 2 seconds, press <Space> to stop switch to partitions #0, OK           
mmc0 is current device                
Scanning mmc 0:1...                   
Found /boot/extlinux/extlinux.conf    
Retrieving file: /boot/extlinux/extlinux.conf
176 bytes read in 2 ms (85.9 KiB/s)   
1:      default                      
Retrieving file: /boot/Image         
22532104 bytes read in 1806 ms (11.9 MiB/s)
append: root=PARTUUID=693bf98f-ac7c-49d5-89d8-bdbebeb8ef82 rootwait console=ttyS0,115200 rootfstype=ext4 quiet panic=10
Retrieving file: /boot/allwinner/sun50i-h616-orangepi-zero3.dtb
Failed to load '/boot/allwinner/sun50i-h616-orangepi-zero3.dtb'
Moving Image from 0x40080000 to 0x40200000, end=41800000                                                                                                     
                                                                                                                                                             
Starting kernel ...

and hangs right there. Also building the whole system just for the dtb is inconvenient.. Is there a way to make build root only update the device tree blob into the filesystem?

EDIT2: Saw this one: How to use custom device tree source correctly in buildroot?

Which device-tree u-boot passes to the kernel is defined by u-boot's CONFIG_DEFAULT_FDT_FILE option <...> This option should be set to something like imx28-custom.dtb.

Still same error Failed to load '/boot/allwinner/sun50i-h616-orangepi-zero3.dtb'.

EDIT3: Okay, I resorted to manually loading the dtb on uboot prompt:

Autoboot in 2 seconds, press <Space> to stop
=> setenv bootargs "root=PARTUUID=693bf98f-ac7c-49d5-89d8-bdbebeb8ef82 rootwait console=ttyS0,115200 rootfstype=ext4 quiet panic=10"
=> ext4load mmc 0:1 ${kernel_addr_r} boot/Image
22532104 bytes read in 1805 ms (11.9 MiB/s)
=> ext4load mmc 0:1 ${fdt_addr_r} boot/sun50i-h616-orangepi-zero3-custom.dtb
39939 bytes read in 5 ms (7.6 MiB/s)
=> booti ${kernel_addr_r} - ${fdt_addr_r}
Moving Image from 0x40080000 to 0x40200000, end=41800000
## Flattened Device Tree blob at 4fa00000
   Booting using the fdt blob at 0x4fa00000
   Loading Device Tree to 0000000049ff3000, end 0000000049fffc02 ... OK

Starting kernel ...

[    0.758652] axp20x-regulator axp20x-regulator: DCDC frequency on AXP313a is fixed to 3 MHz.
[    0.758659] axp20x-regulator axp20x-regulator: Error setting dcdc frequency: -22
[    0.867654] debugfs: Directory '1100000.mixer' with parent 'regmap' already present!
[    0.875431] debugfs: Directory '1100000.mixer' with parent 'regmap' already present!
[    0.911703] OF: /thermal-zones/gpu-thermal/cooling-maps/map0: could not get #cooling-cells for /soc/gpu@1800000
[    0.921811] thermal_sys: Add a cooling_device property with at least one device
[    0.929119] thermal thermal_zone0: binding zone gpu-thermal with cdev cpufreq-cpu0 failed:-2

And it crashes there! What am I doing wrong here? I'm at loss of ideas to try :(

EDIT4 I retried with bootargs "root=PARTUUID=693bf98f-ac7c-49d5-89d8-bdbebeb8ef82 rootfstype=ext4" instead and it worked! So manual boot is working. But need to get buildroot to honour the CONFIG_DEFAULT_FDT_FILE option.

1

There are 1 answers

15
sawdust On

How do I only re-compile the dtb into a precompiled system?

Not sure if there are other/better methods, but I simply delete several hidden files in the Linux kernel build sub-directory:
.stamp_built,
.stamp_images_installed,
.stamp_installed, and
.stamp_target_installed.
Then issue a top-level make from the Buildroot directory.


Addendum

... the only thing left now is that uboot wont honour CONFIG_DEFAULT_FDT_FILE and always try to load the default dtb to the kernel.

You cannot always expect a (modified) build configuration option to be conveyed to the U-Boot runtime (i.e. active) environment.

CONFIG_DEFAULT_FDT_FILE can only affect the default environment of U-Boot. But U-Boot will always attempt to use the saved environment (rather than the default environment) when it starts execution.
If you have not explicitly ensured that the saved U-Boot environment has been removed/cleared, then do not expect U-Boot to a load different .dtb file for the kernel.

Seems like you haven't even identified from where the U-Boot saved environment is retrieved, and what it contains. In other words, (a) where is U-Boot configured to save its environment, (b) what is the U-Boot configuration for the default environment, and (c) what is the saved environment currently on your target board?

If you're confused or unfamiliar with the various "environments" of U-Boot, then refer to this answer.


Addendum II

You have been negligent in providing salient details, such as the versions that you are building.

The current version of Buildroot, the tarball for version 2023.11, which fetches a tarball of U-Boot u-boot-orangepi-6fe17fac388aad17490cf386578b7532975e567f.tar.gz explains your original problem relating to "honour[ing] the CONFIG_DEFAULT_FDT_FILE option."

A complication is that there seems to some confusion between the use of CONFIG_DEFAULT_FDT_FILE and CONFIG_DEFAULT_DEVICE_TREE in U-Boot. The SO answer that is the premise of your problem is simply not 100% accurate. Instead of CONFIG_DEFAULT_FDT_FILE, some boards use CONFIG_DEFAULT_DEVICE_TREE.
Case in point, in include/configs/sunxi-common.h there's :

#define FDTFILE "allwinner/" CONFIG_DEFAULT_DEVICE_TREE ".dtb"

which is then used to define the environment variable:

    "fdtfile=" FDTFILE "\0" \

This code correlates perfectly with what you report up to your EDIT2 of your question.

CONFIG_DEFAULT_FDT_FILE is not going to be "honoured" by U-Boot simply because that option is not used to define any variable for the default environment of your board.
So the proper fix for your code base seems to be defining CONFIG_DEFAULT_DEVICE_TREE with your new Device Tree name, and ignore that SO answer that you found (as well as hacking U-Boot source code to make that solution viable).



Seems like you have three additional problems which are tangential to your stated problem.

First, the C environment while U-Boot compiles has the symbol CONFIG_ARM64 defined. This is evidenced by the allwinner/ subdirectory that prefaces the dtb/FDT filename that you complain about when U-Boot actually runs.
Presumably there's either a Buildroot or kernel Makefile that would be responsible for installing the dtb/FDT file in the boot/ subdirectory of the target/ subdirectory. Apparently this Makefile is not aware that a 64-bit sunxi U-Boot expects the dtb/FDT file in the boot/allwinner/ subdirectory.


Second, U-Boot seems to be configured with its environment stored as a file in a FAT filesystem (as evidenced by the Loading Environment from FAT... failure and the saveenv error). You can also confirm this in your U-Boot build configuration, i.e. CONFIG_ENV_IS_IN_FAT.

As you reported and per the genimage.cfg for OrangePi boards, there's only one ext4 filesystem. The U-Boot image is stored as raw sectors in an unallocated area at the beginning of the SD card.

This discrepancy between the OrangePi layout of the SD card and the sunxi(?) U-Boot configuration is something that the one of those communities should resolve.


Third, you've reported that U-Boot seems to start up with some unknown (stored/saved) environment that is not any known environment. Your descriptions are scattered over several disjointed comments. Your original/first boot log clearly indicates that the attempt to load the saved environment failed; that should have brought in the default environment. You may have to debug U-Boot to gather more information.