You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.2 KiB

/*
* Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights reserved.
* Description: flash.h
* Author: SmartMedia_BSP
* Create: 2020-06-23
*/
#ifndef FLASHH
#define FLASHH
#include <stddef.h>
enum flash_type_t {
FT_SPIFLASH = 0,
FT_NAND = 1,
FT_EMMC = 2,
FT_NONE = 3,
};
struct flash_info_t {
enum flash_type_t type;
char name[32];
u_char ids[8];
int nr_ids;
uint32 pagesize; /* page size */
uint32 blocksize; /* block size */
uint32 oobsize; /* controller used oobsize */
uint32 oobused; /* yaffs2 oobsize used */
uint32 chipsize;
// uint64 chipsize;
uint32 nr_chips;
};
struct flash_ops_t;
struct flash_intf_t {
uint64 from;
uint64 length;
const struct flash_info_t *info;
struct flash_ops_t *ops;
};
/*
* parameter:
* from : offset by flash start address "0";
* length : open flash size, or real operation size;
* offset : offset by partition start address "from"
* if read partition start address, this parameter is "0";
* return:
* <= 0 : fail;
* > 0 : return real erase/write/read length;
*/
struct flash_ops_t {
const char *devname;
int (*open)(uint64 from, uint64 length);
void (*close)(struct flash_intf_t *intf);
int64 (*erase)(struct flash_intf_t *intf, uint64 offset, uint64 length);
int64 (*write)(struct flash_intf_t *intf, uint64 offset, uint64 length, char *buf, int withoob);
int64 (*read)(struct flash_intf_t *intf, uint64 offset, uint64 length, char *buf, int withoob);
struct flash_info_t *(*get_info)(void);
};
int flash_register(enum flash_type_t type, struct flash_ops_t *ops);
void *flash_open_range(uint32 flash, uint64 from, uint64 length);
void *flash_open_part(uint32 flash, const char *partname);
void flash_close(void *intf);
int64 flash_erase(void *intf, uint64 offset, uint64 length);
int64 flash_write(void *intf, uint64 offset, uint64 length, char *buf, int withoob);
int64 flash_read(void *intf, uint64 offset, uint64 length, char *buf, int withoob);
const char *flash_get_name(uint32 type);
void flash_show_info(const struct flash_info_t *info);
const void *flash_get_info(uint32 flash);
/* *************************************************************************** */
#endif