您的位置:首页 > 其它

arm系统启动后运行 helloworld ("hello world" 被封装为ramdisk)

2015-07-07 16:51 465 查看
----------------------------------------

arm系统启动后运行 helloworld

----------------------------------------

编译环境:arm交叉环境:

1. 交叉编译linux 内核。 注意make 时, ARCH=arm

交叉编译前缀为 CROSS_COMPILE=arm-none-linux-gnueabi-

建议直接修改Makefile, 修改ARCH, CROSS_COMPILE 变量为:

ARCH ?= arm

CROSS_COMPILE ?= arm-none-linux-gnueabi-

make defconfig 或者 make versatile_defconfig

此时make 会生成 arch/arm/boot/zImage, 但这个内核文件运行时会出问题:

:Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000004

解决办法:重新配置内核支持EABI

make clean

make menuconfigKernel Features --->

   [*] Use the ARM EABI to compile the kernel

   [*] Allow old ABI binaries to run with this kernel (EXPERIMENTAL)

为什么出现这个问题没有深究,也许是qemu或者代码本身问题,这样解决也就可以了。

2. 编译一个arm 执行程序hello

参考:http://blog.csdn.net/hejinjing_tom_com/article/details/46788283

3. 令内核启动完成后跳入hello

甲: 将hello打包为ramfs

$ echo hello | cpio -o --format=newc > initramfs

乙: 模拟运行

$ qemu-system-arm -M versatilepb -kernel zImage -initrd initramfs -append "root=/dev/ram rdinit=/hello"

root=/dev/ram 指明根文件系统在ram, -initrd 模拟根文件系统。 rdinit= ... 第一个运行程序

$ qemu-system-arm -M versatilepb -kernel zImage -initrd initramfs -nographic -append "root=/dev/ram rdinit=/hello console=ttyAMA0"

这里模拟了串口,控制台输出从那个挺难看的小窗口挪到了本地,字体好看多了。

-nographic disable graphical output and redirect serial I/Os to console

Intel/Sharp Extended Query Table at 0x0031

Using buffer write method

smc91x.c: v1.1, sep 22 2004 by Nicolas Pitre <nico@fluxnic.net>

smc91x smc91x.0 eth0: SMC91C11xFD (rev 1) at c89c8000 IRQ 57

[nowait]

smc91x smc91x.0 eth0: Ethernet addr: 52:54:00:12:34:56

mousedev: PS/2 mouse device common for all mice

TCP: cubic registered

NET: Registered protocol family 17

drivers/rtc/hctosys.c: unable to open rtc device (rtc0)

Freeing unused kernel memory: 124K (c03c2000 - c03e1000)

---------- hello qemu ------------

input: AT Raw Set 2 keyboard as /devices/fpga:06/serio0/input/input0

input: ImExPS/2 Generic Explorer Mouse as /devices/fpga:07/serio1/input/input2

(qemu)

hello qemu 出来的真不容易!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: