目前调试的项目是将uImage文件放在flash中,启动时uboot将其拷贝至内存并带起,所以升级内核时只需要将flash中的uImage替换即可,此时就需要使用spi与flash通信完成擦除、读写等操作。由于设置的是从flash启动,所以硬件上只能使用的是qspi与w25q128通信,相关配置如下:
驱动配置
进入配置界面:
$ cd ~/NUC970_Buildroot-master/
$ make linux-menuconfig
首先依次选择Device Drivers > SPI support,选择项如下,请根据具体硬件设计选择:
同时,还需开启MTD,返回上一层,选择Memory Technology Device (MTD) support,选择项如下:
黄色框中Self-contained MTD device drivers下拉选项选择如下:
注意:若上一层中红色框未选择,此选项不会出现!
红色框选项也有下拉选项,但此选项需根据使用的flash是否支持该功能来选择:
另外,还需要设置支持JFFS2文件系统,选择File systems > Miscellaneous filesystems,具体选项如下:
文件修改
驱动配置完成后,还需要修改相关文件,以保证能正确匹配flash型号。
打开m25p80.c文件
$ cd ~/NUC970_Buildroot-master/output/build/linux-master/drivers/mtd/devices
$ vi m25p80.c
可以找到如下结构体:
static const struct spi_device_id m25p_ids[] = {
/*
* Entries not used in DTs that should be safe to drop after replacing
* them with "nor-jedec" in platform data.
*/
{"s25sl064a"}, {"w25x16"}, {"m25p10"}, {"m25px64"},
/*
* Entries that were used in DTs without "nor-jedec" fallback and should
* be kept for backward compatibility.
*/
{"at25df321a"}, {"at25df641"}, {"at26df081a"},
{"mr25h256"},
{"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"},
{ },
};
确认其中是否有需要的flash型号,可以看到其中支持w25q128该型号flash。
确认完成后再打开dev.c文件:
$ cd ~/NUC970_Buildroot-master/output/build/linux-master/arch/arm/mach-nuc980
$ vi dev.c
根据使用的spi找到对应的结构体,如qspi:
static struct flash_platform_data nuc980_qspi0_flash_data = {
#if defined(CONFIG_BOARD_IOT) || defined(CONFIG_BOARD_ETH2UART) || defined(CONFIG_BOARD_LORAG)
.name = "mt29f",
#else
.name = "m25p80",
#endif
.parts = nuc980_qspi0_flash_partitions,
.nr_parts = ARRAY_SIZE(nuc980_qspi0_flash_partitions),
.type = "mx66l51235l",
};
将type改为需要的型号,注意此处修改需保证是在上面结构体m25p_ids[]中存在的:
.type = "w25q128",
还可以对MTD的分区进行修改:
/* SPI */
#if defined(CONFIG_SPI_NUC980_QSPI0) || defined(CONFIG_SPI_NUC980_QSPI0_MODULE)
/* spi device, spi flash info */
#ifdef CONFIG_MTD_M25P80
static struct mtd_partition nuc980_qspi0_flash_partitions[] = {
#if defined(CONFIG_BOARD_ETH2UART)
{
.name = "lighttpd",
.size = 0x0200000,
.offset = 0x0C00000,
},
#elif defined(CONFIG_BOARD_CHILI) /* chili board spi flash total 32Mbyte*/
{
.name = "kernel", /* uboot, kernel 20Mbyte*/
.size = 0x1400000,
.offset = 0,
},
{
.name = "rootfs", /* kernel 12Mbyte*/
.size = 0x0c00000,
.offset = 0x1400000,
},
#else
{
.name = "kernel",
.size = 0x0400000,
.offset = 0,
},
{
.name = "rootfs",
.size = 0x0400000,
.offset = 0x0400000,
},
#endif
};
我根据现实情况,将其改为:
#else
{
.name = "uboot",
.size = 0x0200000,
.offset = 0,
},
{
.name = "kernel",
.size = 0x0800000,
.offset = 0x0200000,
},
{
.name = "rootfs",
.size = 0x0400000,
.offset = 0x0a00000,
},
#endif
上面程序中还需要注意在初始化配置时使用的是厂商提供的哪一个config文件,如程序中这一段:
#if defined(CONFIG_BOARD_IOT) || defined(CONFIG_BOARD_ETH2UART) || defined(CONFIG_BOARD_LORAG)
.name = "mt29f",
#else
.name = "m25p80",
我在初始化配置是使用的是nuvoton_nuc980_defconfig,而非nuvoton_nuc980_chili_defconfig或nuvoton_nuc980_eth2uart_defconfig,所以按上述修改,请根据自身设置来修改。
修改完成后,保存,make,烧录uimage。
测试
串口工具连接后,可以看到/dev中已经存在设置好的三个分区:
也可以通过如下命令查看更具体的信息:
|