flash_driver_t -> struct flash_driver
[openocd.git] / src / flash / ocl.c
index e6a342e71ac93d04f064ebacd5f63226b167f97f..bd7577e3667888dd32023a7505e49d76399f4fba 100644 (file)
 #include "embeddedice.h"
 
 
-static int ocl_register_commands(struct command_context_s *cmd_ctx);
-static int ocl_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank);
-static int ocl_erase(struct flash_bank_s *bank, int first, int last);
-static int ocl_protect(struct flash_bank_s *bank, int set, int first, int last);
-static int ocl_write(struct flash_bank_s *bank, uint8_t *buffer, uint32_t offset, uint32_t count);
-static int ocl_probe(struct flash_bank_s *bank);
-static int ocl_erase_check(struct flash_bank_s *bank);
-static int ocl_protect_check(struct flash_bank_s *bank);
-static int ocl_info(struct flash_bank_s *bank, char *buf, int buf_size);
-static int ocl_auto_probe(struct flash_bank_s *bank);
-
-flash_driver_t ocl_flash =
-{
-       .name = "ocl",
-       .register_commands = ocl_register_commands,
-       .flash_bank_command = ocl_flash_bank_command,
-       .erase = ocl_erase,
-       .protect = ocl_protect,
-       .write = ocl_write,
-       .probe = ocl_probe,
-       .erase_check = ocl_erase_check,
-       .protect_check = ocl_protect_check,
-       .info = ocl_info,
-       .auto_probe = ocl_auto_probe
-};
-
 typedef struct ocl_priv_s
 {
        arm_jtag_t *jtag_info;
@@ -59,11 +33,6 @@ typedef struct ocl_priv_s
        unsigned int bufalign;
 } ocl_priv_t;
 
-static int ocl_register_commands(struct command_context_s *cmd_ctx)
-{
-       return ERROR_OK;
-}
-
 static int ocl_erase_check(struct flash_bank_s *bank)
 {
        return ERROR_OK;
@@ -75,7 +44,7 @@ static int ocl_protect_check(struct flash_bank_s *bank)
 }
 
 /* flash_bank ocl 0 0 0 0 <target#> */
-static int ocl_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank)
+FLASH_BANK_COMMAND_HANDLER(ocl_flash_bank_command)
 {
        int retval;
        armv4_5_common_t *armv4_5;
@@ -139,7 +108,7 @@ static int ocl_erase(struct flash_bank_s *bank, int first, int last)
        }
 
        /* receive response */
-       if ((retval = embeddedice_receive(ocl->jtag_info, dcc_buffer+1, 1) != ERROR_OK))
+       if ((retval = embeddedice_receive(ocl->jtag_info, dcc_buffer + 1, 1) != ERROR_OK))
                return retval;
 
        if (dcc_buffer[1] != OCL_CMD_DONE)
@@ -182,7 +151,7 @@ static int ocl_write(struct flash_bank_s *bank, uint8_t *buffer, uint32_t offset
        }
 
        /* allocate buffer for max. ocl buffer + overhead */
-       dcc_buffer = malloc(sizeof(uint32_t)*(ocl->buflen/4+3));
+       dcc_buffer = malloc(sizeof(uint32_t)*(ocl->buflen/4 + 3));
 
        while (count)
        {
@@ -200,7 +169,7 @@ static int ocl_write(struct flash_bank_s *bank, uint8_t *buffer, uint32_t offset
                chksum = OCL_CHKS_INIT;
 
                /* copy data to DCC buffer in proper byte order and properly aligned */
-               for (i=0; i<runlen; i++)
+               for (i = 0; i < runlen; i++)
                {
                        switch (byteofs++)
                        {
@@ -321,7 +290,7 @@ static int ocl_probe(struct flash_bank_s *bank)
        ocl->buflen = dcc_buffer[0] & 0xffff;
        ocl->bufalign = dcc_buffer[0] >> 16;
 
-       bank->sectors = realloc(bank->sectors, sizeof(flash_sector_t)*bank->num_sectors);
+       bank->sectors = realloc(bank->sectors, sizeof(struct flash_sector)*bank->num_sectors);
        if (bank->num_sectors == 0)
        {
                LOG_ERROR("number of sectors shall be non zero value");
@@ -332,7 +301,7 @@ static int ocl_probe(struct flash_bank_s *bank)
                return ERROR_FLASH_BANK_INVALID;
        }
        sectsize = bank->size / bank->num_sectors;
-       for (i=0; i<bank->num_sectors; i++)
+       for (i = 0; i < bank->num_sectors; i++)
        {
                bank->sectors[i].offset = i * sectsize;
                bank->sectors[i].size = sectsize;
@@ -378,3 +347,16 @@ static int ocl_auto_probe(struct flash_bank_s *bank)
 
        return ERROR_OK;
 }
+
+struct flash_driver ocl_flash = {
+               .name = "ocl",
+               .flash_bank_command = &ocl_flash_bank_command,
+               .erase = &ocl_erase,
+               .protect = &ocl_protect,
+               .write = &ocl_write,
+               .probe = &ocl_probe,
+               .erase_check = &ocl_erase_check,
+               .protect_check = &ocl_protect_check,
+               .info = &ocl_info,
+               .auto_probe = &ocl_auto_probe,
+       };

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)