Solved Cross kernel build fails FDT on 13.1

Looks like cross-compiled kernel (amd64->arm) fails to pick up options FDT from the kernel config file.

Starting with a clean /usr/src the built kernel does not contain code for FDT support. Steps taken:
Code:
# uname -a
FreeBSD bobthebuilder.localdomain 13.1-RELEASE FreeBSD 13.1-RELEASE releng/13.1-n250148-fc952ac2212 GENERIC  amd64
# rm -R /usr/src
# tar -C / -xvf src.txz
# cd /usr/src
# make TARGET=arm KERNCONF=GENERIC -j 24 buildkernel
# grep FDT /usr/obj/usr/src/arm.armv7/sys/GENERIC/opt_global.h
#
So the kernel build process ignored the options FDT setting in src/sys/arm/conf/GENERIC and did not write a #define for it in opt_global.h.
As a result any driver code that is ifdefed FDT will not make it's way into the binary.

What am I doing wrong here?
 
What am I doing wrong here?
You never told the compiler you need FDT. Plus your env is not set.
-DWITH_FDT

Here is an old arm6 build. Use it as an example. arm6 is dead so you will need to adjust.
 
Which Arm platform are you building for? arm, armv7 or aarch64/arm64 ? What board?
Is there a FreeBSD port with u-boot for the board?
 
Tried it, sadly doesn't fix.

And your instruction adds -DWITH_FDT for buildworld, not for buildkernel:
Code:
.....
[Move to base dir and build world and kernel]
cd $BASEDIR/src
make -j8 buildworld TARGET=arm TARGET_ARCH=armv6 UBLDR_LOADADDR=0x88000000 -DWITH_FDT __MAKE_CONF=/dev/null SRCCONF=/dev/null
make buildkernel TARGET_ARCH=armv6 KERNCONF=BEAGLEBONE
.....
 
Which Arm platform are you building for? arm, armv7 or aarch64/arm64 ? What board?
Is there a FreeBSD port with u-boot for the board?
Working on pcduino3-nano - which is A20.

U-boot works OK. Using u-boot-pcduino3 with simple patch on Makefile:
Code:
*** Makefile    2022-06-08 22:10:59.859770000 +0200
--- Makefile.org    2022-06-08 22:08:00.035792000 +0200
***************
*** 1,10 ****
  # $FreeBSD: head/sysutils/u-boot-pcduino3/Makefile 472714 2018-06-18 20:22:13Z linimon $
 
- .include "${MASTERDIR}/Makefile"
  MASTERDIR=    ${.CURDIR}/../u-boot-master
 
! MODEL=        pcduino3-nano
! BOARD_CONFIG=    Linksprite_pcDuino3_Nano_defconfig
  FAMILY=        allwinner
 
  .include "${MASTERDIR}/Makefile"
--- 1,9 ----
  # $FreeBSD: head/sysutils/u-boot-pcduino3/Makefile 472714 2018-06-18 20:22:13Z linimon $
 
  MASTERDIR=    ${.CURDIR}/../u-boot-master
 
! MODEL=        pcduino3
! BOARD_CONFIG=    Linksprite_pcDuino3_defconfig
  FAMILY=        allwinner
 
  .include "${MASTERDIR}/Makefile"
But generic kernel needs some fixes for some devices (dwc with rgmii-id - camcontrol ahci).
Mods on the kernel were done on system upgraded to 13.1.
Everything went fine - board boots ok - dwc started working recognizing phy.

Until ... On the cross-compiling host I started to implement my mods on a fresh install of src.txz in /usr/src.
After that the FDT option seems to be ignored. I notice from /usr/obj/usr/src/arm.armv7/sys/GENERIC/opt_global.h all the options from /usr/src/sys/arm/conf/std.armv7 are imported.
But - at least - options FDT from GENERIC is missing.
 
Found the culprit. Seems some older code uses #ifdef FDT which is mitigated by juggling with OPT_FDT.
/usr/src/sys/conf/kern.opts.mk comments on using
Code:
.if !empty(OPT_FDT)
In various Makefiles in the /usr/src/sys/modules tree this is done.

But not in /usr/src/sys/dev part or the tree.

Gleaning from /usr/src/sys/dev/mii/vscphy.c the chosen solution for this part of the source tree is to
Code:
#include "opt_platform.h"

After adding this the #ifdef FDT wrapped code from /usr/src/sys/dev is compiled in correctly.
 
Back
Top