David Hendricks would like Nicolas Boichat to review this change.

View Change

linux_mtd: fix wp range detection in mtd_wp_status

The logic in wp range detection in mtd_wp_status is wrong. The first
block (start == 0) may possible be write-protected, thus we can't use
'if (!start)' for detecting start of write-protection. Since start and
end are both uint32_t, we add two new int variables to flag the status.

Signed-off-by: Wei-Ning Huang <wnhuang@google.com>

BUG=chrome-os-partner:40208
TEST=`flashrom --wp-enable --wp-range 0x0 0x200000` then `flashrom --wp-status`
should display: 'WP: write protect range: start=0x00000000, len=0x00200000'

Change-Id: Id8934c2ba997ff8558a9be3a5aa05b56272c9e85
Reviewed-on: https://chromium-review.googlesource.com/330225
Commit-Ready: Wei-Ning Huang <wnhuang@chromium.org>
Tested-by: Wei-Ning Huang <wnhuang@chromium.org>
Reviewed-by: David Hendricks <dhendrix@chromium.org>
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
---
M linux_mtd.c
1 file changed, 9 insertions(+), 4 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/06/22506/1
diff --git a/linux_mtd.c b/linux_mtd.c
index c707167..6055aef 100644
--- a/linux_mtd.c
+++ b/linux_mtd.c
@@ -476,6 +476,7 @@
static int mtd_wp_status(const struct flashchip *flash)
{
uint32_t start = 0, end = 0;
+ int start_found = 0, end_found = 0;
unsigned int u;

/* For now, assume only one contiguous region can be locked (NOR) */
@@ -492,14 +493,18 @@
msg_perr("%s: ioctl: %s\n", __func__, strerror(errno));
return 1;
} else if (rc == 1) {
- if (!start)
+ if (!start_found) {
start = erase_info.start;
+ start_found = 1;
+ }
} else if (rc == 0) {
- if (start)
- end = erase_info.start - 1;
+ if (start_found) {
+ end = erase_info.start;
+ end_found = 1;
+ }
}

- if (start && end) {
+ if (start_found && end_found) {
msg_pinfo("WP: write protect range: start=0x%08x, "
"len=0x%08x\n", start, end - start);
/* TODO: Replace this break with "start = end = 0" if

To view, visit change 22506. To unsubscribe, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id8934c2ba997ff8558a9be3a5aa05b56272c9e85
Gerrit-Change-Number: 22506
Gerrit-PatchSet: 1
Gerrit-Owner: David Hendricks <david.hendricks@gmail.com>
Gerrit-Reviewer: Nicolas Boichat <drinkcat@chromium.org>
Gerrit-Reviewer: Wei-Ning Huang <wnhuang@google.com>