Skip to content

Instantly share code, notes, and snippets.

@madmo
Created December 13, 2014 00:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madmo/8a599ca6385947f11e21 to your computer and use it in GitHub Desktop.
Save madmo/8a599ca6385947f11e21 to your computer and use it in GitHub Desktop.
convert pic32 hex file from virtual to physical addresses
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