aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas Vanek <vanekt@fbl.cz>2022-10-02 11:21:42 +0200
committerAntonio Borneo <borneo.antonio@gmail.com>2023-01-15 14:55:25 +0000
commit0979cbc5bcf0688d10815aaa1b938a6086e75f0e (patch)
treef8020ddf59893be536fa5114cfd97938e560272a
parent59763653c631625f195bf652f226f8537fe66832 (diff)
downloadriscv-openocd-0979cbc5bcf0688d10815aaa1b938a6086e75f0e.zip
riscv-openocd-0979cbc5bcf0688d10815aaa1b938a6086e75f0e.tar.gz
riscv-openocd-0979cbc5bcf0688d10815aaa1b938a6086e75f0e.tar.bz2
flash/nor/rp2040: make SPI flash ID detection optional
Do not read ID from SPI flash and suppress autodetection if non-zero flash bank size is configured. Change-Id: Idcf9ee6ca17f9fa89964a60da7bf11e47b4af5e7 Signed-off-by: Tomas Vanek <vanekt@fbl.cz> Reviewed-on: https://review.openocd.org/c/openocd/+/7241 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
-rw-r--r--src/flash/nor/rp2040.c55
1 files changed, 33 insertions, 22 deletions
diff --git a/src/flash/nor/rp2040.c b/src/flash/nor/rp2040.c
index feff9a6..b0d118b 100644
--- a/src/flash/nor/rp2040.c
+++ b/src/flash/nor/rp2040.c
@@ -50,6 +50,10 @@ struct rp2040_flash_bank {
const struct flash_device *dev;
};
+/* guessed SPI flash description if autodetection disabled (same as win w25q16jv) */
+static const struct flash_device rp2040_default_spi_device =
+ FLASH_ID("autodetect disabled", 0x03, 0x00, 0x02, 0xd8, 0xc7, 0, 0x100, 0x10000, 0);
+
static uint32_t rp2040_lookup_symbol(struct target *target, uint32_t tag, uint16_t *symbol)
{
uint32_t magic;
@@ -432,41 +436,48 @@ static int rp2040_flash_probe(struct flash_bank *bank)
return err;
}
- err = rp2040_stack_grab_and_prep(bank);
+ if (bank->size) {
+ /* size overridden, suppress reading SPI flash ID */
+ priv->dev = &rp2040_default_spi_device;
+ LOG_DEBUG("SPI flash autodetection disabled, using configured size");
- uint32_t device_id = 0;
- if (err == ERROR_OK)
- err = rp2040_spi_read_flash_id(target, &device_id);
+ } else {
+ /* zero bank size in cfg, read SPI flash ID and autodetect */
+ err = rp2040_stack_grab_and_prep(bank);
- rp2040_finalize_stack_free(bank);
+ uint32_t device_id = 0;
+ if (err == ERROR_OK)
+ err = rp2040_spi_read_flash_id(target, &device_id);
- if (err != ERROR_OK)
- return err;
+ rp2040_finalize_stack_free(bank);
- /* search for a SPI flash Device ID match */
- priv->dev = NULL;
- for (const struct flash_device *p = flash_devices; p->name ; p++)
- if (p->device_id == device_id) {
- priv->dev = p;
- break;
+ if (err != ERROR_OK)
+ return err;
+
+ /* search for a SPI flash Device ID match */
+ priv->dev = NULL;
+ for (const struct flash_device *p = flash_devices; p->name ; p++)
+ if (p->device_id == device_id) {
+ priv->dev = p;
+ break;
+ }
+
+ if (!priv->dev) {
+ LOG_ERROR("Unknown flash device (ID 0x%08" PRIx32 ")", device_id);
+ return ERROR_FAIL;
}
+ LOG_INFO("Found flash device '%s' (ID 0x%08" PRIx32 ")",
+ priv->dev->name, priv->dev->device_id);
- if (!priv->dev) {
- LOG_ERROR("Unknown flash device (ID 0x%08" PRIx32 ")", device_id);
- return ERROR_FAIL;
+ bank->size = priv->dev->size_in_bytes;
}
- LOG_INFO("Found flash device \'%s\' (ID 0x%08" PRIx32 ")",
- priv->dev->name, priv->dev->device_id);
-
/* the Boot ROM flash_range_program() routine requires page alignment */
bank->write_start_alignment = priv->dev->pagesize;
bank->write_end_alignment = priv->dev->pagesize;
- bank->size = priv->dev->size_in_bytes;
-
bank->num_sectors = bank->size / priv->dev->sectorsize;
- LOG_INFO("RP2040 B0 Flash Probe: %d bytes @" TARGET_ADDR_FMT ", in %d sectors\n",
+ LOG_INFO("RP2040 B0 Flash Probe: %" PRIu32 " bytes @" TARGET_ADDR_FMT ", in %u sectors\n",
bank->size, bank->base, bank->num_sectors);
bank->sectors = alloc_block_array(0, priv->dev->sectorsize, bank->num_sectors);
if (!bank->sectors)