Busybox init isn't working!
Init is the first program that runs, so it might be that no programs are working on your new system because of a problem with your cross-compiler, kernel, console settings, shared libraries, root filesystem... To rule all that out, first build a statically linked version of the following "hello world" program with your cross compiler toolchain:
#include <stdio.h>
int main(int argc, char *argv)
{
printf("Hello world!\n");
sleep(999999999);
}
Now try to boot your device with an "init=" argument pointing to your hello world program. Did you see the hello world message? Until you do, don't bother messing with Busybox init.
Once you've got it working statically linked, try getting it to work dynamically linked. Then read the FAQ entry How do I build a Busybox-based system?, and the documentation for Busybox init (FIXME: dead link)
Understanding What Causes SEGV in an Application
If a user-space application terminates with SEGV, this means, as it is always the case in Linux, that the application did something that triggered an exception to the Cortex-M processor core. The most likely causes are:
You built your application for a processor architecture other than Cortex-M, which causes an "Unsupported instruction" exception.
Your application makes an attempt to access an address outside of the Cortex-M address space.
Your application makes an attempt to access unaligned data.
To understand what is causing an exception, do the following:
Enable CONFIG_DEBUG_USER in the kernel configuration. From your project directory, bring up the kernel configuration interface by running make kmenuconfig. Go to Kernel hacking and enable Verbose user fault messages.
In U-boot, add user_debug=8 to bootargs.
Having done the above, rebuild your Linux project, bring it up on the target and re-run your application. When the application fails with SEGV, there should be some informational messages on the system console indicating the cause of the fault.
根据上面的操作过程:
开启 CONFIG_DEBUG_USER
在uboot下,bootargs 中user_debug=8
然后,我重新执行上述简单的打印程序,果然,出现了更加详细的提示:
asd: fault at 0xc1208044 [pc=0xc1208044, sp=0xc120ef30]
Invalid ISA state
无效的ISA状态,Attempt to execute an instruction when in an invalid ISA state. For example, not Thumb。然后我猜想可能是编译出来的是arm指令集而不是thumb指令集,然后我就翻看gcc的文档,添加了-march=armv7m选项,重新编译,然后,发现提示我error: target CPU does not support ARM mode。看到了这里,我猜想是印证了我之前的假设,于是我查看如何声明gcc,编译生成thumb指令集的文件,然后,我就发现了-mthumb选项。再我添加了这个选项之后,可以编译通过了,在可以启动的根文件系统下运行这个程序,发现可以打印出来,然后就是修改busybox的编译选项。