Am 14.03.2013 12:13 schrieb Stefan Tauner:
This adds a number of new granularities in a rather inelegant way. Until we figure out how to better handle various granularities this has to be accepted.
I think it's pretty good and I definitely don't consider it to be inelegant.
It also refactors the handling of n-byte granularities by extracting the checking code into a helper function which reduces the pain of the above significantly.
Signed-off-by: Stefan Tauner stefan.tauner@student.tuwien.ac.at
Acked-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net with one small change (see below).
This is one possibility to solve the granularity issue and i think the most likely to get the patch series in fastest...
--- a/flashrom.c +++ b/flashrom.c @@ -676,6 +676,23 @@ out_free: return ret; }
+/* Helper function for need_erase() that focuses on granularities of n bytes. */ +static int need_erase_n_bytes(uint8_t *have, uint8_t *want, unsigned int len, unsigned int n)
Can you please rename n to gran or something similar (don't forget the comment as well)? That would improve readability. No need to repost.
+{
- unsigned int i, j, limit;
- for (j = 0; j < len / n; j++) {
limit = min (n, len - j * n);
/* Are 'have' and 'want' identical? */
if (!memcmp(have + j * n, want + j * n, limit))
continue;
/* have needs to be in erased state. */
for (i = 0; i < limit; i++)
if (have[j * n + i] != 0xff)
return 1;
- }
- return 0;
+}
/*
- 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
Regards, Carl-Daniel