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.

224 lines
8.9 KiB

/*
* Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights reserved.
* Description: IAPI head file for flash
* Author: Hisilicon
* Create: 2020-10-15
*/
#ifndef __UAPI_FLASH__H__
#define __UAPI_FLASH__H__
#include "td_type.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* __cplusplus */
#define FLASH_NAME_LEN 32 /* Flash Name max length */
#define INVALID_FD (-1)
/* Read and write without OOB, for example: kernel/uboot/ubi/cramfs.. */
#define UAPI_FLASH_RW_FLAG_RAW (0x0)
/* Read and write with OOB, example: yaffs2 file system image */
#define UAPI_FLASH_RW_FLAG_WITH_OOB (0x1)
/* Erase before write */
#define UAPI_FLASH_RW_FLAG_ERASE_FIRST (0x2)
/* This macro for return value when nand flash have bad block or valid length
* less partition length.
* CNcomment: nand,//,/,
* ,//, CNend
*/
#define UAPI_FLASH_END_DUETO_BADBLOCK (-10)
/* flash type */
typedef enum {
UAPI_FLASH_TYPE_AUTO = 0x0, /* Auto flash type */
UAPI_FLASH_TYPE_NOR_0 = 0x1, /* SPI NOR flash type */
UAPI_FLASH_TYPE_NAND_0 = 0x4, /* NAND flash type */
UAPI_FLASH_TYPE_EMMC_0 = 0x8, /* eMMC flash type */
UAPI_FLASH_TYPE_UFS_0 = 0xC, /* UFS flash type */
UAPI_FLASH_TYPE_MAX /* Invalid flash type */
} uapi_flash_type;
typedef enum {
RD = 0x01,
WR = 0x02
} pmode_t;
/* Flash partition access permission type */
typedef enum {
ACCESS_NONE = 0,
ACCESS_RD = (1 << RD),
ACCESS_WR = (1 << WR),
ACCESS_RDWR = (ACCESS_RD | ACCESS_WR),
ACCESS_BUTT
} uapi_flash_access_perm;
/*
* struct uapi_flash_partinfo - Flash partition descriptions
* @start_addr: Partiton start address
* @part_size: Partition size
* @dev_name: The device node name where this partition
* @part_name: The partition name of this partition
* @perm: The partition access permission type
*/
typedef struct {
td_u64 start_addr;
td_u64 part_size;
td_char dev_name[FLASH_NAME_LEN];
td_char part_name[FLASH_NAME_LEN];
uapi_flash_access_perm perm;
} uapi_flash_partinfo;
/*
* struct uapi_flash_info - flash information
* @total_size: flash total size
* @part_number: flash partition number
* @block_size: flash block size
* @page_size: flash page size
* @oob_size: flash OOB size
* @open_addr: flash open address
* @open_len: flash open length
* @flash_type: flash type
* @part_info: partition descriptions on this flash
*/
typedef struct {
td_u64 total_size;
td_u64 part_number;
td_u64 open_addr;
td_u64 open_len;
td_u32 block_size;
td_u32 page_size;
td_u32 oob_size;
uapi_flash_type flash_type;
uapi_flash_partinfo *part_info;
} uapi_flash_info;
/*
* Brief: Open flash partition by type and name
* Note: partition name for spi/nand, use '/dev/mtdx' as partition name; use
* '/dev/mmcblk0px' as partion name for EMMC
* CNcomment: EMMC(SPI/NAND),/dev/mtdxEMMC
* /dev/mmcblk0px
* attention N/A
* param[in] flash_type Flash type CNcomment: flash CNend
* param[in] partition_name Partition name CNcomment: CNend
* retval :td_handle Success. CNcomment:flash CNend
* retval :INVALID_FD Failed. CNcomment: CNend
* see N/A
*/
td_handle uapi_flash_open(uapi_flash_type flash_type, const td_char *partition_name);
/*
* Brief: Open flash partition by type and name
* Note: partition name for spi/nand, use '/dev/mtdx' as partition name; use
* '/dev/mmcblk0px' as partion name for EMMC
* CNcomment: EMMC(SPI/NAND),/dev/mtdxEMMC
* /dev/mmcblk0px
* attention N/A
* param[in] flash_type Flash type CNcomment: flash CNend
* param[in] address Address offset CNcomment: CNend
* param[in] len Open length CNcomment: flash CNend
* retval :td_handle Success. CNcomment:flash CNend
* retval :INVALID_FD Failed. CNcomment: CNend
* see N/A
*/
td_handle uapi_flash_open_by_addr(uapi_flash_type flash_type, td_u64 address, td_u64 len);
/*
* Brief: Close opend flash handle
* Note: partition name for spi/nand, use '/dev/mtdx' as partition name; use
* '/dev/mmcblk0px' as partion name for EMMC
* CNcomment: EMMC(SPI/NAND),/dev/mtdxEMMC
* /dev/mmcblk0px
* attention N/A
* param[in] handle Flash handle CNcomment: flash CNend
* retval :TD_SUCCESS Success. CNcomment: CNend
* retval :TD_FAILURE Failed. CNcomment: CNend
* see N/A
*/
td_s32 uapi_flash_close(td_handle handle);
/*
* Brief: Erase Flash partition
* CNcomment: Flash
* attention N/A
* param[in] handle Flash handle CNcomment: flash CNend
* param[in] offset Address offset CNcomment: CNend
* param[in] len Erase length CNcomment: flash CNend
* retval :TotalErase Erase total length. CNcomment: CNend
* retval :TD_FAILURE Failed. CNcomment: CNend
* see N/A
*/
td_s64 uapi_flash_erase(td_handle handle, td_u64 offset, td_u64 len);
/*
* Brief: Read data from flash
* CNcomment: Flash
* attention N/A
* param[in] handle Flash handle CNcomment: flash CNend
* param[in] offset Address offset CNcomment: CNend
* param[in] buf Data buffer pointer CNcomment: buffer CNend
* param[in] len Read length CNcomment: flash CNend
* param[in] flags Read flags, OOB flag use UAPI_FLASH_RW_FLAG_WITH_OOB if data
* includes OOB data
* CNcomment: flash, UAPI_FLASH_RW_FLAG_WITH_OOB
* OOB CNend
* retval :TotalRead Read total length. CNcomment: CNend
* retval :TD_FAILURE Failed. CNcomment: CNend
* retval :UAPI_FLASH_END_DUETO_BADBLOCK
* Return when bad block exist, caller need to check the read result.
* CNcomment: Flash(,,
* ) CNend
*/
td_s64 uapi_flash_read(td_handle handle, td_u64 offset, td_u8 *buf, td_u64 len, td_u32 flags);
/*
* Brief: Write data to flash
* CNcomment: Flash
* attention 1) forbidden used the function when yaffs filesystem is using
* 2) can use UAPI_FLASH_RW_FLAG_ERASE_FIRST manner write flah , can write over
* all partition one time or write with block
* CNcomment: 1) 使yaffs
* 2) Flash使UAPI_FLASH_RW_FLAG_ERASE_FIRST
* yaffs2
* EXT_Flash_Erase CNend
* param[in] handle Flash handle CNcomment: flash CNend
* param[in] offset Address offset CNcomment: CNend
* param[in] buf Data buffer pointer CNcomment: buffer CNend
* param[in] len Read length CNcomment: flash CNend
* param[in] flags Write flags, OOB flag use UAPI_FLASH_RW_FLAG_WITH_OOB if data includes OOB data
* CNcomment: flash,UAPI_FLASH_RW_FLAG_WITH_OOB
* OOB CNend
* retval :TotalWrite Write total length. CNcomment: CNend
* retval :TD_FAILURE Failed. CNcomment: CNend
* retval :UAPI_FLASH_END_DUETO_BADBLOCK
* Return when bad block exist, caller need to check the read result.
* CNcomment: Flash(,,
* ) CNend
*/
td_s64 uapi_flash_write(td_handle handle, td_u64 offset, td_u8 *buf, td_u64 len, td_u32 flags);
/*
* Brief: Get flash information
* CNcomment: Flash
* attention N/A
* param[in] handle Flash handle CNcomment: flash CNend
* param[out] flash_info Flash information pointer CNcomment: CNend
* retval :TD_SUCCESS Success. CNcomment: CNend
* retval :TD_FAILURE Failed. CNcomment: CNend
* see N/A
*/
td_s32 uapi_flash_getinfo(td_handle handle, uapi_flash_info *flash_info);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */
#endif /* __UAPI_FLASH__H__ */