mirror of
https://review.coreboot.org/flashrom.git
synced 2025-10-27 11:22:10 +01:00
flashrom.c: move can_change_target_regions check below wp unlock
We should check if target regions are writable after trying to unlock
them, not before.
Tested on PC Engines APU4A:
```
$ ./flashrom -p internal -c W25Q64BV/W25Q64CV/W25Q64FV --wp-status
(...)
Protection range: start=0x00400000 length=0x00400000 (upper 1/2)
Protection mode: hardware
```
Before this PR trying to write wp protected region:
```
$ ./flashrom -p internal -c W25Q64BV/W25Q64CV/W25Q64FV -l \
<(echo -e '00300000:00500000 wp\n') -i wp -w image.bin
```
Failed with:
```
cannot fully update wp region (0x300000..0x500000) due to chip's
write-protection
```
With this change:
```
Using region: "wp".
coreboot table found at 0x7ecc2000.
Found chipset "AMD FCH".
Enabling flash write... OK.
Found Winbond flash chip "W25Q64BV/W25Q64CV/W25Q64FV" (8192 kB, SPI)
mapped at physical address 0x00000000ff800000.
Reading old flash chip contents... done.
Updating flash chip contents... Region [0x00300000 - 0x00500000] is not
sector aligned! Extending end boundaries by 0x00000fff bytes,
from 0x00500000 -> 0x00500fff
Erase/write done from 300000 to 500fff
```
Change-Id: I624d2b6427e7d5e25d11c16035c7c7ce040e5163
Signed-off-by: Michał Iwanicki <michal.iwanicki@3mdeb.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/89689
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
This commit is contained in:
committed by
Anastasia Klimchuk
parent
78ef763042
commit
3a6d88f438
14
flashrom.c
14
flashrom.c
@@ -1900,13 +1900,6 @@ int prepare_flash_access(struct flashctx *const flash,
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ((write_it || erase_it) && !flash->flags.force) {
|
||||
if (!can_change_target_regions(flash)) {
|
||||
msg_cerr("At least one target region is not fully writable. Aborting.\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (map_flash(flash) != 0)
|
||||
return 1;
|
||||
|
||||
@@ -1930,6 +1923,13 @@ int prepare_flash_access(struct flashctx *const flash,
|
||||
if (ret && bp_func)
|
||||
bp_func(flash);
|
||||
|
||||
if ((write_it || erase_it) && !flash->flags.force) {
|
||||
if (!can_change_target_regions(flash)) {
|
||||
msg_cerr("At least one target region is not fully writable. Aborting.\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
flash->address_high_byte = -1;
|
||||
flash->in_4ba_mode = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user