Don't issue mass erase if BSL password is specified.

This commit is contained in:
Daniel Beer 2019-03-12 12:16:35 +13:00
parent 5c5fec9acd
commit d59fb64ac2
4 changed files with 24 additions and 11 deletions

View File

@ -74,6 +74,7 @@ struct device_breakpoint {
#define DEVICE_FLAG_FORCE_RESET 0x08
#define DEVICE_FLAG_DO_FWUPDATE 0x10
#define DEVICE_FLAG_SKIP_CLOSE 0x20
#define DEVICE_FLAG_BSL_NME 0x40 /* BSL no-mass-erase */
struct device_args {
int flags;

View File

@ -404,12 +404,6 @@ static int flash_bsl_unlock(struct flash_bsl_device *dev,
memcpy(rx_password_cmd + 1, password, 32);
/* 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");
}
/* send password (which is now erased FLASH) */
if (dev->long_password) {
#if defined(FLASH_BSL_VERBOSE)
@ -627,6 +621,16 @@ static device_t flash_bsl_open(const struct device_args *args)
delay_ms(500);
/* mass erase - this might wipe Information Memory on some devices */
/* (according to the documentation it should not) */
if (!(args->flags & DEVICE_FLAG_BSL_NME)) {
printc("Performing initial mass erase...\n");
if (flash_bsl_erase((device_t)dev, DEVICE_ERASE_MAIN, 0) < 0) {
printc_err("flash_bsl_unlock: warning: erase failed\n");
goto fail;
}
}
/* unlock device (erase then send password) */
if (flash_bsl_unlock(dev, args->bsl_entry_password) < 0) {
goto fail;

View File

@ -404,8 +404,7 @@ static int rom_bsl_erase(device_t dev_base, device_erase_type_t type,
return 0;
}
static int unlock_device(struct rom_bsl_device *dev,
const uint8_t *password)
static int mass_erase(struct rom_bsl_device *dev)
{
printc_dbg("Performing mass erase...\n");
@ -414,6 +413,12 @@ static int unlock_device(struct rom_bsl_device *dev,
return -1;
}
return 0;
}
static int unlock_device(struct rom_bsl_device *dev,
const uint8_t *password)
{
printc_dbg("Sending password...\n");
if (rom_bsl_xfer(dev, CMD_RX_PASSWORD, 0, password, 32) < 0) {
@ -481,10 +486,12 @@ static device_t rom_bsl_open(const struct device_args *args)
dev->reply_buf[15],
dev->reply_buf[16]);
if (unlock_device(dev, args->bsl_entry_password) < 0) {
printc_err("rom_bsl: failed to unlock\n");
if (!(args->flags & DEVICE_FLAG_BSL_NME) &&
mass_erase(dev) < 0)
goto fail;
if (unlock_device(dev, args->bsl_entry_password) < 0)
goto fail;
}
return (device_t)dev;

View File

@ -352,6 +352,7 @@ static int parse_cmdline_args(int argc, char **argv,
fprintf(stderr, "invalid BSL password\n");
return -1;
}
args->devarg.flags |= DEVICE_FLAG_BSL_NME;
break;
case LOPT_BSL_ENTRY_SEQUENCE: