How to get a Debian-like kernel header layout?

I’m trying to build some custom DTBs for a new device, which needs the kernel header. It is an Nvidia based device, so the SDK is available here, and the command is ran under Linux_for_Tegra/source.

There are 2 folders under the linux.dev:

$ ls /nix/store/1nsr5hhgr95bqw3z50gm8dxcfr04vmkv-linux-6.12.32-dev/lib/modules/6.12.32/
build  source

I tried with build first, which misses scripts/Kbuild.include from source:

$ make KERNEL_HEADERS=/nix/store/1nsr5hhgr95bqw3z50gm8dxcfr04vmkv-linux-6.12.32-dev/lib/modules/6.12.32/build dtbs
================================================================================
make nvidia-dtbs ...
================================================================================
TEGRA_TOP=/home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source \
srctree=/nix/store/1nsr5hhgr95bqw3z50gm8dxcfr04vmkv-linux-6.12.32-dev/lib/modules/6.12.32/build \
objtree=/nix/store/1nsr5hhgr95bqw3z50gm8dxcfr04vmkv-linux-6.12.32-dev/lib/modules/6.12.32/build \
oottree=/home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source/kernel-devicetree \
HOSTCC=gcc \
make -f /home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source/kernel-devicetree/scripts/Makefile.build \
        obj=/home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source/kernel-devicetree/generic-dts \
        dtbs
make[1]: Entering directory '/home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source'
/home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source/kernel-devicetree/scripts/Makefile.build:38: /nix/store/1nsr5hhgr95bqw3z50gm8dxcfr04vmkv-linux-6.12.32-dev/lib/modules/6.12.32/build/scripts/Kbuild.include: No such file or directory
make[1]: *** No rule to make target '/nix/store/1nsr5hhgr95bqw3z50gm8dxcfr04vmkv-linux-6.12.32-dev/lib/modules/6.12.32/build/scripts/Kbuild.include'.  Stop.
make[1]: Leaving directory '/home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source'
make: *** [Makefile:173: nvidia-dtbs] Error 2

So I tried again with source first, but it also misses scripts/dtc/dtc from build:

$ make KERNEL_HEADERS=/nix/store/1nsr5hhgr95bqw3z50gm8dxcfr04vmkv-linux-6.12.32-dev/lib/modules/6.12.32/source dtbs
================================================================================
make nvidia-dtbs ...
================================================================================
TEGRA_TOP=/home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source \
srctree=/nix/store/1nsr5hhgr95bqw3z50gm8dxcfr04vmkv-linux-6.12.32-dev/lib/modules/6.12.32/source \
objtree=/nix/store/1nsr5hhgr95bqw3z50gm8dxcfr04vmkv-linux-6.12.32-dev/lib/modules/6.12.32/source \
oottree=/home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source/kernel-devicetree \
HOSTCC=gcc \
make -f /home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source/kernel-devicetree/scripts/Makefile.build \
        obj=/home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source/kernel-devicetree/generic-dts \
        dtbs
make[1]: Entering directory '/home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source'
# DTC     /home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source/kernel-devicetree/generic-dts//hardware/nvidia/t23x/nv-public/staging/tegra234-p3737-0000+p3701-0004.dtb
  mkdir -p /home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source/kernel-devicetree/generic-dts//hardware/nvidia/t23x/nv-public/staging/ ; gcc -E -Wp,-MMD,/home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source/kernel-devicetree/generic-dts//hardware/nvidia/t23x/nv-public/staging/.tegra234-p3737-0000+p3701-0004.dtb.d.pre.tmp -nostdinc -I/home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source/hardware/nvidia/tegra/nv-public -I/home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source/hardware/nvidia/t23x/nv-public/include/kernel -I/home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source/hardware/nvidia/t23x/nv-public/include/nvidia-oot -I/home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source/hardware/nvidia/t23x/nv-public/include/platforms -I/home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source/hardware/nvidia/t23x/nv-public -I/nix/store/1nsr5hhgr95bqw3z50gm8dxcfr04vmkv-linux-6.12.32-dev/lib/modules/6.12.32/source/scripts/dtc/include-prefixes  -DLINUX_VERSION=600 -DTEGRA_HOST1X_DT_VERSION=2 -undef -D__DTS__ -x assembler-with-cpp -o /home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source/kernel-devicetree/generic-dts//hardware/nvidia/t23x/nv-public/staging/.tegra234-p3737-0000+p3701-0004.dtb.dts.tmp /home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source/kernel-devicetree/generic-dts/../..//hardware/nvidia/t23x/nv-public/staging/tegra234-p3737-0000+p3701-0004.dts ; /nix/store/1nsr5hhgr95bqw3z50gm8dxcfr04vmkv-linux-6.12.32-dev/lib/modules/6.12.32/source/scripts/dtc/dtc -o /home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source/kernel-devicetree/generic-dts//hardware/nvidia/t23x/nv-public/staging/tegra234-p3737-0000+p3701-0004.dtb -b 0 -i/home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source/kernel-devicetree/generic-dts/../..//hardware/nvidia/t23x/nv-public/staging/ -i/home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source/hardware/nvidia/tegra/nv-public -i/home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source/hardware/nvidia/t23x/nv-public/include/kernel -i/home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source/hardware/nvidia/t23x/nv-public/include/nvidia-oot -i/home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source/hardware/nvidia/t23x/nv-public/include/platforms -i/home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source/hardware/nvidia/t23x/nv-public -i/nix/store/1nsr5hhgr95bqw3z50gm8dxcfr04vmkv-linux-6.12.32-dev/lib/modules/6.12.32/source/scripts/dtc/include-prefixes -Wno-interrupt_provider -Wno-unit_address_vs_reg -Wno-unit_address_format -Wno-avoid_unnecessary_addr_size -Wno-alias_paths -Wno-graph_child_address -Wno-simple_bus_reg -Wno-unique_unit_address   -@ -@ -@ -@ -Wno-interrupt_provider -Wno-unit_address_vs_reg -Wno-unit_address_format -Wno-avoid_unnecessary_addr_size -Wno-alias_paths -Wno-graph_child_address -Wno-simple_bus_reg -Wno-unique_unit_address   -d /home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source/kernel-devicetree/generic-dts//hardware/nvidia/t23x/nv-public/staging/.tegra234-p3737-0000+p3701-0004.dtb.d.dtc.tmp /home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source/kernel-devicetree/generic-dts//hardware/nvidia/t23x/nv-public/staging/.tegra234-p3737-0000+p3701-0004.dtb.dts.tmp ; cat /home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source/kernel-devicetree/generic-dts//hardware/nvidia/t23x/nv-public/staging/.tegra234-p3737-0000+p3701-0004.dtb.d.pre.tmp /home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source/kernel-devicetree/generic-dts//hardware/nvidia/t23x/nv-public/staging/.tegra234-p3737-0000+p3701-0004.dtb.d.dtc.tmp > /home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source/kernel-devicetree/generic-dts//hardware/nvidia/t23x/nv-public/staging/.tegra234-p3737-0000+p3701-0004.dtb.d
sh: line 1: /nix/store/1nsr5hhgr95bqw3z50gm8dxcfr04vmkv-linux-6.12.32-dev/lib/modules/6.12.32/source/scripts/dtc/dtc: No such file or directory
make[1]: *** [/home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source/kernel-devicetree/generic-dts/Makefile:118: /home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source/kernel-devicetree/generic-dts//hardware/nvidia/t23x/nv-public/staging/tegra234-p3737-0000+p3701-0004.dtb] Error 127
make[1]: Leaving directory '/home/excalibur/Documents/GitHub/c200-bootupd/Linux_for_Tegra/source'
make: *** [Makefile:173: nvidia-dtbs] Error 2

I have confirmed that the missing files are in the other folder, and those files are not separated into 2 folders in headers generated by Debian.

Since the Nvidia code is just plugged into the kernel build infrastructure, to fix this build issue, I probably need to patch the kernel header, which is provided by nixpkgs. This makes me feel that it’s the nixpkgs being broken, not Nvidia.

Never mind. I figured out that you can do make KERNEL_HEADERS=/nix/store/1nsr5hhgr95bqw3z50gm8dxcfr04vmkv-linux-6.12.32-dev/lib/modules/6.12.32/source KERNEL_OUTPUT=/nix/store/1nsr5hhgr95bqw3z50gm8dxcfr04vmkv-linux-6.12.32-dev/lib/modules/6.12.32/build/ dtbs to specify both paths.

1 Like