# HG changeset patch # User Michael Spacefalcon # Date 1367648529 0 # Node ID ae6294b8a01553696ba1be5704863cfb34e6e24a # Parent 1a3bbab2ea260663acc366e2a07f99d85af75dbc loadtool: exit jump0 implemented diff -r 1a3bbab2ea26 -r ae6294b8a015 loadtools/Makefile --- a/loadtools/Makefile Sat May 04 05:38:58 2013 +0000 +++ b/loadtools/Makefile Sat May 04 06:22:09 2013 +0000 @@ -5,7 +5,7 @@ SERTOOL_OBJS= defpath.o hexdecode.o hwparam.o romload.o sercomm.o sertool.o \ srecreader.o ttypassthru.o -LOADTOOL_OBJS= defpath.o hexdecode.o hwparam.o ltdispatch.o ltmain.o \ +LOADTOOL_OBJS= defpath.o hexdecode.o hwparam.o ltdispatch.o ltexit.o ltmain.o \ ltpassthru.o romload.o sercomm.o srecreader.o tpinterf.o all: ${PROGS} diff -r 1a3bbab2ea26 -r ae6294b8a015 loadtools/ltdispatch.c --- a/loadtools/ltdispatch.c Sat May 04 05:38:58 2013 +0000 +++ b/loadtools/ltdispatch.c Sat May 04 06:22:09 2013 +0000 @@ -10,14 +10,9 @@ extern char loadtool_command[]; +extern int cmd_exit(); extern int loadtool_cmd_passthru(); -static int -exitcmd() -{ - exit(0); -} - static struct cmdtab { char *cmd; int minargs; @@ -25,8 +20,8 @@ int (*func)(); } cmdtab[] = { {"dump", 2, 2, loadtool_cmd_passthru}, - {"exit", 0, 0, &exitcmd}, - {"quit", 0, 0, &exitcmd}, + {"exit", 0, 1, cmd_exit}, + {"quit", 0, 1, cmd_exit}, {"r8", 1, 1, loadtool_cmd_passthru}, {"r16", 1, 1, loadtool_cmd_passthru}, {"r32", 1, 1, loadtool_cmd_passthru}, diff -r 1a3bbab2ea26 -r ae6294b8a015 loadtools/ltexit.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/loadtools/ltexit.c Sat May 04 06:22:09 2013 +0000 @@ -0,0 +1,55 @@ +/* + * This module implements the loadtool exit command, along with its + * options for jump-reboot or eventual Iota power-off. + */ + +#include +#include +#include +#include + +static void +exit_bare() +{ + exit(0); +} + +static void +exit_jump0() +{ + static char *jump0_argv[3] = {"jump", "0", 0}; + + tpinterf_make_cmd(jump0_argv); + tpinterf_send_cmd(); + exit(0); +} + +void (*default_exit)() = exit_bare; + +static struct kwtab { + char *kw; + void (*func)(); +} exit_modes[] = { + {"bare", exit_bare}, + {"jump0", exit_jump0}, + {0, 0} +}; + +cmd_exit(argc, argv) + char **argv; +{ + struct kwtab *tp; + + if (argc < 2) + default_exit(); + for (tp = exit_modes; tp->kw; tp++) + if (!strcmp(tp->kw, argv[1])) + break; + if (!tp->func) { + fprintf(stderr, + "error: \"%s\" is not an understood exit mode\n", + argv[1]); + return(-1); + } + tp->func(); +} diff -r 1a3bbab2ea26 -r ae6294b8a015 loadtools/ltmain.c --- a/loadtools/ltmain.c Sat May 04 05:38:58 2013 +0000 +++ b/loadtools/ltmain.c Sat May 04 06:22:09 2013 +0000 @@ -13,6 +13,8 @@ extern struct srecreader iramimage; extern char default_loadagent_image[]; +extern void (*default_exit)(); + char loadtool_command[512]; main(argc, argv) @@ -59,7 +61,7 @@ fflush(stdout); } if (!fgets(loadtool_command, sizeof loadtool_command, stdin)) - exit(0); + default_exit(); loadtool_dispatch_cmd(); } }