#include "config.h"
#endif
-#include "log.h"
#include "tms470.h"
-#include <string.h>
-#include <unistd.h>
-
-int tms470_register_commands(struct command_context_s *cmd_ctx);
-int tms470_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank);
-int tms470_erase(struct flash_bank_s *bank, int first, int last);
-int tms470_protect(struct flash_bank_s *bank, int set, int first, int last);
-int tms470_write(struct flash_bank_s *bank, u8 * buffer, u32 offset, u32 count);
-int tms470_probe(struct flash_bank_s *bank);
-int tms470_auto_probe(struct flash_bank_s *bank);
-int tms470_erase_check(struct flash_bank_s *bank);
-int tms470_protect_check(struct flash_bank_s *bank);
-int tms470_info(struct flash_bank_s *bank, char *buf, int buf_size);
+
+
+static int tms470_register_commands(struct command_context_s *cmd_ctx);
+static int tms470_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank);
+static int tms470_erase(struct flash_bank_s *bank, int first, int last);
+static int tms470_protect(struct flash_bank_s *bank, int set, int first, int last);
+static int tms470_write(struct flash_bank_s *bank, uint8_t * buffer, u32 offset, u32 count);
+static int tms470_probe(struct flash_bank_s *bank);
+static int tms470_auto_probe(struct flash_bank_s *bank);
+static int tms470_erase_check(struct flash_bank_s *bank);
+static int tms470_protect_check(struct flash_bank_s *bank);
+static int tms470_info(struct flash_bank_s *bank, char *buf, int buf_size);
flash_driver_t tms470_flash = {
.name = "tms470",
};
#define TMS470R1A256_NUM_SECTORS \
- (sizeof(TMS470R1A256_SECTORS)/sizeof(TMS470R1A256_SECTORS[0]))
+ (sizeof(TMS470R1A256_SECTORS)/sizeof(TMS470R1A256_SECTORS[0]))
const flash_sector_t TMS470R1A288_BANK0_SECTORS[] = {
{0x00000000, 0x00002000, -1, -1},
};
#define TMS470R1A288_BANK0_NUM_SECTORS \
- (sizeof(TMS470R1A288_BANK0_SECTORS)/sizeof(TMS470R1A288_BANK0_SECTORS[0]))
+ (sizeof(TMS470R1A288_BANK0_SECTORS)/sizeof(TMS470R1A288_BANK0_SECTORS[0]))
const flash_sector_t TMS470R1A288_BANK1_SECTORS[] = {
{0x00040000, 0x00010000, -1, -1},
};
#define TMS470R1A288_BANK1_NUM_SECTORS \
- (sizeof(TMS470R1A288_BANK1_SECTORS)/sizeof(TMS470R1A288_BANK1_SECTORS[0]))
+ (sizeof(TMS470R1A288_BANK1_SECTORS)/sizeof(TMS470R1A288_BANK1_SECTORS[0]))
const flash_sector_t TMS470R1A384_BANK0_SECTORS[] = {
- {0x00000000, 0x00002000, -1, -1},
- {0x00002000, 0x00002000, -1, -1},
- {0x00004000, 0x00004000, -1, -1},
- {0x00008000, 0x00004000, -1, -1},
- {0x0000C000, 0x00004000, -1, -1},
- {0x00010000, 0x00004000, -1, -1},
- {0x00014000, 0x00004000, -1, -1},
- {0x00018000, 0x00002000, -1, -1},
- {0x0001C000, 0x00002000, -1, -1},
- {0x0001E000, 0x00002000, -1, -1},
+ {0x00000000, 0x00002000, -1, -1},
+ {0x00002000, 0x00002000, -1, -1},
+ {0x00004000, 0x00004000, -1, -1},
+ {0x00008000, 0x00004000, -1, -1},
+ {0x0000C000, 0x00004000, -1, -1},
+ {0x00010000, 0x00004000, -1, -1},
+ {0x00014000, 0x00004000, -1, -1},
+ {0x00018000, 0x00002000, -1, -1},
+ {0x0001C000, 0x00002000, -1, -1},
+ {0x0001E000, 0x00002000, -1, -1},
};
#define TMS470R1A384_BANK0_NUM_SECTORS \
- (sizeof(TMS470R1A384_BANK0_SECTORS)/sizeof(TMS470R1A384_BANK0_SECTORS[0]))
+ (sizeof(TMS470R1A384_BANK0_SECTORS)/sizeof(TMS470R1A384_BANK0_SECTORS[0]))
const flash_sector_t TMS470R1A384_BANK1_SECTORS[] = {
- {0x00020000, 0x00008000, -1, -1},
- {0x00028000, 0x00008000, -1, -1},
- {0x00030000, 0x00008000, -1, -1},
- {0x00038000, 0x00008000, -1, -1},
+ {0x00020000, 0x00008000, -1, -1},
+ {0x00028000, 0x00008000, -1, -1},
+ {0x00030000, 0x00008000, -1, -1},
+ {0x00038000, 0x00008000, -1, -1},
};
#define TMS470R1A384_BANK1_NUM_SECTORS \
- (sizeof(TMS470R1A384_BANK1_SECTORS)/sizeof(TMS470R1A384_BANK1_SECTORS[0]))
+ (sizeof(TMS470R1A384_BANK1_SECTORS)/sizeof(TMS470R1A384_BANK1_SECTORS[0]))
const flash_sector_t TMS470R1A384_BANK2_SECTORS[] = {
- {0x00040000, 0x00008000, -1, -1},
- {0x00048000, 0x00008000, -1, -1},
- {0x00050000, 0x00008000, -1, -1},
- {0x00058000, 0x00008000, -1, -1},
+ {0x00040000, 0x00008000, -1, -1},
+ {0x00048000, 0x00008000, -1, -1},
+ {0x00050000, 0x00008000, -1, -1},
+ {0x00058000, 0x00008000, -1, -1},
};
#define TMS470R1A384_BANK2_NUM_SECTORS \
- (sizeof(TMS470R1A384_BANK2_SECTORS)/sizeof(TMS470R1A384_BANK2_SECTORS[0]))
+ (sizeof(TMS470R1A384_BANK2_SECTORS)/sizeof(TMS470R1A384_BANK2_SECTORS[0]))
/* ---------------------------------------------------------------------- */
-int tms470_read_part_info(struct flash_bank_s *bank)
+static int tms470_read_part_info(struct flash_bank_s *bank)
{
tms470_flash_bank_t *tms470_info = bank->driver_priv;
target_t *target = bank->target;
case 0x2b:
part_name = "TMS470R1A288";
- if ((bank->base >= 0x00000000) && (bank->base < 0x00008000))
+ if (bank->base < 0x00008000)
{
tms470_info->ordinal = 0;
bank->base = 0x00000000;
}
break;
- case 0x2d:
- part_name = "TMS470R1A384";
-
- if ((bank->base >= 0x00000000) && (bank->base < 0x00020000))
- {
- tms470_info->ordinal = 0;
- bank->base = 0x00000000;
- bank->size = 128 * 1024;
- bank->num_sectors = TMS470R1A384_BANK0_NUM_SECTORS;
- bank->sectors = malloc(sizeof(TMS470R1A384_BANK0_SECTORS));
- if (!bank->sectors)
- {
- return ERROR_FLASH_OPERATION_FAILED;
- }
- (void)memcpy(bank->sectors, TMS470R1A384_BANK0_SECTORS, sizeof(TMS470R1A384_BANK0_SECTORS));
- }
- else if ((bank->base >= 0x00020000) && (bank->base < 0x00040000))
- {
- tms470_info->ordinal = 1;
- bank->base = 0x00020000;
- bank->size = 128 * 1024;
- bank->num_sectors = TMS470R1A384_BANK1_NUM_SECTORS;
- bank->sectors = malloc(sizeof(TMS470R1A384_BANK1_SECTORS));
- if (!bank->sectors)
- {
- return ERROR_FLASH_OPERATION_FAILED;
- }
- (void)memcpy(bank->sectors, TMS470R1A384_BANK1_SECTORS, sizeof(TMS470R1A384_BANK1_SECTORS));
- }
- else if ((bank->base >= 0x00040000) && (bank->base < 0x00060000))
- {
- tms470_info->ordinal = 2;
- bank->base = 0x00040000;
- bank->size = 128 * 1024;
- bank->num_sectors = TMS470R1A384_BANK2_NUM_SECTORS;
- bank->sectors = malloc(sizeof(TMS470R1A384_BANK2_SECTORS));
- if (!bank->sectors)
- {
- return ERROR_FLASH_OPERATION_FAILED;
- }
- (void)memcpy(bank->sectors, TMS470R1A384_BANK2_SECTORS, sizeof(TMS470R1A384_BANK2_SECTORS));
- }
- else
- {
- LOG_ERROR("No %s flash bank contains base address 0x%08x.", part_name, bank->base);
- return ERROR_FLASH_OPERATION_FAILED;
- }
- break;
-
- default:
+ case 0x2d:
+ part_name = "TMS470R1A384";
+
+ if (bank->base < 0x00020000)
+ {
+ tms470_info->ordinal = 0;
+ bank->base = 0x00000000;
+ bank->size = 128 * 1024;
+ bank->num_sectors = TMS470R1A384_BANK0_NUM_SECTORS;
+ bank->sectors = malloc(sizeof(TMS470R1A384_BANK0_SECTORS));
+ if (!bank->sectors)
+ {
+ return ERROR_FLASH_OPERATION_FAILED;
+ }
+ (void)memcpy(bank->sectors, TMS470R1A384_BANK0_SECTORS, sizeof(TMS470R1A384_BANK0_SECTORS));
+ }
+ else if ((bank->base >= 0x00020000) && (bank->base < 0x00040000))
+ {
+ tms470_info->ordinal = 1;
+ bank->base = 0x00020000;
+ bank->size = 128 * 1024;
+ bank->num_sectors = TMS470R1A384_BANK1_NUM_SECTORS;
+ bank->sectors = malloc(sizeof(TMS470R1A384_BANK1_SECTORS));
+ if (!bank->sectors)
+ {
+ return ERROR_FLASH_OPERATION_FAILED;
+ }
+ (void)memcpy(bank->sectors, TMS470R1A384_BANK1_SECTORS, sizeof(TMS470R1A384_BANK1_SECTORS));
+ }
+ else if ((bank->base >= 0x00040000) && (bank->base < 0x00060000))
+ {
+ tms470_info->ordinal = 2;
+ bank->base = 0x00040000;
+ bank->size = 128 * 1024;
+ bank->num_sectors = TMS470R1A384_BANK2_NUM_SECTORS;
+ bank->sectors = malloc(sizeof(TMS470R1A384_BANK2_SECTORS));
+ if (!bank->sectors)
+ {
+ return ERROR_FLASH_OPERATION_FAILED;
+ }
+ (void)memcpy(bank->sectors, TMS470R1A384_BANK2_SECTORS, sizeof(TMS470R1A384_BANK2_SECTORS));
+ }
+ else
+ {
+ LOG_ERROR("No %s flash bank contains base address 0x%08x.", part_name, bank->base);
+ return ERROR_FLASH_OPERATION_FAILED;
+ }
+ break;
+
+ default:
LOG_WARNING("Could not identify part 0x%02x as a member of the TMS470 family.", part_number);
return ERROR_FLASH_OPERATION_FAILED;
}
/* ---------------------------------------------------------------------- */
-u32 keysSet = 0;
-u32 flashKeys[4];
+static u32 keysSet = 0;
+static u32 flashKeys[4];
-int tms470_handle_flash_keyset_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+static int tms470_handle_flash_keyset_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
if (argc > 4)
{
return ERROR_OK;
}
-const u32 FLASH_KEYS_ALL_ONES[] = { 0xFFFFFFFF, 0xFFFFFFFF,
+static const u32 FLASH_KEYS_ALL_ONES[] = { 0xFFFFFFFF, 0xFFFFFFFF,
0xFFFFFFFF, 0xFFFFFFFF,
};
-const u32 FLASH_KEYS_ALL_ZEROS[] = { 0x00000000, 0x00000000,
+static const u32 FLASH_KEYS_ALL_ZEROS[] = { 0x00000000, 0x00000000,
0x00000000, 0x00000000,
};
-const u32 FLASH_KEYS_MIX1[] = { 0xf0fff0ff, 0xf0fff0ff,
+static const u32 FLASH_KEYS_MIX1[] = { 0xf0fff0ff, 0xf0fff0ff,
0xf0fff0ff, 0xf0fff0ff
};
-const u32 FLASH_KEYS_MIX2[] = { 0x0000ffff, 0x0000ffff,
+static const u32 FLASH_KEYS_MIX2[] = { 0x0000ffff, 0x0000ffff,
0x0000ffff, 0x0000ffff
};
/* ---------------------------------------------------------------------- */
-int oscMHz = 12;
+static int oscMHz = 12;
-int tms470_handle_osc_megahertz_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+static int tms470_handle_osc_megahertz_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
if (argc > 1)
{
/* ---------------------------------------------------------------------- */
-int plldis = 0;
+static int plldis = 0;
-int tms470_handle_plldis_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+static int tms470_handle_plldis_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
if (argc > 1)
{
/* ---------------------------------------------------------------------- */
-int tms470_check_flash_unlocked(target_t * target)
+static int tms470_check_flash_unlocked(target_t * target)
{
u32 fmbbusy;
/* ---------------------------------------------------------------------- */
-int tms470_try_flash_keys(target_t * target, const u32 * key_set)
+static int tms470_try_flash_keys(target_t * target, const u32 * key_set)
{
u32 glbctrl, fmmstat;
int retval = ERROR_FLASH_OPERATION_FAILED;
/* ---------------------------------------------------------------------- */
-int tms470_unlock_flash(struct flash_bank_s *bank)
+static int tms470_unlock_flash(struct flash_bank_s *bank)
{
target_t *target = bank->target;
const u32 *p_key_sets[5];
/* ---------------------------------------------------------------------- */
-int tms470_flash_initialize_internal_state_machine(struct flash_bank_s *bank)
+static int tms470_flash_initialize_internal_state_machine(struct flash_bank_s *bank)
{
u32 fmmac2, fmmac1, fmmaxep, k, delay, glbctrl, sysclk;
target_t *target = bank->target;
/* ---------------------------------------------------------------------- */
-int tms470_erase_sector(struct flash_bank_s *bank, int sector)
+static int tms470_erase_sector(struct flash_bank_s *bank, int sector)
{
u32 glbctrl, orig_fmregopt, fmbsea, fmbseb, fmmstat;
target_t *target = bank->target;
* clear status regiser, sent erase command, kickoff erase
*/
target_write_u16(target, flashAddr, 0x0040);
- LOG_DEBUG("write *(u16 *)0x%08x=0x0040", flashAddr);
+ LOG_DEBUG("write *(uint16_t *)0x%08x=0x0040", flashAddr);
target_write_u16(target, flashAddr, 0x0020);
- LOG_DEBUG("write *(u16 *)0x%08x=0x0020", flashAddr);
+ LOG_DEBUG("write *(uint16_t *)0x%08x=0x0020", flashAddr);
target_write_u16(target, flashAddr, 0xffff);
- LOG_DEBUG("write *(u16 *)0x%08x=0xffff", flashAddr);
+ LOG_DEBUG("write *(uint16_t *)0x%08x=0xffff", flashAddr);
/*
* Monitor FMMSTAT, busy until clear, then check and other flags for
Implementation of Flash Driver Interfaces
---------------------------------------------------------------------- */
-int tms470_register_commands(struct command_context_s *cmd_ctx)
+static int tms470_register_commands(struct command_context_s *cmd_ctx)
{
command_t *tms470_cmd = register_command(cmd_ctx, NULL, "tms470", NULL, COMMAND_ANY, "applies to TI tms470 family");
/* ---------------------------------------------------------------------- */
-int tms470_erase(struct flash_bank_s *bank, int first, int last)
+static int tms470_erase(struct flash_bank_s *bank, int first, int last)
{
tms470_flash_bank_t *tms470_info = bank->driver_priv;
int sector, result = ERROR_OK;
/* ---------------------------------------------------------------------- */
-int tms470_protect(struct flash_bank_s *bank, int set, int first, int last)
+static int tms470_protect(struct flash_bank_s *bank, int set, int first, int last)
{
tms470_flash_bank_t *tms470_info = bank->driver_priv;
target_t *target = bank->target;
/* ---------------------------------------------------------------------- */
-int tms470_write(struct flash_bank_s *bank, u8 * buffer, u32 offset, u32 count)
+static int tms470_write(struct flash_bank_s *bank, uint8_t * buffer, u32 offset, u32 count)
{
target_t *target = bank->target;
u32 glbctrl, fmbac2, orig_fmregopt, fmbsea, fmbseb, fmmaxpp, fmmstat;
- int i, result = ERROR_OK;
+ int result = ERROR_OK;
+ u32 i;
if (target->state != TARGET_HALTED)
{
for (i = 0; i < count; i += 2)
{
u32 addr = bank->base + offset + i;
- u16 word = (((u16) buffer[i]) << 8) | (u16) buffer[i + 1];
+ uint16_t word = (((uint16_t) buffer[i]) << 8) | (uint16_t) buffer[i + 1];
if (word != 0xffff)
{
/* ---------------------------------------------------------------------- */
-int tms470_probe(struct flash_bank_s *bank)
+static int tms470_probe(struct flash_bank_s *bank)
{
if (bank->target->state != TARGET_HALTED)
{
return tms470_read_part_info(bank);
}
-int tms470_auto_probe(struct flash_bank_s *bank)
+static int tms470_auto_probe(struct flash_bank_s *bank)
{
tms470_flash_bank_t *tms470_info = bank->driver_priv;
/* ---------------------------------------------------------------------- */
-int tms470_erase_check(struct flash_bank_s *bank)
+static int tms470_erase_check(struct flash_bank_s *bank)
{
target_t *target = bank->target;
tms470_flash_bank_t *tms470_info = bank->driver_priv;
int sector, result = ERROR_OK;
u32 fmmac2, fmbac2, glbctrl, orig_fmregopt;
- static u8 buffer[64 * 1024];
+ static uint8_t buffer[64 * 1024];
if (target->state != TARGET_HALTED)
{
/* ---------------------------------------------------------------------- */
-int tms470_protect_check(struct flash_bank_s *bank)
+static int tms470_protect_check(struct flash_bank_s *bank)
{
target_t *target = bank->target;
tms470_flash_bank_t *tms470_info = bank->driver_priv;
/* ---------------------------------------------------------------------- */
-int tms470_info(struct flash_bank_s *bank, char *buf, int buf_size)
+static int tms470_info(struct flash_bank_s *bank, char *buf, int buf_size)
{
int used = 0;
tms470_flash_bank_t *tms470_info = bank->driver_priv;
* [options...]
*/
-int tms470_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank)
+static int tms470_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank)
{
bank->driver_priv = malloc(sizeof(tms470_flash_bank_t));