diff --git a/src/flash/nor/kinetis.c b/src/flash/nor/kinetis.c index 179527905..c248b0523 100644 --- a/src/flash/nor/kinetis.c +++ b/src/flash/nor/kinetis.c @@ -245,6 +245,8 @@ static int kinetis_mdm_write_register(struct adiv5_dap *dap, unsigned reg, uint3 int retval; LOG_DEBUG("MDM_REG[0x%02x] <- %08" PRIX32, reg, value); + dap_ap_select(dap, 1); + retval = dap_queue_ap_write(dap, reg, value); if (retval != ERROR_OK) { LOG_DEBUG("MDM: failed to queue a write request"); @@ -264,6 +266,9 @@ static int kinetis_mdm_write_register(struct adiv5_dap *dap, unsigned reg, uint3 static int kinetis_mdm_read_register(struct adiv5_dap *dap, unsigned reg, uint32_t *result) { int retval; + + dap_ap_select(dap, 1); + retval = dap_queue_ap_read(dap, reg, result); if (retval != ERROR_OK) { LOG_DEBUG("MDM: failed to queue a read request"); @@ -316,7 +321,6 @@ COMMAND_HANDLER(kinetis_mdm_mass_erase) } int retval; - const uint8_t original_ap = dap_ap_get_select(dap); /* * ... Power on the processor, or if power has already been @@ -333,8 +337,6 @@ COMMAND_HANDLER(kinetis_mdm_mass_erase) LOG_WARNING("Attempting mass erase without hardware reset. This is not reliable; " "it's recommended you connect SRST and use ``reset_config srst_only''."); - dap_ap_select(dap, 1); - retval = kinetis_mdm_write_register(dap, MDM_REG_CTRL, MEM_CTRL_SYS_RES_REQ); if (retval != ERROR_OK) return retval; @@ -384,8 +386,6 @@ COMMAND_HANDLER(kinetis_mdm_mass_erase) if (retval != ERROR_OK) return retval; - dap_ap_select(dap, original_ap); - if (jtag_get_reset_config() & RESET_HAS_SRST) { /* halt MCU otherwise it loops in hard fault - WDOG reset cycle */ target->reset_halt = true; @@ -420,10 +420,6 @@ COMMAND_HANDLER(kinetis_check_flash_security_status) uint32_t val; int retval; - const uint8_t origninal_ap = dap_ap_get_select(dap); - - dap_ap_select(dap, 1); - /* * ... The MDM-AP ID register can be read to verify that the @@ -474,7 +470,6 @@ COMMAND_HANDLER(kinetis_check_flash_security_status) LOG_WARNING("MDM: Secured MCU state detected however it may be a false alarm"); LOG_WARNING("MDM: Halting target to detect secured state reliably"); - dap_ap_select(dap, origninal_ap); retval = target_halt(target); if (retval == ERROR_OK) retval = target_wait_state(target, TARGET_HALTED, 100); @@ -487,7 +482,6 @@ COMMAND_HANDLER(kinetis_check_flash_security_status) } /* re-read status */ - dap_ap_select(dap, 1); retval = kinetis_mdm_read_register(dap, MDM_REG_STAT, &val); if (retval != ERROR_OK) { LOG_ERROR("MDM: failed to read MDM_REG_STAT"); @@ -512,8 +506,6 @@ COMMAND_HANDLER(kinetis_check_flash_security_status) jtag_poll_set_enabled(true); } - dap_ap_select(dap, origninal_ap); - return ERROR_OK; fail: diff --git a/src/flash/nor/sim3x.c b/src/flash/nor/sim3x.c index 0a5906c12..e30ca4543 100644 --- a/src/flash/nor/sim3x.c +++ b/src/flash/nor/sim3x.c @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2014 by Ladislav Bábel * + * Copyright (C) 2014 by Ladislav Bábel * * ladababel@seznam.cz * * * * Copyright (C) 2015 by Andreas Bomholtz * @@ -893,6 +893,8 @@ static int ap_write_register(struct adiv5_dap *dap, unsigned reg, uint32_t value int retval; LOG_DEBUG("DAP_REG[0x%02x] <- %08" PRIX32, reg, value); + dap_ap_select(dap, SIM3X_AP); + retval = dap_queue_ap_write(dap, reg, value); if (retval != ERROR_OK) { LOG_DEBUG("DAP: failed to queue a write request"); @@ -911,6 +913,9 @@ static int ap_write_register(struct adiv5_dap *dap, unsigned reg, uint32_t value static int ap_read_register(struct adiv5_dap *dap, unsigned reg, uint32_t *result) { int retval; + + dap_ap_select(dap, SIM3X_AP); + retval = dap_queue_ap_read(dap, reg, result); if (retval != ERROR_OK) { LOG_DEBUG("DAP: failed to queue a read request"); @@ -959,9 +964,6 @@ COMMAND_HANDLER(sim3x_mass_erase) return ERROR_FAIL; } - const uint8_t origninal_ap = dap_ap_get_select(dap); - dap_ap_select(dap, SIM3X_AP); - ret = ap_read_register(dap, SIM3X_AP_ID, &val); if (ret != ERROR_OK) return ret; @@ -988,8 +990,6 @@ COMMAND_HANDLER(sim3x_mass_erase) if (ret != ERROR_OK) return ret; - dap_ap_select(dap, origninal_ap); - LOG_INFO("Mass erase success"); return ERROR_OK; } @@ -1017,9 +1017,6 @@ COMMAND_HANDLER(sim3x_lock) return ERROR_FAIL; } } else { - const uint8_t origninal_ap = dap_ap_get_select(dap); - dap_ap_select(dap, SIM3X_AP); - /* check SIM3X_AP_ID */ ret = ap_read_register(dap, SIM3X_AP_ID, &val); if (ret != ERROR_OK) @@ -1039,8 +1036,6 @@ COMMAND_HANDLER(sim3x_lock) if (ret != ERROR_OK) return ret; - dap_ap_select(dap, origninal_ap); - if (val & SIM3X_AP_INIT_STAT_LOCK) { LOG_INFO("Target is already locked"); return ERROR_OK; @@ -1049,8 +1044,6 @@ COMMAND_HANDLER(sim3x_lock) return ERROR_FAIL; } } - - dap_ap_select(dap, origninal_ap); } ret = target_read_u32(target, LOCK_WORD_ADDRESS, &val); diff --git a/src/target/arm_adi_v5.c b/src/target/arm_adi_v5.c index 2ddb6b5f8..a28bc1544 100644 --- a/src/target/arm_adi_v5.c +++ b/src/target/arm_adi_v5.c @@ -842,10 +842,8 @@ int dap_get_debugbase(struct adiv5_ap *ap, uint32_t *dbgbase, uint32_t *apid) { struct adiv5_dap *dap = ap->dap; - uint32_t ap_old; int retval; - ap_old = dap_ap_get_select(dap); dap_ap_select(dap, ap->ap_num); retval = dap_queue_ap_read(dap, MEM_AP_REG_BASE, dbgbase); @@ -858,21 +856,16 @@ int dap_get_debugbase(struct adiv5_ap *ap, if (retval != ERROR_OK) return retval; - dap_ap_select(dap, ap_old); - return ERROR_OK; } int dap_lookup_cs_component(struct adiv5_ap *ap, uint32_t dbgbase, uint8_t type, uint32_t *addr, int32_t *idx) { - struct adiv5_dap *dap = ap->dap; - uint32_t ap_old; uint32_t romentry, entry_offset = 0, component_base, devtype; int retval; *addr = 0; - ap_old = dap_ap_get_select(dap); do { retval = mem_ap_read_atomic_u32(ap, (dbgbase&0xFFFFF000) | @@ -916,8 +909,6 @@ int dap_lookup_cs_component(struct adiv5_ap *ap, entry_offset += 4; } while (romentry > 0); - dap_ap_select(dap, ap_old); - if (!*addr) return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;