前情提要:

从零开始的ZYNQ学习(基于矿卡EBAZ4205)(一)

从零开始的ZYNQ学习(基于矿卡EBAZ4205)(二)

从零开始的ZYNQ学习(基于矿卡EBAZ4205)(三)

文章目录

  • 0. 声明
  • 9. 让矿卡从NAND根文件系统启动
    • 9.1 制作NAND根文件系统
      • (1)修改Petalinux工程配置
      • (2)修改设备树
      • (3)Petalinux工程编译
    • 9.2 下载镜像
    • 9.3 启动LOG和验证
    • 9.4 对分区的调整(可选)
    • 9.5 直连网络验证
  • 10. 操作PS_MIO的外设——按键
    • 10.1 GPIO的适配和Vivado工程修改
    • 10.2 Petalinux工程编译
    • 10.3 功能验证
  • 参考资料

0. 声明

本文由长春理工大学电子信息工程学院C&I实验室所有,已获得原作者发布授权。转载请注明出处。

本文编写过程中参考了很多前辈的记录,在此表示感谢,已将所有参考项列于文末。

当前版本R1.0(预发布)。

作者联系方式:E-mail: WindForest@yeah.net

9. 让矿卡从NAND根文件系统启动

在之前的学习中,我们尝试了基于initramfs和Ubuntu两种根文件系统的挂载途径,但是在实际应用中,TF卡更多地被用作额外的存储扩展而非启动设备。而嵌入式的系统和应用也往往不需要很大的空间。因此,学习制作一个从NAND启动的根文件系统是从开发板走向产品的必经之路。

ZYNQ的开发板更多地使用QSPI Flash和SD卡两种启动方式,因为这样可以将NAND占用的MIO引脚用于其它外设。因此网上对于NAND启动的资料有些少。

不过我们已经实现了从NAND启动,此时Linux的根文件系统挂载在基于内存的initramfs中,启动分区之外的NAND区域对于Linux而言是没有文件系统、无法识别的。因此制作根文件系统的主要思想就是:生成一个可被内核识别和挂载的文件系统,并覆盖烧录到NAND的剩余空间中。

注意:本章所用工程和镜像在Petalinux2018.3版本构建和编译。 作者在挂载使用Petalinux2017.4版本生成的JFFS2镜像时出错,且未解决,换用高版本之后问题消失。

使用Petalinux2017.4版本生成的镜像挂载时持续打印错误信息诸如:

jffs2: mtd->read(0x800 bytes from 0x1f800) returned ECC error
jffs2: mtd->read(0x100 bytes from 0x0) returned ECC error
jffs2: mtd->read(0x1ff20 bytes from 0xe0) returned ECC error
jffs2: jffs2_scan_eraseblock(): Node at 0x00000464 {0x1985, 0xe001, 0x0000002c) has invalid CRC 0xe0f15e5f (calculated 0xe0f1565f)
jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00000468: 0x002c instead
jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x0000046c: 0x5e5f instead
jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00000470: 0x0001 instead
jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00000474: 0x000a instead
jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00000478: 0x000c instead
jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x0000047c: 0x57d9 instead
jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00000480: 0x0404 instead
jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00000484: 0xb24f instead
jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00000488: 0x8c8d instead
jffs2: Further such events for this erase block will not be printed
...
jffs2: Argh. No free space left for GC. nr_erasing_blocks is 0. nr_free_blocks is 0. (erasableempty: yes, erasingempty: yes, erasependingempty: yes)
jffs2: jffs2_reserve_space_gc of 196 bytes for garbage_collect_dnode failed: -28
jffs2: Error garbage collecting node at 00100000!
jffs2: No space for garbage collection. Aborting GC thread
...
jffs2: Old JFFS2 bitmask found at 0x00c175a4
jffs2: You cannot use older JFFS2 filesystems with newer kernels

无论是从JFFS2分区启动亦或是从initramfs启动后挂载JFFS2分区均不成功。

参照一些解决方案,手动制作JFFS2镜像:

mkfs.jffs2 --root=./rootfs --little-endian --eraseblock=0x20000 --pagesize=0x800 --pad=0x800000 --no-cleanmarkers --output=rootfs.jffs2.manual.bin

问题依旧。如果您知道这是什么原因引起的,并且愿意分享给我,请按照文首联系方式联系我,我愿意洗耳恭听,谢谢!

9.1 制作NAND根文件系统

首先使用Vivado2018.3构建ZYNQ7010工程,按照前文(5.2章节和6.3章节)所述添加UART1、DDR3、ETH0和TF0模块,执行引脚约束并生成比特流和板级描述文件。

创建Petalinux工程,导入板级描述文件,并按照下文进行配置。

(1)修改Petalinux工程配置

在Petalinux工程目录下运行:

petalinux-config

进入工程配置菜单,进行如下修改:

  1. 修改“Image Packaging Configuration(镜像打包设置)”->“Root filesystem type(根文件系统类型)”为“JFFS2”;

  2. 而后修改“Image Packaging Configuration(镜像打包设置)”->“jffs2 erase block size(KByte)”为“jffs2 erase block size: 128KiB”;

  3. 修改“Subsystem AUTO Hardware Settings(子系统自动硬件设置)”->“Flash Settings(Flash设置)”为下图所示的参数:

    注:在这种分区设置下,Kernel将直接以NAND Flash本地存储作为根文件系统挂载使用。这在进行一些开发时会比较方便操作,例如手动移植某些库和工具等。在矿卡原本的策略中,则采用initramfs启动Kernel、再挂载JFFS2分区的办法,这样应用程序和用于启动的根文件系统分开存放,便于刷机和升级。

  4. 保证“Subsystem AUTO Hardware Settings(子系统自动硬件设置)”->“Flash Settings(Flash设置)”->“Advanced bootable images storage Settings”下各项的“image storage media(镜像存储媒介)”配置为“primary flash”。

注:JFFS2因为其特性可能并不适合大容量NAND,但Petalinux2018.3不支持YAFFS2等文件系统,因此只能选用JFFS2。如需其它文件系统,可考虑采用手动编译内核并移植其它文件系统的方法。

(2)修改设备树

先前的章节中,我们没有修改设备树中有关NAND的设置,即便是从NAND启动,也是挂载的Ramfs根文件系统,镜像由Uboot拷贝到内存中运行,因此Kernel不需要识别NAND。但当Kernel挂载本地的JFFS2文件系统或分区时,它首先需要识别并挂载NAND Flash。

打开Petalinux工程目录下的./project-spec/meta-user/recipes-bsp/device-tree/files/system-usr.dtsi文件,并在末尾追加以下内容:

&nand0 {arm,nand-cycle-t0 = <0x1E>;    /* t_rc  */arm,nand-cycle-t1 = <0x1E>;    /* t_wc  */arm,nand-cycle-t2 = <0x5>;     /* t_rea */arm,nand-cycle-t3 = <0x0F>;    /* t_wp  */arm,nand-cycle-t4 = <0x0F>;    /* t_clr */arm,nand-cycle-t5 = <0x0F>;    /* t_ar  */arm,nand-cycle-t6 = <0x19>;    /* t_rr  */status = "okay";
};

如此在Linux设备树上适配了NAND Flash读写时序,使Kernel启动时可以访问NAND Flash。此处的数值设置为和先前建立Vivado工程时一致,若更换器件则NAND访问时序需要同时被更改。

注:若不增加此内容,则启动时Kernel会报错:

nand : no NAND device found

并无法挂载NAND上的根文件系统。

(3)Petalinux工程编译

在Petalinux工程目录下执行:

petalinux-build
cd ./images/linux/
petalinux-package --boot --format BIN --fsbl zynq_fsbl.elf --fpga ZYNQ7010_wrapper.bit --u-boot --force

./images/linux/下的BOOT.BIN、image.ub和rootfs.jffs2即为待烧录的镜像。将这些文件拷贝并更改后缀名为bin以便Xilinx SDK可以识别。

9.2 下载镜像

该步骤可参考5.4-(5)章节,依次烧录BOOT.BIN、image.bin和rootfs.bin到所设置的对应起始地址,这些起始地址需和Petalinux工程配置中一致。

镜像名称 起始地址
BOOT.BIN 0x0
image.bin 0x300000
rootfs.bin 0xD00000

9.3 启动LOG和验证

重新上电后的启动日志输出如下:

U-Boot 2018.01 (Nov 18 2020 - 05:30:15 +0000) Xilinx Zynq ZC702Board: Xilinx Zynq
Silicon: v3.1
DRAM:  ECC disabled 256 MiB
NAND:  128 MiB
MMC:   Card did not respond to voltage select!----------注:启动时未插卡
mmc_init: -95, time 23
mmc@e0100000 - probe failed: -95
Card did not respond to voltage select!
mmc_init: -95, time 24In:    serial@e0001000
Out:   serial@e0001000
Err:   serial@e0001000
Board: Xilinx Zynq
Silicon: v3.1
Net:   ZYNQ GEM: e000b000, phyaddr ffffffff, interface gmii
Could not get PHY for eth0: addr -1
No ethernet found.
Hit any key to stop autoboot:  0 NAND read: device 0 offset 0x300000, size 0xa0000010485760 bytes read: OK
## Loading kernel from FIT Image at 08000000 ...Using 'conf@system-top.dtb' configurationVerifying Hash Integrity ... OKTrying 'kernel@1' kernel subimageDescription:  Linux kernelType:         Kernel ImageCompression:  gzip compressedData Start:   0x08000104Data Size:    3939629 Bytes = 3.8 MiBArchitecture: ARMOS:           LinuxLoad Address: 0x00008000Entry Point:  0x00008000Hash algo:    sha1Hash value:   f9e71358f94cea061eaddd3024249059e938f212Verifying Hash Integrity ... sha1+ OK
## Loading fdt from FIT Image at 08000000 ...Using 'conf@system-top.dtb' configurationTrying 'fdt@system-top.dtb' fdt subimageDescription:  Flattened Device Tree blobType:         Flat Device TreeCompression:  uncompressedData Start:   0x083c1f34Data Size:    13773 Bytes = 13.5 KiBArchitecture: ARMHash algo:    sha1Hash value:   7cd79570747a523ec6a949210e2d8515d2c8629cVerifying Hash Integrity ... sha1+ OKBooting using the fdt blob at 0x83c1f34
ZYNQ GEM: e000b000, phyaddr ffffffff, interface gmii
mdio_register: non unique device name 'eth0'Uncompressing Kernel Image ... OKLoading Device Tree to 07ff9000, end 07fff5cc ... OKStarting kernel ...Timer summary in microseconds (29 records):Mark    Elapsed  Stage0          0  reset98,721     98,721  board_init_r217,304    118,583  id=64231,846     14,542  main_loop4,289,965  4,058,119  bootm_start4,289,969          4  id=14,295,542      5,573  id=1004,295,551          9  id=1014,295,552          1  id=1024,304,778      9,226  id=1104,480,864    176,086  id=1054,480,878         14  id=1064,480,891         13  id=1074,480,895          4  id=1084,480,895          0  id=1094,486,157      5,262  id=904,486,163          6  id=914,486,163          0  id=924,535,275     49,112  id=954,535,295         20  id=964,535,301          6  id=974,535,304          3  id=984,535,311          7  id=994,936,604    401,293  id=74,944,290      7,686  id=154,946,894      2,604  start_kernel
429,496,729,5,t,,,1,̓,d=1,5,,,1,429,002,040,1,t,,,1,\̓,d=1,5,,,1,  board_init_fAccumulated time:0  dm_f1,589  dm_r
Booting Linux on physical CPU 0x0
Linux version 4.14.0-xilinx-v2018.3 (oe-user@oe-host) (gcc version 7.3.0 (GCC)) #1 SMP PREEMPT Wed Nov 18 02:51:48 UTC 2020
CPU: ARMv7 Processor [413fc090] revision 0 (ARMv7), cr=18c5387d
CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
OF: fdt: Machine model: xlnx,zynq-7000
bootconsole [earlycon0] enabled
Memory policy: Data cache writealloc
cma: Reserved 16 MiB at 0x0f000000
percpu: Embedded 16 pages/cpu @cedc6000 s34764 r8192 d22580 u65536
Built 1 zonelists, mobility grouping on.  Total pages: 65024
Kernel command line: ttyPS0,115200 earlyprintk root=mtd:rootfs rw rootfstype=jffs2
PID hash table entries: 1024 (order: 0, 4096 bytes)
Dentry cache hash table entries: 32768 (order: 5, 131072 bytes)
Inode-cache hash table entries: 16384 (order: 4, 65536 bytes)
Memory: 233160K/262144K available (6144K kernel code, 238K rwdata, 1560K rodata, 1024K init, 152K bss, 12600K reserved, 16384K cma-reserved, 0K highmem)
Virtual kernel memory layout:vector  : 0xffff0000 - 0xffff1000   (   4 kB)fixmap  : 0xffc00000 - 0xfff00000   (3072 kB)vmalloc : 0xd0800000 - 0xff800000   ( 752 MB)lowmem  : 0xc0000000 - 0xd0000000   ( 256 MB)pkmap   : 0xbfe00000 - 0xc0000000   (   2 MB)modules : 0xbf000000 - 0xbfe00000   (  14 MB).text : 0xc0008000 - 0xc0700000   (7136 kB).init : 0xc0900000 - 0xc0a00000   (1024 kB).data : 0xc0a00000 - 0xc0a3b840   ( 239 kB).bss : 0xc0a3b840 - 0xc0a61b84   ( 153 kB)
Preemptible hierarchical RCU implementation.RCU restricting CPUs from NR_CPUS=4 to nr_cpu_ids=2.Tasks RCU enabled.
RCU: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=2
NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16
efuse mapped to d0800000
slcr mapped to d0802000
L2C: platform modifies aux control register: 0x72360000 -> 0x72760000
L2C: DT/platform modifies aux control register: 0x72360000 -> 0x72760000
L2C-310 erratum 769419 enabled
L2C-310 enabling early BRESP for Cortex-A9
L2C-310 full line of zeros enabled for Cortex-A9
L2C-310 ID prefetch enabled, offset 1 lines
L2C-310 dynamic clock gating enabled, standby mode enabled
L2C-310 cache controller enabled, 8 ways, 512 kB
L2C-310: CACHE_ID 0x410000c8, AUX_CTRL 0x76760001
zynq_clock_init: clkc starts at d0802100
Zynq clock init
sched_clock: 64 bits at 333MHz, resolution 3ns, wraps every 4398046511103ns
clocksource: arm_global_timer: mask: 0xffffffffffffffff max_cycles: 0x4ce07af025, max_idle_ns: 440795209040 ns
Switching to timer-based delay loop, resolution 3ns
clocksource: ttc_clocksource: mask: 0xffff max_cycles: 0xffff, max_idle_ns: 537538477 ns
timer #0 at d080a000, irq=17
Console: colour dummy device 80x30
console [tty0] enabled
bootconsole [earlycon0] disabled
Booting Linux on physical CPU 0x0
Linux version 4.14.0-xilinx-v2018.3 (oe-user@oe-host) (gcc version 7.3.0 (GCC)) #1 SMP PREEMPT Wed Nov 18 02:51:48 UTC 2020
CPU: ARMv7 Processor [413fc090] revision 0 (ARMv7), cr=18c5387d
CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
OF: fdt: Machine model: xlnx,zynq-7000
bootconsole [earlycon0] enabled
Memory policy: Data cache writealloc
cma: Reserved 16 MiB at 0x0f000000
percpu: Embedded 16 pages/cpu @cedc6000 s34764 r8192 d22580 u65536
Built 1 zonelists, mobility grouping on.  Total pages: 65024
Kernel command line: ttyPS0,115200 earlyprintk root=mtd:rootfs rw rootfstype=jffs2
PID hash table entries: 1024 (order: 0, 4096 bytes)
Dentry cache hash table entries: 32768 (order: 5, 131072 bytes)
Inode-cache hash table entries: 16384 (order: 4, 65536 bytes)
Memory: 233160K/262144K available (6144K kernel code, 238K rwdata, 1560K rodata, 1024K init, 152K bss, 12600K reserved, 16384K cma-reserved, 0K highmem)
Virtual kernel memory layout:vector  : 0xffff0000 - 0xffff1000   (   4 kB)fixmap  : 0xffc00000 - 0xfff00000   (3072 kB)vmalloc : 0xd0800000 - 0xff800000   ( 752 MB)lowmem  : 0xc0000000 - 0xd0000000   ( 256 MB)pkmap   : 0xbfe00000 - 0xc0000000   (   2 MB)modules : 0xbf000000 - 0xbfe00000   (  14 MB).text : 0xc0008000 - 0xc0700000   (7136 kB).init : 0xc0900000 - 0xc0a00000   (1024 kB).data : 0xc0a00000 - 0xc0a3b840   ( 239 kB).bss : 0xc0a3b840 - 0xc0a61b84   ( 153 kB)
Preemptible hierarchical RCU implementation.RCU restricting CPUs from NR_CPUS=4 to nr_cpu_ids=2.Tasks RCU enabled.
RCU: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=2
NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16
efuse mapped to d0800000
slcr mapped to d0802000
L2C: platform modifies aux control register: 0x72360000 -> 0x72760000
L2C: DT/platform modifies aux control register: 0x72360000 -> 0x72760000
L2C-310 erratum 769419 enabled
L2C-310 enabling early BRESP for Cortex-A9
L2C-310 full line of zeros enabled for Cortex-A9
L2C-310 ID prefetch enabled, offset 1 lines
L2C-310 dynamic clock gating enabled, standby mode enabled
L2C-310 cache controller enabled, 8 ways, 512 kB
L2C-310: CACHE_ID 0x410000c8, AUX_CTRL 0x76760001
zynq_clock_init: clkc starts at d0802100
Zynq clock init
sched_clock: 64 bits at 333MHz, resolution 3ns, wraps every 4398046511103ns
clocksource: arm_global_timer: mask: 0xffffffffffffffff max_cycles: 0x4ce07af025, max_idle_ns: 440795209040 ns
Switching to timer-based delay loop, resolution 3ns
clocksource: ttc_clocksource: mask: 0xffff max_cycles: 0xffff, max_idle_ns: 537538477 ns
timer #0 at d080a000, irq=17
Console: colour dummy device 80x30
console [tty0] enabled
bootconsole [earlycon0] disabled
Calibrating delay loop (skipped), value calculated using timer frequency.. 666.66 BogoMIPS (lpj=3333333)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
CPU: Testing write buffer coherency: ok
CPU0: thread -1, cpu 0, socket 0, mpidr 80000000
Setting up static identity map for 0x100000 - 0x100060
Hierarchical SRCU implementation.
smp: Bringing up secondary CPUs ...
CPU1: thread -1, cpu 1, socket 0, mpidr 80000001
smp: Brought up 1 node, 2 CPUs
SMP: Total of 2 processors activated (1333.33 BogoMIPS).
CPU: All CPU(s) started in SVC mode.
devtmpfs: initialized
random: get_random_u32 called from bucket_table_alloc+0x1c4/0x204 with crng_init=0
VFP support v0.3: implementor 41 architecture 3 part 30 variant 9 rev 4
clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
futex hash table entries: 512 (order: 3, 32768 bytes)
pinctrl core: initialized pinctrl subsystem
NET: Registered protocol family 16
random: fast init done
DMA: preallocated 256 KiB pool for atomic coherent allocations
cpuidle: using governor menu
hw-breakpoint: found 5 (+1 reserved) breakpoint and 1 watchpoint registers.
hw-breakpoint: maximum watchpoint size is 4 bytes.
zynq-ocm f800c000.ocmc: ZYNQ OCM pool: 256 KiB @ 0xd0840000
zynq-pinctrl 700.pinctrl: zynq pinctrl initialized
e0001000.serial: ttyPS0 at MMIO 0xe0001000 (irq = 25, base_baud = 6249999) is a xuartps
console [ttyPS0] enabled
vgaarb: loaded
SCSI subsystem initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
media: Linux media interface: v0.10
Linux video capture interface: v2.00
pps_core: LinuxPPS API ver. 1 registered
pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
PTP clock support registered
EDAC MC: Ver: 3.0.0
FPGA manager framework
fpga-region fpga-full: FPGA Region probed
Advanced Linux Sound Architecture Driver Initialized.
clocksource: Switched to clocksource arm_global_timer
NET: Registered protocol family 2
TCP established hash table entries: 2048 (order: 1, 8192 bytes)
TCP bind hash table entries: 2048 (order: 2, 16384 bytes)
TCP: Hash tables configured (established 2048 bind 2048)
UDP hash table entries: 256 (order: 1, 8192 bytes)
UDP-Lite hash table entries: 256 (order: 1, 8192 bytes)
NET: Registered protocol family 1
RPC: Registered named UNIX socket transport module.
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
hw perfevents: no interrupt-affinity property for /pmu@f8891000, guessing.
hw perfevents: enabled with armv7_cortex_a9 PMU driver, 7 counters available
workingset: timestamp_bits=30 max_order=16 bucket_order=0
jffs2: version 2.2. (NAND) (SUMMARY)  © 2001-2006 Red Hat, Inc.
io scheduler noop registered
io scheduler deadline registered
io scheduler cfq registered (default)
io scheduler mq-deadline registered
io scheduler kyber registered
dma-pl330 f8003000.dmac: Loaded driver for PL330 DMAC-241330
dma-pl330 f8003000.dmac:        DBUFF-128x8bytes Num_Chans-8 Num_Peri-4 Num_Events-16
brd: module loaded
loop: module loaded
libphy: Fixed MDIO Bus: probed
CAN device driver interface
libphy: MACB_mii_bus: probed
macb e000b000.ethernet eth0: Cadence GEM rev 0x00020118 at 0xe000b000 irq 27 (00:0a:35:00:1e:53)
Generic PHY e000b000.ethernet-ffffffff:00: attached PHY driver [Generic PHY] (mii_bus:phy_addr=e000b000.ethernet-ffffffff:00, irq=POLL)
e1000e: Intel(R) PRO/1000 Network Driver - 3.2.6-k
e1000e: Copyright(c) 1999 - 2015 Intel Corporation.
ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
ehci-pci: EHCI PCI platform driver
usbcore: registered new interface driver usb-storage
i2c /dev entries driver
IR NEC protocol handler initialized
IR RC5(x/sz) protocol handler initialized
IR RC6 protocol handler initialized
IR JVC protocol handler initialized
IR Sony protocol handler initialized
IR SANYO protocol handler initialized
IR Sharp protocol handler initialized
IR MCE Keyboard/mouse protocol handler initialized
IR XMP protocol handler initialized
cdns-wdt f8005000.watchdog: Xilinx Watchdog Timer at d083c000 with timeout 10s
EDAC MC: ECC not enabled
Xilinx Zynq CpuIdle Driver started
sdhci: Secure Digital Host Controller Interface driver
sdhci: Copyright(c) Pierre Ossman
sdhci-pltfm: SDHCI platform and OF driver helper
mmc0: SDHCI controller on e0100000.mmc [e0100000.mmc] using ADMA
ledtrig-cpu: registered to indicate activity on CPUs
usbcore: registered new interface driver usbhid
usbhid: USB HID core driver
nand: device found, Manufacturer ID: 0xef, Chip ID: 0xf1
nand: Winbond W29N01HV
nand: 128 MiB, SLC, erase size: 128 KiB, page size: 2048, OOB size: 64
Bad block table found at page 65472, version 0x01
Bad block table found at page 65408, version 0x01
4 ofpart partitions found on MTD device pl35x-nand
Creating 4 MTD partitions on "pl35x-nand":
0x000000000000-0x0000002e0000 : "boot"
0x0000002e0000-0x000000300000 : "bootenv"
0x000000300000-0x000000d00000 : "kernel"
0x000000d00000-0x000008000000 : "rootfs"
fpga_manager fpga0: Xilinx Zynq FPGA Manager registered
NET: Registered protocol family 10
Segment Routing with IPv6
sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
NET: Registered protocol family 17
can: controller area network core (rev 20170425 abi 9)
NET: Registered protocol family 29
can: raw protocol (rev 20170425)
can: broadcast manager protocol (rev 20170425 t)
can: netlink gateway (rev 20170425) max_hops=1
Registering SWP/SWPB emulation handler
hctosys: unable to open rtc device (rtc0)
of_cfs_init
of_cfs_init: OK
ALSA device list:No soundcards found.
jffs2: Empty flash at 0x00721ffc ends at 0x00722000
jffs2: Empty flash at 0x00723ffc ends at 0x00724000
jffs2: Empty flash at 0x00725ffc ends at 0x00726000
jffs2: Empty flash at 0x00727ffc ends at 0x00728000
jffs2: Empty flash at 0x00729ffc ends at 0x0072a000
jffs2: Empty flash at 0x0072bffc ends at 0x0072c000
jffs2: Empty flash at 0x0072dffc ends at 0x0072e000
jffs2: Empty flash at 0x0072fffc ends at 0x00730000
jffs2: Empty flash at 0x00731ffc ends at 0x00732000
jffs2: Empty flash at 0x00733ffc ends at 0x00734000
jffs2: Empty flash at 0x00735ffc ends at 0x00736000
jffs2: Empty flash at 0x00737ffc ends at 0x00738000
jffs2: Empty flash at 0x00739ffc ends at 0x0073a000
jffs2: Empty flash at 0x0073bf90 ends at 0x0073c000
jffs2: Empty flash at 0x0073dffc ends at 0x0073e000
jffs2: Empty flash at 0x00741ffc ends at 0x00742000
jffs2: Empty flash at 0x00743ffc ends at 0x00744000
jffs2: Empty flash at 0x00745ffc ends at 0x00746000
jffs2: Empty flash at 0x00747ffc ends at 0x00748000
jffs2: Empty flash at 0x00749ffc ends at 0x0074a000
jffs2: Empty flash at 0x0074bffc ends at 0x0074c000
jffs2: Empty flash at 0x0074dfe8 ends at 0x0074e000
jffs2: Empty flash at 0x0074ff58 ends at 0x00750000
jffs2: Empty flash at 0x00750970 ends at 0x00751000
VFS: Mounted root (jffs2 filesystem) on device 31:3.
devtmpfs: mounted
Freeing unused kernel memory: 1024K
INIT: version 2.88 booting
Starting udev
udevd[697]: starting version 3.2.2
udevd[698]: starting eudev-3.2.2
hwclock: can't open '/dev/misc/rtc': No such file or directory
Wed Nov 18 03:51:01 UTC 2020
hwclock: can't open '/dev/misc/rtc': No such file or directory
Starting internet superserver: inetd.
INIT: Entering runlevel: 5
Configuring network interfaces... IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
udhcpc (v1.24.1) started
Sending discover...
Sending discover...
Sending discover...
No lease, forking to background
done.
Starting Dropbear SSH server: dropbear.
hwclock: can't open '/dev/misc/rtc': No such file or directory
Starting syslogd/klogd: done
Starting tcf-agent: OKPetaLinux 2018.3 EBAZ4205_linux_NAND /dev/ttyPS0EBAZ4205_linux_NAND login:

如未作修改,用户名和密码均为默认的“root”,在用户目录下创建任意文件并写入字符串:

cd /home/root/
touch test.txt
echo "NAND write test text.">test.txt

重新上电后再检查文件及内容存在,验证通过。

9.4 对分区的调整(可选)

对比多张矿卡,在Kernel启动期间识别MTD分区时均会提示如下所示的信息:

Bad block table found at page 65472, version 0x01
Bad block table found at page 65408, version 0x01

在使用Petalinux2017.4版本生成的镜像启动时,还会有以下信息:

nand_read_bbt: bad block at 0x000007f60000
nand_read_bbt: bad block at 0x000007f80000
nand_read_bbt: bad block at 0x000007fa0000
nand_read_bbt: bad block at 0x000007fc0000

所以矿卡的原分区策略中将这些提示的块所在地址范围设为保留,查看矿卡MTD分区表即知:

0x000000000000-0x000000300000 : "nand-fsbl-uboot"------ 3MiB
0x000000300000-0x000000800000 : "nand-linux"----------- 5MiB
0x000000800000-0x000000820000 : "nand-device-tree"-----128KiB
0x000000820000-0x000001220000 : "nand-rootfs"----------10MiB
0x000001220000-0x000002220000 : "nand-jffs2"-----------16MiB
0x000002220000-0x000002a20000 : "nand-bitstream"------- 8MiB
0x000002a20000-0x000006a20000 : "nand-allrootfs"-------64MiB
0x000006a20000-0x000007e00000 : "nand-release"---------19MiB+896KiB
0x000007e00000-0x000008000000 : "nand-reserve"--------- 2MiB

我们也可以采取相同的策略,在Petalinux工程的Flash设置中作相应修改即可。

可参考的MTD分区表

分区名称 起始地址 跨越长度
boot 0x000000 0x2E0000 (2944KiB)
bootenv 0x2E0000 0x20000 (128KiB)
kernel 0x300000 0xA00000 (10MiB)
rootfs 0xD00000 0x6E00000 (110MiB)
reserve 0x7B00000 0x500000 (5MiB)

9.5 直连网络验证

既然是为了开发,挂载NFS文件系统几乎是必选项,现在验证一下矿卡和PC机通过网线直连的通信(该部分和8.2-(3)-2)过程相同)。

将矿卡网口和PC网口直连,直连可能需要使用交叉线。

测试时本地以太网设置为:

以太网适配器 以太网:IPv4 地址 : 169.254.134.39子网掩码   : 255.255.255.0默认网关   : 169.254.134.1

开发板中设置网络为:

root@EBAZ4205_linux_NAND:/mnt# ifconfig eth0 169.254.134.37 broadcast 169.254.134.255 netmask 255.255.255.0
root@EBAZ4205_linux_NAND:/mnt# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0A:35:00:1E:53  inet addr:169.254.134.37  Bcast:169.254.134.255  Mask:255.255.255.0inet6 addr: fe80::20a:35ff:fe00:1e53%lo/64 Scope:LinkUP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1RX packets:433 errors:0 dropped:0 overruns:0 frame:0TX packets:252 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000 RX bytes:25262 (24.6 KiB)  TX bytes:51968 (50.7 KiB)Interrupt:27 Base address:0xb000 lo        Link encap:Local Loopback  inet addr:127.0.0.1  Mask:255.0.0.0inet6 addr: ::1%1/128 Scope:HostUP LOOPBACK RUNNING  MTU:65536  Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

ping一下PC机:

root@EBAZ4205_linux_NAND:~# ping 169.254.134.39
PING 169.254.134.39 (169.254.134.39): 56 data bytes
64 bytes from 169.254.134.39: seq=0 ttl=128 time=0.824 ms
64 bytes from 169.254.134.39: seq=1 ttl=128 time=0.819 ms
64 bytes from 169.254.134.39: seq=2 ttl=128 time=0.305 ms
64 bytes from 169.254.134.39: seq=3 ttl=128 time=0.369 ms
64 bytes from 169.254.134.39: seq=4 ttl=128 time=0.362 ms
64 bytes from 169.254.134.39: seq=5 ttl=128 time=0.309 ms
^C
--- 169.254.134.39 ping statistics ---
6 packets transmitted, 6 packets received, 0% packet loss
round-trip min/avg/max = 0.305/0.498/0.824 ms

挂载PC机上的NFS目录:

mount -t nfs -o nolock -o sync 169.254.134.39:/share /mnt
cd /mnt
ls

注:推荐一款在Windows上使用的NFS服务器:haneWIN。

至此,矿卡从NAND挂载JFFS2根文件系统并启动的过程成功完成。

10. 操作PS_MIO的外设——按键

当进行到这个阶段,骄傲的心随着成就感逐渐膨胀起来了,这样下去是不行的。再端详一下矿卡,蓦然回首发现:连接在PS_MIO的按键还没有使用到。作为一个近似完美主义者,自然不会略过这种事情不管。

在4.4章节介绍过按键的引脚连接方式:S2接在ZYNQ的A17引脚;S3接在ZYNQ的A14引脚。按照5.2-(2)章节贴出的网站可查找到这两个脚对应的MIO编号和GPIO号,我们要做的就是在Vivado中使能它们。

[文内引用]查找引脚号和对应的引脚名称可登陆下面的网站:XILINX Package Files Portal,选择“Zynq®-7000 SoC Package Files”项,选择对应型号和封装,即可查看引脚信息。

按键丝印 ZYNQ引脚 MIO编号 GPIO编号
S2 A17 PS_MIO20_501 GPIO[20]
S3 A14 PS_MIO32_501 GPIO[32]

本章的目的是尝试在Linux下读取矿卡板载按键的电平状态。

10.1 GPIO的适配和Vivado工程修改

我们在第9章的Vivado工程上进行修改,当然,本章的测试环境依然沿用第9章的Vivado2018.3版本工程。在ZYNQ的IP核上双击并增加GPIO的配置。


在修改过程中比较重要的一点是,需要将按键对应的GPIO的内部上拉电阻 失能 。按照按键连接电路,按键对PS_MIO的连接被外部10K电阻下拉,内部上拉电阻的存在会使按键空闲电平存在不确定性,测试中发现,使能内部上拉会导致按键松开后检测电平维持在高电平状态。

注:将外部下拉电阻改小(例如1KΩ)可以解决启用内部上拉电阻造成的问题。


而后重新综合工程并导出硬件描述文件(*.hdf文件)即可。

10.2 Petalinux工程编译

在原有的Petalinux工程上更新硬件描述文件,并重新运行:

petalinux-config --get-hw-description=./

从硬件描述文件生成工程配置即可,原有的对Petalinux工程、Uboot和Kernel的配置将保持不变。更新配置后直接运行编译:

petalinux-build
cd ./images/linux/
petalinux-package --boot --format BIN --fsbl zynq_fsbl.elf --fpga ZYNQ7010_wrapper.bit --u-boot --force

并得到最终镜像。

10.3 功能验证

将镜像下载到矿卡并启动到Linux,使用Sysfs文件系统可以方便地对GPIO进行验证。

cd /sys/class/gpio/

在此目录下有一个名为gpiochip906的项,因此,若需操作某一MIO_GPIO,需要引出(export)的GPIO编号为:906+MIO号

#引出S2按键对应GPIO到用户空间
echo 926 > /sys/class/gpio/export
#引出S3按键对应GPIO到用户空间
echo 938 > /sys/class/gpio/export

此时在目录下会出现GPIO对应节点:

root@EBAZ4205_linux_NAND:/sys/class/gpio# ls
export       gpio926      gpio938      gpiochip906  unexport

引出时GPIO的方向默认为输入,可如此查看:

cd /sys/class/gpio/
cat /sys/class/gpio/gpio926/direction
cat /sys/class/gpio/gpio938/direction

GPIO电平状态可如此查看(1表示按下,0表示抬起):

#查看S2按键状态
cat /sys/class/gpio/gpio926/value
#查看S3按键状态
cat /sys/class/gpio/gpio938/value

在应用程序中可以使用epoll/poll/select监听GPIO中断,此处不表。

至此,矿卡按键部分描述完毕。

参考资料

本文编写过程中参考的所有资料均列在下方。本文若与任何列表之外的文章、博客、视频、教程等描述相同或相似则纯属巧合。

另在此处再次对以下资料的作者们表示感谢。

  1. SEMC—扩展外部NAND flash
  2. Petalinux 2018.2 nand : no NAND device found 解决办法_CSDN
  3. jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x000a0000: 0x3030 instead 问题分析_CSDN
  4. nand有很多坏块的问题_CSDN
  5. Xilinx Zynq pl353-nand使用_CSDN
  6. 在nand flash上实现JFFS2根文件文件系统_CSDN
  7. jffs2 启动的常见的问题_CSDN
  8. Memory Technology Device (MTD) Subsystem for Linux.
  9. Mount JFFS2 FS in OpenWRT
  10. jffs2_scan_eraseblock(): Magic bitmask解决
  11. While trying to open /dev/mtd2 for read/write access: Permission denied
  12. ZYNQ开机挂载SPI FLASH中的jffs2文件系统_CSDN
  13. 嵌入式linux-Jffs2根文件系统jffs2_scan_eraseblock()错误_CSDN
  14. Linux系统中/dev/mtd与/dev/mtdblock的区别
  15. mtd与mtdblock节点的对应问题_CSDN
  16. jffs2 cleanmarker
  17. 适用于新手的 Linux Flash 讲解:Linux如何与Flash一起使用?_CSDN
  18. Linux flash 操作
  19. AM3358: NAND flash erase error
  20. Zynq芯片NAND启动方式支持
  21. Linux下GPIO的使用_简书
  22. Linux无需开发底层驱动,从应用层获取GPIO中断_CSDN

————2020-11-18 @燕卫博————

《从零开始的ZYNQ学习(基于矿卡EBAZ4205)》系列到此结束,PS-PL通信和协作方式不在“从零”系列。

从零开始的ZYNQ学习(基于矿卡EBAZ4205)(四)相关推荐

  1. 从零开始的ZYNQ学习(基于矿卡EBAZ4205)(一)

    文章目录 0. 声明 1. 矿卡EBAZ4205介绍 2. 学习要点和目标 3. 成品板?开发板! 4. 板载外设们 4.1 TF卡及TF卡启动配置 4.2 PWM输出电路的修改 4.3 LED 4. ...

  2. 百问网7天物联网智能家居 学习心得 打卡第四天

    打卡第三天. 2022/2/16 基础班第三节培训. 主要讲的内容是:中断流程图.中断有那些(概括).中断优先级.GPIO中断. 1.中断流程图,程序开始时先执行主程序,这个时候如果发生中断了,暂停主 ...

  3. EBAZ4205矿卡控制卡

    EBAZ4205矿卡控制卡 写在前面: ​ 前一段由于学习需要,在某鱼入手了一张EBAZ4205的控制卡,当时号称最便宜,最具性价比的ZYNQ开发板,对于穷学生一枚的我,果断入手,仅消耗30.然而在继 ...

  4. 成本低廉的深度学习与渲染显卡购买方案--英伟达矿卡P106

    此方案适用于个人或小型企业,此方案有不稳定性,如果预算充足请购买Tesla 显卡 转载请注明出处 视频:https://www.bilibili.com/video/av35317062 渲染,深度学 ...

  5. 用矿卡P106升级tensorflow深度学习服务器

    PS:本文绝不是广告,也和淘宝店主没任何关系!!! 最近发现淘宝上的矿卡便宜的让人心动,虽然去年已经买了一块技嘉的大将1066显卡,但是如果错失这个大好良机,那势必会给自己留下难以抹去的遗憾!400元 ...

  6. STM32CubeMX学习笔记(49)——USB接口使用(MSC基于SD卡模拟U盘)

    一.USB简介 USB(Universal Serial BUS)通用串行总线,是一个外部总线标准,用于规范电脑与外部设备的连接和通讯.是应用在 PC 领域的接口技术.USB 接口支持设备的即插即用和 ...

  7. ZYNQ学习之路17.自定义SDSoC硬件平台

    前言 在前面的学习中,我们已经学会了使用Vivado及SDK开发环境,熟悉了硬件开发与Linux软件驱动之间的联系及开发流程.本系列教程我们学习SDSoc的开发,在SDSoc IDE中,Xilinx为 ...

  8. ZYNQ学习之路13.创建PetaLinux工程

    在前面的学习中,我们知道如何根据PetaLinux BSP设计去创建一个工程,现在,我们结合Vivado设计我们自己PetaLinux系统. 开发环境:Ubuntu16 64bit, PetaLinu ...

  9. Android学习-- 基于位置的服务 LBS(基于百度地图Android SDK)--定位SDK

    原文:Android学习-- 基于位置的服务 LBS(基于百度地图Android SDK)--定位SDK 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.ne ...

最新文章

  1. html登录界面cookie,HTML中使用cookie保存登录账户
  2. 《STM32库开发实战指南:基于STM32F103(第2版)》——2.1节仿真器简介
  3. 鸿蒙手机系统开发大会,鸿蒙OS+EMUI10,华为开发者大会的创新与看点
  4. python 读取yml文件_Python 读取 yaml 配置文件 | 文艺数学君
  5. Pixel 3的超分辨变焦技术
  6. linux 文件的压缩和打包
  7. Magento教程 5:系统安装与备份
  8. ffice 2016 文件运行excel的数据透视表中的数据切片器的时候自动关闭
  9. linux基础学习【6】
  10. opencv函数介绍—normalize
  11. 《中国史学名著》的读后感作文2600字
  12. Vue学习(学习打卡Day14)
  13. UE4UMG之TreeView
  14. SQL server Date函数
  15. A Complete ActiveX Web Control Tutorial
  16. Fragment 可见性监听方案 - 完美兼容多种 case
  17. Ubuntu下安装搜狗输入法、截屏软件、谷歌浏览器
  18. 视觉增强词向量:我是词向量,我开眼了!
  19. Mysql 中MVCC 设计方式
  20. Oracle培训和认证

热门文章

  1. PT SDC命令持续更新中
  2. 【自动驾驶汽车技术 | 车载雷达系统】
  3. 论文分享 DeepCenterline: A Multi-task Fully Convolutional Network for Centerline Extraction
  4. 低代码开发,推荐一款Web 端自动化神器:Automa!
  5. 访存控制信号——IO/M(M上方带横杠)
  6. java学习网站http://how2j.cn/
  7. module ‘selenium.webdriver‘ has no attribute ‘PhantomJS‘
  8. 惠普win10一键还原_惠普win10一键还原,惠普电脑怎么进入bios
  9. 英文不好看GitHub很费劲怎么办?使用Google浏览器,自带翻译功能
  10. (遇到问题)(已解决) raise NotImplementedErrorNotImplementedError