全志Tina Linux NOR Flash系统开发指南 最详细版本 支持所有全志芯片

1 简介编写目的此文档描述sunxi nor 模块的使用方法,为相关人员调试提供指导
适用范围boot0: 适用于brandy-2.0u-boot: 适用于u-boot-2018kernel: 适用于linux-4.9/linux-5.4 内核bsp 的开发人员、测试人员
2 模块介绍2.1 模块功能介绍linux 中spinor 体系结构如下图所示:
spi nor framework:这层主要是处理不同厂家的nor 物理特色差异,初始化spinor的工作状态,如工作线宽(1 线、2 线、4 线、8 线)、有效地址位(16m 以上的nor 需要使用4 地址模式),为上层mtd 提供读写擦接口。
对应代码目录:drivers/mtd/spi-nor/spi-nor.cm25p80(generic spi nor controller driver):这层主要对spi nor framework层传下来的数据封装成msg,传递给spi framework 层。对应代码目录:drivers/mtd/devices/m25p80.cspi framework:这层主要是将msg 加入ctl 的工作队列中,启动内核线程队列,处理队列中的msg。对应代码目录:drivers/spi/spi.cspi controller driver:这层初始化spi 控制器频率、时钟模式、cs 有效电平、大小端等配置,同时处理上层传下来的msg,通过cpu/dma 方式传输数据到fifo,再传输给外设spinor。对应代码目录:drivers/spi/spi-sunxi.c2.2 相关术语介绍术语解释说明
sunxi 指allwinner 的一系列soc 硬件平台
spi serial peripheral interface,同步串行外设接口
nor flash nor flash 是一种非易失闪存技术,是intel 在1988 年创建
mtd mtd(memory technology device 内存技术设备) 是用于访问memory 设备(rom、flash)的linux 的子系统
2.3 模块配置介绍2.3.1 longan 的配置和打包./build.sh configall available platform: 0. android 1. linuxchoice [linux]: 1... //配置根据需求选择all available flash: //flash类型,只区分nor和非nor方案,android方案无此选项,默认非nor 0. default 1. norchoice [default]: 1打包普通固件#./build.sh clean#./build.sh#./build.sh pack打包卡打印固件#./build.sh clean#./build.sh#./build.sh pack_debug在配置的过程中会把平台目录下的boardconfig.mk 的信息拷贝到.buildconfig 中。
2.3.2 sys_config 配置spinor 的boot0 启动阶段,部分参数是从boot0 头部获取的,而这些参数是我们在打包固件时,通过工具update_boot0 将sys_config.fex 中[spinor_para],更新到boot0 头部的,sys_config.fex 的[spinor_para] 配置参数如下:
[spinor_para];readcmd =0x6b;read_mode =4;write_mode =4;flash_size =16;delay_cycle =1;frequency =100000000;erase_size =64;lock_flag =0;sample_delay =0;sample_mode =2spi_sclk = port:pc00spi_cs = port:pc01spi0_mosi = port:pc02spi0_miso = port:pc03spi0_wp = port:pc04spi0_hold = port:pc05其中:
readcmd:boot0 用于读取数据的命令,不填默认用uboot 传递过来的readcmdread_mode、write_mode:boot0 的工作线宽(1、2、4),不填默认更加readcmd 决定线宽flash_size:flash 的大小delay_cycle:boot0 的采样延时配置,大于60mhz 配置为1,小于24mhz 配置为2,大于24mhz 小于60hz 配置为3frequency:boot0 的spi 工作频率,不填使用默认值50merase_size:boot0 的擦除单位lock_flag:锁功能是否打开sample_delay:boot0 的细调采样的采样延时,uboot、kernel 也会用到,默认不填等于0xaaaaffffsample_mode:boot0 的细调采样的采样模式,uboot、kernel 也会用到,默认不填等于0xaaaaffffspi_sclk、spi_cs、spi0_mosi、spi0_miso、spi0_wp 和spi0_hold 用于配置相应的gpio。2.3.3 uboot 配置2.3.3.1 编译和配置#make clean#make sun8iw19p1_nor_config ----启动的uboot (#make sun8iw19p1_config----烧写uboot)#make -j322.3.3.2 menuconfig 配置#cd brandy/brandy-2.0/u-boot-2018#make menuconfig进入device drivers
device drivers ---->[*]spi suppport ---->[*]sunxi flash support ---->
进入spi support
device drivers ---->[*]spi suppport ---->[*]sunxi spi driver
进入sunxi_flash_support
device drivers ---->[*]sunxi flash support ---->[*]support sunxi spinor devices
2.3.4 kernel 配置2.3.4.1 spinor-驱动配置#cd kernel/liunx-4.9#make arch=arm menuconfig进入device drivers
device drivers ---->memory technology device (mtd) support ---->[*]spi support ---->
进入menory technology device(mtd) support
device drivers ---->memory technology device (mtd) support ---->sunxi partitioning supportdirect char device access to mtd devicescaching block device access to mtd devicesself-contained mtd device drivers ---->spi-nor device support ---->
进入self-contained mtd device drivers(5.4 内核不需要选择此项)
device drivers ---->memory technology device (mtd) support ---->self-contained mtd device drivers ---->support most spi flash chips (at16df, m25p.....)
2.3.4.2 cmdline 方式选择boot opttions ---->
进入boot options
boot opttions ---->kernel command line type ---->
进入kernel command line type
boot opttions ---->kernel command line type ---->(x)use bootloade kernel arguments if available
2.3.4.3 文件系统配置进入file systems
file system ---->[*]miscellaneous filesystems ---->
• 进入miscellaneous filesystems
• incluede support for zlib compressed file systems (new)
• incluede support for lz4 compressed file systems (new)
• incluede support for lzo compressed file systems (new)
• incluede support for xz compressed file systems (new)
file system ---->[*]miscellaneous filesystems ---->[*]incluede support for xz compressed file systems (new)(压缩方式选择如下)
以上的压缩方式(zlib/lz4/lzo/xz)具体选择哪一种需要根据longan/build/mkcmd.sh 中如下代码使用的压缩方式而定,如下代码使用的是gzip 压缩方式,则内核file systems 中配置需选择lzo 压缩方式,若使用的是xz, 则需选择xz 压缩方式。
${rootfs} ${lichee_plat_out}/rootfs.squashfs -root-owned -no-progress -comp gzip -noappend2.4 源码目录介绍2.4.1 uboot 源码目录\\u-boot-2018drivers├──sunxi_flash ---sunxi_flash的初始化/退出/读/写/擦除等flash接口├─mmc ---mmc接口代码├─nand ---nand接口代码├─spinor ---spi nor接口代码├─sunxi_flash.c ---sunxi_flash操作接口└──其他├── spi --sunxi_spi的接口代码├─sunxi_spi.c ---具体代码的实现├──mtd├─spi├─sf_probe.c ---nand接口代码├─spinor ---spi nor接口代码├─sunxi_flash.c ---sunxi_flash2.4.2 kernel 源码目录longankernellinux-4.9drivers├── mtd├─spi-nor├─spi-nor.c ---spi nor驱动代码└──其他├── spi --spi的接口代码└── makefile ---编译文件版3 接口描述3.1 驱动物理层接口3.1.1 spi_nor_erasestatic int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)description:mtd erase interface
@mtd: mtd device structure
@instr: erase operation descrition structure
return:success return 0,fail return fail code**
3.1.2 spi_nor_readstatic int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,size_t *retlen, u_char *buf)description:mtd read interface
@mtd:mtd device structure
@from: offset to read from mtd device
@len: data len
@retlen: had read data len
@buf: data buffer
return:success return max_bitflips,fail return fail code**
3.1.3 spi_nor_writestatic int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,size_t *retlen, const u_char *buf)description:mtd write data interface
@to: offset to mtd device
@len: want write data len
@retlen:return the writen len
@buf: data buffer
return: success return 0, fail return code fail
3.1.4 spi_nor_lockstatic int spi_nor_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)description:check block is badblock or not@mtd:mtd device structure
@ofs: offset the mtd device start (align to simu block size)
@len:the length of the operating
return: success return 0, fail return code fail
3.1.5 spi_nor_unlockstatic int spi_nor_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)description:check block is badblock or not@mtd:mtd device structure
@ofs: offset the mtd device start (align to simu block size)
@len:the length of the operating
return: success return 0, fail return code fail
3.1.6 spi_nor_is_lockedstatic int spi_nor_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)description:check block is badblock or not@mtd:mtd device structure
@ofs: offset the mtd device start (align to simu block size)
@len:the length of the operating
return: is lock return 1, else return 0
3.1.7 spi_nor_has_lock_erasestatic int spi_nor_has_lock_erase(struct mtd_info *mtd, struct erase_info *instr)description:mtd has lock erase interface,first unlock to operate space, after the
completion of the flash lock up
@mtd: mtd device structure
@instr: erase operation descrition structure
return:success return 0,fail return fail code
3.1.8 spi_nor_has_lock_writestatic int spi_nor_has_lock_write(struct mtd_info *mtd, loff_t to, size_t len,size_t *retlen, const u_char *buf)description:mtd has lock write data interface,first unlock to operate space, after
the completion of the flash lock up
@to: offset to mtd device
@len: want write data len
@retlen:return the writen len
@buf: data buffer
return: success return 0, fail return code fail
3.2 uboot 应用接口3.2.1 sunxi_flash_spinor_probestatic int sunxi_flash_spinor_probe(void)description:spinor initialization,set the storage type。
return:zero on success, else a negative error code.
3.2.2 sunxi_flash_spinor_initstatic int sunxi_flash_spinor_init(int boot_mode, int res)description:spinor initialization。
@boot_mode:working mode
@res:the default is 0
return:zero on success, else a negative error code.
3.2.3 sunxi_flash_spinor_exitint sunxi_flash_spinor_exit(void)description:release registration is a resource for applications.
return:zero on success, else a negative error code.
3.2.4 sunxi_flash_spinor_writestatic int sunxi_flash_spinor_write(uint start_block, uint nblock, void *buffer)description:mtd write data interface.
@start_block:want write start sector
@nblock:want write sectorcount
@buffer:data buffer
return:zero on success, else a negative error code.
3.2.5 sunxi_flash_spinor_writestatic int sunxi_flash_spinor_write(uint start_block, uint nblock, void *buffer)description:mtd readdata interface.
@start_block:want read start sector
@nblock:want read sector count
@buffer:data buffer
return:zero on success, else a negative error code.
3.2.6 sunxi_flash_spinor_erasestatic int sunxi_flash_spinor_erase(int erase, void *mbr_buffer)description:erase boot || partition data.
@erase:erase flag
@buffer:the default is null
return:zero on success, else a negative error code.
3.2.7 sunxi_flash_spinor_force_eraseint sunxi_flash_spinor_force_erase(void)description:erase boot & partition data.
return:zero on success, else a negative error code.
3.2.8 sunxi_flash_spinor_flushint sunxi_flash_spinor_flush(void)description:flush physical cache data to flash.
return:zero on success, else a negative error code.
3.2.9 sunxi_flash_spinor_download_splstatic int sunxi_flash_spinor_download_spl(unsigned char *buf, int len, unsigned int ext)description:write boot0.
@buf:boot0 data buffer
@len:boot0 data len
@ext:storage type
return:zero on success, else a negative error code.
3.2.10 sunxi_flash_spinor_download_tocstatic int sunxi_flash_spinor_download_toc(unsigned char *buf, int len, unsigned int ext)description:write uboot.
@buf:uboot data buffer
@len:uboot data len
@ext:storage type
return:zero on success, else a negative error code.
4 使用例子4.1 uboot shell 使用4.1.1 sunxi_flashmem_addr:内存地址,0x40000000 之后可以随便选取如:0x45000000,0x46000000
part_name:分区文件名,boot-resource、env、boot、rootfs
size:可以省略,默认读取整个分区文件
sunxi_flash read [size] 读取flash 中的分区文件到内存中
例:使用sunxi_flash read 命令将boot 分区读入到0x49000000 中,然后使用md 命令读取
0x49000000 中的内容。
验证方法:
0x49000000 读入前与读入后数据有没有发生变化在out/pack_out 目录下找到对应的分区文件,使用hexdump -cv boot.fex -n 500 命
令输出分区文件的数据,对比一致即读入成功。
sunxi_flash write [size] 将内存中的数据,写入到分区中
例:
1)使用mm 命令修改内存内容
2)使用sunxi_flash write 0x44000000 env 将内存中的数据写入env 分区
3)重新将env 分区读入内存中,对比一致表示写入成功


纳多德助力国家超算深圳中心,建设高性能计算通用测试平台
奥迪合作法国全球生物能源公司,助力推进新燃料发动机测试研究
220V指示灯电路哪个更好一些?
信号处理电路-移相电路设计
荣耀20PRO采用了挖孔屏设计是目前DxOMark机评分的第二高分
全志Tina Linux NOR Flash系统开发指南 最详细版本 支持所有全志芯片
区块链除了圈钱与炒币还有什么用?
DiBcom推出最新移动电视解决方案DIB10096
SmartNIC、DPU和IPU的定义和分类
ZXP0120ADB型压力传感器在可穿戴设备的作用
PLC控制系统梯形图的特点及结构分析
Zeiss结合VR和眼球追踪技术,提高人们对眼部疾病的认识
SMT导电硅橡胶在ADAS摄像头的ESD整改案例
生物识别如何应对AI生成的指纹
智能摄像头与其他家用电器设备组合在一起会发生哪些神器的事情吗?
常见的光模块封装形式
探索中国工业互联网的数字化转型之路
笔记本液晶屏幕保养与维护
财政部等三部门:《关于支持集成电路产业和软件产业发展进口税收政策的通知》
倒闸操作模拟图