在前面四章建立好的開發環境基礎上我們來寫一個應用程序,然後將它在Qemu模擬出來的ARM開發板中運行
首先寫程序
#include <stdio.h>
int main()
{
printf("hello linux world!!!");
return 0;
}
編譯程序
arm-none-linux-gnueabi-gcc hello.c -o hello
將程序拷到rootfs目錄下,然後執行如下:
sudo mount -t ext3 a9rootfs.ext3 tmpfs/ -o loop
sudo cp -r rootfs/* tmpfs/
sudo umount tmpfs
用Qemu測試
qemu-system-arm -M vexpress-a9 -m 512M -kernel /qemu_arm/linux-kernel/linux-3.16.39/arch/arm/boot/zImage -nographic -append "root=/dev/mmcblk0 console=ttyAMA0" -sd /qemu_arm/root_system/a9rootfs.ext3
在啓動完成後的提示符下輸入 /hello顯示結果如下:
input: ImExPS/2 Generic Explorer Mouse as /devices/mb:kmi1/serio1/input/input2
kjournald starting. Commit interval 5 seconds
EXT3-fs (mmcblk0): mounted filesystem with writeback data mode
VFS: Mounted root (ext3 filesystem) readonly on device 179:0.
Freeing unused kernel memory: 244K (805d6000 - 80613000)
random: nonblocking pool is initialized
mount: mounting proc on /proc failed: No such file or directory
Processing /etc/profile... Done
/ # /hello
hello linux world!!!/ #
可見程序已經運行起來了,並且輸出了文字.