mirror of
https://review.coreboot.org/flashrom.git
synced 2025-07-02 14:33:18 +02:00
tree/: Convert flashchip decode range func ptr to enum
Replace the `decode_range` function pointer in `struct flashchip` to an enum value. The enum value can be used to find the corresponding function pointer by passing it to `lookup_decode_range_func_ptr()`. Removing function pointers like `decode_range` makes it possible to represent chip data in a declarative format that does not have to be stored as C source code. BUG=b:242479049 BRANCH=none TEST=ninja && ninja test Signed-off-by: Nikolai Artemiev <nartemiev@google.com> Change-Id: If6d08d414d3d1ddadc95ca1d407fc87c23ab543d Reviewed-on: https://review.coreboot.org/c/flashrom/+/67195 Reviewed-by: Edward O'Callaghan <quasisec@chromium.org> Reviewed-by: Felix Singer <felixsinger@posteo.net> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:

committed by
Edward O'Callaghan

parent
bd8a02de6c
commit
2e00f73671
@ -174,11 +174,26 @@ static enum flashrom_wp_result write_wp_bits(struct flashctx *flash, struct wp_b
|
||||
return FLASHROM_WP_OK;
|
||||
}
|
||||
|
||||
static decode_range_func_t *lookup_decode_range_func_ptr(const struct flashchip *chip)
|
||||
{
|
||||
switch (chip->decode_range) {
|
||||
case DECODE_RANGE_SPI25: return &decode_range_spi25;
|
||||
/* default: total function, 0 indicates no decode range function set. */
|
||||
case NO_DECODE_RANGE_FUNC: return NULL;
|
||||
};
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/** Get the range selected by a WP configuration. */
|
||||
static enum flashrom_wp_result get_wp_range(struct wp_range *range, struct flashctx *flash, const struct wp_bits *bits)
|
||||
{
|
||||
flash->chip->decode_range(&range->start, &range->len, bits, flashrom_flash_getsize(flash));
|
||||
decode_range_func_t *decode_range = lookup_decode_range_func_ptr(flash->chip);
|
||||
if (decode_range == NULL)
|
||||
return FLASHROM_WP_ERR_OTHER;
|
||||
|
||||
decode_range(&range->start, &range->len, bits, flashrom_flash_getsize(flash));
|
||||
return FLASHROM_WP_OK;
|
||||
}
|
||||
|
||||
@ -424,7 +439,7 @@ static int set_wp_mode(struct wp_bits *bits, const enum flashrom_wp_mode mode)
|
||||
|
||||
static bool chip_supported(struct flashctx *flash)
|
||||
{
|
||||
return (flash->chip != NULL) && (flash->chip->decode_range != NULL);
|
||||
return (flash->chip != NULL) && (flash->chip->decode_range != NO_DECODE_RANGE_FUNC);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user