Kinetis: suppress false alarms "MCU is secured"

Kinetis driver checks MDM STAT register to detect secured state of MCU.
An unsecured clean device typically triggered a huge fat alarm message.
Now when driver detects secured state it tries to halt MCU and then
re-reads status register.

Command "mdm mass_erase" used to deassert reset when finished
and MCU started looping in hard fault - WDOG reset cycle.
Now "reset halt" is issued. Clean flash is not run after mass_erase.

Change-Id: I23f393509fbd8751d44ffc744ff2d67f1074f74e
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/3010
Tested-by: jenkins
Reviewed-by: Thomas Schmid <thomas@rfranging.com>
Reviewed-by: Freddie Chopin <freddie.chopin@gmail.com>
This commit is contained in:
Tomas Vanek 2015-10-07 16:09:21 +02:00 committed by Freddie Chopin
parent 2594c23d78
commit d028d84026
1 changed files with 34 additions and 3 deletions

View File

@ -34,6 +34,7 @@
#include "jtag/interface.h" #include "jtag/interface.h"
#include "imp.h" #include "imp.h"
#include <helper/binarybuffer.h> #include <helper/binarybuffer.h>
#include <target/target_type.h>
#include <target/algorithm.h> #include <target/algorithm.h>
#include <target/armv7m.h> #include <target/armv7m.h>
#include <target/cortex_m.h> #include <target/cortex_m.h>
@ -383,10 +384,15 @@ COMMAND_HANDLER(kinetis_mdm_mass_erase)
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
if (jtag_get_reset_config() & RESET_HAS_SRST)
adapter_deassert_reset();
dap_ap_select(dap, original_ap); 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;
target->type->assert_reset(target);
target->type->deassert_reset(target);
}
return ERROR_OK; return ERROR_OK;
} }
@ -464,6 +470,31 @@ COMMAND_HANDLER(kinetis_check_flash_security_status)
goto fail; goto fail;
} }
if ((val & (MDM_STAT_SYSSEC | MDM_STAT_CORE_HALTED)) == MDM_STAT_SYSSEC) {
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);
if (retval != ERROR_OK) {
LOG_WARNING("MDM: Target not halted, trying reset halt");
target->reset_halt = true;
target->type->assert_reset(target);
target->type->deassert_reset(target);
}
/* 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");
goto fail;
}
}
if (val & MDM_STAT_SYSSEC) { if (val & MDM_STAT_SYSSEC) {
jtag_poll_set_enabled(false); jtag_poll_set_enabled(false);