X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fflash%2Focl.c;h=10ac230e04a96b16504f14a719348248bb7d8555;hb=92fc7a6fdecac39ebc890ee3c2ae91f3fd50fdc5;hp=4f3b506cbbb361ff48dd939fa287e3ffaf0f2369;hpb=040e25424314b49e35eb158eb88e287c76e50596;p=openocd diff --git a/src/flash/ocl.c b/src/flash/ocl.c index 4f3b506c..10ac230e 100644 --- a/src/flash/ocl.c +++ b/src/flash/ocl.c @@ -21,82 +21,35 @@ #include "config.h" #endif -#include "replacements.h" - #include "ocl.h" - #include "flash.h" -#include "target.h" -#include "log.h" -#include "binarybuffer.h" -#include "types.h" #include "embeddedice.h" -#include "arm7_9_common.h" - -#include -#include -#include - -int ocl_register_commands(struct command_context_s *cmd_ctx); -int ocl_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank); -int ocl_erase(struct flash_bank_s *bank, int first, int last); -int ocl_protect(struct flash_bank_s *bank, int set, int first, int last); -int ocl_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count); -int ocl_probe(struct flash_bank_s *bank); -int ocl_erase_check(struct flash_bank_s *bank); -int ocl_protect_check(struct flash_bank_s *bank); -int ocl_info(struct flash_bank_s *bank, char *buf, int buf_size); -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 +struct ocl_priv { arm_jtag_t *jtag_info; - int buflen; - int bufalign; -} ocl_priv_t; - - -int ocl_register_commands(struct command_context_s *cmd_ctx) -{ - return ERROR_OK; -} - + unsigned int buflen; + unsigned int bufalign; +}; -int ocl_erase_check(struct flash_bank_s *bank) +static int ocl_erase_check(struct flash_bank_s *bank) { return ERROR_OK; } - -int ocl_protect_check(struct flash_bank_s *bank) +static int ocl_protect_check(struct flash_bank_s *bank) { return ERROR_OK; } - /* flash_bank ocl 0 0 0 0 */ -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; arm7_9_common_t *arm7_9; - ocl_priv_t *ocl; + struct ocl_priv *ocl; if (argc < 6) { @@ -107,7 +60,7 @@ int ocl_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char ** if ((retval = arm7_9_get_arch_pointers(bank->target, &armv4_5, &arm7_9)) != ERROR_OK) return retval; - ocl = bank->driver_priv = malloc(sizeof(ocl_priv_t)); + ocl = bank->driver_priv = malloc(sizeof(struct ocl_priv)); ocl->jtag_info = &arm7_9->jtag_info; ocl->buflen = 0; ocl->bufalign = 1; @@ -115,23 +68,22 @@ int ocl_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char ** return ERROR_OK; } - -int ocl_erase(struct flash_bank_s *bank, int first, int last) +static int ocl_erase(struct flash_bank_s *bank, int first, int last) { - ocl_priv_t *ocl = bank->driver_priv; + struct ocl_priv *ocl = bank->driver_priv; int retval; - u32 dcc_buffer[3]; + uint32_t dcc_buffer[3]; /* check preconditions */ if (bank->num_sectors == 0) return ERROR_FLASH_BANK_NOT_PROBED; - + if (bank->target->state != TARGET_RUNNING) { LOG_ERROR("target has to be running to communicate with the loader"); return ERROR_TARGET_NOT_RUNNING; } - + if ((first == 0) && (last == bank->num_sectors - 1)) { dcc_buffer[0] = OCL_ERASE_ALL; @@ -156,42 +108,40 @@ 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) { if (dcc_buffer[0] == OCL_ERASE_ALL) - LOG_ERROR("loader response to OCL_ERASE_ALL 0x%08lX", dcc_buffer[1]); + LOG_ERROR("loader response to OCL_ERASE_ALL 0x%08" PRIx32 "", dcc_buffer[1]); else - LOG_ERROR("loader response to OCL_ERASE_BLOCK 0x%08lX", dcc_buffer[1]); + LOG_ERROR("loader response to OCL_ERASE_BLOCK 0x%08" PRIx32 "", dcc_buffer[1]); return ERROR_FLASH_OPERATION_FAILED; } return ERROR_OK; } - -int ocl_protect(struct flash_bank_s *bank, int set, int first, int last) +static int ocl_protect(struct flash_bank_s *bank, int set, int first, int last) { return ERROR_OK; } - -int ocl_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count) +static int ocl_write(struct flash_bank_s *bank, uint8_t *buffer, uint32_t offset, uint32_t count) { - ocl_priv_t *ocl = bank->driver_priv; + struct ocl_priv *ocl = bank->driver_priv; int retval; - u32 *dcc_buffer; - u32 *dcc_bufptr; + uint32_t *dcc_buffer; + uint32_t *dcc_bufptr; int byteofs; int runlen; - u32 chksum; - + uint32_t chksum; + int i; /* check preconditions */ - if (ocl->buflen == 0 || ocl->bufalign==0) + if (ocl->buflen == 0 || ocl->bufalign == 0) return ERROR_FLASH_BANK_NOT_PROBED; if (bank->target->state != TARGET_RUNNING) @@ -201,7 +151,7 @@ int ocl_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count) } /* allocate buffer for max. ocl buffer + overhead */ - dcc_buffer = malloc(sizeof(u32)*(ocl->buflen/4+3)); + dcc_buffer = malloc(sizeof(uint32_t)*(ocl->buflen/4 + 3)); while (count) { @@ -219,7 +169,7 @@ int ocl_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count) chksum = OCL_CHKS_INIT; /* copy data to DCC buffer in proper byte order and properly aligned */ - for (i=0; ijtag_info, dcc_buffer, dcc_bufptr-dcc_buffer)) != ERROR_OK) { @@ -272,7 +222,7 @@ int ocl_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count) if (dcc_buffer[0] != OCL_CMD_DONE) { - LOG_ERROR("loader response to OCL_FLASH_BLOCK 0x%08lX", dcc_buffer[0]); + LOG_ERROR("loader response to OCL_FLASH_BLOCK 0x%08" PRIx32 "", dcc_buffer[0]); free(dcc_buffer); return ERROR_FLASH_OPERATION_FAILED; } @@ -285,12 +235,11 @@ int ocl_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count) return ERROR_OK; } - -int ocl_probe(struct flash_bank_s *bank) +static int ocl_probe(struct flash_bank_s *bank) { - ocl_priv_t *ocl = bank->driver_priv; + struct ocl_priv *ocl = bank->driver_priv; int retval; - u32 dcc_buffer[1]; + uint32_t dcc_buffer[1]; int sectsize; int i; @@ -312,10 +261,10 @@ int ocl_probe(struct flash_bank_s *bank) /* receive response */ if ((retval = embeddedice_receive(ocl->jtag_info, dcc_buffer, 1) != ERROR_OK)) return retval; - + if (dcc_buffer[0] != OCL_CMD_DONE) { - LOG_ERROR("loader response to OCL_PROBE 0x%08lX", dcc_buffer[0]); + LOG_ERROR("loader response to OCL_PROBE 0x%08" PRIx32 "", dcc_buffer[0]); return ERROR_FLASH_OPERATION_FAILED; } @@ -341,7 +290,7 @@ 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"); @@ -352,7 +301,7 @@ int ocl_probe(struct flash_bank_s *bank) return ERROR_FLASH_BANK_INVALID; } sectsize = bank->size / bank->num_sectors; - for (i=0; inum_sectors; i++) + for (i = 0; i < bank->num_sectors; i++) { bank->sectors[i].offset = i * sectsize; bank->sectors[i].size = sectsize; @@ -384,19 +333,30 @@ int ocl_probe(struct flash_bank_s *bank) return ERROR_OK; } - -int ocl_info(struct flash_bank_s *bank, char *buf, int buf_size) +static int ocl_info(struct flash_bank_s *bank, char *buf, int buf_size) { return ERROR_OK; } - -int ocl_auto_probe(struct flash_bank_s *bank) +static int ocl_auto_probe(struct flash_bank_s *bank) { - ocl_priv_t *ocl = bank->driver_priv; + struct ocl_priv *ocl = bank->driver_priv; - if (ocl->buflen == 0 || ocl->bufalign==0) + if (ocl->buflen == 0 || ocl->bufalign == 0) return ERROR_FLASH_BANK_NOT_PROBED; 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, + };