aboutsummaryrefslogtreecommitdiff
path: root/flashstub/code-to-array.pl
diff options
context:
space:
mode:
Diffstat (limited to 'flashstub/code-to-array.pl')
-rwxr-xr-xflashstub/code-to-array.pl24
1 files changed, 24 insertions, 0 deletions
diff --git a/flashstub/code-to-array.pl b/flashstub/code-to-array.pl
new file mode 100755
index 0000000..5333e31
--- /dev/null
+++ b/flashstub/code-to-array.pl
@@ -0,0 +1,24 @@
+#!/usr/bin/perl
+#
+# Convert the output of objdump to an array of bytes are can include
+# into our program.
+
+while (<>) {
+ if (m/^\s*([0-9a-fA-F]+):\s*([0-9a-fA-F]+)(.*)/) {
+ my $addr = "0x$1";
+ my $value = $2;
+ if (length ($value) == 4) {
+ print " [$addr/2] = 0x$value, // $_";
+ }
+ else {
+ my $lsb = substr ($value, 4, 4);
+ my $msb = substr ($value, 0, 4);
+ print " [$addr/2] = 0x$lsb, // $_";
+ print " [$addr/2 + 1] = 0x$msb,\n";
+ }
+ }
+ else {
+ print "// ", $_;
+ }
+}
+