Skip to content

Instantly share code, notes, and snippets.

@neuschaefer
Last active March 11, 2017 01:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save neuschaefer/2e5505a48dbfa67d2548049b22bfe2e6 to your computer and use it in GitHub Desktop.
Save neuschaefer/2e5505a48dbfa67d2548049b22bfe2e6 to your computer and use it in GitHub Desktop.
#!/bin/sh
PART=input.part
BLUE='\033[1;34m'
WHITE='\033[1;37m'
NC='\033[0m'
hd "$PART" | grep -E '^[0-9a-f]{8} d0 0d fe ed' --line-buffered | \
while read LINE; do
echo "$WHITE$LINE$NC"
OFFSET=`echo "$LINE" | cut -d' ' -f1`
LENGTH=`echo "$LINE" | cut -d' ' -f7-10 | sed -e 's/ //g'`
DTB="$OFFSET.dtb"
DTS="$OFFSET.dts"
echo "${BLUE}extracting $DTB$NC"
OxOFFSET="0x$OFFSET"
OxLENGTH="0x$LENGTH"
dd if="$PART" of="$DTB" bs=1 skip=$((OxOFFSET)) count=$((OxLENGTH))
echo -n "${BLUE}decompiling$NC"
dtc "$DTB" -I dtb -o "$DTS" -O dts > /dev/null 2>&1
echo " done"
echo
done
#!/bin/sh
PART=input.part
OUTPUT=output.part
cp "$PART" "$OUTPUT"
export PART="$OUTPUT"
BLUE='\033[1;34m'
WHITE='\033[1;37m'
NC='\033[0m'
hd "$PART" | grep -E '^[0-9a-f]{8} d0 0d fe ed' --line-buffered | \
while read LINE; do
echo "$WHITE$LINE$NC"
OFFSET=`echo "$LINE" | cut -d' ' -f1`
LENGTH=`echo "$LINE" | cut -d' ' -f7-10 | sed -e 's/ //g'`
DTB="$OFFSET.dtb"
DTS="$OFFSET.dts"
echo -n "${BLUE}compiling$NC"
dtc "$DTS" -I dts -o "$DTB" -O dtb > /dev/null 2>&1
echo " done"
echo "${BLUE}injecting $DTB$NC"
OxOFFSET="0x$OFFSET"
dd conv=notrunc if="$DTB" of="$PART" bs=1 seek=$((OxOFFSET))
echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment