ZYNQ Linux的QSPI Flash启动

硬件平台:XCZ7020 CLG484-1
开发环境:Widows下Vivado 2016.2 、 SDK2016.2 、 Ubuntu 16.04
工具:kermit
所需材料:编译好的u-boot.elf、uImage、devicetree.dtb、uramdisk、硬件平台的bitstream
思路:先通过SDK生成BOOT.bin(不包含bitstream),并使用SDK将BOOT.bin下载到QspiFlash中,配置板卡从QspiFlash启动。Uboot执行之后通过Uboot使用串口将uImage、devicetree.dtb、uramdisk、bitstream下载到QspiFlash中,并将各个文件的地址传给Uboot。配置完Uboot后即完成。

STEP1:
首先:下载kermit工具,并配置kermit。
通过串口将文件下载到QspiFlash中使用的是kermit协议,而常用的minicom不支持kermit协议,所以需要安装kermit。

 # apt-get install ckermit

安装完后配置kermit,将下面代码添加到/etc/kermit/kermrc中。注意:需要改变kermrc文件权限。

    set line          /dev/ttyUSB0
    set speed         115200
    set carrier-watch off
    set handshake     none
    set flow-control none
    robust
    set file type     bin
    set file name     lit
    set rec pack      1000
    set send pack     1000
    set window        5

Kermit模式切换:

 # kermit 即可启动kermit
 C-Kermit>connect 连接串口进入到超级终端模式
 同时按下 Ctrl + \ 再按c切换到kermit命令模式

SETP2:
下载文件到QspiFlash中。我的硬件平台上的QspiFlash大小为32MB,空间分配如下所示:

                起始         SIZE
BOOT.bin     0X000000     0X100000
uImage       0X100000     0X600000
devicetree   0X700000     0X100000
uramdisk     0X800000     0X1200000
bitstream    0X1A00000    0X500000

按照分区更改设备树文件xilinx.dts,并重新生成devicetree.dtb,下段为xilinx.dts内容

/dts-v1/;
/include/ "zynq-7000.dtsi"
/include/ "pcw.dtsi"
/ {
    chosen {
        bootargs = "console=ttyPS0,115200 root=/dev/ram/ rw earlyprintk earlycon";
        stdout-path = "serial0:115200n8";
    };
    aliases {
        ethernet0 = &gem0;
        serial0 = &uart1;
        spi0 = &qspi;
    };
    memory {
        device_type = "memory";
        reg = <0x0 0x20000000>;
    };
    cpus {
    };
};
&qspi{
    status = "okay";
    is-dual=<0>;
    num-cs = <1>;
    flash@0 {
        compatible = "n25q128a11";
        reg = <0x0>;
        spi-tx-bus-width = <1>;
        spi-rx-bus-width = <4>;
        spi-max-frequency=<50000000>;
        #address-cells = <1>;
        #size-cells =<1>;
        partition@qspi-fsbl-uboot{
            label = "qspi-fsbl-uboot";
            reg =<0x0 0x100000>;
        };
        partition@qspi-linux{
            label = "qspi-linux";
            reg =<0x100000 0x600000>;
            };
        partition@qspi-device-tree{
            label = "qspi-device-tree";
            reg =<0x700000 0x100000>;
            };
        partition@qspi-rootfs{
            label = "qspi-rootfs";
            reg =<0x800000 0x1200000>;
            };
        partition@qspi-bitstream{
            label = "qspi-bitstream";
            reg =<0x1A00000 0x500000>;
            };
    };
};

STEP3:
编译生成uboot.elf、uImage、uramdisk、devicetree.dtb,并通过SDK将fsbl.elf和uboot.elf生成BOOT.bin文件,并下载到QspiFlash中。

STEP4:将文件下载到QspiFlash中
调整板卡启动方式为QspiFlash启动,在ubuntu上执行kermit并切换到超级终端模式,等待uboot启动。
uboot启动后进入到uboot命令行,我们需要用到的命令主要是sf命令:
sf erase 从设定地址开始,擦除设定大小的存储空间
sf read 将Flash中内容读到内存中
sf write 将内存中内容写到内存中

//将uImage下载到QpsiFlash起始地址为0X100000,大小0X600000的区域内
zynq>sf probe 0 0 0  //初始化QspiFlash
zynq>sf erase 0x100000 0x600000 //从0x100000开始擦除,擦除大小0x600000
zynq>sf read 0x8000000 0x100000 0x600000 //把flash起始地址0x100000大小为0x600000的内容读到内存的0x8000000(擦除内存)
zynq>laodb 0x8000000 //下载文件到0x8000000

Ctrl+\+c//切换到kermit命令模式下
send ~/ZYNQ/build/linux-xlnx/arch/arm/boot/uImage //发送要下载的文件
//文件下载完毕后
c-kermit>c //切换到终端模式
zynq>sf write 0x8000000 0x100000 0x600000//将内存中0x8000000起始,大小为0x600000的内容写到Flash的0x100000处

执行完这些命令后,内核即被下载到Flash的0x100000处,其它文件的下载和内核下载一样,下面给出参考代码

//devicetree
zynq>sf erase 0x700000 0x100000
zynq>sf read 0x8000000 0x700000 0x100000
zynq>loadb 0x8000000
c-kermit>send ~/ZYNQ/build/xilinx-xlnx/devicetree.dtb
zynq>sf write 0x8000000 0x700000 0x100000
//ramdisk
zynq>sf erase 0x800000 0x1200000
zynq>sf read 0x8000000 0x800000 0x1200000
zynq>loadb 0x8000000
c-kermit>send ~/...
zynq>sf write 0x8000000 0x800000 0x1200000
//bitstream
zynq>sf erase 0x1a00000 0x500000
zynq>sf read 0x8000000 0x1a00000 0x500000
zynq>loadb 0x8000000
c-kermit>send ~/...
zynq>sf write 0x8000000 0x1a00000 0x500000

STEP5:修改Uboot参数

zynq>setenv bootcmd  'sf probe 0 0 0 && echo  qspi-bitstream is loading ... ... && sf read 0x800000 0x1A00000 0x500000 && fpga loadb 0 0x800000 0x400000 && echo uIamge is loading ... ... && sf read 0x2100000 0x100000 0x600000 &&echo deviceTree is loading ... ... && sf read 0x2000000 0x700000 0x100000 && echo ramdisk.image is loading ... ... && sf read 0x4000000 0x800000 0x1200000 && bootm 0x2100000 0x4000000 0x2000000'
zynq>saveenv

Linux的QSPIFlash启动即完成

你可能感兴趣的:(ZYNQ-Linux)