嵌入式linux:通過qemu模擬mini2440開發環境


1 編譯安裝QEMU

首先下載qemu for mini2440,直接打包下載 

解壓后,進入源代碼目錄中:
sudo apt-get install zlib1g-dev
sudo apt-get install libsdl-dev

(prefix指定安裝路徑,這里是$HOME/work/mini2440)

./configure --target-list=arm-softmmu --prefix=$HOME/work/mini2440
make -j4
make install 

 安裝完后,添加環境變量:

sudo vim /etc/bash.bashrc

 添加一行:

export PATH=$PATH:$HOME/work/mini2440/bin 

保存退出后,用source 生效或者注銷重新登錄

source /etc/bash.bashrc

測試是否正常:

qemu-system-arm --version
 
2 使用buildroot一鍵生成uboot和linux內核及根文件系統

首先下載buildroot的源代碼,下載地址: 

解壓后,進入源代碼目錄中:
sudo apt-get install libncurses5-dev
patch configure <../configure.patch    /* 需要修改源碼 打補丁 */
make mini2440_defconfig
make menuconfig

安裝庫:

sudo apt-get install g++
sudo apt-get install bison
sudo apt-get install flex
sudo apt-get install gettext
sudo apt-get install patch
sudo apt-get install git-core
sudo apt-get install xz-utils
sudo apt-get install automake

安裝texinfo 4.13

tar -zxvf texinfo-4.13a.tar.gz
cd texinfo-4.13
./configure
make
sudo make install

修改bug(注釋下面文件中:_GL_WARN_ON_USE (gets,.......  這行代碼):

vim output/build/host-m4-1.4.16/lib/stdio.in.h
vim output/build/host-m4-1.4.16/lib/stdio.h
在安裝 時間比較長(可以先用我提供的安裝文件放到buildroot-2012.05/dl目錄下,這樣省去下載時間)

鏈接:https://pan.baidu.com/s/1PUxi_DejVo-bgChQH5bzmA 密碼:2dkz

3 Flashimg制作nand.bin並啟動系統
下載flashimg源碼 
http://gitorious.org/flashimg/flashimg.git 
解壓后,進入flashimg源碼目錄后
./autogen.sh (要求autoconf版本大於2.67)
./configure 
make 
sudo make install 

 然后把我們生成的三個文件 : u-boot.bin, uImage和rootfs.jffs2 拷貝到 flashimg文件夾下運行 

./flashimg -s 64M -t nand -f nand.bin -p uboot.part -w boot,u-boot.bin -w kernel,uImage -w root,rootfs.jffs2 -z 512 
即可生成nand.bin。啟動方法為:
qemu-system-arm -M mini2440 -serial stdio -mtdblock nand.bin -usbdevice mouse 

(若出現錯誤:浮點數例外啟動不了qemu,請全屏最大化終端,再次執行,這是由於分辨率問題造成)

輸入下面指令加載內核和根文件系統:
nboot kernel 
setenv bootargs root=/dev/mtdblock3 rootfstype=jffs2 console=ttySAC0,115200 
saveenv 
bootm 

 啟動后,輸入默認密碼root,即可成功登錄,此時還沒有配置網絡。ifconfig發現沒有網卡。

 4 NFS掛在根文件系統

 首先安裝nfs服務

sudo apt-get install nfs-kernel-server 
新建nfsroot文件夾
mkdir ~work/nfsroot 
然后配置nfs目錄 
sudo vi /etc/exports 
添加一行
/home/zwx/work/nfsroot *(rw,sync,no_root_squash,no_subtree_check
然后執行:
sudo /etc/init.d/nfs-kernel-server restart
進入NFS共享目錄:
cd /home/zwx/work/nfsroot/ 

 修改權限

sudo chmod -R 777 ./ 

解壓根文件系統

tar xvzf rootfs_qtopia_qt4-20140103.tar.gz

注意:友善之臂提供的qtopia文件系統在掛載時會初始化網卡,但我們是由nfs掛載的文件系統,這會導致nfs連接中斷,掛載失敗,所以用nfs掛載之前需要把網卡的初始化過程取消,對應的文件是/etc/init.d/if-config,只需把該文件內容刪除即可(刪除文件也可以)。

sudo chmod -R 777 ./ 
cd rootfs_qtopia_qt4
cd etc/init.d/
rm ifconfig-eth0

創建虛擬網卡並配置ip

sudo apt-get install uml-utilities //運行tunctl必須的工具
sudo tunctl -u $USER -t tap0
sudo ifconfig tap0 192.168.42.1

帶網絡方式啟動qemu

cd /home/zwx/work/qemu/flashimgflashimg-fb97139
qemu-system-arm -M mini2440 -serial stdio -mtdblock nand.bin -usbdevice mouse -kernel uImage -net nic,vlan=0 -net tap,vlan=0,ifname=tap0,script=no,downscript=no

啟動后進入uboot模式,此時的qemu還不能顯示,輸入下面指令加載內核和根文件系統。

set bootargs noinitrd root=/dev/nfs rw nfsroot=192.168.42.1:/home/zwx/work/nfsroot/rootfs_qtopia_qt4/,proto=tcp,nfsvers=3,nolock  ip=192.168.42.2:192.168.42.1::255.255.255.0 console=ttySAC0,115200
bootm

然后就可以啟動了

 5 安裝交叉編譯工具鏈:

arm-linux-gcc-4.4.3.tar.gz 

安裝庫:

sudo apt-get install lib32stdc++6
sudo apt-get install lib32z1

 

 好了 到此就可以愉快的進行開發了。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM