view rvinterf/asyncshell/oneshot.c @ 11:21eec7569eb8

loadtools support for C139/140 target: -c 1004 compalstage variant supercedes the previous -c 1003 version and supports the new C139 boot code version found in the wild that expects "1004" or greater in the signature bytes
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 25 Jul 2016 21:09:33 +0000
parents e7502631a0f9
children d43d82cbfb85
line wrap: on
line source

/*
 * This module implements the one-shot command mode of fc-shell.
 */

#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include "limits.h"

extern int cmd_poweroff();
extern int cmd_send_oneshot();
extern int cmd_sp_oneshot();
extern int cmd_tchdl_oneshot();
extern int cmd_tgtreset();

static struct cmdtab {
	char *cmd;
	int minargs;
	int maxargs;
	int (*func)();
} cmdtab[] = {
	{"poweroff", 0, 0, cmd_poweroff},
	{"send", 1, MAX_PKT_TO_TARGET, cmd_send_oneshot},
	{"sp", 2, 2, cmd_sp_oneshot},
	{"tch-dl", 1, 1, cmd_tchdl_oneshot},
	{"tgtreset", 0, 0, cmd_tgtreset},
	{0, 0, 0, 0}
};

oneshot_command(argc, argv)
	char **argv;
{
	struct cmdtab *tp;

	for (tp = cmdtab; tp->cmd; tp++)
		if (!strcmp(tp->cmd, argv[0]))
			break;
	if (!tp->func) {
		fprintf(stderr,
			"error: \"%s\" is not a valid one-shot command\n",
			argv[0]);
		exit(1);
	}
	if (argc - 1 > tp->maxargs) {
		fprintf(stderr, "%s: too many arguments\n", tp->cmd);
		exit(1);
	}
	if (argc - 1 < tp->minargs) {
		fprintf(stderr, "%s: too few arguments\n", tp->cmd);
		exit(1);
	}
	return tp->func(argc, argv);
}