Transform 'u16' to 'uint16_t'
[openocd.git] / src / flash / tms470.c
index f74f3ffca0501462659dbb671d76a790d8c83c79..33753d8314c0042f30e2cb9c469fd15b227efa6b 100644 (file)
 #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",
@@ -73,7 +71,7 @@ const flash_sector_t TMS470R1A256_SECTORS[] = {
 };
 
 #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},
@@ -83,7 +81,7 @@ const flash_sector_t TMS470R1A288_BANK0_SECTORS[] = {
 };
 
 #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},
@@ -93,11 +91,47 @@ const flash_sector_t TMS470R1A288_BANK1_SECTORS[] = {
 };
 
 #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},
+};
+
+#define TMS470R1A384_BANK0_NUM_SECTORS \
+       (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},
+};
+
+#define TMS470R1A384_BANK1_NUM_SECTORS \
+       (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},
+};
+
+#define TMS470R1A384_BANK2_NUM_SECTORS \
+       (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;
@@ -160,7 +194,7 @@ int tms470_read_part_info(struct flash_bank_s *bank)
        case 0x2b:
                part_name = "TMS470R1A288";
 
-               if ((bank->base >= 0x00000000) && (bank->base < 0x00008000))
+               if (bank->base < 0x00008000)
                {
                        tms470_info->ordinal = 0;
                        bank->base = 0x00000000;
@@ -193,6 +227,55 @@ int tms470_read_part_info(struct flash_bank_s *bank)
                }
                break;
 
+       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;
@@ -224,10 +307,10 @@ int tms470_read_part_info(struct flash_bank_s *bank)
 
 /* ---------------------------------------------------------------------- */
 
-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)
        {
@@ -270,27 +353,27 @@ int tms470_handle_flash_keyset_command(struct command_context_s *cmd_ctx, char *
        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)
        {
@@ -317,9 +400,9 @@ int tms470_handle_osc_megahertz_command(struct command_context_s *cmd_ctx, char
 
 /* ---------------------------------------------------------------------- */
 
-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)
        {
@@ -339,7 +422,7 @@ int tms470_handle_plldis_command(struct command_context_s *cmd_ctx, char *cmd, c
 
 /* ---------------------------------------------------------------------- */
 
-int tms470_check_flash_unlocked(target_t * target)
+static int tms470_check_flash_unlocked(target_t * target)
 {
        u32 fmbbusy;
 
@@ -350,7 +433,7 @@ int tms470_check_flash_unlocked(target_t * target)
 
 /* ---------------------------------------------------------------------- */
 
-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;
@@ -372,7 +455,7 @@ int tms470_try_flash_keys(target_t * target, const u32 * key_set)
                do
                {
                        target_read_u32(target, 0xFFE8A814, &fmbptr);
-                       usleep(1000);
+                       alive_sleep(1);
                }
                while (!(fmbptr & 0x0200));
 
@@ -428,7 +511,7 @@ int tms470_try_flash_keys(target_t * target, const u32 * key_set)
 
 /* ---------------------------------------------------------------------- */
 
-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];
@@ -467,7 +550,7 @@ int tms470_unlock_flash(struct flash_bank_s *bank)
 
 /* ---------------------------------------------------------------------- */
 
-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;
@@ -659,7 +742,7 @@ int tms470_flash_status(struct flash_bank_s *bank)
 
 /* ---------------------------------------------------------------------- */
 
-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;
@@ -703,11 +786,11 @@ int tms470_erase_sector(struct flash_bank_s *bank, int sector)
         * 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
@@ -718,7 +801,7 @@ int tms470_erase_sector(struct flash_bank_s *bank, int sector)
                target_read_u32(target, 0xFFE8BC0C, &fmmstat);
                if (fmmstat & 0x0100)
                {
-                       usleep(1000);
+                       alive_sleep(1);
                }
        }
        while (fmmstat & 0x0100);
@@ -754,7 +837,7 @@ int tms470_erase_sector(struct flash_bank_s *bank, int sector)
               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");
 
@@ -767,13 +850,14 @@ int tms470_register_commands(struct command_context_s *cmd_ctx)
 
 /* ---------------------------------------------------------------------- */
 
-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;
 
        if (bank->target->state != TARGET_HALTED)
        {
+               LOG_ERROR("Target not halted");
                return ERROR_TARGET_NOT_HALTED;
        }
 
@@ -813,7 +897,7 @@ 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)
+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;
@@ -822,6 +906,7 @@ int tms470_protect(struct flash_bank_s *bank, int set, int first, int last)
 
        if (target->state != TARGET_HALTED)
        {
+               LOG_ERROR("Target not halted");
                return ERROR_TARGET_NOT_HALTED;
        }
 
@@ -864,14 +949,16 @@ 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)
+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)
        {
+               LOG_ERROR("Target not halted");
                return ERROR_TARGET_NOT_HALTED;
        }
 
@@ -907,7 +994,7 @@ int tms470_write(struct flash_bank_s *bank, u8 * buffer, u32 offset, u32 count)
        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)
                {
@@ -929,7 +1016,7 @@ int tms470_write(struct flash_bank_s *bank, u8 * buffer, u32 offset, u32 count)
                                target_read_u32(target, 0xFFE8BC0C, &fmmstat);
                                if (fmmstat & 0x0100)
                                {
-                                       usleep(1000);
+                                       alive_sleep(1);
                                }
                        }
                        while (fmmstat & 0x0100);
@@ -960,7 +1047,7 @@ int tms470_write(struct flash_bank_s *bank, u8 * buffer, u32 offset, u32 count)
 
 /* ---------------------------------------------------------------------- */
 
-int tms470_probe(struct flash_bank_s *bank)
+static int tms470_probe(struct flash_bank_s *bank)
 {
        if (bank->target->state != TARGET_HALTED)
        {
@@ -971,7 +1058,7 @@ int tms470_probe(struct flash_bank_s *bank)
        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;
 
@@ -982,16 +1069,17 @@ int tms470_auto_probe(struct flash_bank_s *bank)
 
 /* ---------------------------------------------------------------------- */
 
-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)
        {
+               LOG_ERROR("Target not halted");
                return ERROR_TARGET_NOT_HALTED;
        }
 
@@ -1072,7 +1160,7 @@ int tms470_erase_check(struct flash_bank_s *bank)
 
 /* ---------------------------------------------------------------------- */
 
-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;
@@ -1081,6 +1169,7 @@ int tms470_protect_check(struct flash_bank_s *bank)
 
        if (target->state != TARGET_HALTED)
        {
+               LOG_ERROR("Target not halted");
                return ERROR_TARGET_NOT_HALTED;
        }
 
@@ -1119,7 +1208,7 @@ 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_info(struct flash_bank_s *bank, char *buf, int buf_size)
 {
        int used = 0;
        tms470_flash_bank_t *tms470_info = bank->driver_priv;
@@ -1153,7 +1242,7 @@ int tms470_info(struct flash_bank_s *bank, char *buf, int buf_size)
  * [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));
 

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)