[flashrom] [PATCH 2/10] 4BA: Flashrom integration for the 4-bytes addressing extensions

Boris Baykov dev at borisbaykov.com
Sun Jan 11 00:21:54 CET 2015


This patch integrates code of the previous patch into Flashrom's code.
All the integrations is around 3 functions spi_nbyte_read, spi_nbyte_program
and spi_byte_program. After this patch then are not static and can be called
by their pointers saved in flashchips array. Also I added to flashrom.c some
code to switch a chip to 4-bytes addressing mode. And one error message is
corrected in spi.c because it's not suitable for 32-bit addresses.

Patched files
-------------
flash.h
+ added set of 4-bytes address functions to flashchip structure definition

flashrom.c
+ added switch to 4-bytes addressing more for chips which support it

serprog.c 
+ added 4-bytes addressing spi_nbyte_read call to serprog_spi_read

spi.c
+ fixed flash chip size check in spi_chip_read

spi25.c
+ added 4-bytes addressing spi_nbyte_read call to spi_read_chunked
+ added 4-bytes addressing spi_nbyte_program call to spi_write_chunked
+ added 4-bytes addressing spi_byte_program call to spi_chip_write_1


Signed-off-by: Boris Baykov <dev at borisbaykov.com>, Russia, Jan 2014
---
diff -U 5 -N ./flashrom/flash.h ./flashrom-1868-4ba-2/flash.h
--- ./flashrom/flash.h  2015-01-11 01:55:15.000000000 +0300
+++ ./flashrom-1868-4ba-2/flash.h       2015-01-10 18:59:50.000000000 +0300
@@ -168,10 +168,18 @@
        unsigned int total_size;
        /* Chip page size in bytes */
        unsigned int page_size;
        int feature_bits;
 
+       /* set of function pointers to use in 4-bytes addressing mode */
+       struct four_bytes_addr_funcs_set {
+               int (*enter_4ba) (struct flashctx *flash);
+               int (*read_nbyte) (struct flashctx *flash, unsigned int addr, uint8_t *bytes, unsigned int len);
+               int (*program_byte) (struct flashctx *flash, unsigned int addr, const uint8_t databyte);
+               int (*program_nbyte) (struct flashctx *flash, unsigned int addr, const uint8_t *bytes, unsigned int len);
+       } four_bytes_addr_funcs;
+
        /* Indicate how well flashrom supports different operations of this flash chip. */
        struct tested {
                enum test_state probe;
                enum test_state read;
                enum test_state erase;
diff -U 5 -N ./flashrom/flashrom.c ./flashrom-1868-4ba-2/flashrom.c
--- ./flashrom/flashrom.c       2015-01-11 01:55:15.000000000 +0300
+++ ./flashrom-1868-4ba-2/flashrom.c    2015-01-10 15:42:06.000000000 +0300
@@ -1934,10 +1934,33 @@
         * erase and write.
         */
        if (flash->chip->unlock)
                flash->chip->unlock(flash);
 
+       /* Switching to 4-Bytes Addressing mode if flash chip supports it */
+       if(flash->chip->feature_bits & FEATURE_4BA_SUPPORT) {
+               /* Do not switch if chip is already in 4-bytes addressing mode */
+               if (flash->chip->feature_bits & FEATURE_4BA_ONLY) {
+                       msg_cdbg("Flash chip is already in 4-bytes addressing mode.\n");
+               }
+               /* Go to 4-Bytes Addressing mode */
+               else {
+                       if (!flash->chip->four_bytes_addr_funcs.enter_4ba) {
+                               msg_cerr("No function for Enter 4-bytes addressing mode for this flash chip.\n"
+                                       "Please report to flashrom at flashrom.org\n");
+                               return 1;
+                       }
+
+                       if(flash->chip->four_bytes_addr_funcs.enter_4ba(flash)) {
+                               msg_cerr("Switching to 4-bytes addressing mode failed!\n");
+                               return 1;
+                       }
+
+                       msg_cdbg("Switched to 4-bytes addressing mode.\n");
+               }
+       }
+
        if (read_it) {
                return read_flash_to_file(flash, filename);
        }
 
        oldcontents = malloc(size);
diff -U 5 -N ./flashrom/serprog.c ./flashrom-1868-4ba-2/serprog.c
--- ./flashrom/serprog.c        2015-01-11 01:55:15.000000000 +0300
+++ ./flashrom-1868-4ba-2/serprog.c     2015-01-10 18:43:32.000000000 +0300
@@ -935,11 +935,14 @@
        unsigned int i, cur_len;
        const unsigned int max_read = spi_master_serprog.max_data_read;
        for (i = 0; i < len; i += cur_len) {
                int ret;
                cur_len = min(max_read, (len - i));
-               ret = spi_nbyte_read(flash, start + i, buf + i, cur_len);
+               ret = (flash->chip->feature_bits & FEATURE_4BA_SUPPORT) == 0
+                       ? spi_nbyte_read(flash, start + i, buf + i, cur_len)
+                       : flash->chip->four_bytes_addr_funcs.read_nbyte(flash, 
+                                                start + i, buf + i, cur_len);
                if (ret)
                        return ret;
        }
        return 0;
 }
diff -U 5 -N ./flashrom/spi25.c ./flashrom-1868-4ba-2/spi25.c
--- ./flashrom/spi25.c  2015-01-11 01:55:15.000000000 +0300
+++ ./flashrom-1868-4ba-2/spi25.c       2015-01-10 18:42:42.000000000 +0300
@@ -26,10 +26,11 @@
 #include "flash.h"
 #include "flashchips.h"
 #include "chipdrivers.h"
 #include "programmer.h"
 #include "spi.h"
+#include "spi4ba.h"
 
 static int spi_rdid(struct flashctx *flash, unsigned char *readarr, int bytes)
 {
        static const unsigned char cmd[JEDEC_RDID_OUTSIZE] = { JEDEC_RDID };
        int ret;
@@ -964,11 +965,14 @@
                starthere = max(start, i * page_size);
                /* Length of bytes in the range in this page. */
                lenhere = min(start + len, (i + 1) * page_size) - starthere;
                for (j = 0; j < lenhere; j += chunksize) {
                        toread = min(chunksize, lenhere - j);
-                       rc = spi_nbyte_read(flash, starthere + j, buf + starthere - start + j, toread);
+                       rc = (flash->chip->feature_bits & FEATURE_4BA_SUPPORT) == 0
+                               ? spi_nbyte_read(flash, starthere + j, buf + starthere - start + j, toread)
+                               : flash->chip->four_bytes_addr_funcs.read_nbyte(flash, starthere + j, 
+                                       buf + starthere - start + j, toread);
                        if (rc)
                                break;
                }
                if (rc)
                        break;
@@ -1009,11 +1013,14 @@
                starthere = max(start, i * page_size);
                /* Length of bytes in the range in this page. */
                lenhere = min(start + len, (i + 1) * page_size) - starthere;
                for (j = 0; j < lenhere; j += chunksize) {
                        towrite = min(chunksize, lenhere - j);
-                       rc = spi_nbyte_program(flash, starthere + j, buf + starthere - start + j, towrite);
+                       rc = (flash->chip->feature_bits & FEATURE_4BA_SUPPORT) == 0
+                               ? spi_nbyte_program(flash, starthere + j, buf + starthere - start + j, towrite)
+                               : flash->chip->four_bytes_addr_funcs.program_nbyte(flash, starthere + j, 
+                                       buf + starthere - start + j, towrite);
                        if (rc)
                                break;
                        while (spi_read_status_register(flash) & SPI_SR_WIP)
                                programmer_delay(10);
                }
@@ -1035,11 +1042,13 @@
 {
        unsigned int i;
        int result = 0;
 
        for (i = start; i < start + len; i++) {
-               result = spi_byte_program(flash, i, buf[i - start]);
+               result = (flash->chip->feature_bits & FEATURE_4BA_SUPPORT) == 0
+                       ? spi_byte_program(flash, i, buf[i - start])
+                       : flash->chip->four_bytes_addr_funcs.program_byte(flash, i, buf[i - start]);
                if (result)
                        return 1;
                while (spi_read_status_register(flash) & SPI_SR_WIP)
                        programmer_delay(10);
        }
diff -U 5 -N ./flashrom/spi.c ./flashrom-1868-4ba-2/spi.c
--- ./flashrom/spi.c    2015-01-11 01:55:15.000000000 +0300
+++ ./flashrom-1868-4ba-2/spi.c 2015-01-10 18:39:45.000000000 +0300
@@ -108,11 +108,14 @@
        /* Check if the chip fits between lowest valid and highest possible
         * address. Highest possible address with the current SPI implementation
         * means 0xffffff, the highest unsigned 24bit number.
         */
        addrbase = spi_get_valid_read_addr(flash);
-       if (addrbase + flash->chip->total_size * 1024 > (1 << 24)) {
+       /* Show flash chip size warning if flash chip doesn't support 
+          4-Bytes Addressing mode and last address excedes 24 bits */
+       if (!(flash->chip->feature_bits & FEATURE_4BA_SUPPORT) &&
+           addrbase + flash->chip->total_size * 1024 > (1 << 24)) {
                msg_perr("Flash chip size exceeds the allowed access window. ");
                msg_perr("Read will probably fail.\n");
                /* Try to get the best alignment subject to constraints. */
                addrbase = (1 << 24) - flash->chip->total_size * 1024;
        }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: flashrom-r1868-4ba-part-2.patch.tar.bz2
Type: application/octet-stream
Size: 2502 bytes
Desc: not available
URL: <http://www.flashrom.org/pipermail/flashrom/attachments/20150111/dc2bd2f2/attachment.obj>


More information about the flashrom mailing list