From 871811ebe82fb9f9be16b4102626552b9f845f42 Mon Sep 17 00:00:00 2001
In-Reply-To: <156892285.20160612183407@yelsakov.ru>
References: <156892285.20160612183407@yelsakov.ru>
From: Hatim Kanchwala <hatim@hatimak.me>
Date: Mon, 13 Jun 2016 16:43:34 +0530
Subject: [PATCH] Print sector lockdown registers for AT25DF161
To: alexey@yelsakov.ru
Cc: flashrom@flashrom.org
When pretty-printing status register byte 1 of AT25DF chips, if chip
is AT25DF161, also print the values of sector lockdown registers for
each of the 32 64kB sectors.
Signed-off-by: Hatim Kanchwala <hatim@hatimak.me>
---
spi25_statusreg.c | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
@@ -14,26 +14,27 @@
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "flash.h"
#include "chipdrivers.h"
#include "spi.h"
+#include "flashchips.h"
/* === Generic functions === */
int spi_write_status_enable(struct flashctx *flash)
{
static const unsigned char cmd[JEDEC_EWSR_OUTSIZE] = { JEDEC_EWSR };
int result;
/* Send EWSR (Enable Write Status Register). */
result = spi_send_command(flash, sizeof(cmd), JEDEC_EWSR_INSIZE, cmd, NULL);
if (result)
msg_cerr("%s failed\n", __func__);
@@ -452,26 +453,61 @@ 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)
+ {
+ int address, i, count, result;
+ unsigned char read_result, lockdown_status_sector[64], cmd[5];
+ cmd[0] = (unsigned char)0x35;
+ cmd[4] = (unsigned char)0x00;
+
+ for (address = 0x000000, i = 0, count = 0; address < 0x200000; 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);
+ if (result)
+ {
+ msg_cerr("%s failed during command execution (ATMEL_AT25DF161)\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)
+ count++;
+ }
+
+ msg_cdbg("%d sector%s locked down permanently%s", count, (count == 1) ? "" : "s", (count == 0) ? "." : " :");
+ if (count)
+ for (i = 0; i < 64; i++)
+ if (lockdown_status_sector[i])
+ msg_cdbg(" %2d", i);
+ msg_cdbg("\n");
+ }
+
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);
}
/* used for AT25F512, AT25F1024(A), AT25F2048 */
int spi_prettyprint_status_register_at25f(struct flashctx *flash)
--
http://hatimak.me