SPI Nor
一 硬件环境
以RD_AD100_EVB_V1.0开发板为例, 从MSC0启动(tf卡对应控制器)进行flash烧录,烧录完成从SFC0启动
二 卡启动镜像制作
2.1 sd卡烧录配置
打开iconfigtool配置页面, 使用ad100_mmc0_5.10_sd_card_burn_sfc_nor_dtb_defconfig配置
升级脚本路径可修改
bhu@bhu-PC:~/work/buildroot/buildroot_patch/rootfs_config/file/sdcard_update$ ls -l
总用量 36
-rwxr-xr-x 1 bhu bhu 7172 4月 19 14:53 S99_510_quickstart_sdcard_update #nand快启升级脚本
-rwxr-xr-x 1 bhu bhu 6398 4月 25 15:09 S99_510_sdcard_update #nand升级脚本
-rwxr-xr-x 1 bhu bhu 6398 4月 25 15:09 S99_510_sdcard_update_nor #nor升级脚本
-rwxr-xr-x 1 bhu bhu 9515 4月 19 14:53 S99sdcard_update
烧录脚本只是参考demo, nand客户需要根据实际使用分区, 对脚本进行修改, nor不需要.
2.2 Nor分区配置
nor是整个升级, 根据flash大小进行修改, 默认为16MB(0x1000000), 位置位于kernel/kernel/module_drivers/dts/ad100_module_base_mmc0_bootargs.dts
2.3 Kernel修改
2.3.1 配置添加flash型号及chip id
以开发板flash GD25B512ME为例, 位于kernel/kernel/module_drivers/drivers/mtd/devices/Kconfig
对应信息可以参考烧录工具
2.3.2 nor_params_node添加参数
文件位于kernel/kernel/module_drivers/drivers/mtd/devices/ingenic_sfc_v2/nor_device/nor_device.c
#define NOR_DEVICES_NUM 4 //记得设备数加1
#ifdef CONFIG_INGENIC_GD25B512ME
/*GD25B512ME*/
[3] = {
.nor_device_info.name = "GD25B512ME",
.nor_device_info.id = 0xC8471A,
.nor_device_info.tCHSH = 5,
.nor_device_info.tSLCH = 5,
.nor_device_info.tSHSL_RD = 20,
.nor_device_info.tSHSL_WR = 40,
.nor_device_info.chip_size = 67108864,
.nor_device_info.page_size = 256,
.nor_device_info.erase_size = 32768,
.nor_device_info.quad_ops_mode = 0,
.nor_device_info.addr_ops_mode = 0,
},
#endif
相关信息查看烧录工具,选中对应flash点击修改
2.3.3 get_cdt_params添加参数
static struct spi_nor_info *get_cdt_params(struct sfc_flash *flash, struct spi_nor_info *nor_device_info)
{
switch(nor_device_info->id) {
case 0xc84018:
if(!(strcmp(nor_device_info->name, "GD25Q127C"))) {
CDT_PARAMS_INIT_COMMON(nor_device_info, 3);
/* quad set 0x31 1 1 1 1 0 */
ST_INFO(nor_device_info->quad_set, SPINOR_OP_WRSR_1, 1, 1, 1, 1, TM_STD_SPI);
/* quad get 0x35 1 1 1 1 0 */
ST_INFO(nor_device_info->quad_get, SPINOR_OP_RDSR_1, 1, 1, 1, 1, TM_STD_SPI);
break;
}
case 0xc84019:
if(!(strcmp(nor_device_info->name, "GD25Q256C"))) {
CDT_PARAMS_INIT_COMMON(nor_device_info, 4);
/* entry 4byte 0xb7 0 0 0 */
CMD_INFO(nor_device_info->en4byte, SPINOR_OP_EN4B, 0, 0, TM_STD_SPI);
/* quad set 0x01 6 1 1 1 0 */
ST_INFO(nor_device_info->quad_set, SPINOR_OP_WRSR, 6, 1, 1, 1, TM_STD_SPI);
/* quad get 0x05 6 1 1 1 0 */
ST_INFO(nor_device_info->quad_get, SPINOR_OP_RDSR, 6, 1, 1, 1, TM_STD_SPI);
break;
}
if(!(strcmp(nor_device_info->name, "GD25S512MD"))) {
CDT_PARAMS_INIT_SPECIAL(nor_device_info);
/* quad set 0x31 1 1 1 1 0 */
ST_INFO(nor_device_info->quad_set, SPINOR_OP_WRSR_1, 1, 1, 1, 1, TM_STD_SPI);
/* quad get 0x35 1 1 1 1 0 */
ST_INFO(nor_device_info->quad_get, SPINOR_OP_RDSR_1, 1, 1, 1, 1, TM_STD_SPI);
break;
}
case 0xC8471A:
if(!(strcmp(nor_device_info->name, "GD25B512ME"))) {
CDT_PARAMS_INIT_SPECIAL(nor_device_info);
break;
}
default:
dev_err(flash->dev, "device_id err, please check your device id: device_id = 0x%02x\n", nor_device_info->id);
return NULL;
}
return nor_device_info;
}
使用CDT_PARAMS_INIT_COMMON还是CDT_PARAMS_INIT_SPECIAL, 参考kernel/kernel/module_drivers/drivers/mtd/devices/ingenic_sfc_v2/nor_device/目录下的文件nor_device.h, 对比烧录工具flash相关的信息
开发板flash GD25B512ME就是CDT_PARAMS_INIT_SPECIAL, 若是CDT_PARAMS_INIT_COMMON(nor_device_info, addr_bytes), 容量超过16MB时填写4, 否则3, 也可以查看烧录工具中flash相关信息address byte , CDT_PARAMS_INIT_SPECIAL默认为4, 不用填写
若支持四线, 即quad_ops_mode = 1, 需配置设置和获取四线, 与烧录工具相关信息要保持一致.如下示例, 其中的SPINOR_OP_WRSR_1 , SPINOR_OP_RDSR_1 参考kernel/kernel/module_drivers/drivers/mtd/devices/ingenic_sfc_v2/spinor_cmd.h
if(!(strcmp(nor_device_info->name, "GD25S512MD"))) {
CDT_PARAMS_INIT_SPECIAL(nor_device_info);
/* quad set 0x31 1 1 1 1 0 */
ST_INFO(nor_device_info->quad_set, SPINOR_OP_WRSR_1, 1, 1, 1, 1, TM_STD_SPI);
/* quad get 0x35 1 1 1 1 0 */
ST_INFO(nor_device_info->quad_get, SPINOR_OP_RDSR_1, 1, 1, 1, 1, TM_STD_SPI);
break;
}
2.4 编译
kernel menuconfig勾选添加的flash配置, 保存退出
查看kernel配置, 并保存
bhu@bhu-PC:~/work/build$ grep -nr "kernel_config" configs/ad100_mmc0_5.10_sd_card_burn_sfc_nor_dtb_defconfig
7:APP_kernel_config=ad100_module_base_sd_card_burn_sfc_nor_dtb_defconfig #kernel配置
bhu@bhu-PC:~/work/build$ cd ../kernel/kernel
bhu@bhu-PC:~/work/kernel/kernel$ cp .config arch/mips/configs/ad100_module_base_sd_card_burn_sfc_nor_dtb_defconfig
编译整个配置
bhu@bhu-PC:~/ad100/build$ make clean #第一次编译不需要make clean
bhu@bhu-PC:~/ad100/build$ make ad100_mmc0_5.10_sd_card_burn_sfc_nor_dtb_defconfig
bhu@bhu-PC:~/ad100/build$ make
编译后生成固件如下:
bhu@bhu-PC:~/ad100/build$ cd output/
bhu@bhu-PC:~/ad100/build/output$ ls -l
总用量 9924
-rw-r--r-- 1 bhu bhu 15935 6月 13 14:05 ad100_module_base_mmc0_bootargs.dtb
-rw-r--r-- 1 bhu bhu 4853760 6月 13 14:05 rootfs.squashfs
-rw-r--r-- 1 bhu bhu 215544 6月 13 14:05 u-boot-with-spl-mbr-gpt.bin
-rw-r--r-- 1 bhu bhu 5070912 6月 13 14:05 xImage
三 TF卡写入启动镜像
offset需要与分区表一致, 位于bootloader/uboot-x2000/board/ingenic/ad100_base/partitions.tab
这里是卡启动的分区信息, 用于sd卡固件启动, 与nor分区不相关
property:
disk_size = 3728m
gpt_header_lba = 512
custom_signature = 0
partition:
#name = start, size, fstype
xboot = 0m, 1m,
kernel = 1m, 8m, EMPTY
dtb = 9m, 1m, EMPTY
rootfs = 10m, 100m, LINUX_FS
kernel2 = 110m, 8m, EMPTY
dtb2 = 118m, 1m, EMPTY
rootfs2 = 119m, 100m, LINUX_FS
ota = 219m, 1m, EMPTY
userdata = 220m, 3508m, LINUX_FS
#fstype could be: LINUX_FS, FAT_FS, EMPTY
使用读卡器将sd卡插入电脑, 使用 ls /dev/sd* 命令查看所有的磁盘设备, 找到sd卡对应设备路径
sudo dd if=/dev/zero of=/dev/sdb bs=4M status=progress #格式化sd卡设备
sync
#重新插拔sd卡确认是否只有/dev/sdb节点,没有/dev/sdb1 .....
sudo dd if=u-boot-with-spl-mbr-gpt.bin of=/dev/sdb
sudo dd if=xImage of=/dev/sdb bs=512 seek=2048 #与uboot目录中的partitions.tab分区一致, offset 1MB
sudo dd if=ad100_module_base_mmc0_bootargs.dtb of=/dev/sdb bs=512 seek=18432 #与uboot目录中partitions.tab分区一致, offset 9MB
sudo dd if=rootfs.squashfs of=/dev/sdb bs=512 seek=20480 #与uboot目录中partitions.tab分区一致, offset 10M
sync
四 Nor烧录镜像制作
4.1 nor镜像编译
以基础配置ad100_nor_5.10_defconfig为例
bhu@bhu-PC:~/ad100/build$ make clean #第一次编译不需要make clean
bhu@bhu-PC:~/ad100/build$ make ad100_nor_5.10_defconfig
bhu@bhu-PC:~/ad100/build$ make
4.2 合并带有分区信息的image镜像
填入flash chip id 及参数偏移, AD100参数偏移是0x5800, 将需要烧录的文件和分区信息打包到一起
点击“合并镜像”按钮,在选择的镜像同级目录下会生成 image.bin 文件
五 TF卡拷贝nor镜像
查看tf卡分区
bhu@bhu-PC:~/Desktop/nand$ sudo parted -s /dev/sdb print
请输入密码:
验证成功
Error: The backup GPT table is corrupt, but the primary appears OK, so that will be used.
Warning: Not all of the space available to /dev/sdb appears to be used, you can fix the GPT to use all of the space (an extra 54698975 blocks) or continue with the current setting?
Model: Generic- SD/MMC (scsi)
Disk /dev/sdb: 31.9GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 9437kB 8389kB kernel msftdata
2 9437kB 10.5MB 1049kB dtb msftdata
3 10.5MB 115MB 105MB rootfs msftdata
4 115MB 124MB 8389kB kernel2 msftdata
5 124MB 125MB 1049kB dtb2 msftdata
6 125MB 230MB 105MB rootfs2 msftdata
7 230MB 231MB 1049kB ota msftdata
8 231MB 3909MB 3678MB userdata msftdata
在userdata分区即/dev/sdb8创建ext4文件系统
bhu@bhu-PC:~/Desktop/sd_card_burn_nand_bin/sb_card_burn_sfc_nand$ sudo mkfs.ext4 /dev/sdb8
将nor镜像全部拷贝到userdata分区, 对应/dev/sdb8
bhu@bhu-PC:~/ad100/build/output$ mkdir userdata
bhu@bhu-PC:~/ad100/build/output$ sudo mount /dev/sdb8 userdata/
bhu@bhu-PC:~/ad100/build/output$ sudo chmod 777 userdata/
bhu@bhu-PC:~/ad100/build/output$ mkdir -p userdata/sdcard_update/
bhu@bhu-PC:~/ad100/build/output$ touch userdata/sdcard_update/enable_update //2.1章节脚本会判断该文件是否存在,才会继续
bhu@bhu-PC:~/ad100/build/output$ cp image.bin userdata/sdcard_update/image.bin //2.1章节脚本中烧录的image.bin
bhu@bhu-PC:~/ad100/build/output$ sync
bhu@bhu-PC:~/ad100/build/output$ sudo umount userdata/
六 卡启动烧录flash
将卡插入开发板, 上电(msc0启动)查看串口打印, 可以看见系统烧录打印, 重新启动(SFC0启动) ,可以看见系统正常启动
Starting mdev... OK
/
Saving random seed: SKIP (read-only file system detected)
Check whether the partition table is initialized successfully!
fsck (busybox 1.31.1)
fsck: fsck.ext4: No such file or directory
Starting network: OK
killall: adbd: no process killed
Starting adb ...
mtd erase all /dev/mtd0
install_listener('tcp:5037','*smartsocket*')
sh: write error: No such device
mtd write all /dev/mtd0 /usr/data/sdcard_update/image.bin
mtd write image ok!