Build a .ko file

I want to build the chrdevbase.ko and use the Makefile below.

KERNELDIR := /home/umlinux/nvidia_sources/Linux_for_Tegra/source/public/kernel/kernel-4.9/out

CURRENT_PATH := $(shell pwd)

obj-m := chrdevbase.o

build: kernel_modules

kernel_modules:

$(MAKE) -C $(KERNELDIR) M=$(CURRENT_PATH) modules

clean:

$(MAKE) -C $(KERNELDIR) M=$(CURRENT_PATH) clean

It’s failed! error:
make -C /home/umlinux/nvidia_sources/Linux_for_Tegra/source/public/kernel/kernel-4.9/out M=/home/umlinux/chrdevbase modules
make[1]: 进入目录“/home/umlinux/nvidia_sources/Linux_for_Tegra/source/public/kernel/kernel-4.9/out”
CC [M] /home/umlinux/chrdevbase/chrdevbase.o
aarch64-linux-gnu-gcc: error: unrecognized argument in option ‘-mcmodel=kernel’
aarch64-linux-gnu-gcc: note: valid arguments to ‘-mcmodel=’ are: large small tiny
aarch64-linux-gnu-gcc: error: unrecognized command line option ‘-mno-sse’; did you mean ‘-fno-dse’?
aarch64-linux-gnu-gcc: error: unrecognized command line option ‘-mno-mmx’
aarch64-linux-gnu-gcc: error: unrecognized command line option ‘-mno-sse2’; did you mean ‘-fno-dse’?
aarch64-linux-gnu-gcc: error: unrecognized command line option ‘-mno-3dnow’
aarch64-linux-gnu-gcc: error: unrecognized command line option ‘-m64’
aarch64-linux-gnu-gcc: error: unrecognized command line option ‘-mno-red-zone’; did you mean ‘-fno-regmove’?
make[4]: *** […/scripts/Makefile.build:342:/home/umlinux/chrdevbase/chrdevbase.o] 错误 1
make[3]: *** [/home/umlinux/nvidia_sources/Linux_for_Tegra/source/public/kernel/kernel-4.9/Makefile:1656:module/home/umlinux/chrdevbase] 错误 2
make[2]: *** [Makefile:171:sub-make] 错误 2
make[1]: *** [Makefile:24:__sub-make] 错误 2
make[1]: 离开目录“/home/umlinux/nvidia_sources/Linux_for_Tegra/source/public/kernel/kernel-4.9/out”
make: *** [Makefile:8:kernel_modules] 错误 2

Could someone help me ? Thanks.

Maybe move the umlinux directory to …/kernel/kernel-4.9/

It can’t work also.

Did you verify it by obj-y := chrdevbase.o

I want to build a separate module, so I use the variable “obj-m”.

modifying the command to “$(MAKE) ARCH=arm64 -C $(KERNELDIR) M=$(CURRENT_PATH) modules” in Makefile can solve the problem.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.