gdbflasher 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8c61751a3541bf40a9abdd0d999dc16aa3d27ae4
4
+ data.tar.gz: 5036ff6f4f7801d322f10d9887995c9b89ae7d36
5
+ SHA512:
6
+ metadata.gz: b8583513a0bc51c34277742bd786106e1b33c26aba4b80bba0a2c2e4c4161ffb27613184ccdb81112565db273fda69b6516a3e2d46914259b2ea8558ed370761
7
+ data.tar.gz: e2c9f0b1434b6c4ce6cc6c587b97d1373da97e4cc76fa15412d483be363a40266ec85d03721c46191ca261071ee6803c017e1d180225eb2cc2b812b7047aa0d7
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Sergey Gridasov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Gdbflasher
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'gdbflasher'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install gdbflasher
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/bin/gdbflasher ADDED
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rubygems"
4
+ require "bundler/setup"
5
+ require "trollop"
6
+ require "gdbflasher"
7
+
8
+ options = Trollop::options do
9
+ version "gdbflasher #{GdbFlasher::VERSION} (c) 2012 Sergey Gridasov"
10
+ banner <<-EOB
11
+ gdbflasher is a gdbserver-compatible tool for loading firmware into ARM MCUs.
12
+
13
+ Usage: gdbserver [options] <IHEX firmware>
14
+ where [options] are:
15
+ EOB
16
+
17
+ opt :server, "GDB server address", :type => :string, :default => "127.0.0.1:2331"
18
+ opt :mcu, "MCU name. Try '--mcu=list' to get list of supported controllers.", :required => true, :type => :string
19
+ opt :start, "Start application after programming"
20
+ end
21
+
22
+ if options[:mcu] == "list"
23
+ GdbFlasher::MCU_CLASSES.each do |sym, klass|
24
+ puts sym.to_s
25
+ end
26
+
27
+ exit 0
28
+ elsif GdbFlasher::MCU_CLASSES[options[:mcu].intern].nil?
29
+ warn "MCU #{options[:mcu]} isn't supported."
30
+
31
+ exit 0
32
+ elsif ARGV.count == 0
33
+ warn "Firmware file must be specified"
34
+
35
+ exit 1
36
+ elsif ARGV.count > 1
37
+ warn "Only one firmware file must be specified"
38
+
39
+ exit 1
40
+ end
41
+
42
+ begin
43
+ firmware = File.open ARGV[0], "r"
44
+ rescue Exception => e
45
+ warn e
46
+
47
+ exit 1
48
+ end
49
+
50
+ ihex = GdbFlasher::IHex.load firmware
51
+ firmware.close
52
+
53
+ puts "Loaded #{ARGV[0]}:"
54
+ ihex.segments.each do |segment|
55
+ printf " -> %08X - %08X\n", segment.base, segment.base + segment.size - 1
56
+ end
57
+
58
+ connection = GdbFlasher::ServerConnection.new
59
+ connection.connect options[:server]
60
+
61
+ mcu = GdbFlasher::MCU_CLASSES[options[:mcu].intern].new connection
62
+
63
+ success = mcu.program_ihex ihex
64
+
65
+ mcu.finalize
66
+
67
+ if options[:start] && success
68
+ puts "Starting target application"
69
+ connection.reset
70
+ end
71
+
72
+ connection.close
73
+
74
+ if !success
75
+ exit 1
76
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/gdbflasher/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Sergey Gridasov"]
6
+ gem.email = ["grindars@gmail.com"]
7
+ gem.description = %q{gdbflasher is a gdbserver-compatible tool for loading firmware into ARM MCUs.}
8
+ gem.summary = %q{Retargetable flasher for ARM microcontrollers}
9
+ gem.homepage = "https://github.com/grindars/gdbflasher"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "gdbflasher"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = GdbFlasher::VERSION
17
+
18
+ gem.add_dependency 'trollop'
19
+ end
@@ -0,0 +1,22 @@
1
+ MCUS = stm32f4xx stm32l1xx stm32f10xx_hd stm32f10xx_md
2
+
3
+ HELPERS = $(addprefix ../helpers/,$(addsuffix .hex,${MCUS}) $(addsuffix .sym,${MCUS}))
4
+ ELVES = $(addsuffix .elf,${MCUS})
5
+ OBJECTS = $(addsuffix .o,${MCUS})
6
+
7
+ all: ${HELPERS}
8
+
9
+ clean:
10
+ rm -f ${HELPERS} ${ELVES} ${OBJECTS}
11
+
12
+ ../helpers/%.sym: %.elf
13
+ ${CROSS_COMPILE}nm -n $< | awk '$$2 == "T" || $$2 == "B" || $$2 == "A" { print $$1 " " $$3 }' > $@
14
+
15
+ ../helpers/%.hex: %.elf
16
+ ${CROSS_COMPILE}objcopy -O ihex $< $@
17
+
18
+ %.elf: %.lds %.o
19
+ ${CROSS_COMPILE}ld -o $@ -T$^
20
+
21
+ %.o: %.S
22
+ ${CROSS_COMPILE}as -o $@ $<
@@ -0,0 +1,115 @@
1
+ .set PAGE_SIZE, 2048
2
+
3
+ .set FPEC, 0x40022000
4
+
5
+ .set FLASH_ACR, 0
6
+ .set FLASH_KEYR, 4
7
+ .set FLASH_OPTKEYR, 8
8
+ .set FLASH_SR, 12
9
+ .set FLASH_CR, 16
10
+ .set FLASH_AR, 20
11
+
12
+ .set FLASH_SR_EOP, 1 << 5
13
+ .set FLASH_SR_WRPRTERR, 1 << 4
14
+ .set FLASH_SR_PGERR, 1 << 2
15
+ .set FLASH_SR_BSY, 1 << 0
16
+
17
+ .set FLASH_CR_EOPIE, 1 << 12
18
+ .set FLASH_CR_ERRIE, 1 << 10
19
+ .set FLASH_CR_OPTWRE, 1 << 9
20
+ .set FLASH_CR_LOCK, 1 << 7
21
+ .set FLASH_CR_STRT, 1 << 6
22
+ .set FLASH_CR_OPTER, 1 << 5
23
+ .set FLASH_CR_OPTPG, 1 << 4
24
+ .set FLASH_CR_MER, 1 << 2
25
+ .set FLASH_CR_PER, 1 << 1
26
+ .set FLASH_CR_PG, 1 << 0
27
+
28
+ .globl trap
29
+ .globl initialize
30
+ .globl finalize
31
+ .globl erase
32
+ .globl program
33
+ .globl page_buffer
34
+ .globl PAGE_SIZE
35
+
36
+ .arch armv7-m
37
+ .syntax unified
38
+ .thumb
39
+ .text
40
+
41
+ trap:
42
+ nop
43
+
44
+ initialize:
45
+ ldr R7, =FPEC
46
+
47
+ ldr R0, =0x45670123
48
+ str R0, [R7, #FLASH_KEYR]
49
+ ldr R0, =0xCDEF89AB
50
+ str R0, [R7, #FLASH_KEYR]
51
+
52
+ bx LR
53
+
54
+ finalize:
55
+ mov R1, #FLASH_CR_LOCK
56
+ str R1, [R7, #FLASH_CR]
57
+
58
+ bx LR
59
+
60
+ erase:
61
+ ldr R1, [R7, #FLASH_CR]
62
+ orr R1, #FLASH_CR_PER
63
+ str R1, [R7, #FLASH_CR]
64
+ str R0, [R7, #FLASH_AR]
65
+ orr R1, #FLASH_CR_STRT
66
+ str R1, [R7, #FLASH_CR]
67
+
68
+ 1: ldr R2, [R7, #FLASH_SR]
69
+ tst R2, #FLASH_SR_BSY
70
+ bne 1b
71
+
72
+ bic R1, #FLASH_CR_PER | FLASH_CR_STRT
73
+ str R1, [R7, #FLASH_CR]
74
+
75
+ and R0, R2, #FLASH_SR_WRPRTERR | FLASH_SR_PGERR
76
+ str R2, [R7, #FLASH_SR]
77
+
78
+ bx LR
79
+
80
+ program:
81
+ ldr R1, [R7, #FLASH_CR]
82
+ orr R1, #FLASH_CR_PG
83
+ str R1, [R7, #FLASH_CR]
84
+
85
+ ldr R4, =page_buffer
86
+ mov R2, #0
87
+
88
+ 1:
89
+ ldrh R3, [R4, R2]
90
+ strh R3, [R0, R2]
91
+
92
+ 2: ldr R1, [R7, #FLASH_SR]
93
+ tst R1, #FLASH_SR_BSY
94
+ bne 2b
95
+
96
+ str R1, [R7, #FLASH_SR]
97
+ ands R1, R1, #FLASH_SR_WRPRTERR | FLASH_SR_PGERR
98
+ bne 1f
99
+
100
+ add R2, #2
101
+ cmp R2, #PAGE_SIZE
102
+ blo 1b
103
+ 1:
104
+
105
+ ldr R2, [R7, #FLASH_CR]
106
+ bic R2, #FLASH_CR_PG
107
+ str R2, [R7, #FLASH_CR]
108
+
109
+ mov R0, R1
110
+ bx LR
111
+
112
+ .bss
113
+ page_buffer:
114
+ .fill PAGE_SIZE, 1
115
+ .size page_buffer, . - page_buffer
@@ -0,0 +1,25 @@
1
+ OUTPUT_FORMAT(elf32-littlearm)
2
+
3
+ MEMORY
4
+ {
5
+ sram : ORIGIN = 0x20000000, LENGTH = 4K
6
+ }
7
+
8
+ SECTIONS
9
+ {
10
+ .text : {
11
+ *(.text)
12
+
13
+ . = ALIGN(4);
14
+
15
+ *(.rodata)
16
+ } > sram
17
+
18
+ . = ALIGN(4);
19
+
20
+ .bss : {
21
+ *(.bss)
22
+ } > sram
23
+
24
+ . = ALIGN(4);
25
+ }
@@ -0,0 +1,115 @@
1
+ .set PAGE_SIZE, 1024
2
+
3
+ .set FPEC, 0x40022000
4
+
5
+ .set FLASH_ACR, 0
6
+ .set FLASH_KEYR, 4
7
+ .set FLASH_OPTKEYR, 8
8
+ .set FLASH_SR, 12
9
+ .set FLASH_CR, 16
10
+ .set FLASH_AR, 20
11
+
12
+ .set FLASH_SR_EOP, 1 << 5
13
+ .set FLASH_SR_WRPRTERR, 1 << 4
14
+ .set FLASH_SR_PGERR, 1 << 2
15
+ .set FLASH_SR_BSY, 1 << 0
16
+
17
+ .set FLASH_CR_EOPIE, 1 << 12
18
+ .set FLASH_CR_ERRIE, 1 << 10
19
+ .set FLASH_CR_OPTWRE, 1 << 9
20
+ .set FLASH_CR_LOCK, 1 << 7
21
+ .set FLASH_CR_STRT, 1 << 6
22
+ .set FLASH_CR_OPTER, 1 << 5
23
+ .set FLASH_CR_OPTPG, 1 << 4
24
+ .set FLASH_CR_MER, 1 << 2
25
+ .set FLASH_CR_PER, 1 << 1
26
+ .set FLASH_CR_PG, 1 << 0
27
+
28
+ .globl trap
29
+ .globl initialize
30
+ .globl finalize
31
+ .globl erase
32
+ .globl program
33
+ .globl page_buffer
34
+ .globl PAGE_SIZE
35
+
36
+ .arch armv7-m
37
+ .syntax unified
38
+ .thumb
39
+ .text
40
+
41
+ trap:
42
+ nop
43
+
44
+ initialize:
45
+ ldr R7, =FPEC
46
+
47
+ ldr R0, =0x45670123
48
+ str R0, [R7, #FLASH_KEYR]
49
+ ldr R0, =0xCDEF89AB
50
+ str R0, [R7, #FLASH_KEYR]
51
+
52
+ bx LR
53
+
54
+ finalize:
55
+ mov R1, #FLASH_CR_LOCK
56
+ str R1, [R7, #FLASH_CR]
57
+
58
+ bx LR
59
+
60
+ erase:
61
+ ldr R1, [R7, #FLASH_CR]
62
+ orr R1, #FLASH_CR_PER
63
+ str R1, [R7, #FLASH_CR]
64
+ str R0, [R7, #FLASH_AR]
65
+ orr R1, #FLASH_CR_STRT
66
+ str R1, [R7, #FLASH_CR]
67
+
68
+ 1: ldr R2, [R7, #FLASH_SR]
69
+ tst R2, #FLASH_SR_BSY
70
+ bne 1b
71
+
72
+ bic R1, #FLASH_CR_PER | FLASH_CR_STRT
73
+ str R1, [R7, #FLASH_CR]
74
+
75
+ and R0, R2, #FLASH_SR_WRPRTERR | FLASH_SR_PGERR
76
+ str R2, [R7, #FLASH_SR]
77
+
78
+ bx LR
79
+
80
+ program:
81
+ ldr R1, [R7, #FLASH_CR]
82
+ orr R1, #FLASH_CR_PG
83
+ str R1, [R7, #FLASH_CR]
84
+
85
+ ldr R4, =page_buffer
86
+ mov R2, #0
87
+
88
+ 1:
89
+ ldrh R3, [R4, R2]
90
+ strh R3, [R0, R2]
91
+
92
+ 2: ldr R1, [R7, #FLASH_SR]
93
+ tst R1, #FLASH_SR_BSY
94
+ bne 2b
95
+
96
+ str R1, [R7, #FLASH_SR]
97
+ ands R1, R1, #FLASH_SR_WRPRTERR | FLASH_SR_PGERR
98
+ bne 1f
99
+
100
+ add R2, #2
101
+ cmp R2, #PAGE_SIZE
102
+ blo 1b
103
+ 1:
104
+
105
+ ldr R2, [R7, #FLASH_CR]
106
+ bic R2, #FLASH_CR_PG
107
+ str R2, [R7, #FLASH_CR]
108
+
109
+ mov R0, R1
110
+ bx LR
111
+
112
+ .bss
113
+ page_buffer:
114
+ .fill PAGE_SIZE, 1
115
+ .size page_buffer, . - page_buffer
@@ -0,0 +1,25 @@
1
+ OUTPUT_FORMAT(elf32-littlearm)
2
+
3
+ MEMORY
4
+ {
5
+ sram : ORIGIN = 0x20000000, LENGTH = 4K
6
+ }
7
+
8
+ SECTIONS
9
+ {
10
+ .text : {
11
+ *(.text)
12
+
13
+ . = ALIGN(4);
14
+
15
+ *(.rodata)
16
+ } > sram
17
+
18
+ . = ALIGN(4);
19
+
20
+ .bss : {
21
+ *(.bss)
22
+ } > sram
23
+
24
+ . = ALIGN(4);
25
+ }
@@ -0,0 +1,109 @@
1
+ .set PAGE_SIZE, 16 * 1024
2
+
3
+ .set FLASH_BASE, 0x40023C00
4
+
5
+ .set FLASH_ACR, 0x00
6
+ .set FLASH_KEYR, 0x04
7
+ .set FLASH_OPTKEYR, 0x08
8
+ .set FLASH_SR, 0x0C
9
+ .set FLASH_CR, 0x10
10
+ .set FLASH_OPTCR, 0x14
11
+
12
+ .globl trap
13
+ .globl initialize
14
+ .globl finalize
15
+ .globl erase
16
+ .globl program
17
+ .globl page_buffer
18
+ .globl PAGE_SIZE
19
+
20
+ .arch armv7-m
21
+ .syntax unified
22
+ .thumb
23
+ .text
24
+
25
+ trap:
26
+ nop
27
+
28
+ initialize:
29
+ ldr R7, =FLASH_BASE
30
+
31
+ ldr R0, =0x45670123
32
+ str R0, [R7, #FLASH_KEYR]
33
+ ldr R0, =0xCDEF89AB
34
+ str R0, [R7, #FLASH_KEYR]
35
+
36
+ bx LR
37
+
38
+ finalize:
39
+ mov R0, #1 << 31
40
+
41
+ str R0, [R7, #FLASH_CR]
42
+ bx LR
43
+
44
+ erase:
45
+ ldr R1, [R7, #FLASH_SR]
46
+ tst R1, #1 << 16
47
+ bne erase
48
+
49
+ mov R1, #0xF0
50
+ str R1, [R7, #FLASH_SR]
51
+
52
+ ldr R2, =0x202
53
+ lsl R1, R0, #3
54
+ orr R1, R2
55
+ str R1, [R7, #FLASH_CR]
56
+ orr R1, #1 << 16
57
+ str R1, [R7, #FLASH_CR]
58
+
59
+ 1:ldr R0, [R7, #FLASH_SR]
60
+ tst R0, #1 << 16
61
+ bne 1b
62
+
63
+ and R0, #0xF0
64
+
65
+ mov R1, #0
66
+ str R1, [R7, #FLASH_CR]
67
+
68
+ bx LR
69
+
70
+ program:
71
+ ldr R1, [R7, #FLASH_SR]
72
+ tst R1, #1 << 16
73
+ bne program
74
+
75
+ ldr R1, =0x201
76
+ str R1, [R7, #FLASH_CR]
77
+
78
+ mov R1, #0xF0
79
+ str R1, [R7, #FLASH_SR]
80
+
81
+ ldr R4, =page_buffer
82
+ mov R2, #0
83
+
84
+ 1:
85
+ ldr R3, [R4, R2]
86
+ str R3, [R0, R2]
87
+
88
+ 2:ldr R1, [R7, #FLASH_SR]
89
+ tst R1, #1 << 16
90
+ bne 2b
91
+
92
+ ands R1, #0xF0
93
+ bne 1f
94
+
95
+ add R2, #4
96
+ cmp R2, #PAGE_SIZE
97
+ blo 1b
98
+
99
+ 1:
100
+ mov R0, R1
101
+ mov R1, #0
102
+ str R1, [R7, #FLASH_CR]
103
+
104
+ bx LR
105
+
106
+ .bss
107
+ page_buffer:
108
+ .fill PAGE_SIZE, 1
109
+ .size page_buffer, . - page_buffer
@@ -0,0 +1,25 @@
1
+ OUTPUT_FORMAT(elf32-littlearm)
2
+
3
+ MEMORY
4
+ {
5
+ sram : ORIGIN = 0x20000000, LENGTH = 192K
6
+ }
7
+
8
+ SECTIONS
9
+ {
10
+ .text : {
11
+ *(.text)
12
+
13
+ . = ALIGN(4);
14
+
15
+ *(.rodata)
16
+ } > sram
17
+
18
+ . = ALIGN(4);
19
+
20
+ .bss : {
21
+ *(.bss)
22
+ } > sram
23
+
24
+ . = ALIGN(4);
25
+ }