W25X芯片为norflash芯片,存储空间较大,可以进行分区管理。
分区表示将norflash划分为多个盘,类似电脑C盘、D盘、E盘等。对每个盘进行各自的操作。
例如将norflash配置为4个分区:
#define MAX_NORFLASH_PART_NUM 4
static struct norflash_partition nor_part[MAX_NORFLASH_PART_NUM];//nor分区
分区信息结构体如下:
struct norflash_partition {
const char *name;//名称
u32 start_addr;//开始地址
u32 size;//大小
struct device device;//设备
};
每个分区有字节的盘符name,开始的地址,分区的大小,设备信息。
这里设备信息结构体如下:
struct device {
atomic_t ref;//设备被引用的计数,涉及设备关闭卸载等
void *private_data;//私有数据
const struct device_operations *ops;//设备操作
void *platform_data;//平台数据
void *driver_data;//驱动数据
};
typedef struct {
int counter;
} atomic_t;
ref仅为一个计数信息。
//设备操作函数
struct device_operations {
bool (*online)(const struct dev_node *node);//在线
int (*init)(const struct dev_node *node, void *);//初始化
int (*open)(const char *name, struct device **device, void *arg);//打开
int (*read)(struct device *device, void *buf, u32 len, u32);//读
int (*write)(struct device *device, void *buf, u32 len, u32);//写
int (*seek)(struct device *device, u32 offset, int orig);//设置读取指针位置
int (*ioctl)(struct device *device, u32 cmd, u32 arg);//io控制
int (*close)(struct device *device);//关闭设备
};
以上是分区信息和