ZYNQ學習(2.1) —— 啟動流程分析及各環節文件生成流程(ZedBoard為例)


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然后選擇3個文件,點擊Create Image,生成文件,其中

u-boot.bin文件就是需要的u-boot image文件,將其重命名為BOOT.BIN后拷貝到SD卡中。

4.1.  Elf文件(FSBL)

fsbl.elf文件需要在SDK軟件中生成,首先新建工程,選擇Xilinx C Project,然后選擇Zynq FSBL,編譯工程即可生成zynq_fsbl_0.elf文件

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 EthernetHDMI

USB 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

bash> mkdir 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,會彈出圖形界面設置窗口:

make menuconfig

進入BusyBox Settings->Installation Options->BusyBox installationprefix設置BusyBox的安裝目錄,將其設置為/home/devel/_rootfs

完成配置后,輸入以下腳本安裝BusyBox

sudo make install

在設置的目錄中會生成rootfs,其中包含了binsbinusr/binusr/sbin 目錄,其下包含了我們常用的命令,這些命令都是指向bin/busybox的軟鏈接

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中建立鏈接,生成scp

sudo make install

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

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/sbin和libc/usr/bin中的文件也拷貝進去。

5. 其它目錄生成和配置
rootfs中還需要創建其它目錄,如下腳本:

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


創建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鏡像文件生成完畢

附錄 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 弄成一個區,只用刪除掉分區,再創建分區,指定大小和格式便可


免責聲明!

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



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