mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-26 22:52:34 +02:00
Refine granularity handling in preparation of AT45DB series support
This adds a number of new granularitie and refines the handling of n-byte granularities by extracting the respective code into a helper function which reduces the pain of the above significantly. Corresponding to flashrom svn r1666. Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
This commit is contained in:
parent
52b6e9dc54
commit
02437458a6
24
flash.h
24
flash.h
@ -59,18 +59,22 @@ enum chipbustype {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The following write granularities are known:
|
* The following enum defines possible write granularities of flash chips. These tend to reflect the properties
|
||||||
* - 1 bit: Each bit can be cleared individually.
|
* of the actual hardware not necesserily the write function(s) defined by the respective struct flashchip.
|
||||||
* - 1 byte: A byte can be written once. Further writes to an already written byte cause its contents to be
|
* The latter might (and should) be more precisely specified, e.g. they might bail out early if their execution
|
||||||
* either undefined or to stay unchanged.
|
* would result in undefined chip contents.
|
||||||
* - 128 bytes: If less than 128 bytes are written, the rest will be erased. Each write to a 128-byte region
|
|
||||||
* will trigger an automatic erase before anything is written. Very uncommon behaviour.
|
|
||||||
* - 256 bytes: If less than 256 bytes are written, the contents of the unwritten bytes are undefined.
|
|
||||||
*/
|
*/
|
||||||
enum write_granularity {
|
enum write_granularity {
|
||||||
write_gran_256bytes = 0, /* We assume 256 byte granularity by default. */
|
/* We assume 256 byte granularity by default. */
|
||||||
write_gran_1bit,
|
write_gran_256bytes = 0,/* If less than 256 bytes are written, the unwritten bytes are undefined. */
|
||||||
write_gran_1byte,
|
write_gran_1bit, /* Each bit can be cleared individually. */
|
||||||
|
write_gran_1byte, /* A byte can be written once. Further writes to an already written byte cause
|
||||||
|
* its contents to be either undefined or to stay unchanged. */
|
||||||
|
write_gran_264bytes, /* If less than 264 bytes are written, the unwritten bytes are undefined. */
|
||||||
|
write_gran_512bytes, /* If less than 512 bytes are written, the unwritten bytes are undefined. */
|
||||||
|
write_gran_528bytes, /* If less than 528 bytes are written, the unwritten bytes are undefined. */
|
||||||
|
write_gran_1024bytes, /* If less than 1024 bytes are written, the unwritten bytes are undefined. */
|
||||||
|
write_gran_1056bytes, /* If less than 1056 bytes are written, the unwritten bytes are undefined. */
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
64
flashrom.c
64
flashrom.c
@ -688,6 +688,23 @@ out_free:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Helper function for need_erase() that focuses on granularities of gran bytes. */
|
||||||
|
static int need_erase_gran_bytes(uint8_t *have, uint8_t *want, unsigned int len, unsigned int gran)
|
||||||
|
{
|
||||||
|
unsigned int i, j, limit;
|
||||||
|
for (j = 0; j < len / gran; j++) {
|
||||||
|
limit = min (gran, len - j * gran);
|
||||||
|
/* Are 'have' and 'want' identical? */
|
||||||
|
if (!memcmp(have + j * gran, want + j * gran, limit))
|
||||||
|
continue;
|
||||||
|
/* have needs to be in erased state. */
|
||||||
|
for (i = 0; i < limit; i++)
|
||||||
|
if (have[j * gran + i] != 0xff)
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check if the buffer @have can be programmed to the content of @want without
|
* Check if the buffer @have can be programmed to the content of @want without
|
||||||
* erasing. This is only possible if all chunks of size @gran are either kept
|
* erasing. This is only possible if all chunks of size @gran are either kept
|
||||||
@ -705,7 +722,7 @@ out_free:
|
|||||||
int need_erase(uint8_t *have, uint8_t *want, unsigned int len, enum write_granularity gran)
|
int need_erase(uint8_t *have, uint8_t *want, unsigned int len, enum write_granularity gran)
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
unsigned int i, j, limit;
|
unsigned int i;
|
||||||
|
|
||||||
switch (gran) {
|
switch (gran) {
|
||||||
case write_gran_1bit:
|
case write_gran_1bit:
|
||||||
@ -723,20 +740,22 @@ int need_erase(uint8_t *have, uint8_t *want, unsigned int len, enum write_granul
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case write_gran_256bytes:
|
case write_gran_256bytes:
|
||||||
for (j = 0; j < len / 256; j++) {
|
result = need_erase_gran_bytes(have, want, len, 256);
|
||||||
limit = min (256, len - j * 256);
|
break;
|
||||||
/* Are 'have' and 'want' identical? */
|
case write_gran_264bytes:
|
||||||
if (!memcmp(have + j * 256, want + j * 256, limit))
|
result = need_erase_gran_bytes(have, want, len, 264);
|
||||||
continue;
|
break;
|
||||||
/* have needs to be in erased state. */
|
case write_gran_512bytes:
|
||||||
for (i = 0; i < limit; i++)
|
result = need_erase_gran_bytes(have, want, len, 512);
|
||||||
if (have[j * 256 + i] != 0xff) {
|
break;
|
||||||
result = 1;
|
case write_gran_528bytes:
|
||||||
break;
|
result = need_erase_gran_bytes(have, want, len, 528);
|
||||||
}
|
break;
|
||||||
if (result)
|
case write_gran_1024bytes:
|
||||||
break;
|
result = need_erase_gran_bytes(have, want, len, 1024);
|
||||||
}
|
break;
|
||||||
|
case write_gran_1056bytes:
|
||||||
|
result = need_erase_gran_bytes(have, want, len, 1056);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
msg_cerr("%s: Unsupported granularity! Please report a bug at "
|
msg_cerr("%s: Unsupported granularity! Please report a bug at "
|
||||||
@ -784,6 +803,21 @@ static unsigned int get_next_write(uint8_t *have, uint8_t *want, unsigned int le
|
|||||||
case write_gran_256bytes:
|
case write_gran_256bytes:
|
||||||
stride = 256;
|
stride = 256;
|
||||||
break;
|
break;
|
||||||
|
case write_gran_264bytes:
|
||||||
|
stride = 264;
|
||||||
|
break;
|
||||||
|
case write_gran_512bytes:
|
||||||
|
stride = 512;
|
||||||
|
break;
|
||||||
|
case write_gran_528bytes:
|
||||||
|
stride = 528;
|
||||||
|
break;
|
||||||
|
case write_gran_1024bytes:
|
||||||
|
stride = 1024;
|
||||||
|
break;
|
||||||
|
case write_gran_1056bytes:
|
||||||
|
stride = 1056;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
msg_cerr("%s: Unsupported granularity! Please report a bug at "
|
msg_cerr("%s: Unsupported granularity! Please report a bug at "
|
||||||
"flashrom@flashrom.org\n", __func__);
|
"flashrom@flashrom.org\n", __func__);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user