app dir changed and src dir removed

This commit is contained in:
2025-02-16 17:37:56 +01:00
parent 4f6cd20130
commit f3c2569a30
22 changed files with 88 additions and 58 deletions

15
bs/CMakeLists.txt Normal file
View File

@@ -0,0 +1,15 @@
file(GLOB_RECURSE ALL_SOURCES "*.c")
# Application configuration
add_executable(
bs
${ALL_SOURCES}
)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../modules)
# linking configuration
target_link_libraries(
bs PRIVATE ${BS_MODULES} readline ncurses
)

91
bs/args.c Normal file
View File

@@ -0,0 +1,91 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <string.h>
#include "common.h"
#include "args.h"
// void global_help() {
// printf("Usage: bs [[-l] [--list]] [[-n] [--nprobe]] [[-b] [--bsdl]] [[-d] [--device_id]] PROBE_NUM] [<cmd>] [<cmd_options>]\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[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:b:d:", long_options, NULL)) != -1) {
// switch (opt) {
// case 'h':
// a->list = 1;
// break;
// case 'n':
// 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;
// }
// }
// // Positional arguments
// if (optind < argc) {
// /* Positional arguments */
// while (optind < argc) {
// for (i=0;i<COMMANDS_NUMBER-1;i++) {
// if (0 == strcmp(COMMAND_STRINGS[i], argv[optind])) {
// a->cmds[command] = (enum commands)i+1;
// }
// }
// optind++;
// }
// }
// // Si aucune option n'est fournie, afficher l'aide
// if (optind == 1) {
// usage();
// }
// return EXIT_SUCCESS;
// }
void parse_command(char *line, int *argc, char **argv) {
*argc = 0;
while (*line != '\0') {
while (*line == ' ' || *line == '\t' || *line == '\n') {
*line++ = '\0';
}
if (*argc >= MAX_ARGS) break;
(*argc)++;
*argv++ = line;
while (*line != '\0' && *line != ' ' && *line != '\t' && *line != '\n') {
line++;
}
}
*argv = '\0';
}

20
bs/args.h Normal file
View File

@@ -0,0 +1,20 @@
#ifndef _ARGS_H
#define _ARGS_H
// #define MAX_LINE 1024
// #define MAX_ARGS 16
// #define MAX_COMMANDS 16
// #define MAX_PATH 1024
// struct args {
// int list;
// int probe;
// char bsdl[MAX_PATH];
// int devid;
// enum commands cmds[MAX_COMMANDS];
// };
// int parse_args(struct args *a, int argc, char *argv[]);
void parse_command(char *line, int *argc, char **argv);
#endif

11
bs/cmds/exit.c Normal file
View File

@@ -0,0 +1,11 @@
#include <stdio.h>
#include <stdlib.h>
#include "exit.h"
const char cmd_exit_help[] = "Bla bla.";
int cmd_exit(jtag_core *jc, int argc, char **argv) {
jtagcore_deinit(jc);
exit(0);
}

10
bs/cmds/exit.h Normal file
View File

@@ -0,0 +1,10 @@
#ifndef _CMD_EXIT_H
#define _CMD_EXIT_H
#include "jtag_core/jtag_core.h"
extern const char cmd_exit_help[];
int cmd_exit(jtag_core *jc, int argc, char *argv[]);
#endif /* _CMD_EXIT_H */

8
bs/cmds/help.c Normal file
View File

@@ -0,0 +1,8 @@
#include <stdio.h>
#include <stdlib.h>
#include "help.h"
int cmd_help(jtag_core *jc, int argc, char **argv) {
}

8
bs/cmds/help.h Normal file
View File

@@ -0,0 +1,8 @@
#ifndef _CMD_HELP_H
#define _CMD_HELP_H
#include "jtag_core/jtag_core.h"
int cmd_help(jtag_core *jc, int argc, char *argv[]);
#endif /* _CMD_help_H */

69
bs/cmds/list_probes.c Normal file
View File

@@ -0,0 +1,69 @@
#include <stdio.h>
#include <string.h>
#include "list_probes.h"
#include "common.h"
const char cmd_list_probes_help[] = "Bla bla.";
struct probe {
int drv;
int probe;
int probe_id;
char name[PROBE_NAME_SIZE];
};
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<n_probe_drv;i++) {
if (0 != show) printf(" JTAG probe driver %d\n", i);
n_probes = jtagcore_get_number_of_probes(jc, i);
if (n_probes > 0) {
if (0 != show) printf("Found a debug probe:\n");
} else {
if (0 != show) printf("No probe found.\n");
continue;
}
for (j=0;j<n_probes;j++) {
jtagcore_get_probe_name(jc, PROBE_ID(i,j), probe_name);
if (n < PROBES_MAX_NUM) {
probes[n].drv = i;
probes[n].probe = j;
probes[n].probe_id = PROBE_ID(i,j);
strncpy(probes[n].name, probe_name, PROBE_NAME_SIZE);
}
if (0 != show) {
printf(" JTAG probe %d: ", n+1);
printf("%s.\n", probe_name);
}
n++;
}
}
return n;
}
int cmd_list_probes(jtag_core *jc, int argc, char *argv[]) {
}

10
bs/cmds/list_probes.h Normal file
View File

@@ -0,0 +1,10 @@
#ifndef _LIST_PROBES_H
#define _LIST_PROBES_H
#include "jtag_core/jtag_core.h"
extern const char cmd_list_probes_help[];
int cmd_list_probes(jtag_core *jc, int argc, char *argv[]);
#endif

39
bs/cmds/scan.c Normal file
View File

@@ -0,0 +1,39 @@
#include <stdio.h>
#include "scan.h"
#include "common.h"
const char cmd_scan_help[] = "Bla bla.";
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_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 cmd_scan(jtag_core *jc, int argc, char *argv[]) {
}

11
bs/cmds/scan.h Normal file
View File

@@ -0,0 +1,11 @@
#ifndef _CMDS_SCAN_H
#define _CMDS_SCAN_H
#include "jtag_core/jtag_core.h"
extern const char cmd_scan_help[];
int cmd_scan(jtag_core *jc, int argc, char *argv[]);
#endif

16
bs/cmds/select_probe.c Normal file
View File

@@ -0,0 +1,16 @@
#include <stdio.h>
#include "select_probe.h"
const char cmd_select_probe_help[] = "Bla bla.";
int cmd_select_probe(jtag_core *jc, int argc, char *argv[]) {
int error = 0;
// error = jtagcore_select_and_open_probe(jc, probe_id);
if (error < 0) {
printf("Impossible to open the selected probe.\n");
return error;
}
}

10
bs/cmds/select_probe.h Normal file
View File

@@ -0,0 +1,10 @@
#ifndef _SELECT_PROBE_H
#define _SELECT_PROBE_H
#include "jtag_core/jtag_core.h"
extern const char cmd_select_probe_help[];
int cmd_select_probe(jtag_core *jc, int argc, char *argv[]);
#endif

63
bs/init.c Normal file
View File

@@ -0,0 +1,63 @@
#include <stddef.h>
#include <stdio.h>
/*
#include "common.h"
#include "cmds/help.h"
#include "cmds/scan.h"
#include "cmds/list_probes.h"
#include "cmds/exit.h"
#include "cmds/select_probe.h"
// Table des commandes internes
Command commands[] = {
{"help", cmd_help, NULL},
{"list_probes", cmd_list_probes, cmd_list_probes_help},
{"scan", cmd_scan, cmd_scan_help},
{"select_probe", cmd_select_probe, cmd_select_probe_help},
{"exit", cmd_exit, cmd_exit_help},
{NULL, NULL}};
*/
#include "jtag_core/jtag_core.h"
void jprint(jtag_core *jc, const char *msg)
{
printf(msg);
}
jtag_core *bsexp_init(void)
{
jtag_core *jc = NULL;
/* initialize the JTAG library */
jc = jtagcore_init();
if (NULL == jc) goto end;
jc->envvar = (void*)initEnv(NULL, NULL);
jtagcore_setEnvVar( jc, "VERSION", "v"jtag_core_VERSION);
sctx = jtagcore_initScript(jc);
jtagcore_execScriptRam( sctx, config_script, config_script_len );
jtagcore_execScriptFile( sctx, "config.script" );
/* Log printing callback */
if (jtagcore_set_logs_callback(jc, jprint) < 0)
{
printf("Impossible to define the logs callback!\n");
}
else
{
if(jtagcore_getEnvVar( jc, "LOG_MESSAGES_FILTER_LEVEL", NULL))
{
jtagcore_set_logs_level( jc, jtagcore_getEnvVarValue( jc, "LOG_MESSAGES_FILTER_LEVEL") );
}
}
end:
return jc;
}

17
bs/init.h Normal file
View File

@@ -0,0 +1,17 @@
#ifndef _UTILS_H
#define _UTILS_H
#include "jtag_core/jtag_core.h"
typedef int (*command_call)(jtag_core *jc, int argc, char *argv[]);
typedef struct {
char *name;
command_call cmd_call;
} Command;
extern Command commands[];
jtag_core *bsexp_init(void);
#endif

117
bs/main.c Normal file
View File

@@ -0,0 +1,117 @@
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <readline/readline.h>
#include <readline/history.h>
#include "jtag_core/jtag_core.h"
#include "common.h"
#include "args.h"
// int main(int argc, char *argv[]) {
// 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);
// jc = bsexp_init();
// if (NULL == jc) {
// error = JTAG_CORE_MEM_ERROR;
// goto err;
// }
// /* List the probes (and display if asked) */
// n_probes = list_probes(jc, probes, a.list);
// i = 0;
// while ((i<MAX_COMMANDS) && (a.cmds[i] != NO_COMMAND)) {
// switch (a.cmds[i]) {
// case COMMAND_SCAN:
// if ((0 >= 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("Exited with error (%d).\n", error);
// end:
// jtagcore_deinit(jc);
// return error;
// }
int execute_command(jtag_core *jc, int argc, char **argv) {
int error = 0;
if (argv[0] == NULL) {
return 0;
}
for (int i = 0; commands[i].name != NULL; i++) {
if (strcmp(argv[0], commands[i].name) == 0) {
error = commands[i].cmd_call(jc, argc, argv);
return error;
}
}
error = -1;
printf("Command not found\n");
}
int main() {
char *line = NULL;
int error = 0;
int cmd_argc=0;
char *cmd_argv[MAX_ARGS] = {0};
jtag_core *jc = NULL;
jc = bsexp_init();
if (NULL == jc) {
error = JTAG_CORE_MEM_ERROR;
printf("JTAG Core execution failed");
goto err;
}
while (1) {
line = readline("bs_explorer> ");
if (line == NULL) {
break;
}
if (*line) {
add_history(line);
}
parse_command(line, &cmd_argc, cmd_argv);
if (cmd_argv[0] == NULL) {
continue;
}
if (strcmp(cmd_argv[0], "exit") == 0) {
break;
}
error = execute_command(jc, cmd_argc, cmd_argv);
printf("\n");
if (0 == error) {
} else {
printf("Command failed with code: %d", error);
}
}
return 0;
err:
return error;
}

14
bs/utils.h Normal file
View File

@@ -0,0 +1,14 @@
#ifndef _UTILS_H
#define _UTILS_H
#define MAX_LINE 1024
#define MAX_ARGS 16
#define PROBES_MAX_NUM 16
#define PROBE_NAME_SIZE 64
#define DEVICES_SCAN_MAX 32
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
#endif

16
bs/version.h Normal file
View File

@@ -0,0 +1,16 @@
#define VDIG1 2
#define VDIG2 6
#define VDIG3 7
#define VDIG4 1
#define STR_DATE "28 Oct 2024"
#define vxstr(s) vstr(s)
#define vstr(s) #s
#define LIB_JTAG_CORE_VERSION vxstr(VDIG1) "." vxstr(VDIG2) "." vxstr(VDIG3) "." vxstr(VDIG4)
#define LIB_JTAG_CORE_VERSION_COMMA vxstr(VDIG1) "," vxstr(VDIG2) "," vxstr(VDIG3) "," vxstr(VDIG4)
#define APP_VER VDIG1.VDIG2.VDIG3.VDIG4
#define APP_VER_TXT( N ) JTAG Boundary Scanner v##N
#define APP_VER_STR( N ) vxstr( APP_VER_TXT( N ) )