页次: 1
@zhang235hai
看一下defconfig文件中是否有CONFIG_SPL=y
@zhang235hai
已在主页更新U-Boot部分,内核和根文件系统待更,根文件系统已经换成了UBIFS,目前运行良好。
U-Boot移植的修改
在最新的U-Boot2022.04中已经包含了U-Boot阶段的SPINAND的驱动,但在SPL和ENV阶段只有SPINOR的驱动,这里只修改了SPL阶段,ENV阶段的bootargs可以放在内核设备树里传入。
下载U-Boot源码,添加spl_spinand_sunxi.c到arch/arm/mach-sunxi下,spl_spinand_sunxi.c由https://whycan.com/t_3123.html修改。
修改arch/arm/mach-sunxi/Kconfig,添加
config SPL_SPINAND_SUNXI
bool "Support for SPI Nand Flash on Allwinner SoCs in SPL"
depends on MACH_SUN8I_V3S
help
Enable support for SPI Nand Flash. This option allows SPL to read from
sunxi SPI Nand Flash. It uses the same method as the boot ROM, so does
not need any extra configuration.
修改arch/arm/mach-sunxi/Makefile,添加obj-$(CONFIG_SPL_SPINAND_SUNXI) += spl_spinand_sunxi.o
修改arch/arm/boot/dts/sun8i-v3s-licheepi-zero.dts,添加
&spi0 {
pinctrl-0 = <&spi0_pins>;
pinctrl-names = "default";
status = "okay";
flash@0 {
#address-cells = <1>;
#size-cells = <1>;
compatible = "spi-nand";
reg = <0>;
spi-max-frequency = <50000000>;
};
};
修改include/configs/sun8i.h,添加
#define CONFIG_BOOTCOMMAND "mtd read spi-nand0 0x41800000 0x100000 0x20000; " \
"mtd read spi-nand0 0x41000000 0x120000 0x500000; " \
"bootz 0x41000000 - 0x41800000"
#define CONFIG_BOOTARGS "console=ttyS0,115200 earlyprintk panic=5 rootwait " \
"mtdparts=spi0.0:1M(uboot)ro,128k(dtb)ro,5M(kernel)ro,-(rootfs) ubi.mtd=3 root=ubi0:rootfs rw rootfstype=ubifs"
注: SPINAND使用的是MX35LF1GE4AB,一页2K,故设备树的读取要读取至少1页故修改成0x20000,linux5.2内核编译后大小已经超过了4M,故修改为0x500000。CONFIG_BOOTARGS实际上是不起作用的,由于ENV处没有spinand驱动(懒得写)且可以在内核设备树传入启动参数,这里预留为后续使用。
执行make ARCH=arm LicheePi_Zero_defconfig,再执行make ARCH=arm menuconfig,修改
ARM architecture勾选Support for SPI Nand Flash on Allwinner SoCs in SPL
Boot options取消掉Enable boot arguments
Device Drivers->MTD Support勾选Enable MTD layer Enable Driver Model for MTD drivers SPI NAND device Support
Command line interface->Device access commands勾选mtd
Environment取消勾选Environment is in SPI flash
保存,make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j8编译生成u-boot-sunxi-with-spl.bin,但是这个镜像不能直接使用。
使用spl_split_exp 2048 u-boot-sunxi-with-spl.bin生成u-boot-sunxi-with-spl.bin_split_exp,(需要将spl段按每页1k写入,在spl_spinand_sunxi.c已经将uboot payload offset扩大了一倍) 此镜像可用于烧录。
主线Linux5.2内核的移植
使用LicheePi Zero的Linux5.2 github修改。
修改设备树文件arch/arm/boot/dts/sun8i-v3s-licheepi-zero.dts
chosen结点:
chosen {
stdout-path = "serial0:115200n8";
bootargs = "console=ttyS0,115200 earlyprintk panic=5 rootwait mtdparts=spi0.0:1M(uboot)ro,128k(dtb)ro,5M(kernel)ro,-(rootfs) ubi.mtd=3 root=ubi0:rootfs rw rootfstype=ubifs";
};
增加spi0结点:
&spi0 {
status ="okay";
spi_nand: spi_nand@0 {
#address-cells = <1>;
#size-cells = <1>;
compatible = "spi-nand";
reg = <0>;
spi-max-frequency = <50000000>;
partition@0 {
label = "uboot";
reg = <0x0 0x100000>;
read-only;
};
partition@100000 {
label = "dtb";
reg = <0x100000 0x20000>;
read-only;
};
partition@120000 {
label = "kernel";
reg = <0x120000 0x500000>;
read-only;
};
partition@620000 {
label = "rootfs";
reg = <0x620000 0x79E0000>;
};
};
};
运行make ARCH=arm licheepi_zero_defconfig,在运行make ARCH=arm menuconfig,修改
Device Drivers->Memory Technology Device (MTD) support勾选SPI NAND device Support Enable UBI - Unsorted block images
File Systems->Miscellaneous filesystems勾选UBIFS file system support
保存,make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j8生产zImage和dtb
UBIFS根文件系统的制作
可以自己使用buildroot生成,这里提供一个LicheePi Zero使用的一个mini的文件系统,解压放置于脚本同级目录,先运行make_ubifs.sh再运行make_ubiimg.sh生成ubi.img。
打包并烧录
将u-boot-sunxi-with-spl.bin_split_exp、sun8i-v3s-licheepi-zero.dtb、zImage、ubi.img和make_flashimg_ubifs.sh放在同一目录下,运行make_flashimg_ubifs.sh生成flashimg.bin。
连接V3s并进入fel模式,下载编译xfel工具,使用xfel spinand write 0 flashimg.bin将镜像烧录至spinand。完成后重启即可。
用到的文件
V3s SPINAND.zip
附:启动日志
U-Boot SPL 2022.04 (May 01 2022 - 12:30:18 +0800)
DRAM: 64 MiB
Trying to boot from sunxi SPI-NAND
sunxi SPI-NAND: Found Macronix MX35LF1GE4AB (c212c2)
sunxi SPI-NAND: Loading u-boot from 0x10000
sunxi SPI-NAND: u-boot hcrc OK!
U-Boot 2022.04 (May 01 2022 - 12:30:18 +0800) Allwinner Technology
CPU: Allwinner V3s (SUN8I 1681)
Model: Lichee Pi Zero
DRAM: 64 MiB
Core: 23 devices, 11 uclasses, devicetree: separate
WDT: Not starting watchdog@1c20ca0
MMC: mmc@1c0f000: 0
Loading Environment from FAT... Card did not respond to voltage select! : -110
In: serial@1c28000
Out: serial@1c28000
Err: serial@1c28000
Net: No ethernet found.
Hit any key to stop autoboot: 0
Reading 131072 byte(s) (64 page(s)) at offset 0x00100000
Reading 5242880 byte(s) (2560 page(s)) at offset 0x00120000
Kernel image @ 0x41000000 [ 0x000000 - 0x443c68 ]
## Flattened Device Tree blob at 41800000
Booting using the fdt blob at 0x41800000
Loading Device Tree to 42dfa000, end 42dffddf ... OK
Starting kernel ...
0.000000] Booting Linux on physical CPU 0x0
[ 0.000000] Linux version 5.2.0-licheepi-zero+ (root@ASUS) (gcc version 7.5.0 (Linaro GCC 7.5-2019.12)) #19 SMP Thu May 5 23:54:21 CST 2022
[ 0.000000] CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=10c5387d
[ 0.000000] CPU: div instructions available: patching division code
[ 0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
[ 0.000000] OF: fdt: Machine model: Lichee Pi Zero
[ 0.000000] Memory policy: Data cache writealloc
[ 0.000000] psci: probing for conduit method from DT.
[ 0.000000] psci: Using PSCI v0.1 Function IDs from DT
[ 0.000000] percpu: Embedded 16 pages/cpu s34508 r8192 d22836 u65536
[ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 16256
[ 0.000000] Kernel command line: console=ttyS0,115200 earlyprintk panic=5 rootwait mtdparts=spi0.0:1M(uboot)ro,128k(dtb)ro,5M(kernel)ro,-(rootfs) ubi.mtd=3 root=ubi0:rootfs rw rootfstype=ubifs
[ 0.000000] Dentry cache hash table entries: 8192 (order: 3, 32768 bytes, linear)
[ 0.000000] Inode-cache hash table entries: 4096 (order: 2, 16384 bytes, linear)
[ 0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
[ 0.000000] Memory: 54004K/65536K available (7168K kernel code, 308K rwdata, 1736K rodata, 1024K init, 257K bss, 11532K reserved, 0K cma-reserved, 0K highmem)
[ 0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[ 0.000000] rcu: Hierarchical RCU implementation.
[ 0.000000] rcu: RCU event tracing is enabled.
[ 0.000000] rcu: RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=1.
[ 0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 10 jiffies.
[ 0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=1
[ 0.000000] NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16
[ 0.000000] GIC: GICv2 detected, but range too small and irqchip.gicv2_force_probe not set
[ 0.000000] random: get_random_bytes called from start_kernel+0x2f8/0x484 with crng_init=0
[ 0.000000] arch_timer: cp15 timer(s) running at 24.00MHz (phys).
[ 0.000000] clocksource: arch_sys_counter: mask: 0xffffffffffffff max_cycles: 0x588fe9dc0, max_idle_ns: 440795202592 ns
[ 0.000006] sched_clock: 56 bits at 24MHz, resolution 41ns, wraps every 4398046511097ns
[ 0.000019] Switching to timer-based delay loop, resolution 41ns
[ 0.000198] clocksource: timer: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 79635851949 ns
[ 0.000432] Console: colour dummy device 80x30
[ 0.000488] Calibrating delay loop (skipped), value calculated using timer frequency.. 48.00 BogoMIPS (lpj=240000)
[ 0.000504] pid_max: default: 32768 minimum: 301
[ 0.000663] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
[ 0.000676] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
[ 0.001466] CPU: Testing write buffer coherency: ok
[ 0.001975] /cpus/cpu@0 missing clock-frequency property
[ 0.001999] CPU0: thread -1, cpu 0, socket 0, mpidr 80000000
[ 0.002799] Setting up static identity map for 0x40100000 - 0x40100060
[ 0.003013] rcu: Hierarchical SRCU implementation.
[ 0.003559] smp: Bringing up secondary CPUs ...
[ 0.003581] smp: Brought up 1 node, 1 CPU
[ 0.003591] SMP: Total of 1 processors activated (48.00 BogoMIPS).
[ 0.003597] CPU: All CPU(s) started in HYP mode.
[ 0.003601] CPU: Virtualization extensions available.
[ 0.004692] devtmpfs: initialized
[ 0.008070] VFP support v0.3: implementor 41 architecture 2 part 30 variant 7 rev 5
[ 0.008369] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[ 0.008400] futex hash table entries: 256 (order: 2, 16384 bytes, linear)
[ 0.008649] pinctrl core: initialized pinctrl subsystem
[ 0.009669] NET: Registered protocol family 16
[ 0.010329] DMA: preallocated 256 KiB pool for atomic coherent allocations
[ 0.011562] hw-breakpoint: found 5 (+1 reserved) breakpoint and 4 watchpoint registers.
[ 0.011580] hw-breakpoint: maximum watchpoint size is 8 bytes.
[ 0.039464] SCSI subsystem initialized
[ 0.039651] usbcore: registered new interface driver usbfs
[ 0.039705] usbcore: registered new interface driver hub
[ 0.039808] usbcore: registered new device driver usb
[ 0.040023] mc: Linux media interface: v0.10
[ 0.040080] videodev: Linux video capture interface: v2.00
[ 0.040458] Advanced Linux Sound Architecture Driver Initialized.
[ 0.042285] clocksource: Switched to clocksource arch_sys_counter
[ 0.053860] NET: Registered protocol family 2
[ 0.054694] tcp_listen_portaddr_hash hash table entries: 512 (order: 0, 6144 bytes, linear)
[ 0.054736] TCP established hash table entries: 1024 (order: 0, 4096 bytes, linear)
[ 0.054762] TCP bind hash table entries: 1024 (order: 1, 8192 bytes, linear)
[ 0.054784] TCP: Hash tables configured (established 1024 bind 1024)
[ 0.054919] UDP hash table entries: 256 (order: 1, 8192 bytes, linear)
[ 0.054971] UDP-Lite hash table entries: 256 (order: 1, 8192 bytes, linear)
[ 0.055268] NET: Registered protocol family 1
[ 0.057102] Initialise system trusted keyrings
[ 0.057469] workingset: timestamp_bits=30 max_order=14 bucket_order=0
[ 0.102646] Key type asymmetric registered
[ 0.102667] Asymmetric key parser 'x509' registered
[ 0.102770] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 250)
[ 0.102783] io scheduler mq-deadline registered
[ 0.102789] io scheduler kyber registered
[ 0.103783] sun4i-usb-phy 1c19400.phy: Couldn't request ID GPIO
[ 0.107458] sun8i-v3s-pinctrl 1c20800.pinctrl: initialized sunXi PIO driver
[ 0.176836] Serial: 8250/16550 driver, 8 ports, IRQ sharing disabled
[ 0.179181] sun8i-v3s-pinctrl 1c20800.pinctrl: 1c20800.pinctrl supply vcc-pb not found, using dummy regulator
[ 0.180279] printk: console [ttyS0] disabled
[ 0.200582] 1c28000.serial: ttyS0 at MMIO 0x1c28000 (irq = 33, base_baud = 1500000) is a U6_16550A
[ 0.737032] printk: console [ttyS0] enabled
[ 0.766932] sun8i-v3s-pinctrl 1c20800.pinctrl: 1c20800.pinctrl supply vcc-pc not found, using dummy regulator
[ 0.778370] spi-nand spi0.0: Macronix SPI NAND was found.
[ 0.783863] spi-nand spi0.0: 128 MiB, block size: 128 KiB, page size: 2048, OOB size: 64
[ 0.792727] 4 fixed-partitions partitions found on MTD device spi0.0
[ 0.799084] Creating 4 MTD partitions on "spi0.0":
[ 0.803965] 0x000000000000-0x000000100000 : "uboot"
[ 0.811399] 0x000000100000-0x000000120000 : "dtb"
[ 0.817316] 0x000000120000-0x000000620000 : "kernel"
[ 0.824031] random: fast init done
[ 0.834894] 0x000000620000-0x000008000000 : "rootfs"
[ 1.007031] random: crng init done
[ 1.037632] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[ 1.044238] ehci-platform: EHCI generic platform driver
[ 1.049764] ehci-platform 1c1a000.usb: EHCI Host Controller
[ 1.055456] ehci-platform 1c1a000.usb: new USB bus registered, assigned bus number 1
[ 1.063424] ehci-platform 1c1a000.usb: irq 25, io mem 0x01c1a000
[ 1.092299] ehci-platform 1c1a000.usb: USB 2.0 started, EHCI 1.00
[ 1.099495] hub 1-0:1.0: USB hub found
[ 1.103439] hub 1-0:1.0: 1 port detected
[ 1.108015] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
[ 1.114328] ohci-platform: OHCI generic platform driver
[ 1.119867] ohci-platform 1c1a400.usb: Generic Platform OHCI controller
[ 1.126608] ohci-platform 1c1a400.usb: new USB bus registered, assigned bus number 2
[ 1.134572] ohci-platform 1c1a400.usb: irq 26, io mem 0x01c1a400
[ 1.207324] hub 2-0:1.0: USB hub found
[ 1.211158] hub 2-0:1.0: 1 port detected
[ 1.218477] usbcore: registered new interface driver usb-storage
[ 1.226075] sun6i-rtc 1c20400.rtc: registered as rtc0
[ 1.231136] sun6i-rtc 1c20400.rtc: RTC enabled
[ 1.235846] i2c /dev entries driver
[ 1.240685] input: ns2009_ts as /devices/platform/soc/1c2ac00.i2c/i2c-0/0-0048/input/input0
[ 1.250329] sunxi-wdt 1c20ca0.watchdog: Watchdog enabled (timeout=16 sec, nowayout=0)
[ 1.259001] sun8i-v3s-pinctrl 1c20800.pinctrl: 1c20800.pinctrl supply vcc-pf not found, using dummy regulator
[ 1.294915] sunxi-mmc 1c0f000.mmc: initialized, max. request size: 16384 KB
[ 1.302474] sun8i-v3s-pinctrl 1c20800.pinctrl: 1c20800.pinctrl supply vcc-pg not found, using dummy regulator
[ 1.313816] usbcore: registered new interface driver usbhid
[ 1.319392] usbhid: USB HID core driver
[ 1.325898] Initializing XFRM netlink socket
[ 1.330210] NET: Registered protocol family 17
[ 1.335343] Registering SWP/SWPB emulation handler
[ 1.341267] Loading compiled-in X.509 certificates
[ 1.355330] usb_phy_generic usb_phy_generic.0.auto: usb_phy_generic.0.auto supply vcc not found, using dummy regulator
[ 1.366846] musb-hdrc musb-hdrc.1.auto: MUSB HDRC host driver
[ 1.372690] musb-hdrc musb-hdrc.1.auto: new USB bus registered, assigned bus number 3
[ 1.382050] hub 3-0:1.0: USB hub found
[ 1.386049] hub 3-0:1.0: 1 port detected
[ 1.391787] ubi0: attaching mtd3
[ 2.425271] ubi0: scanning is finished
[ 2.444176] ubi0: attached mtd3 (name "rootfs", size 121 MiB)
[ 2.449969] ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 126976 bytes
[ 2.456907] ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 2048
[ 2.463706] ubi0: VID header offset: 2048 (aligned 2048), data offset: 4096
[ 2.470658] ubi0: good PEBs: 973, bad PEBs: 2, corrupted PEBs: 0
[ 2.476670] ubi0: user volume: 1, internal volumes: 1, max. volumes count: 128
[ 2.483894] ubi0: max/mean erase counter: 2/1, WL threshold: 4096, image sequence number: 1911005616
[ 2.493024] ubi0: available PEBs: 0, total reserved PEBs: 973, PEBs reserved for bad PEB handling: 18
[ 2.502308] sun6i-rtc 1c20400.rtc: setting system clock to 1970-01-01T00:01:05 UTC (65)
[ 2.510551] vcc3v0: disabling
[ 2.513581] vcc5v0: disabling
[ 2.516550] ALSA device list:
[ 2.519513] No soundcards found.
[ 2.523588] ubi0: background thread "ubi_bgt0d" started, PID 94
[ 2.531835] UBIFS (ubi0:0): Mounting in unauthenticated mode
[ 2.540094] UBIFS (ubi0:0): background thread "ubifs_bgt0_0" started, PID 95
[ 2.612482] UBIFS (ubi0:0): recovery needed
[ 2.796578] UBIFS (ubi0:0): recovery completed
[ 2.801165] UBIFS (ubi0:0): UBIFS: mounted UBI device 0, volume 0, name "rootfs"
[ 2.808620] UBIFS (ubi0:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 2.818542] UBIFS (ubi0:0): FS size: 100184064 bytes (95 MiB, 789 LEBs), journal size 9023488 bytes (8 MiB, 72 LEBs)
[ 2.829060] UBIFS (ubi0:0): reserved for root: 0 bytes (0 KiB)
[ 2.834899] UBIFS (ubi0:0): media format: w4/r0 (latest is w5/r0), UUID ED8B6288-11AB-406A-A3DB-003DE49155BF, small LPT model
[ 2.848255] VFS: Mounted root (ubifs filesystem) on device 0:12.
[ 2.858269] devtmpfs: mounted
[ 2.862482] Freeing unused kernel memory: 1024K
[ 2.867190] Run /sbin/init as init process
Starting logging: OK
Starting mdev...
/etc/init.d/S10mdev: line 21: can't create /proc/sys/kernel/hotplug: nonexistent directory
modprobe: can't change directory to '/lib/modules': No such file or directory
Initializing random number generator... done.
Starting network: OK
Welcome to Lichee Pi
Lichee login:
有可能把spi-nand启动这部分,移植到主线uboot+主线linux上么?
平台:v3s
系统:主线uboot+主线linux
我已经搞定了 Uboot-2022.04+Linux5.2 但是根文件系统用的jffs2 重启两次就搞坏了 还在找原因。
页次: 1