Zynq-Linux移植学习笔记之11-qspi驱动配置与测试接口

1、  devicetree配置

devicetree中涉及到QSPI FLASH的部分如下:

[plain]  view plain  copy
  1. spi@e000d000 {  
  2.                             clock-names= "ref_clk", "pclk";  
  3.                             clocks= <0x1 0xa 0x1 0x2b>;  
  4.                             compatible ="xlnx,zynq-qspi-1.0";  
  5.                             status= "okay";  
  6.                             interrupt-parent= <0x3>;  
  7.                             interrupts= <0x0 0x13 0x4>;  
  8.                             reg= <0xe000d000 0x1000>;  
  9.                             #address-cells= <0x1>;  
  10.                             #size-cells= <0x0>;  
  11.                             is-dual = <0x0>;  
  12.                             num-cs = <0x1>;  
  13.    
  14.                             flash@0{  
  15.                                      compatible ="n25q256a13";  
  16.                                      reg= <0x0>;  
  17.                                      spi-tx-bus-width= <0x1>;  
  18.                                      spi-rx-bus-width= <0x4>;  
  19.                                      spi-max-frequency= <0x2faf080>;  
  20.                                      #address-cells= <0x1>;  
  21.                                      #size-cells= <0x1>;  
  22.    
  23.                                      partition@qspi-fsbl-uboot{  
  24.                                                label= "qspi-fsbl-uboot";  
  25.                                                reg= <0x0 0x100000>;  
  26.                                      };  
  27.    
  28.                                      partition@qspi-linux{  
  29.                                                label= "qspi-linux";  
  30.                                                reg= <0x100000 0x500000>;  
  31.                                      };  
  32.    
  33.                                      partition@qspi-device-tree{  
  34.                                                label= "qspi-device-tree";  
  35.                                                reg= <0x600000 0x20000>;  
  36.                                      };  
  37.    
  38.                                      partition@qspi-rootfs{  
  39.                                                label= "qspi-rootfs";  
  40.                                                reg= <0x620000 0x5e0000>;  
  41.                                      };  
  42.    
  43.                                      partition@qspi-bitstream{  
  44.                                                label= "qspi-bitstream";  
  45.                                                reg= <0xc00000 0x400000>;  
  46.                                      };  
  47.                             };  
  48.                    };  


一般qspi flash被区分为五个分区,配置时需要注意下面几点:

Is_dual表示并行模式,如果不是并行设置为0(Set if parallel. Reset if single or stacked.)

Num_cs表示flash芯片数量,目前zynq把qspi flash当成一个芯片,即使板子上贴了两块芯片,zynq也只是当成一片使用

 

配置完devicetree后在xilinx_zynq_defconfig中也需要配置MTD分区

CONFIG_CMDLINE="

console=ttyPS0,115200n8

root=/dev/ram rw

initrd=0x00800000,16M

earlyprintk

mtdparts=physmap-flash.0:512K(nor-fsbl),512K(nor-u-boot),5M(nor-linux),9M(nor-user),1M(nor-scratch),-(nor-rootfs)"

通过对比devicetree中的分区和defconfig中的分区可以发现共同点:

fsbl和u-boot位于前1M(nor-fsbl+nor-u-boot)分区

linux内核位于接下来的5M(nor-linux)分区

devicetree,rootfs,bitstream中位于后面9M(nor-user)中(实际只占用6M)

 

 

2、  kernel配置

配置完devicetree后需要对kernel进行配置,在编译产生kernel时将相应的驱动加入kernel。


上图中需要将boot选项设置为采用bootloader内核参数。


将zynq QSPI控制器添加到内核中

 

3、  qspi flash测试

启动linux,在启动过程中能找到如下打印,当前linux kernel版本为3.14


从这里可以看出启动分区信息。

1)文件读写测试

当linux启动完成后,可以通过

[plain]  view plain  copy
  1. #cat /proc/mtd  

列出所有的分区


很显然,两个分区信息一致。

接下来进行flash文件读写,首先在本地创建一个文件(大小4M)

[plain]  view plain  copy
  1. #ddif=/dev/urandom of=./sample.bin bs=1024 count=4096  


拷贝到mtd3中

[plain]  view plain  copy
  1. #flashcp-v ./sample.bin /dev/mtd3  


 

2)文件系统测试

除了对flash进行文件读写测试外,Qspiflash中也可以挂载文件系统进行测试

首先列出所有分区信息

[plain]  view plain  copy
  1. #cat/proc/mtd  

对要挂载文件系统的分区进行擦除操作

[plain]  view plain  copy
  1. #flash_eraseall -j /dev/mtd3  



创建目录

[plain]  view plain  copy
  1. #mkdirqspi_flash0  


将分区挂载到qspi_flash0

[plain]  view plain  copy
  1. #mount-t jffs2 /dev/mtdblock3 /qspi_flash0  


创建要写入flash的文件

[plain]  view plain  copy
  1. #ddif=/dev/urandom of=./sample.bin bs=1024 count=4096  


将文件写入flash

[plain]  view plain  copy
  1. #cp./sample.bin /qspi_flash0/  


列出文件系统中文件

[plain]  view plain  copy
  1. ls/qspi_flash0  


卸载文件系统

[plain]  view plain  copy
  1. #umount qspi_flash0  


再次挂载文件系统

[plain]  view plain  copy
  1. #mount-t jffs2 /dev/mtdblock3 /qspi_flash0  


比较之前产生的文件与文件系统中的文件是否一致,一致证明文件系统有效

[plain]  view plain  copy
  1. #diff./sample.bin /qspi_flash0/sample.bin  


再次卸载文件系统

[plain]  view plain  copy
  1. #umountqspi_flash0  


只要不擦除flash,Sample.bin将一直存在flash中,这样就验证了文件系统的正确性。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值