Commit 0cba0d4d authored by ntfreak's avatar ntfreak
Browse files

- remove target specific variant and use target->variant member

- fix build warning in cortex_m3
- code cleanup - remove trailing lf and convert c++ comments

git-svn-id: svn://svn.berlios.de/openocd/trunk@1238 b42882b7-edfa-0310-969c-e2dbd0fdcd60
parent 846a2589
...@@ -148,10 +148,10 @@ typedef struct cfi_fixup_s ...@@ -148,10 +148,10 @@ typedef struct cfi_fixup_s
} cfi_fixup_t; } cfi_fixup_t;
#define CFI_MFR_AMD 0x0001 #define CFI_MFR_AMD 0x0001
#define CFI_MFR_FUJITSU 0x0004 #define CFI_MFR_FUJITSU 0x0004
#define CFI_MFR_ATMEL 0x001F #define CFI_MFR_ATMEL 0x001F
#define CFI_MFR_ST 0x0020 /* STMicroelectronics */ #define CFI_MFR_ST 0x0020 /* STMicroelectronics */
#define CFI_MFR_AMIC 0x0037 #define CFI_MFR_AMIC 0x0037
#define CFI_MFR_SST 0x00BF #define CFI_MFR_SST 0x00BF
#define CFI_MFR_MX 0x00C2 #define CFI_MFR_MX 0x00C2
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#include "replacements.h" #include "replacements.h"
#include "flash.h" #include "flash.h"
#include "target.h" #include "target.h"
...@@ -37,8 +36,6 @@ ...@@ -37,8 +36,6 @@
#include "../target/embeddedice.h" #include "../target/embeddedice.h"
#include "types.h" #include "types.h"
int ecosflash_register_commands(struct command_context_s *cmd_ctx); int ecosflash_register_commands(struct command_context_s *cmd_ctx);
int ecosflash_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank); int ecosflash_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank);
int ecosflash_erase(struct flash_bank_s *bank, int first, int last); int ecosflash_erase(struct flash_bank_s *bank, int first, int last);
...@@ -99,42 +96,41 @@ flash_errmsg(int err); ...@@ -99,42 +96,41 @@ flash_errmsg(int err);
#define FLASH_ERR_DRV_WRONG_PART 0x0d /* Driver does not support device */ #define FLASH_ERR_DRV_WRONG_PART 0x0d /* Driver does not support device */
#define FLASH_ERR_LOW_VOLTAGE 0x0e /* Not enough juice to complete job */ #define FLASH_ERR_LOW_VOLTAGE 0x0e /* Not enough juice to complete job */
char * char *
flash_errmsg(int err) flash_errmsg(int err)
{ {
switch (err) { switch (err) {
case FLASH_ERR_OK: case FLASH_ERR_OK:
return "No error - operation complete"; return "No error - operation complete";
case FLASH_ERR_ERASE_SUSPEND: case FLASH_ERR_ERASE_SUSPEND:
return "Device is in erase suspend state"; return "Device is in erase suspend state";
case FLASH_ERR_PROGRAM_SUSPEND: case FLASH_ERR_PROGRAM_SUSPEND:
return "Device is in program suspend state"; return "Device is in program suspend state";
case FLASH_ERR_INVALID: case FLASH_ERR_INVALID:
return "Invalid FLASH address"; return "Invalid FLASH address";
case FLASH_ERR_ERASE: case FLASH_ERR_ERASE:
return "Error trying to erase"; return "Error trying to erase";
case FLASH_ERR_LOCK: case FLASH_ERR_LOCK:
return "Error trying to lock/unlock"; return "Error trying to lock/unlock";
case FLASH_ERR_PROGRAM: case FLASH_ERR_PROGRAM:
return "Error trying to program"; return "Error trying to program";
case FLASH_ERR_PROTOCOL: case FLASH_ERR_PROTOCOL:
return "Generic error"; return "Generic error";
case FLASH_ERR_PROTECT: case FLASH_ERR_PROTECT:
return "Device/region is write-protected"; return "Device/region is write-protected";
case FLASH_ERR_NOT_INIT: case FLASH_ERR_NOT_INIT:
return "FLASH sub-system not initialized"; return "FLASH sub-system not initialized";
case FLASH_ERR_DRV_VERIFY: case FLASH_ERR_DRV_VERIFY:
return "Data verify failed after operation"; return "Data verify failed after operation";
case FLASH_ERR_DRV_TIMEOUT: case FLASH_ERR_DRV_TIMEOUT:
return "Driver timed out waiting for device"; return "Driver timed out waiting for device";
case FLASH_ERR_DRV_WRONG_PART: case FLASH_ERR_DRV_WRONG_PART:
return "Driver does not support device"; return "Driver does not support device";
case FLASH_ERR_LOW_VOLTAGE: case FLASH_ERR_LOW_VOLTAGE:
return "Device reports low voltage"; return "Device reports low voltage";
default: default:
return "Unknown error"; return "Unknown error";
} }
} }
#endif #endif
...@@ -185,7 +181,6 @@ int ecosflash_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, c ...@@ -185,7 +181,6 @@ int ecosflash_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, c
return ERROR_OK; return ERROR_OK;
} }
int loadDriver(ecosflash_flash_bank_t *info) int loadDriver(ecosflash_flash_bank_t *info)
{ {
u32 buf_cnt; u32 buf_cnt;
...@@ -228,7 +223,6 @@ int loadDriver(ecosflash_flash_bank_t *info) ...@@ -228,7 +223,6 @@ int loadDriver(ecosflash_flash_bank_t *info)
return ERROR_OK; return ERROR_OK;
} }
static int const OFFSET_ERASE=0x0; static int const OFFSET_ERASE=0x0;
static int const OFFSET_ERASE_SIZE=0x8; static int const OFFSET_ERASE_SIZE=0x8;
static int const OFFSET_FLASH=0xc; static int const OFFSET_FLASH=0xc;
...@@ -236,7 +230,6 @@ static int const OFFSET_FLASH_SIZE=0x8; ...@@ -236,7 +230,6 @@ static int const OFFSET_FLASH_SIZE=0x8;
static int const OFFSET_GET_WORKAREA=0x18; static int const OFFSET_GET_WORKAREA=0x18;
static int const OFFSET_GET_WORKAREA_SIZE=0x4; static int const OFFSET_GET_WORKAREA_SIZE=0x4;
int runCode(ecosflash_flash_bank_t *info, int runCode(ecosflash_flash_bank_t *info,
u32 codeStart, u32 codeStop, u32 r0, u32 r1, u32 r2, u32 codeStart, u32 codeStop, u32 r0, u32 r1, u32 r2,
u32 *result, u32 *result,
...@@ -334,8 +327,8 @@ int eCosBoard_flash(ecosflash_flash_bank_t *info, void *data, u32 address, u32 l ...@@ -334,8 +327,8 @@ int eCosBoard_flash(ecosflash_flash_bank_t *info, void *data, u32 address, u32 l
int i; int i;
for (i=0; i<len; i+=chunk) for (i=0; i<len; i+=chunk)
{ {
int t=len-i; int t=len-i;
if (t>chunk) if (t>chunk)
{ {
...@@ -343,38 +336,36 @@ int eCosBoard_flash(ecosflash_flash_bank_t *info, void *data, u32 address, u32 l ...@@ -343,38 +336,36 @@ int eCosBoard_flash(ecosflash_flash_bank_t *info, void *data, u32 address, u32 l
} }
int retval; int retval;
retval=target_write_buffer(target, buffer, t, ((u8 *)data)+i); retval=target_write_buffer(target, buffer, t, ((u8 *)data)+i);
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
u32 flashErr; u32 flashErr;
retval=runCode(info, retval=runCode(info,
info->start_address+OFFSET_FLASH, info->start_address+OFFSET_FLASH,
info->start_address+OFFSET_FLASH+OFFSET_FLASH_SIZE, info->start_address+OFFSET_FLASH+OFFSET_FLASH_SIZE,
buffer, buffer,
address+i, address+i,
t, t,
&flashErr, &flashErr,
timeout); timeout);
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
if (flashErr != 0x0) if (flashErr != 0x0)
{ {
LOG_ERROR("Flash prog failed with %d (%s)\n", flashErr, flash_errmsg(flashErr)); LOG_ERROR("Flash prog failed with %d (%s)\n", flashErr, flash_errmsg(flashErr));
return ERROR_FAIL; return ERROR_FAIL;
} }
} }
return ERROR_OK; return ERROR_OK;
} }
int ecosflash_probe(struct flash_bank_s *bank) int ecosflash_probe(struct flash_bank_s *bank)
{ {
return ERROR_OK; return ERROR_OK;
} }
int ecosflash_register_commands(struct command_context_s *cmd_ctx) int ecosflash_register_commands(struct command_context_s *cmd_ctx)
{ {
register_command(cmd_ctx, NULL, "ecosflash", NULL, COMMAND_ANY, NULL); register_command(cmd_ctx, NULL, "ecosflash", NULL, COMMAND_ANY, NULL);
...@@ -382,7 +373,7 @@ int ecosflash_register_commands(struct command_context_s *cmd_ctx) ...@@ -382,7 +373,7 @@ int ecosflash_register_commands(struct command_context_s *cmd_ctx)
return ERROR_OK; return ERROR_OK;
} }
/* #if 0
static void command(flash_bank_t *bank, u8 cmd, u8 *cmd_buf) static void command(flash_bank_t *bank, u8 cmd, u8 *cmd_buf)
{ {
ecosflash_flash_bank_t *info = bank->driver_priv; ecosflash_flash_bank_t *info = bank->driver_priv;
...@@ -403,7 +394,7 @@ static void command(flash_bank_t *bank, u8 cmd, u8 *cmd_buf) ...@@ -403,7 +394,7 @@ static void command(flash_bank_t *bank, u8 cmd, u8 *cmd_buf)
} }
} }
} }
*/ #endif
u32 ecosflash_address(struct flash_bank_s *bank, u32 address) u32 ecosflash_address(struct flash_bank_s *bank, u32 address)
{ {
...@@ -421,7 +412,6 @@ u32 ecosflash_address(struct flash_bank_s *bank, u32 address) ...@@ -421,7 +412,6 @@ u32 ecosflash_address(struct flash_bank_s *bank, u32 address)
return retval + bank->base; return retval + bank->base;
} }
int ecosflash_erase(struct flash_bank_s *bank, int first, int last) int ecosflash_erase(struct flash_bank_s *bank, int first, int last)
{ {
struct flash_bank_s *c=bank; struct flash_bank_s *c=bank;
...@@ -434,7 +424,6 @@ int ecosflash_protect(struct flash_bank_s *bank, int set, int first, int last) ...@@ -434,7 +424,6 @@ int ecosflash_protect(struct flash_bank_s *bank, int set, int first, int last)
return ERROR_OK; return ERROR_OK;
} }
int ecosflash_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count) int ecosflash_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count)
{ {
ecosflash_flash_bank_t *info = bank->driver_priv; ecosflash_flash_bank_t *info = bank->driver_priv;
...@@ -442,7 +431,6 @@ int ecosflash_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count ...@@ -442,7 +431,6 @@ int ecosflash_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count
return eCosBoard_flash(info, buffer, c->base+offset, count); return eCosBoard_flash(info, buffer, c->base+offset, count);
} }
int ecosflash_protect_check(struct flash_bank_s *bank) int ecosflash_protect_check(struct flash_bank_s *bank)
{ {
return ERROR_OK; return ERROR_OK;
...@@ -455,7 +443,6 @@ int ecosflash_info(struct flash_bank_s *bank, char *buf, int buf_size) ...@@ -455,7 +443,6 @@ int ecosflash_info(struct flash_bank_s *bank, char *buf, int buf_size)
return ERROR_OK; return ERROR_OK;
} }
u32 ecosflash_get_flash_status(flash_bank_t *bank) u32 ecosflash_get_flash_status(flash_bank_t *bank)
{ {
return ERROR_OK; return ERROR_OK;
...@@ -475,7 +462,3 @@ int ecosflash_handle_gpnvm_command(struct command_context_s *cmd_ctx, char *cmd, ...@@ -475,7 +462,3 @@ int ecosflash_handle_gpnvm_command(struct command_context_s *cmd_ctx, char *cmd,
{ {
return ERROR_OK; return ERROR_OK;
} }
...@@ -466,7 +466,6 @@ int handle_flash_erase_check_command(struct command_context_s *cmd_ctx, char *cm ...@@ -466,7 +466,6 @@ int handle_flash_erase_check_command(struct command_context_s *cmd_ctx, char *cm
j, p->sectors[j].offset, p->sectors[j].size, p->sectors[j].size>>10, j, p->sectors[j].offset, p->sectors[j].size, p->sectors[j].size>>10,
erase_state); erase_state);
} }
} }
return ERROR_OK; return ERROR_OK;
...@@ -658,7 +657,6 @@ int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cm ...@@ -658,7 +657,6 @@ int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cm
command_print(cmd_ctx, "auto erase enabled"); command_print(cmd_ctx, "auto erase enabled");
} }
if (argc < 1) if (argc < 1)
{ {
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
...@@ -743,7 +741,6 @@ int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cmd, char ...@@ -743,7 +741,6 @@ int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cmd, char
if(count == 0) if(count == 0)
return ERROR_OK; return ERROR_OK;
switch(cmd[4]) switch(cmd[4])
{ {
case 'w': case 'w':
...@@ -804,7 +801,6 @@ int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cmd, char ...@@ -804,7 +801,6 @@ int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cmd, char
return retval; return retval;
} }
if(err == ERROR_OK) if(err == ERROR_OK)
{ {
float speed; float speed;
......
...@@ -577,7 +577,7 @@ int lpc2000_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count) ...@@ -577,7 +577,7 @@ int lpc2000_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count)
break; break;
if (bytes_remaining >= thisrun_bytes) if (bytes_remaining >= thisrun_bytes)
{ {
if ((retval = target_write_buffer(bank->target, download_area->address, thisrun_bytes, buffer + bytes_written)) != ERROR_OK) if ((retval = target_write_buffer(bank->target, download_area->address, thisrun_bytes, buffer + bytes_written)) != ERROR_OK)
{ {
retval = ERROR_FLASH_OPERATION_FAILED; retval = ERROR_FLASH_OPERATION_FAILED;
......
...@@ -126,7 +126,6 @@ flash_driver_t lpc288x_flash = ...@@ -126,7 +126,6 @@ flash_driver_t lpc288x_flash =
.info = lpc288x_info .info = lpc288x_info
}; };
int lpc288x_register_commands(struct command_context_s *cmd_ctx) int lpc288x_register_commands(struct command_context_s *cmd_ctx)
{ {
return ERROR_OK; return ERROR_OK;
...@@ -204,7 +203,7 @@ int lpc288x_read_part_info(struct flash_bank_s *bank) ...@@ -204,7 +203,7 @@ int lpc288x_read_part_info(struct flash_bank_s *bank)
int lpc288x_protect_check(struct flash_bank_s *bank) int lpc288x_protect_check(struct flash_bank_s *bank)
{ {
return ERROR_OK; return ERROR_OK;
} }
/* flash_bank LPC288x 0 0 0 0 <target#> <cclk> */ /* flash_bank LPC288x 0 0 0 0 <target#> <cclk> */
......
...@@ -69,7 +69,7 @@ nand_flash_controller_t lpc3180_nand_controller = ...@@ -69,7 +69,7 @@ nand_flash_controller_t lpc3180_nand_controller =
int lpc3180_nand_device_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct nand_device_s *device) int lpc3180_nand_device_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct nand_device_s *device)
{ {
lpc3180_nand_controller_t *lpc3180_info; lpc3180_nand_controller_t *lpc3180_info;
if (argc < 3) if (argc < 3)
{ {
LOG_WARNING("incomplete 'lpc3180' nand flash configuration"); LOG_WARNING("incomplete 'lpc3180' nand flash configuration");
...@@ -126,7 +126,7 @@ int lpc3180_pll(int fclkin, u32 pll_ctrl) ...@@ -126,7 +126,7 @@ int lpc3180_pll(int fclkin, u32 pll_ctrl)
if (bypass && !direct) /* bypass mode */ if (bypass && !direct) /* bypass mode */
return fclkin / (2 * p); return fclkin / (2 * p);
if (bypass & direct) /* direct bypass mode */ if (bypass & direct) /* direct bypass mode */
return fclkin; return fclkin;
...@@ -273,7 +273,7 @@ int lpc3180_init(struct nand_device_s *device) ...@@ -273,7 +273,7 @@ int lpc3180_init(struct nand_device_s *device)
trhz = ((30 / cycle) + 1); trhz = ((30 / cycle) + 1);
trbwb = ((100 / cycle) + 1); trbwb = ((100 / cycle) + 1);
tcea = ((45 / cycle) + 1); tcea = ((45 / cycle) + 1);
/* MLC_LOCK = 0xa25e (unlock protected registers) */ /* MLC_LOCK = 0xa25e (unlock protected registers) */
target_write_u32(target, 0x200b8044, 0xa25e); target_write_u32(target, 0x200b8044, 0xa25e);
......
...@@ -80,7 +80,7 @@ static int pxa270_set_gpio_to_output (mflash_gpio_num_t gpio) ...@@ -80,7 +80,7 @@ static int pxa270_set_gpio_to_output (mflash_gpio_num_t gpio)
target_t *target = mflash_bank->target; target_t *target = mflash_bank->target;
int ret; int ret;
// remove alternate function. /* remove alternate function. */
mask = 0x3u << (gpio.num & 0xF)*2; mask = 0x3u << (gpio.num & 0xF)*2;
addr = PXA270_GAFR0_L + (gpio.num >> 4) * 4; addr = PXA270_GAFR0_L + (gpio.num >> 4) * 4;
...@@ -95,7 +95,7 @@ static int pxa270_set_gpio_to_output (mflash_gpio_num_t gpio) ...@@ -95,7 +95,7 @@ static int pxa270_set_gpio_to_output (mflash_gpio_num_t gpio)
if ((ret = target_write_u32(target, addr, value)) != ERROR_OK) if ((ret = target_write_u32(target, addr, value)) != ERROR_OK)
return ret; return ret;
// set direction to output /* set direction to output */
mask = 0x1u << (gpio.num & 0x1F); mask = 0x1u << (gpio.num & 0x1F);
addr = PXA270_GPDR0 + (gpio.num >> 5) * 4; addr = PXA270_GPDR0 + (gpio.num >> 5) * 4;
...@@ -261,75 +261,75 @@ static int mg_dsk_wait(mg_io_type_wait wait, u32 time) ...@@ -261,75 +261,75 @@ static int mg_dsk_wait(mg_io_type_wait wait, u32 time)
duration_start_measure(&duration); duration_start_measure(&duration);
while (time) { while (time) {
target_read_u8(target, mg_task_reg + MG_REG_STATUS, &status); target_read_u8(target, mg_task_reg + MG_REG_STATUS, &status);
if (status & mg_io_rbit_status_busy) if (status & mg_io_rbit_status_busy)
{ {
if (wait == mg_io_wait_bsy) if (wait == mg_io_wait_bsy)
return ERROR_OK; return ERROR_OK;
} else { } else {
switch(wait) switch(wait)
{ {
case mg_io_wait_not_bsy: case mg_io_wait_not_bsy:
return ERROR_OK; return ERROR_OK;
case mg_io_wait_rdy_noerr: case mg_io_wait_rdy_noerr:
if (status & mg_io_rbit_status_ready) if (status & mg_io_rbit_status_ready)
return ERROR_OK; return ERROR_OK;
break; break;
case mg_io_wait_drq_noerr: case mg_io_wait_drq_noerr:
if (status & mg_io_rbit_status_data_req) if (status & mg_io_rbit_status_data_req)
return ERROR_OK; return ERROR_OK;
break; break;
default: default:
break; break;
} }
// Now we check the error condition! /* Now we check the error condition! */
if (status & mg_io_rbit_status_error) if (status & mg_io_rbit_status_error)
{ {
target_read_u8(target, mg_task_reg + MG_REG_ERROR, &error); target_read_u8(target, mg_task_reg + MG_REG_ERROR, &error);
if (error & mg_io_rbit_err_bad_sect_num) { if (error & mg_io_rbit_err_bad_sect_num) {
LOG_ERROR("sector not found"); LOG_ERROR("sector not found");
return ERROR_FAIL; return ERROR_FAIL;
} }
else if (error & (mg_io_rbit_err_bad_block | mg_io_rbit_err_uncorrectable)) { else if (error & (mg_io_rbit_err_bad_block | mg_io_rbit_err_uncorrectable)) {
LOG_ERROR("bad block"); LOG_ERROR("bad block");
return ERROR_FAIL; return ERROR_FAIL;
} else { } else {
LOG_ERROR("disk operation fail"); LOG_ERROR("disk operation fail");
return ERROR_FAIL; return ERROR_FAIL;
} }
} }
switch (wait) switch (wait)
{ {
case mg_io_wait_rdy: case mg_io_wait_rdy:
if (status & mg_io_rbit_status_ready) if (status & mg_io_rbit_status_ready)
return ERROR_OK; return ERROR_OK;
case mg_io_wait_drq: case mg_io_wait_drq:
if (status & mg_io_rbit_status_data_req) if (status & mg_io_rbit_status_data_req)
return ERROR_OK; return ERROR_OK;
default: default:
break; break;
} }
} }
duration_stop_measure(&duration, NULL); duration_stop_measure(&duration, NULL);
t=duration.duration.tv_usec/1000; t=duration.duration.tv_usec/1000;
t+=duration.duration.tv_sec*1000; t+=duration.duration.tv_sec*1000;
if (t > time) if (t > time)
break; break;
} }
LOG_ERROR("timeout occured"); LOG_ERROR("timeout occured");
return ERROR_FAIL; return ERROR_FAIL;
} }
static int mg_dsk_srst(u8 on) static int mg_dsk_srst(u8 on)
...@@ -634,7 +634,6 @@ static int mg_mflash_read (u32 addr, u8 *buff, u32 len) ...@@ -634,7 +634,6 @@ static int mg