惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Hacker News
The Hacker News
博客园_首页
人人都是产品经理
人人都是产品经理
博客园 - 聂微东
J
Java Code Geeks
Stack Overflow Blog
Stack Overflow Blog
Blog — PlanetScale
Blog — PlanetScale
博客园 - 三生石上(FineUI控件)
A
About on SuperTechFans
V
Visual Studio Blog
小众软件
小众软件
MyScale Blog
MyScale Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
F
Full Disclosure
酷 壳 – CoolShell
酷 壳 – CoolShell
T
The Exploit Database - CXSecurity.com
C
CERT Recently Published Vulnerability Notes
T
Threat Research - Cisco Blogs
AWS News Blog
AWS News Blog
T
Tor Project blog
Jina AI
Jina AI
GbyAI
GbyAI
C
Comments on: Blog
IT之家
IT之家
Apple Machine Learning Research
Apple Machine Learning Research
A
Arctic Wolf
有赞技术团队
有赞技术团队
SecWiki News
SecWiki News
L
Lohrmann on Cybersecurity
Security Latest
Security Latest
Webroot Blog
Webroot Blog
C
Cisco Blogs
雷峰网
雷峰网
云风的 BLOG
云风的 BLOG
博客园 - 叶小钗
K
Kaspersky official blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
宝玉的分享
宝玉的分享
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
O
OpenAI News
H
Hacker News: Front Page
D
Darknet – Hacking Tools, Hacker News & Cyber Security
D
Docker
P
Palo Alto Networks Blog
The Register - Security
The Register - Security
B
Blog RSS Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
WordPress大学
WordPress大学
阮一峰的网络日志
阮一峰的网络日志

博客园 - Wu.Country@侠缘

用户中心 - 博客园 [Linux]OpenSuse12图形和文字界面转换 haneWIN NFS Server An Introduction to the Linux-based Assignments Booting Linux with U-Boot on QEMU ARM Using The mkimage Tool To Create U-Boot Images SUSE安全大揭秘之“十诫” CT-NG编译错误以及解决办法 无法忍受在SUSE10上安装开发环境了 Windows的路由命令 【CLFS】记录: Linux内核代码学习笔记(2.6.21.7 ARM) -- 内核启动函数start_kernel [读书笔记]Binary Hancks(2) livepatch在X86下的实践 [读书笔记]Binary Hancks(1) ARM Stack Unwinding Physical Address Extension - PAE Memory and Windows 如何制作grub启动光盘 [译]Kernel Memory Layout on ARM Linux [转]ucLinux下sqlite数据库移植全攻略
[Copy]如何使用qemu执行交叉环境下的内核镜像文件
Wu.Country@侠缘 · 2012-05-01 · via 博客园 - Wu.Country@侠缘

http://balau82.wordpress.com/2010/03/22/compiling-linux-kernel-for-qemu-arm-emulator/ 


[EDIT] I have written a new updated version of this post here.

Last time I experimented on compiling bare-metal ARM programs and U-Boot; now I want to compile a Linux kernel for an ARM architecture from scratch. I don’t have a physical ARM device handy, so I’m using QEMU instead, as I’ve already done before.

Both the mainline kernel and QEMU support the VersatilePB platform, so that’s the target I chose for my tests. The toolchain I’ll be using is the CodeSourcery ARM EABI toolchain. [edit] From version 2010q1 of the toolchain, the manual explicitly says that the compiler is not intended for Linux kernel development; it is anyway possible to use the GNU/Linux toolchain for the same scope. [/edit]

The vanilla kernel can be downloaded from kernel.org; I took the latest at the moment (version 2.6.33) and extracted it in a folder. From that folder I ran:

1make ARCH=arm versatile_defconfig

This command sets a predefined configuration, used in compilation, that is capable of building a kernel targeted to run inside the VersatilePB board. I wanted to tweak it a little bit, so I ran:

1make ARCH=arm menuconfig

I removed module support (for simplicity) and enabled EABI support as a binary format (allowing also old ABI). This is necessary to run software compiled with the CodeSourcery toolchain. I exited the menu and saved the configuration, then I ran:

1make ARCH=arm CROSS_COMPILE=arm-none-eabi- all

[edit] If using the GNU/Linux toolchain, the command that must be used is, instead:

1make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- all

[/edit]

This will start the building of the kernel using the correct ARM compiler; the build will create, among other binaries, a compressed kernel in a file called zImage located in “arch/arm/boot“. This image can be run in QEMU using the following command (assuming that you are in the “arch/arm/boot” directory):

1qemu-system-arm -M versatilepb -m 128M -kernel zImage

QEMU will execute the Linux image: the kernel will display many boot messages and then it will complain that it didn’t find a root filesystem. Let’s then create the simplest filesystem we can do: it consists of a single “Hello World” executable, that can be built using the CodeSourcery GNU/Linux toolchain.

4  printf("Hello World!\n");

Note: an infinite loop is introduced because when Linux executes the first program in the root filesystem, it expects that the program does not exit.

Having the GNU/Linux ARM toolchain installed (be aware that it is different from the bare EABI toolchain) I ran:

1arm-none-linux-gnueabi-gcc -static    test.c   -o test

This creates an executable ELF program for ARM, statically linked (all the libraries that it needs are linked together in a single binary). We can now create a simple filesystem using the cpio tool as follows:

1echo test | cpio -o --format=newc > rootfs

The cpio tool takes a list of files and outputs an archive; the newc format is the format of theinitramfs filesystem, that the Linux kernel recognizes. The rootfs file in our case is a binary image of a filesystem containing a single file, that is the test ELF program. QEMU can pass the filesystem binary image to the kernel using the initrd parameter; the kernel must also know that the root filesystem will be located in RAM (because that’s where QEMU writes the initrd binary) and that the program to launch is our test executable, so the command line becomes:

1qemu-system-arm -M versatilepb -m 128M -kernel zImage -initrd rootfs -append "root=/dev/ram rdinit=/test"

The QEMU window will show the boot messages we saw before, but at the end of the execution a “Hello World!” will be displayed. The next step would be to create a working filesystem with a command shell and at least basic functionality. 

================================
  /\_/\                        
 (=^o^=)  Wu.Country@侠缘      
 (~)@(~)  一辈子,用心做一件事!
--------------------------------
  学而不思则罔,思而不学则怠!  
================================