mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-28 07:23:43 +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 verify_range(struct flashchip *flash, uint8_t *cmpbuf, int start, int len, char *message)
|
||||||
{
|
{
|
||||||
int i, j, starthere, lenhere, ret = 0;
|
int i, ret = 0;
|
||||||
int page_size = flash->page_size;
|
uint8_t *readbuf = malloc(len);
|
||||||
uint8_t *readbuf = malloc(page_size);
|
|
||||||
int failcount = 0;
|
int failcount = 0;
|
||||||
|
|
||||||
if (!len)
|
if (!len)
|
||||||
@ -753,36 +752,21 @@ int verify_range(struct flashchip *flash, uint8_t *cmpbuf, int start, int len, c
|
|||||||
if (!message)
|
if (!message)
|
||||||
message = "VERIFY";
|
message = "VERIFY";
|
||||||
|
|
||||||
/* Warning: This loop has a very unusual condition and body.
|
ret = flash->read(flash, readbuf, start, len);
|
||||||
* The loop needs to go through each page with at least one affected
|
if (ret) {
|
||||||
* byte. The lowest page number is (start / page_size) since that
|
msg_gerr("Verification impossible because read failed "
|
||||||
* division rounds down. The highest page number we want is the page
|
"at 0x%x (len 0x%x)\n", start, len);
|
||||||
* where the last byte of the range lives. That last byte has the
|
return ret;
|
||||||
* 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 = 0; i < len; i++) {
|
||||||
*/
|
if (cmpbuf[i] != readbuf[i]) {
|
||||||
for (i = start / page_size; i <= (start + len - 1) / page_size; i++) {
|
/* Only print the first failure. */
|
||||||
/* Byte position of the first byte in the range in this page. */
|
if (!failcount++)
|
||||||
starthere = max(start, i * page_size);
|
msg_cerr("%s FAILED at 0x%08x! "
|
||||||
/* Length of bytes in the range in this page. */
|
"Expected=0x%02x, Read=0x%02x,",
|
||||||
lenhere = min(start + len, (i + 1) * page_size) - starthere;
|
message, start + i, cmpbuf[i],
|
||||||
ret = flash->read(flash, readbuf, starthere, lenhere);
|
readbuf[i]);
|
||||||
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]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (failcount) {
|
if (failcount) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user