update flash_bsl for increased erase functionality

"erase all" seems to be unsupported by the BSL. Only DEVICE_ERASE_MAIN
and DEVICE_ERASE_SEGMENT are therefore implemented. DEVICE_ERASE_ALL
could be implemented, if the addresses of information memory were known.
This commit is contained in:
Andrew Armenia 2010-12-01 14:29:17 +13:00 committed by Daniel Beer
parent a08d11b25b
commit 1f7808a78f
1 changed files with 23 additions and 9 deletions

View File

@ -331,17 +331,30 @@ static int flash_bsl_erase(device_t dev_base, device_erase_type_t type,
address_t addr)
{
struct flash_bsl_device *dev = (struct flash_bsl_device *)dev_base;
const uint8_t mass_erase_cmd[] = { MASS_ERASE };
uint8_t erase_cmd[4];
uint8_t response_buffer[16];
int ret;
if (type != DEVICE_ERASE_ALL) {
printc_err("flash_bsl_erase: only mass erase is supported\n");
if (type == DEVICE_ERASE_ALL) {
printc_err("flash_bsl_erase: simultaneous code/info erase not supported\n");
return -1;
}
if (flash_bsl_send(dev, mass_erase_cmd, sizeof(mass_erase_cmd)) < 0) {
printc_err("flash_bsl_erase: failed to send erase command\n");
} else if (type == DEVICE_ERASE_MAIN) {
erase_cmd[0] = MASS_ERASE;
if (flash_bsl_send(dev, erase_cmd, 1) < 0) {
printc_err("flash_bsl_erase: failed to send erase command\n");
return -1;
}
} else if (type == DEVICE_ERASE_SEGMENT) {
erase_cmd[0] = ERASE_SEGMENT;
erase_cmd[1] = addr & 0xff;
erase_cmd[2] = (addr >> 8) & 0xff;
erase_cmd[3] = (addr >> 16) & 0xff;
if (flash_bsl_send(dev, erase_cmd, 4) < 0) {
printc_err("flash_bsl_erase: failed to send erase command\n");
return -1;
}
} else {
printc_err("flash_bsl_erase: unsupported erase type\n");
return -1;
}
@ -386,8 +399,9 @@ static int flash_bsl_unlock(struct flash_bsl_device *dev)
uint8_t response_buffer[16];
int ret;
/* mass erase (this might wipe Information Memory on some devices */
if (flash_bsl_erase((device_t)dev, DEVICE_ERASE_ALL, 0) < 0) {
/* mass erase - this might wipe Information Memory on some devices */
/* (according to the documentation it should not) */
if (flash_bsl_erase((device_t)dev, DEVICE_ERASE_MAIN, 0) < 0) {
printc_err("flash_bsl_unlock: warning: erase failed\n");
}