warnings: fix alignment warnings
[fw/openocd] / src / target / arm_adi_v5.c
index dfb45b496b1012f42d291cf838dc97fcd4e7e8f0..34147967a7feda7fa526e670ba7b5c05a59f395e 100644 (file)
@@ -5,7 +5,7 @@
  *   Copyright (C) 2008 by Spencer Oliver                                  *
  *   spen@spen-soft.co.uk                                                  *
  *                                                                         *
- *   Copyright (C) 2009 by Oyvind Harboe                                   *
+ *   Copyright (C) 2009-2010 by Oyvind Harboe                              *
  *   oyvind.harboe@zylin.com                                               *
  *                                                                         *
  *   Copyright (C) 2009-2010 by David Brownell                             *
@@ -309,17 +309,19 @@ int mem_ap_write_buf_u32(struct adiv5_dap *dap, uint8_t *buffer, int count, uint
                if (blocksize == 0)
                        blocksize = 1;
 
-               dap_setup_accessport(dap, CSW_32BIT | CSW_ADDRINC_SINGLE, address);
+               retval = dap_setup_accessport(dap, CSW_32BIT | CSW_ADDRINC_SINGLE, address);
+               if (retval != ERROR_OK)
+                       return retval;
 
                for (writecount = 0; writecount < blocksize; writecount++)
                {
                        retval = dap_queue_ap_write(dap, AP_REG_DRW,
-                               *(uint32_t *) (buffer + 4 * writecount));
+                               *(uint32_t *) ((void *) (buffer + 4 * writecount)));
                        if (retval != ERROR_OK)
                                break;
                }
 
-               if (dap_run(dap) == ERROR_OK)
+               if ((retval = dap_run(dap)) == ERROR_OK)
                {
                        wcount = wcount - blocksize;
                        address = address + 4 * blocksize;
@@ -333,8 +335,7 @@ int mem_ap_write_buf_u32(struct adiv5_dap *dap, uint8_t *buffer, int count, uint
                if (errorcount > 1)
                {
                        LOG_WARNING("Block write error address 0x%" PRIx32 ", wcount 0x%x", address, wcount);
-                       /* REVISIT return the *actual* fault code */
-                       return ERROR_JTAG_DEVICE_ERROR;
+                       return retval;
                }
        }
 
@@ -363,7 +364,9 @@ static int mem_ap_write_buf_packed_u16(struct adiv5_dap *dap,
                if (blocksize == 0)
                        blocksize = 1;
 
-               dap_setup_accessport(dap, CSW_16BIT | CSW_ADDRINC_PACKED, address);
+               retval = dap_setup_accessport(dap, CSW_16BIT | CSW_ADDRINC_PACKED, address);
+               if (retval != ERROR_OK)
+                       return retval;
                writecount = blocksize;
 
                do
@@ -372,13 +375,14 @@ static int mem_ap_write_buf_packed_u16(struct adiv5_dap *dap,
 
                        if (nbytes < 4)
                        {
-                               if (mem_ap_write_buf_u16(dap, buffer,
-                                               nbytes, address) != ERROR_OK)
+                               retval = mem_ap_write_buf_u16(dap, buffer,
+                                               nbytes, address);
+                               if (retval != ERROR_OK)
                                {
                                        LOG_WARNING("Block write error address "
                                                "0x%" PRIx32 ", count 0x%x",
                                                address, count);
-                                       return ERROR_JTAG_DEVICE_ERROR;
+                                       return retval;
                                }
 
                                address += nbytes >> 1;
@@ -401,13 +405,12 @@ static int mem_ap_write_buf_packed_u16(struct adiv5_dap *dap,
                                if (retval != ERROR_OK)
                                        break;
 
-                               if (dap_run(dap) != ERROR_OK)
+                               if ((retval = dap_run(dap)) != ERROR_OK)
                                {
                                        LOG_WARNING("Block write error address "
                                                "0x%" PRIx32 ", count 0x%x",
                                                address, count);
-                                       /* REVISIT return *actual* fault code */
-                                       return ERROR_JTAG_DEVICE_ERROR;
+                                       return retval;
                                }
                        }
 
@@ -430,7 +433,9 @@ int mem_ap_write_buf_u16(struct adiv5_dap *dap, uint8_t *buffer, int count, uint
 
        while (count > 0)
        {
-               dap_setup_accessport(dap, CSW_16BIT | CSW_ADDRINC_SINGLE, address);
+               retval = dap_setup_accessport(dap, CSW_16BIT | CSW_ADDRINC_SINGLE, address);
+               if (retval != ERROR_OK)
+                       return retval;
                uint16_t svalue;
                memcpy(&svalue, buffer, sizeof(uint16_t));
                uint32_t outvalue = (uint32_t)svalue << 8 * (address & 0x3);
@@ -468,7 +473,9 @@ static int mem_ap_write_buf_packed_u8(struct adiv5_dap *dap,
                if (wcount < blocksize)
                        blocksize = wcount;
 
-               dap_setup_accessport(dap, CSW_8BIT | CSW_ADDRINC_PACKED, address);
+               retval = dap_setup_accessport(dap, CSW_8BIT | CSW_ADDRINC_PACKED, address);
+               if (retval != ERROR_OK)
+                       return retval;
                writecount = blocksize;
 
                do
@@ -477,12 +484,13 @@ static int mem_ap_write_buf_packed_u8(struct adiv5_dap *dap,
 
                        if (nbytes < 4)
                        {
-                               if (mem_ap_write_buf_u8(dap, buffer, nbytes, address) != ERROR_OK)
+                               retval = mem_ap_write_buf_u8(dap, buffer, nbytes, address);
+                               if (retval != ERROR_OK)
                                {
                                        LOG_WARNING("Block write error address "
                                                "0x%" PRIx32 ", count 0x%x",
                                                address, count);
-                                       return ERROR_JTAG_DEVICE_ERROR;
+                                       return retval;
                                }
 
                                address += nbytes;
@@ -505,13 +513,12 @@ static int mem_ap_write_buf_packed_u8(struct adiv5_dap *dap,
                                if (retval != ERROR_OK)
                                        break;
 
-                               if (dap_run(dap) != ERROR_OK)
+                               if ((retval = dap_run(dap)) != ERROR_OK)
                                {
                                        LOG_WARNING("Block write error address "
                                                "0x%" PRIx32 ", count 0x%x",
                                                address, count);
-                                       /* REVISIT return *actual* fault code */
-                                       return ERROR_JTAG_DEVICE_ERROR;
+                                       return retval;
                                }
                        }
 
@@ -534,7 +541,9 @@ int mem_ap_write_buf_u8(struct adiv5_dap *dap, uint8_t *buffer, int count, uint3
 
        while (count > 0)
        {
-               dap_setup_accessport(dap, CSW_8BIT | CSW_ADDRINC_SINGLE, address);
+               retval = dap_setup_accessport(dap, CSW_8BIT | CSW_ADDRINC_SINGLE, address);
+               if (retval != ERROR_OK)
+                       return retval;
                uint32_t outvalue = (uint32_t)*buffer << 8 * (address & 0x3);
                retval = dap_queue_ap_write(dap, AP_REG_DRW, outvalue);
                if (retval != ERROR_OK)
@@ -592,8 +601,10 @@ int mem_ap_read_buf_u32(struct adiv5_dap *dap, uint8_t *buffer,
                if (blocksize == 0)
                        blocksize = 1;
 
-               dap_setup_accessport(dap, CSW_32BIT | CSW_ADDRINC_SINGLE,
+               retval = dap_setup_accessport(dap, CSW_32BIT | CSW_ADDRINC_SINGLE,
                                address);
+               if (retval != ERROR_OK)
+                       return retval;
 
                /* FIXME remove these three calls to adi_jtag_dp_scan(),
                 * so this routine becomes transport-neutral.  Be careful
@@ -686,7 +697,9 @@ static int mem_ap_read_buf_packed_u16(struct adiv5_dap *dap,
                if (wcount < blocksize)
                        blocksize = wcount;
 
-               dap_setup_accessport(dap, CSW_16BIT | CSW_ADDRINC_PACKED, address);
+               retval = dap_setup_accessport(dap, CSW_16BIT | CSW_ADDRINC_PACKED, address);
+               if (retval != ERROR_OK)
+                       return retval;
 
                /* handle unaligned data at 4k boundary */
                if (blocksize == 0)
@@ -696,11 +709,12 @@ static int mem_ap_read_buf_packed_u16(struct adiv5_dap *dap,
                do
                {
                        retval = dap_queue_ap_read(dap, AP_REG_DRW, &invalue);
-                       if (dap_run(dap) != ERROR_OK)
+                       if (retval != ERROR_OK)
+                               return retval;
+                       if ((retval = dap_run(dap)) != ERROR_OK)
                        {
                                LOG_WARNING("Block read error address 0x%" PRIx32 ", count 0x%x", address, count);
-                               /* REVISIT return the *actual* fault code */
-                               return ERROR_JTAG_DEVICE_ERROR;
+                               return retval;
                        }
 
                        nbytes = MIN((readcount << 1), 4);
@@ -739,7 +753,9 @@ int mem_ap_read_buf_u16(struct adiv5_dap *dap, uint8_t *buffer,
 
        while (count > 0)
        {
-               dap_setup_accessport(dap, CSW_16BIT | CSW_ADDRINC_SINGLE, address);
+               retval = dap_setup_accessport(dap, CSW_16BIT | CSW_ADDRINC_SINGLE, address);
+               if (retval != ERROR_OK)
+                       return retval;
                retval = dap_queue_ap_read(dap, AP_REG_DRW, &invalue);
                if (retval != ERROR_OK)
                        break;
@@ -795,17 +811,20 @@ static int mem_ap_read_buf_packed_u8(struct adiv5_dap *dap,
                if (wcount < blocksize)
                        blocksize = wcount;
 
-               dap_setup_accessport(dap, CSW_8BIT | CSW_ADDRINC_PACKED, address);
+               retval = dap_setup_accessport(dap, CSW_8BIT | CSW_ADDRINC_PACKED, address);
+               if (retval != ERROR_OK)
+                       return retval;
                readcount = blocksize;
 
                do
                {
                        retval = dap_queue_ap_read(dap, AP_REG_DRW, &invalue);
-                       if (dap_run(dap) != ERROR_OK)
+                       if (retval != ERROR_OK)
+                               return retval;
+                       if ((retval = dap_run(dap)) != ERROR_OK)
                        {
                                LOG_WARNING("Block read error address 0x%" PRIx32 ", count 0x%x", address, count);
-                               /* REVISIT return the *actual* fault code */
-                               return ERROR_JTAG_DEVICE_ERROR;
+                               return retval;
                        }
 
                        nbytes = MIN(readcount, 4);
@@ -844,8 +863,12 @@ int mem_ap_read_buf_u8(struct adiv5_dap *dap, uint8_t *buffer,
 
        while (count > 0)
        {
-               dap_setup_accessport(dap, CSW_8BIT | CSW_ADDRINC_SINGLE, address);
+               retval = dap_setup_accessport(dap, CSW_8BIT | CSW_ADDRINC_SINGLE, address);
+               if (retval != ERROR_OK)
+                       return retval;
                retval = dap_queue_ap_read(dap, AP_REG_DRW, &invalue);
+               if (retval != ERROR_OK)
+                       return retval;
                retval = dap_run(dap);
                if (retval != ERROR_OK)
                        break;
@@ -969,7 +992,11 @@ int ahbap_debugport_init(struct adiv5_dap *dap)
         * place to scan the table and do any topology detection?
         */
        retval = dap_queue_ap_read(dap, AP_REG_IDR, &idreg);
+       if (retval != ERROR_OK)
+               return retval;
        retval = dap_queue_ap_read(dap, AP_REG_BASE, &romaddr);
+       if (retval != ERROR_OK)
+               return retval;
 
        if ((retval = dap_run(dap)) != ERROR_OK)
                return retval;
@@ -1015,7 +1042,11 @@ static int dap_info_command(struct command_context *cmd_ctx,
        apselold = dap->apsel;
        dap_ap_select(dap, apsel);
        retval = dap_queue_ap_read(dap, AP_REG_BASE, &dbgbase);
+       if (retval != ERROR_OK)
+               return retval;
        retval = dap_queue_ap_read(dap, AP_REG_IDR, &apid);
+       if (retval != ERROR_OK)
+               return retval;
        retval = dap_run(dap);
        if (retval != ERROR_OK)
                return retval;
@@ -1066,11 +1097,21 @@ static int dap_info_command(struct command_context *cmd_ctx,
                        command_print(cmd_ctx, "\tROM table in legacy format");
 
                /* Now we read ROM table ID registers, ref. ARM IHI 0029B sec  */
-               mem_ap_read_u32(dap, (dbgbase&0xFFFFF000) | 0xFF0, &cid0);
-               mem_ap_read_u32(dap, (dbgbase&0xFFFFF000) | 0xFF4, &cid1);
-               mem_ap_read_u32(dap, (dbgbase&0xFFFFF000) | 0xFF8, &cid2);
-               mem_ap_read_u32(dap, (dbgbase&0xFFFFF000) | 0xFFC, &cid3);
-               mem_ap_read_u32(dap, (dbgbase&0xFFFFF000) | 0xFCC, &memtype);
+               retval = mem_ap_read_u32(dap, (dbgbase&0xFFFFF000) | 0xFF0, &cid0);
+               if (retval != ERROR_OK)
+                       return retval;
+               retval = mem_ap_read_u32(dap, (dbgbase&0xFFFFF000) | 0xFF4, &cid1);
+               if (retval != ERROR_OK)
+                       return retval;
+               retval = mem_ap_read_u32(dap, (dbgbase&0xFFFFF000) | 0xFF8, &cid2);
+               if (retval != ERROR_OK)
+                       return retval;
+               retval = mem_ap_read_u32(dap, (dbgbase&0xFFFFF000) | 0xFFC, &cid3);
+               if (retval != ERROR_OK)
+                       return retval;
+               retval = mem_ap_read_u32(dap, (dbgbase&0xFFFFF000) | 0xFCC, &memtype);
+               if (retval != ERROR_OK)
+                       return retval;
                retval = dap_run(dap);
                if (retval != ERROR_OK)
                        return retval;
@@ -1092,7 +1133,9 @@ static int dap_info_command(struct command_context *cmd_ctx,
                entry_offset = 0;
                do
                {
-                       mem_ap_read_atomic_u32(dap, (dbgbase&0xFFFFF000) | entry_offset, &romentry);
+                       retval = mem_ap_read_atomic_u32(dap, (dbgbase&0xFFFFF000) | entry_offset, &romentry);
+                       if (retval != ERROR_OK)
+                               return retval;
                        command_print(cmd_ctx, "\tROMTABLE[0x%x] = 0x%" PRIx32 "",entry_offset,romentry);
                        if (romentry&0x01)
                        {
@@ -1108,33 +1151,51 @@ static int dap_info_command(struct command_context *cmd_ctx,
                                /* IDs are in last 4K section */
 
 
-                               mem_ap_read_atomic_u32(dap,
+                               retval = mem_ap_read_atomic_u32(dap,
                                        component_base + 0xFE0, &c_pid0);
+                               if (retval != ERROR_OK)
+                                       return retval;
                                c_pid0 &= 0xff;
-                               mem_ap_read_atomic_u32(dap,
+                               retval = mem_ap_read_atomic_u32(dap,
                                        component_base + 0xFE4, &c_pid1);
+                               if (retval != ERROR_OK)
+                                       return retval;
                                c_pid1 &= 0xff;
-                               mem_ap_read_atomic_u32(dap,
+                               retval = mem_ap_read_atomic_u32(dap,
                                        component_base + 0xFE8, &c_pid2);
+                               if (retval != ERROR_OK)
+                                       return retval;
                                c_pid2 &= 0xff;
-                               mem_ap_read_atomic_u32(dap,
+                               retval = mem_ap_read_atomic_u32(dap,
                                        component_base + 0xFEC, &c_pid3);
+                               if (retval != ERROR_OK)
+                                       return retval;
                                c_pid3 &= 0xff;
-                               mem_ap_read_atomic_u32(dap,
+                               retval = mem_ap_read_atomic_u32(dap,
                                        component_base + 0xFD0, &c_pid4);
+                               if (retval != ERROR_OK)
+                                       return retval;
                                c_pid4 &= 0xff;
 
-                               mem_ap_read_atomic_u32(dap,
+                               retval = mem_ap_read_atomic_u32(dap,
                                        component_base + 0xFF0, &c_cid0);
+                               if (retval != ERROR_OK)
+                                       return retval;
                                c_cid0 &= 0xff;
-                               mem_ap_read_atomic_u32(dap,
+                               retval = mem_ap_read_atomic_u32(dap,
                                        component_base + 0xFF4, &c_cid1);
+                               if (retval != ERROR_OK)
+                                       return retval;
                                c_cid1 &= 0xff;
-                               mem_ap_read_atomic_u32(dap,
+                               retval = mem_ap_read_atomic_u32(dap,
                                        component_base + 0xFF8, &c_cid2);
+                               if (retval != ERROR_OK)
+                                       return retval;
                                c_cid2 &= 0xff;
-                               mem_ap_read_atomic_u32(dap,
+                               retval = mem_ap_read_atomic_u32(dap,
                                        component_base + 0xFFC, &c_cid3);
+                               if (retval != ERROR_OK)
+                                       return retval;
                                c_cid3 &= 0xff;
 
 
@@ -1155,9 +1216,11 @@ static int dap_info_command(struct command_context *cmd_ctx,
                                        unsigned minor;
                                        char *major = "Reserved", *subtype = "Reserved";
 
-                                       mem_ap_read_atomic_u32(dap,
+                                       retval = mem_ap_read_atomic_u32(dap,
                                                        (component_base & 0xfffff000) | 0xfcc,
                                                        &devtype);
+                                       if (retval != ERROR_OK)
+                                               return retval;
                                        minor = (devtype >> 4) & 0x0f;
                                        switch (devtype & 0x0f) {
                                        case 0:
@@ -1434,6 +1497,8 @@ COMMAND_HANDLER(dap_baseaddr_command)
         * use the ID register to verify it's a MEM-AP.
         */
        retval = dap_queue_ap_read(dap, AP_REG_BASE, &baseaddr);
+       if (retval != ERROR_OK)
+               return retval;
        retval = dap_run(dap);
        if (retval != ERROR_OK)
                return retval;
@@ -1497,6 +1562,8 @@ COMMAND_HANDLER(dap_apsel_command)
 
        dap_ap_select(dap, apsel);
        retval = dap_queue_ap_read(dap, AP_REG_IDR, &apid);
+       if (retval != ERROR_OK)
+               return retval;
        retval = dap_run(dap);
        if (retval != ERROR_OK)
                return retval;
@@ -1535,6 +1602,8 @@ COMMAND_HANDLER(dap_apid_command)
                dap_ap_select(dap, apsel);
 
        retval = dap_queue_ap_read(dap, AP_REG_IDR, &apid);
+       if (retval != ERROR_OK)
+               return retval;
        retval = dap_run(dap);
        if (retval != ERROR_OK)
                return retval;