mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-27 15:12:36 +02:00
writeprotect.c: Split register value/mask calculation into pure func
Extract the code that converts `struct wp_bits` into a collection of register values and bit masks out of `write_wp_bits()` into a new function. This avoids monadic transformer stacks where unit-testing cannot penetrate well to give suitable coverage, therefore keep the bit logic in a separate pure function. BUG=b:260019525,b:259013033 BRANCH=none TEST=ninja test TEST=flashrom --wp-{{dis,en}able,range,list,status} on dedede Change-Id: I604478ecbb70392c5584bf5d87c76b6f20f882b1 Signed-off-by: Nikolai Artemiev <nartemiev@google.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/69846 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com> Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
This commit is contained in:
parent
cf030c000c
commit
438b4ef75a
@ -125,7 +125,7 @@ static enum flashrom_wp_result read_wp_bits(struct wp_bits *bits, struct flashct
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** Helper function for write_wp_bits(). */
|
||||
/** Helper function for get_wp_bits_reg_values(). */
|
||||
static void set_reg_bit(
|
||||
uint8_t *reg_values, uint8_t *bit_masks, uint8_t *write_masks,
|
||||
struct reg_bit_info bit, uint8_t value)
|
||||
@ -140,18 +140,16 @@ static void set_reg_bit(
|
||||
}
|
||||
}
|
||||
|
||||
/** Write WP configuration bits to the flash's registers. */
|
||||
static enum flashrom_wp_result write_wp_bits(struct flashctx *flash, struct wp_bits bits)
|
||||
/** Convert wp_bits to register values and write masks */
|
||||
static void get_wp_bits_reg_values(
|
||||
uint8_t *reg_values, uint8_t *bit_masks, uint8_t *write_masks,
|
||||
const struct reg_bit_map *reg_bits, struct wp_bits bits)
|
||||
{
|
||||
size_t i;
|
||||
const struct reg_bit_map *reg_bits = &flash->chip->reg_bits;
|
||||
memset(reg_values, 0, sizeof(uint8_t) * MAX_REGISTERS);
|
||||
memset(bit_masks, 0, sizeof(uint8_t) * MAX_REGISTERS);
|
||||
memset(write_masks, 0, sizeof(uint8_t) * MAX_REGISTERS);
|
||||
|
||||
/* Convert wp_bits to register values and masks */
|
||||
uint8_t reg_values[MAX_REGISTERS] = {0};
|
||||
uint8_t bit_masks[MAX_REGISTERS] = {0}; /* masks of valid bits */
|
||||
uint8_t write_masks[MAX_REGISTERS] = {0}; /* masks of written bits */
|
||||
|
||||
for (i = 0; i < bits.bp_bit_count; i++)
|
||||
for (size_t i = 0; i < bits.bp_bit_count; i++)
|
||||
set_reg_bit(reg_values, bit_masks, write_masks, reg_bits->bp[i], bits.bp[i]);
|
||||
|
||||
set_reg_bit(reg_values, bit_masks, write_masks, reg_bits->tb, bits.tb);
|
||||
@ -161,6 +159,15 @@ static enum flashrom_wp_result write_wp_bits(struct flashctx *flash, struct wp_b
|
||||
set_reg_bit(reg_values, bit_masks, write_masks, reg_bits->srl, bits.srl);
|
||||
/* Note: always setting WPS bit to zero until its fully supported. */
|
||||
set_reg_bit(reg_values, bit_masks, write_masks, reg_bits->wps, 0);
|
||||
}
|
||||
|
||||
/** Write WP configuration bits to the flash's registers. */
|
||||
static enum flashrom_wp_result write_wp_bits(struct flashctx *flash, struct wp_bits bits)
|
||||
{
|
||||
uint8_t reg_values[MAX_REGISTERS];
|
||||
uint8_t bit_masks[MAX_REGISTERS]; /* masks of valid bits */
|
||||
uint8_t write_masks[MAX_REGISTERS]; /* masks of written bits */
|
||||
get_wp_bits_reg_values(reg_values, bit_masks, write_masks, &flash->chip->reg_bits, bits);
|
||||
|
||||
/* Write each register whose value was updated */
|
||||
for (enum flash_reg reg = STATUS1; reg < MAX_REGISTERS; reg++) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user