at45db: Use .prepare_access hook for non-power-of-2 preparations
We performed some additional preparations in probe_spi_at45db(). Turn
it into a .prepare_access hook, spi_prepare_at45db(), so we can use
a pure probing function.
Change-Id: I75570078301b9a06a229543f44714a0941457a5a
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.sourcearcade.org/c/flashprog/+/74895
diff --git a/at45db.c b/at45db.c
index 67692d7..9593aa8 100644
--- a/at45db.c
+++ b/at45db.c
@@ -171,19 +171,23 @@
return 0;
}
-/* Probe function for AT45DB* chips that support multiple page sizes. */
-int probe_spi_at45db(struct flashctx *flash)
+/* Adapt chip entry for AT45DB* chips that support multiple page sizes. */
+int spi_prepare_at45db(struct flashctx *const flash, const enum preparation_steps prep)
{
+ struct flashchip *const chip = flash->chip;
uint8_t status;
- struct flashchip *chip = flash->chip;
- if (!probe_spi_rdid(flash))
+ if (prep != PREPARE_POST_PROBE)
+ return 0;
+
+ /* Power-of-2 check */
+ if (chip->page_size & (chip->page_size - 1))
return 0;
/* Some AT45DB* chips support two different page sizes each (e.g. 264 and 256 B). In order to tell which
* page size this chip has we need to read the status register. */
if (at45db_read_status_register(flash, &status) != 0)
- return 0;
+ return 1;
/* We assume sane power-of-2 page sizes and adjust the chip attributes in case this is not the case. */
if ((status & AT45DB_POWEROF2) == 0) {
@@ -208,12 +212,12 @@
case 1056: chip->gran = write_gran_1056bytes; break;
default:
msg_cerr("%s: unknown page size %d.\n", __func__, chip->page_size);
- return 0;
+ return 1;
}
msg_cdbg2("%s: total size %i kB, page size %i B\n", __func__, chip->total_size * 1024, chip->page_size);
- return 1;
+ return 0;
}
/* In case of non-power-of-two page sizes we need to convert the address flashprog uses to the address the
diff --git a/flashchips.c b/flashchips.c
index 990914f..5744ad7 100644
--- a/flashchips.c
+++ b/flashchips.c
@@ -2810,7 +2810,7 @@
/* OTP: 128B total, 64B pre-programmed; read 0x77; write 0x9B */
.feature_bits = FEATURE_OTP,
.tested = TEST_OK_PREW,
- .probe = probe_spi_at45db,
+ .probe = probe_spi_rdid,
.probe_timing = TIMING_ZERO,
.block_erasers =
{
@@ -2838,6 +2838,7 @@
.write = spi_write_at45db,
.read = spi_read_at45db, /* Fast read (0x0B) supported */
.voltage = {2700, 3600},
+ .prepare_access = spi_prepare_at45db,
},
{
@@ -2852,7 +2853,7 @@
/* OTP: 128B total, 64B pre-programmed; read 0x77; write 0x9B */
.feature_bits = FEATURE_OTP,
.tested = TEST_OK_PREW,
- .probe = probe_spi_at45db,
+ .probe = probe_spi_rdid,
.probe_timing = TIMING_ZERO,
.block_erasers =
{
@@ -2880,6 +2881,7 @@
.write = spi_write_at45db,
.read = spi_read_at45db, /* Fast read (0x0B) supported */
.voltage = {2700, 3600},
+ .prepare_access = spi_prepare_at45db,
},
{
@@ -2894,7 +2896,7 @@
/* OTP: 128B total, 64B pre-programmed; read 0x77; write 0x9B */
.feature_bits = FEATURE_OTP,
.tested = TEST_OK_PREW,
- .probe = probe_spi_at45db,
+ .probe = probe_spi_rdid,
.probe_timing = TIMING_ZERO,
.block_erasers =
{
@@ -2922,6 +2924,7 @@
.write = spi_write_at45db,
.read = spi_read_at45db, /* Fast read (0x0B) supported */
.voltage = {2700, 3600}, /* 2.5-3.6V & 2.7-3.6V models available */
+ .prepare_access = spi_prepare_at45db,
},
{
@@ -2936,7 +2939,7 @@
/* OTP: 128B total, 64B pre-programmed; read 0x77; write 0x9B */
.feature_bits = FEATURE_OTP,
.tested = TEST_OK_PREW,
- .probe = probe_spi_at45db,
+ .probe = probe_spi_rdid,
.probe_timing = TIMING_ZERO,
.block_erasers =
{
@@ -2964,6 +2967,7 @@
.write = spi_write_at45db,
.read = spi_read_at45db, /* Fast read (0x0B) supported */
.voltage = {2700, 3600}, /* 2.5-3.6V & 2.7-3.6V models available */
+ .prepare_access = spi_prepare_at45db,
},
{
@@ -2978,7 +2982,7 @@
/* OTP: 128B total, 64B pre-programmed; read 0x77; write 0x9B */
.feature_bits = FEATURE_OTP,
.tested = TEST_OK_PREW,
- .probe = probe_spi_at45db,
+ .probe = probe_spi_rdid,
.probe_timing = TIMING_ZERO,
.block_erasers =
{
@@ -3006,6 +3010,7 @@
.write = spi_write_at45db,
.read = spi_read_at45db, /* Fast read (0x0B) supported */
.voltage = {2700, 3600}, /* 2.5-3.6V & 2.7-3.6V models available */
+ .prepare_access = spi_prepare_at45db,
},
{
@@ -3063,7 +3068,7 @@
/* OTP: 128B total, 64B pre-programmed; read 0x77; write 0x9B */
.feature_bits = FEATURE_OTP,
.tested = TEST_OK_PREW,
- .probe = probe_spi_at45db,
+ .probe = probe_spi_rdid,
.probe_timing = TIMING_ZERO,
.block_erasers =
{
@@ -3091,6 +3096,7 @@
.write = spi_write_at45db,
.read = spi_read_at45db, /* Fast read (0x0B) supported */
.voltage = {2700, 3600}, /* 2.5-3.6V & 2.7-3.6V models available */
+ .prepare_access = spi_prepare_at45db,
},
{
@@ -3105,7 +3111,7 @@
/* OTP: 128B total, 64B pre-programmed; read 0x77; write 0x9B */
.feature_bits = FEATURE_OTP,
.tested = TEST_UNTESTED,
- .probe = probe_spi_at45db,
+ .probe = probe_spi_rdid,
.probe_timing = TIMING_ZERO,
.block_erasers =
{
@@ -3133,6 +3139,7 @@
.write = spi_write_at45db,
.read = spi_read_at45db, /* Fast read (0x0B) supported */
.voltage = {2500, 3600}, /* 2.3-3.6V & 2.5-3.6V models available */
+ .prepare_access = spi_prepare_at45db,
},
{
@@ -3147,7 +3154,7 @@
/* OTP: 128B total, 64B pre-programmed; read 0x77; write 0x9B */
.feature_bits = FEATURE_OTP,
.tested = TEST_OK_PREW,
- .probe = probe_spi_at45db,
+ .probe = probe_spi_rdid,
.probe_timing = TIMING_ZERO,
.block_erasers =
{
@@ -3175,6 +3182,7 @@
.write = spi_write_at45db,
.read = spi_read_at45db, /* Fast read (0x0B) supported */
.voltage = {2700, 3600},
+ .prepare_access = spi_prepare_at45db,
},
{
diff --git a/include/chipdrivers.h b/include/chipdrivers.h
index 0b1f1f6..f936b6a 100644
--- a/include/chipdrivers.h
+++ b/include/chipdrivers.h
@@ -128,7 +128,7 @@
int erase_opaque(struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
/* at45db.c */
-int probe_spi_at45db(struct flashctx *flash);
+int spi_prepare_at45db(struct flashctx *, const enum preparation_steps);
int spi_prettyprint_status_register_at45db(struct flashctx *flash);
int spi_disable_blockprotect_at45db(struct flashctx *flash);
int spi_read_at45db(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);