Teach you step by step how to install Ubuntu in QEMU virtual machines and simulate analog arm development environment (a) uImage u-boot [turn]

Transfer: https://blog.csdn.net/qq_24188351/article/details/77891353?ops_request_misc=%7B%22request%5Fid%22%3A%22158298496319725222401711%22%2C%22scm%22%3A%2220140713.130056874..%22 % 7D & request_id = 158298496319725222401711 & biz_id = 0 & utm_source = distribute.pc_search_result.none-task

Qemu initial contact is need for work, sometimes after work, you may need to research something at home, because bloggers use environment arm, this time blogger relatively stingy, reluctant to spend money on development board, of course bloggers here give you advice is, if you want to really learn to arm the framework of relevant knowledge, or buy a separate arm of the development board, slowly explore it, after all, this is the best way to learn, if you do not want to spend money then you can a follow-up operation bloggers, today's article, bloggers mainly talking about, in Ubuntu virtual machine environment, the use qemu to simulate the arm of the development environment, before the operation started, first about science:

1. What is QEMU: QEMU can be simply understood as a virtual operating system simulator, as the name suggests it is a virtual existence (more description please refer to Baidu Encyclopedia)

2. Why use QEMU simulate operating environments: (1) to save time for the siege lion who can learn at home, at any time, from the development board can be physical, (2) facilitate debugging, etc.

 

 

Hereby Disclaimer: This article is mainly white struggle for entering the workplace, if you are not for higher-end embedded environment more complex structures, please follow the step by step operation bloggers! ! !

 

Part I: installation, bloggers environment, the host Ubuntu virtual machine is wind64 bit, so we are here to download the Ubuntu mirror to mirror the desktop version of 64-bit

1.Ubuntu17.04 Download and versions:

http://releases.ubuntu.com/17.04/   

 

 

 

Download the host, do not need to unpack,

Please distinguish host your own version, of course, you can install 32-bit, but in order to ensure that no mistakes behind, and I recommend the same

The next step is to open the virtual machine installation step by step, and bloggers in here do not show, I installed the following screen,

 

After 2.Ubuntu installed, we do the following, sudo apt-get update update our software to ensure the installation of other software is the latest version back

 

3, the software update is completed, we install vim tool, for more convenient operation behind sudo apt-get vim

 

4, after vim installed, we are going to install an important tool of, vmware-tools, this tool is interactive between Ubuntu and our host,

 

After clicking, the system will automatically mount the virtual disk, which kept the tools we need vmware-tools installation directory and executable file, copy it to us at home, create a new folder on the inside

 

Decompress and take over is installed, all the way to enter the key and yes no input, waiting for installation

 

 

After installation, we can try to install correctly, we copy a file from the host to our Ubuntu see if it is possible to replicate the success, if you can not replicate, you can enter commands reboot reboot our VM

The problem is solved, of course, you can create a shared folder for the hosts and virtual machines difference (correlation method is not wordy here, Baidu own right), tried bloggers here, correct installation

 

So far our initial Ubuntu development environment to build a complete, just introduced here, not the initial configuration and development environment to build, own more slowly explore it

 

 

Part II: install QEMU, our protagonist finally debut

1. bloggers here chose to install their own network, and this is more convenient, manually install the dependent libraries first, I want to improve their bloggers can learn from someone else's post

Bloggers are also here to provide you the QEMU Download:

http://download.csdn.net/download/jinchengzhou/9464470  (qemu)

The following installation using qemu networking installed:

 

 

 

静等安装完毕吧,安装完毕,我们输如  qemu  敲击tab键,就可以匹配出如下的 可以模拟环境,本次我们模拟的就是

qemu-system-arm  的开发环境

 

 

 

下面来看看我们安装的版本,2.8版本已经很高了

 

 

 

 

第三部分:下载内核源码并编译

1.下载地址:http://www.kernel.org

我们下载一个比较稳定的版本 4.9.98

 

 

 

因为我们此次使用模拟arm  开发环境,所有我们需将内核编译成  arm  版本的内核

 

2.安装arm-linuc-gcc  交叉编译工具,可以到网上去下载,版本如下

 

 

 

我们将安装包拷贝到 /opt/ 在,进行解压工作,将最终得到的  4.4.3  目录在移动到 /opt/下,这样路径变的简短,方便我们解下来配置环境变量

2. shell窗口输入 sudo vi ~/.bashrc  在左后加入一行,保存退出,再输入  source ~/.bashrc  是我们的配置立即生效

 

 

 

3,我们在shll窗口输入 arm-none-   敲击tab 键,看能否匹配出如下:能配置出就说明我们的配置和安装都正确

4,您还可以自己编写一个最简单的程序,用 arm-none-linux-gnueabi-gcc  来编译看看,是不是 arm  版本的可执行文件,博主在这里不做演示

 

 

 

 

4.交叉工具安装好以后我们的内核源码也下在好了,我们将它拷贝到Ubuntu里面,放在你喜欢的目录下,进行解压 

tar -xvf  要解压的文件,解压完毕后我们进入  最 顶层的 Makefile  文件里面,做如下修改:

 

 

 

5.修改完毕后,保存退出

6.我们再查看   aech/arm/configs  目录里的各个厂商的内核配置文件,这个文件非常重要,并做如下操作:

 

 

 

7.至此我们就将我们需要的内核编译时需要的配置文件写入内核了

8,下面还需要对内核进行详细的配置,输入make  menuconfig ,这时,可能会出错,我们还需要安装 库文件

9,输入: sudo apt-get install   libncurses5-dev  就可以解决,我们在输入 make menuconfig 会进入如下画面:

10.我们将如图 标示  的部分 选上,让内核支持nfs功能。

 

 

 

11.因为我们需要用nfs 来挂载根文件系统,所有我们将 nfs  功能 编译进内核之中,使其支持nfs 功能

12.接下来我们就可以进行编译了,输入  make LOADADDR=0X60003000 uImage -j4 ,这里可能会报错,

找不到mkimage  ,起初博主也感动模糊,但经过 某某度  之后,原来是 因为我们需要 u-boot 来通过自动引导内核启动

的工具将内核在编译成uImage 的格式

13.出错解决: 这里单独参看我的博客,更详细的解决方式, 这里我们 输入  sudo  apt-get install u-boot-tools 进行安装,成功后关闭 shell窗口,再次打开, 就可以解决

14,再次进行编译内核,成功了,看到这里,博主心里送了一口气,终于可以喝口茶了

 

 

 

也许看到这里你已经迷糊了,但是作为一名coder,如果你想在你的不惑之年你还想成为一名大师级的coder,那么我可以告诉你,这些都是小儿科,

等着你的大山还很多呢,打起精神来,骚年!接下来才是本文章的重中之重,没有一下的操作做铺垫,前面和后面的我们做的再好在漂亮,都是白搭的

 

第四部分:配置我们的ubuntu 和 qemu 的网络环境,因为我们要通过网络来从主机下载内核并有u-boot引导启动,还要加载跟文件系统,所以如下的操作非常必要:

1.ubuntu安装 tftp 服务器,如图,输入  sudo apt-get install tftp-hpa tftpd-hpa  来自动安装 tftp服务器

 

 

 

2.安装完成后,我们需要做相应的配置 vi /etc/default/tftpd-hpa  做如下的更改

 

 

 

这里的路径可以根据自己的喜好来自己定义,博主在这里就定义在家目录下了,在哪里定义我们就要在哪里创建 tftpboot  目录

配置好后,保存退出,wq退出,

!!!注意:博主在这里在给大家一个建议,我在退出某个文件的时候,你确定好的文件可以 wq  或 w  ,x  ,对于你在查看别人的代码的时候,建议在退出的时候选择 q 退出,这样及时你不小心碰到 键盘对文件经行了无意间的修改也没关系,因为 q 是不保存退出,这是一个好习惯,对应一个上万行代码的文件来说你这样做是必要的

3.   cd /home     我们回到家目录下  ,输入  sudo mkdir tftpboot   创建 tftpboot 目录,加上最高权限  sudo chmod 777 tftpboot 

4保存退出后,我们需要重启tftp 服务器来让其生效 ,输入  sudo /etc/init.d/tftpd-hpa restart  ,显示如下表示重启成功

 

在此,我们还可以输入   ps -e | grep "tftp"   来查看 tftp  的进程号

5,我们将第三部分中编译内核生产的uImage  内核镜像拷贝到tftpboot目录下

 

 

 

6.tftp服务器安装好以后,我们还需要安装nfs  服务,输入  sudo apt-get install  nfs-kernel-server 

 

 

 

7.安装完成  我们在   /dev   目录需要创建nfs 设备的挂载点

mkdir  /dev/nfs 

 

 

 

8.做如下的配置 vi /etc/export  在文件的最后一行添加如下内容

/home/rootfs *(rw,sync,no_root_aquash,no_suntree_check)

前面的内容代表后面我们制作好的根文件的存放的路径

9,重启 nfs  服务,suod /etc/inint.d/nfs-kernel-server restart  

 

10,这一步也很关键,配置qemu和  ubuntu 网络桥接

先安装一个小工具:  sudo apt-get 

install uml-utilities bridge-utils
11 ,打开相应的文件进行配置网络   sudo  vi /etc/network/interfaces

做如下内容的添加,我们再为qemu添加一块网卡   br0

 

 

 

12,同样保存退出,这里我们需要重启ubuntu 来是我们配置的网络生效  输入   reboot   来重启ubuntu

13,ubuntu  重启之后  ,我们输入   ifconfig   指令来查看我们新添加的网络是否成功 ,如果看到  br0  存在且和  ip 地址,说明配置成功

这里博主在制作的过程中忘记保存图片啦,就不贴出来了

 

做到这里我们可以暂时歇一歇,因为我们后面还有很多的事请要做,u-boot  的编译  和  根文件的制作都非常重要!

 

 

第五部分:我们需要为我们的内核启动来编译生成u-boot,u-boot的下载地址和下载的版本

ftp://ftp.denx.de/pub/u-boot/

 

 

 

1.我们将下载来大u--boot文件进行解压  tar -xvf u-boot-2017.07.tar.bz2   得到  u-boot-2017.07  文件夹

2.  cd u-boot-2017.07  进入文件夹,在执行 cd configs  ,在这里我可以看到很多厂商开发板的配置文件

我们选择   vexpress-ca9x4_defconfig  这个配置文件,并做如下的操作

 

 

 

3.这样我们就生成了 .config文件了,接着 我们在 顶层目录下  vi Makefile  打开文件做如下的更改:

  249 行添加     CROSS_COMPILE ?=arm-none-kinux-gnueabi-   这样的内容,完毕  保存退出

4,还是在定层目录  执行   vi  config.mk  打来文件   条件如下的内容:更改25行的内容

 

 

 

5. 接这再输入  vi include/configs/vexpress_comm.h打开文件,别问为什么  跟着操作,加入一下的内容:

 

 

 

6.添加完以上内容,保存退出,这样我们就配置好, 接下来就是见证奇迹的时刻了

7,输入   make -j4   开启4个线程来进行编译

8,得到我们的劳动成果了

 

 

 

9.  cp  u-boot  /tftpboot   目录下,我将从这里启动u-boot并加装内核zai

 

总结我们得到的成果:   内核镜像  uImage   u-boot  ,接下来我们还需要制作 根文件系统!!!!

 

好了,经过以上n多步的操作,我们离目标又更近一步了,但是我们还有工作没做完了,晚已深,人已困,今晚就到这。

后面博主会抽出时间来把  rootfs  的制作方法也展示给大家,让大家尽快把 qemu模拟arm  环境制作出来,给自己增加信心,在IT 的路上越来越好!!!

 

声明::由于博主学识浅薄,文章中的有些地方难免会有纰漏,大家采纳的过程中,希望万分体谅,并给出意见,博主会虚心接受!!

 

未完待续....................................................................................

敬请期待下一节   rootfs  的制作过程!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


————————————————
版权声明:本文为CSDN博主「风清扬的博客」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_24188351/article/details/77891353

Guess you like

Origin www.cnblogs.com/sky-heaven/p/12390559.html