建设银行信用卡网站是哪个好,百度云网站建设教程视频,浅谈博物馆网站建设的意义,自动推广软件Linux NOR 开发指南
1 简介
编写目的
此文档描述Sunxi NOR 模块的使用方法#xff0c;为相关人员调试提供指导
适用范围 boot0: 适用于brandy-2.0u-boot: 适用于u-boot-2018kernel: 适用于linux-4.9/linux-5.4 内核
BSP 的开发人员、测试人员
2 模块介绍
2.1 模块功能…Linux NOR 开发指南
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.c
M25P80generic SPI NOR controller driver这层主要对SPI NOR Framework
层传下来的数据封装成msg传递给SPI framework 层。
对应代码目录drivers/mtd/devices/m25p80.c
SPI Framework这层主要是将msg 加入ctl 的工作队列中启动内核线程队列处理队列
中的msg。
对应代码目录drivers/spi/spi.c
SPI controller driver这层初始化SPI 控制器频率、时钟模式、cs 有效电平、大小端等
配置同时处理上层传下来的msg通过CPU/DMA 方式传输数据到FIFO再传输给外设
SPINOR。
对应代码目录drivers/spi/spi-sunxi.c2.2 相关术语介绍
术语解释说明Sunxi指Allwinner 的一系列SOC 硬件平台SPISerial Peripheral Interface同步串行外设接口NOR FlashNOR Flash 是一种非易失闪存技术是Intel 在1988 年创建MTDMTD(memory technology device 内存技术设备) 是用于访问memory 设备ROM、flash的Linux 的子系统
2.3 模块配置介绍
2.3.1 longan 的配置和打包
./build.sh config
All available platform:0. android1. linux
Choice [linux]: 1
... //配置根据需求选择
All available flash: //flash类型只区分nor和非nor方案Android方案无此选项默认非nor0. default1. nor
Choice [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 2
spi_sclk port:PC00402default
spi_cs port:PC01412default
spi0_mosi port:PC02402default
spi0_miso port:PC03402default
spi0_wp port:PC04402default
spi0_hold port:PC05402default其中
readcmdboot0 用于读取数据的命令不填默认用uboot 传递过来的readcmd
read_mode、write_modeboot0 的工作线宽1、2、4不填默认更加readcmd 决
定线宽
flash_sizeflash 的大小
delay_cycleboot0 的采样延时配置大于60MHZ 配置为1小于24MHZ 配置为2
大于24MHZ 小于60HZ 配置为3
frequencyboot0 的SPI 工作频率不填使用默认值50M
erase_sizeboot0 的擦除单位
lock_flag锁功能是否打开
sample_delayboot0 的细调采样的采样延时uboot、kernel 也会用到默认不填等于
0xaaaaffff
sample_modeboot0 的细调采样的采样模式uboot、kernel 也会用到默认不填等于
0xaaaaffff
spi_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 devices2.3.4 KERNEL 配置
2.3.4.1 SPINOR-驱动配置
#cd kernel/liunx-4.9
#make ARCHarm 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 support
*Direct char device access to MTD devices
*Caching block device access to MTD devices
Self-contained MTD device drivers ----
SPI-NOR device support ----进入Self-contained MTD device drivers5.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 available2.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-2018\drivers
├──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 源码目录
\longan\kernel\linux-4.9\drivers\
├── mtd
├─spi-nor
├─spi-nor.c ---spi nor驱动代码
└──其他
├── spi --spi的接口代码
└── makefile ---编译文件
版3 接口描述
3.1 驱动物理层接口
3.1.1 spi_nor_erase
static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)descriptionmtd erase interface mtd MTD device structure instr erase operation descrition structure returnsuccess return 0fail return fail code**
3.1.2 spi_nor_read
static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
size_t *retlen, u_char *buf)descriptionmtd read interface mtdMTD device structure from offset to read from MTD device len data len retlen had read data len buf data buffer returnsuccess return max_bitflipsfail return fail code**
3.1.3 spi_nor_write
static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
size_t *retlen, const u_char *buf)descriptionmtd write data interface to offset to MTD device len want write data len retlenreturn the writen len buf data buffer return success return 0, fail return code fail
3.1.4 spi_nor_lock
static int spi_nor_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
descriptioncheck block is badblock or notmtdMTD device structure ofs: offset the mtd device start (align to simu block size) lenThe length of the operating return success return 0, fail return code fail
3.1.5 spi_nor_unlock
static int spi_nor_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
descriptioncheck block is badblock or notmtdMTD device structure ofs: offset the mtd device start (align to simu block size) lenThe length of the operating return success return 0, fail return code fail
3.1.6 spi_nor_is_locked
static int spi_nor_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)
descriptioncheck block is badblock or notmtdMTD device structure ofs: offset the mtd device start (align to simu block size) lenThe length of the operating return Is lock return 1, else return 0
3.1.7 spi_nor_has_lock_erase
static int spi_nor_has_lock_erase(struct mtd_info *mtd, struct erase_info *instr)descriptionmtd has lock erase interfaceFirst unlock to operate space, after the completion of the flash lock up mtd MTD device structure instr erase operation descrition structure returnsuccess return 0fail return fail code
3.1.8 spi_nor_has_lock_write
static int spi_nor_has_lock_write(struct mtd_info *mtd, loff_t to, size_t len,
size_t *retlen, const u_char *buf)descriptionmtd has lock write data interfaceFirst unlock to operate space, after the completion of the flash lock up to offset to MTD device len want write data len retlenreturn the writen len buf data buffer return success return 0, fail return code fail
3.2 Uboot 应用接口
3.2.1 sunxi_flash_spinor_probe
static int sunxi_flash_spinor_probe(void)descriptionSPINOR initializationSet the storage type。 returnzero on success, else a negative error code.
3.2.2 sunxi_flash_spinor_init
static int sunxi_flash_spinor_init(int boot_mode, int res)descriptionSPINOR initialization。 boot_modeWorking mode resThe default is 0 returnzero on success, else a negative error code.
3.2.3 sunxi_flash_spinor_exit
int sunxi_flash_spinor_exit(void)descriptionRelease registration is a resource for applications. returnzero on success, else a negative error code.
3.2.4 sunxi_flash_spinor_write
static int sunxi_flash_spinor_write(uint start_block, uint nblock, void *buffer)descriptionmtd write data interface. start_blockwant write start sector nblockwant write sectorcount bufferdata buffer
returnzero on success, else a negative error code.
3.2.5 sunxi_flash_spinor_write
static int sunxi_flash_spinor_write(uint start_block, uint nblock, void *buffer)descriptionmtd readdata interface. start_blockwant read start sector nblockwant read sector count bufferdata buffer returnzero on success, else a negative error code.
3.2.6 sunxi_flash_spinor_erase
static int sunxi_flash_spinor_erase(int erase, void *mbr_buffer)descriptionerase boot || partition data. eraseerase flag bufferThe default is NULL returnzero on success, else a negative error code.
3.2.7 sunxi_flash_spinor_force_erase
int sunxi_flash_spinor_force_erase(void)descriptionerase boot partition data. returnzero on success, else a negative error code.
3.2.8 sunxi_flash_spinor_flush
int sunxi_flash_spinor_flush(void)descriptionFlush physical cache data to flash.
returnzero on success, else a negative error code.
3.2.9 sunxi_flash_spinor_download_spl
static int sunxi_flash_spinor_download_spl(unsigned char *buf, int len, unsigned int ext)descriptionwrite boot0. bufboot0 data buffer lenboot0 data len extstorage type returnzero on success, else a negative error code.
3.2.10 sunxi_flash_spinor_download_toc
static int sunxi_flash_spinor_download_toc(unsigned char *buf, int len, unsigned int ext)descriptionwrite uboot. bufuboot data buffer lenuboot data len extstorage type returnzero on success, else a negative error code.
4 使用例子
4.1 uboot shell 使用
4.1.1 sunxi_flash
mem_addr内存地址0x40000000 之后可以随便选取如0x450000000x46000000 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 分区读入内存中对比一致表示写入成功