Created
December 13, 2014 00:44
-
-
Save madmo/8a599ca6385947f11e21 to your computer and use it in GitHub Desktop.
convert pic32 hex file from virtual to physical addresses
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lines = File.readlines(ARGV[0]) | |
lines.map! do |line| | |
line = line.chomp | |
if line.length > 8 and line[7..8] == "04" then | |
addr = line[9..12].to_i(16) | |
addr &= 0x1fff | |
line[9..12] = addr.to_s(16).upcase.rjust(4, "0") | |
line[13..14] = (((~line[1..-3].scan(/../).inject(0) {|sum, s| sum + s.to_i(16) }) & 0xFF) + 1).to_s(16).upcase | |
end | |
line | |
end | |
File.write(ARGV[0], lines.join("\n")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment