]> git.sur5r.net Git - openocd/commitdiff
Laurentiu Cocanu - more error handling fixes
authoroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Tue, 14 Oct 2008 13:14:52 +0000 (13:14 +0000)
committeroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Tue, 14 Oct 2008 13:14:52 +0000 (13:14 +0000)
git-svn-id: svn://svn.berlios.de/openocd/trunk@1059 b42882b7-edfa-0310-969c-e2dbd0fdcd60

src/flash/flash.c
src/server/gdb_server.c
src/target/armv7m.c

index 5f09c72dd7b8f57497f1ac579d063a2c3873eb53..d5f89de6cf6acd4d6619dee284a5fbf1850a3961 100644 (file)
@@ -514,7 +514,11 @@ int handle_flash_erase_address_command(struct command_context_s *cmd_ctx, char *
 
        if ((retval = flash_erase_address_range(target, address, length)) == ERROR_OK)
        {
-               duration_stop_measure(&duration, &duration_text);
+               if ((retval = duration_stop_measure(&duration, &duration_text)) != ERROR_OK)
+               {
+                       free(duration_text);
+                       return retval;
+               }
                command_print(cmd_ctx, "erased address 0x%8.8x length %i in %s", address, length, duration_text);
                free(duration_text);
        }
@@ -576,7 +580,11 @@ int handle_flash_erase_command(struct command_context_s *cmd_ctx, char *cmd, cha
 
                if ((retval = flash_driver_erase(p, first, last)) == ERROR_OK)
                {
-                       duration_stop_measure(&duration, &duration_text);
+                       if ((retval = duration_stop_measure(&duration, &duration_text)) != ERROR_OK)
+                       {
+                               free(duration_text);
+                               return retval;
+                       }
 
                        command_print(cmd_ctx, "erased sectors %i through %i on flash bank %i in %s", first, last, strtoul(args[0], 0, 0), duration_text);
                        free(duration_text);
@@ -639,7 +647,7 @@ int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cm
        duration_t duration;
        char *duration_text;
 
-       int retval;
+       int retval, retvaltemp;
 
        if (argc < 1)
        {
@@ -697,7 +705,12 @@ int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cm
                return retval;
        }
 
-       duration_stop_measure(&duration, &duration_text);
+       if ((retvaltemp = duration_stop_measure(&duration, &duration_text)) != ERROR_OK)
+       {
+               free(duration_text);
+               image_close(&image);
+               return retvaltemp;
+       }
        if (retval == ERROR_OK)
        {
                command_print(cmd_ctx, "wrote %u byte from file %s in %s (%f kb/s)",
@@ -713,7 +726,7 @@ int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cm
 
 int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
 {
-       int err = ERROR_OK;
+       int err = ERROR_OK, retval;
        u32 address;
        u32 pattern;
        u32 count;
@@ -803,7 +816,12 @@ int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cmd, char
                }
        }
 
-       duration_stop_measure(&duration, &duration_text);
+       if ((retval = duration_stop_measure(&duration, &duration_text)) != ERROR_OK)
+       {
+               free(duration_text);
+               return retval;
+       }
+
 
        if(err == ERROR_OK)
        {
@@ -829,7 +847,7 @@ int handle_flash_write_bank_command(struct command_context_s *cmd_ctx, char *cmd
        duration_t duration;
        char *duration_text;
 
-       int retval;
+       int retval, retvaltemp;
        flash_bank_t *p;
 
        if (argc != 3)
@@ -865,7 +883,12 @@ int handle_flash_write_bank_command(struct command_context_s *cmd_ctx, char *cmd
        free(buffer);
        buffer = NULL;
 
-       duration_stop_measure(&duration, &duration_text);
+       if ((retvaltemp = duration_stop_measure(&duration, &duration_text)) != ERROR_OK)
+       {
+               free(duration_text);
+               fileio_close(&fileio);
+               return retvaltemp;
+       }
        if (retval!=ERROR_OK)
        {
        command_print(cmd_ctx, "wrote  %"PRIi64" byte from file %s to flash bank %i at offset 0x%8.8x in %s (%f kb/s)",
index 69e91dbead1bb3ec3629d7f6f6c75bfadebe0f95..562eb13a4076a016d91d8eccf00db020d2dd1e55 100644 (file)
@@ -335,7 +335,10 @@ int gdb_put_packet_inner(connection_t *connection, char *buffer, int len)
                        local_buffer[len++] = '#';
                        local_buffer[len++] = DIGITS[(my_checksum >> 4) & 0xf];
                        local_buffer[len++] = DIGITS[my_checksum & 0xf];
-                       gdb_write(connection, local_buffer, len);
+                       if((retval = gdb_write(connection, local_buffer, len)) != ERROR_OK)
+                       {
+                               return retval;
+                       }
                }
                else
                {
@@ -344,9 +347,18 @@ int gdb_put_packet_inner(connection_t *connection, char *buffer, int len)
                        local_buffer[1] = '#';
                        local_buffer[2] = DIGITS[(my_checksum >> 4) & 0xf];
                        local_buffer[3] = DIGITS[my_checksum & 0xf];
-                       gdb_write(connection, local_buffer, 1);
-                       gdb_write(connection, buffer, len);
-                       gdb_write(connection, local_buffer+1, 3);
+                       if((retval = gdb_write(connection, local_buffer, 1)) != ERROR_OK)
+                       {
+                               return retval;
+                       }
+                       if((retval = gdb_write(connection, buffer, len)) != ERROR_OK)
+                       {
+                               return retval;
+                       }
+                       if((retval = gdb_write(connection, local_buffer+1, 3)) != ERROR_OK)
+                       {
+                               return retval;
+                       }
                }
 
                if (gdb_con->noack_mode)
@@ -589,7 +601,10 @@ int gdb_get_packet_inner(connection_t *connection, char *buffer, int *len)
                }
                if (checksum_ok)
                {
-                       gdb_write(connection, "+", 1);
+                       if ((retval = gdb_write(connection, "+", 1)) != ERROR_OK)
+                       {
+                               return retval;
+                       }
                        break;
                }
        }
@@ -624,10 +639,10 @@ int gdb_output_con(connection_t *connection, const char* line)
                snprintf(hex_buffer + 1 + i*2, 3, "%2.2x", line[i]);
        hex_buffer[bin_size*2+1] = 0;
 
-       gdb_put_packet(connection, hex_buffer, bin_size*2 + 1);
+       int retval = gdb_put_packet(connection, hex_buffer, bin_size*2 + 1);
 
        free(hex_buffer);
-       return ERROR_OK;
+       return retval;
 }
 
 int gdb_output(struct command_context_s *context, const char* line)
@@ -676,6 +691,7 @@ static void gdb_frontend_halted(struct target_s *target, connection_t *connectio
 
 int gdb_target_callback_event_handler(struct target_s *target, enum target_event event, void *priv)
 {
+       int retval;
        connection_t *connection = priv;
 
        target_handle_event( target, event );
@@ -686,7 +702,10 @@ int gdb_target_callback_event_handler(struct target_s *target, enum target_event
                        break;
                case TARGET_EVENT_GDB_FLASH_ERASE_START:
                        target_handle_event( target, TARGET_EVENT_OLD_gdb_program_config );
-                       jtag_execute_queue();
+                       if((retval = jtag_execute_queue()) != ERROR_OK)
+                       {
+                               return retval;
+                       }
                        break;
                default:
                        break;
@@ -768,7 +787,7 @@ int gdb_new_connection(connection_t *connection)
        return ERROR_OK;
 }
 
-int gdb_connection_closed(connection_t *connection)
+void gdb_connection_closed(connection_t *connection)
 {
        gdb_service_t *gdb_service = connection->service->priv;
        gdb_connection_t *gdb_connection = connection->priv;
@@ -798,7 +817,6 @@ int gdb_connection_closed(connection_t *connection)
        log_remove_callback(gdb_log_callback, connection);
 
        target_call_event_callbacks(gdb_service->target, TARGET_EVENT_GDB_DETACH );
-       return ERROR_OK;
 }
 
 void gdb_send_error(connection_t *connection, u8 the_error)
@@ -1818,6 +1836,7 @@ int gdb_v_packet(connection_t *connection, target_t *target, char *packet, int p
 
        if (strstr(packet, "vFlashWrite:"))
        {
+               int retval;
                unsigned long addr;
                unsigned long length;
                char *parse = packet + 12;
@@ -1843,7 +1862,10 @@ int gdb_v_packet(connection_t *connection, target_t *target, char *packet, int p
                }
 
                /* create new section with content from packet buffer */
-               image_add_section(gdb_connection->vflash_image, addr, length, 0x0, (u8*)parse);
+               if((retval = image_add_section(gdb_connection->vflash_image, addr, length, 0x0, (u8*)parse)) != ERROR_OK)
+               {
+                       return retval;
+               }
 
                gdb_put_packet(connection, "OK", 2);
 
index ae4d82ba0b62312b6c2e8b76d69a0e10b2585b69..6dc224f90048b10262a90ea46a1ef6c6cedf4f17 100644 (file)
@@ -216,7 +216,7 @@ int armv7m_read_core_reg(struct target_s *target, int num)
        armv7m->core_cache->reg_list[num].valid = 1;
        armv7m->core_cache->reg_list[num].dirty = 0;
 
-       return ERROR_OK;
+       return retval;
 }
 
 int armv7m_write_core_reg(struct target_s *target, int num)
@@ -372,10 +372,19 @@ int armv7m_run_algorithm(struct target_s *target, int num_mem_params, mem_param_
 
        /* This code relies on the target specific  resume() and  poll()->debug_entry()
        sequence to write register values to the processor and the read them back */
-       target_resume(target, 0, entry_point, 1, 1);
-       target_poll(target);
+       if((retval = target_resume(target, 0, entry_point, 1, 1)) != ERROR_OK)
+       {
+               return retval;
+       }
+       if((retval = target_poll(target)) != ERROR_OK)
+       {
+               return retval;
+       }
 
-       target_wait_state(target, TARGET_HALTED, timeout_ms);
+       if((retval = target_wait_state(target, TARGET_HALTED, timeout_ms)) != ERROR_OK)
+       {
+               return retval;
+       }
        if (target->state != TARGET_HALTED)
        {
                if ((retval=target_halt(target))!=ERROR_OK)
@@ -401,7 +410,10 @@ int armv7m_run_algorithm(struct target_s *target, int num_mem_params, mem_param_
        for (i = 0; i < num_mem_params; i++)
        {
                if (mem_params[i].direction != PARAM_OUT)
-                       target_read_buffer(target, mem_params[i].address, mem_params[i].size, mem_params[i].value);
+                       if((retval = target_read_buffer(target, mem_params[i].address, mem_params[i].size, mem_params[i].value)) != ERROR_OK)
+                       {
+                               return retval;
+                       }
        }
 
        /* Copy core register values to reg_params[] */
@@ -575,7 +587,10 @@ int armv7m_checksum_memory(struct target_s *target, u32 address, u32 count, u32*
 
        /* convert flash writing code into a buffer in target endianness */
        for (i = 0; i < (sizeof(cortex_m3_crc_code)/sizeof(u16)); i++)
-               target_write_u16(target, crc_algorithm->address + i*sizeof(u16), cortex_m3_crc_code[i]);
+               if((retval = target_write_u16(target, crc_algorithm->address + i*sizeof(u16), cortex_m3_crc_code[i])) != ERROR_OK)
+               {
+                       return retval;
+               }
 
        armv7m_info.common_magic = ARMV7M_COMMON_MAGIC;
        armv7m_info.core_mode = ARMV7M_MODE_ANY;