command_context_t -> struct command_context
[openocd.git] / src / flash / tms470.c
index 91f0cc0f26fe52daa81230eb08cba6841326bbd2..a5f2f36a5a4a27534a43033fd1b0d8d8c630815d 100644 (file)
 #include "config.h"
 #endif
 
-#include "log.h"
 #include "tms470.h"
-#include <string.h>
-#include <unistd.h>
-
-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, u8 * 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",
-       .register_commands = tms470_register_commands,
-       .flash_bank_command = tms470_flash_bank_command,
-       .erase = tms470_erase,
-       .protect = tms470_protect,
-       .write = tms470_write,
-       .probe = tms470_probe,
-       .auto_probe = tms470_auto_probe,
-       .erase_check = tms470_erase_check,
-       .protect_check = tms470_protect_check,
-       .info = tms470_info
-};
 
-/* ---------------------------------------------------------------------- 
+
+/* ----------------------------------------------------------------------
                       Internal Support, Helpers
    ---------------------------------------------------------------------- */
 
-const flash_sector_t TMS470R1A256_SECTORS[] = {
+const struct flash_sector TMS470R1A256_SECTORS[] = {
        {0x00000000, 0x00002000, -1, -1},
        {0x00002000, 0x00002000, -1, -1},
        {0x00004000, 0x00002000, -1, -1},
@@ -75,7 +48,7 @@ const flash_sector_t TMS470R1A256_SECTORS[] = {
 #define TMS470R1A256_NUM_SECTORS \
        (sizeof(TMS470R1A256_SECTORS)/sizeof(TMS470R1A256_SECTORS[0]))
 
-const flash_sector_t TMS470R1A288_BANK0_SECTORS[] = {
+const struct flash_sector TMS470R1A288_BANK0_SECTORS[] = {
        {0x00000000, 0x00002000, -1, -1},
        {0x00002000, 0x00002000, -1, -1},
        {0x00004000, 0x00002000, -1, -1},
@@ -85,7 +58,7 @@ const flash_sector_t TMS470R1A288_BANK0_SECTORS[] = {
 #define TMS470R1A288_BANK0_NUM_SECTORS \
        (sizeof(TMS470R1A288_BANK0_SECTORS)/sizeof(TMS470R1A288_BANK0_SECTORS[0]))
 
-const flash_sector_t TMS470R1A288_BANK1_SECTORS[] = {
+const struct flash_sector TMS470R1A288_BANK1_SECTORS[] = {
        {0x00040000, 0x00010000, -1, -1},
        {0x00050000, 0x00010000, -1, -1},
        {0x00060000, 0x00010000, -1, -1},
@@ -95,7 +68,7 @@ const flash_sector_t TMS470R1A288_BANK1_SECTORS[] = {
 #define TMS470R1A288_BANK1_NUM_SECTORS \
        (sizeof(TMS470R1A288_BANK1_SECTORS)/sizeof(TMS470R1A288_BANK1_SECTORS[0]))
 
-const flash_sector_t TMS470R1A384_BANK0_SECTORS[] = {
+const struct flash_sector TMS470R1A384_BANK0_SECTORS[] = {
        {0x00000000, 0x00002000, -1, -1},
        {0x00002000, 0x00002000, -1, -1},
        {0x00004000, 0x00004000, -1, -1},
@@ -111,7 +84,7 @@ const flash_sector_t TMS470R1A384_BANK0_SECTORS[] = {
 #define TMS470R1A384_BANK0_NUM_SECTORS \
        (sizeof(TMS470R1A384_BANK0_SECTORS)/sizeof(TMS470R1A384_BANK0_SECTORS[0]))
 
-const flash_sector_t TMS470R1A384_BANK1_SECTORS[] = {
+const struct flash_sector TMS470R1A384_BANK1_SECTORS[] = {
        {0x00020000, 0x00008000, -1, -1},
        {0x00028000, 0x00008000, -1, -1},
        {0x00030000, 0x00008000, -1, -1},
@@ -121,7 +94,7 @@ const flash_sector_t TMS470R1A384_BANK1_SECTORS[] = {
 #define TMS470R1A384_BANK1_NUM_SECTORS \
        (sizeof(TMS470R1A384_BANK1_SECTORS)/sizeof(TMS470R1A384_BANK1_SECTORS[0]))
 
-const flash_sector_t TMS470R1A384_BANK2_SECTORS[] = {
+const struct flash_sector TMS470R1A384_BANK2_SECTORS[] = {
        {0x00040000, 0x00008000, -1, -1},
        {0x00048000, 0x00008000, -1, -1},
        {0x00050000, 0x00008000, -1, -1},
@@ -133,15 +106,15 @@ const flash_sector_t TMS470R1A384_BANK2_SECTORS[] = {
 
 /* ---------------------------------------------------------------------- */
 
-static int tms470_read_part_info(struct flash_bank_s *bank)
+static int tms470_read_part_info(struct flash_bank *bank)
 {
-       tms470_flash_bank_t *tms470_info = bank->driver_priv;
-       target_t *target = bank->target;
-       u32 device_ident_reg;
-       u32 silicon_version;
-       u32 technology_family;
-       u32 rom_flash;
-       u32 part_number;
+       struct tms470_flash_bank *tms470_info = bank->driver_priv;
+       struct target *target = bank->target;
+       uint32_t device_ident_reg;
+       uint32_t silicon_version;
+       uint32_t technology_family;
+       uint32_t rom_flash;
+       uint32_t part_number;
        char *part_name;
 
        /* we shall not rely on the caller in this test, this function allocates memory,
@@ -152,7 +125,7 @@ static int tms470_read_part_info(struct flash_bank_s *bank)
        /* read and parse the device identification register */
        target_read_u32(target, 0xFFFFFFF0, &device_ident_reg);
 
-       LOG_INFO("device_ident_reg=0x%08x", device_ident_reg);
+       LOG_INFO("device_ident_reg = 0x%08" PRIx32 "", device_ident_reg);
 
        if ((device_ident_reg & 7) == 0)
        {
@@ -178,7 +151,7 @@ static int tms470_read_part_info(struct flash_bank_s *bank)
 
                if (bank->base >= 0x00040000)
                {
-                       LOG_ERROR("No %s flash bank contains base address 0x%08x.", part_name, bank->base);
+                       LOG_ERROR("No %s flash bank contains base address 0x%08" PRIx32 ".", part_name, bank->base);
                        return ERROR_FLASH_OPERATION_FAILED;
                }
                tms470_info->ordinal = 0;
@@ -224,7 +197,7 @@ static int tms470_read_part_info(struct flash_bank_s *bank)
                }
                else
                {
-                       LOG_ERROR("No %s flash bank contains base address 0x%08x.", part_name, bank->base);
+                       LOG_ERROR("No %s flash bank contains base address 0x%08" PRIx32 ".", part_name, bank->base);
                        return ERROR_FLASH_OPERATION_FAILED;
                }
                break;
@@ -273,13 +246,13 @@ static int tms470_read_part_info(struct flash_bank_s *bank)
                }
                else
                {
-                       LOG_ERROR("No %s flash bank contains base address 0x%08x.", part_name, bank->base);
+                       LOG_ERROR("No %s flash bank contains base address 0x%08" PRIx32 ".", 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);
+               LOG_WARNING("Could not identify part 0x%02x as a member of the TMS470 family.", (unsigned)part_number);
                return ERROR_FLASH_OPERATION_FAILED;
        }
 
@@ -290,7 +263,11 @@ static int tms470_read_part_info(struct flash_bank_s *bank)
        bank->chip_width = 32;
        bank->bus_width = 32;
 
-       LOG_INFO("Identified %s, ver=%d, core=%s, nvmem=%s.", part_name, silicon_version, (technology_family ? "1.8v" : "3.3v"), (rom_flash ? "rom" : "flash"));
+       LOG_INFO("Identified %s, ver=%d, core=%s, nvmem=%s.",
+                part_name,
+                (int)(silicon_version),
+                (technology_family ? "1.8v" : "3.3v"),
+                (rom_flash ? "rom" : "flash"));
 
        tms470_info->device_ident_reg = device_ident_reg;
        tms470_info->silicon_version = silicon_version;
@@ -309,10 +286,10 @@ static int tms470_read_part_info(struct flash_bank_s *bank)
 
 /* ---------------------------------------------------------------------- */
 
-static u32 keysSet = 0;
-static u32 flashKeys[4];
+static uint32_t keysSet = 0;
+static uint32_t flashKeys[4];
 
-static int tms470_handle_flash_keyset_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+COMMAND_HANDLER(tms470_handle_flash_keyset_command)
 {
        if (argc > 4)
        {
@@ -327,7 +304,7 @@ static int tms470_handle_flash_keyset_command(struct command_context_s *cmd_ctx,
                {
                        int start = (0 == strncmp(args[i], "0x", 2)) ? 2 : 0;
 
-                       if (1 != sscanf(&args[i][start], "%x", &flashKeys[i]))
+                       if (1 != sscanf(&args[i][start], "%" SCNx32 "", &flashKeys[i]))
                        {
                                command_print(cmd_ctx, "could not process flash key %s", args[i]);
                                LOG_ERROR("could not process flash key %s", args[i]);
@@ -345,7 +322,8 @@ static int tms470_handle_flash_keyset_command(struct command_context_s *cmd_ctx,
 
        if (keysSet)
        {
-               command_print(cmd_ctx, "using flash keys 0x%08x, 0x%08x, 0x%08x, 0x%08x", flashKeys[0], flashKeys[1], flashKeys[2], flashKeys[3]);
+               command_print(cmd_ctx, "using flash keys 0x%08" PRIx32 ", 0x%08" PRIx32 ", 0x%08" PRIx32 ", 0x%08" PRIx32 "",
+                             flashKeys[0], flashKeys[1], flashKeys[2], flashKeys[3]);
        }
        else
        {
@@ -355,19 +333,19 @@ static int tms470_handle_flash_keyset_command(struct command_context_s *cmd_ctx,
        return ERROR_OK;
 }
 
-static const u32 FLASH_KEYS_ALL_ONES[] = { 0xFFFFFFFF, 0xFFFFFFFF,
+static const uint32_t FLASH_KEYS_ALL_ONES[] = { 0xFFFFFFFF, 0xFFFFFFFF,
        0xFFFFFFFF, 0xFFFFFFFF,
 };
 
-static const u32 FLASH_KEYS_ALL_ZEROS[] = { 0x00000000, 0x00000000,
+static const uint32_t FLASH_KEYS_ALL_ZEROS[] = { 0x00000000, 0x00000000,
        0x00000000, 0x00000000,
 };
 
-static const u32 FLASH_KEYS_MIX1[] = { 0xf0fff0ff, 0xf0fff0ff,
+static const uint32_t FLASH_KEYS_MIX1[] = { 0xf0fff0ff, 0xf0fff0ff,
        0xf0fff0ff, 0xf0fff0ff
 };
 
-static const u32 FLASH_KEYS_MIX2[] = { 0x0000ffff, 0x0000ffff,
+static const uint32_t FLASH_KEYS_MIX2[] = { 0x0000ffff, 0x0000ffff,
        0x0000ffff, 0x0000ffff
 };
 
@@ -375,7 +353,7 @@ static const u32 FLASH_KEYS_MIX2[] = { 0x0000ffff, 0x0000ffff,
 
 static int oscMHz = 12;
 
-static int tms470_handle_osc_megahertz_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+COMMAND_HANDLER(tms470_handle_osc_megahertz_command)
 {
        if (argc > 1)
        {
@@ -404,11 +382,11 @@ static int tms470_handle_osc_megahertz_command(struct command_context_s *cmd_ctx
 
 static int plldis = 0;
 
-static int tms470_handle_plldis_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+COMMAND_HANDLER(tms470_handle_plldis_command)
 {
        if (argc > 1)
        {
-               command_print(cmd_ctx, "tms470 plldis <0|1>");
+               command_print(cmd_ctx, "tms470 plldis <0 | 1>");
                return ERROR_INVALID_ARGUMENTS;
        }
        else if (argc == 1)
@@ -424,20 +402,20 @@ static int tms470_handle_plldis_command(struct command_context_s *cmd_ctx, char
 
 /* ---------------------------------------------------------------------- */
 
-static int tms470_check_flash_unlocked(target_t * target)
+static int tms470_check_flash_unlocked(struct target * target)
 {
-       u32 fmbbusy;
+       uint32_t fmbbusy;
 
        target_read_u32(target, 0xFFE89C08, &fmbbusy);
-       LOG_INFO("tms470 fmbbusy=0x%08x -> %s", fmbbusy, fmbbusy & 0x8000 ? "unlocked" : "LOCKED");
+       LOG_INFO("tms470 fmbbusy = 0x%08" PRIx32 " -> %s", fmbbusy, fmbbusy & 0x8000 ? "unlocked" : "LOCKED");
        return fmbbusy & 0x8000 ? ERROR_OK : ERROR_FLASH_OPERATION_FAILED;
 }
 
 /* ---------------------------------------------------------------------- */
 
-static int tms470_try_flash_keys(target_t * target, const u32 * key_set)
+static int tms470_try_flash_keys(struct target * target, const uint32_t * key_set)
 {
-       u32 glbctrl, fmmstat;
+       uint32_t glbctrl, fmmstat;
        int retval = ERROR_FLASH_OPERATION_FAILED;
 
        /* set GLBCTRL.4  */
@@ -449,7 +427,7 @@ static int tms470_try_flash_keys(target_t * target, const u32 * key_set)
        if (!(fmmstat & 0x08))
        {
                unsigned i;
-               u32 fmbptr, fmbac2, orig_fmregopt;
+               uint32_t fmbptr, fmbac2, orig_fmregopt;
 
                target_write_u32(target, 0xFFE8BC04, fmmstat & ~0x07);
 
@@ -471,7 +449,7 @@ static int tms470_try_flash_keys(target_t * target, const u32 * key_set)
 
                for (i = 0; i < 4; i++)
                {
-                       u32 tmp;
+                       uint32_t tmp;
 
                        /* There is no point displaying the value of tmp, it is
                         * filtered by the chip.  The purpose of this read is to
@@ -479,20 +457,20 @@ static int tms470_try_flash_keys(target_t * target, const u32 * key_set)
                         */
                        target_read_u32(target, 0x00001FF0 + 4 * i, &tmp);
 
-                       LOG_INFO("tms470 writing fmpkey=0x%08x", key_set[i]);
+                       LOG_INFO("tms470 writing fmpkey = 0x%08" PRIx32 "", key_set[i]);
                        target_write_u32(target, 0xFFE89C0C, key_set[i]);
                }
 
                if (ERROR_OK == tms470_check_flash_unlocked(target))
                {
-                       /* 
+                       /*
                         * There seems to be a side-effect of reading the FMPKEY
                         * register in that it re-enables the protection.  So we
                         * re-enable it.
                         */
                        for (i = 0; i < 4; i++)
                        {
-                               u32 tmp;
+                               uint32_t tmp;
 
                                target_read_u32(target, 0x00001FF0 + 4 * i, &tmp);
                                target_write_u32(target, 0xFFE89C0C, key_set[i]);
@@ -513,10 +491,10 @@ static int tms470_try_flash_keys(target_t * target, const u32 * key_set)
 
 /* ---------------------------------------------------------------------- */
 
-static int tms470_unlock_flash(struct flash_bank_s *bank)
+static int tms470_unlock_flash(struct flash_bank *bank)
 {
-       target_t *target = bank->target;
-       const u32 *p_key_sets[5];
+       struct target *target = bank->target;
+       const uint32_t *p_key_sets[5];
        unsigned i, key_set_count;
 
        if (keysSet)
@@ -552,11 +530,11 @@ static int tms470_unlock_flash(struct flash_bank_s *bank)
 
 /* ---------------------------------------------------------------------- */
 
-static int tms470_flash_initialize_internal_state_machine(struct flash_bank_s *bank)
+static int tms470_flash_initialize_internal_state_machine(struct flash_bank *bank)
 {
-       u32 fmmac2, fmmac1, fmmaxep, k, delay, glbctrl, sysclk;
-       target_t *target = bank->target;
-       tms470_flash_bank_t *tms470_info = bank->driver_priv;
+       uint32_t fmmac2, fmmac1, fmmaxep, k, delay, glbctrl, sysclk;
+       struct target *target = bank->target;
+       struct tms470_flash_bank *tms470_info = bank->driver_priv;
        int result = ERROR_OK;
 
        /*
@@ -567,7 +545,7 @@ static int tms470_flash_initialize_internal_state_machine(struct flash_bank_s *b
        fmmac2 &= ~0x0007;
        fmmac2 |= (tms470_info->ordinal & 7);
        target_write_u32(target, 0xFFE8BC04, fmmac2);
-       LOG_DEBUG("set fmmac2=0x%04x", fmmac2);
+       LOG_DEBUG("set fmmac2 = 0x%04" PRIx32 "", fmmac2);
 
        /*
         * Disable level 1 sector protection by setting bit 15 of FMMAC1.
@@ -575,25 +553,25 @@ static int tms470_flash_initialize_internal_state_machine(struct flash_bank_s *b
        target_read_u32(target, 0xFFE8BC00, &fmmac1);
        fmmac1 |= 0x8000;
        target_write_u32(target, 0xFFE8BC00, fmmac1);
-       LOG_DEBUG("set fmmac1=0x%04x", fmmac1);
+       LOG_DEBUG("set fmmac1 = 0x%04" PRIx32 "", fmmac1);
 
        /*
-        * FMTCREG=0x2fc0;
+        * FMTCREG = 0x2fc0;
         */
        target_write_u32(target, 0xFFE8BC10, 0x2fc0);
-       LOG_DEBUG("set fmtcreg=0x2fc0");
+       LOG_DEBUG("set fmtcreg = 0x2fc0");
 
        /*
-        * MAXPP=50
+        * MAXPP = 50
         */
        target_write_u32(target, 0xFFE8A07C, 50);
-       LOG_DEBUG("set fmmaxpp=50");
+       LOG_DEBUG("set fmmaxpp = 50");
 
        /*
-        * MAXCP=0xf000+2000
+        * MAXCP = 0xf000 + 2000
         */
        target_write_u32(target, 0xFFE8A084, 0xf000 + 2000);
-       LOG_DEBUG("set fmmaxcp=0x%04x", 0xf000 + 2000);
+       LOG_DEBUG("set fmmaxcp = 0x%04x", 0xf000 + 2000);
 
        /*
         * configure VHV
@@ -603,22 +581,22 @@ static int tms470_flash_initialize_internal_state_machine(struct flash_bank_s *b
        {
                fmmaxep = 0xf000 + 4095;
                target_write_u32(target, 0xFFE8A80C, 0x9964);
-               LOG_DEBUG("set fmptr3=0x9964");
+               LOG_DEBUG("set fmptr3 = 0x9964");
        }
        else
        {
                fmmaxep = 0xa000 + 4095;
                target_write_u32(target, 0xFFE8A80C, 0x9b64);
-               LOG_DEBUG("set fmptr3=0x9b64");
+               LOG_DEBUG("set fmptr3 = 0x9b64");
        }
        target_write_u32(target, 0xFFE8A080, fmmaxep);
-       LOG_DEBUG("set fmmaxep=0x%04x", fmmaxep);
+       LOG_DEBUG("set fmmaxep = 0x%04" PRIx32 "", fmmaxep);
 
        /*
-        * FMPTR4=0xa000
+        * FMPTR4 = 0xa000
         */
        target_write_u32(target, 0xFFE8A810, 0xa000);
-       LOG_DEBUG("set fmptr4=0xa000");
+       LOG_DEBUG("set fmptr4 = 0xa000");
 
        /*
         * FMPESETUP, delay parameter selected based on clock frequency.
@@ -632,70 +610,70 @@ static int tms470_flash_initialize_internal_state_machine(struct flash_bank_s *b
        sysclk = (plldis ? 1 : (glbctrl & 0x08) ? 4 : 8) * oscMHz / (1 + (glbctrl & 7));
        delay = (sysclk > 10) ? (sysclk + 1) / 2 : 5;
        target_write_u32(target, 0xFFE8A018, (delay << 4) | (delay << 8));
-       LOG_DEBUG("set fmpsetup=0x%04x", (delay << 4) | (delay << 8));
+       LOG_DEBUG("set fmpsetup = 0x%04" PRIx32 "", (delay << 4) | (delay << 8));
 
        /*
         * FMPVEVACCESS, based on delay.
         */
        k = delay | (delay << 8);
        target_write_u32(target, 0xFFE8A05C, k);
-       LOG_DEBUG("set fmpvevaccess=0x%04x", k);
+       LOG_DEBUG("set fmpvevaccess = 0x%04" PRIx32 "", k);
 
        /*
         * FMPCHOLD, FMPVEVHOLD, FMPVEVSETUP, based on delay.
         */
        k <<= 1;
        target_write_u32(target, 0xFFE8A034, k);
-       LOG_DEBUG("set fmpchold=0x%04x", k);
+       LOG_DEBUG("set fmpchold = 0x%04" PRIx32 "", k);
        target_write_u32(target, 0xFFE8A040, k);
-       LOG_DEBUG("set fmpvevhold=0x%04x", k);
+       LOG_DEBUG("set fmpvevhold = 0x%04" PRIx32 "", k);
        target_write_u32(target, 0xFFE8A024, k);
-       LOG_DEBUG("set fmpvevsetup=0x%04x", k);
+       LOG_DEBUG("set fmpvevsetup = 0x%04" PRIx32 "", k);
 
        /*
         * FMCVACCESS, based on delay.
         */
        k = delay * 16;
        target_write_u32(target, 0xFFE8A060, k);
-       LOG_DEBUG("set fmcvaccess=0x%04x", k);
+       LOG_DEBUG("set fmcvaccess = 0x%04" PRIx32 "", k);
 
        /*
         * FMCSETUP, based on delay.
         */
        k = 0x3000 | delay * 20;
        target_write_u32(target, 0xFFE8A020, k);
-       LOG_DEBUG("set fmcsetup=0x%04x", k);
+       LOG_DEBUG("set fmcsetup = 0x%04" PRIx32 "", k);
 
        /*
         * FMEHOLD, based on delay.
         */
        k = (delay * 20) << 2;
        target_write_u32(target, 0xFFE8A038, k);
-       LOG_DEBUG("set fmehold=0x%04x", k);
+       LOG_DEBUG("set fmehold = 0x%04" PRIx32 "", k);
 
        /*
         * PWIDTH, CWIDTH, EWIDTH, based on delay.
         */
        target_write_u32(target, 0xFFE8A050, delay * 8);
-       LOG_DEBUG("set fmpwidth=0x%04x", delay * 8);
+       LOG_DEBUG("set fmpwidth = 0x%04" PRIx32 "", delay * 8);
        target_write_u32(target, 0xFFE8A058, delay * 1000);
-       LOG_DEBUG("set fmcwidth=0x%04x", delay * 1000);
+       LOG_DEBUG("set fmcwidth = 0x%04" PRIx32 "", delay * 1000);
        target_write_u32(target, 0xFFE8A054, delay * 5400);
-       LOG_DEBUG("set fmewidth=0x%04x", delay * 5400);
+       LOG_DEBUG("set fmewidth = 0x%04" PRIx32 "", delay * 5400);
 
        return result;
 }
 
 /* ---------------------------------------------------------------------- */
 
-int tms470_flash_status(struct flash_bank_s *bank)
+int tms470_flash_status(struct flash_bank *bank)
 {
-       target_t *target = bank->target;
+       struct target *target = bank->target;
        int result = ERROR_OK;
-       u32 fmmstat;
+       uint32_t fmmstat;
 
        target_read_u32(target, 0xFFE8BC0C, &fmmstat);
-       LOG_DEBUG("set fmmstat=0x%04x", fmmstat);
+       LOG_DEBUG("set fmmstat = 0x%04" PRIx32 "", fmmstat);
 
        if (fmmstat & 0x0080)
        {
@@ -744,25 +722,25 @@ int tms470_flash_status(struct flash_bank_s *bank)
 
 /* ---------------------------------------------------------------------- */
 
-static int tms470_erase_sector(struct flash_bank_s *bank, int sector)
+static int tms470_erase_sector(struct flash_bank *bank, int sector)
 {
-       u32 glbctrl, orig_fmregopt, fmbsea, fmbseb, fmmstat;
-       target_t *target = bank->target;
-       u32 flashAddr = bank->base + bank->sectors[sector].offset;
+       uint32_t glbctrl, orig_fmregopt, fmbsea, fmbseb, fmmstat;
+       struct target *target = bank->target;
+       uint32_t flashAddr = bank->base + bank->sectors[sector].offset;
        int result = ERROR_OK;
 
-       /* 
+       /*
         * Set the bit GLBCTRL4 of the GLBCTRL register (in the System
         * module) to enable writing to the flash registers }.
         */
        target_read_u32(target, 0xFFFFFFDC, &glbctrl);
        target_write_u32(target, 0xFFFFFFDC, glbctrl | 0x10);
-       LOG_DEBUG("set glbctrl=0x%08x", glbctrl | 0x10);
+       LOG_DEBUG("set glbctrl = 0x%08" PRIx32 "", glbctrl | 0x10);
 
        /* Force normal read mode. */
        target_read_u32(target, 0xFFE89C00, &orig_fmregopt);
        target_write_u32(target, 0xFFE89C00, 0);
-       LOG_DEBUG("set fmregopt=0x%08x", 0);
+       LOG_DEBUG("set fmregopt = 0x%08x", 0);
 
        (void)tms470_flash_initialize_internal_state_machine(bank);
 
@@ -774,25 +752,25 @@ static int tms470_erase_sector(struct flash_bank_s *bank, int sector)
        {
                target_read_u32(target, 0xFFE88008, &fmbsea);
                target_write_u32(target, 0xFFE88008, fmbsea | (1 << sector));
-               LOG_DEBUG("set fmbsea=0x%04x", fmbsea | (1 << sector));
+               LOG_DEBUG("set fmbsea = 0x%04" PRIx32 "", fmbsea | (1 << sector));
        }
        else
        {
                target_read_u32(target, 0xFFE8800C, &fmbseb);
                target_write_u32(target, 0xFFE8800C, fmbseb | (1 << (sector - 16)));
-               LOG_DEBUG("set fmbseb=0x%04x", fmbseb | (1 << (sector - 16)));
+               LOG_DEBUG("set fmbseb = 0x%04" PRIx32 "", fmbseb | (1 << (sector - 16)));
        }
        bank->sectors[sector].is_protected = 0;
 
-       /* 
-        * clear status regiser, sent erase command, kickoff erase 
+       /*
+        * 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%08" PRIx32 "=0x0040", flashAddr);
        target_write_u16(target, flashAddr, 0x0020);
-       LOG_DEBUG("write *(u16 *)0x%08x=0x0020", flashAddr);
+       LOG_DEBUG("write *(uint16_t *)0x%08" PRIx32 "=0x0020", flashAddr);
        target_write_u16(target, flashAddr, 0xffff);
-       LOG_DEBUG("write *(u16 *)0x%08x=0xffff", flashAddr);
+       LOG_DEBUG("write *(uint16_t *)0x%08" PRIx32 "=0xffff", flashAddr);
 
        /*
         * Monitor FMMSTAT, busy until clear, then check and other flags for
@@ -813,19 +791,19 @@ static int tms470_erase_sector(struct flash_bank_s *bank, int sector)
        if (sector < 16)
        {
                target_write_u32(target, 0xFFE88008, fmbsea);
-               LOG_DEBUG("set fmbsea=0x%04x", fmbsea);
+               LOG_DEBUG("set fmbsea = 0x%04" PRIx32 "", fmbsea);
                bank->sectors[sector].is_protected = fmbsea & (1 << sector) ? 0 : 1;
        }
        else
        {
                target_write_u32(target, 0xFFE8800C, fmbseb);
-               LOG_DEBUG("set fmbseb=0x%04x", fmbseb);
+               LOG_DEBUG("set fmbseb = 0x%04" PRIx32 "", fmbseb);
                bank->sectors[sector].is_protected = fmbseb & (1 << (sector - 16)) ? 0 : 1;
        }
        target_write_u32(target, 0xFFE89C00, orig_fmregopt);
-       LOG_DEBUG("set fmregopt=0x%08x", orig_fmregopt);
+       LOG_DEBUG("set fmregopt = 0x%08" PRIx32 "", orig_fmregopt);
        target_write_u32(target, 0xFFFFFFDC, glbctrl);
-       LOG_DEBUG("set glbctrl=0x%08x", glbctrl);
+       LOG_DEBUG("set glbctrl = 0x%08" PRIx32 "", glbctrl);
 
        if (result == ERROR_OK)
        {
@@ -835,11 +813,11 @@ static int tms470_erase_sector(struct flash_bank_s *bank, int sector)
        return result;
 }
 
-/* ---------------------------------------------------------------------- 
+/* ----------------------------------------------------------------------
               Implementation of Flash Driver Interfaces
    ---------------------------------------------------------------------- */
 
-static int tms470_register_commands(struct command_context_s *cmd_ctx)
+static int tms470_register_commands(struct command_context *cmd_ctx)
 {
        command_t *tms470_cmd = register_command(cmd_ctx, NULL, "tms470", NULL, COMMAND_ANY, "applies to TI tms470 family");
 
@@ -852,9 +830,9 @@ static int tms470_register_commands(struct command_context_s *cmd_ctx)
 
 /* ---------------------------------------------------------------------- */
 
-static int tms470_erase(struct flash_bank_s *bank, int first, int last)
+static int tms470_erase(struct flash_bank *bank, int first, int last)
 {
-       tms470_flash_bank_t *tms470_info = bank->driver_priv;
+       struct tms470_flash_bank *tms470_info = bank->driver_priv;
        int sector, result = ERROR_OK;
 
        if (bank->target->state != TARGET_HALTED)
@@ -899,11 +877,11 @@ 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_protect(struct flash_bank *bank, int set, int first, int last)
 {
-       tms470_flash_bank_t *tms470_info = bank->driver_priv;
-       target_t *target = bank->target;
-       u32 fmmac2, fmbsea, fmbseb;
+       struct tms470_flash_bank *tms470_info = bank->driver_priv;
+       struct target *target = bank->target;
+       uint32_t fmmac2, fmbsea, fmbseb;
        int sector;
 
        if (target->state != TARGET_HALTED)
@@ -951,12 +929,12 @@ static int tms470_protect(struct flash_bank_s *bank, int set, int first, int las
 
 /* ---------------------------------------------------------------------- */
 
-static int tms470_write(struct flash_bank_s *bank, u8 * buffer, u32 offset, u32 count)
+static int tms470_write(struct flash_bank *bank, uint8_t * buffer, uint32_t offset, uint32_t count)
 {
-       target_t *target = bank->target;
-       u32 glbctrl, fmbac2, orig_fmregopt, fmbsea, fmbseb, fmmaxpp, fmmstat;
+       struct target *target = bank->target;
+       uint32_t glbctrl, fmbac2, orig_fmregopt, fmbsea, fmbseb, fmmaxpp, fmmstat;
        int result = ERROR_OK;
-       u32 i;
+       uint32_t i;
 
        if (target->state != TARGET_HALTED)
        {
@@ -966,7 +944,7 @@ static int tms470_write(struct flash_bank_s *bank, u8 * buffer, u32 offset, u32
 
        tms470_read_part_info(bank);
 
-       LOG_INFO("Writing %d bytes starting at 0x%08x", count, bank->base + offset);
+       LOG_INFO("Writing %" PRId32 " bytes starting at 0x%08" PRIx32 "", count, bank->base + offset);
 
        /* set GLBCTRL.4  */
        target_read_u32(target, 0xFFFFFFDC, &glbctrl);
@@ -995,12 +973,12 @@ static int tms470_write(struct flash_bank_s *bank, u8 * buffer, u32 offset, u32
 
        for (i = 0; i < count; i += 2)
        {
-               u32 addr = bank->base + offset + i;
-               u16 word = (((u16) buffer[i]) << 8) | (u16) buffer[i + 1];
+               uint32_t addr = bank->base + offset + i;
+               uint16_t word = (((uint16_t) buffer[i]) << 8) | (uint16_t) buffer[i + 1];
 
                if (word != 0xffff)
                {
-                       LOG_INFO("writing 0x%04x at 0x%08x", word, addr);
+                       LOG_INFO("writing 0x%04x at 0x%08" PRIx32 "", word, addr);
 
                        /* clear status register */
                        target_write_u16(target, addr, 0x0040);
@@ -1025,15 +1003,15 @@ static int tms470_write(struct flash_bank_s *bank, u8 * buffer, u32 offset, u32
 
                        if (fmmstat & 0x3ff)
                        {
-                               LOG_ERROR("fmstat=0x%04x", fmmstat);
-                               LOG_ERROR("Could not program word 0x%04x at address 0x%08x.", word, addr);
+                               LOG_ERROR("fmstat = 0x%04" PRIx32 "", fmmstat);
+                               LOG_ERROR("Could not program word 0x%04x at address 0x%08" PRIx32 ".", word, addr);
                                result = ERROR_FLASH_OPERATION_FAILED;
                                break;
                        }
                }
                else
                {
-                       LOG_INFO("skipping 0xffff at 0x%08x", addr);
+                       LOG_INFO("skipping 0xffff at 0x%08" PRIx32 "", addr);
                }
        }
 
@@ -1049,7 +1027,7 @@ static int tms470_write(struct flash_bank_s *bank, u8 * buffer, u32 offset, u32
 
 /* ---------------------------------------------------------------------- */
 
-static int tms470_probe(struct flash_bank_s *bank)
+static int tms470_probe(struct flash_bank *bank)
 {
        if (bank->target->state != TARGET_HALTED)
        {
@@ -1060,9 +1038,9 @@ static int tms470_probe(struct flash_bank_s *bank)
        return tms470_read_part_info(bank);
 }
 
-static int tms470_auto_probe(struct flash_bank_s *bank)
+static int tms470_auto_probe(struct flash_bank *bank)
 {
-       tms470_flash_bank_t *tms470_info = bank->driver_priv;
+       struct tms470_flash_bank *tms470_info = bank->driver_priv;
 
        if (tms470_info->device_ident_reg)
                return ERROR_OK;
@@ -1071,13 +1049,13 @@ static int tms470_auto_probe(struct flash_bank_s *bank)
 
 /* ---------------------------------------------------------------------- */
 
-static int tms470_erase_check(struct flash_bank_s *bank)
+static int tms470_erase_check(struct flash_bank *bank)
 {
-       target_t *target = bank->target;
-       tms470_flash_bank_t *tms470_info = bank->driver_priv;
+       struct target *target = bank->target;
+       struct tms470_flash_bank *tms470_info = bank->driver_priv;
        int sector, result = ERROR_OK;
-       u32 fmmac2, fmbac2, glbctrl, orig_fmregopt;
-       static u8 buffer[64 * 1024];
+       uint32_t fmmac2, fmbac2, glbctrl, orig_fmregopt;
+       static uint8_t buffer[64 * 1024];
 
        if (target->state != TARGET_HALTED)
        {
@@ -1102,7 +1080,7 @@ static int tms470_erase_check(struct flash_bank_s *bank)
        target_read_u32(target, 0xFFE8BC04, &fmmac2);
        target_write_u32(target, 0xFFE8BC04, (fmmac2 & ~7) | tms470_info->ordinal);
 
-       /* TCR=0 */
+       /* TCR = 0 */
        target_write_u32(target, 0xFFE8BC10, 0x2fc0);
 
        /* clear TEZ in fmbrdy */
@@ -1112,7 +1090,7 @@ static int tms470_erase_check(struct flash_bank_s *bank)
        target_read_u32(target, 0xFFE88004, &fmbac2);
        target_write_u32(target, 0xFFE88004, fmbac2 | 0xff);
 
-       /* 
+       /*
         * The TI primitives inspect the flash memory by reading one 32-bit
         * word at a time.  Here we read an entire sector and inspect it in
         * an attempt to reduce the JTAG overhead.
@@ -1121,7 +1099,7 @@ static int tms470_erase_check(struct flash_bank_s *bank)
        {
                if (bank->sectors[sector].is_erased != 1)
                {
-                       u32 i, addr = bank->base + bank->sectors[sector].offset;
+                       uint32_t i, addr = bank->base + bank->sectors[sector].offset;
 
                        LOG_INFO("checking flash bank %d sector %d", tms470_info->ordinal, sector);
 
@@ -1133,7 +1111,7 @@ static int tms470_erase_check(struct flash_bank_s *bank)
                                if (buffer[i] != 0xff)
                                {
                                        LOG_WARNING("tms470 bank %d, sector %d, not erased.", tms470_info->ordinal, sector);
-                                       LOG_WARNING("at location 0x%08x: flash data is 0x%02x.", addr + i, buffer[i]);
+                                       LOG_WARNING("at location 0x%08" PRIx32 ": flash data is 0x%02x.", addr + i, buffer[i]);
 
                                        bank->sectors[sector].is_erased = 0;
                                        break;
@@ -1162,12 +1140,12 @@ static int tms470_erase_check(struct flash_bank_s *bank)
 
 /* ---------------------------------------------------------------------- */
 
-static int tms470_protect_check(struct flash_bank_s *bank)
+static int tms470_protect_check(struct flash_bank *bank)
 {
-       target_t *target = bank->target;
-       tms470_flash_bank_t *tms470_info = bank->driver_priv;
+       struct target *target = bank->target;
+       struct tms470_flash_bank *tms470_info = bank->driver_priv;
        int sector, result = ERROR_OK;
-       u32 fmmac2, fmbsea, fmbseb;
+       uint32_t fmmac2, fmbsea, fmbseb;
 
        if (target->state != TARGET_HALTED)
        {
@@ -1210,10 +1188,10 @@ static int tms470_protect_check(struct flash_bank_s *bank)
 
 /* ---------------------------------------------------------------------- */
 
-static int tms470_info(struct flash_bank_s *bank, char *buf, int buf_size)
+static int tms470_info(struct flash_bank *bank, char *buf, int buf_size)
 {
        int used = 0;
-       tms470_flash_bank_t *tms470_info = bank->driver_priv;
+       struct tms470_flash_bank *tms470_info = bank->driver_priv;
 
        if (!tms470_info->device_ident_reg)
        {
@@ -1244,16 +1222,30 @@ static int tms470_info(struct flash_bank_s *bank, char *buf, int buf_size)
  * [options...]
  */
 
-static int tms470_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank)
+FLASH_BANK_COMMAND_HANDLER(tms470_flash_bank_command)
 {
-       bank->driver_priv = malloc(sizeof(tms470_flash_bank_t));
+       bank->driver_priv = malloc(sizeof(struct tms470_flash_bank));
 
        if (!bank->driver_priv)
        {
                return ERROR_FLASH_OPERATION_FAILED;
        }
 
-       (void)memset(bank->driver_priv, 0, sizeof(tms470_flash_bank_t));
+       (void)memset(bank->driver_priv, 0, sizeof(struct tms470_flash_bank));
 
        return ERROR_OK;
 }
+
+struct flash_driver tms470_flash = {
+               .name = "tms470",
+               .register_commands = &tms470_register_commands,
+               .flash_bank_command = &tms470_flash_bank_command,
+               .erase = &tms470_erase,
+               .protect = &tms470_protect,
+               .write = &tms470_write,
+               .probe = &tms470_probe,
+               .auto_probe = &tms470_auto_probe,
+               .erase_check = &tms470_erase_check,
+               .protect_check = &tms470_protect_check,
+               .info = &tms470_info,
+       };

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)