把内核里的mtd分区表信息改成自己想要的,在新的内核里分区信息在dts里描述:
qspi: spi@ff705000 {
...
partition@qspi-preloader{
/* 256KB for preloader */
label = "preloader";
reg = <0x0 0x40000>;
};
partition@qspi-env{
/* 64KB for env */
label = "u-boot env";
reg = <0x40000 0x10000>;
};
partition@qspi-fdt{
/* 64KB for dtb */
label = "device tree blob";
reg = <0x50000 0x10000>;
};
partition@qspi-uboot{
/* 256KB for u-boot */
label = "u-boot";
reg = <0x60000 0x40000>;
};
partition@qspi-kernel{
/* 7.6MB for kernel */
label = "kernel";
reg = <0xa0000 0x760000>;
};
partition@qspi-rootfs {
/* 120MB for jffs2 data. */
label = "Flash 0 jffs2 Filesystem";
reg = <0x800000 0x7800000>;
};
};
};
我的系统中有一个128MB的qspi nor flash,并能挂载。为了更新qspi nor flash分区信息包括文件系统分区,你必须挂载其他存储设备比如tf卡的文件系统分区,nfs也可以。
启动进入系统后,你可以使用:
root#cat /pro/mtd
dev: size erasesize name
mtd0: 00040000 00010000 "preloader"
mtd1: 00010000 00010000 "u-boot env"
mtd2: 00010000 00010000 "device tree blob"
mtd3: 00040000 00010000 "u-boot"
mtd4: 00760000 00010000 "kernel"
mtd5: 07800000 00010000 "Flash 0 jffs2 Filesystem"
另外你可能需要移植mtd-utils工具,我的文件系统正好自带了这个工具,需要移植的可以自己google。
先擦除各个分区
root# flash_eraseall /dev/mtd0
flash_eraseall has been replaced by `flash_erase <mtddev> 0 0`; please use it
Erasing 64 Kibyte @ 30000 -- 100 % complete
root# flash_eraseall /dev/mtd1
flash_eraseall has been replaced by `flash_erase <mtddev> 0 0`; please use it
Erasing 64 Kibyte @ 0 -- 100 % complete
root# flash_eraseall /dev/mtd2
flash_eraseall has been replaced by `flash_erase <mtddev> 0 0`; please use it
Erasing 64 Kibyte @ 0 -- 100 % complete
root# flash_eraseall /dev/mtd3
flash_eraseall has been replaced by `flash_erase <mtddev> 0 0`; please use it
Erasing 64 Kibyte @ 30000 -- 100 % complete
root# flash_eraseall /dev/mtd4
flash_eraseall has been replaced by `flash_erase <mtddev> 0 0`; please use it
Erasing 64 Kibyte @ 750000 -- 100 % complete
root# flash_eraseall /dev/mtd5
flash_eraseall has been replaced by `flash_erase <mtddev> 0 0`; please use it
Erasing 64 Kibyte @ 77f0000 -- 100 % complete
root# sync
再更新各分区:
root# flashcp preloader.bin /dev/mtd0
root# sync
root# flashcp u-boot.img /dev/mtd3
root# sync
root# flashcp socfpga_cyclone5.dtb /dev/mtd2
root# sync
root# flashcp zImage /dev/mtd4
root# sync
root# flashcp jffs2.img /dev/mtd5
root# sync
最后你可能需要在内核里查看和设置环境变量,这就需要使用上面的工具fw_printenv和fw_setenv。
该工具是uboot中提供的,需要把它交叉编译一下放到文件系统中,交叉编译方法:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- HOSTCC=arm-linux-gnueabihf-gcc HOSTSTRIP=arm-linux-gnueabihf-strip env
这个工具交叉编译容易,但是需要写个/etc/fw_env.conf配置文件:
我的配置文件如下:
# Configuration file for fw_(printenv/saveenv) utility.
# Up to two entries are valid, in this case the redundant
# environment sector is assumed present.
# Notice, that the "Number of sectors" is ignored on NOR and SPI-dataflash.
# Futhermore, if the Flash sector size is ommitted, this value is assumed to
# be the same as the Environment size, which is valid for NOR and SPI-dataflash
# NOR example
# MTD device name Device offset Env. size Flash sector size Number of sectors
/dev/mtd1 0x00000 0x1000 0x10000
这里解释一下为什么这么设置?很明显,我的环境变量分区放在mtd1分区,设备偏移是针对mtd1的偏移,是个相对偏移,由于整个分区是环境变量分区,所以偏移就为了0了;
接着是设置环境变量大小,我设置的是4096,这个从哪里来的呢?请查看你的uboot中的配置文件里的宏
#define CONFIG_ENV_SIZE 4096
这个是就是环境变量的大小,网上的资料都说的不清楚,这才是正解。否则你fw_setenv会提示env crc bad而失败。
最后的参数flash扇区大小,这个可以从芯片手册查到的,我的nor flash手册上:
一共有2048个扇区,每个setcor size(64KB);也可以看成32K个子扇区,每个子扇区为4KB;
或者512K个页,每页256B,这里应该是擦除块大小,(不支持页擦除)
我的qspi nor flash的驱动配置的sector擦除,而不是sub-sector擦除,所以这里填上64KB。