Bug 258081

Summary: opt_platform.h always created empty on kmod build
Product: Base System Reporter: Alexander Mishin <mishin>
Component: kernAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed Not A Bug    
Severity: Affects Only Me    
Priority: ---    
Version: 13.0-STABLE   
Hardware: arm   
OS: Any   

Description Alexander Mishin 2021-08-27 11:02:59 UTC
Running "make depend" in a kernel module sources folder outside of the kernel sources tree makes an empty "./opt_platform.h". I expect it to contain the lines "#define FDT 1" and "#define EFI 1" which are contained in "/usr/obj/arm.armv7/sys/${KERNCONF}/opt_platform.h".

My "Makefile":
# $FreeBSD$
KMOD=rcrecv
SRCS=rcrecv.c
SRCS+=  \
        bus_if.h \
        device_if.h \
        gpio_if.h \
        gpiobus_if.h \
        ofw_bus_if.h \
        opt_platform.h \
        fdt_pinctrl_if.h \
CFLAGS+=  -I.
.include <bsd.kmod.mk>

Maybe it is important: I always mount on my ARM host "/usr/src" for building kernel modules by nfs but I have not mounted "/usr/obj" there.

I tried also run "make TARGET_ARCH=armv7 KERNCONF=OPI_PC depend" on amd64 PC (I build world & kernel for my OrangePI PC, on amd64 and with that variables, and "/usr/obj/arm.armv7/sys/${KERNCONF}/opt_platform.h" is exists and is not empty). But the "./opt_platform.h" created empty in this case too.

This is an output of the command I run (I don't got what ":>" means):
machine -> /usr/src/sys/amd64/include
x86 -> /usr/src/sys/x86/include
awk -f /usr/src/sys/tools/makeobjops.awk /usr/src/sys/kern/bus_if.m -h
awk -f /usr/src/sys/tools/makeobjops.awk /usr/src/sys/kern/device_if.m -h
awk -f /usr/src/sys/tools/makeobjops.awk /usr/src/sys/dev/gpio/gpio_if.m -h
awk -f /usr/src/sys/tools/makeobjops.awk /usr/src/sys/dev/gpio/gpiobus_if.m -h
awk -f /usr/src/sys/tools/makeobjops.awk /usr/src/sys/dev/ofw/ofw_bus_if.m -h
:> opt_platform.h
awk -f /usr/src/sys/tools/makeobjops.awk /usr/src/sys/dev/fdt/fdt_pinctrl_if.m -h
touch opt_global.h

Of course I can place a definition of FDT to the code, to the Makefile or even to the "./opt_platform.h" file but I want to make it more platform dependent.
Is it a bug or maybe I misunderstand this step of making kmods?
Comment 1 Andriy Gapon freebsd_committer freebsd_triage 2021-08-28 09:31:30 UTC
A standalone module build has no idea of the target platform properties and so it cannot make any meaningful definitions for it.

If you want to build a module to work with a specific kernel (and its configuration must have all the necessary platform specifications), then either build the module as a part of the kernel build or use KERNBUILDDIR make variable to point to the kernel build.

P.S. In general, when you are not sure it's better to ask a question first and then to file a bug.  FreeBSD has many forums for all kinds of questions.
Comment 2 Alexander Mishin 2021-08-28 11:35:17 UTC
Thank You