arm板子写flash(2)
imx6arm板子写spiflash的代码第一篇博客地址在下面,这里主要写一下测试,我们不知道我们写进入的数据是否正确,前面把写进入的数据读出去进行打印,当文件为几兆字节时,密密麻麻的二级制怎么看, 这里测试写入一些exe,pdf文件进行测试。
http://blog.csdn.net/chenqianleo/article/details/73658493
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/types.h>
#include <linux/spi/spidev.h>
#include <string.h>
/*
* write a file to spi_flash
*/
#define W25_WRITE_ENABLE 0x06
#define W25_WRITE_DISABLE 0x04
#define W25_READ_STATUS_1 0x05
#define W25_READ_STATUS_2 0x35
#define W25_WRITE_STATUS 0x01
#define w25_WRITE_SATTUS_ENABLE 0x50
#define W25_READ_DATA 0x03
#define W25_READ_FAST_DATA 0x0B
#define W25_ERASE_SECTOR 0x20
#define W25_ERASE_BLOCK 0xD8
#define W25_ERASE_CHIP 0xc7
#define W25_PAGE_PROGRAM 0x02
#define W25_CHIP_ID 0x9F
#define RDSR_CNT 1000
#define W25_SR_BUSY 0x01
#define FLASH_MAX_SIZE (8*1024*1024)
#define ONE_SELECTOR_SIZE (4*1024)
#define WRITE_READ_ONCE_SIZE 256
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
static const char* spi_device = "/dev/spidev2.2";
static unsigned char mode;
static unsigned char bits = 8;
static unsigned int speed = 3000000;
static unsigned short delay;
static unsigned char buf[256] = {
0};
static unsigned char rxbuffer[1];
static unsigned char txbuffer[260];
static int getFileSize(const char* name);
static void dis_array(const char* info , const unsigned char* buf, unsigned int len);
static int w25_write_read(int fd , const char* wbuf,unsigned int wlen,
const char* rbuf , unsigned int rlen);
static int wait_for_idle(int fd);
static int write_spiflash(int fd ,char* buf, int offset ,
int address_one, int address_two , int address_three);
static int write_spiflash_finally(int fd ,char* buf, int offset , int num,
int address_one, int address_two , int address_three);
static void read_spiflash(int fd, int address_one , int address_two,
int address_three);
static