mirror of
https://review.coreboot.org/flashrom.git
synced 2025-07-02 06:23:18 +02:00
writeprotect: Add function to get register values and WP bit masks
Add a new wp_cfg_to_reg_values() function that takes a generic wp_cfg instance and returns the chip-specific values that need to be written to the chip's registers to enable the specified protection range/mode. The function returns three values for each chip register: - reg_values[reg] - Value writeprotect will write to reg - bit_masks[reg] - Bit mask for WP-related bits in reg - write_masks[reg] - Bit mask for writable WP-related bits in reg (i.e. the ones writeprotect will try to write) BUG=b:260019525,b:259013033,260020006 BRANCH=none TEST=ninja test Change-Id: Ib2a47153b230c9f82bb4eca357c335f2abbacc20 Signed-off-by: Nikolai Artemiev <nartemiev@google.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/69847 Reviewed-by: Edward O'Callaghan <quasisec@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
This commit is contained in:

committed by
Edward O'Callaghan

parent
1d6d23bee2
commit
29a3a09f91
@ -597,3 +597,31 @@ out:
|
||||
free(range_pairs);
|
||||
return ret;
|
||||
}
|
||||
|
||||
enum flashrom_wp_result wp_cfg_to_reg_values(
|
||||
uint8_t *reg_values, uint8_t *bit_masks, uint8_t *write_masks,
|
||||
struct flashctx *flash, const struct flashrom_wp_cfg *cfg)
|
||||
{
|
||||
struct wp_bits bits;
|
||||
|
||||
if (!chip_supported(flash))
|
||||
return FLASHROM_WP_ERR_CHIP_UNSUPPORTED;
|
||||
|
||||
enum flashrom_wp_result ret = read_wp_bits(&bits, flash);
|
||||
if (ret != FLASHROM_WP_OK)
|
||||
return ret;
|
||||
|
||||
/* Set protection range */
|
||||
ret = set_wp_range(&bits, flash, cfg->range);
|
||||
if (ret != FLASHROM_WP_OK)
|
||||
return ret;
|
||||
|
||||
/* Set protection mode */
|
||||
ret = set_wp_mode(&bits, cfg->mode);
|
||||
if (ret != FLASHROM_WP_OK)
|
||||
return ret;
|
||||
|
||||
get_wp_bits_reg_values(reg_values, bit_masks, write_masks, &flash->chip->reg_bits, bits);
|
||||
|
||||
return FLASHROM_WP_OK;
|
||||
}
|
||||
|
Reference in New Issue
Block a user