- fix power of 2 bug in calculating the block size and add warning if block 
size is too big
- rename i to dw
- fix output
- remove unnecessary code

Signed-off-by: Stefan Tauner <[email protected]>
---
 spi25.c |   52 ++++++++++++++++++++++++++--------------------------
 1 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/spi25.c b/spi25.c
index 7f648bf..ae59ce1 100644
--- a/spi25.c
+++ b/spi25.c
@@ -134,21 +134,13 @@ struct sfdp_tbl_hdr {
        uint32_t ptp; /* 24b pointer */
 };
 
-struct sfdp_tbl_0 {
-       uint8_t id;
-       uint8_t v_minor;
-       uint8_t v_major;
-       uint8_t len;
-       uint32_t ptp; /* 24b pointer */
-};
-
 static int sfdp_fill_flash(struct flashchip *f, uint8_t *buf, uint16_t len)
 {
        uint32_t tmp32;
        uint8_t tmp8;
        uint32_t total_size; /* in bytes */
        uint32_t bsize;
-       int i, j;
+       int dw, j;
 
        msg_cspew("Parsing JEDEC SFDP parameter table...\n");
        if (len == 9 * 4) {
@@ -157,11 +149,11 @@ static int sfdp_fill_flash(struct flashchip *f, uint8_t 
*buf, uint16_t len)
        }
 
        /* 1. double word */
-       i = 0;
-       tmp32 = buf[(4 * i) + 0];
-       tmp32 |= ((unsigned int)buf[(4 * i) + 1]) << 8;
-       tmp32 |= ((unsigned int)buf[(4 * i) + 2]) << 16;
-       tmp32 |= ((unsigned int)buf[(4 * i) + 3]) << 24;
+       dw = 0;
+       tmp32 = buf[(4 * dw) + 0];
+       tmp32 |= ((unsigned int)buf[(4 * dw) + 1]) << 8;
+       tmp32 |= ((unsigned int)buf[(4 * dw) + 2]) << 16;
+       tmp32 |= ((unsigned int)buf[(4 * dw) + 3]) << 24;
 
        tmp8 = (tmp32 >> 17) & 0x3;
        switch (tmp8) {
@@ -195,28 +187,36 @@ static int sfdp_fill_flash(struct flashchip *f, uint8_t 
*buf, uint16_t len)
                msg_cspew("not to be especially enabled.\n");
 
        /* 2. double word */
-       i = 1;
-       tmp32 = buf[(4 * i) + 0];
-       tmp32 |= ((unsigned int)buf[(4 * i) + 1]) << 8;
-       tmp32 |= ((unsigned int)buf[(4 * i) + 2]) << 16;
-       tmp32 |= ((unsigned int)buf[(4 * i) + 3]) << 24;
-
-       if (tmp32 & (1<<31)) {
-               msg_cdbg("  Flash chip size >= 4 Gb/ 500 MB not supported.\n");
+       dw = 1;
+       tmp32 = buf[(4 * dw) + 0];
+       tmp32 |= ((unsigned int)buf[(4 * dw) + 1]) << 8;
+       tmp32 |= ((unsigned int)buf[(4 * dw) + 2]) << 16;
+       tmp32 |= ((unsigned int)buf[(4 * dw) + 3]) << 24;
+
+       if (tmp32 & (1 << 31)) {
+               msg_cdbg("  Flash chip size >= 4 Gb/500 MB not supported.\n");
                return 1;
        }
        total_size = (tmp32 & 0x7FFFFFFF) / 8;
        f->total_size = total_size / 1024;
        msg_cspew("  Flash chip size is %d kB.\n", f->total_size);
 
-       i = 8;
+       dw = 8;
        for(j = 0; j < 4; j++) {
                /* 8 double words from the start + 2 words for every eraser */
-               bsize = 2^(buf[(4 * i) + (2 * j)]);
-               if (bsize == 0)
+               tmp32 = buf[(4 * dw) + (2 * j)];
+               if (tmp32 == 0) {
+                       msg_cspew("  Block eraser %d is unused.\n", j);
                        continue;
+               }
+               if (tmp32 >= 31) {
+                       msg_cspew("  Block size of eraser %d (2^%d) is too big."
+                                 "\n", j, tmp32);
+                       continue;
+               }
+               bsize = 1 << (tmp32); /* bsize = 2 ^ field */
 
-               tmp32 = buf[(4 * i) + (2 * j) + 1];
+               tmp32 = buf[(4 * dw) + (2 * j) + 1];
                switch(tmp32){
                case 0x00:
                case 0xff:
-- 
1.7.1


_______________________________________________
flashrom mailing list
[email protected]
http://www.flashrom.org/mailman/listinfo/flashrom

Reply via email to