#!/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( '/cygdrive/c/78k_data/yav-mcu-basara/bsr.hex' ) 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 ### 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" )