Using QEMU for Embedded Systems Development, Part 3
来源:互联网 发布:中国农大网络远程教育 编辑:程序博客网 时间:2024/05/19 05:40
http://www.linuxforu.com/2011/08/qemu-for-embedded-systems-development-part-3/
Using QEMU for Embedded Systems Development, Part 3
By Manoj Kumar on August 1, 2011 in Coding, Developers · 4 Comments
It's time to u-boot
This is the last article of this series on QEMU. In the previous article, we worked on bare-metal programming, and discussed the need for a bootloader. Most GNU/Linux distros use GRUB as their boot-loader (earlier, LILO was the choice). In this article, we will test the famous U-Boot (Universal BootLoader).
In embedded systems, especially in mobile devices, ARM processor-based devices are leading the market. For ARM, U-Boot is the best choice for a bootloader. The good thing about it is that we can use it for different architectures like PPC, MIPS, x86, etc. So let’s get started.
Download and compile U-Boot
U-Boot is released under a GPL licence. Download it from this FTP server, which has every version of U-Boot available. For this article, I got version 1.2.0 (u-boot-1.2.0.tar.bz2). Extract the downloaded tar ball and enter the source code directory:
# tar -jxvf u-boot-1.2.0.tar.bz2
# cd u-boot-1.2.0
To begin, we must configure U-Boot for a particular board. We will use the same ARM Versatile Platform Baseboard (versatilepb) we used in the previous article, so let’s run:
# make versatilepb_config arch=ARM CROSS_COMPILE=arm-none-eabi-
Configuring for versatile board...
Variant:: PB926EJ-S
After configuration is done, compile the source code:
# make all arch=ARM CROSS_COMPILE=arm-none-eabi-
for dir in tools examples post post/cpu ; do make -C $dir _depend ; done
make[1]: Entering directory `/root/qemu/u-boot-1.2.0/tools'
ln -s ../common/environment.c environment.c
.
.
G++_Lite/bin/../lib/gcc/arm-none-eabi/4.4.1 -lgcc \
-Map u-boot.map -o u-boot
arm-none-eabi-objcopy --gap-fill=0xff -O srec u-boot u-boot.srec
arm-none-eabi-objcopy --gap-fill=0xff -O binary u-boot u-boot.bin
Find the size of the compiled U-Boot binary file (around 72 KB in my experience) with ls -lh u-boot* — we will use it later in this article. I assume that you have set up QEMU, networking and the ARM tool chain, as explained in previous articles in this series (1, 2, 3). If not, then I suggest you read the last three articles.
Boot U-Boot in QEMU
Now we can boot the U-Boot binary in QEMU, which is simple. Instead of specifying the Linux kernel as the file to boot in QEMU, use the U-Boot binary:
# qemu-system-arm -M versatilepb -nographic -kernel u-boot.bin
Run some commands in U-Boot, to check if it is working:
Versatile # printenv
bootargs=root=/dev/nfs mem=128M ip=dhcp netdev=25,0,0xf1010000,0xf1010010,eth0
bootdelay=2
baudrate=38400
bootfile="/tftpboot/uImage"
stdin=serial
stdout=serial
stderr=serial
verify=n
Environment size: 184/65532 bytes
U-Boot
Figure 1: U-Boot
The next step is to boot a small program from U-Boot. In the previous article, we wrote a small bare-metal program — so let us use that.
We will create a flash binary image that includes u-boot.bin and the bare-metal program in it. The test program from the last article will be used here again with some modification. As the u-boot.bin size is around 72 KB, we will move our sample program upward in memory. In the linker script, change the starting address of the program:
ENTRY(_Start)
SECTIONS
{
. = 0x100000;
startup : { startup.o(.text)}
.data : {*(.data)}
.bss : {*(.bss)}
. = . + 0x500;
sp_top = .;
}
Compile the test program as shown below:
# arm-none-eabi-gcc -c -mcpu=arm926ej-s init.c -o init.o
# arm-none-eabi-as -mcpu=arm926ej-s startup.s -o startup.o
# arm-none-eabi-ld -T linker.ld init.o startup.o -o test.elf
# arm-none-eabi-objcopy -O binary test.elf test.bin
Now, our test program’s binary file and the u-boot.bin must be packed in a single file. Let’s use the mkimage tool for this; locate it in the U-Boot source-code directory.
# mkimage -A arm -C none -O linux -T kernel -d test.bin -a 0x00100000 -e 0x00100000 test.uimg
Image Name:
Created: Wed Jul 6 13:29:54 2011
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 148 Bytes = 0.14 kB = 0.00 MB
Load Address: 0x00100000
Entry Point: 0x00100000
Our sample binary file is ready. Let’s combine it with u-boot.bin to create the final flash image file:
#cat u-boot.bin test.uimg > flash.bin
Calculate the starting address of the test program in the flash.bin file:
# printf "0x%X" $(expr $(stat -c%s u-boot.bin) + 65536)
0x21C68
Boot the flash image in QEMU:
# qemu-system-arm -M versatilepb -nographic -kernel flash.bin
Now verify the image address in U-Boot:
Versatile # iminfo 0x21C68
## Checking Image at 00021c68 ...
Image Name:
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 136 Bytes = 0.1 kB
Load Address: 00100000
Entry Point: 00100000
Verifying Checksum ... OK
The image is present at the address 0x21C68. Boot it by executing the bootm command:
Versatile # bootm 0x21C68
## Booting image at 00021c68 ...
Image Name:
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 148 Bytes = 0.1 kB
Load Address: 00100000
Entry Point: 00100000
OK
Starting kernel ...
Hello Open World
That’s all folks!
Acknowledgement
This article is inspired by the following blog post: “U-boot for ARM on QEMU“.
Using QEMU for Embedded Systems Development, Part 3
By Manoj Kumar on August 1, 2011 in Coding, Developers · 4 Comments
It's time to u-boot
This is the last article of this series on QEMU. In the previous article, we worked on bare-metal programming, and discussed the need for a bootloader. Most GNU/Linux distros use GRUB as their boot-loader (earlier, LILO was the choice). In this article, we will test the famous U-Boot (Universal BootLoader).
In embedded systems, especially in mobile devices, ARM processor-based devices are leading the market. For ARM, U-Boot is the best choice for a bootloader. The good thing about it is that we can use it for different architectures like PPC, MIPS, x86, etc. So let’s get started.
Download and compile U-Boot
U-Boot is released under a GPL licence. Download it from this FTP server, which has every version of U-Boot available. For this article, I got version 1.2.0 (u-boot-1.2.0.tar.bz2). Extract the downloaded tar ball and enter the source code directory:
# tar -jxvf u-boot-1.2.0.tar.bz2
# cd u-boot-1.2.0
To begin, we must configure U-Boot for a particular board. We will use the same ARM Versatile Platform Baseboard (versatilepb) we used in the previous article, so let’s run:
# make versatilepb_config arch=ARM CROSS_COMPILE=arm-none-eabi-
Configuring for versatile board...
Variant:: PB926EJ-S
After configuration is done, compile the source code:
# make all arch=ARM CROSS_COMPILE=arm-none-eabi-
for dir in tools examples post post/cpu ; do make -C $dir _depend ; done
make[1]: Entering directory `/root/qemu/u-boot-1.2.0/tools'
ln -s ../common/environment.c environment.c
.
.
G++_Lite/bin/../lib/gcc/arm-none-eabi/4.4.1 -lgcc \
-Map u-boot.map -o u-boot
arm-none-eabi-objcopy --gap-fill=0xff -O srec u-boot u-boot.srec
arm-none-eabi-objcopy --gap-fill=0xff -O binary u-boot u-boot.bin
Find the size of the compiled U-Boot binary file (around 72 KB in my experience) with ls -lh u-boot* — we will use it later in this article. I assume that you have set up QEMU, networking and the ARM tool chain, as explained in previous articles in this series (1, 2, 3). If not, then I suggest you read the last three articles.
Boot U-Boot in QEMU
Now we can boot the U-Boot binary in QEMU, which is simple. Instead of specifying the Linux kernel as the file to boot in QEMU, use the U-Boot binary:
# qemu-system-arm -M versatilepb -nographic -kernel u-boot.bin
Run some commands in U-Boot, to check if it is working:
Versatile # printenv
bootargs=root=/dev/nfs mem=128M ip=dhcp netdev=25,0,0xf1010000,0xf1010010,eth0
bootdelay=2
baudrate=38400
bootfile="/tftpboot/uImage"
stdin=serial
stdout=serial
stderr=serial
verify=n
Environment size: 184/65532 bytes
U-Boot
Figure 1: U-Boot
The next step is to boot a small program from U-Boot. In the previous article, we wrote a small bare-metal program — so let us use that.
We will create a flash binary image that includes u-boot.bin and the bare-metal program in it. The test program from the last article will be used here again with some modification. As the u-boot.bin size is around 72 KB, we will move our sample program upward in memory. In the linker script, change the starting address of the program:
ENTRY(_Start)
SECTIONS
{
. = 0x100000;
startup : { startup.o(.text)}
.data : {*(.data)}
.bss : {*(.bss)}
. = . + 0x500;
sp_top = .;
}
Compile the test program as shown below:
# arm-none-eabi-gcc -c -mcpu=arm926ej-s init.c -o init.o
# arm-none-eabi-as -mcpu=arm926ej-s startup.s -o startup.o
# arm-none-eabi-ld -T linker.ld init.o startup.o -o test.elf
# arm-none-eabi-objcopy -O binary test.elf test.bin
Now, our test program’s binary file and the u-boot.bin must be packed in a single file. Let’s use the mkimage tool for this; locate it in the U-Boot source-code directory.
# mkimage -A arm -C none -O linux -T kernel -d test.bin -a 0x00100000 -e 0x00100000 test.uimg
Image Name:
Created: Wed Jul 6 13:29:54 2011
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 148 Bytes = 0.14 kB = 0.00 MB
Load Address: 0x00100000
Entry Point: 0x00100000
Our sample binary file is ready. Let’s combine it with u-boot.bin to create the final flash image file:
#cat u-boot.bin test.uimg > flash.bin
Calculate the starting address of the test program in the flash.bin file:
# printf "0x%X" $(expr $(stat -c%s u-boot.bin) + 65536)
0x21C68
Boot the flash image in QEMU:
# qemu-system-arm -M versatilepb -nographic -kernel flash.bin
Now verify the image address in U-Boot:
Versatile # iminfo 0x21C68
## Checking Image at 00021c68 ...
Image Name:
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 136 Bytes = 0.1 kB
Load Address: 00100000
Entry Point: 00100000
Verifying Checksum ... OK
The image is present at the address 0x21C68. Boot it by executing the bootm command:
Versatile # bootm 0x21C68
## Booting image at 00021c68 ...
Image Name:
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 148 Bytes = 0.1 kB
Load Address: 00100000
Entry Point: 00100000
OK
Starting kernel ...
Hello Open World
That’s all folks!
Acknowledgement
This article is inspired by the following blog post: “U-boot for ARM on QEMU“.
0
上一篇:Using QEMU for Embedded Systems Development, Part 2
下一篇:I need to learn ARM assembly, and I use Linux.
相关热门文章
- SHTML是什么_SSI有什么用...
- shell中字符串操作
- 卡尔曼滤波的原理说明...
- 关于java中的“错误:找不到或...
- shell中的特殊字符
- linux dhcp peizhi roc
- 关于Unix文件的软链接
- 求教这个命令什么意思,我是新...
- sed -e "/grep/d" 是什么意思...
- 谁能够帮我解决LINUX 2.6 10...
给主人留下些什么吧!~~
评论热议
0 0
- Using QEMU for Embedded Systems Development, Part 3
- Using QEMU for Embedded Systems Development, Part 3
- Using QEMU for Embedded Systems Development, Part 1
- Using QEMU for Embedded Systems Development, Part 2
- Using QEMU for Embedded Systems Development, Part 1
- Using QEMU for Embedded Systems Development, Part 2
- Software Development for Embedded Multi-core Systems: A Practical Guide Using Embedded Intel® Ar
- Embedded Systems Architecture for Agile Development.pdf 英文原版 免费下载
- GNU Tools for Embedded Systems
- Embedded Linux: Using Compressed File Systems
- Using ODB on Mobile and Embedded Systems
- Programming Embedded Systems: With C and Gnu Development Tools
- Real-Time Concepts for Embedded Systems----读书笔记
- Real-Time Concepts for Embedded Systems
- Writing Efficient C Code for Embedded Systems
- Design Patterns for Embedded Systems in C
- Projects:GTK on DirectFB for Embedded Systems
- Workshop For Embedded Linux Development on PowerPC
- Activity 的 LaunchMode
- ARM汇编调试
- Using QEMU for Embedded Systems Development, Part 1
- Using QEMU for Embedded Systems Development, Part 2
- C#委托的介绍(delegate、Action、Func、predicate)
- Using QEMU for Embedded Systems Development, Part 3
- I need to learn ARM assembly, and I use Linux.
- 290. Word Pattern
- easy ui 隐藏textbox
- ‘Hello World!’ in ARM assembly
- 虚拟机中PXE-MOF:Exiting intel PXE ROM.Operating system not found
- hibernate 4.3.X遇到的一些问题收集
- [leetcode] 339. Nested List Weight Sum 解题报告
- An exploration of ARM assembly language
原创粉丝点击
热门IT博客
热门问题
老师的惩罚
人脸识别
我在镇武司摸鱼那些年
重生之率土为王
我在大康的咸鱼生活
盘龙之生命进化
天生仙种
凡人之先天五行
春回大明朝
姑娘不必设防,我是瞎子
银信科技股票
300231银信科技
300231
银圆
银圆价格及图片
元大头报价图片
银圆价格
银园价格
银圆图片
yinyuan
大洋图片及价格表
银园
銀元
洋钱图片及价格
银光
银兽学园
银兽学园1
银兽学院
银兽学院在线全集播放
兽世之情定风银 木棉花海
银兽学园 1
银兽学园 2
银之冠碧之泪
银之冠碧之泪攻略
银牙冠
银冠
医统天下银瓶
医统天下 银瓶
银医 臧福生
金九银十什么意思
十月蛇胎 银花火树
郑州银基童装批发五元至十元
金九银十数据
金九银十买房划算吗
麒零x银尘生子文十世
金九银十买车真的便宜
银华88
银华
银华优选
银华领先
银华优势