ctr_mcu/snake_trunk/nec_s_2_bsrbin2.rb

83 lines
1.8 KiB
Ruby
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/ruby
$KCODE = "S"
=begin
 NECの環境が吐きだしたSRECを、
  ●未指定部分には0xFFパディングし、
  ●BSRのアップデート用に必要な部分だけ切り出します。
            0x0000 - 0x0FFF, 0x2000-0x47FF
=end
=begin
if( ARGV[0] == nil )
print( "input file name is nessesary!\nabort.\n" )
exit(1)
end
unless(File.exist?( ARGV[0] ))
print( "file" << ARGV[0] << " not found.\nabort.\n" )
exit(1)
end
=end
src = File.open( 'bsr.hex' )
dest = File.new( "hoge.bin","wb" )
dest.write( 'jhl' )
### get data ##########################
src_in = Hash.new
tempA = Array.new
dataTemp = Array.new
offset = Numeric.new
bindata = Array.new( 32*1024, 0xFF )
while(src.readline)
tempA = $_.scan(/(\:)(\w\w)(\w\w\w\w)(\w\w)(\w+)(\w\w)/)
break if( tempA.size == 0 )
src_in = { "len" => tempA[0][1], "offset" => tempA[0][2], "type" => tempA[0][3], "data" => tempA[0][4], "CRC" => tempA[0][5] }
break if src_in["type"].hex == 01
break if src_in["len"].hex == 00
# next if src_in["type"].hex != 00
if( src_in["type"].hex != 00 )
# p dat
next
end
offset = src_in["offset"].hex
next if(( 0x1000 <= offset ) && ( offset < 0x2000 ))
dataTemp = src_in["data"].scan(/\w\w/)
( 0...(src_in["len"].to_s.hex) ).each{|i|
bindata[ offset + i ] = ( dataTemp[ i ] ).to_s.hex
}
end
### debug enable bit check #############
# デバッグ許可になっているとISデバッガで起動しないMCUが動作しない
p bindata[0xC3]
if( bindata[0xC3] != 0x04 )
print( "!E debug enable!!" )
exit( 1 )
end
### format data and output #############
4096.times{
bindata.delete_at(4096)
}
dest.write( bindata[0..(0x4FFF - 0x1000)].pack("c*") )
dest.close
printf( "intel-HEX to bsr bin converter\n file converted!\n\n" )