samd/samx5x: Switched to the unified mass erase command and added progress dots to stop GDB timing out
This commit is contained in:
parent
e9b75ba4bc
commit
94d5c0576b
|
@ -40,10 +40,9 @@
|
||||||
#include "cortexm.h"
|
#include "cortexm.h"
|
||||||
|
|
||||||
static int samd_flash_erase(struct target_flash *t, target_addr addr, size_t len);
|
static int samd_flash_erase(struct target_flash *t, target_addr addr, size_t len);
|
||||||
static int samd_flash_write(struct target_flash *f,
|
static int samd_flash_write(struct target_flash *f, target_addr dest, const void *src, size_t len);
|
||||||
target_addr dest, const void *src, size_t len);
|
bool samd_mass_erase(target *t);
|
||||||
|
|
||||||
bool samd_cmd_erase_all(target *t, int argc, const char **argv);
|
|
||||||
static bool samd_cmd_lock_flash(target *t, int argc, const char **argv);
|
static bool samd_cmd_lock_flash(target *t, int argc, const char **argv);
|
||||||
static bool samd_cmd_unlock_flash(target *t, int argc, const char **argv);
|
static bool samd_cmd_unlock_flash(target *t, int argc, const char **argv);
|
||||||
static bool samd_cmd_unlock_bootprot(target *t, int argc, const char **argv);
|
static bool samd_cmd_unlock_bootprot(target *t, int argc, const char **argv);
|
||||||
|
@ -54,7 +53,6 @@ static bool samd_cmd_mbist(target *t, int argc, const char **argv);
|
||||||
static bool samd_cmd_ssb(target *t, int argc, const char **argv);
|
static bool samd_cmd_ssb(target *t, int argc, const char **argv);
|
||||||
|
|
||||||
const struct command_s samd_cmd_list[] = {
|
const struct command_s samd_cmd_list[] = {
|
||||||
{"erase_mass", (cmd_handler)samd_cmd_erase_all, "Erase entire flash memory"},
|
|
||||||
{"lock_flash", (cmd_handler)samd_cmd_lock_flash, "Locks flash against spurious commands"},
|
{"lock_flash", (cmd_handler)samd_cmd_lock_flash, "Locks flash against spurious commands"},
|
||||||
{"unlock_flash", (cmd_handler)samd_cmd_unlock_flash, "Unlocks flash"},
|
{"unlock_flash", (cmd_handler)samd_cmd_unlock_flash, "Unlocks flash"},
|
||||||
{"lock_bootprot", (cmd_handler)samd_cmd_lock_bootprot, "Lock the boot protections to maximum"},
|
{"lock_bootprot", (cmd_handler)samd_cmd_lock_bootprot, "Lock the boot protections to maximum"},
|
||||||
|
@ -348,6 +346,7 @@ struct samd_descr {
|
||||||
char variant;
|
char variant;
|
||||||
char package[3];
|
char package[3];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct samd_descr samd_parse_device_id(uint32_t did)
|
struct samd_descr samd_parse_device_id(uint32_t did)
|
||||||
{
|
{
|
||||||
struct samd_descr samd;
|
struct samd_descr samd;
|
||||||
|
@ -357,14 +356,10 @@ struct samd_descr samd_parse_device_id(uint32_t did)
|
||||||
samd.ram_size = 0x8000;
|
samd.ram_size = 0x8000;
|
||||||
samd.flash_size = 0x40000;
|
samd.flash_size = 0x40000;
|
||||||
|
|
||||||
uint8_t family = (did >> SAMD_DID_FAMILY_POS)
|
uint8_t family = (did >> SAMD_DID_FAMILY_POS) & SAMD_DID_FAMILY_MASK;
|
||||||
& SAMD_DID_FAMILY_MASK;
|
uint8_t series = (did >> SAMD_DID_SERIES_POS) & SAMD_DID_SERIES_MASK;
|
||||||
uint8_t series = (did >> SAMD_DID_SERIES_POS)
|
uint8_t revision = (did >> SAMD_DID_REVISION_POS) & SAMD_DID_REVISION_MASK;
|
||||||
& SAMD_DID_SERIES_MASK;
|
uint8_t devsel = (did >> SAMD_DID_DEVSEL_POS) & SAMD_DID_DEVSEL_MASK;
|
||||||
uint8_t revision = (did >> SAMD_DID_REVISION_POS)
|
|
||||||
& SAMD_DID_REVISION_MASK;
|
|
||||||
uint8_t devsel = (did >> SAMD_DID_DEVSEL_POS)
|
|
||||||
& SAMD_DID_DEVSEL_MASK;
|
|
||||||
|
|
||||||
/* Family */
|
/* Family */
|
||||||
switch (family) {
|
switch (family) {
|
||||||
|
@ -468,6 +463,7 @@ struct samd_priv_s {
|
||||||
char samd_variant_string[60];
|
char samd_variant_string[60];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
bool samd_probe(target *t)
|
bool samd_probe(target *t)
|
||||||
{
|
{
|
||||||
ADIv5_AP_t *ap = cortexm_ap(t);
|
ADIv5_AP_t *ap = cortexm_ap(t);
|
||||||
|
@ -486,6 +482,7 @@ bool samd_probe(target *t)
|
||||||
if ((did & SAMD_DID_MASK) != SAMD_DID_CONST_VALUE)
|
if ((did & SAMD_DID_MASK) != SAMD_DID_CONST_VALUE)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
t->mass_erase = samd_mass_erase;
|
||||||
struct samd_priv_s *priv_storage = calloc(1, sizeof(*priv_storage));
|
struct samd_priv_s *priv_storage = calloc(1, sizeof(*priv_storage));
|
||||||
t->target_storage = (void*)priv_storage;
|
t->target_storage = (void*)priv_storage;
|
||||||
|
|
||||||
|
@ -639,10 +636,8 @@ static int samd_flash_write(struct target_flash *f,
|
||||||
/**
|
/**
|
||||||
* Uses the Device Service Unit to erase the entire flash
|
* Uses the Device Service Unit to erase the entire flash
|
||||||
*/
|
*/
|
||||||
bool samd_cmd_erase_all(target *t, int argc, const char **argv)
|
bool samd_mass_erase(target *t)
|
||||||
{
|
{
|
||||||
(void)argc;
|
|
||||||
(void)argv;
|
|
||||||
/* Clear the DSU status bits */
|
/* Clear the DSU status bits */
|
||||||
target_mem_write32(t, SAMD_DSU_CTRLSTAT,
|
target_mem_write32(t, SAMD_DSU_CTRLSTAT,
|
||||||
SAMD_STATUSA_DONE | SAMD_STATUSA_PERR |
|
SAMD_STATUSA_DONE | SAMD_STATUSA_PERR |
|
||||||
|
@ -651,12 +646,16 @@ bool samd_cmd_erase_all(target *t, int argc, const char **argv)
|
||||||
/* Erase all */
|
/* Erase all */
|
||||||
target_mem_write32(t, SAMD_DSU_CTRLSTAT, SAMD_CTRL_CHIP_ERASE);
|
target_mem_write32(t, SAMD_DSU_CTRLSTAT, SAMD_CTRL_CHIP_ERASE);
|
||||||
|
|
||||||
|
platform_timeout timeout;
|
||||||
|
platform_timeout_set(&timeout, 500);
|
||||||
/* Poll for DSU Ready */
|
/* Poll for DSU Ready */
|
||||||
uint32_t status;
|
uint32_t status;
|
||||||
while (((status = target_mem_read32(t, SAMD_DSU_CTRLSTAT)) &
|
while (((status = target_mem_read32(t, SAMD_DSU_CTRLSTAT)) &
|
||||||
(SAMD_STATUSA_DONE | SAMD_STATUSA_PERR | SAMD_STATUSA_FAIL)) == 0)
|
(SAMD_STATUSA_DONE | SAMD_STATUSA_PERR | SAMD_STATUSA_FAIL)) == 0) {
|
||||||
if (target_check_error(t))
|
if (target_check_error(t))
|
||||||
return false;
|
return false;
|
||||||
|
target_print_progress(&timeout);
|
||||||
|
}
|
||||||
|
|
||||||
/* Test the protection error bit in Status A */
|
/* Test the protection error bit in Status A */
|
||||||
if (status & SAMD_STATUSA_PERR) {
|
if (status & SAMD_STATUSA_PERR) {
|
||||||
|
@ -669,9 +668,6 @@ bool samd_cmd_erase_all(target *t, int argc, const char **argv)
|
||||||
tc_printf(t, "Erase failed.\n");
|
tc_printf(t, "Erase failed.\n");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
tc_printf(t, "Erase successful!\n");
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,9 +52,8 @@ static bool samx5x_cmd_ssb(target *t, int argc, const char **argv);
|
||||||
static bool samx5x_cmd_update_user_word(target *t, int argc, const char **argv);
|
static bool samx5x_cmd_update_user_word(target *t, int argc, const char **argv);
|
||||||
|
|
||||||
/* (The SAM D1x/2x implementation of erase_all is reused as it's identical)*/
|
/* (The SAM D1x/2x implementation of erase_all is reused as it's identical)*/
|
||||||
extern bool samd_cmd_erase_all(target *t, int argc, const char **argv);
|
bool samd_mass_erase(target *t);
|
||||||
#define samx5x_cmd_erase_all samd_cmd_erase_all
|
#define samx5x_mass_erase samd_mass_erase
|
||||||
|
|
||||||
|
|
||||||
#ifdef SAMX5X_EXTRA_CMDS
|
#ifdef SAMX5X_EXTRA_CMDS
|
||||||
static bool samx5x_cmd_mbist(target *t, int argc, const char **argv);
|
static bool samx5x_cmd_mbist(target *t, int argc, const char **argv);
|
||||||
|
@ -64,8 +63,6 @@ static bool samx5x_cmd_write32(target *t, int argc, const char **argv);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const struct command_s samx5x_cmd_list[] = {
|
const struct command_s samx5x_cmd_list[] = {
|
||||||
{"erase_mass", (cmd_handler)samx5x_cmd_erase_all,
|
|
||||||
"Erase entire flash memory"},
|
|
||||||
{"lock_flash", (cmd_handler)samx5x_cmd_lock_flash,
|
{"lock_flash", (cmd_handler)samx5x_cmd_lock_flash,
|
||||||
"Locks flash against spurious commands"},
|
"Locks flash against spurious commands"},
|
||||||
{"unlock_flash", (cmd_handler)samx5x_cmd_unlock_flash,
|
{"unlock_flash", (cmd_handler)samx5x_cmd_unlock_flash,
|
||||||
|
@ -95,12 +92,6 @@ const struct command_s samx5x_cmd_list[] = {
|
||||||
{NULL, NULL, NULL}
|
{NULL, NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct command_s samx5x_protected_cmd_list[] = {
|
|
||||||
{"erase_mass", (cmd_handler)samx5x_cmd_erase_all,
|
|
||||||
"Erase entire flash memory"},
|
|
||||||
{NULL, NULL, NULL}
|
|
||||||
};
|
|
||||||
|
|
||||||
/* RAM Parameters */
|
/* RAM Parameters */
|
||||||
#define SAMX5X_RAM_START 0x20000000
|
#define SAMX5X_RAM_START 0x20000000
|
||||||
|
|
||||||
|
@ -391,6 +382,7 @@ bool samx5x_probe(target *t)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Setup Target */
|
/* Setup Target */
|
||||||
|
t->mass_erase = samx5x_mass_erase;
|
||||||
t->driver = priv_storage->samx5x_variant_string;
|
t->driver = priv_storage->samx5x_variant_string;
|
||||||
t->reset = samx5x_reset;
|
t->reset = samx5x_reset;
|
||||||
|
|
||||||
|
@ -426,10 +418,7 @@ bool samx5x_probe(target *t)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (protected)
|
if (!protected)
|
||||||
target_add_commands(t, samx5x_protected_cmd_list,
|
|
||||||
"SAMD5x/E5x (protected)");
|
|
||||||
else
|
|
||||||
target_add_commands(t, samx5x_cmd_list, "SAMD5x/E5x");
|
target_add_commands(t, samx5x_cmd_list, "SAMD5x/E5x");
|
||||||
|
|
||||||
/* If we're not in reset here */
|
/* If we're not in reset here */
|
||||||
|
|
Loading…
Reference in New Issue