This is the mail archive of the ecos-patches@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RedBoot fis_create fix and cursor key editing


On Thu, 2005-09-08 at 06:44 -0600, Gary Thomas wrote:
> On Thu, 2005-09-08 at 13:41 +0100, David Vrabel wrote:
> > Gary Thomas wrote:
> > > On Thu, 2005-09-08 at 12:03 +0200, Stefan Sommerfeld wrote:
> > > 
> > >>I also added cursor-key support for editing. It's much more comfortable now 
> > >>and should work as before if the terminal doesn't use escape codes.
> > > 
> > > Nice :-)  This reminded me of some stuff I had done in this area
> > > (that slipped away and was not contributed), so I'll merge in my
> > > version which is a bit more complete along with documentation, etc.
> > 
> > Which terminal type are you assuming?
> 
> Standard ANSI cursor keys

To be more complete - my changes are pretty much the same as those
suggested by Stefan, they just include more keyboard characters and
the code is a little cleaner (easier to extend, etc).  I also made
it configurable so you don't need the extra code in there if you
don't want it. [the eCos philosophy!]

Full patch of what was committed is attached.

-- 
------------------------------------------------------------
Gary Thomas                 |  Consulting for the
MLB Associates              |    Embedded world
------------------------------------------------------------
Index: redboot/current/ChangeLog
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/ChangeLog,v
retrieving revision 1.233
retrieving revision 1.234
diff -u -5 -p -r1.233 -r1.234
--- redboot/current/ChangeLog	3 Sep 2005 13:35:08 -0000	1.233
+++ redboot/current/ChangeLog	8 Sep 2005 12:14:28 -0000	1.234
@@ -1,5 +1,17 @@
+2005-09-08  Gary Thomas  <gary@mlbassoc.com>
+
+	* src/io.c: 
+	* include/redboot.h: 
+	* doc/redboot.sgml: 
+	* cdl/redboot.cdl: Add support for ANSI keyboard cursor keys
+	such as HOME/END/Arrows
+
+2005-09-08  Stefan Sommerfeld  <sommerfeld@mikrom.com>
+	* src/flash.c: Fix usage of "fis create", more arguments are optional
+	Set mem_base to mem_addr instead of flash_addr for a loaded image
+	
 2005-09-03  Andrew Lunn  <andrew.lunn@ascom.ch>
 
 	* cdl/redboot.cdl: White space changes to aid readability. 
 
 2005-09-03  Isaac Claymore   <iclaymore@gmail.com>
Index: redboot/current/cdl/redboot.cdl
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/cdl/redboot.cdl,v
retrieving revision 1.72
retrieving revision 1.73
diff -u -5 -p -r1.72 -r1.73
--- redboot/current/cdl/redboot.cdl	3 Sep 2005 13:35:10 -0000	1.72
+++ redboot/current/cdl/redboot.cdl	8 Sep 2005 12:14:29 -0000	1.73
@@ -7,11 +7,11 @@
 # ====================================================================
 #####ECOSGPLCOPYRIGHTBEGIN####
 ## -------------------------------------------
 ## This file is part of eCos, the Embedded Configurable Operating System.
 ## Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
-## Copyright (C) 2002, 2003, 2004 Gary Thomas
+## Copyright (C) 2002, 2003, 2004, 2005 Gary Thomas
 ##
 ## eCos 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 or (at your option) any later version.
 ##
@@ -151,10 +151,20 @@ cdl_package CYGPKG_REDBOOT {
                last N command lines.  These lines may be reused.
                Enabling this history will also enable rudimentary
                editting of the lines themselves."
         }
 
+        cdl_option CYGSEM_REDBOOT_CMD_LINE_ANSI_SEQUENCES {
+            display          "Enable command line editing using ANSI arrows, etc"
+            flavor           bool
+            default_value    1
+            active_if        CYGNUM_REDBOOT_CMD_LINE_EDITING != 0
+            description      "
+               If this option is enabled, RedBoot will accept standard ANSI key
+               sequences for cursor movement (along with the emacs style keys)."
+        }
+
         cdl_option CYGBLD_REDBOOT_CMD_LINE_HISTORY {
             display        "Enable history command and expansion"
             requires       { CYGNUM_REDBOOT_CMD_LINE_EDITING > 0 }
             flavor         bool
             default_value  1
@@ -308,11 +318,11 @@ cdl_package CYGPKG_REDBOOT {
         compile -library=libextras.a load.c
 
         make -priority 320 {
             <PREFIX>/bin/redboot.elf : $(PREFIX)/lib/target.ld $(PREFIX)/lib/vectors.o $(PREFIX)/lib/libtarget.a $(PREFIX)/lib/libextras.a
                     @sh -c "mkdir -p $(dir $@)"
-                    $(CC) -c $(INCLUDE_PATH) $(CFLAGS) -o $(PREFIX)/lib/version.o $(REPOSITORY)/$(PACKAGE)/src/version.c
+                    $(CC) -c $(INCLUDE_PATH) $(ACTUAL_CFLAGS) -o $(PREFIX)/lib/version.o $(REPOSITORY)/$(PACKAGE)/src/version.c
                     $(CC) $(LDFLAGS) -L$(PREFIX)/lib -Ttarget.ld -o $@ $(PREFIX)/lib/version.o
         }
 
         cdl_component CYGPKG_REDBOOT_NETWORKING {
             display       "Redboot Networking"
Index: redboot/current/doc/redboot.sgml
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/doc/redboot.sgml,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -5 -p -r1.9 -r1.10
--- redboot/current/doc/redboot.sgml	19 Apr 2004 15:27:37 -0000	1.9
+++ redboot/current/doc/redboot.sgml	8 Sep 2005 12:14:30 -0000	1.10
@@ -159,42 +159,42 @@ by typing the letter &ldquo;A&rdquo; whi
 <listitem><para><guibutton>Delete</guibutton> (0x7F) or 
 <guibutton>Backspace</guibutton> (0x08) 
 erases the character to the left of the cursor.
 </para></listitem>
 <listitem><para>
-<guibutton>^A</guibutton>
+<guibutton>^A</guibutton> or <guibutton>HOME</guibutton>
 moves the cursor (insertion point) to the beginning of the line.
 </para></listitem>
 <listitem><para>
 <guibutton>^K</guibutton>
 erases all characters on the line from the cursor to the end.
 </para></listitem>
 <listitem><para>
-<guibutton>^E</guibutton>
+<guibutton>^E</guibutton> or <guibutton>END</guibutton>
 positions the cursor to the end of the line.
 </para></listitem>
 <listitem><para>
-<guibutton>^D</guibutton>
+<guibutton>^D</guibutton> or <guibutton>DELETE</guibutton>
 erases the character under the cursor.
 </para></listitem>
 <listitem><para>
-<guibutton>^F</guibutton>
+<guibutton>^F</guibutton> or <guibutton>RIGHT-ARROW</guibutton>
 moves the cursor one character to the right.
 </para></listitem>
 <listitem><para>
-<guibutton>^B</guibutton>
+<guibutton>^B</guibutton> or <guibutton>LEFT-ARROW</guibutton>
 moves the cursor one character to the left.
 </para></listitem>
 <listitem><para>
-<guibutton>^P</guibutton>
+<guibutton>^P</guibutton> or <guibutton>UP-ARROW</guibutton>
 replaces the current line by a previous line from the history buffer.  
 A small number of lines
 can be kept as history.  Using ^P (and ^N), the current line can be replaced
 by any one of the previously typed lines.
 </para></listitem>
 <listitem><para>
-<guibutton>^N</guibutton>
+<guibutton>^N</guibutton> or <guibutton>DOWN-ARROW</guibutton>
 replaces the current line by the next line from the history buffer.  
 </para></listitem>
 </itemizedlist></para>
 <para>In the case of the <command>fconfig</command>
 command, additional editing commands are possible. 
Index: redboot/current/include/redboot.h
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/include/redboot.h,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -5 -p -r1.34 -r1.35
--- redboot/current/include/redboot.h	1 Sep 2004 21:21:30 -0000	1.34
+++ redboot/current/include/redboot.h	8 Sep 2005 12:14:31 -0000	1.35
@@ -7,11 +7,11 @@
 //==========================================================================
 //####ECOSGPLCOPYRIGHTBEGIN####
 // -------------------------------------------
 // This file is part of eCos, the Embedded Configurable Operating System.
 // Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004 Red Hat, Inc.
-// Copyright (C) 2002, 2003, 2004 Gary Thomas
+// Copyright (C) 2002, 2003, 2004, 2005 Gary Thomas
 //
 // eCos 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 or (at your option) any later version.
 //
@@ -133,10 +133,12 @@ EXTERN void cyg_plf_redboot_startup(void
 typedef int _printf_fun(const char *fmt, ...);
 externC int  strcasecmp(const char *s1, const char *s2);
 externC int  strncasecmp(const char *s1, const char *s2, size_t len);
 
 externC void mon_write_char(char c);
+externC bool mon_read_char_with_timeout(char *c);
+externC void mon_set_read_char_timeout(int ms);
 externC bool verify_action(char *fmt, ...);
 externC bool verify_action_with_timeout(int timeout, char *fmt, ...);
 
 // Read a single line of input from the console, possibly with timeout
 externC int  _rb_gets(char *line, int len, int timeout);
Index: redboot/current/src/flash.c
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/src/flash.c,v
retrieving revision 1.75
retrieving revision 1.76
diff -u -5 -p -r1.75 -r1.76
--- redboot/current/src/flash.c	3 Sep 2005 13:10:22 -0000	1.75
+++ redboot/current/src/flash.c	8 Sep 2005 12:14:33 -0000	1.76
@@ -111,11 +111,11 @@ local_cmd_entry("load",
                 fis_load,
                 FIS_cmds
     );
 local_cmd_entry("create",
                 "Create an image",
-                "-b <mem_base> -l <image_length> [-s <data_length>]\n"
+                "[-b <mem_base>] [-l <image_length>] [-s <data_length>]\n"
                 "      [-f <flash_addr>] [-e <entry_point>] [-r <ram_addr>] [-n] <name>",
                 fis_create,
                 FIS_cmds
     );
 #endif
@@ -938,11 +938,11 @@ fis_create(int argc, char *argv[])
     if (prog_ok) {
         // Update directory
         memset(img, 0, sizeof(*img));
         strcpy(img->name, name);
         img->flash_base = flash_addr;
-        img->mem_base = exec_addr_set ? exec_addr : (flash_addr_set ? flash_addr : mem_addr);
+        img->mem_base = exec_addr_set ? exec_addr : (mem_addr_set ? mem_addr : flash_addr);
         img->entry_point = entry_addr_set ? entry_addr : (CYG_ADDRESS)entry_address;  // Hope it's been set
         img->size = length;
         img->data_length = img_size;
 #ifdef CYGSEM_REDBOOT_FIS_CRC_CHECK
         if (!no_copy) {
Index: redboot/current/src/io.c
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/src/io.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -5 -p -r1.32 -r1.33
--- redboot/current/src/io.c	5 Dec 2003 12:51:55 -0000	1.32
+++ redboot/current/src/io.c	8 Sep 2005 12:14:34 -0000	1.33
@@ -7,11 +7,11 @@
 //==========================================================================
 //####ECOSGPLCOPYRIGHTBEGIN####
 // -------------------------------------------
 // This file is part of eCos, the Embedded Configurable Operating System.
 // Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc.
-// Copyright (C) 2002, 2003 Gary Thomas
+// Copyright (C) 2002, 2003, 2005 Gary Thomas
 //
 // eCos 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 or (at your option) any later version.
 //
@@ -162,11 +162,11 @@ mon_read_char(char *c)
 
 #ifdef CYGPKG_REDBOOT_ANY_CONSOLE
 static int _mon_timeout;
 #endif
 
-static bool
+bool
 mon_read_char_with_timeout(char *c)
 {
     bool res = false;
     hal_virtual_comm_table_t *__chan;
 
@@ -214,11 +214,11 @@ mon_read_char_with_timeout(char *c)
         }
     }
     return res;
 }
 
-static void
+void
 mon_set_read_char_timeout(int ms)
 {
     hal_virtual_comm_table_t *__chan;
 
 #ifdef CYGPKG_REDBOOT_ANY_CONSOLE
@@ -337,10 +337,18 @@ static void expand_history(char *);
 //    ^N - Select next line from history
 //    ^A - Move insertion [cursor] to start of line
 //    ^E - Move cursor to end of line
 //    ^B - Move cursor back [previous character]
 //    ^F - Move cursor forward [next character]
+// "standard" arrow keys work as well
+//   left  ^[[D      == ^B
+//   right ^[[C      == ^F
+//   up    ^[[A      == ^P
+//   down  ^[[B      == ^N
+//   home  ^[[H/^[1~ == ^A
+//   end   ^[[F/^[OF == ^E
+//   del   ^[3~      == ^D
 //
 int
 _rb_gets_preloaded(char *buf, int buflen, int timeout)
 {
     char *ip = buf;   // Insertion point
@@ -348,12 +356,16 @@ _rb_gets_preloaded(char *buf, int buflen
     char c;
     bool res = false;
     static char last_ch = '\0';
     int _timeout;
 #if CYGNUM_REDBOOT_CMD_LINE_EDITING != 0
-    int _index = _cl_index;  // Last saved line
+    int   _index = _cl_index;  // Last saved line
     char *xp;
+#ifdef CYGSEM_REDBOOT_CMD_LINE_ANSI_SEQUENCES
+    int   ansi_state = 0;      // Used to drive ANSI parser
+    char  ansi_char = '\0';
+#endif
 #endif
 
     // Display current buffer data
     while (*eol) {
         mon_write_char(*eol++);
@@ -385,12 +397,91 @@ _rb_gets_preloaded(char *buf, int buflen
             }
         } else {
             mon_read_char(&c);
         }
         *eol = '\0';
-        switch (c) {
 #define CTRL(c) ((c)&0x1F)
+#ifdef CYGSEM_REDBOOT_CMD_LINE_ANSI_SEQUENCES
+        // Special handling of ANSI keyboard sequences (arrows, etc)
+        if (c == 0x1B) {
+            // Leadin for ANSI keyboard sequence
+            ansi_state = 1;
+            continue;
+        }
+        switch (ansi_state) {
+        case 0:
+            // No ANSI sequence in progress
+            break;
+        case 1:
+            // ESC seen, look for '['
+            if (c == '[') {
+                ansi_state = 2;
+            } else if (c == 'O') {
+                ansi_state = 4;
+            } else {
+                // Handle bad sequences?
+                ansi_state = 0;
+            }
+            continue;
+        case 2:
+            // ESC+[ seen, process key
+            ansi_state = 0;
+            switch (c) {
+            case 'A':
+                c = CTRL('P');
+                break;
+            case 'B':
+                c = CTRL('N');
+                break;
+            case 'C':
+                c = CTRL('F');
+                break;
+            case 'D':
+                c = CTRL('B');
+                break;
+            case 'F':
+                c = CTRL('E');
+                break;
+            case 'H':
+                c = CTRL('A');
+                break;
+            case '1':
+                ansi_char = CTRL('A');
+                ansi_state = 3;
+                continue;
+            case '3':
+                ansi_char = CTRL('D');
+                ansi_state = 3;
+                continue;
+            default:
+                // Handle bad sequences?
+                continue;
+            }
+            break;
+        case 3:
+            // Sequences like ^[[1~ == ^H
+            ansi_state = 0;
+            if (c == '~') {
+                c = ansi_char;
+            } else {
+                // Handle bad sequences?
+                continue;
+            }
+            break;
+        case 4:
+            // Sequences like ^[OF == ^E
+            ansi_state = 0;
+            if (c == 'F') {
+                c = CTRL('E');
+            } else {
+                // Handle bad sequences?
+                continue;
+            }
+            break;
+        }
+#endif
+        switch (c) {
 #if CYGNUM_REDBOOT_CMD_LINE_EDITING != 0
         case CTRL('P'):
             // Fetch the previous line into the buffer
             if (_index >= 0) {
                 // Erase the previous line [crude]

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]