ASR_BASE

Change-Id: Icf3719cc0afe3eeb3edc7fa80a2eb5199ca9dda1
diff --git a/marvell/swd/tools/CpDumpDecoder/busybox.exe b/marvell/swd/tools/CpDumpDecoder/busybox.exe
new file mode 100644
index 0000000..cee7221
--- /dev/null
+++ b/marvell/swd/tools/CpDumpDecoder/busybox.exe
Binary files differ
diff --git a/marvell/swd/tools/CpDumpDecoder/do_cp_dump_unpack.bat b/marvell/swd/tools/CpDumpDecoder/do_cp_dump_unpack.bat
new file mode 100644
index 0000000..d731020
--- /dev/null
+++ b/marvell/swd/tools/CpDumpDecoder/do_cp_dump_unpack.bat
@@ -0,0 +1,3 @@
+@set CP_DUMP=COM_DDR_*.bin

+@if not "%1"=="" set CP_DUMP=%1

+%~dp0busybox sh %~dp0uncprdp.sh %CP_DUMP%

diff --git a/marvell/swd/tools/CpDumpDecoder/readme.txt b/marvell/swd/tools/CpDumpDecoder/readme.txt
new file mode 100644
index 0000000..a172fea
--- /dev/null
+++ b/marvell/swd/tools/CpDumpDecoder/readme.txt
@@ -0,0 +1,9 @@
+1. how to decode all the COM_DDR_XXX.bin? 
+   a. click do_cp_dump_unpack.bat to run the script the decode the dump file
+   b. the output files are place at the sub director named COM_DDR_XXX-unpacked
+
+2. how to decode your specified CP dump file?
+   a. modify the content of do_cp_dump_unpack.bat, change COM_DDR_*.bin to 
+      your specified name
+   b. click do_cp_dump_unpack.bat to run the script the decode the dump file
+   c. the output files are place at the sub director named COM_DDR_XXX-unpacked
diff --git a/marvell/swd/tools/CpDumpDecoder/uncprdp.sh b/marvell/swd/tools/CpDumpDecoder/uncprdp.sh
new file mode 100644
index 0000000..36166dd
--- /dev/null
+++ b/marvell/swd/tools/CpDumpDecoder/uncprdp.sh
@@ -0,0 +1,67 @@
+#!/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