I haven’t tried your specific file, but for cross compile you also need to name the tool chain (and preferably a separate output location). For example, if your compiler is at (adjust to where it really is):
make ARCH=arm64 CROSS_COMPILE=~/nvidia/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu- O=~/output -C ~/nvidia/kernel_headers/linux-headers-4.9.140-tegra-ubuntu18.04_aarch64/kernel-4.9 M=~/nvidia/nvidia_sdk/module_src/test modules
make: Entering directory '/home/maxsense/nvidia/kernel_headers/linux-headers-4.9.140-tegra-ubuntu18.04_aarch64/kernel-4.9'
make[1]: Entering directory '/home/maxsense/output'
WARNING: Symbol version dump ./Module.symvers
is missing; modules will have no dependencies and modversions.
CC [M] /home/maxsense/nvidia/nvidia_sdk/module_src/test/test.o
In file included from /home/maxsense/nvidia/kernel_headers/linux-headers-4.9.140-tegra-ubuntu18.04_aarch64/kernel-4.9/include/linux/types.h:5:0,
from /home/maxsense/nvidia/kernel_headers/linux-headers-4.9.140-tegra-ubuntu18.04_aarch64/kernel-4.9/include/linux/list.h:4,
from /home/maxsense/nvidia/kernel_headers/linux-headers-4.9.140-tegra-ubuntu18.04_aarch64/kernel-4.9/include/linux/module.h:9,
from /home/maxsense/nvidia/nvidia_sdk/module_src/test/test.c:22:
/home/maxsense/nvidia/kernel_headers/linux-headers-4.9.140-tegra-ubuntu18.04_aarch64/kernel-4.9/include/uapi/linux/types.h:4:10: fatal error: asm/types.h: No such file or directory
#include <asm/types.h>
^~~~~~~~~~~~~
compilation terminated.
/home/maxsense/nvidia/kernel_headers/linux-headers-4.9.140-tegra-ubuntu18.04_aarch64/kernel-4.9/scripts/Makefile.build:341: recipe for target '/home/maxsense/nvidia/nvidia_sdk/module_src/test/test.o' failed
make[2]: *** [/home/maxsense/nvidia/nvidia_sdk/module_src/test/test.o] Error 1
/home/maxsense/nvidia/kernel_headers/linux-headers-4.9.140-tegra-ubuntu18.04_aarch64/kernel-4.9/Makefile:1629: recipe for target '_module_/home/maxsense/nvidia/nvidia_sdk/module_src/test' failed
make[1]: *** [_module_/home/maxsense/nvidia/nvidia_sdk/module_src/test] Error 2
make[1]: Leaving directory '/home/maxsense/output'
Makefile:171: recipe for target 'sub-make' failed
make: *** [sub-make] Error 2
make: Leaving directory '/home/maxsense/nvidia/kernel_headers/linux-headers-4.9.140-tegra-ubuntu18.04_aarch64/kernel-4.9'
command 2, no output path
make ARCH=arm64 CROSS_COMPILE=~/nvidia/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu- -C ~/nvidia/kernel_headers/linux-headers-4.9.140-tegra-ubuntu18.04_aarch64/kernel-4.9 M=~/nvidia/nvidia_sdk/module_src/test modules
Some suggestions, but probably not a complete answer. Go to the “~/output” directory, recursively clean out everything. Then, from a running Jetson, copy the “/proc/config.gz” there. Use gunzip, and finally, rename it as “.config”. Edit the entry for “CONFIG_LOCALVERSION” to be:
CONFIG_LOCALVERSION="-tegra"
Then build a full kernel. See if the kernel dependencies are met to complete a non-custom module this way:
Does this succeed? You could then do the same command with “modules” target instead of “Image” target. Keep in mind that any time you build a module you do need “modules_prepare” if the base kernel build did not occur first (there are setup details which would be missing if you build modules without full kernel information, and “modules_prepare” target sets that up…or building the kernel sets it up, but a full kernel build is a superior sanity check).
If your host PC has multiple cores, e.g., 8 cores, then you can speed things up with “-J #”, where “#” is the number of cores you have. Example:
On non-Jetson system, I must have kernel source if I want to build kernel image. And if I build external modules, I must unZip kernel_headers.You mean I can build a kernel image from the kernel_headers?? According to the guider, I have built kernel image successfully from kernel source.
I think I know what you mean.
the “O=/home/…” path must be the kernel image path, which means I must compile kernel image before modules.
I have built kernel image before, so I change the makefile as follows and build test module successfully: