全志F1C100S/F1C200S学习笔记(11)——spi-flash 启动全流程适配烧录及踩坑指南

文章目录

  • 一、分区规划:
  • 二、uboot 配置
    • 1、bootcmd 和 bootarg 参数修改
      • 方法一:
      • 方法二:
      • 参数解析:
    • 2、dts 修改:
    • 3、添加FLASH支持
  • 三、kernel 配置
    • 1、配置文件系统格式支持
    • 2、修改对应spi-flash支持
  • 四、buildroot 配置
    • 1、配置
    • 2、jffs2格式 rootfs 生成
  • 五、二进制bin 打包
  • 六、烧录
    • 1、RAM运行
    • 2、烧录单独镜像
    • 3、烧录完整镜像
  • 七、问题:
    • 问题一:
    • 问题二:
    • 问题三:
    • 问题四:
    • 问题五:
  • 附:
    • 1、仓库
    • 2、关于启动顺序
    • 3、支持FLASH型号
    • 4、启动LOG
    • 5、参考资料

  • 通过参考荔枝派nano官方和论坛大佬的帖子,总结了烧录 spi-flash 启动的方法。
  • 通过搜寻资料,把其中有错误或者做了多余的操作的步骤做了修正,以免大家再次踩坑,耗费青春。
  • 以下包括 uboot、kernel、buildroot 和 烧录的详细步骤和需要注意的问题,尽量精简方法,以期容易上手和理解。
  • 各种配置项也做了详细注释,要知其然,也知其所以然。
  • 最理想的状态应该是是:有的坑,踩的人多了,也便没有了坑。

一、分区规划:

分区序号 分区大小 分区作用 地址空间及分区名
mtd0 1MB (0x100000) spl+uboot 0x0000000-0x0100000 : “uboot”
mtd1 64KB (0x10000) dtb文件 0x0100000-0x0110000 : “dtb”
mtd2 4MB (0x400000) linux内核 0x0110000-0x0510000 : “kernel”
mtd3 剩余 (0xAF0000) 根文件系统 0x0510000-0x1000000 : “rootfs”

二、uboot 配置

这里只写使用spi-flash需要做的修改,详细配置参考:全志F1C100S/F1C200S学习笔记(3)——u-boot编译与烧录

1、bootcmd 和 bootarg 参数修改

方法一:

这种方法只需要修改配置就行,不需要修改源码和设备树:

git clone https://gitee.com/LicheePiNano/u-boot.git -b nano-v2018.01&&cd u-boot
make licheepi_nano_spiflash_defconfig
make menuconfig
# 对应 `CONFIG_BOOTCMD` 的宏定义
# 选中 然后 run distro_bootcmd 修改为以下参数
[*] Enable a default value for bootcmd
	(sf probe 0 50000000; sf read 0x80C00000 0x100000 0x4000; sf read 0x80008000 0x110000 0x400000; bootz 0x80008000 - 0x80C00000) bootcmd value

# 对应 `CONFIG_BOOTARGS` 的宏定义
[*] Enable boot arguments
	(console=ttyS0,115200 earlyprintk panic=5 rootwait; mtdparts=spi32766.0:1M(uboot)ro,64k(dtb)ro,4M(kernel)ro,-(rootfs) root=/dev/mtdblock3 rw rootfstype=jffs2)    Boot arguments

U-Boot中Distro_bootcmd的实现分析


方法二:

参考:spi-flash 启动适配、SPI Flash 系统编译
(1)取消勾选 [ ] Enable a default value for bootcmd
(2)修改 uboot 源码目录下 ./include/configs/suniv.h:

# 在 `#include ` 的前面添加:
# 重要!!!官方文档这里有错误,不是 `"sf probe 0:50000000; "` ,应该是 `"sf probe 0 50000000; "`

#ifndef CONFIG_BOOTCOMMAND
#define CONFIG_BOOTCOMMAND   "sf probe 0 50000000; "  \
                             "sf read 0x80C00000 0x100000 0x4000; "  \
                             "sf read 0x80008000 0x110000 0x400000; " \
                             "bootz 0x80008000 - 0x80C00000"
#endif

#ifndef CONFIG_BOOTARGS
#define CONFIG_BOOTARGS      "console=ttyS0,115200 panic=5 rootwait" \
                             "mtdparts=spi32766.0:1M(uboot)ro,64k(dtb)ro,4M(kernel)ro,-(rootfs) root=/dev/mtdblock3 rw rootfstype=jffs2"
#endif

注:

  • 重要!!!官方文档这里有错误,不是 "sf probe 0:50000000; " ,应该是 "sf probe 0 50000000; "
  • root=/dev/mtdblock3 也可以用 root=31:03 表示。
  • mtdparts=spi32766.0:1M(uboot)ro,64k(dtb)ro,4M(kernel)ro,-(rootfs) 是FLASH分区,分区指定也可以在dts中声明。即修改内核源码目录下的 ./arch/arm/boot/dts/suniv-f1c100s-licheepi-nano.dts。修改方式在后面。

参数解析:

环境命令解析:

# 初始化Flash设备(CS拉低)
sf probe 0 50000000;
# 从flash0x100000(1MB)位置读取dtb放到内存0x41800000偏移处。
sf read 0x41800000 0x100000 0x10000; 
# 从flash0x110000(1MB+64KB)位置读取dtb放到内存0x41000000偏移处。
sf read 0x41000000 0x110000 0x400000; 
# 启动内核
bootz 0x41000000 (内核地址)- 0x41800000(dtb地址) 

启动参数解析:

# 在串口0上输出信息,如果要用串口1做控制台就改为 console=ttyS1
# 由于在kernel刚启动的过程中,还没有为串口等设备等注册console(在device probe阶段实现),此时无法通过正常的console来输出log。
# early console机制,用于实现为设备注册console之前的早期log的输出。
# earlyprintk 是基于 early console的基础上实现
console=ttyS0,115200 earlyprintk panic=5 rootwait

# spi32766.0是设备名,后面是分区大小,名字,读写属性。
# 根文件系统是mtd3;jffs2格式  root=31:03 等同于 /dev/mtdblock3 指的是mtd设备第三分区
mtdparts=spi32766.0:1M(uboot)ro,64k(dtb)ro,4M(kernel)ro,-(rootfs) root=31:03 rw rootfstype=jffs2 

2、dts 修改:

  • 前面已经设置了 mtdparts=spi32766.0:1M(uboot)ro,64k(dtb)ro,4M(kernel)ro,-(rootfs) ,通过bootargs传递给内核进行解析分区信息了,这个就不需要再修改了。
  • 修改内核源码目录下的 ./arch/arm/boot/dts/suniv-f1c100s-licheepi-nano.dts,此处在dts中为mtd设备预先划分好了分区内容,内核将会自动解析。
&spi0 {
    pinctrl-names = "default";
    pinctrl-0 = <&spi0_pins_a>;
    status = "okay";
    spi-max-frequency = <50000000>;
    flash: w25q128@0 {
        #address-cells = <1>;
        #size-cells = <1>;
        compatible = "winbond,w25q128", "jedec,spi-nor";
        reg = <0>;
        spi-max-frequency = <50000000>;
        partitions {
            compatible = "fixed-partitions";
            #address-cells = <1>;
            #size-cells = <1>;

            partition@0 {
                label = "u-boot";
                reg = <0x000000 0x100000>;
                read-only;
            };

            partition@100000 {
                label = "dtb";
                reg = <0x100000 0x10000>;
                read-only;
            };

            partition@110000 {
                label = "kernel";
                reg = <0x110000 0x400000>;
                read-only;
            };

            partition@510000 {
                label = "rootfs";
                reg = <0x510000 0xAF0000>;
            };
        };
    };
};

3、添加FLASH支持

由于我这开发板的FLASH没在支持列表(xt25f128b),所以需要自己添加,不然的话启动后报错 SF: unrecognized JEDEC id bytes: 0b, 40, 18
修改步骤:
(1)查询FLASH信息:

# 显示spiflash的信息 
$ sudo sunxi-fel spiflash-info
Manufacturer: Unknown (0Bh), model: 40h, size: 16777216 bytes.

(2)添加flash支持列表:
修改 u-boot/drivers/mtd/spi/spi_flash_ids.c,根据上面查询的信息增加 xt25f128b

const struct spi_flash_info spi_flash_ids[] = {
    ...
	{"w25q128fw",	   INFO(0xef6018, 0x0,	64 * 1024,   256, RD_FULL | WR_QPP | SECT_4K) },
	{"xt25f128b",	   INFO(0x0b4018, 0x0,	64 * 1024,   256, RD_FULL | WR_QPP | SECT_4K) },
    ...
};

(3)修改设备树:
修改 u-boot/arch/arm/dts/suniv-f1c100s-licheepi-nano.dts:(好像不修改也没事)

&spi0 {
	...
	flash@0 {
        ...
		compatible = "winbond,xt25f128b", "jedec,spi-nor";
		...
	};
};

三、kernel 配置

这里只写使用spi-flash需要做的修改,详细配置参考:
全志F1C100S/F1C200S学习笔记(5)——主线Linux编译
全志F1C100S/F1C200S学习笔记(6)——设备树添加节点

1、配置文件系统格式支持

# 以下适配了 800*480屏幕 和 xt25f128bflash
git clone https://gitee.com/LicheePiNano/Linux.git && cd linux/
wget http://dl.sipeed.com/LICHEE/Nano/SDK/config
cp config .config
make menuconfig
File systems  --->
	[*] Miscellaneous filesystems  --->
		<*>   Journalling Flash File System v2 (JFFS2) support	# 打开jffs2的文件系统支持
		(0)     JFFS2 debugging verbosity (0 = quiet, 2 = noisy)
		[*]     JFFS2 write-buffering support
		[ ]     JFFS2 summary support
		[ ]     JFFS2 XATTR support
		[ ]     Advanced compression options for JFFS2
Device Drivers  --->
	<*> Memory Technology Device (MTD) support  --->
		<*>   Command line partition table parsing	# 勾选,用来解析uboot传递过来的flash分区信息。(如果 bootarg 是用的我的方法一就需要勾选)
		<*>   Caching block device access to MTD devices	# 勾选,读写块设备用户模块
		<*>   SPI-NOR device support  --->
			[ ]   Use small 4096 B erase sectors	# 取消勾选,否则jffs2文件系统会报错

注:

  • lichee官方的u-boot 中 kernel cmdline 使用jffs2格式的 mtdblock3 作为rootfs,但config中没有打开mtdblock设备接口。所以需要勾选 Caching block device access to MTD devices
  • mkfs.jffs2 使用的最小擦除尺寸是 8KB,而spi flash的扇区大小是 4KB,所以按照扇区擦除的话,会无法使用,所以必须使用块擦除。即勾选 Use small 4096 B erase sectors
  • 如果不勾选 Caching block device access to MTD devices,会卡在 Waiting for root device /dev/mtdblock3

2、修改对应spi-flash支持

修改文件 linux/drivers/mtd/spi-nor/spi-nor.c
我的是 xt25f128b 就直接在下面添加了:

{ "xt25f128b", INFO(0x0b4018, 0, 64 * 1024, 256, SECT_4K) },

注:对于开机后报大量 JFFS2 erase size 错误,官方是采用修改内核 SECT_4K 改为 0,即下面的方式。实际可以使用上一步的方法,取消 Use small 4096 B erase sectors 的勾选就可以,不用修改内核。参考:lichee nano官方linux config文件踩坑与填坑
w25q128 :

{ "w25q128", INFO(0xef4018, 0, 64 * 1024, 256, SECT_4K) },
# 修改为 (不使用sector,使用块擦除):
{ "w25q128", INFO(0xef4018, 0, 64 * 1024, 256, 0) },

四、buildroot 配置

参考:全志F1C100S/F1C200S学习笔记(7)——根文件系统编译

1、配置

这里不要用之前使用TF卡的配置,那个文件系统有96M,放不进flash,重新获取源码编译:
获取源码:

git clone https://gitee.com/LicheePiNano/buildroot-2017.08.git
cd buildroot-2017.08/
# 图形界面配置
make menuconfig

配置:(根据以下的配置,生成的 rootfs 只有 2.5M

Target options  --->
	Target Architecture (ARM (little endian))  --->
	Target Architecture Variant (arm926t)  --->
Toolchain  ---> 
	C library (musl)  --->
System configuration  --->
	(gateway) System hostname	# 主机名,随便改
	(Welcome to gateway) System banner	# 欢迎语,随便改
	[*] Enable root login with password (NEW)
		(123456) Root password	# 登录密码,随便改
	[*] remount root filesystem read-write during boot (NEW)	# 重新挂载根文件系统到可读写
	[*] Install timezone info	# 安装时区信息,可选
		(asia) timezone list
		(Asia/Shanghai) default local time	
Target packages  --->
	System tools  --->
	[*] util-linux  --->
		[*]   mount/umount	# 访问其它文件系统中的资源,如果要用overlayfs,那就要用这个挂载

2、jffs2格式 rootfs 生成

方法一:(自动生成)
生成 rootfs.jffs2 格式的rootfs,打开后会自动下载 mtd-utils 软件包。

Filesystem images  --->
	[*] jffs2 root filesystem
			Flash Type (Parallel flash with 64 kB erase size)  ---> # 具有64 kB擦除大小的并行闪存 -e 参数
		[*]   Do not use Cleanmarker	# 用于标记一个块是_完整地_被擦除了。 -n 参数 Do not use cleanmarkers if using NAND flash or Dataflash where the pagesize is not a power of 
		[*]   Pad output
			(0xAF0000) Pad output size (0x0 = to end of EB) 	# 指定 jffs2 分区总空间 -p(--pad) 参数
		Endianess (little-endian)  --->
		[ ]   Produce a summarized JFFS2 image (NEW)	# 生成镜像的
		[*]   Select custom virtual memory page size
		(0x100) Virtual memory page size	# 虚拟内存页大小	-s 参数

方法二:(手动生成)
Flash支持 jffs2 文件系统格式,所以需要使用此该rootfs制作jffs2文件系统镜像。

# 下载jffs2文件系统制作工具
sudo apt-get install mtd-utils

# 解压
# -C 当前目录的绝对目录
mkdir rootfs && sudo tar -xvf rootfs.tar -C ./rootfs

# 生成 rootfs.jffs2
# -r :指定要做成image的目录名
# -o : 指定输出image的文件名
# -s :页大小 0x100 256 字节
# -e :块大小 0x10000 64k
# -p :或--pad 参数指定 jffs2 分区总空间
# 由此计算得到 0x1000000(16M)-0x10000(64K)-0x100000(1M)-0x400000(4M)=0xAF0000
# -n 如果挂载后会出现类似:CLEANMARKER node found at0x0042c000 has totlen 0xc != normal 0x0  的警告,则加上-n 就会消失。
# jffs2.img 是生成的文件系统镜像
sudo mkfs.jffs2 -s 0x100 -e 0x10000 -p 0xAF0000 -r rootfs -o rootfs.jffs2 -n

# 为根文件系统制作jffs2镜像包
sudo mkfs.jffs2 -s 0x100 -e 0x10000 -p 0xAF0000 -d rootfs/ -o jffs2.img
# 或者
sudo mkfs.jffs2 -s 0x100 -e 0x10000 --pad=0xAF0000 -d rootfs/ -o jffs2.img

五、二进制bin 打包

Nano_SDK
nano_flash_dd.sh

脚本:
以16M 大小flash镜像打包脚本为例:
nano_flash_dd.sh

#!/bin/sh
UBOOT_FILE=./u-boot/u-boot-sunxi-with-spl.bin
DTB_FILE=./linux/arch/arm/boot/dts/suniv-f1c100s-licheepi-nano.dtb
KERNEL_FILE=./linux/arch/arm/boot/zImage
MOD_FILE=./linux/out/lib/modules/4.15.0-rc8-licheepi-nano+
ROOTFS_FILE=./buildroot-2017.08/output/images/rootfs.tar

dd if=/dev/zero of=flashimg.bin bs=1M count=16 &&\
dd if=$UBOOT_FILE of=flashimg.bin bs=1K conv=notrunc &&\
dd if=$DTB_FILE of=flashimg.bin bs=1K seek=1024 conv=notrunc &&\
dd if=$KERNEL_FILE of=flashimg.bin bs=1K seek=1088 conv=notrunc &&\
mkdir rootfs
tar -xvf $ROOTFS_FILE -C ./rootfs &&\
cp -r $MOD_FILE rootfs/lib/modules/ &&\

# 为根文件系统制作jffs2镜像包
# -r :指定要做成image的目录名
# -o : 指定输出image的文件名
# -s :页大小 0x100 256 字节
# -e :块大小 0x10000 64k
# -p :或--pad 参数指定 jffs2 分区总空间
# 由此计算得到 0x1000000(16M)-0x10000(64K)-0x100000(1M)-0x400000(4M)=0xAF0000
# -n 如果挂载后会出现类似:CLEANMARKER node found at0x0042c000 has totlen 0xc != normal 0x0  的警告,则加上-n 就会消失。
mkfs.jffs2 -s 0x100 -e 0x10000 --pad=0xAF0000 -d rootfs/ -o jffs2.img &&\
dd if=jffs2.img of=flashimg.bin bs=1K seek=5184 conv=notrunc &&\
rm -rf rootfs &&\
rm jffs2.img

以上脚本通过对一个生成的16M空bin文件填充 uboot、dtb、kernel、rootfs 生成 16M 镜像,如需修改,请注意各个文件的大小,修改成对应地址(注意对齐)。

# 下载jffs2文件系统制作工具
sudo apt-get install mtd-utils
# 给脚本权限
chmod 777 nano_flash_dd.sh
# 加 sudo,不然会报错 tar: 由于前次错误,将以上次的错误状态退出
sudo ./nano_flash_dd.sh

六、烧录

  • 短接 FLASH CS 引脚,即FLASH 的 1、4 脚,进入 FEL 模式。
  • 在启动到内核前,回车进入uboot,执行 sf probe 0;sf erase 0 0x100000;reset 即可重新进入fel模式。

1、RAM运行

如果要先测试修改的固件有没有问题,可以现在RAM运行:

# 烧录到RAM中去执行,以 uboot file-with-spl形式进行(单次运行,测试时个人推荐)
# -p 显示进度条
sudo sunxi-fel -p uboot u-boot-sunxi-with-spl.bin

# 烧录到RAM试运行
sudo sunxi-fel -p uboot u-boot-sunxi-with-spl.bin write 0x80000000 zImage write 0x80700000 suniv-f1c100s-licheepi-nano.dtb

2、烧录单独镜像

sudo sunxi-fel -p spiflash-write 0 ./u-boot/u-boot-sunxi-with-spl.bin   
sudo sunxi-fel -p spiflash-write 0x0100000 ./linux/arch/arm/boot/dts/suniv-f1c100s-licheepi-nano.dtb
sudo sunxi-fel -p spiflash-write 0x0110000 ./linux/arch/arm/boot/zImage 
sudo sunxi-fel -p spiflash-write 0x0510000 ./buildroot-2017.08/output/images/rootfs.jffs2

3、烧录完整镜像

用之前打包的完整镜像烧录:

sudo sunxi-fel -p spiflash-write 0 flashimg.bin

烧录的时候会显示进度:

$ sudo sunxi-fel -p spiflash-write 0 u-boot-sunxi-with-spl.bin
100% [================================================]  1008 kB,  135.2 kB/s 

或请参考镜像包中的 write_flash.sh 烧录脚本;
启动后使用 账号:root 密码:licheepi 登录


七、问题:

问题一:

$ sudo sunxi-fel ver
Warning: no 'soc_sram_info' data for your SoC (id=1663)
AWUSBFEX soc=00001663(unknown) 00000001 ver=0001 44 08 scratchpad=00007e00 00000000 00000000

sunxi-fel -l
libusb_open() ERROR -3: Access denied (insufficient permissions)

$ sudo sunxi-fel -l
Warning: no 'soc_sram_info' data for your SoC (id=1663)
USB device 003:008   Allwinner 0x1663  

原因:
sunxi-tools 分支不对,用 f1c100s-spiflash 分支

# 切换到 f1c100s-spiflash
git clone https://github.com/Icenowy/sunxi-tools.git -b f1c100s-spiflash
或者
git checkout f1c100s-spiflash
# 编译安装
make && sudo make install

在这里插入图片描述


问题二:

报错:uboot移植nor-flash

U-Boot 2018.01-05679-g013ca457fd-dirty (Dec 12 2021 - 17:21:16 +0800) Allwinner Technology

CPU:   Allwinner F Series (SUNIV)
Model: Lichee Pi Nano
DRAM:  32 MiB
MMC:   SUNXI SD/MMC: 0
SF: unrecognized JEDEC id bytes: 0b, 40, 18
*** Warning - spi_flash_probe_bus_cs() failed, using default environment

Setting up a 480x272 lcd console (overscan 0x0)
In:    serial@1c25000
Out:   serial@1c25000
Err:   serial@1c25000
Net:   No ethernet found.
starting USB...
No controllers found
Hit any key to stop autoboot:  0 
spi_flash@0:50000000: failed to activate chip-select 50000000
SF: error -2 reading JEDEC ID
Failed to initialize SPI flash at 0:50000000 (error -2)
No SPI flash selected. Please run `sf probe'
No SPI flash selected. Please run `sf probe'

解决:
参考上面 配置FLASH型号 章节。

启动后注册成功:

U-Boot 2018.01-05679-g013ca457fd-dirty (Dec 12 2021 - 17:34:10 +0800) Allwinner Technology

CPU:   Allwinner F Series (SUNIV)
Model: Lichee Pi Nano
DRAM:  32 MiB
MMC:   SUNXI SD/MMC: 0
SF: Detected xt25f128b with page size 256 Bytes, erase size 4 KiB, total 16 MiB
*** Warning - bad CRC, using default environment

会有个警告信息,这个没有影响。
我按照 :解决 WARNING - BAD CRC, USING DEFAULT ENVIRONMENT警告 这个方法解决。

=> env default -a
=> saveenv 

结果返回烧录uboot都无法正常,只好把FLASH擦除或者写入一个 16M 的空文件,才把这个环境清除。


问题三:

上面成功后还是有 Failed to initialize SPI flash at 0:50000000 (error -2) 这个错误:

U-Boot 2018.01-05679-g013ca457fd-dirty (Dec 12 2021 - 17:34:10 +0800) Allwinner Technology

CPU:   Allwinner F Series (SUNIV)
Model: Lichee Pi Nano
DRAM:  32 MiB
MMC:   SUNXI SD/MMC: 0
SF: Detected xt25f128b with page size 256 Bytes, erase size 4 KiB, total 16 MiB
Setting up a 480x272 lcd console (overscan 0x0)
In:    serial@1c25000
Out:   serial@1c25000
Err:   serial@1c25000
Net:   No ethernet found.
starting USB...
No controllers found
Hit any key to stop autoboot:  0 
spi_flash@0:50000000: failed to activate chip-select 50000000
SF: error -2 reading JEDEC ID
Failed to initialize SPI flash at 0:50000000 (error -2)
No SPI flash selected. Please run `sf probe'
No SPI flash selected. Please run `sf probe'

解决:
参考上面的 bootcmd 和 bootarg 参数修改 章节配置就可以了。
吐槽 spi-flash 启动适配 这个官方文档的错误,这个冒号不要:
全志F1C100S/F1C200S学习笔记(11)——spi-flash 启动全流程适配烧录及踩坑指南_第1张图片
参考:
荔枝派Nano F1C100S 烧写进去bin后启动log:No SPI flash selected. Please run `sf
官方文档 bootcmd 错误


问题四:

内核无法找到 mtdblock3

[    1.476051] VFS: Cannot open root device "mtdblock3" or unknown-block(31,3): error -19
[    1.484131] Please append a correct "root=" boot option; here are the available partitions:
[    1.492542] 1f00            1024 mtdblock0 
[    1.492554]  (driver?)
[    1.499197] 1f01              64 mtdblock1 
[    1.499208]  (driver?)
[    1.505747] 1f02            4096 mtdblock2 
[    1.505753]  (driver?)
[    1.512349] 1f03           11200 mtdblock3 
[    1.512358]  (driver?)

解决:
jffs2文件系统挂载不上的常见原因
如果 bootarg 是用的我的方法一配置的就需要勾选上mtd的 <*> Command line partition table parsing 支持,该项目用来解析uboot传递过来的flash分区信息。

Device Drivers  --->
	<*> Memory Technology Device (MTD) support  --->
		<*>   Command line partition table parsing	# 勾选,用来解析uboot传递过来的flash分区信息。(如果 bootarg 是用的我的方法一就需要勾选)

问题五:

[    0.927393] m25p80 spi0.0: found w25q128, expected xt25f128b
[    0.933212] m25p80 spi0.0: w25q128 (16384 Kbytes)
[    0.938067] 4 ofpart partitions found on MTD device spi0.0
[    0.943548] Creating 4 MTD partitions on "spi0.0":
[    0.948416] 0x000000000000-0x000000100000 : "u-boot"
[    0.956033] 0x000000100000-0x000000110000 : "dtb"
[    0.963339] 0x000000110000-0x000000510000 : "kernel"
[    0.970896] 0x000000510000-0x000001000000 : "rootfs"

解决:
这里纯粹是手贱,把uboot传参的 booarg 参数root=/dev/mtdblock3 rw rootfstype=jffs2 写到 console 参数里了,这个是根文件系统的位置和格式,应该写在 mtdparts 里面。


附:

1、仓库

发现荔枝派nano在gitee建立了仓库:git clone https://gitee.com/LicheePiNano


2、关于启动顺序

  • 全志F1C200s的启动顺序依次是SDIO(TF卡)- SPI NAND - SPI NOR - USB。
  • SD卡启动,优先级最高。在提前插入TF卡,且TF卡有可启动镜像的前提下,则TINY200会从TF卡启动系统。否则会按照启动顺序来尝试NAND、NOR和USB。
  • SPI NAND和NOR启动,优先级居中。
  • USB启动,优先级最低。sunxi-fel刷机方式,拉低 FLASH 的 CS 引脚即可。

3、支持FLASH型号

uboot 可识别的 SPI flash 的信息在drivers/mtd/spi/spi_flash_ids.c

const struct spi_flash_info spi_flash_ids[] = {
        {"w25p80",         INFO(0xef2014, 0x0,  64 * 1024,    16, 0) },
        {"w25p16",         INFO(0xef2015, 0x0,  64 * 1024,    32, 0) },
        {"w25p32",         INFO(0xef2016, 0x0,  64 * 1024,    64, 0) },
        {"w25x40",         INFO(0xef3013, 0x0,  64 * 1024,     8, SECT_4K) },
        {"w25x16",         INFO(0xef3015, 0x0,  64 * 1024,    32, SECT_4K) },
        {"w25x32",         INFO(0xef3016, 0x0,  64 * 1024,    64, SECT_4K) },
        {"w25x64",         INFO(0xef3017, 0x0,  64 * 1024,   128, SECT_4K) },
        {"w25q80bl",       INFO(0xef4014, 0x0,  64 * 1024,    16, RD_FULL | WR_QPP | SECT_4K) },
        {"w25q16cl",       INFO(0xef4015, 0x0,  64 * 1024,    32, RD_FULL | WR_QPP | SECT_4K) },
        {"w25q32bv",       INFO(0xef4016, 0x0,  64 * 1024,    64, RD_FULL | WR_QPP | SECT_4K) },
        {"w25q64cv",       INFO(0xef4017, 0x0,  64 * 1024,   128, RD_FULL | WR_QPP | SECT_4K) },
        {"w25q128bv",      INFO(0xef4018, 0x0,  64 * 1024,   256, RD_FULL | WR_QPP | SECT_4K) },
        {"w25q256",        INFO(0xef4019, 0x0,  64 * 1024,   512, RD_FULL | WR_QPP | SECT_4K) },
        {"w25q80bw",       INFO(0xef5014, 0x0,  64 * 1024,    16, RD_FULL | WR_QPP | SECT_4K) },
        {"w25q16dw",       INFO(0xef6015, 0x0,  64 * 1024,    32, RD_FULL | WR_QPP | SECT_4K) },
        {"w25q32dw",       INFO(0xef6016, 0x0,  64 * 1024,    64, RD_FULL | WR_QPP | SECT_4K) },
        {"w25q64dw",       INFO(0xef6017, 0x0,  64 * 1024,   128, RD_FULL | WR_QPP | SECT_4K) },
        {"w25q128fw",      INFO(0xef6018, 0x0,  64 * 1024,   256, RD_FULL | WR_QPP | SECT_4K) },


#define INFO(_jedec_id, _ext_id, _sector_size, _n_sectors, _flags)      \
                .id = {                                                 \
                        ((_jedec_id) >> 16) & 0xff,                     \
                        ((_jedec_id) >> 8) & 0xff,                      \
                        (_jedec_id) & 0xff,                             \
                        ((_ext_id) >> 8) & 0xff,                        \
                        (_ext_id) & 0xff,                               \
                        },                                              \
                .id_len = (!(_jedec_id) ? 0 : (3 + ((_ext_id) ? 2 : 0))),       \
                .sector_size = (_sector_size),                          \
                .n_sectors = (_n_sectors),                              \
                .page_size = 256,                                       \
                .flags = (_flags),


struct spi_flash_info {
        /* Device name ([MANUFLETTER][DEVTYPE][DENSITY][EXTRAINFO]) */
        const char      *name;

        /*
        * This array stores the ID bytes.
        * The first three bytes are the JEDIC ID.
        * JEDEC ID zero means "no ID" (mostly older chips).
        */
        u8              id[SPI_FLASH_MAX_ID_LEN];
        u8              id_len;

        /*
        * The size listed here is what works with SPINOR_OP_SE, which isn't
        * necessarily called a "sector" by the vendor.
        */
        u32             sector_size;
        u32             n_sectors;

        u16             page_size;

        u16             flags;


#define SECT_4K                 BIT(0)  /* CMD_ERASE_4K works uniformly */
#define E_FSR                   BIT(1)  /* use flag status register for */
#define SST_WR                  BIT(2)  /* use SST byte/word programming */
#define WR_QPP                  BIT(3)  /* use Quad Page Program */
#define RD_QUAD                 BIT(4)  /* use Quad Read */
#define RD_DUAL                 BIT(5)  /* use Dual Read */
#define RD_QUADIO               BIT(6)  /* use Quad IO Read */
#define RD_DUALIO               BIT(7)  /* use Dual IO Read */
#define RD_FULL                 (RD_QUAD | RD_DUAL | RD_QUADIO | RD_DUALIO)
};

4、启动LOG

U-Boot SPL 2018.01-05679-g013ca457fd-dirty (Dec 16 2021 - 14:37:53)
DRAM: 64 MiB
Trying to boot from MMC1
Card did not respond to voltage select!
mmc_init: -95, time 21
spl: mmc init failed with error: -95
Trying to boot from sunxi SPI


U-Boot 2018.01-05679-g013ca457fd-dirty (Dec 16 2021 - 14:37:53 +0800) Allwinner Technology

CPU:   Allwinner F Series (SUNIV)
Model: Lichee Pi Nano
DRAM:  64 MiB
MMC:   SUNXI SD/MMC: 0
SF: Detected w25q128bv with page size 256 Bytes, erase size 4 KiB, total 16 MiB
*** Warning - bad CRC, using default environment

Setting up a 480x272 lcd console (overscan 0x0)
In:    serial@1c25400
Out:   serial@1c25400
Err:   serial@1c25400
Net:   No ethernet found.
starting USB...
No controllers found
Hit any key to stop autoboot:  0 
SF: Detected w25q128bv with page size 256 Bytes, erase size 4 KiB, total 16 MiB
device 0 offset 0x100000, size 0x4000
SF: 16384 bytes @ 0x100000 Read: OK
device 0 offset 0x110000, size 0x400000
SF: 4194304 bytes @ 0x110000 Read: OK
## Flattened Device Tree blob at 80c00000
   Booting using the fdt blob at 0x80c00000
   Loading Device Tree to 816fb000, end 816fffce ... OK

Starting kernel ...

[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Linux version 4.15.0-rc8-licheepi-nano+ (pjw@pjw-virtual-machine) (gcc version 7.2.1 20171011 (Linaro GCC 7.2-2017.11)) #4 Thu Dec 16 14:01:32 CST 2021
[    0.000000] CPU: ARM926EJ-S [41069265] revision 5 (ARMv5TEJ), cr=0005317f
[    0.000000] CPU: VIVT data cache, VIVT instruction cache
[    0.000000] OF: fdt: Machine model: Lichee Pi Nano
[    0.000000] Memory policy: Data cache writeback
[    0.000000] random: fast init done
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 16256
[    0.000000] Kernel command line: console=ttyS1,115200 earlyprintk panic=5 rootwait; mtdparts=spi32766.0:1M(uboot)ro,64k(dtb)ro,4M(kernel)ro,-(rootfs) root=/dev/mtdblock3 rw rootfstype=jffs2
[    0.000000] Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
[    0.000000] Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
[    0.000000] Memory: 55160K/65536K available (6144K kernel code, 237K rwdata, 1412K rodata, 1024K init, 246K bss, 10376K reserved, 0K cma-reserved, 0K highmem)
[    0.000000] Virtual kernel memory layout:
[    0.000000]     vector  : 0xffff0000 - 0xffff1000   (   4 kB)
[    0.000000]     fixmap  : 0xffc00000 - 0xfff00000   (3072 kB)
[    0.000000]     vmalloc : 0xc4800000 - 0xff800000   ( 944 MB)
[    0.000000]     lowmem  : 0xc0000000 - 0xc4000000   (  64 MB)
[    0.000000]     pkmap   : 0xbfe00000 - 0xc0000000   (   2 MB)
[    0.000000]     modules : 0xbf000000 - 0xbfe00000   (  14 MB)
[    0.000000]       .text : 0x(ptrval) - 0x(ptrval)   (7136 kB)
[    0.000000]       .init : 0x(ptrval) - 0x(ptrval)   (1024 kB)
[    0.000000]       .data : 0x(ptrval) - 0x(ptrval)   ( 238 kB)
[    0.000000]        .bss : 0x(ptrval) - 0x(ptrval)   ( 247 kB)
[    0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16
[    0.000046] sched_clock: 32 bits at 24MHz, resolution 41ns, wraps every 89478484971ns
[    0.000112] clocksource: timer: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 79635851949 ns
[    0.000654] Console: colour dummy device 80x30
[    0.000742] Calibrating delay loop... 203.16 BogoMIPS (lpj=1015808)
[    0.070235] pid_max: default: 32768 minimum: 301
[    0.070547] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.070587] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.072030] CPU: Testing write buffer coherency: ok
[    0.073728] Setting up static identity map for 0x80100000 - 0x80100058
[    0.076287] devtmpfs: initialized
[    0.083187] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.083254] futex hash table entries: 256 (order: -1, 3072 bytes)
[    0.083513] pinctrl core: initialized pinctrl subsystem
[    0.085506] NET: Registered protocol family 16
[    0.087105] DMA: preallocated 256 KiB pool for atomic coherent allocations
[    0.088890] cpuidle: using governor menu
[    0.114773] SCSI subsystem initialized
[    0.115102] usbcore: registered new interface driver usbfs
[    0.115248] usbcore: registered new interface driver hub
[    0.115471] usbcore: registered new device driver usb
[    0.115880] pps_core: LinuxPPS API ver. 1 registered
[    0.115907] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <[email protected]>
[    0.115964] PTP clock support registered
[    0.116442] Advanced Linux Sound Architecture Driver Initialized.
[    0.118117] clocksource: Switched to clocksource timer
[    0.144277] NET: Registered protocol family 2
[    0.145687] TCP established hash table entries: 1024 (order: 0, 4096 bytes)
[    0.145763] TCP bind hash table entries: 1024 (order: 0, 4096 bytes)
[    0.145815] TCP: Hash tables configured (established 1024 bind 1024)
[    0.146096] UDP hash table entries: 256 (order: 0, 4096 bytes)
[    0.146150] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
[    0.146628] NET: Registered protocol family 1
[    0.147849] RPC: Registered named UNIX socket transport module.
[    0.147890] RPC: Registered udp transport module.
[    0.147905] RPC: Registered tcp transport module.
[    0.147921] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    0.150417] NetWinder Floating Point Emulator V0.97 (double precision)
[    0.152233] Initialise system trusted keyrings
[    0.152778] workingset: timestamp_bits=30 max_order=14 bucket_order=0
[    0.170142] NFS: Registering the id_resolver key type
[    0.170223] Key type id_resolver registered
[    0.170242] Key type id_legacy registered
[    0.170350] jffs2: version 2.2. (NAND)2001-2006 Red Hat, Inc.
[    0.185106] Key type asymmetric registered
[    0.185146] Asymmetric key parser 'x509' registered
[    0.185334] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 251)
[    0.185368] io scheduler noop registered
[    0.185385] io scheduler deadline registered
[    0.186169] io scheduler cfq registered (default)
[    0.186200] io scheduler mq-deadline registered
[    0.186218] io scheduler kyber registered
[    0.187329] sun4i-usb-phy 1c13400.phy: Couldn't request ID GPIO
[    0.196733] suniv-pinctrl 1c20800.pinctrl: initialized sunXi PIO driver
[    0.365121] Serial: 8250/16550 driver, 8 ports, IRQ sharing disabled
[    0.392177] 1c25000.serial: ttyS0 at MMIO 0x1c25000 (irq = 23, base_baud = 6250000) is a 16550A
[    0.414805] 1c25400.serial: ttyS1 at MMIO 0x1c25400 (irq = 24, base_baud = 6250000) is a 16550A
[    0.901350] console [ttyS1] enabled
[    0.912017] panel-simple panel: panel supply power not found, using dummy regulator
[    0.921421] SCSI Media Changer driver v0.25 
[    0.929194] m25p80 spi0.0: found w25q128, expected xt25f128b
[    0.934898] m25p80 spi0.0: w25q128 (16384 Kbytes)
[    0.939792] 4 ofpart partitions found on MTD device spi0.0
[    0.945276] Creating 4 MTD partitions on "spi0.0":
[    0.950148] 0x000000000000-0x000000100000 : "u-boot"
[    0.957743] 0x000000100000-0x000000110000 : "dtb"
[    0.965056] 0x000000110000-0x000000510000 : "kernel"
[    0.972576] 0x000000510000-0x000001000000 : "rootfs"
[    0.980672] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[    0.987207] ehci-platform: EHCI generic platform driver
[    0.992841] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
[    0.999151] ohci-platform: OHCI generic platform driver
[    1.004773] usbcore: registered new interface driver usb-storage
[    1.011787] udc-core: couldn't find an available UDC - added [g_cdc] to list of pending drivers
[    1.020864] i2c /dev entries driver
[    1.078246] sunxi-mmc 1c0f000.mmc: base:0x39132871 irq:19
[    1.085689] usbcore: registered new interface driver usbhid
[    1.091393] usbhid: USB HID core driver
[    1.113176] NET: Registered protocol family 17
[    1.117901] Key type dns_resolver registered
[    1.124729] Loading compiled-in X.509 certificates
[    1.140062] sun4i-drm display-engine: bound 1e60000.display-backend (ops 0xc0739c58)
[    1.148951] sun4i-drm display-engine: bound 1c0c000.lcd-controller (ops 0xc0738f3c)
[    1.156616] [drm] Supports vblank timestamp caching Rev 2 (21.10.2013).
[    1.163322] [drm] No driver support for vblank timestamp query.
[    1.301441] Console: switching to colour frame buffer device 100x30
[    1.341207] sun4i-drm display-engine: fb0:  frame buffer device
[    1.348448] [drm] Initialized sun4i-drm 1.0.0 20150629 for display-engine on minor 0
[    1.357557] usb_phy_generic usb_phy_generic.0.auto: usb_phy_generic.0.auto supply vcc not found, using dummy regulator
[    1.369518] musb-hdrc musb-hdrc.1.auto: MUSB HDRC host driver
[    1.375317] musb-hdrc musb-hdrc.1.auto: new USB bus registered, assigned bus number 1
[    1.385587] hub 1-0:1.0: USB hub found
[    1.389690] hub 1-0:1.0: 1 port detected
[    1.395236] using random self ethernet address
[    1.399887] using random host ethernet address
[    1.406197] usb0: HOST MAC 52:1c:07:d0:b2:5e
[    1.410735] usb0: MAC d2:67:27:e7:76:82
[    1.414728] g_cdc gadget: CDC Composite Gadget, version: King Kamehameha Day 2008
[    1.422296] g_cdc gadget: g_cdc ready
[    1.426994] cfg80211: Loading compiled-in X.509 certificates for regulatory database
[    1.444876] cfg80211: Loaded X.509 cert 'sforshee: 00b28ddf47aef9cea7'
[    1.451763] vcc3v3: disabling
[    1.454749] ALSA device list:
[    1.457717]   #0: Loopback 1
[    1.461599] platform regulatory.0: Direct firmware load for regulatory.db failed with error -2
[    1.470352] cfg80211: failed to load regulatory.db
[    1.573936] random: crng init done
[    2.073531] VFS: Mounted root (jffs2 filesystem) on device 31:3.
[    2.081640] devtmpfs: mounted
[    2.091942] Freeing unused kernel memory: 1024K
Starting logging: OK
Initializing random number generator... done.
Starting network: OK

Welcome to gateway
gateway login: root
Password: 
# 

5、参考资料

荔枝派Nano | spi-flash 启动适配
荔枝派Zero | SPI Flash 系统编译
荔枝派Zero | jffs2文件系统挂载不上的常见原因
荔枝派Zero | Zero Spi Nor Flash启动系统制作指南
sipeed | spi_flash编译
lichee nano官方linux config文件踩坑与填坑(常见配置误区)
荔枝派nano(f1c100s)的SPI-Flash系统编译创建全过程

你可能感兴趣的:(全志Linux,linux)