Remove redundant sys/types.h #include directives (now in types.h).
[openocd.git] / src / flash / mflash.c
index 9bc94adf24cbf98181a828987cb8b9fd3a072cb3..451d942b1e7717b0ea599b4a9c4ac402755f445c 100644 (file)
@@ -25,7 +25,6 @@
 #include <string.h>
 #include <unistd.h>
 #include <stdlib.h>
-#include <sys/types.h>
 #include <sys/stat.h>
 #include <errno.h>
 #include <inttypes.h>
@@ -80,7 +79,7 @@ static int pxa270_set_gpio_to_output (mflash_gpio_num_t gpio)
        target_t *target = mflash_bank->target;
        int ret;
 
-       // remove alternate function.
+       /* remove alternate function. */
        mask = 0x3u << (gpio.num & 0xF)*2;
 
        addr = PXA270_GAFR0_L + (gpio.num >> 4) * 4;
@@ -95,7 +94,7 @@ static int pxa270_set_gpio_to_output (mflash_gpio_num_t gpio)
        if ((ret = target_write_u32(target, addr, value)) != ERROR_OK)
                return ret;
 
-       // set direction to output
+       /* set direction to output */
        mask = 0x1u << (gpio.num & 0x1F);
 
        addr = PXA270_GPDR0 + (gpio.num >> 5) * 4;
@@ -206,31 +205,6 @@ static int mflash_rst(u8 level)
        return mflash_bank->gpio_drv->set_gpio_output_val(mflash_bank->rst_pin, level);
 }
 
-static int mg_dump_task_reg (void)
-{
-       target_t *target = mflash_bank->target;
-       u32 address = mflash_bank->base + MG_REG_OFFSET + MG_REG_ERROR;
-       u8 value, i;
-       char *reg_name[9] = {
-               "error                  ",
-               "sector count           ",
-               "sector num (LBA  7- 0) ",
-               "cyl. low   (LBA 15- 8) ",
-               "cyl. high  (LBA 23-16) ",
-               "drv/head               ",
-               "status                 ",
-               "dev control            ",
-               "burst control          "
-       };
-
-       for (i = 0; i < 9; i++) {
-               target_read_u8(target, address + i * 2, &value);
-               LOG_INFO("%s : 0x%2.2x", reg_name[i], value);
-       }
-
-       return ERROR_OK;
-
-}
 static int mflash_init_gpio (void)
 {
        mflash_gpio_drv_t *gpio_drv = mflash_bank->gpio_drv;
@@ -261,75 +235,75 @@ static int mg_dsk_wait(mg_io_type_wait wait, u32 time)
 
        duration_start_measure(&duration);
 
-    while (time) {
-
-       target_read_u8(target, mg_task_reg + MG_REG_STATUS, &status);
-
-       if (status & mg_io_rbit_status_busy)
-           {
-               if (wait == mg_io_wait_bsy)
-                      return ERROR_OK;
-           } else {
-               switch(wait)
-               {
-                   case mg_io_wait_not_bsy:
-                       return ERROR_OK;
-                   case mg_io_wait_rdy_noerr:
-                       if (status & mg_io_rbit_status_ready)
-                           return ERROR_OK;
-                       break;
-                   case mg_io_wait_drq_noerr:
-                       if (status & mg_io_rbit_status_data_req)
-                           return ERROR_OK;
-                       break;
-                   default:
-                       break;
-               }
-
-               // Now we check the error condition!
-               if (status & mg_io_rbit_status_error)
-               {
-                   target_read_u8(target, mg_task_reg + MG_REG_ERROR, &error);
-
-                if (error & mg_io_rbit_err_bad_sect_num) {
-                       LOG_ERROR("sector not found");
-                    return ERROR_FAIL;
-                }
-                else if (error & (mg_io_rbit_err_bad_block | mg_io_rbit_err_uncorrectable)) {
-                       LOG_ERROR("bad block");
-                    return ERROR_FAIL;
-                } else {
-                       LOG_ERROR("disk operation fail");
-                       return ERROR_FAIL;
-                   }
-               }
-
-               switch (wait)
-               {
-                   case mg_io_wait_rdy:
-                       if (status & mg_io_rbit_status_ready)
-                           return ERROR_OK;
-
-                   case mg_io_wait_drq:
-                       if (status & mg_io_rbit_status_data_req)
-                           return ERROR_OK;
-
-                   default:
-                       break;
-               }
-           }
-
-       duration_stop_measure(&duration, NULL);
-
-               t=duration.duration.tv_usec/1000;
-               t+=duration.duration.tv_sec*1000;
+       while (time) {
+
+               target_read_u8(target, mg_task_reg + MG_REG_STATUS, &status);
+
+               if (status & mg_io_rbit_status_busy)
+               {
+                       if (wait == mg_io_wait_bsy)
+                               return ERROR_OK;
+               } else {
+                       switch(wait)
+                       {
+                               case mg_io_wait_not_bsy:
+                                       return ERROR_OK;
+                               case mg_io_wait_rdy_noerr:
+                                       if (status & mg_io_rbit_status_ready)
+                                               return ERROR_OK;
+                                       break;
+                               case mg_io_wait_drq_noerr:
+                                       if (status & mg_io_rbit_status_data_req)
+                                               return ERROR_OK;
+                                       break;
+                               default:
+                                       break;
+                       }
+
+                       /* Now we check the error condition! */
+                       if (status & mg_io_rbit_status_error)
+                       {
+                               target_read_u8(target, mg_task_reg + MG_REG_ERROR, &error);
+
+                               if (error & mg_io_rbit_err_bad_sect_num) {
+                                       LOG_ERROR("sector not found");
+                                       return ERROR_FAIL;
+                               }
+                               else if (error & (mg_io_rbit_err_bad_block | mg_io_rbit_err_uncorrectable)) {
+                                       LOG_ERROR("bad block");
+                                       return ERROR_FAIL;
+                               } else {
+                                       LOG_ERROR("disk operation fail");
+                                       return ERROR_FAIL;
+                               }
+                       }
+
+                       switch (wait)
+                       {
+                               case mg_io_wait_rdy:
+                                       if (status & mg_io_rbit_status_ready)
+                                               return ERROR_OK;
+
+                               case mg_io_wait_drq:
+                                       if (status & mg_io_rbit_status_data_req)
+                                               return ERROR_OK;
+
+                               default:
+                                       break;
+                       }
+               }
+
+               duration_stop_measure(&duration, NULL);
+
+               t=duration.duration.tv_usec/1000;
+               t+=duration.duration.tv_sec*1000;
 
                if (t > time)
-            break;
-    }
+                       break;
+       }
 
-    LOG_ERROR("timeout occured");
-    return ERROR_FAIL;
+       LOG_ERROR("timeout occured");
+       return ERROR_FAIL;
 }
 
 static int mg_dsk_srst(u8 on)
@@ -498,14 +472,16 @@ static int mg_mflash_read_sects(void *buff, u32 sect_num, u32 sect_cnt)
        residue = sect_cnt % 256;
 
        for (i = 0; i < quotient; i++) {
-               LOG_DEBUG("sect num : %u buff : 0x%8.8x", sect_num, (u32)buff_ptr);
+               LOG_DEBUG("sect num : %u buff : 0x%0lx", sect_num, 
+                       (unsigned long)buff_ptr);
                mg_mflash_do_read_sects(buff_ptr, sect_num, 256);
                sect_num += 256;
                buff_ptr += 256 * MG_MFLASH_SECTOR_SIZE;
        }
 
        if (residue) {
-               LOG_DEBUG("sect num : %u buff : %8.8x", sect_num, (u32)buff_ptr);
+               LOG_DEBUG("sect num : %u buff : %0lx", sect_num, 
+                       (unsigned long)buff_ptr);
                mg_mflash_do_read_sects(buff_ptr, sect_num, residue);
        }
 
@@ -567,14 +543,16 @@ static int mg_mflash_write_sects(void *buff, u32 sect_num, u32 sect_cnt)
        residue = sect_cnt % 256;
 
        for (i = 0; i < quotient; i++) {
-               LOG_DEBUG("sect num : %u buff : %8.8x", sect_num, (u32)buff_ptr);
+               LOG_DEBUG("sect num : %u buff : %0lx", sect_num, 
+                       (unsigned long)buff_ptr);
                mg_mflash_do_write_sects(buff_ptr, sect_num, 256);
                sect_num += 256;
                buff_ptr += 256 * MG_MFLASH_SECTOR_SIZE;
        }
 
        if (residue) {
-               LOG_DEBUG("sect num : %u buff : %8.8x", sect_num, (u32)buff_ptr);
+               LOG_DEBUG("sect num : %u buff : %0lx", sect_num, 
+                       (unsigned long)buff_ptr);
                mg_mflash_do_write_sects(buff_ptr, sect_num, residue);
        }
 
@@ -634,7 +612,6 @@ static int mg_mflash_read (u32 addr, u8 *buff, u32 len)
                        LOG_DEBUG("copies %u byte", end_addr - cur_addr);
 
                }
-
        }
 
        free(sect_buff);
@@ -671,7 +648,6 @@ static int mg_mflash_write(u32 addr, u8 *buff, u32 len)
                }
 
                mg_mflash_write_sects(sect_buff, sect_num, 1);
-
        }
 
        if (cur_addr < end_addr) {
@@ -697,9 +673,7 @@ static int mg_mflash_write(u32 addr, u8 *buff, u32 len)
                        memcpy(sect_buff, buff_ptr, end_addr - cur_addr);
                        LOG_DEBUG("copies %u byte", end_addr - cur_addr);
                        mg_mflash_write_sects(sect_buff, sect_num, 1);
-
                }
-
        }
 
        free(sect_buff);
@@ -711,7 +685,7 @@ static int mflash_write_command(struct command_context_s *cmd_ctx, char *cmd, ch
 {
        u32 address, buf_cnt;
        u8 *buffer;
-       // TODO : multi-bank support, large file support
+       /* TODO : multi-bank support, large file support */
        fileio_t fileio;
        duration_t duration;
        char *duration_text;
@@ -727,7 +701,6 @@ static int mflash_write_command(struct command_context_s *cmd_ctx, char *cmd, ch
                mg_mflash_probe();
        }
 
-
        if (fileio_open(&fileio, args[1], FILEIO_READ, FILEIO_BINARY) != ERROR_OK) {
                return ERROR_FAIL;
        }
@@ -764,7 +737,7 @@ static int mflash_dump_command(struct command_context_s *cmd_ctx, char *cmd, cha
 {
        u32 address, size_written, size;
        u8 *buffer;
-       // TODO : multi-bank support
+       /* TODO : multi-bank support */
        fileio_t fileio;
        duration_t duration;
        char *duration_text;

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)