rp: Cleanup in how we define some of the Flash constants

This commit is contained in:
dragonmux 2022-07-12 20:59:21 -04:00 committed by Piotr Esden-Tempski
parent ce94169099
commit d64992ade8
1 changed files with 53 additions and 58 deletions

View File

@ -52,10 +52,12 @@
#define SSI_DR0_ADDR 0x18000060
#define QSPI_CTRL_ADDR 0x4001800c
#define FLASHSIZE_4K_SECTOR (4 * 1024)
#define FLASHSIZE_32K_BLOCK (32 * 1024)
#define FLASHSIZE_64K_BLOCK (64 * 1024)
#define MAX_FLASH (16 * 1024 * 1024)
#define FLASHSIZE_4K_SECTOR (4U * 1024U)
#define FLASHSIZE_32K_BLOCK (32U * 1024U)
#define FLASHSIZE_64K_BLOCK (64U * 1024U)
#define FLASHSIZE_32K_BLOCK_MASK ~(FLASHSIZE_32K_BLOCK - 1U)
#define FLASHSIZE_64K_BLOCK_MASK ~(FLASHSIZE_64K_BLOCK - 1U)
#define MAX_FLASH (16U * 1024U * 1024U)
/* Instruction codes taken from Winbond W25Q16JV datasheet, as used on the
* original Pico board from Raspberry Pi.
@ -127,9 +129,8 @@ static bool rp2040_fill_table(struct rp_priv_s *priv, uint16_t *table, int max)
}
tag = *table++;
}
DEBUG_TARGET("connect %04x debug_trampoline %04x end %04x\n",
priv->_connect_internal_flash, priv->_debug_trampoline,
priv->_debug_trampoline_end);
DEBUG_TARGET("connect %04x debug_trampoline %04x end %04x\n", priv->_connect_internal_flash,
priv->_debug_trampoline, priv->_debug_trampoline_end);
return (check != 9);
}
@ -178,8 +179,7 @@ static bool rp_rom_call(target *t, uint32_t *regs, uint32_t cmd, uint32_t timeou
target_regs_read(t, dbg_regs);
bool ret = ((dbg_regs[REG_PC] & ~1) != (ps->_debug_trampoline_end & ~1));
if (ret) {
DEBUG_WARN("rp_rom_call cmd %04" PRIx32 " failed, PC %08" PRIx32 "\n",
cmd, dbg_regs[REG_PC]);
DEBUG_WARN("rp_rom_call cmd %04" PRIx32 " failed, PC %08" PRIx32 "\n", cmd, dbg_regs[REG_PC]);
}
return ret;
}
@ -241,7 +241,7 @@ static int rp_flash_erase(struct target_flash *f, target_addr addr, size_t len)
bool ret = 0;
while (len) {
if (len >= FLASHSIZE_64K_BLOCK) {
const uint32_t chunk = len & ~(FLASHSIZE_64K_BLOCK - 1U);
const uint32_t chunk = len & FLASHSIZE_64K_BLOCK_MASK;
ps->regs[0] = addr;
ps->regs[1] = chunk;
ps->regs[2] = FLASHSIZE_64K_BLOCK;
@ -251,7 +251,7 @@ static int rp_flash_erase(struct target_flash *f, target_addr addr, size_t len)
len -= chunk;
addr += chunk;
} else if (len >= FLASHSIZE_32K_BLOCK) {
const uint32_t chunk = len & ~(FLASHSIZE_32K_BLOCK - 1U);
const uint32_t chunk = len & FLASHSIZE_32K_BLOCK_MASK;
ps->regs[0] = addr;
ps->regs[1] = chunk;
ps->regs[2] = FLASHSIZE_32K_BLOCK;
@ -306,8 +306,7 @@ static int rp_flash_write(struct target_flash *f, target_addr dest, const void *
* however it takes much longer if the XOSC is not enabled
* so lets give ourselves a little bit more time (x10)
*/
ret |= rp_rom_call(t, ps->regs, ps->flash_range_program,
(3 * chunksize * 10) >> 8);
ret |= rp_rom_call(t, ps->regs, ps->flash_range_program, (3 * chunksize * 10) >> 8);
if (ret) {
DEBUG_WARN("Write failed!\n");
break;
@ -353,8 +352,7 @@ static bool rp_cmd_erase_sector(target *t, int argc, const char *argv[])
if (argc == 3) {
start = strtoul(argv[1], NULL, 0);
length = strtoul(argv[2], NULL, 0);
}
else if (argc == 2)
} else if (argc == 2)
length = strtoul(argv[1], NULL, 0);
else
return -1;
@ -366,11 +364,8 @@ static bool rp_cmd_erase_sector(target *t, int argc, const char *argv[])
return result;
}
const struct command_s rp_cmd_list[] = {
{"erase_sector", rp_cmd_erase_sector, "Erase a sector: [start address] length" },
{"reset_usb_boot", rp_cmd_reset_usb_boot, "Reboot the device into BOOTSEL mode"},
{NULL, NULL, NULL}
};
const struct command_s rp_cmd_list[] = {{"erase_sector", rp_cmd_erase_sector, "Erase a sector: [start address] length"},
{"reset_usb_boot", rp_cmd_reset_usb_boot, "Reboot the device into BOOTSEL mode"}, {NULL, NULL, NULL}};
static void rp_add_flash(target *t, uint32_t addr, size_t length)
{