doc: add stm32lx mass_erase description
[openocd.git] / tcl / tools / firmware-recovery.tcl
blob0f2bc2ab07c56518cc95915f4ab4d91f00deebc2
1 echo "\n\nFirmware recovery helpers"
2 echo "Use -c firmware_help to get help\n"
4 set known_boards {
5 "asus-rt-n16 ASUS RT-N16"
6 "asus-rt-n66u ASUS RT-N66U"
7 "linksys-wrt54gl Linksys WRT54GL v1.1"
8 "netgear-dg834v3 Netgear DG834G v3"
9 "bt-homehubv1 BT HomeHub v1"
12 proc firmware_help { } {
13 echo "
14 Your OpenOCD command should look like this:
15 openocd -f interface/<jtag adapter>.cfg -f tools/firmware-recovery.tcl -c \"<commands>*; shutdown\"
17 Where:
18 <jtag adapter> is one of the supported devices, e.g. ftdi/jtagkey2
19 <commands> are firmware-recovery commands separated by semicolon
21 Supported commands:
22 firmware_help get this help
23 list_boards list known boards and exit
24 board <name> select board you work with
25 list_partitions list partitions of the currently selected board
26 dump_part <name> <filename> save partition's contents to a file
27 erase_part <name> erase the given partition
28 flash_part <name> <filename> erase, flash and verify the given partition
29 ram_boot <filename> load binary file to RAM and run it
30 adapter_khz <freq> set JTAG clock frequency in kHz
32 For example, to clear nvram and reflash CFE on an RT-N16 using TUMPA, run:
33 openocd -f interface/ftdi/tumpa.cfg -f tools/firmware-recovery.tcl \\
34 -c \"board asus-rt-n16; erase_part nvram; flash_part CFE cfe-n16.bin; shutdown\"
35 \n\n"
36 shutdown
39 # set default, can be overriden later
40 adapter_khz 1000
42 proc get_partition { name } {
43 global partition_list
44 dict get $partition_list $name
47 proc partition_desc { name } { lindex [get_partition $name] 0 }
48 proc partition_start { name } { lindex [get_partition $name] 1 }
49 proc partition_size { name } { lindex [get_partition $name] 2 }
51 proc list_boards { } {
52 global known_boards
53 echo "List of the supported boards:\n"
54 echo "Board name\t\tDescription"
55 echo "-----------------------------------"
56 foreach i $known_boards {
57 echo $i
59 echo "\n\n"
62 proc board { name } {
63 script [find board/$name.cfg]
66 proc list_partitions { } {
67 global partition_list
68 set fstr "%-16s%-14s%-14s%s"
69 echo "\nThe currently selected board is known to have these partitions:\n"
70 echo [format $fstr Name Start Size Description]
71 echo "-------------------------------------------------------"
72 for {set i 0} {$i < [llength $partition_list]} {incr i 2} {
73 set key [lindex $partition_list $i]
74 echo [format $fstr $key [partition_start $key] [partition_size $key] [partition_desc $key]]
76 echo "\n\n"
79 # Magic to work with any targets, including semi-functional
80 proc prepare_target { } {
81 init
82 catch {halt}
83 catch {reset init}
84 catch {halt}
87 proc dump_part { name filename } {
88 prepare_target
89 dump_image $filename [partition_start $name] [partition_size $name]
92 proc erase_part { name } {
93 prepare_target
94 flash erase_address [partition_start $name] [partition_size $name]
97 proc flash_part { name filename } {
98 prepare_target
99 flash write_image erase $filename [partition_start $name] bin
100 echo "Verifying:"
101 verify_image $filename [partition_start $name]
104 proc ram_boot { filename } {
105 global ram_boot_address
106 prepare_target
107 load_image $filename $ram_boot_address bin
108 resume $ram_boot_address
111 echo ""