Browse Source

rp: Made use of the SFDP routines to extract the necessary Flash parameters

pull/1185/head
dragonmux 2 years ago
committed by Piotr Esden-Tempski
parent
commit
9681475ab5
  1. 23
      src/target/rp.c

23
src/target/rp.c

@ -148,9 +148,17 @@ static int rp_flash_write(struct target_flash *f, target_addr dest, const void *
static bool rp_read_rom_func_table(target *t); static bool rp_read_rom_func_table(target *t);
static bool rp_attach(target *t); static bool rp_attach(target *t);
static void rp_flash_prepare(target *t);
static void rp_flash_resume(target *t);
static void rp_spi_read(target *t, uint16_t command, target_addr address, void *buffer, size_t length);
static uint32_t rp_get_flash_length(target *t); static uint32_t rp_get_flash_length(target *t);
static bool rp_mass_erase(target *t); static bool rp_mass_erase(target *t);
static void rp_spi_read_sfdp(target *const t, const uint32_t address, void *const buffer, const size_t length)
{
rp_spi_read(t, SPI_FLASH_CMD_READ_SFDP, address, buffer, length);
}
static void rp_add_flash(target *t, uint32_t addr, size_t length) static void rp_add_flash(target *t, uint32_t addr, size_t length)
{ {
struct target_flash *f = calloc(1, sizeof(*f)); struct target_flash *f = calloc(1, sizeof(*f));
@ -206,10 +214,19 @@ static bool rp_attach(target *t)
/* Free previously loaded memory map */ /* Free previously loaded memory map */
target_mem_map_free(t); target_mem_map_free(t);
size_t size = rp_get_flash_length(t); spi_parameters_s spi_parameters;
DEBUG_INFO("Flash size: %zu MB\n", size / (1024U * 1024U)); rp_flash_prepare(t);
if (!sfdp_read_parameters(t, &spi_parameters, rp_spi_read_sfdp)) {
rp_flash_resume(t);
/* SFDP readout failed, so make some assumptions and hope for the best. */
spi_parameters.capacity = rp_get_flash_length(t);
}
else
rp_flash_resume(t);
DEBUG_INFO("Flash size: %zu MB\n", spi_parameters.capacity / (1024U * 1024U));
rp_add_flash(t, RP_XIP_FLASH_BASE, size); rp_add_flash(t, RP_XIP_FLASH_BASE, spi_parameters.capacity);
target_add_ram(t, RP_SRAM_BASE, RP_SRAM_SIZE); target_add_ram(t, RP_SRAM_BASE, RP_SRAM_SIZE);
return true; return true;

Loading…
Cancel
Save