dsp5680xx - mark erase after unlocking flash

the unlocking procedure erases the flash mem (even if it wasn't locked), so it should be marked as erased after unlocking.

Change-Id: I5cc6a1e1d6cf4e1f243de532eff54111ffd66187
Signed-off-by: Rodrigo L. Rosa <rodrigorosa.lg@gmail.com>
Reviewed-on: http://openocd.zylin.com/222
Tested-by: jenkins
Reviewed-by: Øyvind Harboe <oyvindharboe@gmail.com>
This commit is contained in:
rodrigo_l_rosa 2011-11-19 15:39:20 -08:00 committed by Øyvind Harboe
parent e0c0810a8e
commit c725167ba8
2 changed files with 61 additions and 50 deletions

View File

@ -132,8 +132,15 @@ static int dsp5680xx_flash_protect(struct flash_bank *bank, int set, int first,
int retval; int retval;
if(set) if(set)
retval = dsp5680xx_f_lock(bank->target); retval = dsp5680xx_f_lock(bank->target);
else else{
retval = dsp5680xx_f_unlock(bank->target); retval = dsp5680xx_f_unlock(bank->target);
if (retval == ERROR_OK) {
/* mark all as erased */
for (int i = 0; i <= (HFM_SECTOR_COUNT-1); i++)
/* FM does not recognize it as erased if erased via JTAG. */
bank->sectors[i].is_erased = 1;
}
}
return retval; return retval;
} }

View File

@ -64,22 +64,24 @@ static int reset_jtag(void){
return retval; return retval;
} }
static int dsp5680xx_drscan(struct target * target, uint8_t * data_to_shift_into_dr, uint8_t * data_shifted_out_of_dr, int len){ static int dsp5680xx_drscan(struct target *target, uint8_t *d_in, uint8_t *d_out, int len)
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- {
// /** -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
// Inputs: *
// - data_to_shift_into_dr: This is the data that will be shifted into the JTAG DR reg. * Inputs:
// - data_shifted_out_of_dr: The data that will be shifted out of the JTAG DR reg will stored here * - d_in: This is the data that will be shifted into the JTAG DR reg.
// - len: Length of the data to be shifted to JTAG DR. * - d_out: The data that will be shifted out of the JTAG DR reg will stored here
// * - len: Length of the data to be shifted to JTAG DR.
// Note: If data_shifted_out_of_dr == NULL, discard incoming bits. *
// * Note: If d_out == NULL, discard incoming bits.
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- *
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
*/
int retval = ERROR_OK; int retval = ERROR_OK;
if (NULL == target->tap){ if (NULL == target->tap) {
retval = ERROR_FAIL; retval = ERROR_FAIL;
err_check(retval, DSP5680XX_ERROR_JTAG_INVALID_TAP, "Invalid tap"); err_check(retval, DSP5680XX_ERROR_JTAG_INVALID_TAP, "Invalid tap");
} }
if (len > 32){ if (len > 32){
retval = ERROR_FAIL; retval = ERROR_FAIL;
err_check(retval, DSP5680XX_ERROR_JTAG_DR_LEN_OVERFLOW, "dr_len overflow, maxium is 32"); err_check(retval, DSP5680XX_ERROR_JTAG_DR_LEN_OVERFLOW, "dr_len overflow, maxium is 32");
@ -87,14 +89,14 @@ static int dsp5680xx_drscan(struct target * target, uint8_t * data_to_shift_into
//TODO what values of len are valid for jtag_add_plain_dr_scan? //TODO what values of len are valid for jtag_add_plain_dr_scan?
//can i send as many bits as i want? //can i send as many bits as i want?
//is the casting necessary? //is the casting necessary?
jtag_add_plain_dr_scan(len,data_to_shift_into_dr,data_shifted_out_of_dr, TAP_IDLE); jtag_add_plain_dr_scan(len, d_in, d_out, TAP_IDLE);
if(dsp5680xx_context.flush){ if(dsp5680xx_context.flush){
retval = dsp5680xx_execute_queue(); retval = dsp5680xx_execute_queue();
err_check(retval, DSP5680XX_ERROR_JTAG_DRSCAN, "drscan failed!"); err_check(retval, DSP5680XX_ERROR_JTAG_DRSCAN, "drscan failed!");
} }
if(data_shifted_out_of_dr!=NULL){ if (d_out != NULL)
LOG_DEBUG("Data read (%d bits): 0x%04X",len,*data_shifted_out_of_dr); LOG_DEBUG("Data read (%d bits): 0x%04X", len, *d_out);
}else else
LOG_DEBUG("Data read was discarded."); LOG_DEBUG("Data read was discarded.");
return retval; return retval;
} }
@ -478,20 +480,21 @@ static int switch_tap(struct target * target, struct jtag_tap * master_tap,struc
int retval = ERROR_OK; int retval = ERROR_OK;
uint32_t instr; uint32_t instr;
uint32_t ir_out;//not used, just to make jtag happy. uint32_t ir_out;//not used, just to make jtag happy.
if(master_tap == NULL){ if (master_tap == NULL) {
master_tap = jtag_tap_by_string("dsp568013.chp"); master_tap = jtag_tap_by_string("dsp568013.chp");
if(master_tap == NULL){ if (master_tap == NULL) {
retval = ERROR_FAIL; retval = ERROR_FAIL;
err_check(retval, DSP5680XX_ERROR_JTAG_TAP_FIND_MASTER, "Failed to get master tap."); const char *msg = "Failed to get master tap.";
err_check(retval, DSP5680XX_ERROR_JTAG_TAP_FIND_MASTER, msg);
} }
} }
if(core_tap == NULL){ if (core_tap == NULL) {
core_tap = jtag_tap_by_string("dsp568013.cpu"); core_tap = jtag_tap_by_string("dsp568013.cpu");
if(core_tap == NULL){ if (core_tap == NULL) {
retval = ERROR_FAIL; retval = ERROR_FAIL;
err_check(retval, DSP5680XX_ERROR_JTAG_TAP_FIND_CORE, "Failed to get core tap."); err_check(retval, DSP5680XX_ERROR_JTAG_TAP_FIND_CORE, "Failed to get core tap.");
} }
} }
if(!(((int)master_tap->enabled) ^ ((int)core_tap->enabled))){ if(!(((int)master_tap->enabled) ^ ((int)core_tap->enabled))){
LOG_WARNING("Wrong tap enabled/disabled status:\nMaster tap:%d\nCore Tap:%d\nOnly one tap should be enabled at a given time.\n",(int)master_tap->enabled,(int)core_tap->enabled); LOG_WARNING("Wrong tap enabled/disabled status:\nMaster tap:%d\nCore Tap:%d\nOnly one tap should be enabled at a given time.\n",(int)master_tap->enabled,(int)core_tap->enabled);
@ -592,18 +595,18 @@ static int eonce_enter_debug_mode(struct target * target, uint16_t * eonce_statu
// First try the easy way // First try the easy way
retval = eonce_enter_debug_mode_without_reset(target,eonce_status); retval = eonce_enter_debug_mode_without_reset(target,eonce_status);
if(retval == ERROR_OK) if (retval == ERROR_OK)
return retval; return retval;
struct jtag_tap * tap_chp; struct jtag_tap * tap_chp;
struct jtag_tap * tap_cpu; struct jtag_tap * tap_cpu;
tap_chp = jtag_tap_by_string("dsp568013.chp"); tap_chp = jtag_tap_by_string("dsp568013.chp");
if(tap_chp == NULL){ if (tap_chp == NULL) {
retval = ERROR_FAIL; retval = ERROR_FAIL;
err_check(retval, DSP5680XX_ERROR_JTAG_TAP_FIND_MASTER, "Failed to get master tap."); err_check(retval, DSP5680XX_ERROR_JTAG_TAP_FIND_MASTER, "Failed to get master tap.");
} }
tap_cpu = jtag_tap_by_string("dsp568013.cpu"); tap_cpu = jtag_tap_by_string("dsp568013.cpu");
if(tap_cpu == NULL){ if (tap_cpu == NULL) {
retval = ERROR_FAIL; retval = ERROR_FAIL;
err_check(retval, DSP5680XX_ERROR_JTAG_TAP_FIND_CORE, "Failed to get master tap."); err_check(retval, DSP5680XX_ERROR_JTAG_TAP_FIND_CORE, "Failed to get master tap.");
} }
@ -671,15 +674,15 @@ else {
uint16_t data_read_from_dr; uint16_t data_read_from_dr;
retval = eonce_read_status_reg(target, &data_read_from_dr); retval = eonce_read_status_reg(target, &data_read_from_dr);
err_check_propagate(retval); err_check_propagate(retval);
if((data_read_from_dr&0x30) == 0x30){ if ((data_read_from_dr&0x30) == 0x30) {
LOG_DEBUG("EOnCE successfully entered debug mode."); LOG_DEBUG("EOnCE successfully entered debug mode.");
dsp5680xx_context.debug_mode_enabled = true; dsp5680xx_context.debug_mode_enabled = true;
retval = ERROR_OK; retval = ERROR_OK;
}else{ } else {
const char *msg = "Failed to set EOnCE module to debug mode"; const char *msg = "Failed to set EOnCE module to debug mode";
retval = ERROR_TARGET_FAILURE; retval = ERROR_TARGET_FAILURE;
err_check(retval, DSP5680XX_ERROR_ENTER_DEBUG_MODE, msg); err_check(retval, DSP5680XX_ERROR_ENTER_DEBUG_MODE, msg);
} }
if(eonce_status!=NULL) if(eonce_status!=NULL)
*eonce_status = data_read_from_dr; *eonce_status = data_read_from_dr;
return retval; return retval;
@ -1333,7 +1336,7 @@ if (protected == NULL) {
* @param address Command parameter. * @param address Command parameter.
* @param data Command parameter. * @param data Command parameter.
* @param hfm_ustat FM status register. * @param hfm_ustat FM status register.
* @param pmem Address is P: (program) memory (@pmem==1) or X: (dat) memory (@pmem==0) * @param pmem Address is P: (program) memory (@pmem == 1) or X: (dat) memory (@pmem == 0)
* *
* @return * @return
*/ */
@ -1368,7 +1371,8 @@ if ((watchdog--) == 1) {
dsp5680xx_context.flush = 0; dsp5680xx_context.flush = 0;
retval = core_move_value_at_r2_disp(target,0x00,HFM_CNFG); // write to HFM_CNFG (lock=0, select bank) -- flash_desc.bank&0x03,0x01 == 0x00,0x01 ??? /* write to HFM_CNFG (lock=0, select bank) -- flash_desc.bank&0x03,0x01 == 0x00,0x01 ??? */
retval = core_move_value_at_r2_disp(target, 0x00, HFM_CNFG);
err_check_propagate(retval); err_check_propagate(retval);
retval = core_move_value_at_r2_disp(target,0x04,HFM_USTAT); // write to HMF_USTAT, clear PVIOL, ACCERR & BLANK bits retval = core_move_value_at_r2_disp(target,0x04,HFM_USTAT); // write to HMF_USTAT, clear PVIOL, ACCERR & BLANK bits
err_check_propagate(retval); err_check_propagate(retval);