phase 1: cleanup, REPL polish, README
- fix format-string in jprint/script_print (printf(msg) -> fputs)
- fix bsexp_deinit: deinit_script guarded by sctx, not jc
- silence "config.script not found" when the optional override is absent
- remove dead code: bs/cmds/, bs/args.{c,h}, bs/utils.h, commented blocks
- REPL: welcome banner with version, readline tab-completion on
script_commands_list, skip blank lines, clean Ctrl-D exit
- README: build, REPL usage, typical SPI flow, command table, probes,
Xilinx STARTUPE3/CCLK caveat
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
96
bs/init.c
96
bs/init.c
@@ -1,24 +1,4 @@
|
||||
#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 <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
@@ -27,42 +7,33 @@ Command commands[] = {
|
||||
#include "config/version.h"
|
||||
#include "script/env.h"
|
||||
#include "script/script.h"
|
||||
|
||||
#include "config/config_script.h"
|
||||
|
||||
#include "init.h"
|
||||
|
||||
void jprint(jtag_core *jc, const char *msg)
|
||||
{
|
||||
printf(msg);
|
||||
fputs(msg, stdout);
|
||||
}
|
||||
|
||||
int script_print(script_ctx *sctx, enum MSGTYPE typ, char *string, ...)
|
||||
{
|
||||
int ret = 0;
|
||||
char msg[64] = {0};
|
||||
const char *prefix = "";
|
||||
va_list args;
|
||||
|
||||
switch (typ)
|
||||
{
|
||||
case MSG_DEBUG:
|
||||
strcpy(msg, "DEBUG :");
|
||||
break;
|
||||
case MSG_INFO_1:
|
||||
strcpy(msg, "INFO :");
|
||||
break;
|
||||
case MSG_WARNING:
|
||||
strcpy(msg, "WARNING :");
|
||||
break;
|
||||
case MSG_ERROR:
|
||||
strcpy(msg, "ERROR :");
|
||||
break;
|
||||
case MSG_DEBUG: prefix = "DEBUG : "; break;
|
||||
case MSG_INFO_1: prefix = "INFO : "; break;
|
||||
case MSG_WARNING: prefix = "WARNING : "; break;
|
||||
case MSG_ERROR: prefix = "ERROR : "; break;
|
||||
case MSG_INFO_0:
|
||||
default:
|
||||
strcpy(msg, "");
|
||||
break;
|
||||
default: prefix = ""; break;
|
||||
}
|
||||
|
||||
va_start(args, string);
|
||||
ret = printf(msg);
|
||||
ret = fputs(prefix, stdout);
|
||||
ret += vprintf(string, args);
|
||||
va_end(args);
|
||||
return ret;
|
||||
@@ -70,64 +41,61 @@ int script_print(script_ctx *sctx, enum MSGTYPE typ, char *string, ...)
|
||||
|
||||
void bsexp_init(jtag_core **jc, script_ctx **sctx)
|
||||
{
|
||||
// JTAG core initialization
|
||||
*jc = jtagcore_init();
|
||||
if (NULL == *jc)
|
||||
goto end;
|
||||
return;
|
||||
|
||||
// Environment initialization
|
||||
(*jc)->envvar = (void *)initEnv(NULL, NULL);
|
||||
if (NULL == (*jc)->envvar) {
|
||||
jtagcore_deinit(*jc);
|
||||
*jc = NULL;
|
||||
goto end;
|
||||
return;
|
||||
}
|
||||
jtagcore_setEnvVar(*jc, "VERSION", "v" APP_VER_STR(APP_VER));
|
||||
|
||||
// Scripts initialization
|
||||
*sctx = jtagcore_initScript(*jc);
|
||||
if (NULL == *sctx) {
|
||||
deinitEnv((*jc)->envvar);
|
||||
jtagcore_deinit(*jc);
|
||||
*jc = NULL;
|
||||
goto end;
|
||||
return;
|
||||
}
|
||||
setOutputFunc_script(*sctx, script_print);
|
||||
execute_ram_script(*sctx, config_script, config_script_len);
|
||||
execute_file_script(*sctx, "config.script");
|
||||
/* User override is optional — silence the engine's "not found" message. */
|
||||
{
|
||||
FILE *f = fopen("config.script", "r");
|
||||
if (f) {
|
||||
fclose(f);
|
||||
execute_file_script(*sctx, "config.script");
|
||||
}
|
||||
}
|
||||
|
||||
/* Log printing callback */
|
||||
if (jtagcore_set_logs_callback(*jc, jprint) < 0)
|
||||
{
|
||||
printf("Impossible to define the logs callback!\n");
|
||||
fputs("Impossible to define the logs callback!\n", stderr);
|
||||
return;
|
||||
}
|
||||
else
|
||||
|
||||
if (jtagcore_getEnvVar(*jc, "LOG_MESSAGES_FILTER_LEVEL", NULL))
|
||||
{
|
||||
if (jtagcore_getEnvVar(*jc, "LOG_MESSAGES_FILTER_LEVEL", NULL))
|
||||
{
|
||||
jtagcore_set_logs_level(*jc, jtagcore_getEnvVarValue(*jc, "LOG_MESSAGES_FILTER_LEVEL"));
|
||||
}
|
||||
if (jtagcore_getEnvVar(*jc, "LOG_MESSAGES_FILE_OUTPUT", NULL))
|
||||
{
|
||||
jtagcore_set_logs_file(*jc, jtagcore_getEnvVar(*jc, "LOG_MESSAGES_FILE_OUTPUT", NULL));
|
||||
}
|
||||
jtagcore_set_logs_level(*jc, jtagcore_getEnvVarValue(*jc, "LOG_MESSAGES_FILTER_LEVEL"));
|
||||
}
|
||||
if (jtagcore_getEnvVar(*jc, "LOG_MESSAGES_FILE_OUTPUT", NULL))
|
||||
{
|
||||
jtagcore_set_logs_file(*jc, jtagcore_getEnvVar(*jc, "LOG_MESSAGES_FILE_OUTPUT", NULL));
|
||||
}
|
||||
end:
|
||||
return;
|
||||
}
|
||||
|
||||
void bsexp_deinit(jtag_core *jc, script_ctx *sctx)
|
||||
{
|
||||
envvar_entry *env = NULL;
|
||||
|
||||
if (NULL != jc)
|
||||
if (NULL != sctx)
|
||||
{
|
||||
deinit_script(sctx);
|
||||
}
|
||||
if (NULL != jc)
|
||||
{
|
||||
env = jc->envvar;
|
||||
deinitEnv(env);
|
||||
deinitEnv((envvar_entry *)jc->envvar);
|
||||
jtagcore_deinit(jc);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user