- fixed endianness helper macros (thanks to obilix and wiml for finding and fixing...
[fw/openocd] / src / target / etm.c
index a775bbd1f713abce1acd902f4144eee6588c431c..367eafffabe38ab00dc6bfb2faed8301670fd00b 100644 (file)
@@ -1231,6 +1231,14 @@ int handle_etm_config_command(struct command_context_s *cmd_ctx, char *cmd, char
                }
        }
        
+       if (!etm_capture_drivers[i])
+       {
+               /* no supported capture driver found, don't register an ETM */
+               free(etm_ctx);
+               ERROR("trace capture driver '%s' not found", args[4]);
+               return ERROR_OK;
+       }
+       
        etm_ctx->target = target;
        etm_ctx->trace_data = NULL;
        etm_ctx->trace_depth = 0;
@@ -1313,7 +1321,7 @@ int handle_etm_image_command(struct command_context_s *cmd_ctx, char *cmd, char
 
        if (argc < 1)
        {
-               command_print(cmd_ctx, "usage: etm image <file> ['bin'|'ihex'|'elf'] [base address]");
+               command_print(cmd_ctx, "usage: etm image <file> [base address] [type]");
                return ERROR_OK;
        }
        
@@ -1342,18 +1350,18 @@ int handle_etm_image_command(struct command_context_s *cmd_ctx, char *cmd, char
        etm_ctx->image->base_address_set = 0;
        etm_ctx->image->start_address_set = 0;
        
-       for (i = 1; i < argc; i++)
+       /* a base address isn't always necessary, default to 0x0 (i.e. don't relocate) */
+       if (argc >= 2)
        {
-               /* optional argument could be image type */
-               if (identify_image_type(&etm_ctx->image->type, args[i], args[0]) == ERROR_IMAGE_TYPE_UNKNOWN)
-               {
-                       /* if it wasn't a valid image type, treat it as the base address */
-                       etm_ctx->image->base_address_set = 1;
-                       etm_ctx->image->base_address = strtoul(args[i], NULL, 0);
-               }
+               etm_ctx->image->base_address_set = 1;
+               etm_ctx->image->base_address = strtoul(args[1], NULL, 0);
        }
-       
-       if (image_open(etm_ctx->image, args[0], FILEIO_READ) != ERROR_OK)
+       else
+       {
+               etm_ctx->image->base_address_set = 0;
+       }
+               
+       if (image_open(etm_ctx->image, args[0], (argc >= 3) ? args[2] : NULL) != ERROR_OK)
        {
                command_print(cmd_ctx, "image opening error: %s", etm_ctx->image->error_str);
                free(etm_ctx->image);
@@ -1494,9 +1502,13 @@ int handle_etm_load_command(struct command_context_s *cmd_ctx, char *cmd, char *
        
        for (i = 0; i < etm_ctx->trace_depth; i++)
        {
-               fileio_read_u32(&file, &etm_ctx->trace_data[i].pipestat);
-               fileio_read_u32(&file, &etm_ctx->trace_data[i].packet);
-               fileio_read_u32(&file, &etm_ctx->trace_data[i].flags);
+               u32 pipestat, packet, flags;
+               fileio_read_u32(&file, &pipestat);
+               fileio_read_u32(&file, &packet);
+               fileio_read_u32(&file, &flags);
+               etm_ctx->trace_data[i].pipestat = pipestat & 0xff;
+               etm_ctx->trace_data[i].packet = packet & 0xffff;
+               etm_ctx->trace_data[i].flags = flags;
        }
        
        fileio_close(&file);