前情提要:
文章目录
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
进入工程配置菜单,进行如下修改:
-
修改“Image Packaging Configuration(镜像打包设置)”->“Root filesystem type(根文件系统类型)”为“JFFS2”;
-
而后修改“Image Packaging Configuration(镜像打包设置)”->“jffs2 erase block size(KByte)”为“jffs2 erase block size: 128KiB”;
-
修改“Subsystem AUTO Hardware Settings(子系统自动硬件设置)”->“Flash Settings(Flash设置)”为下图所示的参数:
注:在这种分区设置下,Kernel将直接以NAND Flash本地存储作为根文件系统挂载使用。这在进行一些开发时会比较方便操作,例如手动移植某些库和工具等。在矿卡原本的策略中,则采用initramfs启动Kernel、再挂载JFFS2分区的办法,这样应用程序和用于启动的根文件系统分开存放,便于刷机和升级。
-
保证“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 ZC702
Board: 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 24
In: 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 0xa00000
10485760 bytes read: OK
## Loading kernel from FIT Image at 08000000 ...
Using 'conf@system-top.dtb' configuration
Verifying Hash Integrity ... OK
Trying 'kernel@1' kernel subimage
Description: Linux kernel
Type: Kernel Image
Compression: gzip compressed
Data Start: 0x08000104
Data Size: 3939629 Bytes = 3.8 MiB
Architecture: ARM
OS: Linux
Load Address: 0x00008000
Entry Point: 0x00008000
Hash algo: sha1
Hash value: f9e71358f94cea061eaddd3024249059e938f212
Verifying Hash Integrity ... sha1+ OK
## Loading fdt from FIT Image at 08000000 ...
Using 'conf@system-top.dtb' configuration
Trying 'fdt@system-top.dtb' fdt subimage
Description: Flattened Device Tree blob
Type: Flat Device Tree
Compression: uncompressed
Data Start: 0x083c1f34
Data Size: 13773 Bytes = 13.5 KiB
Architecture: ARM
Hash algo: sha1
Hash value: 7cd79570747a523ec6a949210e2d8515d2c8629c
Verifying Hash Integrity ... sha1+ OK
Booting using the fdt blob at 0x83c1f34
ZYNQ GEM: e000b000, phyaddr ffffffff, interface gmii
mdio_register: non unique device name 'eth0'
Uncompressing Kernel Image ... OK
Loading Device Tree to 07ff9000, end 07fff5cc ... OK
Starting kernel ...
Timer summary in microseconds (29 records):
Mark Elapsed Stage
0 0 reset
98,721 98,721 board_init_r
217,304 118,583 id=64
231,846 14,542 main_loop
4,289,965 4,058,119 bootm_start
4,289,969 4 id=1
4,295,542 5,573 id=100
4,295,551 9 id=101
4,295,552 1 id=102
4,304,778 9,226 id=110
4,480,864 176,086 id=105
4,480,878 14 id=106
4,480,891 13 id=107
4,480,895 4 id=108
4,480,895 0 id=109
4,486,157 5,262 id=90
4,486,163 6 id=91
4,486,163 0 id=92
4,535,275 49,112 id=95
4,535,295 20 id=96
4,535,301 6 id=97
4,535,304 3 id=98
4,535,311 7 id=99
4,936,604 401,293 id=7
4,944,290 7,686 id=15
4,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_f
Accumulated time:
0 dm_f
1,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: OK
PetaLinux 2018.3 EBAZ4205_linux_NAND /dev/ttyPS0
EBAZ4205_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.0
inet6 addr: fe80::20a:35ff:fe00:1e53%lo/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:433 errors:0 dropped:0 overruns:0 frame:0
TX packets:252 errors:0 dropped:0 overruns:0 carrier:0
collisions: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.0
inet6 addr: ::1%1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions: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中断,此处不表。
至此,矿卡按键部分描述完毕。
参考资料
本文编写过程中参考的所有资料均列在下方。本文若与任何列表之外的文章、博客、视频、教程等描述相同或相似则纯属巧合。
另在此处再次对以下资料的作者们表示感谢。
- SEMC—扩展外部NAND flash
- Petalinux 2018.2 nand : no NAND device found 解决办法_CSDN
- jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x000a0000: 0x3030 instead 问题分析_CSDN
- nand有很多坏块的问题_CSDN
- Xilinx Zynq pl353-nand使用_CSDN
- 在nand flash上实现JFFS2根文件文件系统_CSDN
- jffs2 启动的常见的问题_CSDN
- Memory Technology Device (MTD) Subsystem for Linux.
- Mount JFFS2 FS in OpenWRT
- jffs2_scan_eraseblock(): Magic bitmask解决
- While trying to open /dev/mtd2 for read/write access: Permission denied
- ZYNQ开机挂载SPI FLASH中的jffs2文件系统_CSDN
- 嵌入式linux-Jffs2根文件系统jffs2_scan_eraseblock()错误_CSDN
- Linux系统中/dev/mtd与/dev/mtdblock的区别
- mtd与mtdblock节点的对应问题_CSDN
- jffs2 cleanmarker
- 适用于新手的 Linux Flash 讲解:Linux如何与Flash一起使用?_CSDN
- Linux flash 操作
- AM3358: NAND flash erase error
- Zynq芯片NAND启动方式支持
- Linux下GPIO的使用_简书
- Linux无需开发底层驱动,从应用层获取GPIO中断_CSDN
————2020-11-18 @燕卫博————
《从零开始的ZYNQ学习(基于矿卡EBAZ4205)》系列到此结束,PS-PL通信和协作方式不在“从零”系列。