全志V3S中spi nor flash 系统镜像配置

一,u-boot篇章

1.首先移植u-boot,下载u-boot

git clone -b v3s-spi-experimental https://github.com/Lichee-Pi/u-boot.git

2.图形化配置u-boot

make ARCH=arm menuconfig

3.图形配置如下:

我的flash是W25Q128选择图片中的那个。

如果使用的是16MB以上的flash,需要勾选flash
bank支持选项,否则最多只能读到16MB: CONFIG_SPI_FLASH_BAR

4.配置uboot默认环境变量


在文件 include/configs/sun8i.h
中添加默认bootcmd和bootargs的环境变量设置,注意添加的位置在“#include <configs/sunxi-common.h> ”的前边。
 

#define CONFIG_BOOTCOMMAND   "sf probe 0; "                           \
                            "sf read 0x41800000 0x100000 0x10000; "  \
                            "sf read 0x41000000 0x110000 0x400000; " \
                            "bootz 0x41000000 - 0x41800000"

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

注意上述的u-boot环境变量是在Linux内核版本4.9.13,现在最新的内核时5.2.0,所以使用下面的环境变量设置。

#define CONFIG_BOOTCOMMAND   "sf probe 0; "                           \
                            "sf read 0x41800000 0x100000 0x10000; "  \
                            "sf read 0x41000000 0x110000 0x400000; " \
                            "bootz 0x41000000 - 0x41800000"

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

5.编译u-boot

time make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- 2>&1 | tee build.log
 

编译出来的结果为u-boot-sunxi-with-spl.bin

提醒:
        

环境命令解析:

  • sf probe 0; //初始化Flash设备(CS拉低)
  • sf read 0x41800000 0x100000 0x10000;//从flash0x100000(1MB)位置读取dtb放到内存0x41800000偏移处。//如果是bsp的bin,则是0x41d00000
  • sf read 0x41000000 0x110000 0x400000;//从flash0x110000(1MB+64KB)位置读取dtb放到内存0x41000000偏移处。
  • bootz 0x41000000 (内核地址)- 0x41800000(dtb地址) 启动内核

启动参数解析:

  • console=ttyS0,115200 earlyprintk panic=5 rootwait//在串口0上输出信息
  • mtdparts=spi32766.0:1M(uboot)ro,64k(dtb)ro,4M(kernel)ro,-(rootfs) root=31:03 rw rootfstype=jffs2 //spi32766.0是设备名,后面是分区大小,名字,读写属性。
  • root=31:03表示根文件系统是mtd3;jffs2格式
     

二:Linux内核篇章

1.准备内核,下载地址:
 

https://github.com/Lichee-Pi/linux.git

2.图形化配置
       

make ARCH=arm menuconfig

3.设备树配置
 

添加spi flash节点

/*
 * Copyright (C) 2016 Icenowy Zheng <icenowy@aosc.xyz>
 *
 * This file is dual-licensed: you can use it either under the terms
 * of the GPL or the X11 license, at your option. Note that this dual
 * licensing only applies to this file, and not this project as a
 * whole.
 *
 *  a) This file is free software; you can redistribute it and/or
 *     modify it under the terms of the GNU General Public License as
 *     published by the Free Software Foundation; either version 2 of the
 *     License, or (at your option) any later version.
 *
 *     This file is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 * Or, alternatively,
 *
 *  b) Permission is hereby granted, free of charge, to any person
 *     obtaining a copy of this software and associated documentation
 *     files (the "Software"), to deal in the Software without
 *     restriction, including without limitation the rights to use,
 *     copy, modify, merge, publish, distribute, sublicense, and/or
 *     sell copies of the Software, and to permit persons to whom the
 *     Software is furnished to do so, subject to the following
 *     conditions:
 *
 *     The above copyright notice and this permission notice shall be
 *     included in all copies or substantial portions of the Software.
 *
 *     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 *     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 *     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 *     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 *     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 *     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 *     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 *     OTHER DEALINGS IN THE SOFTWARE.
 */

/dts-v1/;
#include "sun8i-v3s.dtsi"
#include "sunxi-common-regulators.dtsi"

/ {
	model = "Lichee Pi Zero";
	compatible = "licheepi,licheepi-zero", "allwinner,sun8i-v3s";

	aliases {
		serial0 = &uart0;
		ethernet0 = &emac;
	};

	chosen {
		stdout-path = "serial0:115200n8";
	};

	leds {
		compatible = "gpio-leds";

		blue_led {
			label = "licheepi:blue:usr";
			gpios = <&pio 6 1 GPIO_ACTIVE_LOW>; /* PG1 */
		};

		green_led {
			label = "licheepi:green:usr";
			gpios = <&pio 6 0 GPIO_ACTIVE_LOW>; /* PG0 */
			default-state = "on";
		};

		red_led {
			label = "licheepi:red:usr";
			gpios = <&pio 6 2 GPIO_ACTIVE_LOW>; /* PG2 */
		};
	};
};

&ehci0 {
	status = "okay";
};

&emac {
       phy-handle = <&int_mii_phy>;
       phy-mode = "mii";
       allwinner,leds-active-low;
       status = "okay";
};

&mmc0 {
	broken-cd;
	bus-width = <4>;
	vmmc-supply = <&reg_vcc3v3>;
	status = "disabled";
};

&i2c0 {
	status = "disabled";

	ns2009: ns2009@48 {
		compatible = "nsiway,ns2009";
		reg = <0x48>;
	};
};

&ohci0 {
	status = "okay";
};

&spi0 {
        status ="okay";
        w25q128:w25q128@0 {
			compatible = "winbond, w25q128","jedec,spi-nor";
			reg = <0x0>;
			spi-max-frequency = <50000000>;
			#address-cells = <1>;
			#size-cells = <1>;
        };
};


&uart0 {
	pinctrl-0 = <&uart0_pb_pins>;
	pinctrl-names = "default";
	status = "okay";
};

/*&usb_otg {
	dr_mode = "otg";
	status = "okay";
};*/

&usb_otg {
	dr_mode = "device";
	status = "okay";
};

&usbphy {
	usb0_id_det-gpios = <&pio 5 6 GPIO_ACTIVE_HIGH>;
	status = "disabled";
};

这里的flash型号需要在下表之中,否则将无法识别:(注意容量也一定要对应)

static const struct spi_device_id m25p_ids[] = {
        /*
        * Allow non-DT platform devices to bind to the "spi-nor" modalias, and
        * hack around the fact that the SPI core does not provide uevent
        * matching for .of_match_table
        */
        {"spi-nor"},

        /*
        * Entries not used in DTs that should be safe to drop after replacing
        * them with "spi-nor" in platform data.
        */
        {"s25sl064a"},  {"w25x16"},     {"m25p10"},     {"m25px64"},

        /*
        * Entries that were used in DTs without "jedec,spi-nor" fallback and
        * should be kept for backward compatibility.
        */
        {"at25df321a"}, {"at25df641"},  {"at26df081a"},
        {"mx25l4005a"}, {"mx25l1606e"}, {"mx25l6405d"}, {"mx25l12805d"},
        {"mx25l25635e"},{"mx66l51235l"},
        {"n25q064"},    {"n25q128a11"}, {"n25q128a13"}, {"n25q512a"},
        {"s25fl256s1"}, {"s25fl512s"},  {"s25sl12801"}, {"s25fl008k"},
        {"s25fl064k"},
        {"sst25vf040b"},{"sst25vf016b"},{"sst25vf032b"},{"sst25wf040"},
        {"m25p40"},     {"m25p80"},     {"m25p16"},     {"m25p32"},
        {"m25p64"},     {"m25p128"},
        {"w25x80"},     {"w25x32"},     {"w25q32"},     {"w25q32dw"},
        {"w25q80bl"},   {"w25q128"},    {"w25q256"},

        /* Flashes that can't be detected using JEDEC */
        {"m25p05-nonjedec"},    {"m25p10-nonjedec"},    {"m25p20-nonjedec"},
        {"m25p40-nonjedec"},    {"m25p80-nonjedec"},    {"m25p16-nonjedec"},
        {"m25p32-nonjedec"},    {"m25p64-nonjedec"},    {"m25p128-nonjedec"},

        /* Everspin MRAMs (non-JEDEC) */
        { "mr25h256" }, /* 256 Kib, 40 MHz */
        { "mr25h10" },  /*   1 Mib, 40 MHz */
        { "mr25h40" },  /*   4 Mib, 40 MHz */

        { },
};

4.编译内核镜像和设备树
 

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j32
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- dtbs
 

三,准备jffs2文件系统

1.下载jffs2文件系统制作工具

apt-get install mtd-utils

2.解压文件系统

tar xzvf rootfs-brmin.tar.gz

3.打包文件系统镜像
 

总空间是32M-1M-64K-4M=0x1AF0000

mkfs.jffs2 -s 0x100 -e 0x10000 -p 0x1AF0000 -d rootfs/ -o jffs2.img

    • 页大小0x100 256字节
    • 块大小0x10000 64k
    • jffs2分区总空间0x1AF0000
    • jffs2.img是生成的文件系统镜像。

    4.打包生成烧录固件

    #!/bin/sh
    dd if=/dev/zero of=flashimg.bin bs=1M count=$1
    dd if=u-boot-sunxi-with-spl-$2.bin of=flashimg.bin bs=1K conv=notrunc
    dd if=sun8i-v3s-licheepi-zero-$2.dtb of=flashimg.bin bs=1K seek=1024  conv=notrunc
    dd if=zImage of=flashimg.bin bs=1K seek=1088  conv=notrunc
    dd if=jffs2.img of=flashimg.bin  bs=1K seek=5184  conv=notrunc
     

    第一步: 生成一个空文件,大小是32MB\
    第二步: 将uboot添加到文件开头\
    第三步: 将dtb放到1M偏移处\
    第四步: 将kernel放到1M+64K偏移处
    第五步: 将rootfs放到1M+64K+4M偏移处

    偏移大小是seek,单位是KB。

    四:烧写镜像
     

    1.下载sunxiflash烧写工具#

    git clone -b spi-rebase https://github.com/Icenowy/sunxi-tools.git

    进入工具目录执行 make && sudo make install

    2.进入fel模式#

    Zero有一个usb下载模式称为fel模式,进入fel模式有下面几种方式:

    1. TF卡和spi flash 同时没有可启动镜像

    也就是说你不插卡,且焊接的是新的或者没有有效镜像的spi flash,那就上电自动进入fel下载模式

    1. TF卡中有进入fel模式的特殊固件 fel-sdboot.sunxi

    如果你的spiflash已经有了启动镜像,那么需要在TF卡中烧入一个sunxi提供的启动工具 (dd if=fel-sdboot.sunxi of=/dev/mmcblk0 bs=1024 seek=8 ),那么插入该TF卡启动会进入fel模式;

    1. 上电时SPI_MISO拉低到地

    该引脚为boot引脚,上电时出于低电平即会进入fel下载模式。

    3. sunxi-fel的操作#

    进入fel模式后使用usb数据线连接pc和zero,即可进行操作。

    sudo sunxi-fel version      #查看连接的cpu信息
    AWUSBFEX soc=00001681(V3s) 00000001 ver=0001 44 08 scratchpad=00007e00 00000000 00000000
    sudo sunxi-fel spiflash-info    #显示flash信息
    Manufacturer: Unknown (C2h), model: 20h, size: 33554432 bytes.
     

    执行如下命令烧入我们前边制作好的镜像文件

    sudo sunxi-fel -p spiflash-write 0 flashimg.bin
    # -p 显示进度条
    #   spiflash-info           Retrieves basic information
    #   spiflash-hex[dump] addr length  Dumps SPI flash region in hex
    #   spiflash-read addr length file  Write SPI flash contents into file
    #   spiflash-write addr file    Store file contents into SPI flash
     

    评论
    添加红包

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

    当前余额3.43前往充值 >
    需支付:10.00
    成就一亿技术人!
    领取后你会自动成为博主和红包主的粉丝 规则
    hope_wisdom
    发出的红包

    打赏作者

    hqb_newfarmer

    你的鼓励将是我创作的最大动力

    ¥1 ¥2 ¥4 ¥6 ¥10 ¥20
    扫码支付:¥1
    获取中
    扫码支付

    您的余额不足,请更换扫码支付或充值

    打赏作者

    实付
    使用余额支付
    点击重新获取
    扫码支付
    钱包余额 0

    抵扣说明:

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

    余额充值