Committed.
1. This is a step in the direction of telnet UI vs. low level API commands.
2. The "openocd_throw" prefix is no longer necessary when invoking
OpenOCD commands from Tcl. The "unknown" proc defined in
tcl/commands.tcl redirects any unknown Tcl commands to OpenOCD
"flash_banks" is a low level tcl command that returns a list of banks.
This command
is intended to be part of the OpenOCD API.
"flash banks" is now implemented in tcl for illustrative purposes. This command
is *not* part of the API, but rather part of the telnet UI.
"flash_banks_pretty" is the actual Tcl proc which impleements "flash banks".
# Show flash in human readable form
# This is an example of a human readable form of a low level fn
proc flash_banks_pretty {} {
set i 0
set result ""
foreach {a} [flash_banks] {
if {$i > 0} {
set result "$result\n"
}
set result [format "$result#%d: %s at 0x%08x, size 0x%08x,
buswidth
%d, chipwidth %d" $i [lindex $a 0] [lindex $a 1] [lindex $a 2] [lindex
$a 3] [lindex $a 4]]
set i [expr $i+1]
}
return $result
}
Behaviour is the same as before:
Open On-Chip Debugger
> flash_banks
{ecosflash 16777216 2097152 2 2}
> flash bnaks
> flash banks
#0: ecosflash at 0x01000000, size 0x00200000, buswidth 2, chipwidth 2
>
> flash_banks_pretty
#0: ecosflash at 0x01000000, size 0x00200000, buswidth 2, chipwidth 2
>
--
Øyvind Harboe
http://www.zylin.com/zy1000.html
ARM7 ARM9 XScale Cortex
JTAG debugger and flash programmer
Index: C:/workspace/trunk/src/flash/flash.c
===================================================================
--- C:/workspace/trunk/src/flash/flash.c (revision 778)
+++ C:/workspace/trunk/src/flash/flash.c (working copy)
@@ -48,7 +48,6 @@
/* command handlers */
int handle_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd,
char **args, int argc);
-int handle_flash_banks_command(struct command_context_s *cmd_ctx, char *cmd,
char **args, int argc);
int handle_flash_info_command(struct command_context_s *cmd_ctx, char *cmd,
char **args, int argc);
int handle_flash_probe_command(struct command_context_s *cmd_ctx, char *cmd,
char **args, int argc);
int handle_flash_erase_check_command(struct command_context_s *cmd_ctx, char
*cmd, char **args, int argc);
@@ -186,8 +185,6 @@
{
Jim_CreateCommand(interp, "flash_banks",
Jim_Command_flash_banks, NULL, NULL );
- register_command(cmd_ctx, flash_cmd, "banks",
handle_flash_banks_command, COMMAND_EXEC,
- "list configured flash banks
");
register_command(cmd_ctx, flash_cmd, "info",
handle_flash_info_command, COMMAND_EXEC,
"print info about flash bank
<num>");
register_command(cmd_ctx, flash_cmd, "probe",
handle_flash_probe_command, COMMAND_EXEC,
@@ -340,26 +337,6 @@
return ERROR_OK;
}
-int handle_flash_banks_command(struct command_context_s *cmd_ctx, char *cmd,
char **args, int argc)
-{
- flash_bank_t *p;
- int i = 0;
-
- if (!flash_banks)
- {
- command_print(cmd_ctx, "no flash banks configured");
- return ERROR_OK;
- }
-
- for (p = flash_banks; p; p = p->next)
- {
- command_print(cmd_ctx, "#%i: %s at 0x%8.8x, size 0x%8.8x,
buswidth %i, chipwidth %i",
- i++, p->driver->name, p->base,
p->size, p->bus_width, p->chip_width);
- }
-
- return ERROR_OK;
-}
-
int handle_flash_info_command(struct command_context_s *cmd_ctx, char *cmd,
char **args, int argc)
{
flash_bank_t *p;
Index: C:/workspace/trunk/src/helper/command.c
===================================================================
--- C:/workspace/trunk/src/helper/command.c (revision 778)
+++ C:/workspace/trunk/src/helper/command.c (working copy)
@@ -465,25 +465,13 @@
int command_run_line(command_context_t *context, char *line)
{
- int retval;
-
- if ((!context) || (!line))
- return ERROR_INVALID_ARGUMENTS;
-
- if ((retval = command_run_line_internal(context, line)) ==
ERROR_COMMAND_NOTFOUND)
- {
- /* If we can't find a command, then try the interpreter.
- * If there is no interpreter implemented, then this will
- * simply print a syntax error.
- *
- * These hooks were left in to reduce patch size for
- * wip to add scripting language.
- */
-
- return jim_command(context, line);
- }
-
- return retval;
+ /* if a command is unknown to the "unknown" proc in tcl/commands.tcl
will
+ * redirect it to OpenOCD.
+ *
+ * This avoids having to type the "openocd" prefix and makes OpenOCD
+ * commands "native" to Tcl.
+ */
+ return jim_command(context, line);
}
int command_run_file(command_context_t *context, FILE *file, enum command_mode
mode)
Index: C:/workspace/trunk/src/openocd.c
===================================================================
--- C:/workspace/trunk/src/openocd.c (revision 778)
+++ C:/workspace/trunk/src/openocd.c (working copy)
@@ -379,6 +379,12 @@
line = Jim_GetString(objPtr, NULL);
LOG_USER_N("In procedure '%s' called at file \"%s\",
line %s" JIM_NL, proc, file, line);
}
+ long t;
+ if (Jim_GetLong(interp, Jim_GetVariableStr(interp,
"openocd_result", JIM_ERRMSG), &t)==JIM_OK)
+ {
+ return t;
+ }
+ return ERROR_FAIL;
} else if (retcode == JIM_EXIT) {
/* ignore. */
/* exit(Jim_GetExitCode(interp)); */
@@ -419,6 +425,13 @@
log_add_callback(tcl_output, tclOutput);
retval=command_run_line_internal(active_cmd_ctx, cmd);
+
+ /* we need to be able to get at the retval, so we store in a variable
+ */
+ Jim_Obj *resultvar=Jim_NewIntObj(interp, retval);
+ Jim_IncrRefCount(resultvar);
+ Jim_SetGlobalVariableStr(interp, "openocd_result", resultvar);
+ Jim_DecrRefCount(interp, resultvar);
if (startLoop)
{
Index: C:/workspace/trunk/src/tcl/commands.tcl
===================================================================
--- C:/workspace/trunk/src/tcl/commands.tcl (revision 778)
+++ C:/workspace/trunk/src/tcl/commands.tcl (working copy)
@@ -12,3 +12,47 @@
proc board_test {} {
echo "Production test not implemented"
}
+
+# Show flash in human readable form
+# This is an example of a human readable form of a low level fn
+proc flash_banks_pretty {} {
+ set i 0
+ set result ""
+ foreach {a} [flash_banks] {
+ if {$i > 0} {
+ set result "$result\n"
+ }
+ set result [format "$result#%d: %s at 0x%08x, size 0x%08x,
buswidth %d, chipwidth %d" $i [lindex $a 0] [lindex $a 1] [lindex $a 2] [lindex
$a 3] [lindex $a 4]]
+ set i [expr $i+1]
+ }
+ return $result
+}
+
+# We need to explicitly redirect this to the OpenOCD command
+# as Tcl defines the exit proc
+proc exit {} {
+ openocd_throw exit
+}
+
+# If a fn is unknown to Tcl, we try to execute it as an OpenOCD command
+proc unknown {args} {
+
+ # This is uglier than it needs to be since the "flash banks" is really
+ # a single command. For now only "flash banks" has been converted from
+ # C to Tcl as an example, but if we do decide to go down this path, then
+ # some more generic scheme will be put in place here.
+ #
+ # Help texts need a makeover. There needs to be help texts for
+ # tcl procs + perhaps some work w.r.t. making the help command
+ # format things prettier.
+ if {[string compare [lindex $args 0] flash]==0 && [string compare
[lindex $args 1] banks]==0} {
+ return [flash_banks_pretty]
+ }
+
+ # We print out as we run the command
+ openocd_throw "$args"
+ # The primary return value have been set by "openocd" above,
+ # so we need to clear it, lest we print out the output from
+ # the command twice.
+ return ""
+}
\ No newline at end of file
_______________________________________________
Openocd-development mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/openocd-development