stlink: add none 32bit memory read/write functions
[fw/openocd] / src / target / etm.c
index 5c42fb59a8f75b98b1646c8cb33905a6a49a62b9..27983698f866f555eac13b4b6f1535737e2b13c2 100644 (file)
@@ -314,7 +314,6 @@ struct reg_cache *etm_build_reg_cache(struct target *target,
 
        /* figure ETM version then add base registers */
        if (config & (1 << 31)) {
-               bcd_vers = 0x20;
                LOG_WARNING("ETMv2+ support is incomplete");
 
                /* REVISIT more registers may exist; they may now be
@@ -500,12 +499,14 @@ static int etm_read_reg_w_check(struct reg *reg,
 
        if (etm_reg->reg_info->mode == WO) {
                LOG_ERROR("BUG: can't read write-only register %s", r->name);
-               return ERROR_INVALID_ARGUMENTS;
+               return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
        LOG_DEBUG("%s (%u)", r->name, reg_addr);
 
-       arm_jtag_scann(etm_reg->jtag_info, 0x6, TAP_IDLE);
+       retval = arm_jtag_scann(etm_reg->jtag_info, 0x6, TAP_IDLE);
+       if (retval != ERROR_OK)
+               return retval;
        retval = arm_jtag_set_instr(etm_reg->jtag_info, etm_reg->jtag_info->intest_instr, NULL, TAP_IDLE);
        if (retval != ERROR_OK)
                return retval;
@@ -584,12 +585,14 @@ static int etm_write_reg(struct reg *reg, uint32_t value)
 
        if (etm_reg->reg_info->mode == RO) {
                LOG_ERROR("BUG: can't write read--only register %s", r->name);
-               return ERROR_INVALID_ARGUMENTS;
+               return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
        LOG_DEBUG("%s (%u): 0x%8.8" PRIx32 "", r->name, reg_addr, value);
 
-       arm_jtag_scann(etm_reg->jtag_info, 0x6, TAP_IDLE);
+       retval = arm_jtag_scann(etm_reg->jtag_info, 0x6, TAP_IDLE);
+       if (retval != ERROR_OK)
+               return retval;
        retval = arm_jtag_set_instr(etm_reg->jtag_info, etm_reg->jtag_info->intest_instr, NULL, TAP_IDLE);
        if (retval != ERROR_OK)
                return retval;
@@ -665,7 +668,7 @@ static int etm_read_instruction(struct etm_context *ctx, struct arm_instruction
                        ctx->current_pc - ctx->image->sections[section].base_address,
                        4, buf, &size_read)) != ERROR_OK)
                {
-                       LOG_ERROR("error while reading instruction: %i", retval);
+                       LOG_ERROR("error while reading instruction");
                        return ERROR_TRACE_INSTRUCTION_UNAVAILABLE;
                }
                opcode = target_buffer_get_u32(ctx->target, buf);
@@ -678,7 +681,7 @@ static int etm_read_instruction(struct etm_context *ctx, struct arm_instruction
                        ctx->current_pc - ctx->image->sections[section].base_address,
                        2, buf, &size_read)) != ERROR_OK)
                {
-                       LOG_ERROR("error while reading instruction: %i", retval);
+                       LOG_ERROR("error while reading instruction");
                        return ERROR_TRACE_INSTRUCTION_UNAVAILABLE;
                }
                opcode = target_buffer_get_u16(ctx->target, buf);
@@ -1193,7 +1196,7 @@ static COMMAND_HELPER(handle_etm_tracemode_command_update,
        else
        {
                command_print(CMD_CTX, "invalid option '%s'", CMD_ARGV[0]);
-               return ERROR_INVALID_ARGUMENTS;
+               return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
        uint8_t context_id;
@@ -1214,7 +1217,7 @@ static COMMAND_HELPER(handle_etm_tracemode_command_update,
                break;
        default:
                command_print(CMD_CTX, "invalid option '%s'", CMD_ARGV[1]);
-               return ERROR_INVALID_ARGUMENTS;
+               return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
        bool etmv1_cycle_accurate;
@@ -1265,13 +1268,7 @@ COMMAND_HANDLER(handle_etm_tracemode_command)
                                &tracemode);
                break;
        default:
-               command_print(CMD_CTX, "usage: tracemode "
-                               "('none'|'data'|'address'|'all') "
-                               "context_id_bits "
-                               "('enable'|'disable') "
-                               "('enable'|'disable')"
-                               );
-               return ERROR_FAIL;
+               return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
        /**
@@ -1735,8 +1732,7 @@ COMMAND_HANDLER(handle_etm_image_command)
 
        if (CMD_ARGC < 1)
        {
-               command_print(CMD_CTX, "usage: etm image <file> [base address] [type]");
-               return ERROR_FAIL;
+               return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
        target = get_current_target(CMD_CTX);
@@ -1796,8 +1792,7 @@ COMMAND_HANDLER(handle_etm_dump_command)
 
        if (CMD_ARGC != 1)
        {
-               command_print(CMD_CTX, "usage: etm dump <file>");
-               return ERROR_FAIL;
+               return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
        target = get_current_target(CMD_CTX);
@@ -1863,8 +1858,7 @@ COMMAND_HANDLER(handle_etm_load_command)
 
        if (CMD_ARGC != 1)
        {
-               command_print(CMD_CTX, "usage: etm load <file>");
-               return ERROR_FAIL;
+               return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
        target = get_current_target(CMD_CTX);
@@ -1893,7 +1887,15 @@ COMMAND_HANDLER(handle_etm_load_command)
                return ERROR_FAIL;
        }
 
-       if (file.size % 4)
+       int filesize;
+       int retval = fileio_size(&file, &filesize);
+       if (retval != ERROR_OK)
+       {
+               fileio_close(&file);
+               return retval;
+       }
+
+       if (filesize % 4)
        {
                command_print(CMD_CTX, "size isn't a multiple of 4, no valid trace data");
                fileio_close(&file);
@@ -2097,6 +2099,7 @@ COMMAND_HANDLER(handle_etm_analyze_command)
 
        if ((retval = etmv1_analyze_trace(etm_ctx, CMD_CTX)) != ERROR_OK)
        {
+               /* FIX! error should be reported inside etmv1_analyze_trace() */
                switch (retval)
                {
                        case ERROR_ETM_ANALYSIS_FAILED:
@@ -2109,7 +2112,7 @@ COMMAND_HANDLER(handle_etm_analyze_command)
                                command_print(CMD_CTX, "no image available for trace analysis");
                                break;
                        default:
-                               command_print(CMD_CTX, "unknown error: %i", retval);
+                               command_print(CMD_CTX, "unknown error");
                }
        }
 
@@ -2194,7 +2197,7 @@ static const struct command_registration etm_exec_command_handlers[] = {
                .handler = handle_etm_image_command,
                .mode = COMMAND_EXEC,
                .help = "load image from file with optional offset",
-               .usage = "filename [offset]",
+               .usage = "<file> [base address] [type]",
        },
        {
                .name = "dump",