blob: 36166dd99d8ffd361ecd0f315a93aefd66a935d6 [file] [log] [blame]
#!/bin/sh
set -e
peek4()
{
FILE="$1"
OFFSET="$2"
COUNT="$3"
if [ -z "$OFFSET" ]; then
OFFSET=0
fi
if [ -z "$COUNT" ]; then
COUNT=1
fi
dd if="$FILE" bs=4 count=$COUNT skip=$(($OFFSET / 4)) status=none | hexdump -v -e '/4 "%08X\n"'
}
while [ -n "$1" ]; do
BIN="$1"
shift
MAGIC="$(peek4 "$BIN")"
if [ "$MAGIC" != "43504450" ]; then # CPDP
echo "$BIN is not a CP ramdump file!"
continue
fi
NR_FILES="$(peek4 "$BIN" 4)"
NR_FILES=$((0x$NR_FILES))
if [ $NR_FILES -eq 0 ]; then
echo "$BIN contains no dump files"
continue
else
echo "$BIN contains $NR_FILES dump files"
fi
OUTDIR="${BIN%.bin}-unpacked"
mkdir -p "$OUTDIR"
N=0
for I in `seq 0 $(($NR_FILES - 1))`; do
OFS=$(($I * 136 + 8))
FNAME="$(printf '%s' "$(dd if="$BIN" bs=1 count=128 skip=$OFS status=none)")"
OFS=$(($OFS + 128))
FILEOFS=$((0x`peek4 "$BIN" $OFS`))
OFS=$(($OFS + 4))
FILELEN=$((0x`peek4 "$BIN" $OFS`))
echo "$I. $FNAME|$FILEOFS|$FILELEN"
if [ $FILELEN -ne 0 ]; then
tail -c +$(($FILEOFS + 1)) "$BIN" | head -c $FILELEN > "$OUTDIR/$FNAME"
N=$(($N + 1))
fi
done
echo "$N dump files unpacked under $OUTDIR"
BASE="$(basename "$BIN")"
SFX="$(echo "$BASE" | sed 's/^COM_DDR_//')"
if [ -n "$SFX" -a "$SFX" != "$BASE" ]; then
DIR="$(dirname "$BIN")"
if [ -e "$OUTDIR/com_DSP_DDR.bin" -o -e "$OUTDIR/com_dsp_ddr.bin" ]; then
rm -fv "$DIR"/*"DSP_DDR_$SFX" "$DIR"/*"dsp_ddr_$SFX"
else
mv -v "$DIR"/*"DSP_DDR_$SFX" "$DIR"/*"dsp_ddr_$SFX" "$OUTDIR" || true
fi
for C in "$DIR"/com_dspdump_*; do
[ -e "$C" ] && mv -v "$C" "$OUTDIR" || true
done
for C in "$DIR"/com_extra_*; do
[ -e "$C" ] && mv -v "$C" "$OUTDIR" || true
done
fi
done