mirror of
https://github.com/jclehner/bcm2-utils.git
synced 2025-01-18 10:41:54 +00:00
37 lines
624 B
Ruby
Executable File
37 lines
624 B
Ruby
Executable File
#!/usr/bin/ruby
|
|
|
|
require 'tempfile'
|
|
|
|
def file_to_c(file, func)
|
|
data = File.read(file, mode: "rb")
|
|
raise "#{file.path} is empty" if data.size == 0
|
|
|
|
printf("uint32_t %s_code[] = {", func)
|
|
|
|
i = 0
|
|
while i < data.size
|
|
printf("\n\t") if (i % 16) == 0
|
|
printf("0x%08x, ", data[i, 4].unpack("L>")[0])
|
|
i += 4
|
|
end
|
|
|
|
printf("\n};\n")
|
|
end
|
|
|
|
puts "/*"
|
|
puts " * AUTO-GENERATED BY #{__FILE__} - DO NOT EDIT!"
|
|
puts " */"
|
|
|
|
|
|
# FIXME
|
|
arch = "mips"
|
|
tmp = "tmp.bin"
|
|
|
|
[ "read", "write" ].each do |func|
|
|
func = "#{arch}_#{func}"
|
|
system("#{ARGV[0]}objcopy -j .text.#{func} -O binary #{ARGV[1]} #{tmp}")
|
|
puts
|
|
file_to_c(tmp, func)
|
|
end
|
|
|