Norman James | 6a58a27 | 2015-10-07 14:34:16 -0500 | [diff] [blame] | 1 | #ifndef __LIBFLASH_H
|
| 2 | #define __LIBFLASH_H
|
| 3 |
|
| 4 | #include <stdint.h>
|
| 5 | #include <stdbool.h>
|
| 6 |
|
| 7 | #ifndef FL_INF
|
| 8 | #define FL_INF(fmt...) do { printf(fmt); } while(0)
|
| 9 | #endif
|
| 10 |
|
| 11 | #ifndef FL_DBG
|
| 12 | #define FL_DBG(fmt...) do { if (libflash_debug) printf(fmt); } while(0)
|
| 13 | #endif
|
| 14 |
|
| 15 | #ifndef FL_ERR
|
| 16 | #define FL_ERR(fmt...) do { printf(fmt); } while(0)
|
| 17 | #endif
|
| 18 |
|
| 19 | extern bool libflash_debug;
|
| 20 |
|
| 21 | /* API status/return:
|
| 22 | *
|
| 23 | * <0 = flash controller errors passed through,
|
| 24 | * 0 = success
|
| 25 | * >0 = libflash error
|
| 26 | */
|
| 27 |
|
| 28 | #define FLASH_ERR_MALLOC_FAILED 1
|
| 29 | #define FLASH_ERR_CHIP_UNKNOWN 2
|
| 30 | #define FLASH_ERR_PARM_ERROR 3
|
| 31 | #define FLASH_ERR_ERASE_BOUNDARY 4
|
| 32 | #define FLASH_ERR_WREN_TIMEOUT 5
|
| 33 | #define FLASH_ERR_WIP_TIMEOUT 6
|
| 34 | #define FLASH_ERR_BAD_PAGE_SIZE 7
|
| 35 | #define FLASH_ERR_VERIFY_FAILURE 8
|
| 36 | #define FLASH_ERR_4B_NOT_SUPPORTED 9
|
| 37 | #define FLASH_ERR_CTRL_CONFIG_MISMATCH 10
|
| 38 | #define FLASH_ERR_CHIP_ER_NOT_SUPPORTED 11
|
| 39 | #define FLASH_ERR_CTRL_CMD_UNSUPPORTED 12
|
| 40 | #define FLASH_ERR_CTRL_TIMEOUT 13
|
| 41 |
|
| 42 | /* Flash chip, opaque */
|
| 43 | struct flash_chip;
|
| 44 | struct spi_flash_ctrl;
|
| 45 |
|
| 46 | int flash_init(struct spi_flash_ctrl *ctrl, struct flash_chip **flash);
|
| 47 | void flash_exit(struct flash_chip *chip);
|
| 48 |
|
| 49 | int flash_get_info(struct flash_chip *chip, const char **name,
|
| 50 | uint32_t *total_size, uint32_t *erase_granule);
|
| 51 |
|
| 52 | /* libflash sets the 4b mode automatically based on the flash
|
| 53 | * size and controller capabilities but it can be overriden
|
| 54 | */
|
| 55 | int flash_force_4b_mode(struct flash_chip *chip, bool enable_4b);
|
| 56 |
|
| 57 | int flash_read(struct flash_chip *c, uint32_t pos, void *buf, uint32_t len);
|
| 58 | int flash_erase(struct flash_chip *c, uint32_t dst, uint32_t size);
|
| 59 | int flash_write(struct flash_chip *c, uint32_t dst, const void *src,
|
| 60 | uint32_t size, bool verify);
|
| 61 | int flash_smart_write(struct flash_chip *c, uint32_t dst, const void *src,
|
| 62 | uint32_t size);
|
| 63 |
|
| 64 | /* chip erase may not be supported by all chips/controllers, get ready
|
| 65 | * for FLASH_ERR_CHIP_ER_NOT_SUPPORTED
|
| 66 | */
|
| 67 | int flash_erase_chip(struct flash_chip *c);
|
| 68 |
|
| 69 | #endif /* __LIBFLASH_H */
|