How to get modules_prepare to function?

I am looking into installing of v4l2loopback, but that seems to have an issue :

sudo su
root@jetson-876876:/home/nvidia# cd /usr/src/linux-headers-4.9.108-tegra/root@jetson-:/usr/src/linux-headers-4.9.108-tegra# make modules_prepare
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/basic/bin2c
  HOSTCC  scripts/kconfig/conf.o
  HOSTCC  scripts/kconfig/zconf.tab.o
  HOSTLD  scripts/kconfig/conf
scripts/kconfig/conf  --silentoldconfig Kconfig
arch/arm64/Kconfig:1221: can't open file "drivers/firmware/tegra/Kconfig"
scripts/kconfig/Makefile:37: recipe for target 'silentoldconfig' failed
make[2]: *** [silentoldconfig] Error 1
Makefile:562: recipe for target 'silentoldconfig' failed
make[1]: *** [silentoldconfig] Error 2
make: *** No rule to make target 'include/config/auto.conf', needed by 'include/config/kernel.release'.  Stop.

Did you download and install the L4T kernel sources first?

what is the sequence for download and install the L4T kernel sources ?

You can download the source package from Nvidia:

[url]https://developer.nvidia.com/embedded/dlc/l4t-sources-31-0-2[/url]

Or you can use source_sync.sh in L4T that will clone the public Nvidia repositories for you. Unfortunately that script is currently broken but you can fix it:

[url]https://devtalk.nvidia.com/default/topic/1039294/jetson-agx-xavier/custom-kernel-selection-on-xavier/post/5286679/#5286679[/url]

Thank you for sharing,
if my objective is to perform

./modules_prepare

for integrating v4l2loopback, and I have downloaded the source package https://developer.nvidia.com/embedded/dlc/l4t-sources-31-0-2 to the jetson, what will be the next step that will allow to execute the

modules_prepare

?
I downloaded them, unzipped, extracted the component kernel_src.tbz2
how do I install them?
Thanks

It is a “make” target. “make modules_prepare”. You’d need to know that your config is valid prior to this. I always start with putting the decompressed version of “/proc/config.gz” in the kernel top level directory and editing CONFIG_LOCALVERSION. Other than that it becomes fairly standard for a kernel build (add whatever cross compile arguments you need if not doing native compile).

but how to build the kernel at the target device natively after I downloaded and unpacked the sources to ‘kernel/kernel-4.9/’.
Could you extend on that?
As I understand, first it needs to copy and unpack /proc/config.gz to ‘the kernel top level folder’.
But what edition of CONFIG_LOCALVERSION may be required?
Thanks.

Can anybody confirm make module prepare to work at their side?

cd /usr/src/linux-headers-4.9.108-tegra/root@jetson-0423018055018:/usr/src/linux-headers-4.9.108-tegra# make modules_prepare
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/basic/bin2c
  HOSTCC  scripts/kconfig/conf.o
  HOSTCC  scripts/kconfig/zconf.tab.o
  HOSTLD  scripts/kconfig/conf
scripts/kconfig/conf  --silentoldconfig Kconfig
arch/arm64/Kconfig:1221: can't open file "drivers/firmware/tegra/Kconfig"
scripts/kconfig/Makefile:37: recipe for target 'silentoldconfig' failed
make[2]: *** [silentoldconfig] Error 1
Makefile:562: recipe for target 'silentoldconfig' failed
make[1]: *** [silentoldconfig] Error 2
make: *** No rule to make target 'include/config/auto.conf', needed by 'include/config/kernel.release'.  Stop.

@snarky in that iteration I downloaded and installed the kernel sources first.

I installed “gcc-6” since the 6.4 version was specified in docs:

sudo apt-get install gcc-6

EDIT: I forgot to mention, before building the kernel, I run this:

export CC=/usr/bin/gcc-6

…which causes the 6.4 version of gcc to be used.

I didn’t do just the modules_prepare, but after having my source it goes something like this (you will have to create and set permissions for user ubuntu or nvidia since I don’t compile as root):

sudo nvpmodel -m 0
# Unpack in "/usr/local/src/kernel_tree/", owned and writeable by user "ubuntu".
export SRC=/usr/local/src/kernel_tree/kernel/kernel-4.9
export STAGE=/usr/local/src/build
export TEGRA_KERNEL_OUT=${STAGE}/kernel
export TEGRA_MODULES_OUT=${STAGE}/modules
rm -Rf ${STAGE:-/usr/local/src/build}/*
mkdir ${STAGE:-/usr/local/src/build}/kernel
mkdir ${STAGE:-/usr/local/src/build}/modules
mkdir ${STAGE:-/usr/local/src/build}/firmware
cp /proc/config.gz ${STAGE:-/usr/local/src/build}/
gunzip ${STAGE:-/usr/local/src/build}/config.gz
mv ${STAGE:-/usr/local/src/build}/config ${STAGE:-/usr/local/src/build}/config-$(uname -r)
# Edit CONFIG_LOCALVERSION for the "uname -r" suffix.
cd $SRC
make O=$TEGRA_KERNEL_OUT nconfig
make -j8 O=$TEGRA_KERNEL_OUT Image
make -j8 O=$TEGRA_KERNEL_OUT modules
make O=$TEGRA_KERNEL_OUT modules_install INSTALL_MOD_PATH=$TEGRA_MODULES_OUT
make O=$TEGRA_KERNEL_OUT firmware_install INSTALL_FW_PATH=$TEGRA_FIRMWARE_OUT

In theory (I didn’t test) you could run “make O=$TEGRA_KERNEL_OUT modules_prepare” instead of “Image”.

@linuxdev, thank you for sharing.
I am looking to get v4l2loopback module to function somehow.
At TX2 I could get that with module_prepare, or with a provided by other folk .ko file.

I added one “EDIT” to that post…I had forgot to mention that installing gcc-6 doesn’t cause it to be used. It also has to be exported as “CC=/usr/bin/gcc-6”.

In any case, try building the whole kernel just as a debug step if modules_prepare won’t do the trick.

At a minum, you have to install the correct config file, and “make oldconfig” in the kernel directory before you can then “make modules_prepare”

This means something’s not yet prepared about your kernel tree. “make oldconfig” or a similar command “make menuconfig” could potentially fix that.

@snarky:

/usr/src/linux-headers-4.9.108-tegra$ make menuconfig
  HOSTCC  scripts/kconfig/mconf.o
<command-line>:0:12: fatal error: curses.h: No such file or directory
compilation terminated.
scripts/Makefile.host:124: recipe for target 'scripts/kconfig/mconf.o' failed
make[1]: *** [scripts/kconfig/mconf.o] Error 1
Makefile:562: recipe for target 'menuconfig' failed
make: *** [menuconfig] Error 2
nvidia@jetson-12345:/usr/src/linux-headers-4.9.108-tegra$ make oldconfigscripts/kconfig/conf  --oldconfig Kconfig

arch/arm64/Kconfig:1221: can't open file "drivers/firmware/tegra/Kconfig"
scripts/kconfig/Makefile:86: recipe for target 'oldconfig' failed
make[1]: *** [oldconfig] Error 1
Makefile:562: recipe for target 'oldconfig' failed
make: *** [oldconfig] Error 2

@linuxdev: thank you for the hint, next rebuild kernel procedure I will try specify gcc-6 parameter

sudo apt-get install libncurses5-dev
Setting up libncurses5-dev:arm64 (6.1-1ubuntu1.18.04) ...
Processing triggers for man-db (2.8.3-2) ...
nvidia@jetson-786876:/usr/src/linux-headers-4.9.108-tegra$ make modules_prepare
arch/arm64/Makefile:40: LSE atomics not supported by binutils
  HOSTCC  scripts/kconfig/conf.o
scripts/kconfig/conf.c:723:1: fatal error: opening dependency file scripts/kconfig/.conf.o.d: Permission denied
 }
 ^
compilation terminated.
scripts/Makefile.host:124: recipe for target 'scripts/kconfig/conf.o' failed
make[2]: *** [scripts/kconfig/conf.o] Error 1
Makefile:562: recipe for target 'silentoldconfig' failed
make[1]: *** [silentoldconfig] Error 2
make: *** No rule to make target 'include/config/auto.conf', needed by 'include/config/kernel.release'.  Stop.
nvidia@jetson-8768976:/usr/src/linux-headers-4.9.108-tegra$ sudo make modules_prepare
  HOSTCC  scripts/kconfig/conf.o
  HOSTCC  scripts/kconfig/zconf.tab.o
  HOSTLD  scripts/kconfig/conf
scripts/kconfig/conf  --silentoldconfig Kconfig
arch/arm64/Kconfig:1221: can't open file "drivers/firmware/tegra/Kconfig"
scripts/kconfig/Makefile:37: recipe for target 'silentoldconfig' failed
make[2]: *** [silentoldconfig] Error 1
Makefile:562: recipe for target 'silentoldconfig' failed
make[1]: *** [silentoldconfig] Error 2
make: *** No rule to make target 'include/config/auto.conf', needed by 'include/config/kernel.release'.  Stop.
sudo make menuconfig
  HOSTCC  scripts/kconfig/mconf.o
  HOSTCC  scripts/kconfig/lxdialog/checklist.o
  HOSTCC  scripts/kconfig/lxdialog/util.o
  HOSTCC  scripts/kconfig/lxdialog/inputbox.o
  HOSTCC  scripts/kconfig/lxdialog/textbox.o
  HOSTCC  scripts/kconfig/lxdialog/yesno.o
  HOSTCC  scripts/kconfig/lxdialog/menubox.o
  HOSTLD  scripts/kconfig/mconf
scripts/kconfig/mconf  Kconfig
arch/arm64/Kconfig:1221: can't open file "drivers/firmware/tegra/Kconfig"
scripts/kconfig/Makefile:28: recipe for target 'menuconfig' failed
make[1]: *** [menuconfig] Error 1
Makefile:562: recipe for target 'menuconfig' failed
make: *** [menuconfig] Error 2

will try to rebuild kernel again

You might try to build in the kernel source directory instead of the headers directory.

thank you, that is a good idea

cp ~/kernel_out/.config .config
~/Downloads/public_sources/kernel/kernel-4.9$ make modules_prepare
  HOSTCC  scripts/kconfig/conf.o
  HOSTLD  scripts/kconfig/conf
scripts/kconfig/conf  --silentoldconfig Kconfig
  CHK     include/config/kernel.release
  UPD     include/config/kernel.release
  WRAP    arch/arm64/include/generated/asm/bugs.h
  WRAP    arch/arm64/include/generated/asm/clkdev.h
  WRAP    arch/arm64/include/generated/asm/cputime.h
  WRAP    arch/arm64/include/generated/asm/current.h
  WRAP    arch/arm64/include/generated/asm/delay.h
  WRAP    arch/arm64/include/generated/asm/div64.h
  WRAP    arch/arm64/include/generated/asm/dma.h
  WRAP    arch/arm64/include/generated/asm/dma-contiguous.h
  WRAP    arch/arm64/include/generated/asm/early_ioremap.h
  WRAP    arch/arm64/include/generated/asm/emergency-restart.h
  WRAP    arch/arm64/include/generated/asm/errno.h
  WRAP    arch/arm64/include/generated/asm/hw_irq.h
  WRAP    arch/arm64/include/generated/asm/ioctl.h
  WRAP    arch/arm64/include/generated/asm/ioctls.h
  WRAP    arch/arm64/include/generated/asm/ipcbuf.h
  WRAP    arch/arm64/include/generated/asm/irq_regs.h
  WRAP    arch/arm64/include/generated/asm/kdebug.h
  WRAP    arch/arm64/include/generated/asm/kmap_types.h
  WRAP    arch/arm64/include/generated/asm/kvm_para.h
  WRAP    arch/arm64/include/generated/asm/local.h
  WRAP    arch/arm64/include/generated/asm/local64.h
  WRAP    arch/arm64/include/generated/asm/mcs_spinlock.h
  WRAP    arch/arm64/include/generated/asm/mm-arch-hooks.h
  WRAP    arch/arm64/include/generated/asm/mman.h
  WRAP    arch/arm64/include/generated/asm/msgbuf.h
  WRAP    arch/arm64/include/generated/asm/msi.h
  WRAP    arch/arm64/include/generated/asm/mutex.h
  WRAP    arch/arm64/include/generated/asm/poll.h
  WRAP    arch/arm64/include/generated/asm/preempt.h
  WRAP    arch/arm64/include/generated/asm/resource.h
  WRAP    arch/arm64/include/generated/asm/rwsem.h
  WRAP    arch/arm64/include/generated/asm/segment.h
  WRAP    arch/arm64/include/generated/asm/sembuf.h
  WRAP    arch/arm64/include/generated/asm/serial.h
  WRAP    arch/arm64/include/generated/asm/shmbuf.h
  WRAP    arch/arm64/include/generated/asm/simd.h
  WRAP    arch/arm64/include/generated/asm/sizes.h
  WRAP    arch/arm64/include/generated/asm/socket.h
  WRAP    arch/arm64/include/generated/asm/sockios.h
  WRAP    arch/arm64/include/generated/asm/swab.h
  WRAP    arch/arm64/include/generated/asm/switch_to.h
  WRAP    arch/arm64/include/generated/asm/termbits.h
  WRAP    arch/arm64/include/generated/asm/termios.h
  WRAP    arch/arm64/include/generated/asm/trace_clock.h
  WRAP    arch/arm64/include/generated/asm/types.h
  WRAP    arch/arm64/include/generated/asm/unaligned.h
  WRAP    arch/arm64/include/generated/asm/user.h
  WRAP    arch/arm64/include/generated/asm/vga.h
  WRAP    arch/arm64/include/generated/asm/xor.h
  WRAP    arch/arm64/include/generated/uapi/asm/kvm_para.h
  CHK     include/generated/uapi/linux/version.h
  UPD     include/generated/uapi/linux/version.h
  CHK     include/generated/utsrelease.h
  UPD     include/generated/utsrelease.h
  HOSTCC  scripts/basic/bin2c
  CC      kernel/bounds.s
  CHK     include/generated/bounds.h
  UPD     include/generated/bounds.h
  CHK     include/generated/timeconst.h
  UPD     include/generated/timeconst.h
  CC      arch/arm64/kernel/asm-offsets.s
  CHK     include/generated/asm-offsets.h
  UPD     include/generated/asm-offsets.h
  CALL    scripts/checksyscalls.sh
  LDS     arch/arm64/kernel/vdso/vdso.lds
  VDSOA   arch/arm64/kernel/vdso/gettimeofday.o
  VDSOA   arch/arm64/kernel/vdso/note.o
  VDSOA   arch/arm64/kernel/vdso/sigreturn.o
  VDSOL   arch/arm64/kernel/vdso/vdso.so.dbg
  VDSOSYM include/generated/vdso-offsets.h
  HOSTCC  scripts/dtc/dtc.o
  HOSTCC  scripts/dtc/flattree.o
  HOSTCC  scripts/dtc/fstree.o
  HOSTCC  scripts/dtc/data.o
  HOSTCC  scripts/dtc/livetree.o
  HOSTCC  scripts/dtc/treesource.o
  HOSTCC  scripts/dtc/srcpos.o
  HOSTCC  scripts/dtc/checks.o
  HOSTCC  scripts/dtc/util.o
  SHIPPED scripts/dtc/dtc-lexer.lex.c
  SHIPPED scripts/dtc/dtc-parser.tab.h
  HOSTCC  scripts/dtc/dtc-lexer.lex.o
  SHIPPED scripts/dtc/dtc-parser.tab.c
  HOSTCC  scripts/dtc/dtc-parser.tab.o
  HOSTLD  scripts/dtc/dtc
  HOSTCC  scripts/genksyms/genksyms.o
  SHIPPED scripts/genksyms/parse.tab.c
  HOSTCC  scripts/genksyms/parse.tab.o
  SHIPPED scripts/genksyms/lex.lex.c
  SHIPPED scripts/genksyms/keywords.hash.c
  SHIPPED scripts/genksyms/parse.tab.h
  HOSTCC  scripts/genksyms/lex.lex.o
  HOSTLD  scripts/genksyms/genksyms
  CC      scripts/mod/empty.o
  HOSTCC  scripts/mod/mk_elfconfig
  MKELF   scripts/mod/elfconfig.h
  HOSTCC  scripts/mod/modpost.o
  CC      scripts/mod/devicetable-offsets.s
  GEN     scripts/mod/devicetable-offsets.h
  HOSTCC  scripts/mod/file2alias.o
  HOSTCC  scripts/mod/sumversion.o
  HOSTLD  scripts/mod/modpost
  HOSTCC  scripts/kallsyms
  HOSTCC  scripts/pnmtologo
  HOSTCC  scripts/conmakehash
  HOSTCC  scripts/recordmcount
  HOSTCC  scripts/sortextable

but that way the output error of different kind happens

~/Downloads/public_sources/kernel/kernel-4.9$ mkdir v4l2loopback
nvidia@jetson-:~/Downloads/public_sources/kernel/kernel-4.9$ cd v4l2loopback
nvidia@jetson-:~/Downloads/public_sources/kernel/kernel-4.9/v4l2loopback$ 
nvidia@jetson-:~/Downloads/public_sources/kernel/kernel-4.9/v4l2loopback$ git clone https://github.com/umlaeute/v4l2loopback.git
Cloning into 'v4l2loopback'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 1672 (delta 0), reused 1 (delta 0), pack-reused 1669
Receiving objects: 100% (1672/1672), 763.47 KiB | 708.00 KiB/s, done.
Resolving deltas: 100% (938/938), done.
nvidia@jetson:~/Downloads/public_sources/kernel/kernel-4.9/v4l2loopback$ 
nvidia@jetson:~/Downloads/public_sources/kernel/kernel-4.9/v4l2loopback$ cd v4l2loopback
nvidia@jetson-:~/Downloads/public_sources/kernel/kernel-4.9/v4l2loopback/v4l2loopback$ 
nvidia@jetson-:~/Downloads/public_sources/kernel/kernel-4.9/v4l2loopback/v4l2loopback$ make
make
Building v4l2-loopback driver...
make -C /lib/modules/`uname -r`/build M=/home/nvidia/Downloads/public_sources/kernel/kernel-4.9/v4l2loopback/v4l2loopback modules
make[1]: *** /lib/modules/4.9.108/build: No such file or directory.  Stop.
Makefile:42: recipe for target 'v4l2loopback.ko' failed
make: *** [v4l2loopback.ko] Error 2
sudo apt-get install v4l2loopback-utils
[sudo] password for nvidia: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  liblockfile-bin liblockfile1 lockfile-progs
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  dkms libv4l2rds0 linux-headers-4.15.0-36 linux-headers-4.15.0-36-generic
  linux-headers-generic v4l-utils v4l2loopback-dkms
Suggested packages:
  menu
The following NEW packages will be installed:
  dkms libv4l2rds0 linux-headers-4.15.0-36 linux-headers-4.15.0-36-generic
  linux-headers-generic v4l-utils v4l2loopback-dkms v4l2loopback-utils
0 upgraded, 8 newly installed, 0 to remove and 199 not upgraded.
Need to get 12.2 MB of archives.
After this operation, 87.2 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://ports.ubuntu.com/ubuntu-ports bionic-updates/main arm64 dkms all 2.3-3ubuntu9.2 [68.0 kB]
Get:2 http://ports.ubuntu.com/ubuntu-ports bionic/main arm64 libv4l2rds0 arm64 1.14.2-1 [14.8 kB]
Get:3 http://ports.ubuntu.com/ubuntu-ports bionic-updates/main arm64 linux-headers-4.15.0-36 all 4.15.0-36.39 [11.0 MB]
Get:4 http://ports.ubuntu.com/ubuntu-ports bionic-updates/main arm64 linux-headers-4.15.0-36-generic arm64 4.15.0-36.39 [744 kB]
Get:5 http://ports.ubuntu.com/ubuntu-ports bionic-updates/main arm64 linux-headers-generic arm64 4.15.0.36.38 [2,376 B]
Get:6 http://ports.ubuntu.com/ubuntu-ports bionic/universe arm64 v4l-utils arm64 1.14.2-1 [384 kB]
Get:7 http://ports.ubuntu.com/ubuntu-ports bionic/universe arm64 v4l2loopback-dkms all 0.10.0-1ubuntu1 [23.1 kB]
Get:8 http://ports.ubuntu.com/ubuntu-ports bionic/universe arm64 v4l2loopback-utils arm64 0.10.0-1ubuntu1 [8,544 B]
Fetched 12.2 MB in 8s (1,537 kB/s)                                             
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package dkms.
(Reading database ... 113142 files and directories currently installed.)
Preparing to unpack .../0-dkms_2.3-3ubuntu9.2_all.deb ...
Unpacking dkms (2.3-3ubuntu9.2) ...
Selecting previously unselected package libv4l2rds0:arm64.
Preparing to unpack .../1-libv4l2rds0_1.14.2-1_arm64.deb ...
Unpacking libv4l2rds0:arm64 (1.14.2-1) ...
Selecting previously unselected package linux-headers-4.15.0-36.
Preparing to unpack .../2-linux-headers-4.15.0-36_4.15.0-36.39_all.deb ...
Unpacking linux-headers-4.15.0-36 (4.15.0-36.39) ...
Selecting previously unselected package linux-headers-4.15.0-36-generic.
Preparing to unpack .../3-linux-headers-4.15.0-36-generic_4.15.0-36.39_arm64.deb ...
Unpacking linux-headers-4.15.0-36-generic (4.15.0-36.39) ...
Selecting previously unselected package linux-headers-generic.
Preparing to unpack .../4-linux-headers-generic_4.15.0.36.38_arm64.deb ...
Unpacking linux-headers-generic (4.15.0.36.38) ...
Selecting previously unselected package v4l-utils.
Preparing to unpack .../5-v4l-utils_1.14.2-1_arm64.deb ...
Unpacking v4l-utils (1.14.2-1) ...
Selecting previously unselected package v4l2loopback-dkms.
Preparing to unpack .../6-v4l2loopback-dkms_0.10.0-1ubuntu1_all.deb ...
Unpacking v4l2loopback-dkms (0.10.0-1ubuntu1) ...
Selecting previously unselected package v4l2loopback-utils:arm64.
Preparing to unpack .../7-v4l2loopback-utils_0.10.0-1ubuntu1_arm64.deb ...
Unpacking v4l2loopback-utils:arm64 (0.10.0-1ubuntu1) ...
Setting up libv4l2rds0:arm64 (1.14.2-1) ...
Setting up v4l-utils (1.14.2-1) ...
Setting up dkms (2.3-3ubuntu9.2) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Processing triggers for man-db (2.8.3-2) ...
Setting up v4l2loopback-utils:arm64 (0.10.0-1ubuntu1) ...
Setting up linux-headers-4.15.0-36 (4.15.0-36.39) ...
Setting up linux-headers-4.15.0-36-generic (4.15.0-36.39) ...
Setting up v4l2loopback-dkms (0.10.0-1ubuntu1) ...
Loading new v4l2loopback-0.10.0 DKMS files...
It is likely that 4.9.108 belongs to a chroot's host
Building for 4.15.0-36-generic and 4.9.108-tegra
Building initial module for 4.15.0-36-generic
Done.

v4l2loopback:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/4.15.0-36-generic/updates/dkms/

depmod...

DKMS: install completed.
Building initial module for 4.9.108-tegra
ERROR (dkms apport): kernel package linux-headers-4.9.108-tegra is not supported
Error! Bad return status for module build on kernel: 4.9.108-tegra (aarch64)
Consult /var/lib/dkms/v4l2loopback/0.10.0/build/make.log for more information.
Setting up linux-headers-generic (4.15.0.36.38)

what to specify at the step below?

make O=$TEGRA_KERNEL_OUT nconfig