diff --git a/.vscode/launch.json b/.vscode/launch.json index a3d192b..2b75f26 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,11 +5,11 @@ "version": "0.2.0", "configurations": [ { - "name": "(gdb) Launch", + "name": "bs list", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/build/app/bs", - "args": ["-l", "scan"], + "args": ["-l"], "stopAtEntry": false, "cwd": "${fileDirname}", "environment": [], @@ -26,8 +26,58 @@ "text": "-gdb-set disassembly-flavor intel", "ignoreFailures": true } - ] - } - + ], + "preLaunchTask": "build", + }, + { + "name": "bs scan", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/build/app/bs", + "args": ["-n", "2", "scan"], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Set Disassembly Flavor to Intel", + "text": "-gdb-set disassembly-flavor intel", + "ignoreFailures": true + } + ], + "preLaunchTask": "build", + }, + { + "name": "bs devid", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/build/app/bs", + "args": ["-n", "2", "-b", "/data/frd/xcku15p_ffve1517.bsd", "-d", "0x14a56093"], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Set Disassembly Flavor to Intel", + "text": "-gdb-set disassembly-flavor intel", + "ignoreFailures": true + } + ], + "preLaunchTask": "build", + }, ] } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..0e947d2 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,15 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "type": "shell", + "command": "cd build && cmake -DCMAKE_BUILD_TYPE=Debug .. && make", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": ["$gcc"] + } + ] +} \ No newline at end of file diff --git a/app/src/args.c b/app/src/args.c index dd99b11..ac356ff 100644 --- a/app/src/args.c +++ b/app/src/args.c @@ -11,32 +11,45 @@ char * COMMAND_STRINGS[COMMANDS_NUMBER-1] = { }; void usage() { - printf("Usage: bs [[-l] [--list]] [[-n] [--nprobe] PROBE_NUM] [scan]\n"); + printf("Usage: bs [[-l] [--list]] [[-n] [--nprobe]] [[-b] [--bsdl]] [[-d] [--device_id]] PROBE_NUM] [scan]\n"); } int parse_args(struct args *a, int argc, char *argv[]) { int opt = 0; int i = 0; + unsigned int devid = 0; int command = 0; - __uint8_t option_arg[32] = {0}; + __uint8_t option_arg[MAX_PATH] = {0}; // Définir les options longues static struct option long_options[] = { {"list", no_argument, 0, 'l'}, {"nprobe", required_argument, 0, 'n'}, + {"bsdl", required_argument, 0, 'b'}, + {"device_id", required_argument, 0, 'd'}, {0, 0, 0, 0} }; // Utilisation de getopt_long pour parser les options - while ((opt = getopt_long(argc, argv, "ln:", long_options, NULL)) != -1) { + while ((opt = getopt_long(argc, argv, "ln:b:d:", long_options, NULL)) != -1) { switch (opt) { case 'l': a->list = 1; break; case 'n': - snprintf(option_arg, sizeof(option_arg)-2, "%s"); + snprintf(option_arg, sizeof(option_arg)-2, "%s", optarg); a->probe = atoi(option_arg); break; + case 'b': + snprintf(a->bsdl, MAX_PATH-2, "%s", optarg); + break; + case 'd': + i = sscanf(optarg, "0x%x", &devid); + if (i == 0) { + printf("Device ID must be an hex value like '0xABCD'"); + return EXIT_FAILURE; + } + break; default: usage(); return EXIT_FAILURE; diff --git a/app/src/args.h b/app/src/args.h index 680c754..5c83340 100644 --- a/app/src/args.h +++ b/app/src/args.h @@ -2,6 +2,7 @@ #define _ARGS_H #define MAX_COMMANDS 16 +#define MAX_PATH 1024 enum commands { NO_COMMAND=0, @@ -12,6 +13,8 @@ enum commands { struct args { int list; int probe; + char bsdl[MAX_PATH]; + int devid; enum commands cmds[MAX_COMMANDS]; }; diff --git a/app/src/main.c b/app/src/main.c index 5458729..c1a7917 100644 --- a/app/src/main.c +++ b/app/src/main.c @@ -5,10 +5,12 @@ #include "jtag_core.h" #include "args.h" +#include "utils.h" #define PROBES_MAX_NUM 16 #define PROBE_NAME_SIZE 64 +#define DEVICES_SCAN_MAX 32 struct probe { @@ -65,24 +67,63 @@ int list_probes(jtag_core *jc, struct probe probes[], int show) { probes[n].probe_id = PROBE_ID(i,j); strncpy(probes[n].name, probe_name, PROBE_NAME_SIZE); } - n++; if (0 != show) { printf(" JTAG probe %d: ", n+1); printf("%s.\n", probe_name); } + n++; } } return n; } +int scan(jtag_core *jc, int probe_id, int *ndevs, unsigned long ids[], int show) { + int err = JTAG_CORE_NO_ERROR; + int n = 0; + int i = 0; + + if (0 != show) printf("Devices scan in progress...\n"); + + err = jtagcore_select_and_open_probe(jc, probe_id); + if (err < 0) { + if (0 != show) printf("Impossible to open the selected probe.\n"); + return err; + } + + err = jtagcore_scan_and_init_chain(jc); + if (err < 0) { + if (0 != show) printf("Impossible to scan the JTAG chain"); + return err; + } + + n = jtagcore_get_number_of_devices(jc); + if (n < 0) { + if (0 != show) printf("Error while getting the number of devices on the chain.\n"); + return err; + } + *ndevs = n; + for (i=0;i < MIN(n, DEVICES_SCAN_MAX);i++) { + ids[i] = jtagcore_get_dev_id(jc, i); + if (0 != show) printf(" device %d : 0x%08x\n", i, ids[i]); + } + + if (0 != show) printf("Done.\n"); + return err; +} + + int main(int argc, char *argv[]) { - int success; - int n_probes; + int success = 0; + int n_probes = 0; + int i = 0; + int error = 0; jtag_core *jc = NULL; struct args a = {0}; struct probe probes[PROBES_MAX_NUM] = {0}; + unsigned long dev_ids[DEVICES_SCAN_MAX] = {0}; + int ndevs = 0; success = parse_args(&a, argc, argv); if (EXIT_FAILURE == success) exit(EXIT_FAILURE); @@ -97,12 +138,26 @@ int main(int argc, char *argv[]) { /* List the probes (and display if asked) */ n_probes = list_probes(jc, probes, a.list); + i = 0; + while ((i= a.probe) || (a.probe > MIN(n_probes, PROBES_MAX_NUM))) goto err; + error = scan(jc, probes[a.probe-1].probe_id, &ndevs, dev_ids, 1); + break; + default: + printf("Unknown command."); + goto err; + } + i++; + } + goto end; + err: - printf("Error while executing a command.\n"); + printf("Exited with error (%d).\n", error); end: jtagcore_deinit(jc); - printf("Finished."); - return 0; + return error; } \ No newline at end of file diff --git a/app/src/utils.h b/app/src/utils.h new file mode 100644 index 0000000..b9ac895 --- /dev/null +++ b/app/src/utils.h @@ -0,0 +1,7 @@ +#ifndef _UTILS_H +#define _UTILS_H + +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define MAX(a,b) (((a)>(b))?(a):(b)) + +#endif \ No newline at end of file