summaryrefslogtreecommitdiffstats
path: root/include/flash.h
diff options
context:
space:
mode:
authorEdward O'Callaghan <quasisec@google.com>2022-08-29 10:36:21 +1000
committerEdward O'Callaghan <quasisec@chromium.org>2022-11-11 13:04:07 +0000
commit3bba710d98b60eba7ebbae0869fd58f7dc987afd (patch)
tree0a5fc97c3edad996c21b4c66828dd366e9d0792f /include/flash.h
parent3c44e12a287ce9a91cf97c3303bf4222f63d25c7 (diff)
downloadflashrom-3bba710d98b60eba7ebbae0869fd58f7dc987afd.tar.gz
flashrom-3bba710d98b60eba7ebbae0869fd58f7dc987afd.tar.bz2
flashrom-3bba710d98b60eba7ebbae0869fd58f7dc987afd.zip
tree/: Convert flashchip erase_block func ptr to enumerate
This forges the way for flashchips.c to be pure declarative data and lookup functions for dispatch to be pure. This means that the flashchips data could be extracted out to be agnostic data of the flashrom code and algorithms. Change-Id: I02ae7e4c67c5bf34ec2fd7ffe4af8a2aba6fd5e5 Signed-off-by: Edward O'Callaghan <quasisec@google.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/69133 Reviewed-by: Angel Pons <th3fanbus@gmail.com> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'include/flash.h')
-rw-r--r--include/flash.h75
1 files changed, 39 insertions, 36 deletions
diff --git a/include/flash.h b/include/flash.h
index 03c1e2c69..238d0101e 100644
--- a/include/flash.h
+++ b/include/flash.h
@@ -268,41 +268,44 @@ enum read_func {
typedef int (read_func_t)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
int read_flash(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
-#define NO_BLOCK_ERASE_FUNC NULL
-#define SPI_BLOCK_ERASE_EMULATION &spi_block_erase_emulation
-#define SPI_BLOCK_ERASE_20 &spi_block_erase_20
-#define SPI_BLOCK_ERASE_21 &spi_block_erase_21
-#define SPI_BLOCK_ERASE_40 &spi_block_erase_40
-#define SPI_BLOCK_ERASE_50 &spi_block_erase_50
-#define SPI_BLOCK_ERASE_52 &spi_block_erase_52
-#define SPI_BLOCK_ERASE_53 &spi_block_erase_53
-#define SPI_BLOCK_ERASE_5C &spi_block_erase_5c
-#define SPI_BLOCK_ERASE_60 &spi_block_erase_60
-#define SPI_BLOCK_ERASE_62 &spi_block_erase_62
-#define SPI_BLOCK_ERASE_81 &spi_block_erase_81
-#define SPI_BLOCK_ERASE_C4 &spi_block_erase_c4
-#define SPI_BLOCK_ERASE_C7 &spi_block_erase_c7
-#define SPI_BLOCK_ERASE_D7 &spi_block_erase_d7
-#define SPI_BLOCK_ERASE_D8 &spi_block_erase_d8
-#define SPI_BLOCK_ERASE_DB &spi_block_erase_db
-#define SPI_BLOCK_ERASE_DC &spi_block_erase_dc
-#define S25FL_BLOCK_ERASE &s25fl_block_erase
-#define S25FS_BLOCK_ERASE_D8 &s25fs_block_erase_d8
-#define JEDEC_SECTOR_ERASE &erase_sector_jedec
-#define JEDEC_BLOCK_ERASE &erase_block_jedec
-#define JEDEC_CHIP_BLOCK_ERASE &erase_chip_block_jedec
-#define OPAQUE_ERASE &erase_opaque
-#define SPI_ERASE_AT45CS_SECTOR &spi_erase_at45cs_sector
-#define SPI_ERASE_AT45DB_BLOCK &spi_erase_at45db_block
-#define SPI_ERASE_AT45DB_CHIP &spi_erase_at45db_chip
-#define SPI_ERASE_AT45DB_PAGE &spi_erase_at45db_page
-#define SPI_ERASE_AT45DB_SECTOR &spi_erase_at45db_sector
-#define ERASE_CHIP_28SF040 &erase_chip_28sf040
-#define ERASE_SECTOR_28SF040 &erase_sector_28sf040
-#define ERASE_BLOCK_82802AB &erase_block_82802ab
-#define ERASE_SECTOR_49LFXXXC &erase_sector_49lfxxxc
-#define STM50_SECTOR_ERASE &erase_sector_stm50
-#define EDI_CHIP_BLOCK_ERASE &edi_chip_block_erase
+enum block_erase_func {
+ NO_BLOCK_ERASE_FUNC = 0, /* 0 indicates no block erase function set. */
+ SPI_BLOCK_ERASE_EMULATION = 1,
+ SPI_BLOCK_ERASE_20,
+ SPI_BLOCK_ERASE_21,
+ SPI_BLOCK_ERASE_40,
+ SPI_BLOCK_ERASE_50,
+ SPI_BLOCK_ERASE_52,
+ SPI_BLOCK_ERASE_53,
+ SPI_BLOCK_ERASE_5C,
+ SPI_BLOCK_ERASE_60,
+ SPI_BLOCK_ERASE_62,
+ SPI_BLOCK_ERASE_81,
+ SPI_BLOCK_ERASE_C4,
+ SPI_BLOCK_ERASE_C7,
+ SPI_BLOCK_ERASE_D7,
+ SPI_BLOCK_ERASE_D8,
+ SPI_BLOCK_ERASE_DB,
+ SPI_BLOCK_ERASE_DC,
+ S25FL_BLOCK_ERASE,
+ S25FS_BLOCK_ERASE_D8,
+ JEDEC_SECTOR_ERASE,
+ JEDEC_BLOCK_ERASE,
+ JEDEC_CHIP_BLOCK_ERASE,
+ OPAQUE_ERASE,
+ SPI_ERASE_AT45CS_SECTOR,
+ SPI_ERASE_AT45DB_BLOCK,
+ SPI_ERASE_AT45DB_CHIP,
+ SPI_ERASE_AT45DB_PAGE,
+ SPI_ERASE_AT45DB_SECTOR,
+ ERASE_CHIP_28SF040,
+ ERASE_SECTOR_28SF040,
+ ERASE_BLOCK_82802AB,
+ ERASE_SECTOR_49LFXXXC,
+ STM50_SECTOR_ERASE,
+ EDI_CHIP_BLOCK_ERASE,
+ TEST_ERASE_INJECTOR, /* special case must come last. */
+};
struct flashchip {
const char *vendor;
@@ -366,7 +369,7 @@ struct flashchip {
} eraseblocks[NUM_ERASEREGIONS];
/* a block_erase function should try to erase one block of size
* 'blocklen' at address 'blockaddr' and return 0 on success. */
- int (*block_erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
+ enum block_erase_func block_erase;
} block_erasers[NUM_ERASEFUNCTIONS];
int (*printlock) (struct flashctx *flash);