rp: More code re-ordering to make the order of definitions make more sense

This commit is contained in:
dragonmux 2022-07-31 16:42:07 +01:00 committed by Piotr Esden-Tempski
parent 982d1ac847
commit 7266e3cf54
1 changed files with 26 additions and 25 deletions

View File

@ -100,7 +100,9 @@ const struct command_s rp_cmd_list[] = {
static int rp_flash_erase(struct target_flash *f, target_addr addr, size_t len); static int rp_flash_erase(struct target_flash *f, target_addr addr, size_t len);
static int rp_flash_write(struct target_flash *f, target_addr dest, const void *src, size_t len); static int rp_flash_write(struct target_flash *f, target_addr dest, const void *src, size_t len);
static bool rp2040_fill_table(struct rp_priv_s *priv, uint16_t *table, int max);
static bool rp_attach(target *t); static bool rp_attach(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_add_flash(target *t, uint32_t addr, size_t length) static void rp_add_flash(target *t, uint32_t addr, size_t length)
@ -148,6 +150,30 @@ bool rp_probe(target *t)
return true; return true;
} }
static bool rp_attach(target *t)
{
if (!cortexm_attach(t))
return false;
struct rp_priv_s *ps = (struct rp_priv_s*)t->target_storage;
uint16_t table[RP_MAX_TABLE_SIZE];
uint16_t table_offset = target_mem_read32( t, BOOTROM_MAGIC_ADDR + 4);
if (target_mem_read(t, table, table_offset, RP_MAX_TABLE_SIZE) ||
rp2040_fill_table(ps, table, RP_MAX_TABLE_SIZE))
return false;
/* Free previously loaded memory map */
target_mem_map_free(t);
size_t size = rp_get_flash_length(t);
DEBUG_INFO("Flash size: %zu MB\n", size / (1024U * 1024U));
rp_add_flash(t, XIP_FLASH_START, size);
target_add_ram(t, SRAM_START, SRAM_SIZE);
return true;
}
static bool rp2040_fill_table(struct rp_priv_s *priv, uint16_t *table, int max) static bool rp2040_fill_table(struct rp_priv_s *priv, uint16_t *table, int max)
{ {
uint16_t tag = *table++; uint16_t tag = *table++;
@ -465,31 +491,6 @@ static uint32_t rp_get_flash_length(target *t)
return size; return size;
} }
static bool rp_attach(target *t)
{
if (!cortexm_attach(t))
return false;
struct rp_priv_s *ps = (struct rp_priv_s*)t->target_storage;
uint16_t table[RP_MAX_TABLE_SIZE];
uint16_t table_offset = target_mem_read32( t, BOOTROM_MAGIC_ADDR + 4);
if (target_mem_read(t, table, table_offset, RP_MAX_TABLE_SIZE))
return false;
if (rp2040_fill_table(ps, table, RP_MAX_TABLE_SIZE))
return false;
/* Free previously loaded memory map */
target_mem_map_free(t);
size_t size = rp_get_flash_length(t);
DEBUG_INFO("Flash size: %zu MB\n", size / (1024U * 1024U));
rp_add_flash(t, XIP_FLASH_START, size);
target_add_ram(t, SRAM_START, SRAM_SIZE);
return true;
}
static bool rp_cmd_erase_sector(target *t, int argc, const char **argv) static bool rp_cmd_erase_sector(target *t, int argc, const char **argv)
{ {
uint32_t start = t->flash->start; uint32_t start = t->flash->start;