u-boot places device-tree in bss

Yuri Honegger <[email protected]> Sun, 14 Dec 2025 19:56:51 +0100
Newsgroups gmane.os.netbsd.ports.arm
Message-ID <[email protected]>
Hello,
When the memory address for the device tree isn't provided to u-boot, u-boot
decides where to place the device tree by itself. For me, it chooses to place it
right after the code, overlapping the bss section. This means the device tree 
gets overwritten when clearing the bss and a bit later, NetBSD rightfully panics
because of a corrupt device tree.

Since u-boot leaves some space between the code and the device tree, it works
with a small kernel, but as soon as I enable more features and bss grows, I run 
into this issue.

I can work around this by giving u-boot a boot.scr that manually places the 
device tree, but I'm wondering if this could be fixed in NetBSD.

We could add a panic if we encounter this situation. That would be a bit more
helpful than the current error:
[ 1.0000000] panic: fdt_check_header failed: FDT_ERR_BADMAGIC

Another option would be to add some logic that preserves the device tree in this
scenario. For example, we could move the device tree out of the way of the bss 
if they overlap. The question is where would we move it though? Perhaps 
beyond the end of the bss section?

Any thought/opinions/suggestions? I'm happy to provide a patch if there is a
consensus for how this should be solved.

Thanks,
yuri