Implement long options initial commit

This commit is contained in:
SId Price 2022-06-26 10:19:04 -06:00 committed by Rachel Mant
parent 6f38b844af
commit 7dd82418e0
1 changed files with 79 additions and 52 deletions

View File

@ -28,6 +28,7 @@
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <getopt.h>
#include "version.h" #include "version.h"
#include "target_internal.h" #include "target_internal.h"
#include "cortexm.h" #include "cortexm.h"
@ -133,68 +134,94 @@ static void cl_help(char **argv)
PRINT_INFO( PRINT_INFO(
"\n" "\n"
"Usage: %s [-h | -l | [-vBITMASK] [-d PATH | -P NUMBER | -s SERIAL | -c TYPE]\n" "Usage: %s [-h | -l | [-vBITMASK] [-d PATH | -P NUMBER | -s SERIAL | -c TYPE]\n"
" [-n NUMBER] [-j] [-C] [-t | -T] [-e] [-p] [-R[h]] [-H] [-M STRING ...]\n" "\t[-n NUMBER] [-j] [-C] [-t | -T] [-e] [-p] [-R[h]] [-H] [-M STRING ...]\n"
" [-E | -w | -V | -r] [-a ADDR] [-S number] [file]]\n" "\t[-f | -m] [-E | -w | -V | -r] [-a ADDR] [-S number] [file]]\n"
"\n" "\n"
"Single-shot and verbosity options [-h | -l | -vBITMASK]:\n" "\t-h, --help Show the version and this help, then exit\n"
"\t-h Show the version version and this help, then exit\n" "\t-l, --list List available supported probes\n"
"\t-l List available supported probes\n" "\t-v, --verbose <bitmask> Set the output verbosity level based on some combination of:\n"
"\t-v<bitmask> Set the output verbosity level based on some combination of:\n" "\t 1 = INFO, 2 = GDB, 4 = TARGET, 8 = PROBE, 16 = WIRE\n"
"\t 1 = INFO, 2 = GDB, 4 = TARGET, 8 = PROBE, 16 = WIRE\n"
"\n" "\n"
"Probe selection arguments [-d PATH | -P NUMBER | -s SERIAL | -c TYPE]:\n" "Probe selection arguments (If used, choose one):\n"
"\t-d <path> Use a serial device at the given path (Deprecated!)\n" "\t-d, --device <path> Use a serial device at the given path (Deprecated!)\n"
"\t-P <number> Use the <number>th debug probe found while scanning the\n" "\t-P, --probe <number> Use the <number>th debug probe found while scanning the\n"
"\t system, see the output from list for the order\n" "\t system, see the output from list for the order\n"
"\t-s <serial> Select the debug probe with the given serial number\n" "\t-s, --serial <serial> Select the debug probe with the given serial number\n"
"\t-c <type> Select the FTDI-based debug probe with of the given\n" "\t-c, --ftdi-type <type> Select the FTDI-based debug probe with of the given\n"
"\t type (cable)\n" "\t type (cable)\n"
"\n" "\n"
"The default is to start a debug server at localhost:2000\n" "General configuration options:\n"
"General configuration options: [-n NUMBER] [-j] [-C] [-t | -T] [-e] [-p] [-R[h]]\n" "\t-n, --number <scan-number> Select the target device at the given position in the\n"
" [-H] [-M STRING ...]\n" "\t scan chain (use the -t option to get a scan chain listing)\n"
"\t-n <number> Select the target device at the given position in the\n" "\t-j, --jtag Use JTAG instead of SWD\n"
"\t scan chain (use the -t option to get a scan chain listing)\n" "\t-C, --hw-reset Connect to target under hardware reset\n"
"\t-j Use JTAG instead of SWD\n" "\t-t, --list-chain Perform a chain scan and display information about the\n"
"\t-C Connect to target under hardware reset\n" "\t conected devices\n"
"\t-t Perform a chain scan and display information about the\n" "\t-T, --timing Perform continues read- or write-back of a value to allow\n"
"\t conected devices\n" "\t measurement of protocol timing. Aborted by ^C\n"
"\t-T Perform continues read- or write-back of a value to allow\n" "\t-e, --ext-res Assume external resistors for FTDI devices, that is having the\n"
"\t measurement of protocol timing. Aborted by ^C\n" "\t FTDI chip connected through resistors to TMS, TDI and TDO\n"
"\t-e Assume external resistors for FTDI devices, that is having the\n" "\t-p, --power Power the target from the probe (if possible)\n"
"\t FTDI chip connected through resistors to TMS, TDI and TDO\n" "\t-R, --reset [h] Reset the device. If followed by 'h', this will be done using\n"
"\t-p Power the target from the probe (if possible)\n" "\t the hardware reset line instead of over the debug link\n"
"\t-R[h] Reset the device. If followed by 'h', this will be done using\n" "\t-H, --high-level Do not use the high level command API (bmp-remote)\n"
"\t the hardware reset line instead of over the debug link\n" "\t-M, --monitor <string> Run target-specific monitor commands. This option\n"
"\t-H Do not use the high level command API (bmp-remote)\n" "\t can be repeated for as many commands you wish to run.\n"
"\t-M <string> Run target-specific monitor commands. This option\n" "\t If the command contains spaces, use quotes around the\n"
"\t can be repeated for as many commands you wish to run.\n" "\t complete command\n"
"\t If the command contains spaces, use quotes around the\n"
"\t complete command\n"
"\n" "\n"
"SWD-specific configuration options [-f FREQUENCY | -m TARGET]:\n" "SWD-specific configuration options:\n"
"\t-f <frequency> Set an operating frequency for SWD\n" "\t-f, --freq <frequency> Set an operating frequency for SWD\n"
"\t-m <target> Use the given target ID for selection in SWD multi-drop\n" "\t-m, --mult-drop <target> Use the given target ID for selection in SWD multi-drop\n"
"\n" "\n"
"Flash operation selection options [-E | -w | -V | -r]:\n" "Flash operation options:\n"
"\t-E Erase the target device Flash\n" "\t-E, --erase Erase the target device Flash\n"
"\t-w Write the specified binary file to the target device\n" "\t-w, --write Write the specified binary file to the target device\n"
"\t Flash (the default)\n" "\t Flash (the default)\n"
"\t-V Verify the target device Flash against the specified\n" "\t-V, --verify Verify the target device Flash against the specified\n"
"\t binary file\n" "\t binary file\n"
"\t-r Read the target device Flash\n" "\t-r, --read Read the target device Flash\n"
"\n" "\n"
"Flash operation modifiers options: [-a ADDR] [-S number] [FILE]\n" "Flash operation modifier options:\n"
"\t-a <addr> Start address for the given Flash operation (defaults to\n" "\t-a, --addr <addr> Start address for the given Flash operation (defaults to\n"
"\t the start of Flash)\n" "\t the start of Flash)\n"
"\t-S <number> Number of bytes to work on in the Flash operation (default\n" "\t-S, --byte-count <number> Number of bytes to work on in the Flash operation (default\n"
"\t is till the operation fails or is complete)\n" "\t is till the operation fails or is complete)\n"
"\t<file> Binary file to use in Flash operations\n", "\t<file> Binary file to use in Flash operations\n",
argv[0] argv[0]
); );
exit(0); exit(0);
} }
static struct option long_options[] = {
{"help", no_argument, NULL, 'h'},
{"list", no_argument, NULL, 'l'},
{"verbose", required_argument, NULL, 'v'},
{"device", required_argument, NULL, 'd'},
{"probe", required_argument, NULL, 'P'},
{"serial", required_argument, NULL, 's'},
{"ftdi-type", required_argument, NULL, 'c'},
{"number", required_argument, NULL, 'n'},
{"jtag", no_argument, NULL, 'j'},
{"hw-reset", no_argument, NULL, 'C'},
{"list-chain", no_argument, NULL, 't'},
{"timing", no_argument, NULL, 'T'},
{"ext-res", no_argument, NULL, 'e'},
{"power", no_argument, NULL, 'p'},
{"reset", optional_argument, NULL, 'R'},
{"high-level", no_argument, NULL, 'H'},
{"monitor", required_argument, NULL, 'M'},
{"freq", required_argument, NULL, 'f'},
{"multi-drop", required_argument, NULL, 'm'},
{"erase", no_argument, NULL, 'E'},
{"write", no_argument, NULL, 'W'},
{"verify", no_argument, NULL, 'V'},
{"read", no_argument, NULL, 'r'},
{"addr", required_argument, NULL, 'a'},
{"byte-count", required_argument, NULL, 'S'},
{NULL, 0, NULL, 0}
} ;
void cl_init(BMP_CL_OPTIONS_t *opt, int argc, char **argv) void cl_init(BMP_CL_OPTIONS_t *opt, int argc, char **argv)
{ {
int c; int c;
@ -202,7 +229,7 @@ void cl_init(BMP_CL_OPTIONS_t *opt, int argc, char **argv)
opt->opt_flash_size = 0xffffffff; opt->opt_flash_size = 0xffffffff;
opt->opt_flash_start = 0xffffffff; opt->opt_flash_start = 0xffffffff;
opt->opt_max_swj_frequency = 4000000; opt->opt_max_swj_frequency = 4000000;
while((c = getopt(argc, argv, "eEhHv:d:f:s:I:c:Cln:m:M:wVtTa:S:jpP:rR::")) != -1) { while((c = getopt_long(argc, argv, "eEhHv:d:f:s:I:c:Cln:m:M:wVtTa:S:jpP:rR::", long_options, NULL)) != -1) {
switch(c) { switch(c) {
case 'c': case 'c':
if (optarg) if (optarg)