[flashrom] [PATCH] Check if an erase is needed to write
Carl-Daniel Hailfinger
c-d.hailfinger.devel.2006 at gmx.net
Wed Sep 16 18:56:26 CEST 2009
For optimal partial reflashing, we have to find out which parts of the
chip can be written without erase. For that, the only criterion (except
a limit on the number of writes for very old chips) is whether the write
will only clear bits (set them to 0).
If (current&new==new) we can skip the erase.
If any bit would have to be set to 1, we need to erase.
Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006 at gmx.net>
Index: flashrom-need_erase/flash.h
===================================================================
--- flashrom-need_erase/flash.h (Revision 725)
+++ flashrom-need_erase/flash.h (Arbeitskopie)
@@ -455,6 +455,7 @@
int max(int a, int b);
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 need_erase(uint8_t *have, uint8_t *want, int len);
char *strcat_realloc(char *dest, const char *src);
#define OK 0
Index: flashrom-need_erase/flashrom.c
===================================================================
--- flashrom-need_erase/flashrom.c (Revision 725)
+++ flashrom-need_erase/flashrom.c (Arbeitskopie)
@@ -379,6 +379,26 @@
return ret;
}
+/**
+ * Check if the buffer have can be programmed to the content of want without
+ * erasing. This is only possible if no bit has to be set to 1.
+ *
+ * @have buffer with current content
+ * @want buffer with desired content
+ * @len length of the verified area
+ * @return 0 if no erase is needed, >0 otherwise
+ */
+int need_erase(uint8_t *have, uint8_t *want, int len)
+{
+ int failcount = 0;
+ int i;
+
+ for (i = 0; i < len; i++)
+ if ((have[i] & want[i]) != want[i])
+ failcount++;
+ return failcount;
+}
+
struct flashchip *probe_flash(struct flashchip *first_flash, int force)
{
struct flashchip *flash;
--
http://www.hailfinger.org/
More information about the flashrom
mailing list