1 /***************************************************************************
2 * (c) Copyright 2007, 2008 by Christopher Kilgour *
3 * techie |_at_| whiterocker |_dot_| com *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
31 tms470_register_commands( struct command_context_s
*cmd_ctx
);
34 tms470_flash_bank_command( struct command_context_s
*cmd_ctx
,
38 struct flash_bank_s
*bank
);
41 tms470_erase( struct flash_bank_s
*bank
,
46 tms470_protect( struct flash_bank_s
*bank
,
52 tms470_write( struct flash_bank_s
*bank
,
58 tms470_probe( struct flash_bank_s
*bank
);
61 tms470_erase_check( struct flash_bank_s
*bank
);
64 tms470_protect_check( struct flash_bank_s
*bank
);
67 tms470_info( struct flash_bank_s
*bank
,
71 flash_driver_t tms470_flash
=
74 .register_commands
= tms470_register_commands
,
75 .flash_bank_command
= tms470_flash_bank_command
,
76 .erase
= tms470_erase
,
77 .protect
= tms470_protect
,
78 .write
= tms470_write
,
79 .probe
= tms470_probe
,
80 .erase_check
= tms470_erase_check
,
81 .protect_check
= tms470_protect_check
,
85 /* ----------------------------------------------------------------------
86 Internal Support, Helpers
87 ---------------------------------------------------------------------- */
89 const flash_sector_t TMS470R1A256_SECTORS
[] =
91 { 0x00000000, 0x00002000, -1, -1 },
92 { 0x00002000, 0x00002000, -1, -1 },
93 { 0x00004000, 0x00002000, -1, -1 },
94 { 0x00006000, 0x00002000, -1, -1 },
95 { 0x00008000, 0x00008000, -1, -1 },
96 { 0x00010000, 0x00008000, -1, -1 },
97 { 0x00018000, 0x00008000, -1, -1 },
98 { 0x00020000, 0x00008000, -1, -1 },
99 { 0x00028000, 0x00008000, -1, -1 },
100 { 0x00030000, 0x00008000, -1, -1 },
101 { 0x00038000, 0x00002000, -1, -1 },
102 { 0x0003A000, 0x00002000, -1, -1 },
103 { 0x0003C000, 0x00002000, -1, -1 },
104 { 0x0003E000, 0x00002000, -1, -1 },
107 #define TMS470R1A256_NUM_SECTORS \
108 (sizeof(TMS470R1A256_SECTORS)/sizeof(TMS470R1A256_SECTORS[0]))
110 const flash_sector_t TMS470R1A288_BANK0_SECTORS
[] =
112 { 0x00000000, 0x00002000, -1, -1 },
113 { 0x00002000, 0x00002000, -1, -1 },
114 { 0x00004000, 0x00002000, -1, -1 },
115 { 0x00006000, 0x00002000, -1, -1 },
118 #define TMS470R1A288_BANK0_NUM_SECTORS \
119 (sizeof(TMS470R1A288_BANK0_SECTORS)/sizeof(TMS470R1A288_BANK0_SECTORS[0]))
121 const flash_sector_t TMS470R1A288_BANK1_SECTORS
[] =
123 { 0x00040000, 0x00010000, -1, -1 },
124 { 0x00050000, 0x00010000, -1, -1 },
125 { 0x00060000, 0x00010000, -1, -1 },
126 { 0x00070000, 0x00010000, -1, -1 },
129 #define TMS470R1A288_BANK1_NUM_SECTORS \
130 (sizeof(TMS470R1A288_BANK1_SECTORS)/sizeof(TMS470R1A288_BANK1_SECTORS[0]))
132 /* ---------------------------------------------------------------------- */
135 tms470_read_part_info( struct flash_bank_s
*bank
)
137 tms470_flash_bank_t
*tms470_info
= bank
->driver_priv
;
138 target_t
*target
= bank
->target
;
139 u32 device_ident_reg
;
141 u32 technology_family
;
146 if (target
->state
!= TARGET_HALTED
)
148 WARNING( "Cannot communicate... target not halted." );
149 return ERROR_TARGET_NOT_HALTED
;
152 /* read and parse the device identification register */
153 target_read_u32( target
, 0xFFFFFFF0, &device_ident_reg
);
155 INFO( "device_ident_reg=0x%08x", device_ident_reg
);
157 if ((device_ident_reg
& 7) == 0)
159 WARNING( "Cannot identify target as a TMS470 family." );
160 return ERROR_FLASH_OPERATION_FAILED
;
163 silicon_version
= (device_ident_reg
>> 12) & 0xF;
164 technology_family
= (device_ident_reg
>> 11) & 1;
165 rom_flash
= (device_ident_reg
>> 10) & 1;
166 part_number
= (device_ident_reg
>> 3) & 0x7f;
169 * If the part number is known, determine if the flash bank is valid
170 * based on the base address being within the known flash bank
171 * ranges. Then fixup/complete the remaining fields of the flash
174 switch( part_number
)
177 part_name
= "TMS470R1A256";
179 if (bank
->base
>= 0x00040000)
181 ERROR( "No %s flash bank contains base address 0x%08x.",
182 part_name
, bank
->base
);
183 return ERROR_FLASH_OPERATION_FAILED
;
185 tms470_info
->ordinal
= 0;
186 bank
->base
= 0x00000000;
187 bank
->size
= 256*1024;
188 bank
->num_sectors
= TMS470R1A256_NUM_SECTORS
;
189 bank
->sectors
= malloc( sizeof( TMS470R1A256_SECTORS
) );
192 return ERROR_FLASH_OPERATION_FAILED
;
194 (void) memcpy( bank
->sectors
,
195 TMS470R1A256_SECTORS
,
196 sizeof( TMS470R1A256_SECTORS
) );
200 part_name
= "TMS470R1A288";
202 if ((bank
->base
>= 0x00000000) && (bank
->base
< 0x00008000))
204 tms470_info
->ordinal
= 0;
205 bank
->base
= 0x00000000;
206 bank
->size
= 32*1024;
207 bank
->num_sectors
= TMS470R1A288_BANK0_NUM_SECTORS
;
208 bank
->sectors
= malloc( sizeof( TMS470R1A288_BANK0_SECTORS
) );
211 return ERROR_FLASH_OPERATION_FAILED
;
213 (void) memcpy( bank
->sectors
,
214 TMS470R1A288_BANK0_SECTORS
,
215 sizeof( TMS470R1A288_BANK0_SECTORS
) );
217 else if ((bank
->base
>= 0x00040000) && (bank
->base
< 0x00080000))
219 tms470_info
->ordinal
= 1;
220 bank
->base
= 0x00040000;
221 bank
->size
= 256*1024;
222 bank
->num_sectors
= TMS470R1A288_BANK1_NUM_SECTORS
;
223 bank
->sectors
= malloc( sizeof( TMS470R1A288_BANK1_SECTORS
) );
226 return ERROR_FLASH_OPERATION_FAILED
;
228 (void) memcpy( bank
->sectors
,
229 TMS470R1A288_BANK1_SECTORS
,
230 sizeof( TMS470R1A288_BANK1_SECTORS
) );
234 ERROR( "No %s flash bank contains base address 0x%08x.",
235 part_name
, bank
->base
);
236 return ERROR_FLASH_OPERATION_FAILED
;
241 WARNING( "Could not identify part 0x%02x as a member of the TMS470 family.",
243 return ERROR_FLASH_OPERATION_FAILED
;
246 /* turn off memory selects */
247 target_write_u32( target
, 0xFFFFFFE4, 0x00000000 );
248 target_write_u32( target
, 0xFFFFFFE0, 0x00000000 );
250 bank
->chip_width
= 32;
251 bank
->bus_width
= 32;
253 INFO( "Identified %s, ver=%d, core=%s, nvmem=%s.",
256 (technology_family
? "1.8v" : "3.3v"),
257 (rom_flash
? "rom" : "flash") );
259 tms470_info
->device_ident_reg
= device_ident_reg
;
260 tms470_info
->silicon_version
= silicon_version
;
261 tms470_info
->technology_family
= technology_family
;
262 tms470_info
->rom_flash
= rom_flash
;
263 tms470_info
->part_number
= part_number
;
264 tms470_info
->part_name
= part_name
;
267 * Disable reset on address access violation.
269 target_write_u32( target
, 0xFFFFFFE0, 0x00004007 );
274 /* ---------------------------------------------------------------------- */
280 tms470_handle_flash_keyset_command( struct command_context_s
* cmd_ctx
,
287 command_print( cmd_ctx
, "tms470 flash_keyset <key0> <key1> <key2> <key3>" );
288 return ERROR_INVALID_ARGUMENTS
;
296 int start
= (0 == strncmp( args
[i
], "0x", 2 )) ? 2 : 0;
297 if (1 != sscanf( &args
[i
][start
], "%x", &flashKeys
[i
] ))
299 command_print( cmd_ctx
, "could not process flash key %s", args
[i
] );
300 ERROR( "could not process flash key %s", args
[i
] );
301 return ERROR_INVALID_ARGUMENTS
;
309 command_print( cmd_ctx
, "tms470 flash_keyset <key0> <key1> <key2> <key3>" );
310 return ERROR_INVALID_ARGUMENTS
;
315 command_print( cmd_ctx
, "using flash keys 0x%08x, 0x%08x, 0x%08x, 0x%08x",
316 flashKeys
[0], flashKeys
[1], flashKeys
[2], flashKeys
[3] );
320 command_print( cmd_ctx
, "flash keys not set" );
326 const u32 FLASH_KEYS_ALL_ONES
[] = { 0xFFFFFFFF, 0xFFFFFFFF,
327 0xFFFFFFFF, 0xFFFFFFFF, };
329 const u32 FLASH_KEYS_ALL_ZEROS
[] = { 0x00000000, 0x00000000,
330 0x00000000, 0x00000000, };
332 const u32 FLASH_KEYS_MIX1
[] = { 0xf0fff0ff, 0xf0fff0ff,
333 0xf0fff0ff, 0xf0fff0ff };
335 const u32 FLASH_KEYS_MIX2
[] = { 0x0000ffff, 0x0000ffff,
336 0x0000ffff, 0x0000ffff };
338 /* ---------------------------------------------------------------------- */
343 tms470_handle_osc_megahertz_command( struct command_context_s
* cmd_ctx
,
350 command_print( cmd_ctx
, "tms470 osc_megahertz <MHz>" );
351 return ERROR_INVALID_ARGUMENTS
;
355 sscanf( args
[0], "%d", &oscMHz
);
360 ERROR( "osc_megahertz must be positive and non-zero!" );
361 command_print( cmd_ctx
, "osc_megahertz must be positive and non-zero!" );
363 return ERROR_INVALID_ARGUMENTS
;
366 command_print( cmd_ctx
, "osc_megahertz=%d", oscMHz
);
371 /* ---------------------------------------------------------------------- */
376 tms470_handle_plldis_command( struct command_context_s
* cmd_ctx
,
383 command_print( cmd_ctx
, "tms470 plldis <0|1>" );
384 return ERROR_INVALID_ARGUMENTS
;
388 sscanf( args
[0], "%d", &plldis
);
389 plldis
= plldis
? 1 : 0;
392 command_print( cmd_ctx
, "plldis=%d", plldis
);
397 /* ---------------------------------------------------------------------- */
400 tms470_check_flash_unlocked( target_t
* target
)
404 target_read_u32( target
, 0xFFE89C08, &fmbbusy
);
405 INFO( "tms470 fmbbusy=0x%08x -> %s",
407 fmbbusy
& 0x8000 ? "unlocked" : "LOCKED" );
408 return fmbbusy
& 0x8000 ? ERROR_OK
: ERROR_FLASH_OPERATION_FAILED
;
411 /* ---------------------------------------------------------------------- */
414 tms470_try_flash_keys( target_t
* target
,
415 const u32
* key_set
)
417 u32 glbctrl
, fmmstat
;
418 int retval
= ERROR_FLASH_OPERATION_FAILED
;
421 target_read_u32( target
, 0xFFFFFFDC, &glbctrl
);
422 target_write_u32( target
, 0xFFFFFFDC, glbctrl
| 0x10 );
424 /* only perform the key match when 3VSTAT is clear */
425 target_read_u32( target
, 0xFFE8BC0C, &fmmstat
);
426 if (!(fmmstat
& 0x08))
429 u32 fmmac2
, fmbptr
, fmbac2
, fmbbusy
, orig_fmregopt
;
431 target_write_u32( target
, 0xFFE8BC04, fmmstat
& ~0x07 );
433 /* wait for pump ready */
436 target_read_u32( target
, 0xFFE8A814, &fmbptr
);
439 while( !(fmbptr
& 0x0200) );
441 /* force max wait states */
442 target_read_u32( target
, 0xFFE88004, &fmbac2
);
443 target_write_u32( target
, 0xFFE88004, fmbac2
| 0xff );
445 /* save current access mode, force normal read mode */
446 target_read_u32( target
, 0xFFE89C00, &orig_fmregopt
);
447 target_write_u32( target
, 0xFFE89C00, 0x00 );
453 /* There is no point displaying the value of tmp, it is
454 * filtered by the chip. The purpose of this read is to
455 * prime the unlocking logic rather than read out the value.
457 target_read_u32( target
, 0x00001FF0+4*i
, &tmp
);
459 INFO( "tms470 writing fmpkey=0x%08x", key_set
[i
] );
460 target_write_u32( target
, 0xFFE89C0C, key_set
[i
] );
463 if (ERROR_OK
== tms470_check_flash_unlocked( target
))
466 * There seems to be a side-effect of reading the FMPKEY
467 * register in that it re-enables the protection. So we
473 target_read_u32( target
, 0x00001FF0+4*i
, &tmp
);
474 target_write_u32( target
, 0xFFE89C0C, key_set
[i
] );
479 /* restore settings */
480 target_write_u32( target
, 0xFFE89C00, orig_fmregopt
);
481 target_write_u32( target
, 0xFFE88004, fmbac2
);
484 /* clear config bit */
485 target_write_u32( target
, 0xFFFFFFDC, glbctrl
);
490 /* ---------------------------------------------------------------------- */
493 tms470_unlock_flash( struct flash_bank_s
* bank
)
495 tms470_flash_bank_t
* tms470_info
= bank
->driver_priv
;
496 target_t
* target
= bank
->target
;
497 const u32
* p_key_sets
[5];
498 unsigned i
, key_set_count
;
502 p_key_sets
[0] = flashKeys
;
503 p_key_sets
[1] = FLASH_KEYS_ALL_ONES
;
504 p_key_sets
[2] = FLASH_KEYS_ALL_ZEROS
;
505 p_key_sets
[3] = FLASH_KEYS_MIX1
;
506 p_key_sets
[4] = FLASH_KEYS_MIX2
;
511 p_key_sets
[0] = FLASH_KEYS_ALL_ONES
;
512 p_key_sets
[1] = FLASH_KEYS_ALL_ZEROS
;
513 p_key_sets
[2] = FLASH_KEYS_MIX1
;
514 p_key_sets
[3] = FLASH_KEYS_MIX2
;
517 for( i
=0; i
<key_set_count
; i
++ )
519 if (tms470_try_flash_keys( target
, p_key_sets
[i
] ) == ERROR_OK
)
521 INFO( "tms470 flash is unlocked" );
526 WARNING( "tms470 could not unlock flash memory protection level 2" );
527 return ERROR_FLASH_OPERATION_FAILED
;
530 /* ---------------------------------------------------------------------- */
533 tms470_flash_initialize_internal_state_machine( struct flash_bank_s
* bank
)
535 u32 fmmac2
, fmmac1
, fmmaxep
, k
, delay
, glbctrl
, sysclk
;
536 target_t
*target
= bank
->target
;
537 tms470_flash_bank_t
* tms470_info
= bank
->driver_priv
;
538 int result
= ERROR_OK
;
541 * Select the desired bank to be programmed by writing BANK[2:0] of
544 target_read_u32( target
, 0xFFE8BC04, &fmmac2
);
546 fmmac2
|= (tms470_info
->ordinal
& 7);
547 target_write_u32( target
, 0xFFE8BC04, fmmac2
);
548 DEBUG( "set fmmac2=0x%04x", fmmac2
);
551 * Disable level 1 sector protection by setting bit 15 of FMMAC1.
553 target_read_u32( target
, 0xFFE8BC00, &fmmac1
);
555 target_write_u32( target
, 0xFFE8BC00, fmmac1
);
556 DEBUG( "set fmmac1=0x%04x", fmmac1
);
561 target_write_u32( target
, 0xFFE8BC10, 0x2fc0 );
562 DEBUG( "set fmtcreg=0x2fc0" );
567 target_write_u32( target
, 0xFFE8A07C, 50 );
568 DEBUG( "set fmmaxpp=50" );
573 target_write_u32( target
, 0xFFE8A084, 0xf000+2000 );
574 DEBUG( "set fmmaxcp=0x%04x", 0xf000+2000 );
579 target_read_u32( target
, 0xFFE8A080, &fmmaxep
);
580 if (fmmaxep
== 0xf000)
582 fmmaxep
= 0xf000+4095;
583 target_write_u32( target
, 0xFFE8A80C, 0x9964 );
584 DEBUG( "set fmptr3=0x9964" );
588 fmmaxep
= 0xa000+4095;
589 target_write_u32( target
, 0xFFE8A80C, 0x9b64 );
590 DEBUG( "set fmptr3=0x9b64" );
592 target_write_u32( target
, 0xFFE8A080, fmmaxep
);
593 DEBUG( "set fmmaxep=0x%04x", fmmaxep
);
598 target_write_u32( target
, 0xFFE8A810, 0xa000 );
599 DEBUG( "set fmptr4=0xa000" );
602 * FMPESETUP, delay parameter selected based on clock frequency.
604 * According to the TI App Note SPNU257 and flashing code, delay is
605 * int((sysclk(MHz) + 1) / 2), with a minimum of 5. The system
606 * clock is usually derived from the ZPLL module, and selected by
609 target_read_u32( target
, 0xFFFFFFDC, &glbctrl
);
610 sysclk
= (plldis
? 1 : (glbctrl
& 0x08) ? 4 : 8 ) * oscMHz
/ (1 + (glbctrl
& 7));
611 delay
= (sysclk
> 10) ? (sysclk
+ 1) / 2 : 5;
612 target_write_u32( target
, 0xFFE8A018, (delay
<<4)|(delay
<<8) );
613 DEBUG( "set fmpsetup=0x%04x", (delay
<<4)|(delay
<<8) );
616 * FMPVEVACCESS, based on delay.
618 k
= delay
|(delay
<<8);
619 target_write_u32( target
, 0xFFE8A05C, k
);
620 DEBUG( "set fmpvevaccess=0x%04x", k
);
623 * FMPCHOLD, FMPVEVHOLD, FMPVEVSETUP, based on delay.
626 target_write_u32( target
, 0xFFE8A034, k
);
627 DEBUG( "set fmpchold=0x%04x", k
);
628 target_write_u32( target
, 0xFFE8A040, k
);
629 DEBUG( "set fmpvevhold=0x%04x", k
);
630 target_write_u32( target
, 0xFFE8A024, k
);
631 DEBUG( "set fmpvevsetup=0x%04x", k
);
634 * FMCVACCESS, based on delay.
637 target_write_u32( target
, 0xFFE8A060, k
);
638 DEBUG( "set fmcvaccess=0x%04x", k
);
641 * FMCSETUP, based on delay.
643 k
= 0x3000 | delay
*20;
644 target_write_u32( target
, 0xFFE8A020, k
);
645 DEBUG( "set fmcsetup=0x%04x", k
);
648 * FMEHOLD, based on delay.
651 target_write_u32( target
, 0xFFE8A038, k
);
652 DEBUG( "set fmehold=0x%04x", k
);
655 * PWIDTH, CWIDTH, EWIDTH, based on delay.
657 target_write_u32( target
, 0xFFE8A050, delay
*8 );
658 DEBUG( "set fmpwidth=0x%04x", delay
*8 );
659 target_write_u32( target
, 0xFFE8A058, delay
*1000 );
660 DEBUG( "set fmcwidth=0x%04x", delay
*1000 );
661 target_write_u32( target
, 0xFFE8A054, delay
*5400 );
662 DEBUG( "set fmewidth=0x%04x", delay
*5400 );
668 /* ---------------------------------------------------------------------- */
671 tms470_flash_status( struct flash_bank_s
* bank
)
673 target_t
*target
= bank
->target
;
674 int result
= ERROR_OK
;
677 target_read_u32( target
, 0xFFE8BC0C, &fmmstat
);
678 DEBUG( "set fmmstat=0x%04x", fmmstat
);
680 if (fmmstat
& 0x0080)
682 WARNING( "tms470 flash command: erase still active after busy clear." );
683 result
= ERROR_FLASH_OPERATION_FAILED
;
686 if (fmmstat
& 0x0040)
688 WARNING( "tms470 flash command: program still active after busy clear." );
689 result
= ERROR_FLASH_OPERATION_FAILED
;
692 if (fmmstat
& 0x0020)
694 WARNING( "tms470 flash command: invalid data command." );
695 result
= ERROR_FLASH_OPERATION_FAILED
;
698 if (fmmstat
& 0x0010)
700 WARNING( "tms470 flash command: program, erase or validate sector failed." );
701 result
= ERROR_FLASH_OPERATION_FAILED
;
704 if (fmmstat
& 0x0008)
706 WARNING( "tms470 flash command: voltage instability detected." );
707 result
= ERROR_FLASH_OPERATION_FAILED
;
710 if (fmmstat
& 0x0006)
712 WARNING( "tms470 flash command: command suspend detected." );
713 result
= ERROR_FLASH_OPERATION_FAILED
;
716 if (fmmstat
& 0x0001)
718 WARNING( "tms470 flash command: sector was locked." );
719 result
= ERROR_FLASH_OPERATION_FAILED
;
725 /* ---------------------------------------------------------------------- */
728 tms470_erase_sector( struct flash_bank_s
* bank
,
731 u32 glbctrl
, orig_fmregopt
, fmbsea
, fmbseb
, fmmstat
;
732 target_t
*target
= bank
->target
;
733 u32 flashAddr
= bank
->base
+ bank
->sectors
[sector
].offset
;
734 int result
= ERROR_OK
;
737 * Set the bit GLBCTRL4 of the GLBCTRL register (in the System
738 * module) to enable writing to the flash registers }.
740 target_read_u32( target
, 0xFFFFFFDC, &glbctrl
);
741 target_write_u32( target
, 0xFFFFFFDC, glbctrl
| 0x10 );
742 DEBUG( "set glbctrl=0x%08x", glbctrl
| 0x10 );
744 /* Force normal read mode. */
745 target_read_u32( target
, 0xFFE89C00, &orig_fmregopt
);
746 target_write_u32( target
, 0xFFE89C00, 0 );
747 DEBUG( "set fmregopt=0x%08x", 0 );
749 (void) tms470_flash_initialize_internal_state_machine( bank
);
752 * Select one or more bits in FMBSEA or FMBSEB to disable Level 1
753 * protection for the particular sector to be erased/written.
757 target_read_u32( target
, 0xFFE88008, &fmbsea
);
758 target_write_u32( target
, 0xFFE88008, fmbsea
| (1<<sector
) );
759 DEBUG( "set fmbsea=0x%04x", fmbsea
| (1<<sector
) );
763 target_read_u32( target
, 0xFFE8800C, &fmbseb
);
764 target_write_u32( target
, 0xFFE8800C, fmbseb
| (1<<(sector
-16)) );
765 DEBUG( "set fmbseb=0x%04x", fmbseb
| (1<<(sector
-16)) );
767 bank
->sectors
[sector
].is_protected
= 0;
770 * clear status regiser, sent erase command, kickoff erase
772 target_write_u16( target
, flashAddr
, 0x0040 );
773 DEBUG( "write *(u16 *)0x%08x=0x0040", flashAddr
);
774 target_write_u16( target
, flashAddr
, 0x0020 );
775 DEBUG( "write *(u16 *)0x%08x=0x0020", flashAddr
);
776 target_write_u16( target
, flashAddr
, 0xffff );
777 DEBUG( "write *(u16 *)0x%08x=0xffff", flashAddr
);
780 * Monitor FMMSTAT, busy until clear, then check and other flags for
781 * ultimate result of the operation.
785 target_read_u32( target
, 0xFFE8BC0C, &fmmstat
);
786 if (fmmstat
& 0x0100)
791 while( fmmstat
& 0x0100 );
793 result
= tms470_flash_status( bank
);
797 target_write_u32( target
, 0xFFE88008, fmbsea
);
798 DEBUG( "set fmbsea=0x%04x", fmbsea
);
799 bank
->sectors
[sector
].is_protected
=
800 fmbsea
& (1<<sector
) ? 0 : 1;
804 target_write_u32( target
, 0xFFE8800C, fmbseb
);
805 DEBUG( "set fmbseb=0x%04x", fmbseb
);
806 bank
->sectors
[sector
].is_protected
=
807 fmbseb
& (1<<(sector
-16)) ? 0 : 1;
809 target_write_u32( target
, 0xFFE89C00, orig_fmregopt
);
810 DEBUG( "set fmregopt=0x%08x", orig_fmregopt
);
811 target_write_u32( target
, 0xFFFFFFDC, glbctrl
);
812 DEBUG( "set glbctrl=0x%08x", glbctrl
);
814 if (result
== ERROR_OK
)
816 bank
->sectors
[sector
].is_erased
= 1;
822 /* ----------------------------------------------------------------------
823 Implementation of Flash Driver Interfaces
824 ---------------------------------------------------------------------- */
827 tms470_register_commands( struct command_context_s
*cmd_ctx
)
829 command_t
*tms470_cmd
= register_command( cmd_ctx
,
834 "applies to TI tms470 family" );
836 register_command( cmd_ctx
,
839 tms470_handle_flash_keyset_command
,
841 "tms470 flash_keyset <key0> <key1> <key2> <key3>" );
843 register_command( cmd_ctx
,
846 tms470_handle_osc_megahertz_command
,
848 "tms470 osc_megahertz <MHz>" );
850 register_command( cmd_ctx
,
853 tms470_handle_plldis_command
,
855 "tms470 plldis <0/1>" );
860 /* ---------------------------------------------------------------------- */
863 tms470_erase( struct flash_bank_s
* bank
,
867 tms470_flash_bank_t
*tms470_info
= bank
->driver_priv
;
868 target_t
*target
= bank
->target
;
869 int sector
, result
= ERROR_OK
;
871 if (!tms470_info
->device_ident_reg
)
873 tms470_read_part_info( bank
);
877 (first
>= bank
->num_sectors
) ||
879 (last
>= bank
->num_sectors
) ||
882 ERROR( "Sector range %d to %d invalid.", first
, last
);
883 return ERROR_FLASH_SECTOR_INVALID
;
886 result
= tms470_unlock_flash( bank
);
887 if (result
!= ERROR_OK
)
892 for( sector
=first
; sector
<=last
; sector
++ )
894 INFO( "Erasing tms470 bank %d sector %d...",
895 tms470_info
->ordinal
, sector
);
897 result
= tms470_erase_sector( bank
, sector
);
899 if (result
!= ERROR_OK
)
901 ERROR( "tms470 could not erase flash sector." );
906 INFO( "sector erased successfully." );
913 /* ---------------------------------------------------------------------- */
916 tms470_protect( struct flash_bank_s
* bank
,
921 tms470_flash_bank_t
*tms470_info
= bank
->driver_priv
;
922 target_t
*target
= bank
->target
;
923 u32 fmmac2
, fmbsea
, fmbseb
;
926 if (!tms470_info
->device_ident_reg
)
928 tms470_read_part_info( bank
);
932 (first
>= bank
->num_sectors
) ||
934 (last
>= bank
->num_sectors
) ||
937 ERROR( "Sector range %d to %d invalid.", first
, last
);
938 return ERROR_FLASH_SECTOR_INVALID
;
941 /* enable the appropriate bank */
942 target_read_u32( target
, 0xFFE8BC04, &fmmac2
);
943 target_write_u32( target
, 0xFFE8BC04,
944 (fmmac2
& ~7) | tms470_info
->ordinal
);
946 /* get the original sector proection flags for this bank */
947 target_read_u32( target
, 0xFFE88008, &fmbsea
);
948 target_read_u32( target
, 0xFFE8800C, &fmbseb
);
950 for( sector
=0; sector
<bank
->num_sectors
; sector
++ )
954 fmbsea
= set
? fmbsea
& ~(1<<sector
) :
955 fmbsea
| (1<<sector
);
956 bank
->sectors
[sector
].is_protected
= set
? 1 : 0;
960 fmbseb
= set
? fmbseb
& ~(1<<(sector
-16)) :
961 fmbseb
| (1<<(sector
-16));
962 bank
->sectors
[sector
].is_protected
= set
? 1 : 0;
966 /* update the protection bits */
967 target_write_u32( target
, 0xFFE88008, fmbsea
);
968 target_write_u32( target
, 0xFFE8800C, fmbseb
);
973 /* ---------------------------------------------------------------------- */
976 tms470_write( struct flash_bank_s
* bank
,
981 target_t
*target
= bank
->target
;
982 tms470_flash_bank_t
*tms470_info
= bank
->driver_priv
;
983 u32 glbctrl
, fmbac2
, orig_fmregopt
, fmbsea
, fmbseb
, fmmaxpp
, fmmstat
;
984 int i
, result
= ERROR_OK
;
986 if (!tms470_info
->device_ident_reg
)
988 tms470_read_part_info( bank
);
991 INFO( "Writing %d bytes starting at 0x%08x",
992 count
, bank
->base
+ offset
);
995 target_read_u32( target
, 0xFFFFFFDC, &glbctrl
);
996 target_write_u32( target
, 0xFFFFFFDC, glbctrl
| 0x10 );
998 (void) tms470_flash_initialize_internal_state_machine( bank
);
1000 /* force max wait states */
1001 target_read_u32( target
, 0xFFE88004, &fmbac2
);
1002 target_write_u32( target
, 0xFFE88004, fmbac2
| 0xff );
1004 /* save current access mode, force normal read mode */
1005 target_read_u32( target
, 0xFFE89C00, &orig_fmregopt
);
1006 target_write_u32( target
, 0xFFE89C00, 0x00 );
1009 * Disable Level 1 protection for all sectors to be erased/written.
1011 target_read_u32( target
, 0xFFE88008, &fmbsea
);
1012 target_write_u32( target
, 0xFFE88008, 0xffff );
1013 target_read_u32( target
, 0xFFE8800C, &fmbseb
);
1014 target_write_u32( target
, 0xFFE8800C, 0xffff );
1017 target_read_u32( target
, 0xFFE8A07C, &fmmaxpp
);
1019 for( i
=0; i
<count
; i
+=2 )
1021 u32 addr
= bank
->base
+ offset
+ i
;
1022 u16 word
= (((u16
) buffer
[i
]) << 8) | (u16
) buffer
[i
+1];
1026 INFO( "writing 0x%04x at 0x%08x", word
, addr
);
1028 /* clear status register */
1029 target_write_u16( target
, addr
, 0x0040 );
1030 /* program flash command */
1031 target_write_u16( target
, addr
, 0x0010 );
1032 /* burn the 16-bit word (big-endian) */
1033 target_write_u16( target
, addr
, word
);
1036 * Monitor FMMSTAT, busy until clear, then check and other flags
1037 * for ultimate result of the operation.
1041 target_read_u32( target
, 0xFFE8BC0C, &fmmstat
);
1042 if (fmmstat
& 0x0100)
1047 while( fmmstat
& 0x0100 );
1049 if (fmmstat
& 0x3ff)
1051 ERROR( "fmstat=0x%04x", fmmstat
);
1052 ERROR( "Could not program word 0x%04x at address 0x%08x.",
1054 result
= ERROR_FLASH_OPERATION_FAILED
;
1060 INFO( "skipping 0xffff at 0x%08x", addr
);
1065 target_write_u32( target
, 0xFFE88008, fmbsea
);
1066 target_write_u32( target
, 0xFFE8800C, fmbseb
);
1067 target_write_u32( target
, 0xFFE88004, fmbac2
);
1068 target_write_u32( target
, 0xFFE89C00, orig_fmregopt
);
1069 target_write_u32( target
, 0xFFFFFFDC, glbctrl
);
1074 /* ---------------------------------------------------------------------- */
1077 tms470_probe( struct flash_bank_s
* bank
)
1079 tms470_flash_bank_t
* tms470_info
= bank
->driver_priv
;
1081 if (!tms470_info
->device_ident_reg
)
1083 tms470_read_part_info( bank
);
1089 /* ---------------------------------------------------------------------- */
1092 tms470_erase_check( struct flash_bank_s
* bank
)
1094 target_t
*target
= bank
->target
;
1095 tms470_flash_bank_t
* tms470_info
= bank
->driver_priv
;
1096 int sector
, result
= ERROR_OK
;
1097 u32 fmmac2
, fmbac2
, glbctrl
, orig_fmregopt
;
1098 static u8 buffer
[64*1024];
1100 if (!tms470_info
->device_ident_reg
)
1102 tms470_read_part_info( bank
);
1106 target_read_u32( target
, 0xFFFFFFDC, &glbctrl
);
1107 target_write_u32( target
, 0xFFFFFFDC, glbctrl
| 0x10 );
1109 /* save current access mode, force normal read mode */
1110 target_read_u32( target
, 0xFFE89C00, &orig_fmregopt
);
1111 target_write_u32( target
, 0xFFE89C00, 0x00 );
1113 /* enable the appropriate bank */
1114 target_read_u32( target
, 0xFFE8BC04, &fmmac2
);
1115 target_write_u32( target
, 0xFFE8BC04,
1116 (fmmac2
& ~7) | tms470_info
->ordinal
);
1119 target_write_u32( target
, 0xFFE8BC10, 0x2fc0 );
1121 /* clear TEZ in fmbrdy */
1122 target_write_u32( target
, 0xFFE88010, 0x0b );
1124 /* save current wait states, force max */
1125 target_read_u32( target
, 0xFFE88004, &fmbac2
);
1126 target_write_u32( target
, 0xFFE88004, fmbac2
| 0xff );
1129 * The TI primitives inspect the flash memory by reading one 32-bit
1130 * word at a time. Here we read an entire sector and inspect it in
1131 * an attempt to reduce the JTAG overhead.
1133 for( sector
=0; sector
<bank
->num_sectors
; sector
++ )
1135 if (bank
->sectors
[sector
].is_erased
!= 1)
1137 u32 i
, addr
= bank
->base
+ bank
->sectors
[sector
].offset
;
1139 INFO( "checking flash bank %d sector %d",
1140 tms470_info
->ordinal
,
1143 target_read_buffer( target
,
1145 bank
->sectors
[sector
].size
,
1148 bank
->sectors
[sector
].is_erased
= 1;
1149 for( i
=0; i
<bank
->sectors
[sector
].size
; i
++ )
1151 if (buffer
[i
] != 0xff)
1153 WARNING( "tms470 bank %d, sector %d, not erased.",
1154 tms470_info
->ordinal
,
1156 WARNING( "at location 0x%08x: flash data is 0x%02x.",
1160 bank
->sectors
[sector
].is_erased
= 0;
1165 if (bank
->sectors
[sector
].is_erased
!= 1)
1167 result
= ERROR_FLASH_SECTOR_NOT_ERASED
;
1172 INFO( "sector erased" );
1176 /* reset TEZ, wait states, read mode, GLBCTRL.4 */
1177 target_write_u32( target
, 0xFFE88010, 0x0f );
1178 target_write_u32( target
, 0xFFE88004, fmbac2
);
1179 target_write_u32( target
, 0xFFE89C00, orig_fmregopt
);
1180 target_write_u32( target
, 0xFFFFFFDC, glbctrl
);
1185 /* ---------------------------------------------------------------------- */
1188 tms470_protect_check( struct flash_bank_s
* bank
)
1190 target_t
*target
= bank
->target
;
1191 tms470_flash_bank_t
* tms470_info
= bank
->driver_priv
;
1192 int sector
, result
= ERROR_OK
;
1193 u32 fmmac2
, fmbsea
, fmbseb
;
1195 if (!tms470_info
->device_ident_reg
)
1197 tms470_read_part_info( bank
);
1200 /* enable the appropriate bank */
1201 target_read_u32( target
, 0xFFE8BC04, &fmmac2
);
1202 target_write_u32( target
, 0xFFE8BC04,
1203 (fmmac2
& ~7) | tms470_info
->ordinal
);
1205 target_read_u32( target
, 0xFFE88008, &fmbsea
);
1206 target_read_u32( target
, 0xFFE8800C, &fmbseb
);
1208 for( sector
=0; sector
<bank
->num_sectors
; sector
++ )
1214 protected = fmbsea
& (1<<sector
) ? 0 : 1;
1215 bank
->sectors
[sector
].is_protected
= protected;
1219 protected = fmbseb
& (1<<(sector
-16)) ? 0 : 1;
1220 bank
->sectors
[sector
].is_protected
= protected;
1223 DEBUG( "bank %d sector %d is %s",
1224 tms470_info
->ordinal
,
1226 protected ? "protected" : "not protected" );
1232 /* ---------------------------------------------------------------------- */
1235 tms470_info( struct flash_bank_s
* bank
,
1240 tms470_flash_bank_t
* tms470_info
= bank
->driver_priv
;
1242 if (!tms470_info
->device_ident_reg
)
1244 tms470_read_part_info( bank
);
1247 if (!tms470_info
->device_ident_reg
)
1249 (void) snprintf(buf
, buf_size
, "Cannot identify target as a TMS470\n");
1250 return ERROR_FLASH_OPERATION_FAILED
;
1253 used
+= snprintf( buf
, buf_size
,
1254 "\ntms470 information: Chip is %s\n",
1255 tms470_info
->part_name
);
1259 used
+= snprintf( buf
, buf_size
,
1260 "Flash protection level 2 is %s\n",
1261 tms470_check_flash_unlocked( bank
->target
) == ERROR_OK
? "disabled" : "enabled" );
1268 /* ---------------------------------------------------------------------- */
1271 * flash bank tms470 <base> <size> <chip_width> <bus_width> <target>
1276 tms470_flash_bank_command( struct command_context_s
*cmd_ctx
,
1280 struct flash_bank_s
*bank
)
1282 bank
->driver_priv
= malloc( sizeof( tms470_flash_bank_t
) );
1284 if (!bank
->driver_priv
)
1286 return ERROR_FLASH_OPERATION_FAILED
;
1289 (void) memset( bank
->driver_priv
, 0, 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)