I have an embedded ARM system with processor AT91SAM9G45. I try to build linux kernel with initramfs for this system. Kernel version is 4.14.79.
After loading kernel and initramfs image at device I have following:
Kernel definitely finds out initramfs image, unpacks it and sets it into memory.
Kernel definityle finds all files in initramfs image, I see it in debug messages I've added into linux kernel source code.
After unpacking initramfs image kernel tries to start /init process. /init processes starts and instantly returns 0 (0 means no errors) and then instantly throws kernel panic message:
Freeing unused kernel memory: 384K
This architecture does not have kernel memory protection.
run_init_process BEFORE /init
run_init_process AFTER /init, result = 0
Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000004
"run_init_process_BEFORE /init" and "run_init_process /init, result = 0" are debug messages that I've added to linux source code.
Initramfs image is build by using busybox.
There is no difference, what an initial script or executable file I try to start. Results are same. If /init script tries to echo some message and sleep for some seconds, kernel does not show message and does not wait, and throws panic message instantly.
So I compiled statically this simple program and tried to start it:
#include <stdio.h>
int main(int argc, char *argv)
{
printf("Hello world!\n");
sleep(999999999);
}
Same result, with no "Hello world!" and with no sleeping:
Freeing unused kernel memory: 384K
This architecture does not have kernel memory protection.
run_init_process BEFORE /hello
run_init_process AFTER /hello, result = 0
Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000004
If I compile this program with x86_64 gcc compiler, result is -8:
Same result, with no "Hello world!" and sleeping:
Freeing unused kernel memory: 384K
This architecture does not have kernel memory protection.
run_init_process BEFORE /hello
run_init_process AFTER /hello, result = -8
Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000004
So it means that linux kernel defines whether the file is executable at current platform.
If I compile hello.c program with no static linking, result is -2 (and kernel panic message after this). If I put .so files into initramfs image at the /lib folder, result is 0, and kernel panic message after this. If I put .so files that are compiled with x86_64 compiler, result is -13, and kernel panic message after this.
So what's the reason of this message? I cannot find it out.