diff mbox

Print lock register configuration for N25Q128

Message ID 1468503734-4248-1-git-send-email-hatim@hatimak.me
State New
Headers show

Commit Message

Hatim Kanchwala July 14, 2016, 1:42 p.m. UTC
Hi,

As discussed over IRC, please apply this patch over the latest stable
branch of flashrom from https://github.com/flashrom/flashrom. This is
a "hacked" solution and is certainly not merge-worthy in its current
state.

Patch description -
  When prettyprinting status register byte 1 of N25Q128 chip, also print
  least two significant bits of lock register for each 64 kB sector.

Thanks,
Hatim

Signed-off-by: Hatim Kanchwala <hatim@hatimak.me>
---
 spi25_statusreg.c | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)
diff mbox

Patch

diff --git a/spi25_statusreg.c b/spi25_statusreg.c
index 266e7a9..b050ae1 100644
--- a/spi25_statusreg.c
+++ b/spi25_statusreg.c
@@ -454,58 +454,65 @@  static void spi_prettyprint_status_register_atmel_at25_swp(uint8_t status)
 }
 
 int spi_prettyprint_status_register_at25df(struct flashctx *flash)
 {
 	uint8_t status = spi_read_status_register(flash);
 	spi_prettyprint_status_register_hex(status);
 
 	spi_prettyprint_status_register_atmel_at25_srpl(status);
 	spi_prettyprint_status_register_bit(status, 6);
 	spi_prettyprint_status_register_atmel_at25_epewpp(status);
 	spi_prettyprint_status_register_atmel_at25_swp(status);
 	spi_prettyprint_status_register_welwip(status);
 
-	if (flash->chip->model_id == ATMEL_AT25DF161)
+	if (flash->chip->model_id == ST_N25Q128__3E)
 	{
 		int address, i, count, result;
-		unsigned char read_result, lockdown_status_sector[32], cmd[5];
-		cmd[0] = (unsigned char)0x35;
-		cmd[4] = (unsigned char)0x00;
+		uint8_t read_result, lockdown_status_sector[flash->chip->total_size / 64], cmd[4];
+		cmd[0] = (uint8_t)0xE8;
 
-		for (address = 0x000000, i = 0, count = 0; address < 0x200000; address += 0x010000, i++)
+		msg_cdbg("Additional information regarding block locks for %s\n", flash->chip->name);
+		for (address = 0x000000, i = 0, count = 0;
+			address < flash->chip->total_size * 1024;
+			address += 0x010000, i++)
 		{
 			cmd[1] = (unsigned char)(address >> 16) & 0xff;
 			cmd[2] = (unsigned char)(address >> 8) & 0xff;
 			cmd[3] = (unsigned char)address & 0xff;
-			result = spi_send_command(flash, sizeof(cmd), sizeof(unsigned char), cmd, &read_result);
+			result = spi_send_command(flash, sizeof(cmd), sizeof(uint8_t), cmd, &read_result);
 			if (result)
 			{
-				msg_cerr("%s failed during command execution (ATMEL_AT25DF161)\n", __func__);
+				msg_cerr("%s failed during command execution (ST_N25Q128__3E)\n", __func__);
 				return result;
 			}
 			if (i % 8 == 0)
 				msg_cdbg("0x%02x:", i);
-			msg_cdbg(" %02x%s", read_result, (i + 1) % 8 == 0 ? "\n": "");
-			lockdown_status_sector[address / 0x010000] = read_result;
-			if (read_result)
+			msg_cdbg(" [%s,%s]%s",
+				(read_result & 0x02) ? "1" : "0",
+				(read_result & 0x01) ? "1" : "0",
+				(i + 1) % 8 == 0 ? "\n": "");
+			lockdown_status_sector[address / 0x010000] = read_result & 0x03;
+			if (read_result & 0x01)
 				count++;
 		}
 
-		msg_cdbg("%d sector%s locked down permanently%s", count, (count == 1) ? "" : "s", (count == 0) ? "." : " :");
+		msg_cdbg("%d sector%s locked down%s", count, (count == 1) ? "" : "s",
+			(count == 0) ? "." : " :");
 		if (count)
-			for (i = 0; i < 32; i++)
+			for (i = 0; i < ARRAY_SIZE(lockdown_status_sector); i++)
 				if (lockdown_status_sector[i])
 					msg_cdbg(" %2d", i);
 		msg_cdbg("\n");
+		msg_cdbg("You _may_ be able to unlock the sector%s\n", (count == 1) ? "" : "s");
 	}
 
 	return 0;
 }
 
 int spi_prettyprint_status_register_at25df_sec(struct flashctx *flash)
 {
 	/* FIXME: We should check the security lockdown. */
 	msg_cdbg("Ignoring security lockdown (if present)\n");
 	msg_cdbg("Ignoring status register byte 2\n");
 	return spi_prettyprint_status_register_at25df(flash);
 }