diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..a3d192b --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,33 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "(gdb) Launch", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/build/app/bs", + "args": ["-l", "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 + } + ] + } + + ] +} \ No newline at end of file diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 8b47ed1..9aa596d 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -1,8 +1,10 @@ +file(GLOB_RECURSE ALL_SOURCES "src/*.c") + # Application configuration add_executable( bs - main.c + ${ALL_SOURCES} ) # linking configuration diff --git a/app/main.c b/app/main.c deleted file mode 100644 index 6bbcdb1..0000000 --- a/app/main.c +++ /dev/null @@ -1,21 +0,0 @@ -#include - -#include "jtag_core.h" - - -void jtcprint(jtag_core *jc, const char *msg) { - printf(msg); -} - -int main(int argc, char **argv) { - - jtag_core *jc; - - jc = jtagcore_init(); - if (jtagcore_set_logs_callback(jc, jtcprint) < 0) goto end; - -end: - jtagcore_deinit(jc); - printf("Finished."); - return 0; -} \ No newline at end of file diff --git a/app/src/args.c b/app/src/args.c new file mode 100644 index 0000000..dd99b11 --- /dev/null +++ b/app/src/args.c @@ -0,0 +1,65 @@ +#include +#include +#include +#include +#include + +#include "args.h" + +char * COMMAND_STRINGS[COMMANDS_NUMBER-1] = { + "scan" +}; + +void usage() { + printf("Usage: bs [[-l] [--list]] [[-n] [--nprobe] PROBE_NUM] [scan]\n"); +} + +int parse_args(struct args *a, int argc, char *argv[]) { + int opt = 0; + int i = 0; + int command = 0; + __uint8_t option_arg[32] = {0}; + + // Définir les options longues + static struct option long_options[] = { + {"list", no_argument, 0, 'l'}, + {"nprobe", required_argument, 0, 'n'}, + {0, 0, 0, 0} + }; + + // Utilisation de getopt_long pour parser les options + while ((opt = getopt_long(argc, argv, "ln:", long_options, NULL)) != -1) { + switch (opt) { + case 'l': + a->list = 1; + break; + case 'n': + snprintf(option_arg, sizeof(option_arg)-2, "%s"); + a->probe = atoi(option_arg); + break; + default: + usage(); + return EXIT_FAILURE; + } + } + + // Positional arguments + if (optind < argc) { + /* Positional arguments */ + while (optind < argc) { + for (i=0;icmds[command] = (enum commands)i+1; + } + } + optind++; + } + } + + // Si aucune option n'est fournie, afficher l'aide + if (optind == 1) { + usage(); + } + + return EXIT_SUCCESS; +} diff --git a/app/src/args.h b/app/src/args.h new file mode 100644 index 0000000..680c754 --- /dev/null +++ b/app/src/args.h @@ -0,0 +1,20 @@ +#ifndef _ARGS_H +#define _ARGS_H + +#define MAX_COMMANDS 16 + +enum commands { + NO_COMMAND=0, + COMMAND_SCAN, + COMMANDS_NUMBER, /* The number of enums +1*/ +}; + +struct args { + int list; + int probe; + enum commands cmds[MAX_COMMANDS]; +}; + +int parse_args(struct args *a, int argc, char *argv[]); + +#endif diff --git a/app/src/main.c b/app/src/main.c new file mode 100644 index 0000000..5458729 --- /dev/null +++ b/app/src/main.c @@ -0,0 +1,108 @@ +#include +#include +#include +#include + +#include "jtag_core.h" +#include "args.h" + + +#define PROBES_MAX_NUM 16 +#define PROBE_NAME_SIZE 64 + + +struct probe { + int drv; + int probe; + int probe_id; + char name[PROBE_NAME_SIZE]; +}; + + +void jprint(jtag_core *jc, const char *msg) { + printf(msg); +} + + +int list_probes(jtag_core *jc, struct probe probes[], int show) { + int i = 0; + int j = 0; + int n = 0; + + char probe_name[PROBE_NAME_SIZE] = {0}; + int n_probe_drv = 0; + int n_probes = 0; + + /* Drivers and probes */ + n_probe_drv = jtagcore_get_number_of_probes_drv(jc); + if (n_probe_drv > 0) { + if (0 != show) printf("Found a debug probe driver:\n"); + } else { + if (0 != show) printf("No probes driver found\n"); + return n; + } + + for (i=0;i 0) { + + if (0 != show) printf("Found a debug probe:\n"); + + } else { + + if (0 != show) printf("No probe found.\n"); + continue; + } + for (j=0;j