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 <[email protected]> Acked-by: Carl-Daniel Hailfinger <[email protected]> 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 -- http://www.hailfinger.org/ _______________________________________________ flashrom mailing list [email protected] http://www.flashrom.org/mailman/listinfo/flashrom
