-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathflash.rb
More file actions
64 lines (52 loc) · 1.3 KB
/
flash.rb
File metadata and controls
64 lines (52 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
$: << File.realpath('..', __FILE__)
require 'device'
require 'backend-driver'
require 'optparse'
require 'ostruct'
options = {}
OptionParser.new do |opts|
opts.banner = 'Usage: flash [options] file1 offset1 [file2 offset2 ...]'
options[:backend] = BackendDriver.options(opts)
opts.on('--mass-erase', 'Mass erase') do |v|
options[:mass_erase] = v
end
end.parse!
def readbins
ret = []
pos = 0
while ARGV.count > pos
fw = OpenStruct.new({
name: ARGV[pos],
data: File.read(ARGV[pos], :mode => 'rb'),
address: Integer(ARGV[pos + 1]),
})
pos += 2
ret << fw
end
ret
end
bins = readbins
$stderr.puts "Attaching debugger..."
k = Device.detect(BackendDriver.from_opts(options[:backend]))
$stderr.puts "done."
#k.program do
k.halt_core!
begin
if options[:mass_erase]
$stderr.puts "Mass erasing chip..."
k.mass_erase
$stderr.puts "done."
end
bins.each do |fw|
$stderr.puts "Programming %s, %d bytes to address %#x..." % [fw.name, fw.data.bytesize, fw.address]
k.program_section(fw.address, fw.data) do |address, i, total|
$stderr.puts "programming %#x, %d of %d" % [address, i, total]
end
$stderr.puts "done with %s." % fw.name
end
$stderr.puts "finishing..."
end
k.reset_system!
k.disable_debug!
k.continue!
$stderr.puts "done."