kylemanna
11/18/2011 - 4:16 PM

Reverse endianess on a binary file

Reverse endianess on a binary file

#!/bin/sh
# Following command will reorder 32 bit words from little endian to big endian
#
# This is needed on TI81xx platforms to convert a standard LE bootloader/SPL/MLO 
# to a byte ordering the works via SPI flash

arm-none-linux-gnueabi-objcopy -Ibinary --reverse-bytes=4 MLO MLO.spi

# Output:
# $ hexdump -C MLO | head -n2
# 00000000  40 00 00 00 0c 00 00 00  00 00 00 00 00 00 00 00  |@...............|
# 00000010  00 00 00 00 43 48 53 45  54 54 49 4e 47 53 00 00  |....CHSETTINGS..|
# $ hexdump -C MLO.spi | head -n2
# 00000000  00 00 00 40 00 00 00 0c  00 00 00 00 00 00 00 00  |...@............|
# 00000010  00 00 00 00 45 53 48 43  4e 49 54 54 00 00 53 47  |....ESHCNITT..SG|