- using ERROR_COMMAND_SYNTAX_ERROR to print syntax in a couple of places
authoroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Mon, 25 Feb 2008 07:50:03 +0000 (07:50 +0000)
committeroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Mon, 25 Feb 2008 07:50:03 +0000 (07:50 +0000)
- some more flash cleanup of checking halted state
- moved output handler into options.c
- very slightly tweaked server.c to make it a bit more compatible with eCos
- retired arch_state. Not quite sure how I managed to leave that out last time.

git-svn-id: svn://svn.berlios.de/openocd/trunk@338 b42882b7-edfa-0310-969c-e2dbd0fdcd60

src/flash/at91sam7.c
src/flash/lpc2000.c
src/helper/configuration.c
src/helper/options.c
src/jtag/jtag.c
src/server/server.c
src/server/telnet_server.c
src/target/target.c

index 3e920e3..a9776d4 100644 (file)
@@ -955,8 +955,7 @@ int at91sam7_handle_gpnvm_command(struct command_context_s *cmd_ctx, char *cmd,
        }\r
        else\r
        {\r
-               command_print(cmd_ctx, "usage: at91sam7 gpnvm <num> <bit> <set|clear>");\r
-               return ERROR_OK;\r
+               return ERROR_COMMAND_SYNTAX_ERROR;
        }\r
 \r
        /* Configure the flash controller timing */\r
index da79ea7..009c0c0 100644 (file)
@@ -476,11 +476,6 @@ int lpc2000_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count)
        int i;\r
        working_area_t *download_area;\r
                 \r
-       if (bank->target->state != TARGET_HALTED)\r
-       {\r
-               return ERROR_TARGET_NOT_HALTED;\r
-       }\r
-       \r
        /* allocate a working area */\r
        if (target_alloc_working_area(target, lpc2000_info->cmd51_max_buffer, &download_area) != ERROR_OK)\r
        {\r
@@ -654,8 +649,7 @@ int lpc2000_handle_part_id_command(struct command_context_s *cmd_ctx, char *cmd,
 \r
        if (argc < 1)\r
        {\r
-               command_print(cmd_ctx, "usage: lpc2000 part_id <num>");\r
-               return ERROR_OK;\r
+               return ERROR_COMMAND_SYNTAX_ERROR;
        }\r
        \r
        bank = get_flash_bank_by_num(strtoul(args[0], NULL, 0));\r
index 0a7bf18..1bed1e0 100644 (file)
@@ -36,12 +36,6 @@ static char** config_file_names;
 static size_t num_script_dirs;\r
 static char** script_search_dirs;\r
 \r
-int configuration_output_handler(struct command_context_s *context, char* line)\r
-{\r
-       INFO(line);\r
-       \r
-       return ERROR_OK;\r
-}\r
 \r
 void add_script_search_dir (const char *dir)\r
 {\r
index 908748d..b6b2c6d 100644 (file)
@@ -48,6 +48,15 @@ static struct option long_options[] =
 };\r
 \r
 \r
+\r
+int configuration_output_handler(struct command_context_s *context, char* line)\r
+{\r
+       INFO(line);\r
+\r
+       return ERROR_OK;\r
+}\r
+\r
+\r
 int parse_cmdline_args(struct command_context_s *cmd_ctx, int argc, char *argv[])\r
 {\r
        int c;\r
index 974328c..c401511 100644 (file)
@@ -1610,7 +1610,7 @@ int handle_endstate_command(struct command_context_s *cmd_ctx, char *cmd, char *
 
        if (argc < 1)
        {
-               command_print(cmd_ctx, "usage: endstate <tap_state>");
+               return ERROR_COMMAND_SYNTAX_ERROR;\r
        }
        else
        {
@@ -1632,13 +1632,12 @@ int handle_jtag_reset_command(struct command_context_s *cmd_ctx, char *cmd, char
 {
        int trst = -1;
        int srst = -1;
-       char *usage = "usage: jtag_reset <trst> <srst>";
        int retval;
        
        if (argc < 1)
        {
-               command_print(cmd_ctx, usage);
-               return ERROR_OK;
+               return ERROR_COMMAND_SYNTAX_ERROR;\r
+\r
        }
 
        if (args[0][0] == '1')
@@ -1647,8 +1646,7 @@ int handle_jtag_reset_command(struct command_context_s *cmd_ctx, char *cmd, char
                trst = 0;
        else
        {
-               command_print(cmd_ctx, usage);
-               return ERROR_OK;
+               return ERROR_COMMAND_SYNTAX_ERROR;\r
        }
 
        if (args[1][0] == '1')
@@ -1657,8 +1655,7 @@ int handle_jtag_reset_command(struct command_context_s *cmd_ctx, char *cmd, char
                srst = 0;
        else
        {
-               command_print(cmd_ctx, usage);
-               return ERROR_OK;
+               return ERROR_COMMAND_SYNTAX_ERROR;\r
        }
 
        if ((retval = jtag_add_reset(trst, srst)) != ERROR_OK)
@@ -1684,8 +1681,7 @@ int handle_runtest_command(struct command_context_s *cmd_ctx, char *cmd, char **
 {
        if (argc < 1)
        {
-               command_print(cmd_ctx, "usage: runtest <num_cycles>");
-               return ERROR_OK;
+               return ERROR_COMMAND_SYNTAX_ERROR;\r
        }
 
        jtag_add_runtest(strtol(args[0], NULL, 0), -1);
@@ -1725,8 +1721,7 @@ int handle_irscan_command(struct command_context_s *cmd_ctx, char *cmd, char **a
        
        if ((argc < 2) || (argc % 2))
        {
-               command_print(cmd_ctx, "usage: irscan <device> <instr> [dev2] [instr2] ...");
-               return ERROR_OK;
+               return ERROR_COMMAND_SYNTAX_ERROR;\r
        }
 
        fields = malloc(sizeof(scan_field_t) * argc / 2);
@@ -1766,8 +1761,7 @@ int handle_drscan_command(struct command_context_s *cmd_ctx, char *cmd, char **a
        
        if ((argc < 2) || (argc % 2))
        {
-               command_print(cmd_ctx, "usage: drscan <device> <var> [dev2] [var2]");
-               return ERROR_OK;
+               return ERROR_COMMAND_SYNTAX_ERROR;\r
        }
 
        for (i = 0; i < argc; i+=2)
@@ -1818,20 +1812,25 @@ int handle_drscan_command(struct command_context_s *cmd_ctx, char *cmd, char **a
 
 int handle_verify_ircapture_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
 {
-       if (argc == 0)
-       {
-               command_print(cmd_ctx, "verify Capture-IR is %s", (jtag_verify_capture_ir) ? "enabled": "disabled");
-               return ERROR_OK;
-       }
-       
-       if (strcmp(args[0], "enable") == 0)
+       if (argc == 1)\r
        {
-               jtag_verify_capture_ir = 1;
-       }
-       else if (strcmp(args[0], "disable") == 0)
-       {
-               jtag_verify_capture_ir = 0;
-       }
+               if (strcmp(args[0], "enable") == 0)
+               {
+                       jtag_verify_capture_ir = 1;
+               }
+               else if (strcmp(args[0], "disable") == 0)
+               {
+                       jtag_verify_capture_ir = 0;
+               } else\r
+               {\r
+                       return ERROR_COMMAND_SYNTAX_ERROR;\r
+               }
+       } else if (argc != 0)\r
+       {\r
+               return ERROR_COMMAND_SYNTAX_ERROR;\r
+       }\r
+       \r
+       command_print(cmd_ctx, "verify Capture-IR is %s", (jtag_verify_capture_ir) ? "enabled": "disabled");\r
        
        return ERROR_OK;
 }
index b0ad834..6e43cf7 100644 (file)
@@ -277,7 +277,9 @@ int server_loop(command_context_t *command_context)
                FD_SET(fileno(stdin), &read_fds);
 #endif
 
-               if ((retval = select(fd_max + 1, &read_fds, NULL, NULL, &tv)) == -1)
+               retval = select(fd_max + 1, &read_fds, NULL, NULL, &tv);
+               
+               if (retval == -1)
                {
 #ifdef _WIN32
 
@@ -293,7 +295,9 @@ int server_loop(command_context_t *command_context)
 #else
 
                        if (errno == EINTR)
+                       {\r
                                FD_ZERO(&read_fds);
+                       }\r
                        else
                        {
                                ERROR("error during select: %s", strerror(errno));
@@ -309,6 +313,7 @@ int server_loop(command_context_t *command_context)
                        /* do regular tasks after at most 100ms */
                        tv.tv_sec = 0;
                        tv.tv_usec = 10000;
+                       FD_ZERO(&read_fds); /* eCos leaves read_fds unchanged in this case!  */\r
                }
                
                for (service = services; service; service = service->next)
@@ -318,7 +323,9 @@ int server_loop(command_context_t *command_context)
                                && (FD_ISSET(service->fd, &read_fds))) 
                        {
                                if (service->max_connections > 0)
+                               {\r
                                        add_connection(service, command_context);
+                               }
                                else
                                {
                                        struct sockaddr_in sin;
index b40daca..899902a 100644 (file)
@@ -121,13 +121,11 @@ int telnet_target_callback_event_handler(struct target_s *target, enum target_ev
        switch (event)
        {
                case TARGET_EVENT_HALTED:
-                       command_print(cmd_ctx, "Target %i halted", get_num_by_target(target));
                        target_arch_state(target);
                        if (!t_con->suppress_prompt)
                                telnet_prompt(connection);
                        break;
                case TARGET_EVENT_RESUMED:
-                       command_print(cmd_ctx, "Target %i resumed", get_num_by_target(target));
                        if (!t_con->suppress_prompt)
                                telnet_prompt(connection);
                        break;
index fc1adb0..27df12f 100644 (file)
@@ -50,7 +50,6 @@
 int cli_target_callback_event_handler(struct target_s *target, enum target_event event, void *priv);
 
 
-int handle_arch_state_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
 int handle_target_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
 int handle_daemon_startup_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
 int handle_targets_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
@@ -749,7 +748,6 @@ int target_register_commands(struct command_context_s *cmd_ctx)
        register_command(cmd_ctx, NULL, "run_and_halt_time", handle_run_and_halt_time_command, COMMAND_CONFIG, NULL);
        register_command(cmd_ctx, NULL, "working_area", handle_working_area_command, COMMAND_ANY, "working_area <target#> <address> <size> <'backup'|'nobackup'> [virtual address]");
        register_command(cmd_ctx, NULL, "virt2phys", handle_virt2phys_command, COMMAND_ANY, "virt2phys <virtual address>");
-       register_command(cmd_ctx, NULL, "arch_state", handle_arch_state_command, COMMAND_ANY, "prints CPU state information");
 
        return ERROR_OK;
 }
@@ -1488,11 +1486,7 @@ int handle_poll_command(struct command_context_s *cmd_ctx, char *cmd, char **arg
        if (argc == 0)
        {
                target->type->poll(target);
-               command_print(cmd_ctx, "target state: %s", target_state_strings[target->state]);
-               if (target->state == TARGET_HALTED)
-               {
                        target_arch_state(target);
-               }
        }
        else
        {
@@ -1547,7 +1541,6 @@ static int wait_state(struct command_context_s *cmd_ctx, char *cmd, enum target_
        
        gettimeofday(&timeout, NULL);
        timeval_add_time(&timeout, 0, ms * 1000);
-       command_print(cmd_ctx, "waiting for target %s...", target_state_strings[state]);
        
        target_t *target = get_current_target(cmd_ctx);
        for (;;)
@@ -1557,9 +1550,9 @@ static int wait_state(struct command_context_s *cmd_ctx, char *cmd, enum target_
                target_call_timer_callbacks();
                if (target->state == state)
                {
-                       command_print(cmd_ctx, "target %s", target_state_strings[state]);
                        break;
                }
+               command_print(cmd_ctx, "waiting for target %s...", target_state_strings[state]);
                
                gettimeofday(&now, NULL);
                if ((now.tv_sec > timeout.tv_sec) || ((now.tv_sec == timeout.tv_sec) && (now.tv_usec >= timeout.tv_usec)))
@@ -1702,34 +1695,20 @@ int handle_resume_command(struct command_context_s *cmd_ctx, char *cmd, char **a
        int retval;
        target_t *target = get_current_target(cmd_ctx);
        
-       DEBUG("-");
-       
        if (argc == 0)
                retval = target->type->resume(target, 1, 0, 1, 0); /* current pc, addr = 0, handle breakpoints, not debugging */
        else if (argc == 1)
                retval = target->type->resume(target, 0, strtoul(args[0], NULL, 0), 1, 0); /* addr = args[0], handle breakpoints, not debugging */
        else
        {
-               command_print(cmd_ctx, "usage: resume [address]");
-               return ERROR_OK;
-       }
-       
-       if (retval != ERROR_OK)
-       {       
-               switch (retval)
-               {
-                       case ERROR_TARGET_NOT_HALTED:
-                               command_print(cmd_ctx, "target not halted");
-                               break;
-                       default:
-                               command_print(cmd_ctx, "unknown error... shutting down");
-                               exit(-1);
-               }
+               return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
        target_process_events(cmd_ctx);
        
-       return ERROR_OK;
+       target_arch_state(target);
+       
+       return retval;
 }
 
 int handle_step_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
@@ -2351,13 +2330,3 @@ int handle_virt2phys_command(command_context_t *cmd_ctx, char *cmd, char **args,
        }
        return retval;
 }
-int handle_arch_state_command(command_context_t *cmd_ctx, char *cmd, char **args, int argc)
-{
-       int retval;
-       if (argc!=0)
-               return ERROR_COMMAND_SYNTAX_ERROR;
-       
-       target_t *target = get_target_by_num(cmd_ctx->current_target);
-       retval=target_arch_state(target);
-       return retval;
-}