]> git.karo-electronics.de Git - karo-tx-redboot.git/blobdiff - packages/redboot/v2_0/src/main.c
TX51 pre-release
[karo-tx-redboot.git] / packages / redboot / v2_0 / src / main.c
index 9f1b3d8aa0a95b5f36a9ab9354eb0fa97682f27d..04d7cdf4cf7971c475d4fca9e5502e6a360f6e82 100644 (file)
@@ -42,9 +42,9 @@
 // Author(s):    gthomas
 // Contributors: gthomas, tkoeller, eCosCentric
 // Date:         2000-07-14
-// Purpose:      
-// Description:  
-//              
+// Purpose:
+// Description:
+//
 // This code is part of RedBoot (tm).
 //
 //####DESCRIPTIONEND####
 #include CYGHWR_MEMORY_LAYOUT_H
 
 #ifdef CYGPKG_IO_ETH_DRIVERS
-#include <cyg/io/eth/eth_drv.h>            // Logical driver interfaces
+#include <cyg/io/eth/eth_drv.h>                           // Logical driver interfaces
 #endif
 
 #include <cyg/hal/hal_tables.h>
-#include <cyg/infra/cyg_ass.h>         // assertion macros
+#include <cyg/infra/cyg_ass.h>            // assertion macros
 #include <cyg/infra/cyg_type.h>
 #ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
 #ifdef CYGBLD_HAL_PLATFORM_STUB_H
@@ -87,48 +87,48 @@ static void return_to_redboot(int status);
 
 // Address of area where current context is saved before executing
 // trampoline procedure
-static void * saved_context;
+static void *saved_context;
 
 // Status returned after trampoline execution
 static int return_status;
+
 
 // CLI command processing (defined in this file)
-RedBoot_cmd("version", 
-            "Display RedBoot version information",
-            "",
-            do_version
-    );
-RedBoot_cmd("help", 
-            "Help about help?", 
-            "[<topic>]",
-            do_help 
-    );
+RedBoot_cmd("version",
+                       "Display RedBoot version information",
+                       "",
+                       do_version
+       );
+RedBoot_cmd("help",
+                       "Help about help?",
+                       "[<topic>]",
+                       do_help
+       );
 
 static char go_usage[] = "[-w <timeout>] [-c] "
 #ifdef CYGPKG_IO_ETH_DRIVERS
-                      "[-n] "
+       "[-n] "
 #endif
-                      "[entry]";
+       "[entry]";
 
-RedBoot_cmd("go", 
-            "Execute code at a location", 
-            go_usage,
-            do_go 
-    );
+RedBoot_cmd("go",
+                       "Execute code at a location",
+                       go_usage,
+                       do_go
+       );
 #ifdef HAL_PLATFORM_RESET
-RedBoot_cmd("reset", 
-            "Reset the system", 
-            "",
-            do_reset 
-    );
+RedBoot_cmd("reset",
+                       "Reset the system",
+                       "",
+                       do_reset
+       );
 #endif
 #ifdef CYGSEM_REDBOOT_VARIABLE_BAUD_RATE
-RedBoot_cmd("baudrate", 
-            "Set/Query the system console baud rate", 
-            "[-b <rate>]",
-            do_baud_rate
-    );
+RedBoot_cmd("baudrate",
+                       "Set/Query the system console baud rate",
+                       "[-b <rate>]",
+                       do_baud_rate
+       );
 #endif
 
 // Define table boundaries
@@ -148,13 +148,13 @@ extern struct idle_tab_entry __RedBoot_IDLE_TAB__[], __RedBoot_IDLE_TAB_END__;
 extern void HAL_ARCH_PROGRAM_NEW_STACK(void *fun);
 #endif
 
-// 
+//
 // [Null] Builtin [Power On] Self Test
 //
 void bist(void) CYGBLD_ATTRIB_WEAK;
 
 void
-bist(void) 
+bist(void)
 {
 }
 
@@ -165,33 +165,33 @@ void
 do_version(int argc, char *argv[])
 {
 #if CYGBLD_REDBOOT_MAX_MEM_SEGMENTS > 1
-    int seg;
+       int seg;
 #endif
 #ifdef CYGPKG_REDBOOT_FLASH
-    externC void _flash_info(void);
+       externC void _flash_info(void);
 #endif
-    char *version = CYGACC_CALL_IF_MONITOR_VERSION();
+       char *version = CYGACC_CALL_IF_MONITOR_VERSION();
 
-    diag_printf(version);
+       diag_printf(version);
 #ifdef HAL_PLATFORM_CPU
-    diag_printf("Platform: %s (%s) %s\n", HAL_PLATFORM_BOARD, HAL_PLATFORM_CPU, HAL_PLATFORM_EXTRA);
+       diag_printf("Platform: %s (%s) %s\n", HAL_PLATFORM_BOARD, HAL_PLATFORM_CPU, HAL_PLATFORM_EXTRA);
 #endif
-    diag_printf("Copyright (C) 2000, 2001, 2002, 2003, 2004 Red Hat, Inc.\n");
-    diag_printf("Copyright (C) 2003, 2004, 2005, 2006 eCosCentric Limited\n\n");
-    diag_printf("RAM: %p-%p, ", (void*)ram_start, (void*)ram_end);
-    diag_printf("[%p-%p]", mem_segments[0].start, mem_segments[0].end);
-    diag_printf(" available\n");
+       diag_printf("Copyright (C) 2000, 2001, 2002, 2003, 2004 Red Hat, Inc.\n");
+       diag_printf("Copyright (C) 2003, 2004, 2005, 2006 eCosCentric Limited\n\n");
+       diag_printf("RAM: %p-%p, ", (void*)ram_start, (void*)ram_end);
+       diag_printf("[%p-%p]", mem_segments[0].start, mem_segments[0].end);
+       diag_printf(" available\n");
 #if CYGBLD_REDBOOT_MAX_MEM_SEGMENTS > 1
-    for (seg = 1;  seg < CYGBLD_REDBOOT_MAX_MEM_SEGMENTS;  seg++) {
-        if (mem_segments[seg].start != NO_MEMORY) {
-            diag_printf("     %p-%p, ", mem_segments[seg].start, mem_segments[seg].end);
-            diag_printf("[%p-%p]", mem_segments[seg].start, mem_segments[seg].end);
-            diag_printf(" available\n");
-        }
-    }
+       for (seg = 1;  seg < CYGBLD_REDBOOT_MAX_MEM_SEGMENTS;  seg++) {
+               if (mem_segments[seg].start != NO_MEMORY) {
+                       diag_printf("     %p-%p, ", mem_segments[seg].start, mem_segments[seg].end);
+                       diag_printf("[%p-%p]", mem_segments[seg].start, mem_segments[seg].end);
+                       diag_printf(" available\n");
+               }
+       }
 #endif
 #ifdef CYGPKG_REDBOOT_FLASH
-    _flash_info();
+       _flash_info();
 #endif
 }
 
@@ -203,22 +203,22 @@ do_version(int argc, char *argv[])
 void
 do_idle(bool is_idle)
 {
-    struct idle_tab_entry *idle_entry;
+       struct idle_tab_entry *idle_entry;
 
-    for (idle_entry = __RedBoot_IDLE_TAB__; 
-         idle_entry != &__RedBoot_IDLE_TAB_END__;  idle_entry++) {
-        (*idle_entry->fun)(is_idle);
-    }
+       for (idle_entry = __RedBoot_IDLE_TAB__;
+                idle_entry != &__RedBoot_IDLE_TAB_END__;  idle_entry++) {
+               (*idle_entry->fun)(is_idle);
+       }
 }
 
 // Wrapper used by diag_printf()
 static void
 _mon_write_char(char c, void *param)
 {
-    if (c == '\n') {
-        mon_write_char('\r');
-    }
-    mon_write_char(c);
+       if (c == '\n') {
+               mon_write_char('\r');
+       }
+       mon_write_char(c);
 }
 
 //
@@ -226,11 +226,11 @@ _mon_write_char(char c, void *param)
 //
 static hal_jmp_buf error_jmpbuf;
 #ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
-__externC voidvolatile __mem_fault_handler;
+__externC void *volatile __mem_fault_handler;
 
 static void error_handler(void)
 {
-    hal_longjmp(error_jmpbuf, 1);
+       hal_longjmp(error_jmpbuf, 1);
 }
 #endif
 
@@ -242,392 +242,392 @@ static void error_handler(void)
 void
 cyg_start(void)
 {
-    int res = 0;
-    bool prompt = true;
-    static char line[CYGPKG_REDBOOT_MAX_CMD_LINE];
-    char *command;
-    struct cmd *cmd;
-    int cur;
-    struct init_tab_entry *init_entry;
-    extern char RedBoot_version[];
+       int res = 0;
+       bool prompt = true;
+       static char line[CYGPKG_REDBOOT_MAX_CMD_LINE];
+       char *command;
+       struct cmd *cmd;
+       int cur;
+       struct init_tab_entry *init_entry;
+       extern char RedBoot_version[];
 #if CYGBLD_REDBOOT_MAX_MEM_SEGMENTS > 1
-    int seg;
+       int seg;
 #endif
 
-    // Export version information
-    CYGACC_CALL_IF_MONITOR_VERSION_SET(RedBoot_version);
+       // Export version information
+       CYGACC_CALL_IF_MONITOR_VERSION_SET(RedBoot_version);
 
-    CYGACC_CALL_IF_MONITOR_RETURN_SET(return_to_redboot);
+       CYGACC_CALL_IF_MONITOR_RETURN_SET(return_to_redboot);
 
-    // Make sure the channels are properly initialized.
-    diag_init_putc(_mon_write_char);
-    hal_if_diag_init();
+       // Make sure the channels are properly initialized.
+       diag_init_putc(_mon_write_char);
+       hal_if_diag_init();
 
-    // Force console to output raw text - but remember the old setting
-    // so it can be restored if interaction with a debugger is
-    // required.
-    cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
-    CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_HAL_VIRTUAL_VECTOR_DEBUG_CHANNEL);
+       // Force console to output raw text - but remember the old setting
+       // so it can be restored if interaction with a debugger is
+       // required.
+       cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
+       CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_HAL_VIRTUAL_VECTOR_DEBUG_CHANNEL);
 #ifdef CYGPKG_REDBOOT_ANY_CONSOLE
-    console_selected = false;
+       console_selected = false;
 #endif
-    console_echo = true;
+       console_echo = true;
 
-    ram_start = (unsigned char *)CYGMEM_REGION_ram;
-    ram_end = (unsigned char *)(CYGMEM_REGION_ram+CYGMEM_REGION_ram_SIZE);
+       ram_start = (unsigned char *)CYGMEM_REGION_ram;
+       ram_end = (unsigned char *)(CYGMEM_REGION_ram+CYGMEM_REGION_ram_SIZE);
 #ifdef HAL_MEM_REAL_REGION_TOP
-    {
-        unsigned char *ram_end_tmp = ram_end;
-        ram_end = HAL_MEM_REAL_REGION_TOP( ram_end_tmp );
-    }
+       {
+               unsigned char *ram_end_tmp = ram_end;
+               ram_end = HAL_MEM_REAL_REGION_TOP( ram_end_tmp );
+       }
 #endif
 #ifdef CYGMEM_SECTION_heap1
-    workspace_start = (unsigned char *)CYGMEM_SECTION_heap1;
-    workspace_end = (unsigned char *)(CYGMEM_SECTION_heap1+CYGMEM_SECTION_heap1_SIZE);
+       workspace_start = (unsigned char *)CYGMEM_SECTION_heap1;
+       workspace_end = (unsigned char *)(CYGMEM_SECTION_heap1+CYGMEM_SECTION_heap1_SIZE);
 #else
-    workspace_start = (unsigned char *)CYGMEM_REGION_ram;
-    workspace_end = (unsigned char *)(CYGMEM_REGION_ram+CYGMEM_REGION_ram_SIZE);
+       workspace_start = (unsigned char *)CYGMEM_REGION_ram;
+       workspace_end = (unsigned char *)(CYGMEM_REGION_ram+CYGMEM_REGION_ram_SIZE);
 #endif
 
-    if (ram_end < workspace_end) {
-        // when *less* SDRAM is installed than the possible maximum,
-        // but the heap1 region remains greater...
-        workspace_end = ram_end;
-    }
+       if (ram_end < workspace_end) {
+               // when *less* SDRAM is installed than the possible maximum,
+               // but the heap1 region remains greater...
+               workspace_end = ram_end;
+       }
 
-    workspace_end_init=workspace_end;
+       workspace_end_init = workspace_end;
 
-    // Nothing has ever been loaded into memory
-    entry_address = (unsigned long)NO_MEMORY;
+       // Nothing has ever been loaded into memory
+       entry_address = (unsigned long)NO_MEMORY;
 
-    bist();
+       bist();
 
 #if defined(CYGPRI_REDBOOT_ZLIB_FLASH) && defined(CYGOPT_REDBOOT_FIS_ZLIB_COMMON_BUFFER)
-    fis_zlib_common_buffer =
-    workspace_end -= CYGNUM_REDBOOT_FIS_ZLIB_COMMON_BUFFER_SIZE;
+       fis_zlib_common_buffer =
+               workspace_end -= CYGNUM_REDBOOT_FIS_ZLIB_COMMON_BUFFER_SIZE;
 #endif
 
 #ifdef CYGFUN_REDBOOT_BOOT_SCRIPT
-    script_timeout = CYGNUM_REDBOOT_BOOT_SCRIPT_DEFAULT_TIMEOUT;
+       script_timeout = CYGNUM_REDBOOT_BOOT_SCRIPT_DEFAULT_TIMEOUT;
 #endif
 
-    for (init_entry = __RedBoot_INIT_TAB__; init_entry != &__RedBoot_INIT_TAB_END__; init_entry++) {
-        (*init_entry->fun)();
-    }
+       for (init_entry = __RedBoot_INIT_TAB__; init_entry != &__RedBoot_INIT_TAB_END__; init_entry++) {
+               (*init_entry->fun)();
+       }
 
-    mem_segments[0].start = workspace_start;
-    mem_segments[0].end = workspace_end;
+       mem_segments[0].start = workspace_start;
+       mem_segments[0].end = workspace_end;
 #if CYGBLD_REDBOOT_MAX_MEM_SEGMENTS > 1
-    for (seg = 1;  seg < CYGBLD_REDBOOT_MAX_MEM_SEGMENTS;  seg++) {
-        cyg_plf_memory_segment(seg, &mem_segments[seg].start, &mem_segments[seg].end);
-    }
+       for (seg = 1;  seg < CYGBLD_REDBOOT_MAX_MEM_SEGMENTS;  seg++) {
+               cyg_plf_memory_segment(seg, &mem_segments[seg].start, &mem_segments[seg].end);
+       }
 #endif
 
 #ifdef CYGSEM_REDBOOT_PLF_STARTUP
 
-    cyg_plf_redboot_startup();
+       cyg_plf_redboot_startup();
 #endif
-    do_version(0,0);
+       do_version(0, 0);
 
 #ifdef CYGFUN_REDBOOT_BOOT_SCRIPT
 # ifdef CYGDAT_REDBOOT_DEFAULT_BOOT_SCRIPT
-    if (!script) {
-       script = CYGDAT_REDBOOT_DEFAULT_BOOT_SCRIPT;
-    }
-# endif
-    if (script) {
-       // Give the guy a chance to abort any boot script
-       unsigned char *hold_script = script;
-       int script_timeout_ms = script_timeout * CYGNUM_REDBOOT_BOOT_SCRIPT_TIMEOUT_RESOLUTION;
-       diag_printf("== Executing boot script in %d.%03d seconds - enter ^C to abort\n", 
-                   script_timeout_ms / 1000, script_timeout_ms % 1000);
-       script = NULL;
-       res = _GETS_CTRLC;  // Treat 0 timeout as ^C
-       while (script_timeout_ms >= CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT) {
-           res = _rb_gets(line, sizeof(line), CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT);
-           if (res >= _GETS_OK) {
-               diag_printf("== Executing boot script in %d.%03d seconds - enter ^C to abort\n", 
-                           script_timeout_ms / 1000, script_timeout_ms % 1000);
-           } else if (res != _GETS_TIMEOUT) {
-               break;
-           }
-           script_timeout_ms -= CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT;
+       if (!script) {
+               script = CYGDAT_REDBOOT_DEFAULT_BOOT_SCRIPT;
        }
-       if (res == _GETS_CTRLC) {
-           script = NULL;  // Disable script
-       } else {
-           script = hold_script;  // Re-enable script
+# endif
+       if (script) {
+               // Give the guy a chance to abort any boot script
+               unsigned char *hold_script = script;
+               int script_timeout_ms = script_timeout * CYGNUM_REDBOOT_BOOT_SCRIPT_TIMEOUT_RESOLUTION;
+               diag_printf("== Executing boot script in %d.%03d seconds - enter ^C to abort\n",
+                                       script_timeout_ms / 1000, script_timeout_ms % 1000);
+               script = NULL;
+               res = _GETS_CTRLC;  // Treat 0 timeout as ^C
+               while (script_timeout_ms >= CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT) {
+                       res = _rb_gets(line, sizeof(line), CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT);
+                       if (res >= _GETS_OK) {
+                               diag_printf("== Executing boot script in %d.%03d seconds - enter ^C to abort\n",
+                                                       script_timeout_ms / 1000, script_timeout_ms % 1000);
+                       } else if (res != _GETS_TIMEOUT) {
+                               break;
+                       }
+                       script_timeout_ms -= CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT;
+               }
+               if (res == _GETS_CTRLC) {
+                       script = NULL;  // Disable script
+               } else {
+                       script = hold_script;  // Re-enable script
+               }
        }
-    }
-#endif
-    CYG_ASSERT(workspace_start < workspace_end, 
-               "negative workspace size");
-    while (true) {
-        if (prompt) {
-            diag_printf("RedBoot> ");
-            prompt = false;
-        }
+#endif
+       CYG_ASSERT(workspace_start < workspace_end,
+                       "negative workspace size");
+       while (true) {
+               if (prompt) {
+                       diag_printf("RedBoot> ");
+                       prompt = false;
+               }
 #if CYGNUM_REDBOOT_CMD_LINE_EDITING != 0
-        cmd_history = true;  // Enable history collection
+               cmd_history = true;  // Enable history collection
 #endif
-        res = _rb_gets(line, sizeof(line), CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT);
+               res = _rb_gets(line, sizeof(line), CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT);
 #if CYGNUM_REDBOOT_CMD_LINE_EDITING != 0
-        cmd_history = false;  // Enable history collection
+               cmd_history = false;  // Enable history collection
 #endif
-        if (res == _GETS_TIMEOUT) {
-            // No input arrived
-        } else {
+               if (res == _GETS_TIMEOUT) {
+                       // No input arrived
+               } else {
 #ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
-            if (res == _GETS_GDB) {
-               int dbgchan;
-                hal_virtual_comm_table_t *__chan;
-                int i;
-                // Special case of '$' - need to start GDB protocol
-                gdb_active = true;
-                // Mask interrupts on all channels
-                for (i = 0;  i < CYGNUM_HAL_VIRTUAL_VECTOR_NUM_CHANNELS;  i++) {
-                    CYGACC_CALL_IF_SET_CONSOLE_COMM(i);
-                    __chan = CYGACC_CALL_IF_CONSOLE_PROCS();
-                    CYGACC_COMM_IF_CONTROL( *__chan, __COMMCTL_IRQ_DISABLE );
-                }
-    
-                CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
-
-                // set up a temporary context that will take us to the trampoline
-                HAL_THREAD_INIT_CONTEXT(workspace_end,
-                                        breakpoint, trampoline,0);
-
-                // switch context to trampoline (get GDB stubs started)
-                HAL_THREAD_SWITCH_CONTEXT(&saved_context, &workspace_end);
-
-                gdb_active = false;
-
-               dbgchan = CYGACC_CALL_IF_SET_DEBUG_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
-               CYGACC_CALL_IF_SET_CONSOLE_COMM(dbgchan);
-            } else 
+                       if (res == _GETS_GDB) {
+                               int dbgchan;
+                               hal_virtual_comm_table_t *__chan;
+                               int i;
+                               // Special case of '$' - need to start GDB protocol
+                               gdb_active = true;
+                               // Mask interrupts on all channels
+                               for (i = 0;  i < CYGNUM_HAL_VIRTUAL_VECTOR_NUM_CHANNELS;  i++) {
+                                       CYGACC_CALL_IF_SET_CONSOLE_COMM(i);
+                                       __chan = CYGACC_CALL_IF_CONSOLE_PROCS();
+                                       CYGACC_COMM_IF_CONTROL( *__chan, __COMMCTL_IRQ_DISABLE );
+                               }
+
+                               CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
+
+                               // set up a temporary context that will take us to the trampoline
+                               HAL_THREAD_INIT_CONTEXT(workspace_end,
+                                                                               breakpoint, trampoline,0);
+
+                               // switch context to trampoline (get GDB stubs started)
+                               HAL_THREAD_SWITCH_CONTEXT(&saved_context, &workspace_end);
+
+                               gdb_active = false;
+
+                               dbgchan = CYGACC_CALL_IF_SET_DEBUG_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
+                               CYGACC_CALL_IF_SET_CONSOLE_COMM(dbgchan);
+                       } else
 #endif // CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
-            {
-                expand_aliases(line, sizeof(line));
-               command = line;
-                if ((*command == '#') || (*command == '=')) {
-                    // Special cases
-                    if (*command == '=') {
-                        // Print line on console
-                        diag_printf("%s\n", &line[2]);
-                    }
-                } else {
-                    while (strlen(command) > 0) {                    
-                        if ((cmd = parse(&command, &argc, &argv[0])) != NULL) {
-                            // Try to handle aborts - messy because of the stack unwinding...
+                       {
+                               expand_aliases(line, sizeof(line));
+                               command = line;
+                               if ((*command == '#') || (*command == '=')) {
+                                       // Special cases
+                                       if (*command == '=') {
+                                               // Print line on console
+                                               diag_printf("%s\n", &line[2]);
+                                       }
+                               } else {
+                                       while (strlen(command) > 0) {
+                                               if ((cmd = parse(&command, &argc, &argv[0])) != NULL) {
+                                                       // Try to handle aborts - messy because of the stack unwinding...
 #ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
-                            __mem_fault_handler = error_handler;
+                                                       __mem_fault_handler = error_handler;
 #endif
-                            if (hal_setjmp(error_jmpbuf)) {
-                                diag_printf("** command abort - illegal memory access?\n");
-                            } else {
-                                (cmd->fun)(argc, argv);
-                            }
+                                                       if (hal_setjmp(error_jmpbuf)) {
+                                                               diag_printf("** command abort - illegal memory access?\n");
+                                                       } else {
+                                                               (cmd->fun)(argc, argv);
+                                                       }
 #ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
-                            __mem_fault_handler = 0;
-#endif
-                        } else {
-                            diag_printf("** Error: Illegal command: \"%s\"\n", argv[0]);
-                        }
-                    }
-                }
-                prompt = true;
-            }
-        }
-    }
+                                                       __mem_fault_handler = 0;
+#endif
+                                               } else {
+                                                       diag_printf("** Error: Illegal command: \"%s\"\n", argv[0]);
+                                               }
+                                       }
+                               }
+                               prompt = true;
+                       }
+               }
+       }
 }
 
 void
 show_help(struct cmd *cmd, struct cmd *cmd_end, char *which, char *pre)
 {
-    bool show;
-    int len = 0;
-
-    if (which) {
-        len = strlen(which);
-    }
-    while (cmd != cmd_end) {
-        show = true;
-        if (which && (strncasecmp(which, cmd->str, len) != 0)) {
-            show = false;
-        }
-        if (show) {
-            diag_printf("%s\n  %s %s %s\n", cmd->help, pre, cmd->str, cmd->usage);
-            if ((cmd->sub_cmds != NULL) && (which != NULL)) {
-                show_help(cmd->sub_cmds, cmd->sub_cmds_end, 0, cmd->str);
-            }
-        }
-        cmd++;
-    }
+       bool show;
+       int len = 0;
+
+       if (which) {
+               len = strlen(which);
+       }
+       while (cmd != cmd_end) {
+               show = true;
+               if (which && (strncasecmp(which, cmd->str, len) != 0)) {
+                       show = false;
+               }
+               if (show) {
+                       diag_printf("%s\n  %s %s %s\n", cmd->help, pre, cmd->str, cmd->usage);
+                       if ((cmd->sub_cmds != NULL) && (which != NULL)) {
+                               show_help(cmd->sub_cmds, cmd->sub_cmds_end, 0, cmd->str);
+                       }
+               }
+               cmd++;
+       }
 }
 
 void
 do_help(int argc, char *argv[])
 {
-    struct cmd *cmd;
-    char *which = NULL;
-
-    if (!scan_opts(argc, argv, 1, 0, 0, &which, OPTION_ARG_TYPE_STR, "<topic>")) {
-        diag_printf("Invalid argument\n");
-        return;
-    }
-    cmd = __RedBoot_CMD_TAB__;
-    show_help(cmd, &__RedBoot_CMD_TAB_END__, which, "");
-    return;
+       struct cmd *cmd;
+       char *which = NULL;
+
+       if (!scan_opts(argc, argv, 1, NULL, 0, &which, OPTION_ARG_TYPE_STR, "<topic>")) {
+               diag_printf("Invalid argument\n");
+               return;
+       }
+       cmd = __RedBoot_CMD_TAB__;
+       show_help(cmd, &__RedBoot_CMD_TAB_END__, which, "");
+       return;
 }
 
 static void
 trampoline(unsigned long entry)
 {
-    typedef void code_fun(void);
-    code_fun *fun = (code_fun *)entry;
-    unsigned long oldints;
+       typedef void code_fun(void);
+       code_fun *fun = (code_fun *)entry;
+       unsigned long oldints;
 
-    HAL_DISABLE_INTERRUPTS(oldints);
+       HAL_DISABLE_INTERRUPTS(oldints);
 
 #ifdef HAL_ARCH_PROGRAM_NEW_STACK
-    HAL_ARCH_PROGRAM_NEW_STACK(fun);
+       HAL_ARCH_PROGRAM_NEW_STACK(fun);
 #else
-    (*fun)();
+       (*fun)();
 #endif
 
-    HAL_THREAD_LOAD_CONTEXT(&saved_context);
+       HAL_THREAD_LOAD_CONTEXT(&saved_context);
 }
 
 static void
 return_to_redboot(int status)
 {
-    CYGARC_HAL_SAVE_GP();
+       CYGARC_HAL_SAVE_GP();
 
-    return_status = status;
-    HAL_THREAD_LOAD_CONTEXT(&saved_context);
-    // never returns
+       return_status = status;
+       HAL_THREAD_LOAD_CONTEXT(&saved_context);
+       // never returns
 
-    // need this to balance above CYGARC_HAL_SAVE_GP on
-    // some platforms. It will never run, though.
-    CYGARC_HAL_RESTORE_GP();
+       // need this to balance above CYGARC_HAL_SAVE_GP on
+       // some platforms. It will never run, though.
+       CYGARC_HAL_RESTORE_GP();
 }
 
 void
 do_go(int argc, char *argv[])
 {
-    int i, cur, num_options = 0;
-    unsigned long entry;
-    unsigned long oldints;
-    bool wait_time_set;
-    int  wait_time, res;
-    bool cache_enabled = false;
+       int i, cur, num_options = 0;
+       unsigned long entry;
+       unsigned long oldints;
+       bool wait_time_set;
+       int  wait_time, res;
+       bool cache_enabled = false;
 #ifdef CYGPKG_IO_ETH_DRIVERS
-    bool stop_net = false;
+       bool stop_net = false;
 #endif
-    struct option_info opts[3];
-    char line[8];
-    hal_virtual_comm_table_t *__chan;
+       struct option_info opts[3];
+       char line[8];
+       hal_virtual_comm_table_t *__chan;
 
 #ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
-    __mem_fault_handler = 0; // Let GDB handle any faults directly
+       __mem_fault_handler = 0; // Let GDB handle any faults directly
 #endif
-    entry = entry_address;  // Default from last 'load' operation
-    init_opts(&opts[num_options++], 'w', true, OPTION_ARG_TYPE_NUM, 
-              &wait_time, &wait_time_set, "wait timeout");
-    init_opts(&opts[num_options++], 'c', false, OPTION_ARG_TYPE_FLG, 
-              &cache_enabled, NULL, "go with caches enabled");
+       entry = entry_address;  // Default from last 'load' operation
+       init_opts(&opts[num_options++], 'w', true, OPTION_ARG_TYPE_NUM,
+                       &wait_time, &wait_time_set, "wait timeout");
+       init_opts(&opts[num_options++], 'c', false, OPTION_ARG_TYPE_FLG,
+                       &cache_enabled, NULL, "go with caches enabled");
 #ifdef CYGPKG_IO_ETH_DRIVERS
-    init_opts(&opts[num_options++], 'n', false, OPTION_ARG_TYPE_FLG, 
-             &stop_net, NULL, "go with network driver stopped");
-#endif
-
-    CYG_ASSERT(num_options <= NUM_ELEMS(opts), "Too many options");
-
-    if (!scan_opts(argc, argv, 1, opts, num_options, &entry,
-                  OPTION_ARG_TYPE_NUM, "starting address")) {
-        return;
-    }
-    if (entry == (unsigned long)NO_MEMORY) {
-        err_printf("No entry point known - aborted\n");
-        return;
-    }
-    if (wait_time_set) {
-        int script_timeout_ms = wait_time * 1000;
+       init_opts(&opts[num_options++], 'n', false, OPTION_ARG_TYPE_FLG,
+                       &stop_net, NULL, "go with network driver stopped");
+#endif
+
+       CYG_ASSERT(num_options <= NUM_ELEMS(opts), "Too many options");
+
+       if (!scan_opts(argc, argv, 1, opts, num_options, &entry,
+                                       OPTION_ARG_TYPE_NUM, "starting address")) {
+               return;
+       }
+       if (entry == (unsigned long)NO_MEMORY) {
+               err_printf("No entry point known - aborted\n");
+               return;
+       }
+       if (wait_time_set) {
+               int script_timeout_ms = wait_time * 1000;
 #ifdef CYGSEM_REDBOOT_FLASH_CONFIG
-        unsigned char *hold_script = script;
-        script = NULL;
-#endif
-        diag_printf("About to start execution at %p - abort with ^C within %d seconds\n",
-                    (void *)entry, wait_time);
-        while (script_timeout_ms >= CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT) {
-            res = _rb_gets(line, sizeof(line), CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT);
-            if (res == _GETS_CTRLC) {
+               unsigned char *hold_script = script;
+               script = NULL;
+#endif
+               diag_printf("About to start execution at %p - abort with ^C within %d seconds\n",
+                                       (void *)entry, wait_time);
+               while (script_timeout_ms >= CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT) {
+                       res = _rb_gets(line, sizeof(line), CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT);
+                       if (res == _GETS_CTRLC) {
 #ifdef CYGSEM_REDBOOT_FLASH_CONFIG
-                script = hold_script;  // Re-enable script
-#endif
-                return;
-            }
-            script_timeout_ms -= CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT;
-        }
-    }
-
-    // Mask interrupts on all channels
-    cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
-    for (i = 0;  i < CYGNUM_HAL_VIRTUAL_VECTOR_NUM_CHANNELS;  i++) {
-       CYGACC_CALL_IF_SET_CONSOLE_COMM(i);
-       __chan = CYGACC_CALL_IF_CONSOLE_PROCS();
-       CYGACC_COMM_IF_CONTROL( *__chan, __COMMCTL_IRQ_DISABLE );
-    }
-    CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
+                               script = hold_script;  // Re-enable script
+#endif
+                               return;
+                       }
+                       script_timeout_ms -= CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT;
+               }
+       }
 
-    __chan = CYGACC_CALL_IF_CONSOLE_PROCS();
-    CYGACC_COMM_IF_CONTROL(*__chan, __COMMCTL_ENABLE_LINE_FLUSH);
+       // Mask interrupts on all channels
+       cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
+       for (i = 0;  i < CYGNUM_HAL_VIRTUAL_VECTOR_NUM_CHANNELS;  i++) {
+               CYGACC_CALL_IF_SET_CONSOLE_COMM(i);
+               __chan = CYGACC_CALL_IF_CONSOLE_PROCS();
+               CYGACC_COMM_IF_CONTROL( *__chan, __COMMCTL_IRQ_DISABLE );
+       }
+       CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
+
+       __chan = CYGACC_CALL_IF_CONSOLE_PROCS();
+       CYGACC_COMM_IF_CONTROL(*__chan, __COMMCTL_ENABLE_LINE_FLUSH);
 
 #ifdef CYGPKG_IO_ETH_DRIVERS
-    if (stop_net)
-       eth_drv_stop();
-#endif
-       
-    HAL_DISABLE_INTERRUPTS(oldints);
-    HAL_DCACHE_SYNC();
-    if (!cache_enabled) {
-       HAL_ICACHE_DISABLE();
-       HAL_DCACHE_DISABLE();
+       if (stop_net)
+               eth_drv_stop();
+#endif
+
+       HAL_DISABLE_INTERRUPTS(oldints);
        HAL_DCACHE_SYNC();
-    }
-    HAL_ICACHE_INVALIDATE_ALL();
-    HAL_DCACHE_INVALIDATE_ALL();
-    // set up a temporary context that will take us to the trampoline
-    HAL_THREAD_INIT_CONTEXT(workspace_end, 
-                            entry, trampoline, 0);
+       if (!cache_enabled) {
+               HAL_ICACHE_DISABLE();
+               HAL_DCACHE_DISABLE();
+               HAL_DCACHE_SYNC();
+       }
+       HAL_ICACHE_INVALIDATE_ALL();
+       HAL_DCACHE_INVALIDATE_ALL();
+       // set up a temporary context that will take us to the trampoline
+       HAL_THREAD_INIT_CONTEXT(workspace_end,
+                                                       entry, trampoline, 0);
 
-    // switch context to trampoline
-    HAL_THREAD_SWITCH_CONTEXT(&saved_context, &workspace_end);
+       // switch context to trampoline
+       HAL_THREAD_SWITCH_CONTEXT(&saved_context, &workspace_end);
 
-    // we get back here by way of return_to_redboot()
+       // we get back here by way of return_to_redboot()
 
-    // undo the changes we made before switching context
-    if (!cache_enabled) {
-       HAL_ICACHE_ENABLE();
-       HAL_DCACHE_ENABLE();
-    }
+       // undo the changes we made before switching context
+       if (!cache_enabled) {
+               HAL_ICACHE_ENABLE();
+               HAL_DCACHE_ENABLE();
+       }
 
-    CYGACC_COMM_IF_CONTROL(*__chan, __COMMCTL_DISABLE_LINE_FLUSH);
+       CYGACC_COMM_IF_CONTROL(*__chan, __COMMCTL_DISABLE_LINE_FLUSH);
 
-    HAL_RESTORE_INTERRUPTS(oldints);
+       HAL_RESTORE_INTERRUPTS(oldints);
 
-    diag_printf("\nProgram completed with status %d\n", return_status);
+       diag_printf("\nProgram completed with status %d\n", return_status);
 }
 
 #ifdef HAL_PLATFORM_RESET
 void
 do_reset(int argc, char *argv[])
 {
-    diag_printf("... Resetting.");
-    CYGACC_CALL_IF_DELAY_US(2*100000);
-    diag_printf("\n");
-    CYGACC_CALL_IF_RESET();
-    diag_printf("!! oops, RESET not working on this platform\n");
+       diag_printf("... Resetting.");
+       CYGACC_CALL_IF_DELAY_US(2 * 100000);
+       diag_printf("\n");
+       CYGACC_CALL_IF_RESET();
+       diag_printf("!! oops, RESET not working on this platform\n");
 }
 #endif
 
@@ -639,107 +639,107 @@ do_reset(int argc, char *argv[])
 static int
 set_comm_baud_rate(hal_virtual_comm_table_t *chan, int rate)
 {
-    int current_rate;
+       int current_rate;
 
-    current_rate = CYGACC_COMM_IF_CONTROL(*chan, __COMMCTL_GETBAUD);
-    if (rate != current_rate)
-        return CYGACC_COMM_IF_CONTROL(*chan, __COMMCTL_SETBAUD, rate);
+       current_rate = CYGACC_COMM_IF_CONTROL(*chan, __COMMCTL_GETBAUD);
+       if (rate != current_rate)
+               return CYGACC_COMM_IF_CONTROL(*chan, __COMMCTL_SETBAUD, rate);
 
-    return 0;
+       return 0;
 }
 
 int
 set_console_baud_rate(int rate)
 {
-    int ret = -1;
+       int ret = -1;
 #ifdef CYGPKG_REDBOOT_ANY_CONSOLE
-    if (!console_selected) {
-        int cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
-        int i;
-        // Set baud for all channels
-        for (i = 0;  i < CYGNUM_HAL_VIRTUAL_VECTOR_COMM_CHANNELS;  i++) {
-            CYGACC_CALL_IF_SET_CONSOLE_COMM(i);
-           ret = set_comm_baud_rate(CYGACC_CALL_IF_CONSOLE_PROCS(), rate);
-           if (ret < 0)
-               break;
-        }
-        CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
-    } else
-#endif
-    ret = set_comm_baud_rate(CYGACC_CALL_IF_CONSOLE_PROCS(), rate);
-
-    if (ret < 0)
-       diag_printf("Setting console baud rate to %d failed\n", rate);
-
-    return ret;
+       if (!console_selected) {
+               int cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
+               int i;
+               // Set baud for all channels
+               for (i = 0;  i < CYGNUM_HAL_VIRTUAL_VECTOR_COMM_CHANNELS;  i++) {
+                       CYGACC_CALL_IF_SET_CONSOLE_COMM(i);
+                       ret = set_comm_baud_rate(CYGACC_CALL_IF_CONSOLE_PROCS(), rate);
+                       if (ret < 0)
+                               break;
+               }
+               CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
+       } else
+#endif
+               ret = set_comm_baud_rate(CYGACC_CALL_IF_CONSOLE_PROCS(), rate);
+
+       if (ret < 0)
+               diag_printf("Setting console baud rate to %d failed\n", rate);
+
+       return ret;
 }
 
 static void
 _sleep(int ms)
 {
-    int i;
-    for (i = 0;  i < ms;  i++) {
-        CYGACC_CALL_IF_DELAY_US((cyg_int32)1000);
-    }
+       int i;
+       for (i = 0;  i < ms;  i++) {
+               CYGACC_CALL_IF_DELAY_US((cyg_int32)1000);
+       }
 }
 
 void
 do_baud_rate(int argc, char *argv[])
 {
-    int new_rate, ret, old_rate;
-    bool new_rate_set;
-    hal_virtual_comm_table_t *__chan;
-    struct option_info opts[1];
+       int new_rate, ret, old_rate;
+       bool new_rate_set;
+       hal_virtual_comm_table_t *__chan;
+       struct option_info opts[1];
 #ifdef CYGSEM_REDBOOT_FLASH_CONFIG
-    struct config_option opt;
-#endif
-
-    init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM, 
-              &new_rate, &new_rate_set, "new baud rate");
-    if (!scan_opts(argc, argv, 1, opts, 1, 0, 0, "")) {
-        return;
-    }
-    __chan = CYGACC_CALL_IF_CONSOLE_PROCS();
-    if (new_rate_set) {
-        diag_printf("Baud rate will be changed to %d - update your settings\n", new_rate);
-        _sleep(500);  // Give serial time to flush
-        old_rate = CYGACC_COMM_IF_CONTROL(*__chan, __COMMCTL_GETBAUD);
-        ret = set_console_baud_rate(new_rate);
-        if (ret < 0) {
-            if (old_rate > 0) {
-                // Try to restore
-                set_console_baud_rate(old_rate);
-                _sleep(500);  // Give serial time to flush
-                diag_printf("\nret = %d\n", ret);
-            }
-            return;  // Couldn't set the desired rate
-        }
-        // Make sure this new rate works or back off to previous value
-        // Sleep for a few seconds, then prompt to see if it works
-        _sleep(3000);  // Give serial time to flush
-        if (!verify_action_with_timeout(5000, "Baud rate changed to %d", new_rate)) {
-            _sleep(500);  // Give serial time to flush
-            set_console_baud_rate(old_rate);
-            _sleep(500);  // Give serial time to flush
-            return;
-        }
+       struct config_option opt;
+#endif
+
+       init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM,
+                       &new_rate, &new_rate_set, "new baud rate");
+       if (!scan_opts(argc, argv, 1, opts, 1, NULL, 0, "")) {
+               return;
+       }
+       __chan = CYGACC_CALL_IF_CONSOLE_PROCS();
+       if (new_rate_set) {
+               diag_printf("Baud rate will be changed to %d - update your settings\n", new_rate);
+               _sleep(500);  // Give serial time to flush
+               old_rate = CYGACC_COMM_IF_CONTROL(*__chan, __COMMCTL_GETBAUD);
+               ret = set_console_baud_rate(new_rate);
+               if (ret < 0) {
+                       if (old_rate > 0) {
+                               // Try to restore
+                               set_console_baud_rate(old_rate);
+                               _sleep(500);  // Give serial time to flush
+                               diag_printf("\nret = %d\n", ret);
+                       }
+                       return;  // Couldn't set the desired rate
+               }
+               // Make sure this new rate works or back off to previous value
+               // Sleep for a few seconds, then prompt to see if it works
+               _sleep(3000);  // Give serial time to flush
+               if (!verify_action_with_timeout(5000, "Baud rate changed to %d", new_rate)) {
+                       _sleep(500);  // Give serial time to flush
+                       set_console_baud_rate(old_rate);
+                       _sleep(500);  // Give serial time to flush
+                       return;
+               }
 #ifdef CYGSEM_REDBOOT_FLASH_CONFIG
-        opt.type = CONFIG_INT;
-        opt.enable = NULL;
-        opt.enable_sense = 1;
-        opt.key = "console_baud_rate";
-        opt.dflt = new_rate;
-        flash_add_config(&opt, true);
-#endif
-    } else {
-        ret = CYGACC_COMM_IF_CONTROL(*__chan, __COMMCTL_GETBAUD);
-        diag_printf("Baud rate = ");
-        if (ret <= 0) {
-            diag_printf("unknown\n");
-        } else {
-            diag_printf("%d\n", ret);
-        }
-    }
+               opt.type = CONFIG_INT;
+               opt.enable = NULL;
+               opt.enable_sense = 1;
+               opt.key = "console_baud_rate";
+               opt.dflt = new_rate;
+               flash_add_config(&opt, true);
+#endif
+       } else {
+               ret = CYGACC_COMM_IF_CONTROL(*__chan, __COMMCTL_GETBAUD);
+               diag_printf("Baud rate = ");
+               if (ret <= 0) {
+                       diag_printf("unknown\n");
+               } else {
+                       diag_printf("%d\n", ret);
+               }
+       }
 }
 #endif
 
@@ -749,14 +749,14 @@ do_baud_rate(int argc, char *argv[])
 bool
 valid_address(unsigned char *addr)
 {
-    int seg;
-
-    for (seg = 0;  seg < CYGBLD_REDBOOT_MAX_MEM_SEGMENTS;  seg++) {
-        if (mem_segments[seg].start != NO_MEMORY) {
-            if ((addr >= mem_segments[seg].start) && (addr < mem_segments[seg].end)) {
-                return true;
-            }
-        }
-    }
-    return false;
+       int seg;
+
+       for (seg = 0;  seg < CYGBLD_REDBOOT_MAX_MEM_SEGMENTS;  seg++) {
+               if (mem_segments[seg].start != NO_MEMORY) {
+                       if ((addr >= mem_segments[seg].start) && (addr < mem_segments[seg].end)) {
+                               return true;
+                       }
+               }
+       }
+       return false;
 }