hosted: Run target specific monitor commands with -M "command" .

Lists available commands: "blackmagic -M help"
Quote multi argument monitor commands, e.g. STM32F1: blackmagic -M "option help"
This commit is contained in:
Uwe Bonnes 2020-12-30 11:56:24 +01:00 committed by UweBonnes
parent 165560edd8
commit 8e2f6937d5
5 changed files with 54 additions and 17 deletions

View File

@ -3,6 +3,8 @@
*
* Copyright (C) 2011 Black Sphere Technologies Ltd.
* Written by Gareth McMullin <gareth@blacksphere.co.nz>
* Copyright (C) 2021 Uwe Bonnes
* (bon@elektron.ikp.physik.tu-darmstadt.de)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -27,6 +29,7 @@
#include "command.h"
#include "gdb_packet.h"
#include "target.h"
#include "target_internal.h"
#include "morse.h"
#include "version.h"
#include "serialno.h"
@ -37,13 +40,6 @@
typedef bool (*cmd_handler)(target *t, int argc, const char **argv);
struct command_s {
const char *cmd;
cmd_handler handler;
const char *help;
};
static bool cmd_version(target *t, int argc, char **argv);
static bool cmd_help(target *t, int argc, char **argv);
@ -161,10 +157,11 @@ bool cmd_help(target *t, int argc, char **argv)
(void)argv;
const struct command_s *c;
if (!t || t->tc->destroy_callback) {
gdb_out("General commands:\n");
for(c = cmd_list; c->cmd; c++)
gdb_outf("\t%s -- %s\n", c->cmd, c->help);
}
if (!t)
return -1;

View File

@ -36,7 +36,19 @@ blackmagic -V <file>.bin
```
### Show more options
```
blackmagic -h"
blackmagic -h
```
### Show available monitor commands
```
blackmagic -M help
```
### Show available monitor commands on second target
```
blackmagic -n 2 -M help
```
### Monitor commands with multiple arguments, e.g.Stm32F1:
```
blackmagic -M "option help"
```
## Used shared libraries:
### libusb

View File

@ -32,6 +32,7 @@
#include "target.h"
#include "target_internal.h"
#include "cortexm.h"
#include "command.h"
#include "cl_utils.h"
#include "bmp_hosted.h"
@ -45,6 +46,18 @@
# include <sys/mman.h>
#endif
static void cl_target_printf(struct target_controller *tc,
const char *fmt, va_list ap)
{
(void)tc;
vprintf(fmt, ap);
}
static struct target_controller cl_controller = {
.printf = cl_target_printf,
};
struct mmap_data {
void *data;
size_t size;
@ -152,6 +165,8 @@ static void cl_help(char **argv)
DEBUG_WARN("\t-p\t\t: Supplies power to the target (where applicable)\n");
DEBUG_WARN("\t-R\t\t: Reset device\n");
DEBUG_WARN("\t-H\t\t: Do not use high level commands (BMP-Remote)\n");
DEBUG_WARN("\t-M <string>\t: Run target specific monitor commands. Quote multi\n");
DEBUG_WARN("\t\t\t word strings. Run \"-M help\" for help.\n");
DEBUG_WARN("Flash operation modifiers options:\n");
DEBUG_WARN("\tDefault action with given file is to write to flash\n");
DEBUG_WARN("\t-a <addr>\t: Start flash operation at flash address <addr>\n"
@ -168,7 +183,7 @@ void cl_init(BMP_CL_OPTIONS_t *opt, int argc, char **argv)
opt->opt_flash_size = 16 * 1024 *1024;
opt->opt_flash_start = 0xffffffff;
opt->opt_max_swj_frequency = 4000000;
while((c = getopt(argc, argv, "eEhHv:d:f:s:I:c:Cln:tVtTa:S:jpP:rR")) != -1) {
while((c = getopt(argc, argv, "eEhHv:d:f:s:I:c:Cln:M:tVtTa:S:jpP:rR")) != -1) {
switch(c) {
case 'c':
if (optarg)
@ -255,6 +270,11 @@ void cl_init(BMP_CL_OPTIONS_t *opt, int argc, char **argv)
if (optarg)
opt->opt_target_dev = strtol(optarg, NULL, 0);
break;
case 'M':
opt->opt_mode = BMP_MODE_MONITOR;
if (optarg)
opt->opt_monitor = optarg;
break;
case 'P':
if (optarg)
opt->opt_position = atoi(optarg);
@ -340,7 +360,8 @@ int cl_execute(BMP_CL_OPTIONS_t *opt)
opt->opt_target_dev, num_targets);
return res;
}
target *t = target_attach_n(opt->opt_target_dev, NULL);
target *t = target_attach_n(opt->opt_target_dev, &cl_controller);
if (!t) {
DEBUG_WARN("Can not attach to target %d\n", opt->opt_target_dev);
goto target_detach;
@ -403,6 +424,8 @@ int cl_execute(BMP_CL_OPTIONS_t *opt)
default:
DEBUG_WARN("No test for this core type yet\n");
}
} else if (opt->opt_mode == BMP_MODE_MONITOR) {
command_process(t, opt->opt_monitor);
}
if ((opt->opt_mode == BMP_MODE_TEST) ||
(opt->opt_mode == BMP_MODE_SWJ_TEST))
@ -525,8 +548,11 @@ int cl_execute(BMP_CL_OPTIONS_t *opt)
uint32_t end_time = platform_time_ms();
if (read_file != -1)
close(read_file);
if ((opt->opt_mode == BMP_MODE_FLASH_VERIFY) ||
(opt->opt_mode == BMP_MODE_FLASH_READ))
DEBUG_WARN("Read/Verify succeeded for %d bytes, %8.3f kiB/s\n",
bytes_read, (((bytes_read * 1.0)/(end_time - start_time))));
bytes_read,
(((bytes_read * 1.0)/(end_time - start_time))));
}
free_map:
if (map.size)

View File

@ -35,6 +35,7 @@ enum bmp_cl_mode {
BMP_MODE_FLASH_READ,
BMP_MODE_FLASH_VERIFY,
BMP_MODE_SWJ_TEST,
BMP_MODE_MONITOR,
};
typedef struct BMP_CL_OPTIONS_s {
@ -51,6 +52,7 @@ typedef struct BMP_CL_OPTIONS_s {
char *opt_ident_string;
int opt_position;
char *opt_cable;
char *opt_monitor;
int opt_debuglevel;
int opt_target_dev;
uint32_t opt_flash_start;

View File

@ -100,7 +100,7 @@ void target_list_free(void)
while(target_list) {
target *t = target_list->next;
if (target_list->tc)
if (target_list->tc && target_list->tc->destroy_callback)
target_list->tc->destroy_callback(target_list->tc, target_list);
if (target_list->priv)
target_list->priv_free(target_list->priv);