From 6831c9f100752d86f350fc8003e1c6e5feae67f1 Mon Sep 17 00:00:00 2001 From: Marcel Telka Date: Tue, 3 Jun 2003 12:30:56 +0000 Subject: [PATCH] 2003-06-03 Marcel Telka * Makefile.am (libbrux_a_SOURCES): Added cmd/cmd.c, cmd/help.c, cmd/quit.c, and cmd/detectflash.c. * cmd/cmd.c: New file moved from jtag module, direcory src/cmd. * cmd/help.c: Ditto. * cmd/quit.c: Ditto. * cmd/detectflash.c: Ditto. git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@465 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- libbrux/ChangeLog | 8 ++++ libbrux/Makefile.am | 4 ++ libbrux/cmd/cmd.c | 82 +++++++++++++++++++++++++++++++++++++++ libbrux/cmd/detectflash.c | 62 +++++++++++++++++++++++++++++ libbrux/cmd/help.c | 79 +++++++++++++++++++++++++++++++++++++ libbrux/cmd/quit.c | 54 ++++++++++++++++++++++++++ 6 files changed, 289 insertions(+) create mode 100644 libbrux/cmd/cmd.c create mode 100644 libbrux/cmd/detectflash.c create mode 100644 libbrux/cmd/help.c create mode 100644 libbrux/cmd/quit.c diff --git a/libbrux/ChangeLog b/libbrux/ChangeLog index 64cbb089..c0416748 100644 --- a/libbrux/ChangeLog +++ b/libbrux/ChangeLog @@ -1,3 +1,11 @@ +2003-06-03 Marcel Telka + + * Makefile.am (libbrux_a_SOURCES): Added cmd/cmd.c, cmd/help.c, cmd/quit.c, and cmd/detectflash.c. + * cmd/cmd.c: New file moved from jtag module, direcory src/cmd. + * cmd/help.c: Ditto. + * cmd/quit.c: Ditto. + * cmd/detectflash.c: Ditto. + 2003-06-03 Marcel Telka * Makefile.am (libbrux_a_SOURCES): Added flash/detectflash.c. diff --git a/libbrux/Makefile.am b/libbrux/Makefile.am index 2095458f..5ce25859 100644 --- a/libbrux/Makefile.am +++ b/libbrux/Makefile.am @@ -26,6 +26,10 @@ include $(top_srcdir)/../Makefile.rules noinst_LIBRARIES = libbrux.a libbrux_a_SOURCES = \ + cmd/cmd.c \ + cmd/help.c \ + cmd/quit.c \ + cmd/detectflash.c \ flash/cfi.c \ flash/detectflash.c \ flash/amd.c \ diff --git a/libbrux/cmd/cmd.c b/libbrux/cmd/cmd.c new file mode 100644 index 00000000..0e4ee1aa --- /dev/null +++ b/libbrux/cmd/cmd.c @@ -0,0 +1,82 @@ +/* + * $Id$ + * + * Copyright (C) 2002, 2003 ETC s.r.o. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Written by Marcel Telka , 2002, 2003. + * + */ + +#include + +#include +#include + +#include + +int +cmd_run( char *params[] ) +{ + int i; + + if (!params[0]) + return 1; + + for (i = 0; cmds[i]; i++) + if (strcmp( cmds[i]->name, params[0] ) == 0) { + int r = cmds[i]->run( params ); + if (r < 0) + printf( _("%s: syntax error!\n"), params[0] ); + return r; + } + + printf( _("%s: unknown command\n"), params[0] ); + return 1; +} + +int +cmd_params( char *params[] ) +{ + int i = 0; + + while (params[i]) + i++; + + return i; +} + +int +cmd_get_number( char *s, unsigned int *i ) +{ + int n; + int r; + int l; + + if (!s || !i) + return -1; + + l = strlen( s ); + r = sscanf( s, "0x%x%n", i, &n); + if (r == 1 && n == l) + return 0; + r = sscanf( s, "%u%n", i, &n ); + if (r == 1 && n == l) + return 0; + + return -1; +} diff --git a/libbrux/cmd/detectflash.c b/libbrux/cmd/detectflash.c new file mode 100644 index 00000000..08749ccb --- /dev/null +++ b/libbrux/cmd/detectflash.c @@ -0,0 +1,62 @@ +/* + * $Id$ + * + * Copyright (C) 2003 ETC s.r.o. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Written by Marcel Telka , 2003. + * + */ + +#include + +#include + +#include +#include + +static int +cmd_detectflash_run( char *params[] ) +{ + if (cmd_params( params ) != 1) + return -1; + + if (!bus) { + printf( _("Error: Bus driver missing.\n") ); + return 1; + } + + detectflash( bus ); + + return 1; +} + +static void +cmd_detectflash_help( void ) +{ + printf( _( + "Usage: %s\n" + "Detect flash memory type connected to a part.\n" + ), "detectflash" ); +} + +cmd_t cmd_detectflash = { + "detectflash", + N_("detect parameters of flash chips attached to a part"), + cmd_detectflash_help, + cmd_detectflash_run +}; diff --git a/libbrux/cmd/help.c b/libbrux/cmd/help.c new file mode 100644 index 00000000..9842b45a --- /dev/null +++ b/libbrux/cmd/help.c @@ -0,0 +1,79 @@ +/* + * $Id$ + * + * Copyright (C) 2003 ETC s.r.o. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Written by Marcel Telka , 2003. + * + */ + +#include + +#include +#include + +#include + +extern cmd_t *cmds[]; + +static int +cmd_help_run( char *params[] ) +{ + int i; + + /* short description generation */ + if (!params[1]) { + int i; + printf( _("Command list:\n\n") ); + for (i = 0; cmds[i]; i++) + printf( _("%-13s %s\n"), cmds[i]->name, cmds[i]->desc ? _(cmds[i]->desc) : _("(no description available)") ); + printf( _("\nType \"help COMMAND\" for details about particular command.\n") ); + return 1; + } + + if (params[2]) + return -1; + + /* search and print help for particular command */ + for (i = 0; cmds[i]; i++) + if (strcmp( cmds[i]->name, params[1] ) == 0) { + if (cmds[i]->help) + cmds[i]->help(); + return 1; + } + + printf( _("%s: unknown command\n"), params[1] ); + + return 1; +} + +static void +cmd_help_help( void ) +{ + printf( _( + "Usage: %s [COMMAND]\n" + "Print short help for COMMAND, or list of available commands.\n" + ), "help" ); +} + +cmd_t cmd_help = { + "help", + N_("display this help"), + cmd_help_help, + cmd_help_run +}; diff --git a/libbrux/cmd/quit.c b/libbrux/cmd/quit.c new file mode 100644 index 00000000..682c45b2 --- /dev/null +++ b/libbrux/cmd/quit.c @@ -0,0 +1,54 @@ +/* + * $Id$ + * + * Copyright (C) 2003 ETC s.r.o. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Written by Marcel Telka , 2003. + * + */ + +#include + +#include + +#include + +static int +cmd_quit_run( char *params[] ) +{ + if (params[1]) + return -1; + + return 0; +} + +static void +cmd_quit_help( void ) +{ + printf( _( + "Usage: %s\n" + "Exit from %s.\n" + ), "quit", PACKAGE ); +} + +cmd_t cmd_quit = { + "quit", + N_("exit and terminate this session"), + cmd_quit_help, + cmd_quit_run +};