Nikolai Artemiev has uploaded this change for review.

View Change

flashrom: only unlock for write/erase operations

Don't unlock for read/verify operations because most chips don't have
read locks, and the ones that do aren't supported by flashrom's unlock
functions anyway.

Unconditionally unlocking slows down flashrom significantly with some
programmers, particularly linux_mtd due to inefficiency in the current
kernel MTD interface.

BUG=b:283779258
BRANCH=none
TEST=`ninja test`
TEST=`flashrom -{r,w,E,v}` on strongbad
TEST=`flashrom --wp-enable; flashrom -{w,E}` on strongbad

Change-Id: I5dc66474a0b7969b51b86ac9f5daa2c95ae968f1
Signed-off-by: Nikolai Artemiev <nartemiev@google.com>
---
M flashrom.c
1 file changed, 15 insertions(+), 9 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/91/75991/1
diff --git a/flashrom.c b/flashrom.c
index b6e5cf8..918bcea 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -2092,17 +2092,23 @@
/* Initialize chip_restore_fn_count before chip unlock calls. */
flash->chip_restore_fn_count = 0;

- /* Given the existence of read locks, we want to unlock for read, erase and write. */
+ /*
+ * Only unlock for erase and write. Read and verify generally do not
+ * require unlocking. Some chips have read locks, but flashrom's chip
+ * drivers don't support disabling them anyway.
+ */
int ret = 1;
- if (flash->chip->decode_range != NO_DECODE_RANGE_FUNC ||
- (flash->mst->buses_supported & BUS_PROG && flash->mst->opaque.wp_write_cfg)) {
- ret = unlock_flash_wp(flash);
- if (ret)
- msg_cerr("Failed to unlock flash status reg with wp support.\n");
+ if (write_it || erase_it) {
+ if (flash->chip->decode_range != NO_DECODE_RANGE_FUNC ||
+ (flash->mst->buses_supported & BUS_PROG && flash->mst->opaque.wp_write_cfg)) {
+ ret = unlock_flash_wp(flash);
+ if (ret)
+ msg_cerr("Failed to unlock flash status reg with wp support.\n");
+ }
+ blockprotect_func_t *bp_func = lookup_blockprotect_func_ptr(flash->chip);
+ if (ret && bp_func)
+ bp_func(flash);
}
- blockprotect_func_t *bp_func = lookup_blockprotect_func_ptr(flash->chip);
- if (ret && bp_func)
- bp_func(flash);

flash->address_high_byte = -1;
flash->in_4ba_mode = false;

To view, visit change 75991. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I5dc66474a0b7969b51b86ac9f5daa2c95ae968f1
Gerrit-Change-Number: 75991
Gerrit-PatchSet: 1
Gerrit-Owner: Nikolai Artemiev <nartemiev@google.com>
Gerrit-MessageType: newchange