X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Fflash%2Fstellaris.c;h=32fa415ee05bd6b831e5d1edf17ac3d0f817d601;hp=806544d5ae996e5c6c4848c07e8eba3cca476894;hb=ff25e76bad7e57da4ebd363f1b35d4af04acaa67;hpb=fbe1c23c12c8db7820a8f9a3fb62cfa9a60a745c
diff --git a/src/flash/stellaris.c b/src/flash/stellaris.c
index 806544d5ae..32fa415ee0 100644
--- a/src/flash/stellaris.c
+++ b/src/flash/stellaris.c
@@ -31,41 +31,17 @@
#include "stellaris.h"
#include "armv7m.h"
#include "binarybuffer.h"
+#include "algorithm.h"
#define DID0_VER(did0) ((did0 >> 28)&0x07)
-static int stellaris_register_commands(struct command_context_s *cmd_ctx);
-static int stellaris_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank);
-static int stellaris_erase(struct flash_bank_s *bank, int first, int last);
-static int stellaris_protect(struct flash_bank_s *bank, int set, int first, int last);
-static int stellaris_write(struct flash_bank_s *bank, uint8_t *buffer, uint32_t offset, uint32_t count);
-static int stellaris_auto_probe(struct flash_bank_s *bank);
-static int stellaris_probe(struct flash_bank_s *bank);
-static int stellaris_protect_check(struct flash_bank_s *bank);
-static int stellaris_info(struct flash_bank_s *bank, char *buf, int buf_size);
-
-static int stellaris_read_part_info(struct flash_bank_s *bank);
-static uint32_t stellaris_get_flash_status(flash_bank_t *bank);
-static void stellaris_set_flash_mode(flash_bank_t *bank,int mode);
-//static uint32_t stellaris_wait_status_busy(flash_bank_t *bank, uint32_t waitbits, int timeout);
-
-static int stellaris_handle_mass_erase_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
-static int stellaris_mass_erase(struct flash_bank_s *bank);
-
-flash_driver_t stellaris_flash =
-{
- .name = "stellaris",
- .register_commands = stellaris_register_commands,
- .flash_bank_command = stellaris_flash_bank_command,
- .erase = stellaris_erase,
- .protect = stellaris_protect,
- .write = stellaris_write,
- .probe = stellaris_probe,
- .auto_probe = stellaris_auto_probe,
- .erase_check = default_flash_mem_blank_check,
- .protect_check = stellaris_protect_check,
- .info = stellaris_info
-};
+
+static int stellaris_read_part_info(struct flash_bank *bank);
+static uint32_t stellaris_get_flash_status(struct flash_bank *bank);
+static void stellaris_set_flash_mode(struct flash_bank *bank,int mode);
+//static uint32_t stellaris_wait_status_busy(struct flash_bank *bank, uint32_t waitbits, int timeout);
+
+static int stellaris_mass_erase(struct flash_bank *bank);
static struct {
uint32_t partno;
@@ -238,17 +214,17 @@ static char * StellarisClassname[5] =
/* flash_bank stellaris 0 0
*/
-static int stellaris_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank)
+FLASH_BANK_COMMAND_HANDLER(stellaris_flash_bank_command)
{
- stellaris_flash_bank_t *stellaris_info;
+ struct stellaris_flash_bank *stellaris_info;
- if (argc < 6)
+ if (CMD_ARGC < 6)
{
LOG_WARNING("incomplete flash_bank stellaris configuration");
return ERROR_FLASH_BANK_INVALID;
}
- stellaris_info = calloc(sizeof(stellaris_flash_bank_t), 1);
+ stellaris_info = calloc(sizeof(struct stellaris_flash_bank), 1);
bank->base = 0x0;
bank->driver_priv = stellaris_info;
@@ -264,18 +240,10 @@ static int stellaris_flash_bank_command(struct command_context_s *cmd_ctx, char
return ERROR_OK;
}
-static int stellaris_register_commands(struct command_context_s *cmd_ctx)
-{
- command_t *stm32x_cmd = register_command(cmd_ctx, NULL, "stellaris", NULL, COMMAND_ANY, "stellaris flash specific commands");
-
- register_command(cmd_ctx, stm32x_cmd, "mass_erase", stellaris_handle_mass_erase_command, COMMAND_EXEC, "mass erase device");
- return ERROR_OK;
-}
-
-static int stellaris_info(struct flash_bank_s *bank, char *buf, int buf_size)
+static int stellaris_info(struct flash_bank *bank, char *buf, int buf_size)
{
int printed, device_class;
- stellaris_flash_bank_t *stellaris_info = bank->driver_priv;
+ struct stellaris_flash_bank *stellaris_info = bank->driver_priv;
stellaris_read_part_info(bank);
@@ -349,9 +317,9 @@ static int stellaris_info(struct flash_bank_s *bank, char *buf, int buf_size)
* chip identification and status *
***************************************************************************/
-static uint32_t stellaris_get_flash_status(flash_bank_t *bank)
+static uint32_t stellaris_get_flash_status(struct flash_bank *bank)
{
- target_t *target = bank->target;
+ struct target *target = bank->target;
uint32_t fmc;
target_read_u32(target, FLASH_CONTROL_BASE | FLASH_FMC, &fmc);
@@ -394,10 +362,10 @@ static const unsigned rcc_xtal[32] = {
[0x16] = 16384000,
};
-static void stellaris_read_clock_info(flash_bank_t *bank)
+static void stellaris_read_clock_info(struct flash_bank *bank)
{
- stellaris_flash_bank_t *stellaris_info = bank->driver_priv;
- target_t *target = bank->target;
+ struct stellaris_flash_bank *stellaris_info = bank->driver_priv;
+ struct target *target = bank->target;
uint32_t rcc, rcc2, pllcfg, sysdiv, usesysdiv, bypass, oscsrc;
unsigned xtal;
unsigned long mainfreq;
@@ -481,10 +449,10 @@ static void stellaris_read_clock_info(flash_bank_t *bank)
}
/* Setup the timimg registers */
-static void stellaris_set_flash_mode(flash_bank_t *bank,int mode)
+static void stellaris_set_flash_mode(struct flash_bank *bank,int mode)
{
- stellaris_flash_bank_t *stellaris_info = bank->driver_priv;
- target_t *target = bank->target;
+ struct stellaris_flash_bank *stellaris_info = bank->driver_priv;
+ struct target *target = bank->target;
uint32_t usecrl = (stellaris_info->mck_freq/1000000ul-1);
LOG_DEBUG("usecrl = %i",(int)(usecrl));
@@ -492,7 +460,7 @@ static void stellaris_set_flash_mode(flash_bank_t *bank,int mode)
}
#if 0
-static uint32_t stellaris_wait_status_busy(flash_bank_t *bank, uint32_t waitbits, int timeout)
+static uint32_t stellaris_wait_status_busy(struct flash_bank *bank, uint32_t waitbits, int timeout)
{
uint32_t status;
@@ -509,10 +477,10 @@ static uint32_t stellaris_wait_status_busy(flash_bank_t *bank, uint32_t waitbits
}
/* Send one command to the flash controller */
-static int stellaris_flash_command(struct flash_bank_s *bank,uint8_t cmd,uint16_t pagen)
+static int stellaris_flash_command(struct flash_bank *bank,uint8_t cmd,uint16_t pagen)
{
uint32_t fmc;
- target_t *target = bank->target;
+ struct target *target = bank->target;
fmc = FMC_WRKEY | cmd;
target_write_u32(target, FLASH_CONTROL_BASE | FLASH_FMC, fmc);
@@ -528,10 +496,10 @@ static int stellaris_flash_command(struct flash_bank_s *bank,uint8_t cmd,uint16_
#endif
/* Read device id register, main clock frequency register and fill in driver info structure */
-static int stellaris_read_part_info(struct flash_bank_s *bank)
+static int stellaris_read_part_info(struct flash_bank *bank)
{
- stellaris_flash_bank_t *stellaris_info = bank->driver_priv;
- target_t *target = bank->target;
+ struct stellaris_flash_bank *stellaris_info = bank->driver_priv;
+ struct target *target = bank->target;
uint32_t did0, did1, ver, fam, status;
int i;
@@ -625,7 +593,7 @@ static int stellaris_read_part_info(struct flash_bank_s *bank)
/* provide this for the benefit of the higher flash driver layers */
bank->num_sectors = stellaris_info->num_pages;
- bank->sectors = malloc(sizeof(flash_sector_t) * bank->num_sectors);
+ bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
for (i = 0; i < bank->num_sectors; i++)
{
bank->sectors[i].offset = i * stellaris_info->pagesize;
@@ -646,11 +614,11 @@ static int stellaris_read_part_info(struct flash_bank_s *bank)
* flash operations *
***************************************************************************/
-static int stellaris_protect_check(struct flash_bank_s *bank)
+static int stellaris_protect_check(struct flash_bank *bank)
{
uint32_t status;
- stellaris_flash_bank_t *stellaris_info = bank->driver_priv;
+ struct stellaris_flash_bank *stellaris_info = bank->driver_priv;
if (bank->target->state != TARGET_HALTED)
{
@@ -675,12 +643,12 @@ static int stellaris_protect_check(struct flash_bank_s *bank)
return ERROR_OK;
}
-static int stellaris_erase(struct flash_bank_s *bank, int first, int last)
+static int stellaris_erase(struct flash_bank *bank, int first, int last)
{
int banknr;
uint32_t flash_fmc, flash_cris;
- stellaris_flash_bank_t *stellaris_info = bank->driver_priv;
- target_t *target = bank->target;
+ struct stellaris_flash_bank *stellaris_info = bank->driver_priv;
+ struct target *target = bank->target;
if (bank->target->state != TARGET_HALTED)
{
@@ -745,13 +713,13 @@ static int stellaris_erase(struct flash_bank_s *bank, int first, int last)
return ERROR_OK;
}
-static int stellaris_protect(struct flash_bank_s *bank, int set, int first, int last)
+static int stellaris_protect(struct flash_bank *bank, int set, int first, int last)
{
uint32_t fmppe, flash_fmc, flash_cris;
int lockregion;
- stellaris_flash_bank_t *stellaris_info = bank->driver_priv;
- target_t *target = bank->target;
+ struct stellaris_flash_bank *stellaris_info = bank->driver_priv;
+ struct target *target = bank->target;
if (bank->target->state != TARGET_HALTED)
{
@@ -861,15 +829,15 @@ static uint8_t stellaris_write_code[] =
0x01,0x00,0x42,0xA4 /* .word 0xA4420001 */
};
-static int stellaris_write_block(struct flash_bank_s *bank, uint8_t *buffer, uint32_t offset, uint32_t wcount)
+static int stellaris_write_block(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t wcount)
{
- target_t *target = bank->target;
+ struct target *target = bank->target;
uint32_t buffer_size = 8192;
- working_area_t *source;
- working_area_t *write_algorithm;
+ struct working_area *source;
+ struct working_area *write_algorithm;
uint32_t address = bank->base + offset;
- reg_param_t reg_params[3];
- armv7m_algorithm_t armv7m_info;
+ struct reg_param reg_params[3];
+ struct armv7m_algorithm armv7m_info;
int retval = ERROR_OK;
LOG_DEBUG("(bank=%p buffer=%p offset=%08" PRIx32 " wcount=%08" PRIx32 "",
@@ -917,8 +885,8 @@ static int stellaris_write_block(struct flash_bank_s *bank, uint8_t *buffer, uin
buf_set_u32(reg_params[0].value, 0, 32, source->address);
buf_set_u32(reg_params[1].value, 0, 32, address);
buf_set_u32(reg_params[2].value, 0, 32, 4*thisrun_count);
- LOG_INFO("Algorithm flash write %" PRIi32 " words to 0x%" PRIx32 ", %" PRIi32 " remaining", thisrun_count, address, wcount);
- LOG_DEBUG("Algorithm flash write %" PRIi32 " words to 0x%" PRIx32 ", %" PRIi32 " remaining", thisrun_count, address, wcount);
+ LOG_INFO("Algorithm flash write %" PRIi32 " words to 0x%" PRIx32 ", %" PRIi32 " remaining", thisrun_count, address, (wcount - thisrun_count));
+ LOG_DEBUG("Algorithm flash write %" PRIi32 " words to 0x%" PRIx32 ", %" PRIi32 " remaining", thisrun_count, address, (wcount - thisrun_count));
if ((retval = target_run_algorithm(target, 0, NULL, 3, reg_params, write_algorithm->address, write_algorithm->address + sizeof(stellaris_write_code)-10, 10000, &armv7m_info)) != ERROR_OK)
{
LOG_ERROR("error executing stellaris flash write algorithm");
@@ -941,10 +909,10 @@ static int stellaris_write_block(struct flash_bank_s *bank, uint8_t *buffer, uin
return retval;
}
-static int stellaris_write(struct flash_bank_s *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
+static int stellaris_write(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
{
- stellaris_flash_bank_t *stellaris_info = bank->driver_priv;
- target_t *target = bank->target;
+ struct stellaris_flash_bank *stellaris_info = bank->driver_priv;
+ struct target *target = bank->target;
uint32_t address = offset;
uint32_t flash_cris, flash_fmc;
uint32_t words_remaining = (count / 4);
@@ -1076,7 +1044,7 @@ static int stellaris_write(struct flash_bank_s *bank, uint8_t *buffer, uint32_t
return ERROR_OK;
}
-static int stellaris_probe(struct flash_bank_s *bank)
+static int stellaris_probe(struct flash_bank *bank)
{
/* we can't probe on an stellaris
* if this is an stellaris, it has the configured flash
@@ -1092,18 +1060,18 @@ static int stellaris_probe(struct flash_bank_s *bank)
return stellaris_read_part_info(bank);
}
-static int stellaris_auto_probe(struct flash_bank_s *bank)
+static int stellaris_auto_probe(struct flash_bank *bank)
{
- stellaris_flash_bank_t *stellaris_info = bank->driver_priv;
+ struct stellaris_flash_bank *stellaris_info = bank->driver_priv;
if (stellaris_info->did1)
return ERROR_OK;
return stellaris_probe(bank);
}
-static int stellaris_mass_erase(struct flash_bank_s *bank)
+static int stellaris_mass_erase(struct flash_bank *bank)
{
- target_t *target = NULL;
- stellaris_flash_bank_t *stellaris_info = NULL;
+ struct target *target = NULL;
+ struct stellaris_flash_bank *stellaris_info = NULL;
uint32_t flash_fmc;
stellaris_info = bank->driver_priv;
@@ -1160,23 +1128,20 @@ static int stellaris_mass_erase(struct flash_bank_s *bank)
return ERROR_OK;
}
-static int stellaris_handle_mass_erase_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+COMMAND_HANDLER(stellaris_handle_mass_erase_command)
{
- flash_bank_t *bank;
int i;
- if (argc < 1)
+ if (CMD_ARGC < 1)
{
- command_print(cmd_ctx, "stellaris mass_erase ");
+ command_print(CMD_CTX, "stellaris mass_erase ");
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;
- }
+ struct flash_bank *bank;
+ int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
+ if (ERROR_OK != retval)
+ return retval;
if (stellaris_mass_erase(bank) == ERROR_OK)
{
@@ -1186,12 +1151,38 @@ static int stellaris_handle_mass_erase_command(struct command_context_s *cmd_ctx
bank->sectors[i].is_erased = 1;
}
- command_print(cmd_ctx, "stellaris mass erase complete");
+ command_print(CMD_CTX, "stellaris mass erase complete");
}
else
{
- command_print(cmd_ctx, "stellaris mass erase failed");
+ command_print(CMD_CTX, "stellaris mass erase failed");
}
return ERROR_OK;
}
+
+static int stellaris_register_commands(struct command_context *cmd_ctx)
+{
+ struct command *stm32x_cmd = register_command(cmd_ctx, NULL, "stellaris",
+ NULL, COMMAND_ANY, "stellaris flash specific commands");
+
+ register_command(cmd_ctx, stm32x_cmd, "mass_erase",
+ stellaris_handle_mass_erase_command, COMMAND_EXEC,
+ "mass erase device");
+ return ERROR_OK;
+}
+
+
+struct flash_driver stellaris_flash = {
+ .name = "stellaris",
+ .register_commands = &stellaris_register_commands,
+ .flash_bank_command = &stellaris_flash_bank_command,
+ .erase = &stellaris_erase,
+ .protect = &stellaris_protect,
+ .write = &stellaris_write,
+ .probe = &stellaris_probe,
+ .auto_probe = &stellaris_auto_probe,
+ .erase_check = &default_flash_mem_blank_check,
+ .protect_check = &stellaris_protect_check,
+ .info = &stellaris_info,
+ };