add const keyword to some APIs
[openocd.git] / src / flash / lpc2900.c
index 26ca67f5fa70ec5175032c394940d8c737293de1..251f682f21eae6fc7b8d4cda75b4ba2d5884aaec 100644 (file)
@@ -171,21 +171,6 @@ typedef struct lpc2900_flash_bank_s
 } lpc2900_flash_bank_t;
 
 
-
-
-static int lpc2900_register_commands(struct command_context_s *cmd_ctx);
-static int lpc2900_flash_bank_command(struct command_context_s *cmd_ctx,
-                                      char *cmd, char **args, int argc,
-                                      struct flash_bank_s *bank);
-static int lpc2900_erase(struct flash_bank_s *bank, int first, int last);
-static int lpc2900_protect(struct flash_bank_s *bank, int set, int first, int last);
-static int lpc2900_write(struct flash_bank_s *bank,
-                         uint8_t *buffer, uint32_t offset, uint32_t count);
-static int lpc2900_probe(struct flash_bank_s *bank);
-static int lpc2900_erase_check(struct flash_bank_s *bank);
-static int lpc2900_protect_check(struct flash_bank_s *bank);
-static int lpc2900_info(struct flash_bank_s *bank, char *buf, int buf_size);
-
 static uint32_t lpc2900_wait_status(flash_bank_t *bank, uint32_t mask, int timeout);
 static void lpc2900_setup(struct flash_bank_s *bank);
 static uint32_t lpc2900_is_ready(struct flash_bank_s *bank);
@@ -444,9 +429,9 @@ static int lpc2900_write_index_page( struct flash_bank_s *bank,
                                      uint8_t (*page)[FLASH_PAGE_SIZE] )
 {
        /* Only pages 4...7 are user writable */
-       if( (pagenum < 4) || (pagenum > 7) )
+       if ((pagenum < 4) || (pagenum > 7))
        {
-               LOG_ERROR( "Refuse to burn index sector page %" PRIu32, pagenum );
+               LOG_ERROR("Refuse to burn index sector page %d", pagenum);
                return ERROR_COMMAND_ARGUMENT_INVALID;
        }
 
@@ -479,7 +464,7 @@ static int lpc2900_write_index_page( struct flash_bank_s *bank,
                                 bank->base + pagenum * FLASH_PAGE_SIZE,
                                 4, FLASH_PAGE_SIZE / 4, (uint8_t *)page) != ERROR_OK )
        {
-               LOG_ERROR( "Index sector write failed @ page %" PRIu32, pagenum );
+               LOG_ERROR("Index sector write failed @ page %d", pagenum);
                target_write_u32( target, FCTR, FCTR_FS_CS | FCTR_FS_WEB );
 
                return ERROR_FLASH_OPERATION_FAILED;
@@ -501,10 +486,10 @@ static int lpc2900_write_index_page( struct flash_bank_s *bank,
        /* Wait for the end of the write operation. If it's not over after one
         * second, something went dreadfully wrong... :-(
         */
-       if( lpc2900_wait_status( bank, INTSRC_END_OF_BURN, 1000 ) != ERROR_OK )
+       if (lpc2900_wait_status(bank, INTSRC_END_OF_BURN, 1000) != ERROR_OK)
        {
-               LOG_ERROR( "Index sector write failed @ page %" PRIu32, pagenum );
-               target_write_u32( target, FCTR, FCTR_FS_CS | FCTR_FS_WEB );
+               LOG_ERROR("Index sector write failed @ page %d", pagenum);
+               target_write_u32(target, FCTR, FCTR_FS_CS | FCTR_FS_WEB);
 
                return ERROR_FLASH_OPERATION_FAILED;
        }
@@ -528,7 +513,7 @@ static uint32_t lpc2900_calc_tr( uint32_t clock, uint32_t time )
         * FPTR.TR = -------------------------------
         *                         512
         *
-        * The result is the 
+        * The result is the
         */
 
        uint32_t tr_val = (uint32_t)((((time / 1e6) * clock) + 511.0) / 512.0);
@@ -554,7 +539,6 @@ static uint32_t lpc2900_calc_tr( uint32_t clock, uint32_t time )
 static int lpc2900_handle_signature_command( struct command_context_s *cmd_ctx,
                                              char *cmd, char **args, int argc )
 {
-       flash_bank_t *bank;
        uint32_t status;
        uint32_t signature[4];
 
@@ -565,13 +549,10 @@ static int lpc2900_handle_signature_command( struct command_context_s *cmd_ctx,
                return ERROR_FLASH_BANK_INVALID;
        }
 
-       /* Get the bank descriptor */
-       bank = get_flash_bank_by_num( strtoul(args[0], NULL, 0) );
-       if( !bank )
-       {
-               command_print( cmd_ctx, "flash bank '#%s' is out of bounds", args[0] );
-               return ERROR_OK;
-       }
+       flash_bank_t *bank;
+       int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &bank);
+       if (ERROR_OK != retval)
+               return retval;
 
        if( bank->target->state != TARGET_HALTED )
        {
@@ -614,21 +595,16 @@ static int lpc2900_handle_signature_command( struct command_context_s *cmd_ctx,
 static int lpc2900_handle_read_custom_command( struct command_context_s *cmd_ctx,
                                                char *cmd, char **args, int argc )
 {
-       flash_bank_t *bank;
-
-
        if( argc < 2 )
        {
                return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
-       /* Get the bank descriptor */
-       bank = get_flash_bank_by_num( strtoul(args[0], NULL, 0) );
-       if( !bank )
-       {
-               command_print( cmd_ctx, "flash bank '#%s' is out of bounds", args[0] );
-               return ERROR_OK;
-       }
+       flash_bank_t *bank;
+       int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &bank);
+       if (ERROR_OK != retval)
+               return retval;
+
        lpc2900_flash_bank_t *lpc2900_info = bank->driver_priv;
        lpc2900_info->risky = 0;
 
@@ -659,7 +635,7 @@ static int lpc2900_handle_read_custom_command( struct command_context_s *cmd_ctx
 
        /* Try and open the file */
        fileio_t fileio;
-       char *filename = args[1];
+       const char *filename = args[1];
        int ret = fileio_open( &fileio, filename, FILEIO_WRITE, FILEIO_BINARY );
        if( ret != ERROR_OK )
        {
@@ -696,21 +672,16 @@ static int lpc2900_handle_read_custom_command( struct command_context_s *cmd_ctx
 static int lpc2900_handle_password_command(struct command_context_s *cmd_ctx,
                                            char *cmd, char **args, int argc)
 {
-       flash_bank_t *bank;
-
-
        if (argc < 2)
        {
                return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
-       /* Get the bank descriptor */
-       bank = get_flash_bank_by_num(strtoul(args[0], NULL, 0));
-       if (!bank)
-       {
-               command_print(cmd_ctx, "flash bank '#%s' is out of bounds", args[0]);
-               return ERROR_OK;
-       }
+       flash_bank_t *bank;
+       int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &bank);
+       if (ERROR_OK != retval)
+               return retval;
+
        lpc2900_flash_bank_t *lpc2900_info = bank->driver_priv;
 
 #define ISS_PASSWORD "I_know_what_I_am_doing"
@@ -747,13 +718,11 @@ static int lpc2900_handle_write_custom_command( struct command_context_s *cmd_ct
                return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
-       /* Get the bank descriptor */
-       flash_bank_t *bank = get_flash_bank_by_num(strtoul(args[0], NULL, 0));
-       if (!bank)
-       {
-               command_print(cmd_ctx, "flash bank '#%s' is out of bounds", args[0]);
-               return ERROR_OK;
-       }
+       flash_bank_t *bank;
+       int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &bank);
+       if (ERROR_OK != retval)
+               return retval;
+
        lpc2900_flash_bank_t *lpc2900_info = bank->driver_priv;
 
        /* Check if command execution is allowed. */
@@ -778,9 +747,9 @@ static int lpc2900_handle_write_custom_command( struct command_context_s *cmd_ct
        image.base_address = 0;
        image.start_address_set = 0;
 
-       char *filename = args[1];
-       char *type = (argc >= 3) ? args[2] : NULL;
-       int retval = image_open(&image, filename, type);
+       const char *filename = args[1];
+       const char *type = (argc >= 3) ? args[2] : NULL;
+       retval = image_open(&image, filename, type);
        if (retval != ERROR_OK)
        {
                return retval;
@@ -796,7 +765,8 @@ static int lpc2900_handle_write_custom_command( struct command_context_s *cmd_ct
        if( (image.sections[0].base_address != 0) ||
         (image.sections[0].size != ISS_CUSTOMER_SIZE) )
        {
-               LOG_ERROR("Incorrect image file size. Expected %" PRIu32 ", got %" PRIu32,
+               LOG_ERROR("Incorrect image file size. Expected %d, "
+                       "got %" PRIu32,
                    ISS_CUSTOMER_SIZE, image.sections[0].size);
                return ERROR_COMMAND_SYNTAX_ERROR;
        }
@@ -865,12 +835,11 @@ static int lpc2900_handle_secure_sector_command(struct command_context_s *cmd_ct
        }
 
        /* Get the bank descriptor */
-       flash_bank_t *bank = get_flash_bank_by_num(strtoul(args[0], NULL, 0));
-       if (!bank)
-       {
-               command_print(cmd_ctx, "flash bank '#%s' is out of bounds", args[0]);
-               return ERROR_OK;
-       }
+       flash_bank_t *bank;
+       int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &bank);
+       if (ERROR_OK != retval)
+               return retval;
+
        lpc2900_flash_bank_t *lpc2900_info = bank->driver_priv;
 
        /* Check if command execution is allowed. */
@@ -883,8 +852,9 @@ static int lpc2900_handle_secure_sector_command(struct command_context_s *cmd_ct
        lpc2900_info->risky = 0;
 
        /* Read sector range, and do a sanity check. */
-       int first = strtoul(args[1], NULL, 0);
-       int last = strtoul(args[2], NULL, 0);
+       int first, last;
+       COMMAND_PARSE_NUMBER(int, args[1], first);
+       COMMAND_PARSE_NUMBER(int, args[2], last);
        if( (first >= bank->num_sectors) ||
            (last >= bank->num_sectors) ||
            (first > last) )
@@ -895,7 +865,6 @@ static int lpc2900_handle_secure_sector_command(struct command_context_s *cmd_ct
 
        uint8_t page[FLASH_PAGE_SIZE];
        int sector;
-       int retval;
 
        /* Sectors in page 6 */
        if( (first <= 4) || (last >= 8) )
@@ -971,12 +940,11 @@ static int lpc2900_handle_secure_jtag_command(struct command_context_s *cmd_ctx,
        }
 
        /* Get the bank descriptor */
-       flash_bank_t *bank = get_flash_bank_by_num(strtoul(args[0], NULL, 0));
-       if (!bank)
-       {
-               command_print(cmd_ctx, "flash bank '#%s' is out of bounds", args[0]);
-               return ERROR_OK;
-       }
+       flash_bank_t *bank;
+       int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &bank);
+       if (ERROR_OK != retval)
+               return retval;
+
        lpc2900_flash_bank_t *lpc2900_info = bank->driver_priv;
 
        /* Check if command execution is allowed. */
@@ -1000,7 +968,6 @@ static int lpc2900_handle_secure_jtag_command(struct command_context_s *cmd_ctx,
        page[0x30 +  3] = 0x7F;
 
        /* Write to page 5 */
-       int retval;
        if( (retval = lpc2900_write_index_page( bank, 5, &page ))
                        != ERROR_OK )
        {
@@ -1116,7 +1083,9 @@ static int lpc2900_flash_bank_command(struct command_context_s *cmd_ctx,
         * Reject it if we can't meet the requirements for program time
         * (if clock too slow), or for erase time (clock too fast).
         */
-       lpc2900_info->clk_sys_fmc = strtoul(args[6], NULL, 0) * 1000;
+       uint32_t clk_sys_fmc;
+       COMMAND_PARSE_NUMBER(u32, args[6], clk_sys_fmc);
+       lpc2900_info->clk_sys_fmc = clk_sys_fmc * 1000;
 
        uint32_t clock_limit;
        /* Check program time limit */
@@ -1477,12 +1446,13 @@ static int lpc2900_write(struct flash_bank_s *bank, uint8_t *buffer,
                        }
 
                        /* Skip the current sector if it is secured */
-                       if( bank->sectors[start_sector].is_protected )
+                       if (bank->sectors[start_sector].is_protected)
                        {
-                               LOG_DEBUG( "Skip secured sector %" PRIu32, start_sector );
+                               LOG_DEBUG("Skip secured sector %d",
+                                               start_sector);
 
                                /* Stop if this is the last sector */
-                               if( start_sector == bank->num_sectors - 1 )
+                               if (start_sector == bank->num_sectors - 1)
                                {
                                        break;
                                }
@@ -1763,9 +1733,9 @@ static int lpc2900_probe(struct flash_bank_s *bank)
        }
 
        /* Show detected device */
-       LOG_INFO("Flash bank %" PRIu32
+       LOG_INFO("Flash bank %d"
                 ": Device %s, %" PRIu32
-                " KiB in %" PRIu32 " sectors",
+                " KiB in %d sectors",
                 bank->bank_number,
                 lpc2900_info->target_name, bank->size / KiB,
                 bank->num_sectors);
@@ -1805,7 +1775,7 @@ static int lpc2900_probe(struct flash_bank_s *bank)
                         * that has more than 19 sectors. Politely ask for a fix then.
                         */
                        bank->sectors[i].size = 0;
-                       LOG_ERROR("Never heard about sector %" PRIu32 " (FIXME please)", i);
+                       LOG_ERROR("Never heard about sector %d", i);
                }
 
                offset += bank->sectors[i].size;

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)