ZYNQ启动流程分析及各环节文件生成流程

来源:互联网 发布:数据共享原理 编辑:程序博客网 时间:2024/05/12 15:45

1. ZYNQ的启动流程

Zynq7000就如同他的名字一样,Zynq-7000 Extensible Processing Platform,是一个可扩展处理平台,简单说就是有个FPGA做外设的A9双核处理器。

所以,它的启动流程自然也和FPGA完全不同,而与传统的ARM处理器类似。

Zynq7000支持从多种设备启动,包括JTAGNANDparallel NORSerial NOR (Quad-SPI),以及SD卡。按手册说明除了JTAG之外的启动方式均支持安全启动,使用AESSHA256加密后的启动代码,(不过在勘误里说到,当前硅片版本的无法正常使用secure configuration功能,所以俺就不介绍它鸟)。 

还是按照时间顺序来介绍下具体流程吧

1.在器件上电运行后,处理器自动开始Stage-0 Boot,也就是执行片内BootROM中的代码

2.BootROM会初始化CPU和一些外设,以便读取下一个启动阶段所需的程序代码,FSBLFirst Stage Bootloader)。

不过这又有一个问题了----之前说到,Zynq支持多种启动设备,BootROM怎么知道从哪个启动设备里去加载FSBL?这就得靠几个特殊的MIO引脚来选择了,具体见下图:

BootROM会去读取MIO[2..8],从而确定启动设备,将选定设备的头192Kbyte内容,也就是FSBL,复制到OCM(On Chip Memory)中,并将控制器交给FSBL

3FSBL启动时可以使用整块256KbOCM,当FSBL开始运行后,器件就正式由咱自己控制了。Xilinx提供了一份FSBL代码,如果没什么特殊要求,可以直接使用。

按照手册说明,FSBL应该完成以下几件事。

1). 使用XPS提供的代码,继续初始化PS

2). bitstream写入PL(配置FPGA),不过这一步也可以以后再做

3). 将接下来启动用的Second Stage BootloaderSSBL,一般就是U-Boot一类的东西),或者裸奔程序,复制到内存中

4). 跳到SSBL运行去

4,接下来的步骤就没啥特别了,Uboot开始运行,初始化好Linux启动环境,然后开始运行Linux系统。 

2. 启动时SD卡文件内容

1. zImageBOOT.BINdevicetree_ramdisk.dtbramdisk8M.image.gz

2. zynq芯片上电初始化,进入u-boot,会自动加载devicetreezImagerootfs,然后启动Linux

3. BOOTDevicetreezImage,放到SD卡的第一个分区里(分区方式在http://wiki.analog.com/resources/tools-software/linux-drivers/platforms/zynq,第一个区BOOT 50MB fat32格式,第二个区rootfs ext4格式)。

Linarorootfs在这里下载:

http://releases.linaro.org/12.06/ubuntu/precise-images/ubuntu-desktop/linaro-precise-ubuntu-desktop-20120626-247.tar.gz

下载后,通过下面的命令解压到SD卡的第二个分区里即可:

sudo tar --strip-components=3 -C /media/rootfs -xzpf linaro-precise-ubuntu-desktop-20120626-247.tar.gz binary/boot/filesystem.dir

3. SD卡文件内容一(zImage)

详细步骤:以下操作均在root用户下进行,官方参考网址的东西仅是参考

1,下载交叉编译器

ubuntu里下载arm-2010.09-62-arm-xilinxa9-linux-gnueabi.bin安装文件,在网站https://code.google.com/p/zedboard-book-source/downloads/list上的download里下载,放到/tools/ 

2,同步xilinxlinux kernel

mkdir /kernel

cd  /kernel

git clone git://git.xilinx.com/(project name)

(project name) has 3: 

linux-xlnx.gitLinux sources

u-boot-xlnx.gitU-boot sources

qemu-xarm.gitZynq-7000 AP SoC QEMU system model

然后就等着吧,总共1.3G的代码,下载完毕后,

cd /kernel/

ls

有个新的文件夹linux-xlnx,这个就是zynqlinux kernel代码了。。

如果你的网络不支持git,可以用http代理服务,先建立一个 git-proxy.sh文件,在里面写上:

#!/bin/sh

exec corkscrew $*

然后export一下,

bash> export GIT_PROXY_COMMAND="//git-proxy.sh"

上面http://wiki.xilinx.com/using-git 上的方法,我的实际情况比较特殊,网络服务器还要用户名和密码,怎么办呢,稍微麻烦一点:

git-proxy.sh中的内容修改成这样滴:

#!/bin/sh

exec corkscrew 172.16.0.252 8080 $* /disk2data/authfile

然后再在git-proxy.sh同目录下建立一个authfile文件,内容为

用户名:密码

最后export GIT_PROXY_COMMAND="//git-proxy.sh"

至此我的电脑也可以无忧无虑的git 

3,安装交叉编译器

cd  //tools/

chmod 755 arm-2010.09-62-arm-xilinxa9-linux-gnueabi.bin   

./ arm-2010.09-62-arm-xilinxa9-linux-gnueabi.bin  

然后出现了安装界面,选择安装的文件夹等等,可以自己设,嫌麻烦就一路回车或者“yes”就行了。不过要记住安装的目录,这个一会儿编译的时候要用到…. 

4,设置交叉编译环境

官网http://wiki.xilinx.com/zynq-tools 上说下载ia32-libs的库,

apt-get install ia32-libs

但是我的电脑因为之前配置过android的编译环境,已经安装了,直接修改设置/etc/bash.bashrc文件就可以了:

在命令行上输入gedit /etc/bash.bashrc,添加以下内容:

export ARCH=arm

export CROSS_COMPILE=arm-xilinx-linux-gnueabi-

export PATH=/home/(…)/Sourcery_CodeBench_Lite_for_Xilinx_GNU_Linux/bin:$PATH

5,编译zynq的内核

由于zedboard内核还没有被加入到zynq的内核中,我们就先用zc702/770的板卡配置来测试一下环境吧:

cd  //kernel/linux-2.6-xlnx

make ARCH=arm xilinx_zynq_defconfig   -- 配置内核

make ARCH=arm                      -- 编译 

大概需要几分钟吧,编译就完成了,查看

cd /myPath/kernel/linux-xlnx/arch/arm/boot

里面的zImage就是刚刚生成的内核

============ 如果git没安装且用apt-get install git时找不到服务器 ===============

修改 /etc/apt/source.list 来增加源的服务器来获得软件的列表

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ natty main restricted universe multiverse

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ natty-security main restricted universe multiverse

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ natty-updates main restricted universe multiverse

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ natty-backports main restricted universe multiverse

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ natty-proposed main restricted universe multiverse

deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ natty main restricted universe multiverse

deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ natty-security main restricted universe multiverse

deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ natty-updates main restricted universe multiverse

deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ natty-backports main restricted universe multiverse

deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ natty-proposed main restricted universe multiverse

deb http://mirror.bjtu.edu.cn/ubuntu/ karmic main multiverse restricted universe

deb http://mirror.bjtu.edu.cn/ubuntu/ karmic-backports main multiverse restricted universe

deb http://mirror.bjtu.edu.cn/ubuntu/ karmic-proposed main multiverse restricted universe

deb http://mirror.bjtu.edu.cn/ubuntu/ karmic-security main multiverse restricted universe

deb http://mirror.bjtu.edu.cn/ubuntu/ karmic-updates main multiverse restricted universe

deb-src http://mirror.bjtu.edu.cn/ubuntu/ karmic main multiverse restricted universe

deb-src http://mirror.bjtu.edu.cn/ubuntu/ karmic-backports main multiverse restricted universe

deb-src http://mirror.bjtu.edu.cn/ubuntu/ karmic-proposed main multiverse restricted universe

deb-src http://mirror.bjtu.edu.cn/ubuntu/ karmic-security main multiverse restricted universe

deb-src http://mirror.bjtu.edu.cn/ubuntu/ karmic-updates main multiverse restricted universe

在修改完源列表后, 切记要 sudo apt-get update一下, 否则修改后的源是不生效的。

4. SD卡文件内容二(BOOT.bin)

SDK会生成FSBLelf文件,另外加上从XPS导出的System.bit,以及我们在第一篇文章中编译生成的u-boot.elf,就可以生成用来实现SD卡启动系统的完整Bootloader

集齐u-boot.elfsystem.bitfsbl.elf就可以生成Image文件了,在SDK软件中点击Xilinx Tools→CreateBoot Image,如图6所示,然后选择3个文件,点击Create Image,生成文件如图8所示,其中u-boot.bin文件就是需要的u-boot image文件,将其重命名为BOOT.BIN后拷贝到SD卡中。

6


7

8

4.1.  Elf文件(FSBL)

fsbl.elf文件需要在SDK软件中生成,首先新建工程,选择Xilinx C Project,然后选择Zynq FSBL,编译工程即可生成zynq_fsbl_0.elf文件,过程如图345所示。

3


4

5

4.2.  System.bit文件

system.bitPL部分的BIT文件,首先在ISE软件中新建工程,加入zynq系统,在EDK中配置ARM核及其外设,返回ISE生成TOP HDL Source,点击generate Programming File即可生成Bit文件,如下图所示,然后点击Export Hardware Design To SDK with Bitstream进入下一步。

4.3.  U-boot.elf文件(SSBL)

1.首先Git下载Xilinx U-Boot代码       

git clone git://git.xilinx.com/u-boot-xlnx.git


2.配置u-boot,在上一篇博客中介绍了交叉编译环境的建立,此处可直接进行配置       

cd u-boot-xlnx

make zynq_zed_config 

3. 编译u-boot

Make

以上步骤完成之后会生成一个u-boot文件,将其另存为u-boot.elf文件,此文件在生成Bootimage文件时会使用到。

5. SD卡文件内容三(Device Tree Blob)

5.1.  Xilinx官网方法

This how-to describes the process of compiling a device tree blob.
Build Device Tree Blob is a part of the Xilinx design flow described in Getting Started.

Task Dependencies (Pre-requisites)

· Fetch Sources(Device Tree Generator sources and Linux sources)

· Hardware Project

Input Files Required

· Hardware Project directory

· Linux source directory

Output Files Produced

· *.dts, *.dtb

Task Description

Creating a Device Tree Source (.dts) file

Open the hardware project in XPS.

Export the hardware system to SDK:
XPS Menu: Project > Export Hardware Design to SDK... > Export & Launch SDK

The Device Tree Generator Git repository needs to be downloaded as specified on the Fetch Sources page. In order for SDK to be able to import the Device Tree Generator correctly, the downloaded Git repository device-tree/ will need to be placed under <bsp repo>/bsp/ (create this directory hierarchy, if needed). The file hierarchy needs to look like:
<bsp repo>/bsp/device-tree/data/device-tree_v2_1_0.mld
<bsp repo>/bsp/device-tree/data/device-tree_v2_1_0.tcl

Add the BSP repository in SDK:
SDK Menu: Xilinx Tools > Repositories > New... (<bsp repo>) > OK

Create a Device Tree Board Support Package (BSP):
SDK Menu: File > New > Board Support Package > Board Support Package OS: device-tree > Finish

A BSP settings window will appear. This window can also be accessed by opening the Device Tree BSP's system.mss file and clicking 'Modify this BSP's Settings'. Fill in the values as appropriate: 

The 'bootargs' parameter specifies the arguments passed to the kernel at boot time (kernel command line). ***

The 'console device' parameter specifies which serial output device will be used. Select a value from the drop-down.


The .dts file is now located in <SDK workspace>/<device-tree bsp name>/<processor name>/libsrc/device-tree_v*/xilinx.dts.

*** e.g. console=<tty>,<baudrate> root=/dev/ram rw ip=:::::eth0:dhcp earlyprintk
*** Some example values for <tty> are ttyPS0 when using Zynq, ttyUL0 when using the UART Lite soft ip, or ttyS0 when using the UART16550 soft ip.

In the Linux source directory, there are also some DTS files available for use in linux-xlnx/arch/<architecture>/boot/dts/.

Compiling a Device Tree Blob (.dtb) file from the DTS

A utility called DTC is used to compile the DTS file into a DTB file. DTC is part of the Linux source directory. linux-xlnx/scripts/dtc/ contains the source code for DTC and needs to be compiled in order to be used. One way to compile the DTC is to build the Linux tree.

Once the DTC is available, the tool may be invoked to generate the DTB:

./scripts/dtc/dtc -I dts -O dtb -o <devicetree name>.dtb <devicetree name>.dts

DTC may also be used to convert a DTB back into a DTS:

./scripts/dtc/dtc -I dtb -O dts -o <devicetree name>.dts <devicetree name>.dtb

Alternative: For ARM only
In the Linux source directory, making the target 'dtbs' will compile all DTS files from linux-xlnx/arch/arm/boot/dts/ into DTB files.

make ARCH=arm dtbs

The compiled DTB files will be located in linux-xlnx/arch/arm/boot/dts/.
A single linux-xlnx/arch/arm/boot/dts/<devicetree name>.dts may be compiled into linux-xlnx/arch/arm/boot/dts/<devicetree name>.dtb:

make ARCH=arm <devicetree name>.dtb

5.2. 懒兔子博客方法

在上一篇博文中,我已经介绍了建立AXI总线自定义外设的全过程,包括Verilog逻辑部分,和裸机软件部分。裸机控制外设是非常简单的,与普通的单片机并无二异,但仅仅有裸奔代码还远远无法发挥Cortex-A9硬核的作用,毕竟Zynq芯片集成了一颗最高能跑到1GHz的双核CPUZedBoard上的XC7Z020只能到800MHz)。并且ZedBoard上配备了Gigabit EthernetHDMIUSB OTG接口,不运行操作系统岂不浪费。

有朋友想要在ZedBoard上做WinCE,但这方面的资料极为稀缺,而WinCE又是体积庞大、版权成本很高的操作系统,于是开源有小巧的嵌入式Linux就成了首选。之前兔子为了做出图形界面,还致力于移植桌面型的Linaro Ubuntu系统,不过ADI给出的参考例子未经优化奇卡无比,Xillinux正式版迟迟未现又只支持色彩度很低的简易VGA接口(ZedBoard上的VGA甚至到不了16位色),于是兔子不得不放弃之前的工作,重新启用ZedBoard出厂默认的轻量级Linux上。这个系统没有图形桌面,但已包含了网卡、HDMI驱动和其他基本功能,足够使用了。

想要在Linux下控制外设,最重要的一环就是驱动了,但在动手写驱动之前,先要做些准备工作。为了减少工作量,我们就直接修改ZedBoard的出厂Demo,加入之前完成的my_gpio外设,并通过U-Boot实现Bootloader功能。这个Demo的源工程可以在Digilent网站的ZedBoard页面找到:

http://digilentinc.com/Products/Detail.cfm?NavPath=2,400,1028&Prod=ZEDBOARD

点击下面的Download,可以下载到ZedBoard_OOB_Design.zip文件,这个压缩包里包含了XPS工程、U-Boot文件、Linux内核配置文件、DeviceTree源文件、rootfs等。README.txt中有相近的操作说明,建议通读一遍。

ZedBoard上默认的XPS系统工程位于hw\xps_proj文件夹下,双击system.xmp打开工程,按照之前所说的方法,将my_gpio外设IP核导入到工程中。

传送门:ZedBoard学习手记(二) 开发自定义AXI总线外设IP——LED和开关为例

 

之后,查看一下XPS是否为我们的外设分配了地址空间,如果没有,就需要手动设置一个地址,这里我们设成0x75C80000,空间大小为AXI设备统一的64K

按照ZedBoard学习手记(二)中的方法设置总线连接,结果如下图:

修改xps_proj\data\system.ucf文件,为my_gpio外设分配外部引脚(ucf约束文件中的引脚名称和Ports中的一定要相同,已经有不少网友在这里出过问题了)。另外我们分配的引脚占用了原来ARMGPIO 引脚位置,应在XPSPort列表里将processing_system7_0_GPIO数量设为[0:6]或干禁用,以除后患。

完成后先单击Generate BitStream生成配置数据,再点击Export Design,选Export & Launch SDK将硬件信息导出到SDK中。

 

 

SDK里,新建一个C工程,不同于裸机的HelloWorld,这次要建立的是Bootloader,因此选择FSBL工程,即First Stage Bootloader,用实现U-Boot之前的初始化和启动工作。其他选项默认即可。

 

编译一下工程,完成后SDK会生成FSBLelf文件,另外加上从XPS导出的System.bit,以及我们在第一篇文章中编译生成的u-boot.elf,就可以生成用来实现SD卡启动系统的完整Bootloader文件了。

u-boot.elfZedBoard_OOB_Design中包含,不过这个兔子没试过,通过Xilinx U-Boot编译生成u-boot.elf的方法请见:ZedBoard学习手记(一) First Step——建立Xilinx交叉编译环境

 

集齐这三个文件之后,点击Xilinx Tools→Create Boot Image,添加到列表中,选择一个输出路径,就可以创建Bootloader了。

 

 

SDK会在输出路劲生成u-boot.bin文件,将其改为BOOT.bin,拷贝到SD卡中,为ZedBoard板配置合适的跳线。这时再打开ZedBoard电源,Bootloader会初始化PS,用BitStream配置PL(包含了我们创建的my_gpio外设),并将操作权移交给U-BootU-Boot会自动加载Device TreeLinux内核镜像和RootFS,最终启动Linux

ZedBoard出场时SD中还带有zImagedevicetreerootfs文件,这些文件都可以采用原有的,直接用Xilinx交叉编译工具编译写好的C语言驱动就可以在这个系统上运行并控制外设了。

当然,如果你想自己编译内核,或者不想采用静态物理地址的方式调用外设,就需要再往下进行一步,注意这一步对于Linux下控制AXI总线自定义外设并非必要。

为了给有兴趣的朋友继续深入研究做个铺垫,这里兔子就讲一下编译ZedBoard上运行的Linux内核和设备树吧。当然这个方法也详细记录在ZedBoard_OOB_DesignREADME文件中。

PCLinux环境下(兔子这里是Ubuntu)通过Git指令下载Digilent Linux内核源码:

git clone git://github.com/Digilent/linux-3.3-digilent.git

 

切换到ZedBoard Branch

cd linux-3.3-digilent

git checkout -b zedboard_oob v3.3.0-digilent-12.07-zed-beta

 

ZedBoard_OOB_Design中的.config文件拷贝到源码目录下,然后编译内核(指的是ZedBoard_OOB_Design所在目录):

cp /linux/.config ./.config

make

 

生成的内核镜像zImage 位于/arch/arm/boot/文件夹下。

之后修改devicetree_ramdisk.dts文件,加入my_gpio外设信息。

/******* LED & Swtich Controller ******/

my_gpio@75c80000 {

     compatible = "xlnx,my_gpio-1.00.a";

     reg = <0x75c80000 0x10000>;

     xlnx,dphase-timeout = <0x8>;

     xlnx,family = "virtex6";

     xlnx,c_num_reg = <0x1>;

     xlnx,c_num_mem = <0x1>;

     xlnx,s-axi-min-size = <0x1ff>;

     xlnx,c_slv_awidth = <0x20>;

     xlnx,c_slv_dwidth = <0x20>;

     xlnx,use-wstrb = <0x0>;

};

 

通过下面指令生成设备树,同样CopySD卡中:

./scripts/dtc/dtc -O dtb –I dts –o ./devicetree_ramdisk.dtb \          /linux/devicetree_ramdisk.dts

 

这个设备树文件有网友说是将驱动加入到内核中用的,但兔子以为不然。如果不想通过静态设备物理地址(上面的0x75c80000)来加载驱动,就可以根据这个设备树信息(具体是通过xlnx,my_gpio-1.00.a字串)来动态识别设备。

6. SD卡文件内容四(ramdisk8M.image.gz)

DigilentOOB设计给出了一个ZedBoard上完整的运行的linux系统所需要的所有文件,包括配置FPGAbit文件、 配置ARM PS系统的First-Stage boot loader(FSBL)和引导linux需要的Second-Stage boot loader(SSBL)Linux内核zImage、设备树文件devicetree_ramdisk.dtb 以及根文件系统ramdisk8M.image.gzlinux在运行时,加载这个ramdisk8M.image.gz镜像文件到DDR3中来执行实现根文件系统的建立,很多并不像在ubuntu中对文件系统操作那样简单。本小节介绍如何制作ZedBoard可运行的根文件系统ramdisk8M.image.gz镜像文件,参照xilinx wiki http://wiki.xilinx.com/zynq-rootfs。

通过本小节的学习,在以后的开发中,可以更加顺利的修改文件系统,给设计带来方便。

更多更新请关注我的博客:@超群天晴 http://www.cnblogs.com/surpassal/

 

硬件平台:Digilent ZedBoard

开发环境:Windows XP 32 bit + Wmare 8.0 + Ubuntu 10.04 + arm-linux-xilinx-gnueabi交叉编译环境

Zedboard linux: Digilent OOB Design 

 

1FHSFilesystem Hierarchy Standard)标准介绍

当我们在linux下输入ls  / 的时候,见到的目录结构以及这些目录下的内容都大同小异,这是因为所有的linux发行版在对根文件系统布局上都遵循FHS标准的建议规定。该标准规定了根目录下各个子目录的名称及其存放的内容:

目录名

存放的内容

/bin

必备的用户命令,例如lscp

/sbin

必备的系统管理员命令,例如ifconfigreboot

/dev

设备文件,例如mtdblock0tty1

/etc

系统配置文件,包括启动文件,例如inittab

/lib

必要的链接库,例如C链接库、内核模块

/home

普通用户主目录

/root

root用户主目录

/usr/bin

非必备的用户程序,例如finddu

/usr/sbin

非必备的管理员程序,例如chrootinetd

/usr/lib

库文件

/var

守护程序和工具程序所存放的可变,例如日志文件

/proc

用来提供内核与进程信息的虚拟文件系统,由内核自动生成目录下的内容

/sys

用来提供内核与设备信息的虚拟文件系统,由内核自动生成目录下的内容

/mnt

文件系统挂接点,用于临时安装文件系统

/tmp

临时性的文件,重启后将自动清除

 

制作根文件系统就是要建立以上的目录,并在其中建立完整目录内容。其过程大体包括:

· 编译/安装busybox,生成/bin/sbin/usr/bin/usr/sbin目录

· 利用交叉编译工具链,构建/lib目录

· 手工构建/etc目录

· 制作根文件系统的镜像文件

下面就来详细介绍这个过程。

1、编译安装busybox,生成/bin/sbin/usr/bin/usr/sbin目录

首先下载BusyBox源码,使用命令

git clone git://git.busybox.net/busybox

当然,和往常一样,为了给上不了国外网站的同学们提供便利,这里提供一个国内的下载链接:

busybox下载

下载后,切换到busybox目录,并进行默认配置

make ARCH=arm CROSS_COMPILE=arm-xilinx-linux-gnueabi- defconfig

使用命令

make ARCH=arm CROSS_COMPILE=arm-xilinx-linux-gnueabi- menuconfig

打开可视化界面配置

逐一进入

BusyBox Settings->Installation Options->BusyBox installation prefix

将目录设置为

/home/devel/_rootfs

保存后退出,并安装busybox

make ARCH=arm CROSS_COMPILE=arm-xilinx-linux-gnueabi- install

安装好后,我们能够在/home/devel/_rootfs目录下看到生成了的bin sbin usr/bin usr/sbin 目录,其下包含了我们常用的命令,这些命令都是指向bin/busybox的软链接。

 3、安装Dropbear

我对dropbear的功能不是很明白,从百度上获取到的信息是“dropbear实现完整的SSH客户端和服务器版本2协议。它不支持SSH版本的向后兼容性,以节省空间和资源,并避免在SSH版本1的固有的安全漏洞。还实施了SCP的。SFTP支持依赖于一个二进制文件,可以通过提供的OpenSSH或类似的计划。由于xilinx wiki上有这样的步骤,还是老老实实的做吧。

下载dropbear,并解压

wget http://matt.ucc.asn.au/dropbear/releases/dropbear-0.53.1.tar.gz

tar xfvz dropbear-0.53.1.tar.gz

配置dropbear

./configure --prefix=/home/devel/_rootfs --host=arm-xilinx-linux-gnueabi --disable-zlib CC=arm-xilinx-linux-gnueabi-gcc LDFLAGS="-Wl,--gc-sections" CFLAGS="-ffunction-sections -fdata-sections -Os"

编译

make PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp" MULTI=1 strip

安装dropbear并创建符号链接

make install

ln -s http://www.cnblogs.com/sbin/dropbear /home/devel/_rootfs/usr/bin/scp

4、利用交叉编译工具链,构建/lib目录

进入/home/devel/_rootfs,创建lib目录

cd /home/devel/_rootfs

bashmkdir lib

将交叉编译环境库拷贝到这个目录下

cp /opt/14.2/ISE_DS/EDK/gnu/arm/lin64/arm-xilinx-linux-gnueabi/libc/lib/* lib -r

同样,将工具链拷贝到sbin/usr/bin/

cp /opt/14.2/ISE_DS/EDK/gnu/arm/lin64/arm-xilinx-linux-gnueabi/libc/sbin/* sbin/ -r

cp /opt/14.2/ISE_DS/EDK/gnu/arm/lin64/arm-xilinx-linux-gnueabi/libc/usr/bin/* usr/bin/ -r

注意:很多网友说,自己的电脑上没有lin64文件夹,只有nt文件夹。这个问题是由于在安装ISE版本是,操作系统32/64位决定的。我在XP(32)下安装时也只有nt文件夹,因而我选择一个的方法:把OOB中的lib/sbin/bin、 usr/bin文件夹直接拷贝出来,相应替换掉。

 usr/bin目录文件下载

 sbin目录文件下载

 lib目录文件下载

 

5、创建其他目录和相应配置

至此,几个重要的目录和文件都已经创建完毕,需要安装FHS要求把其他目录和文件创建。切换到_rootfs目录下,使用命令

mkdir dev etc etc/dropbear etc/init.d mnt opt proc root sys tmp var var/log var/www

创建"etc/fstab"文件,内容如下

LABEL=/     /           tmpfs   defaults        0 0none        /dev/pts    devpts  gid=5,mode=620  0 0none        /proc       proc    defaults        0 0none        /sys        sysfs   defaults        0 0none        /tmp        tmpfs   defaults        0 0

创建"etc/inittab"文件,内容如下

::sysinit:/etc/init.d/rcS

# /bin/ash

# Start an askfirst shell on the serial ports

ttyPS0::respawn:-/bin/ash

# What to do when restarting the init process

::restart:/sbin/init

# What to do before rebooting

::shutdown:/bin/umount -a -r

创建"etc/passwd"文件,内容如下

root:$1$qC.CEbjC$SVJyqm.IG.gkElhaeM.FD0:0:0:root:/root:/bin/sh

创建文件"etc/init.d/rcS" ,内容如下

#!/bin/sh

echo "Starting rcS..."

echo "++ Mounting filesystem"mount -t proc none /proc

mount -t sysfs none /sys

mount -t tmpfs none /tmp

echo "++ Setting up mdev"

echo /sbin/mdev > /proc/sys/kernel/hotplug

mdev -s

mkdir -p /dev/pts

mkdir -p /dev/i2c

mount -t devpts devpts /dev/pts

echo "++ Starting telnet daemon"telnetd -l /bin/sh

echo "++ Starting http daemon"httpd -h /var/www

echo "++ Starting ftp daemon"tcpsvd 0:21 ftpd ftpd -w /&

echo "++ Starting dropbear (ssh) daemon"dropbear

echo "rcS Complete"

并设置其权限

chmod 755 etc/init.d/rcS

sudo chown root:root etc/init.d/rcS

BTW,我们的后续设计中,为了实现应用程序上电后自动启动运行,可以修改rcS文件内容,将应用程序执行命令写入到rcS文件中。

6、生成ramdisk镜像文件

至此,根文件系统所有需要的目录和文件已经准备完毕。查看_rootfs下的内容

这个根文件系统能够被执行,还需要将其制作成image镜像文件,并压缩。

接下来的操作如果和xilinx wiki上操作一致,最终的文件系统并不能被识别,所以这里介绍的和xilinx wiki有少许不同。

创建镜像文件ramdisk8M.image,并设置大小为8M,文件系统格式为ext2

cd ~dd if=/dev/zero of=ramdisk8M.image bs=1024 count=8192mke2fs -F ramdisk8M.image -L "ramdisk" -b 1024 -m 0tune2fs ramdisk8M.image -i 0

chmod 777 ramdisk8M.image

大小可以按照需要自己调整,但是最好不要超过32M

创建ramdisk目录,将ramdisk8M.image 挂载到该目录下,

mkdir ramdisk

mount -o loop ramdisk8M.image ramdisk/

接下来,只需要将_rootfs目录下的内容全部拷贝到ramdisk下即可

cp -R /home/devel/_rootfs/* ramdisk

注意,这里cp的参数一定是R而非r

这样,这个镜像文件的内容就是_rootfs目录下的内容了。将其卸载就可

umount ramdisk/

到此,根文件系统镜像文件ramdisk8M.image 制作完成,将其压缩

gzip -9 ramdisk8M.image

生成ramdisk8M.image.gz文件,拷贝到SD上就可以了。

 

==========================

7. SD卡文件内容五(rootfs)

LinuxRoot Filesystem(根文件系统)是必不可少的,常用的是BusyBox,本节就介绍一下使用BusyBox制作Linux根文件系统rootfs,主要参考xilinx wikiZynq Root FileSystem Creation方法:http://wiki.xilinx.com/zynq-rootfs

1. 准备工作:
首先在Ubuntu中建立ARM GNU交叉编译环境,笔者使用的是Ubuntu11.04平台。
通过Git下载BusyBox

git clone git://git.busybox.net/busybox

复制代码

2. 编译安装BusyBox
Ubuntu平台中进入BusyBox,进行初始化默认配置:

cd busybox

make defconfig

自定义配置BusyBox,会弹出图形界面设置窗口,如图1所示

make menuconfig

1

进入BusyBox Settings->Installation Options->BusyBox installationprefix设置BusyBox的安装目录,将其设置为/home/devel/_rootfs,如图2所示。

2


完成配置后,输入以下脚本安装BusyBox

sudo make install


在设置的目录中会生成rootfs,其中包含了binsbinusr/binusr/sbin 目录,其下包含了我们常用的命令,这些命令都是指向bin/busybox的软链接,如图3所示。

3

3. 编译安装Dropbear
Dropbear提供支持SSH客户端/服务器功能。


Dropbear网站上下载Dropbear,并解压:

wget http://matt.ucc.asn.au/dropbear/releases/dropbear-0.53.1.tar.gz

tar xfvz dropbear-0.53.1.tar.gz

cd dropbear-0.53.1



配置Dropbear

./configure --prefix=/home/devel/_rootfs --host=arm-xilinx-linux-gnueabi --disable-zlib CC=arm-xilinx-linux-gnueabi-gcc LDFLAGS="-Wl,--gc-sections" CFLAGS="-ffunction-sections -fdata-sections -Os"


编译Dropbear

make PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp" MULTI=1 strip


安装Dropbear,并且在rootfs中建立链接,如图4所示为生成的scp

sudo make install

ln -s ../../sbin/dropbear /home/devel/_rootfs/usr/bin/scp


4

4. 工具链和应用程序配置
需要将Xilinx ARM工具链的库拷贝到rootfs中的lib文件夹下,由于笔者没有在Ubuntu平台上安装ISE套件,因此从Windows平台上拷贝,在Windows平台上的位置:*:\Xilinx\14.2\ISE_DS\EDK\gnu\arm\nt\arm-xilinx-linux-gnueabi\libc\lib


然后将libc/sbinlibc/usr/bin中的文件也拷贝进去。

5. 其它目录生成和配置
rootfs中还需要创建其它目录,如下脚本:

mkdir dev etc etc/dropbear etc/init.d mnt opt proc root sys tmp var var/log var/www

5


创建etc/fstab文件:sudo gedit etc/fstab,文件内容如下:

LABEL=/    /           tmpfs   defaults        0 0

none       /dev/pts    devpts  gid=5,mode=620  0 0

none       /proc       proc    defaults        0 0

none       /sys        sysfs   defaults        0 0

none       /tmp        tmpfs   defaults        0 0


创建etc/inittab文件:sudo gedit etc/inittab,文件内容如下:

::sysinit:/etc/init.d/rcS

# /bin/ash

# Start an askfirst shell on the serial ports

ttyPS0::respawn:-/bin/ash

# What to do when restarting the init process

::restart:/sbin/init

# What to do before rebooting

::shutdown:/bin/umount -a –r


创建etc/ passwd文件:sudo gedit etc/passwd,文件内容如下:

root:$1$qC.CEbjC$SVJyqm.IG.gkElhaeM.FD0:0:0:root:/root:/bin/sh


创建etc/init.d/rcS文件:sudo gedit etc/init.d/rcS,文件内容如下:

#!/bin/sh

echo "Starting rcS..."

echo "++ Mounting filesystem"

mount -t proc none /proc

mount -t sysfs none /sys

mount -t tmpfs none /tmp

echo "++ Setting up mdev"

echo /sbin/mdev > /proc/sys/kernel/hotplug

mdev -s

mkdir -p /dev/pts

mkdir -p /dev/i2c

mount -t devpts devpts /dev/pts

echo "++ Starting telnet daemon"

telnetd -l /bin/sh

echo "++ Starting http daemon"

httpd -h /var/www

echo "++ Starting ftp daemon"

tcpsvd 0:21 ftpd ftpd -w /&

echo "++ Starting dropbear (ssh)daemon"

dropbear

echo "rcS Complete"



设置etc/init.d/rcS的权限:

chmod 755 etc/init.d/rcS

sudo chown root:root etc/init.d/rcS



到这一步,rootfs目录算是创建完成了

6. 生成ramdisk镜像文件
rootfs想要被识别,需要将其制作成镜像image文件,并且压缩。如下脚本为创建image文件:

cd ~

dd if=/dev/zero of=ramdisk8M.image bs=1024 count=8192

mke2fs -F ramdisk8M.image -L "ramdisk" -b 1024 -m 0

tune2fs ramdisk8M.image -i 0

chmod 777 ramdisk8M.image


新建一个ramdisk目录,然后将ramdisk8M.image加载到该目录下:

mkdir ramdisk

mount -o loop ramdisk8M.image ramdisk/


_rootfs/目录下的文件拷贝到ramdisk中:

cp -R /home/devel/_rootfs/* ramdisk


拷贝完成后卸载ramdisk

umount ramdisk/


最后压缩ramdisk8M.image文件:

gzip -9 ramdisk8M.image


ramdisk8M.image.gz镜像文件生成完毕,如图6所示。

6

附录 SD卡分区方法

可以在windows系统和linux中分别进行分区操作,在linux下使用gparted分区工具,

windows推荐使用sd 卡分区软件PM9.0 汉化版工具。我是在xp下装的ubuntu的虚拟机,

因此是在xp下对SD 卡进行分区的,使用的是PM工具。

使用VMware 虚拟机+gpartedSD卡分区参考:

http://blog.csdn.net/flyingforever_wl/article/details/8095489

安装过程大同小异,选择安装目录就可以了。

分区过程如下:

1) 插入SD 卡,容量不小于4GB

2) 将SD 卡格式化为FAT32 格式,注意不要选择快速格式化

3) 打开PM 软件,在SD 卡上右键打击,选择移动/调整分区大小,如下图:

4) 将下图的红线框的数值改为FAT32 的大小,确保大于50MB,我这边给的是100MB

然后点击线面的两个框,就会自动更新数值,然后点击

5) 鼠标放在上图蓝色区域,点击右键,选择更改卷标,如下图:

将其改为BOOT,即:

然后点击

6) 接下来创建linux 分区,如下图:

点击创建分区,然后创建新分区为主分区,卷标为“rootfs”,文件系统为“Linux

Ext3,由于只分两个区,因此新分区大小就为剩下的区域的最大值,如图:

然后点击

7) 回到主界面,点击应用改变

一路选择“yes”,直到:

时间比较长,耐心等待。

8) 分区完成后,点击“close”,退出软件。

9) 要想重新将SD 弄成一个区,只用删除掉分区,再创建分区,指定大小和格式便可。

原创粉丝点击