]>
git.zerfleddert.de Git - fnordlicht-mini/blob - firmware/tests/flash_file.rb
3 $
:.unshift(File
.dirname(__FILE__
)+"/lib")
10 $dev = SerialPort
.new("/dev/ttyUSB0", 19200)
12 def crc16_update(crc
, data)
13 return nil if crc
< 0 || crc
> 0xffff
14 return nil if data < 0 || data > 255
19 crc
= (crc
>> 1) ^
0xA001
29 def compute_checksum(data)
33 checksum
= crc16_update(checksum
, b
)
40 $stderr.puts
"usage: %s ADDRESS FILE" % $0
44 address
= ARGV.shift
.to_i
47 puts
"sending sync sequence"
51 open(file
, 'r') do |f
|
52 puts
"configure bootloader"
53 boot_config(address
, 0)
57 puts
"writing chunk (%s bytes)" % d
.length
60 d
.split('').each_slice(13) do |s
|
61 boot_data(address
, s
.join(''))
64 checksum
= compute_checksum(d
)
65 boot_crc_check(address
, d
.length
, checksum
, 5);
71 break if d
.length
< 512
76 open(file
, 'r') do |f
|
81 checksum
= compute_checksum(data)
82 puts
"verifying checksum (%u bytes): 0x%04x" % [data.length
, checksum
]
83 boot_crc_flash(address
, 0, data.length
, checksum
, 50)