This is an automated email from Gerrit. Hsiangkai Wang ([email protected]) just uploaded a new patch set to Gerrit, which you can find at http://openocd.zylin.com/1325
-- gerrit commit f90e9b90a151833c2ef5c4c81d620d345c748dd0 Author: Hsiangkai <[email protected]> Date: Wed Apr 10 14:11:07 2013 +0800 nds32: customize EDM operations for secure MCU Before debugging secure MCU, users need to enter passcode to gain appropriate privilege. The passcode is entered into EDM through edm operations on edm misc registers. Users could use "nds login_edm_operation <misc_reg_no> <value>" to specify the passcode. Change-Id: I1aabe314a5caf116ae53a0a7e799b184b4cffda1 Signed-off-by: Hsiangkai <[email protected]> diff --git a/src/target/nds32.c b/src/target/nds32.c index 81adcbb..6b8f838 100644 --- a/src/target/nds32.c +++ b/src/target/nds32.c @@ -31,6 +31,9 @@ const int NDS32_BREAK_16 = 0x00EA; /* 0xEA00 */ const int NDS32_BREAK_32 = 0x0A000064; /* 0x6400000A */ +struct nds32_edm_operation nds32_edm_ops[NDS32_EDM_OPERATION_MAX_NUM]; +uint32_t nds32_edm_ops_num; + const char *nds32_debug_type_name[11] = { "SOFTWARE BREAK", "SOFTWARE BREAK_16", @@ -2063,6 +2066,8 @@ int nds32_login(struct nds32 *nds32) uint32_t code; uint32_t i; + LOG_DEBUG("nds32_login"); + if (nds32->edm_passcode != NULL) { /* convert EDM passcode to command sequences */ passcode_length = strlen(nds32->edm_passcode); @@ -2091,6 +2096,23 @@ int nds32_login(struct nds32 *nds32) LOG_INFO("Current privilege level: %d", nds32->privilege_level); } + if (nds32_edm_ops_num > 0) { + const char *reg_name; + for (i = 0 ; i < nds32_edm_ops_num ; i++) { + code = nds32_edm_ops[i].value; + if (nds32_edm_ops[i].reg_no == 6) + reg_name = "gen_port0"; + else if (nds32_edm_ops[i].reg_no == 7) + reg_name = "gen_port1"; + else + return ERROR_FAIL; + + sprintf(command_str, "write_misc %s 0x%x;", reg_name, code); + if (ERROR_OK != aice->port->api->program_edm(command_str)) + return ERROR_FAIL; + } + } + return ERROR_OK; } diff --git a/src/target/nds32.h b/src/target/nds32.h index 524d41e..0b37cae 100644 --- a/src/target/nds32.h +++ b/src/target/nds32.h @@ -31,6 +31,8 @@ #include "nds32_insn.h" #include "nds32_edm.h" +#define NDS32_EDM_OPERATION_MAX_NUM 64 + #define CHECK_RETVAL(action) \ do { \ int __retval = (action); \ @@ -356,6 +358,11 @@ struct nds32_reg { bool enable; }; +struct nds32_edm_operation { + uint32_t reg_no; + uint32_t value; +}; + extern int nds32_config(struct nds32 *nds32); extern int nds32_init_arch_info(struct target *target, struct nds32 *nds32); extern int nds32_full_context(struct nds32 *nds32); diff --git a/src/target/nds32_cmd.c b/src/target/nds32_cmd.c index 8905847..bf51771 100644 --- a/src/target/nds32_cmd.c +++ b/src/target/nds32_cmd.c @@ -26,6 +26,9 @@ #include "nds32.h" #include "nds32_disassembler.h" +extern struct nds32_edm_operation nds32_edm_ops[NDS32_EDM_OPERATION_MAX_NUM]; +extern uint32_t nds32_edm_ops_num; + static const char *const NDS_MEMORY_ACCESS_NAME[] = { "BUS", "CPU", @@ -315,7 +318,7 @@ COMMAND_HANDLER(handle_nds32_boot_time_command) return ERROR_OK; } -COMMAND_HANDLER(handle_nds32_edm_passcode_command) +COMMAND_HANDLER(handle_nds32_login_edm_passcode_command) { struct target *target = get_current_target(CMD_CTX); struct nds32 *nds32 = target_to_nds32(target); @@ -332,6 +335,37 @@ COMMAND_HANDLER(handle_nds32_edm_passcode_command) return ERROR_OK; } +COMMAND_HANDLER(handle_nds32_login_edm_operation_command) +{ + struct target *target = get_current_target(CMD_CTX); + struct nds32 *nds32 = target_to_nds32(target); + + if (!is_nds32(nds32)) { + command_print(CMD_CTX, "current target isn't an Andes core"); + return ERROR_FAIL; + } + + if (CMD_ARGC > 1) { + + uint32_t misc_reg_no; + uint32_t data; + + COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], misc_reg_no); + COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], data); + + if (nds32_edm_ops_num >= NDS32_EDM_OPERATION_MAX_NUM) + return ERROR_FAIL; + + /* Just save the operation. Execute it in nds32_login() */ + nds32_edm_ops[nds32_edm_ops_num].reg_no = misc_reg_no; + nds32_edm_ops[nds32_edm_ops_num].value = data; + nds32_edm_ops_num++; + } else + return ERROR_FAIL; + + return ERROR_OK; +} + COMMAND_HANDLER(handle_nds32_max_stop_command) { struct target *target = get_current_target(CMD_CTX); @@ -839,13 +873,20 @@ static const struct command_registration nds32_exec_command_handlers[] = { .help = "set the period to wait after srst.", }, { - .name = "edm_passcode", - .handler = handle_nds32_edm_passcode_command, + .name = "login_edm_passcode", + .handler = handle_nds32_login_edm_passcode_command, .mode = COMMAND_ANY, .usage = "passcode", .help = "set EDM passcode for secure MCU debugging.", }, { + .name = "login_edm_operation", + .handler = handle_nds32_login_edm_operation_command, + .mode = COMMAND_ANY, + .usage = "login_edm_operation misc_reg_no value", + .help = "add EDM operations for secure MCU debugging.", + }, + { .name = "max_stop", .handler = handle_nds32_max_stop_command, .mode = COMMAND_EXEC, -- ------------------------------------------------------------------------------ Precog is a next-generation analytics platform capable of advanced analytics on semi-structured data. The platform includes APIs for building apps and a phenomenal toolset for data science. Developers can use our toolset for easy data analysis & visualization. Get a free account! http://www2.precog.com/precogplatform/slashdotnewsletter _______________________________________________ OpenOCD-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openocd-devel
