insmod: init_module ‘hello.ko’ failed (Exec format error)

With the metere kernel, an Android simulator has been run and another compiled kernel is being added dynamically.
I initially found a hello.c file from the Web and wrote the Makefile the way he did, but when I ran the command insmod, it reported an error:
insmod: init_module ‘hello.ko’ failed (Exec format error)
Period, check a lot of information is still not solved, and then to test it according to this blog, succeeded, the connection address:
Next I post his Makefie file. There is no problem with the hello.c file, but the problem is with the Makefile. Write the Makefile the way he writes it and you can dynamically insert your own compiled kernel. The following code is posted:
Obj – m: = hello – yf. O
hello – yf – objs: = hello. O

KID: = ~/android – kernel/goldfish
the PWD: = $(shell PWD)
the ARCH = arm
CROSS_COMPILE = arm eabi –

the make – C $(KID) ARCH = $(ARCH) CROSS_COMPILE = $(CROSS_COMPILE) M = ${PWD} modules

the clean:
rm-rf *. O. CMD *. Ko *. Mod. C. tmp_versions
however, I do not know why he writes this way right now, I am looking into it. I’ve been updating this blog since I figured it out, but this problem has been solved.
I think I understand why, but look at this code:
mak-c $(KID) ARCH=$(CROSS_COMPILE) M=${PWD} modules

I think this piece of code is the key to solve this problem. First, with mak-c $(KID), the local path of the current source code is given into the compile environment. Then assign the ARCH and cross-compiled environment variables separately, so that the above problems will not occur. You should have no problem writing makefiles this way if you want to compile your own kernel.
——————————————————————————————————————————————————————————————————– ———————–
To update this, the ‘M=’ option is used to add ‘M=dir’ to the make modules command when the user needs to compile an external module based on a kernel. The program will automatically look for the module’s source code in the dir directory you specify, compile it, and generate the KO file. This allows the generated KO files to be dynamically inserted into the kernel.

Read More: