On Sat, 05 May 2012 01:22:12 +0200
Carl-Daniel Hailfinger <[email protected]> wrote:

> Fix ICH SPI reprogram_opcode_on_the_fly return code.

i wouldnt call this a fix.

> Helpful for SFDP debugging.
> 
> Signed-off-by: Carl-Daniel Hailfinger <[email protected]>
> 
> Index: flashrom-sfdp_read_dummy_reduce_param_chunksize/ichspi.c
> ===================================================================
> --- flashrom-ichspi_invalid_length_consistent/ichspi.c        (Revision 1528)
> +++ flashrom-ichspi_invalid_length_consistent/ichspi.c        (Arbeitskopie)
> @@ -416,7 +416,10 @@
>               msg_pdbg ("on-the-fly OPCODE (0x%02X) re-programmed, 
> op-pos=%d\n", opcode, oppos);
>               return oppos;
>       }
> -     return -1;
> +     /* This case only happens if the writecnt/readcnt combination is
> +      * impossible to achieve on ICH SPI.
> +      */
> +     return SPI_INVALID_LENGTH;
>  }

imho it would make more sense to have less comments + a cleaner code
flow instead ;) see attached patch.

>  static int find_opcode(OPCODES *op, uint8_t opcode)
> @@ -1001,7 +1004,11 @@
>       if (opcode_index == -1) {
>               if (!ichspi_lock)
>                       opcode_index = reprogram_opcode_on_the_fly(cmd, 
> writecnt, readcnt);
> -             if (opcode_index == -1) {
> +             if (opcode_index == SPI_INVALID_LENGTH) {
> +                     msg_pdbg("OPCODE 0x%02x has unsupported length, will "
> +                              "not execute.\n", cmd);
> +                     return SPI_INVALID_LENGTH;
> +             } else if (opcode_index == -1) {
>                       msg_pdbg("Invalid OPCODE 0x%02x, will not execute.\n",
>                                cmd);
>                       return SPI_INVALID_OPCODE;
> 
> 


-- 
Kind regards/Mit freundlichen Grüßen, Stefan Tauner
>From 8f5f3fc0b9b258fae5af1e53fdd3a943dc3161e6 Mon Sep 17 00:00:00 2001
From: Stefan Tauner <[email protected]>
Date: Sun, 6 May 2012 14:12:57 +0200
Subject: [PATCH] Refine reprogram_opcode_on_the_fly to indicate wrong
 readcnt/writecnt combinations.


Signed-off-by: Stefan Tauner <[email protected]>
---
 ichspi.c |   27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/ichspi.c b/ichspi.c
index 403d763..b7d312c 100644
--- a/ichspi.c
+++ b/ichspi.c
@@ -405,18 +405,16 @@ static int reprogram_opcode_on_the_fly(uint8_t opcode, unsigned int writecnt, un
 			spi_type = SPI_OPCODE_TYPE_READ_NO_ADDRESS;
 		else if (writecnt == 4) // and readcnt is > 0
 			spi_type = SPI_OPCODE_TYPE_READ_WITH_ADDRESS;
-		// else we have an invalid case, will be handled below
-	}
-	if (spi_type <= 3) {
-		int oppos=2;	// use original JEDEC_BE_D8 offset
-		curopcodes->opcode[oppos].opcode = opcode;
-		curopcodes->opcode[oppos].spi_type = spi_type;
-		program_opcodes(curopcodes, 0);
-		oppos = find_opcode(curopcodes, opcode);
-		msg_pdbg ("on-the-fly OPCODE (0x%02X) re-programmed, op-pos=%d\n", opcode, oppos);
-		return oppos;
-	}
-	return -1;
+		else // we have an invalid case
+			return SPI_INVALID_LENGTH;
+	}
+	int oppos = 2;	// use original JEDEC_BE_D8 offset
+	curopcodes->opcode[oppos].opcode = opcode;
+	curopcodes->opcode[oppos].spi_type = spi_type;
+	program_opcodes(curopcodes, 0);
+	oppos = find_opcode(curopcodes, opcode);
+	msg_pdbg ("on-the-fly OPCODE (0x%02X) re-programmed, op-pos=%d\n", opcode, oppos);
+	return oppos;
 }
 
 static int find_opcode(OPCODES *op, uint8_t opcode)
@@ -1001,7 +999,10 @@ static int ich_spi_send_command(struct flashctx *flash, unsigned int writecnt,
 	if (opcode_index == -1) {
 		if (!ichspi_lock)
 			opcode_index = reprogram_opcode_on_the_fly(cmd, writecnt, readcnt);
-		if (opcode_index == -1) {
+		if (opcode_index == SPI_INVALID_LENGTH) {
+			msg_pdbg("OPCODE 0x%02x has unsupported length, will not execute.\n", cmd);
+			return SPI_INVALID_LENGTH;
+		} else if (opcode_index == -1) {
 			msg_pdbg("Invalid OPCODE 0x%02x, will not execute.\n",
 				 cmd);
 			return SPI_INVALID_OPCODE;
-- 
Kind regards, Stefan Tauner

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

Reply via email to