flash_driver_t -> struct flash_driver
[openocd.git] / src / flash / pic32mx.c
index 48ba38c323e5027adf8a17d5cb914d69bccf8e13..18dfa979386cb0d277dcfc722f2b7c30f4d5d4ac 100644 (file)
@@ -57,62 +57,12 @@ struct pic32mx_devs_s {
        { 0x00, NULL, 0 }
 };
 
-static int pic32mx_register_commands(struct command_context_s *cmd_ctx);
-static int pic32mx_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank);
-static int pic32mx_erase(struct flash_bank_s *bank, int first, int last);
-static int pic32mx_protect(struct flash_bank_s *bank, int set, int first, int last);
-static int pic32mx_write(struct flash_bank_s *bank, uint8_t *buffer, uint32_t offset, uint32_t count);
 static int pic32mx_write_row(struct flash_bank_s *bank, uint32_t address, uint32_t srcaddr);
 static int pic32mx_write_word(struct flash_bank_s *bank, uint32_t address, uint32_t word);
-static int pic32mx_probe(struct flash_bank_s *bank);
-static int pic32mx_auto_probe(struct flash_bank_s *bank);
-//static int pic32mx_handle_part_id_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
-static int pic32mx_protect_check(struct flash_bank_s *bank);
-static int pic32mx_info(struct flash_bank_s *bank, char *buf, int buf_size);
-
-#if 0
-int pic32mx_handle_lock_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
-int pic32mx_handle_unlock_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
-#endif
-static int pic32mx_handle_chip_erase_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
-static int pic32mx_handle_pgm_word_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
-//static int pic32mx_chip_erase(struct flash_bank_s *bank);
-
-flash_driver_t pic32mx_flash =
-{
-       .name = "pic32mx",
-       .register_commands = pic32mx_register_commands,
-       .flash_bank_command = pic32mx_flash_bank_command,
-       .erase = pic32mx_erase,
-       .protect = pic32mx_protect,
-       .write = pic32mx_write,
-       .probe = pic32mx_probe,
-       .auto_probe = pic32mx_auto_probe,
-       .erase_check = default_flash_mem_blank_check,
-       .protect_check = pic32mx_protect_check,
-       .info = pic32mx_info
-};
-
-static int pic32mx_register_commands(struct command_context_s *cmd_ctx)
-{
-       command_t *pic32mx_cmd = register_command(cmd_ctx, NULL, "pic32mx", NULL, COMMAND_ANY, "pic32mx flash specific commands");
-
-#if 0
-       register_command(cmd_ctx, pic32mx_cmd, "lock", pic32mx_handle_lock_command, COMMAND_EXEC,
-                                        "lock device");
-       register_command(cmd_ctx, pic32mx_cmd, "unlock", pic32mx_handle_unlock_command, COMMAND_EXEC,
-                                        "unlock protected device");
-#endif
-       register_command(cmd_ctx, pic32mx_cmd, "chip_erase", pic32mx_handle_chip_erase_command, COMMAND_EXEC,
-                                        "erase device");
-       register_command(cmd_ctx, pic32mx_cmd, "pgm_word", pic32mx_handle_pgm_word_command, COMMAND_EXEC,
-                                        "program a word");
-       return ERROR_OK;
-}
 
 /* flash bank pic32mx <base> <size> 0 0 <target#>
  */
-static int pic32mx_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank)
+FLASH_BANK_COMMAND_HANDLER(pic32mx_flash_bank_command)
 {
        pic32mx_flash_bank_t *pic32mx_info;
 
@@ -657,7 +607,7 @@ static int pic32mx_probe(struct flash_bank_s *bank)
        bank->num_sectors = num_pages;
        bank->chip_width = 4;
        bank->bus_width  = 4;
-       bank->sectors = malloc(sizeof(flash_sector_t) * num_pages);
+       bank->sectors = malloc(sizeof(struct flash_sector) * num_pages);
 
        for (i = 0; i < num_pages; i++)
        {
@@ -681,7 +631,7 @@ static int pic32mx_auto_probe(struct flash_bank_s *bank)
 }
 
 #if 0
-static int pic32mx_handle_part_id_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+COMMAND_HANDLER(pic32mx_handle_part_id_command)
 {
        return ERROR_OK;
 }
@@ -722,9 +672,8 @@ static int pic32mx_info(struct flash_bank_s *bank, char *buf, int buf_size)
 }
 
 #if 0
-int pic32mx_handle_lock_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+COMMAND_HANDLER(pic32mx_handle_lock_command)
 {
-       flash_bank_t *bank;
        target_t *target = NULL;
        pic32mx_flash_bank_t *pic32mx_info = NULL;
 
@@ -734,12 +683,10 @@ int pic32mx_handle_lock_command(struct command_context_s *cmd_ctx, char *cmd, ch
                return ERROR_OK;
        }
 
-       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;
 
        pic32mx_info = bank->driver_priv;
 
@@ -771,9 +718,8 @@ int pic32mx_handle_lock_command(struct command_context_s *cmd_ctx, char *cmd, ch
        return ERROR_OK;
 }
 
-int pic32mx_handle_unlock_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+COMMAND_HANDLER(pic32mx_handle_unlock_command)
 {
-       flash_bank_t *bank;
        target_t *target = NULL;
        pic32mx_flash_bank_t *pic32mx_info = NULL;
 
@@ -783,12 +729,10 @@ int pic32mx_handle_unlock_command(struct command_context_s *cmd_ctx, char *cmd,
                return ERROR_OK;
        }
 
-       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;
 
        pic32mx_info = bank->driver_priv;
 
@@ -864,10 +808,9 @@ static int pic32mx_chip_erase(struct flash_bank_s *bank)
 }
 #endif
 
-static int pic32mx_handle_chip_erase_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+COMMAND_HANDLER(pic32mx_handle_chip_erase_command)
 {
 #if 0
-       flash_bank_t *bank;
        int i;
 
        if (argc != 0)
@@ -876,12 +819,10 @@ static int pic32mx_handle_chip_erase_command(struct command_context_s *cmd_ctx,
                return ERROR_OK;
        }
 
-       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 (pic32mx_chip_erase(bank) == ERROR_OK)
        {
@@ -902,9 +843,8 @@ static int pic32mx_handle_chip_erase_command(struct command_context_s *cmd_ctx,
        return ERROR_OK;
 }
 
-static int pic32mx_handle_pgm_word_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+COMMAND_HANDLER(pic32mx_handle_pgm_word_command)
 {
-       flash_bank_t *bank;
        uint32_t address, value;
        int status, res;
 
@@ -914,15 +854,14 @@ static int pic32mx_handle_pgm_word_command(struct command_context_s *cmd_ctx, ch
                return ERROR_OK;
        }
 
-       address = strtoul(args[0], NULL, 0);
-       value   = strtoul(args[1], NULL, 0);
+       COMMAND_PARSE_NUMBER(u32, args[0], address);
+       COMMAND_PARSE_NUMBER(u32, args[1], value);
+
+       flash_bank_t *bank;
+       int retval = flash_command_get_bank_by_num(cmd_ctx, args[2], &bank);
+       if (ERROR_OK != retval)
+               return retval;
 
-       bank = get_flash_bank_by_num(strtoul(args[2], NULL, 0));
-       if (!bank)
-       {
-               command_print(cmd_ctx, "flash bank '#%s' is out of bounds", args[2]);
-               return ERROR_OK;
-       }
        if (address < bank->base || address >= (bank->base + bank->size))
        {
                command_print(cmd_ctx, "flash address '%s' is out of bounds", args[0]);
@@ -943,3 +882,38 @@ static int pic32mx_handle_pgm_word_command(struct command_context_s *cmd_ctx, ch
 
        return ERROR_OK;
 }
+
+static int pic32mx_register_commands(struct command_context_s *cmd_ctx)
+{
+       command_t *pic32mx_cmd = register_command(cmd_ctx, NULL, "pic32mx",
+                       NULL, COMMAND_ANY, "pic32mx flash specific commands");
+#if 0
+       register_command(cmd_ctx, pic32mx_cmd, "lock",
+                       pic32mx_handle_lock_command, COMMAND_EXEC,
+                       "lock device");
+       register_command(cmd_ctx, pic32mx_cmd, "unlock",
+                       pic32mx_handle_unlock_command, COMMAND_EXEC,
+                       "unlock protected device");
+#endif
+       register_command(cmd_ctx, pic32mx_cmd, "chip_erase",
+                       pic32mx_handle_chip_erase_command, COMMAND_EXEC,
+                       "erase device");
+       register_command(cmd_ctx, pic32mx_cmd, "pgm_word",
+                       pic32mx_handle_pgm_word_command, COMMAND_EXEC,
+                       "program a word");
+       return ERROR_OK;
+}
+
+struct flash_driver pic32mx_flash = {
+               .name = "pic32mx",
+               .register_commands = &pic32mx_register_commands,
+               .flash_bank_command = &pic32mx_flash_bank_command,
+               .erase = &pic32mx_erase,
+               .protect = &pic32mx_protect,
+               .write = &pic32mx_write,
+               .probe = &pic32mx_probe,
+               .auto_probe = &pic32mx_auto_probe,
+               .erase_check = &default_flash_mem_blank_check,
+               .protect_check = &pic32mx_protect_check,
+               .info = &pic32mx_info,
+       };

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)