Author: stepan
Date: 2008-11-02 20:51:50 +0100 (Sun, 02 Nov 2008)
New Revision: 3721

Modified:
   trunk/util/flashrom/ichspi.c
Log:
Drop nr/opcode_index parameter from run_opcode and search the opmenu for the 
opcode instead.
This is slightly slower (ha, ha), but works on boards with a locked opmenu. 
Tested on ICH7 and works.

Signed-off-by: Stefan Reinauer <[EMAIL PROTECTED]>
Acked-by: Carl-Daniel Hailfinger <[EMAIL PROTECTED]>



Modified: trunk/util/flashrom/ichspi.c
===================================================================
--- trunk/util/flashrom/ichspi.c        2008-11-02 17:48:20 UTC (rev 3720)
+++ trunk/util/flashrom/ichspi.c        2008-11-02 19:51:50 UTC (rev 3721)
@@ -148,7 +148,7 @@
 
 /* Common SPI functions */
 static int program_opcodes(OPCODES * op);
-static int run_opcode(uint8_t nr, OPCODE op, uint32_t offset,
+static int run_opcode(OPCODE op, uint32_t offset,
                      uint8_t datalength, uint8_t * data);
 static int ich_spi_read_page(struct flashchip *flash, uint8_t * buf,
                             int offset, int maxdata);
@@ -225,7 +225,7 @@
        return 0;
 }
 
-static int ich7_run_opcode(uint8_t nr, OPCODE op, uint32_t offset,
+static int ich7_run_opcode(OPCODE op, uint32_t offset,
                           uint8_t datalength, uint8_t * data, int maxdata)
 {
        int write_cmd = 0;
@@ -233,6 +233,8 @@
        uint32_t temp32 = 0;
        uint16_t temp16;
        uint32_t a;
+       uint64_t opmenu;
+       int opcode_index;
 
        /* Is it a write command? */
        if ((op.spi_type == SPI_OPCODE_TYPE_WRITE_NO_ADDRESS)
@@ -280,8 +282,21 @@
        }
 
        /* Select opcode */
-       temp16 |= ((uint16_t) (nr & 0x07)) << 4;
+       opmenu = REGREAD32(ICH7_REG_OPMENU);
+       opmenu |= ((uint64_t)REGREAD32(ICH7_REG_OPMENU + 4)) << 32;
 
+       for (opcode_index=0; opcode_index<8; opcode_index++) {
+               if((opmenu & 0xff) == op.opcode) {
+                       break;
+               }
+               opmenu >>= 8;
+       }
+       if (opcode_index == 8) {
+               printf_debug("Opcode %x not found.\n", op.opcode);
+               return 1;
+       }
+       temp16 |= ((uint16_t) (opcode_index & 0x07)) << 4;
+
        /* Handle Atomic */
        if (op.atomic != 0) {
                /* Select atomic command */
@@ -328,13 +343,15 @@
        return 0;
 }
 
-static int ich9_run_opcode(uint8_t nr, OPCODE op, uint32_t offset,
+static int ich9_run_opcode(OPCODE op, uint32_t offset,
                           uint8_t datalength, uint8_t * data)
 {
        int write_cmd = 0;
        int timeout;
        uint32_t temp32;
        uint32_t a;
+       uint64_t opmenu;
+       int opcode_index;
 
        /* Is it a write command? */
        if ((op.spi_type == SPI_OPCODE_TYPE_WRITE_NO_ADDRESS)
@@ -383,8 +400,21 @@
        }
 
        /* Select opcode */
-       temp32 |= ((uint32_t) (nr & 0x07)) << (8 + 4);
+       opmenu = REGREAD32(ICH9_REG_OPMENU);
+       opmenu |= ((uint64_t)REGREAD32(ICH9_REG_OPMENU + 4)) << 32;
 
+       for (opcode_index=0; opcode_index<8; opcode_index++) {
+               if((opmenu & 0xff) == op.opcode) {
+                       break;
+               }
+               opmenu >>= 8;
+       }
+       if (opcode_index == 8) {
+               printf_debug("Opcode %x not found.\n", op.opcode);
+               return 1;
+       }
+       temp32 |= ((uint32_t) (opcode_index & 0x07)) << (8 + 4);
+
        /* Handle Atomic */
        if (op.atomic != 0) {
                /* Select atomic command */
@@ -431,16 +461,16 @@
        return 0;
 }
 
-static int run_opcode(uint8_t nr, OPCODE op, uint32_t offset,
+static int run_opcode(OPCODE op, uint32_t offset,
                      uint8_t datalength, uint8_t * data)
 {
        switch (flashbus) {
        case BUS_TYPE_VIA_SPI:
-               return ich7_run_opcode(nr, op, offset, datalength, data, 16);
+               return ich7_run_opcode(op, offset, datalength, data, 16);
        case BUS_TYPE_ICH7_SPI:
-               return ich7_run_opcode(nr, op, offset, datalength, data, 64);
+               return ich7_run_opcode(op, offset, datalength, data, 64);
        case BUS_TYPE_ICH9_SPI:
-               return ich9_run_opcode(nr, op, offset, datalength, data);
+               return ich9_run_opcode(op, offset, datalength, data);
        default:
                printf_debug("%s: unsupported chipset\n", __FUNCTION__);
        }
@@ -453,7 +483,7 @@
 {
        printf_debug("ich_spi_erase_block: offset=%d, sectors=%d\n", offset, 1);
 
-       if (run_opcode(2, curopcodes->opcode[2], offset, 0, NULL) != 0) {
+       if (run_opcode(curopcodes->opcode[2], offset, 0, NULL) != 0) {
                printf_debug("Error erasing sector at 0x%x", offset);
                return -1;
        }
@@ -477,7 +507,7 @@
                if (remaining < maxdata) {
 
                        if (run_opcode
-                           (1, curopcodes->opcode[1],
+                           (curopcodes->opcode[1],
                             offset + (page_size - remaining), remaining,
                             &buf[page_size - remaining]) != 0) {
                                printf_debug("Error reading");
@@ -486,7 +516,7 @@
                        remaining = 0;
                } else {
                        if (run_opcode
-                           (1, curopcodes->opcode[1],
+                           (curopcodes->opcode[1],
                             offset + (page_size - remaining), maxdata,
                             &buf[page_size - remaining]) != 0) {
                                printf_debug("Error reading");
@@ -512,7 +542,7 @@
        for (a = 0; a < page_size; a += maxdata) {
                if (remaining < maxdata) {
                        if (run_opcode
-                           (0, curopcodes->opcode[0],
+                           (curopcodes->opcode[0],
                             offset + (page_size - remaining), remaining,
                             &bytes[page_size - remaining]) != 0) {
                                printf_debug("Error writing");
@@ -521,7 +551,7 @@
                        remaining = 0;
                } else {
                        if (run_opcode
-                           (0, curopcodes->opcode[0],
+                           (curopcodes->opcode[0],
                             offset + (page_size - remaining), maxdata,
                             &bytes[page_size - remaining]) != 0) {
                                printf_debug("Error writing");
@@ -641,7 +671,7 @@
                count = readcnt;
        }
 
-       if (run_opcode(opcode_index, *opcode, addr, count, data) != 0) {
+       if (run_opcode(*opcode, addr, count, data) != 0) {
                printf_debug("run OPCODE 0x%02x failed\n", opcode->opcode);
                return 1;
        }


--
coreboot mailing list: [email protected]
http://www.coreboot.org/mailman/listinfo/coreboot

Reply via email to