mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-27 23:22:37 +02:00
Read the to-be-verified area in one go
Verify_range() and check_erased_range() check each page separately. While that may have seemed like a good idea back when the code was introduced, it has no benefits for any of the chips where we support write because all of them handle cross-page reads nicely. The only class of chips where this change could be a problem is chips with non power of two sector sizes which have gaps in the address space. We simply require their read functions to provide gap-free results and leave it at that. Corresponding to flashrom svn r1233. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Acked-by: Michael Karcher <flashrom@mkarcher.dialup.fu-berlin.de>
This commit is contained in:
parent
2bee8cf898
commit
d836941f9e
50
flashrom.c
50
flashrom.c
@ -726,9 +726,8 @@ int check_erased_range(struct flashchip *flash, int start, int len)
|
||||
*/
|
||||
int verify_range(struct flashchip *flash, uint8_t *cmpbuf, int start, int len, char *message)
|
||||
{
|
||||
int i, j, starthere, lenhere, ret = 0;
|
||||
int page_size = flash->page_size;
|
||||
uint8_t *readbuf = malloc(page_size);
|
||||
int i, ret = 0;
|
||||
uint8_t *readbuf = malloc(len);
|
||||
int failcount = 0;
|
||||
|
||||
if (!len)
|
||||
@ -753,36 +752,21 @@ int verify_range(struct flashchip *flash, uint8_t *cmpbuf, int start, int len, c
|
||||
if (!message)
|
||||
message = "VERIFY";
|
||||
|
||||
/* Warning: This loop has a very unusual condition and body.
|
||||
* The loop needs to go through each page with at least one affected
|
||||
* byte. The lowest page number is (start / page_size) since that
|
||||
* division rounds down. The highest page number we want is the page
|
||||
* where the last byte of the range lives. That last byte has the
|
||||
* address (start + len - 1), thus the highest page number is
|
||||
* (start + len - 1) / page_size. Since we want to include that last
|
||||
* page as well, the loop condition uses <=.
|
||||
*/
|
||||
for (i = start / page_size; i <= (start + len - 1) / page_size; i++) {
|
||||
/* Byte position of the first byte in the range in this page. */
|
||||
starthere = max(start, i * page_size);
|
||||
/* Length of bytes in the range in this page. */
|
||||
lenhere = min(start + len, (i + 1) * page_size) - starthere;
|
||||
ret = flash->read(flash, readbuf, starthere, lenhere);
|
||||
if (ret) {
|
||||
msg_gerr("Verification impossible because read failed "
|
||||
"at 0x%x (len 0x%x)\n", starthere, lenhere);
|
||||
break;
|
||||
}
|
||||
for (j = 0; j < lenhere; j++) {
|
||||
if (cmpbuf[starthere - start + j] != readbuf[j]) {
|
||||
/* Only print the first failure. */
|
||||
if (!failcount++)
|
||||
msg_cerr("%s FAILED at 0x%08x! "
|
||||
"Expected=0x%02x, Read=0x%02x,",
|
||||
message, starthere + j,
|
||||
cmpbuf[starthere - start + j],
|
||||
readbuf[j]);
|
||||
}
|
||||
ret = flash->read(flash, readbuf, start, len);
|
||||
if (ret) {
|
||||
msg_gerr("Verification impossible because read failed "
|
||||
"at 0x%x (len 0x%x)\n", start, len);
|
||||
return ret;
|
||||
}
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
if (cmpbuf[i] != readbuf[i]) {
|
||||
/* Only print the first failure. */
|
||||
if (!failcount++)
|
||||
msg_cerr("%s FAILED at 0x%08x! "
|
||||
"Expected=0x%02x, Read=0x%02x,",
|
||||
message, start + i, cmpbuf[i],
|
||||
readbuf[i]);
|
||||
}
|
||||
}
|
||||
if (failcount) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user