129 lines
2.8 KiB
C
129 lines
2.8 KiB
C
#include <stdio.h>
|
|
#include <stdarg.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <signal.h>
|
|
#include <readline/readline.h>
|
|
#include <readline/history.h>
|
|
|
|
#include "config/bs_defines.h"
|
|
#include "utils.h"
|
|
#include "init.h"
|
|
#include "args.h"
|
|
#include "script/script.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;
|
|
// }
|
|
|
|
jtag_core *jc = NULL;
|
|
script_ctx *sctx = NULL;
|
|
|
|
// Fonction de gestion du signal
|
|
void handle_sigint(int sig) {
|
|
bsexp_deinit(jc, sctx);
|
|
exit(0);
|
|
}
|
|
|
|
int execute_command(script_ctx *sctx, char *line)
|
|
{
|
|
int error = 0;
|
|
error = execute_line_script(sctx, line);
|
|
return error;
|
|
}
|
|
|
|
int main()
|
|
{
|
|
char *line = NULL;
|
|
int error = 0;
|
|
int cmd_argc = 0;
|
|
|
|
bsexp_init(&jc, &sctx);
|
|
script_print(sctx, MSG_NONE, "\n");
|
|
if ((NULL == jc) || (NULL == sctx))
|
|
{
|
|
error = JTAG_CORE_MEM_ERROR;
|
|
printf("JTAG Core initialization failed!\n");
|
|
goto err_no_deinit;
|
|
}
|
|
|
|
signal(SIGINT, handle_sigint);
|
|
while (1)
|
|
{
|
|
line = readline("bs_explorer> ");
|
|
if (line == NULL)
|
|
{
|
|
break;
|
|
}
|
|
if (*line)
|
|
{
|
|
add_history(line);
|
|
}
|
|
if (strcmp(line, "exit") == 0) {
|
|
break;
|
|
}
|
|
if (strcmp(line, "quit") == 0) {
|
|
break;
|
|
}
|
|
error = execute_command(sctx, line);
|
|
if (0 == error)
|
|
{
|
|
}
|
|
else
|
|
{
|
|
printf("Command failed with code: %d\n", error);
|
|
}
|
|
}
|
|
|
|
err_no_deinit:
|
|
exit(error);
|
|
err:
|
|
printf("Failed with error (%d)", error);
|
|
end:
|
|
bsexp_deinit(jc, sctx);
|
|
exit(error);
|
|
} |