bin_header_debug: add new image for debug mode

	** this is patch #1 in bin_header_debug series of patches

	- Add new image for bin header debug mode
	- The image is uploaded to the board via UART
	** this patch only makes new uart image, the functionality
	** of the debug mode will be uploaded in different patches

Change-Id: If2486758cca92f64dd900d96a3e8327e653b18c4
Signed-off-by: Bassel Saba <basselsa@marvell.com>
Reviewed-on: http://vgitil04.il.marvell.com:8080/19491
Tested-by: Star_Automation <star@marvell.com>
Reviewed-by: Omri Itach <omrii@marvell.com>
diff --git a/build.pl b/build.pl
index 3733949..11de266 100755
--- a/build.pl
+++ b/build.pl
@@ -430,6 +430,7 @@
 print "\n**** [Creating Image]\t*****\n\n";
 
 $failUart = system("./tools/marvell/doimage -T uart -D 0 -E 0 -G ./tools/marvell/bin_hdr/bin_hdr.uart.bin u-boot.bin u-boot-$boardID-$opt_v-$flash_name$targetBoard-uart.bin");
+$failDebug = system("./tools/marvell/doimage -T uart -D 0 -E 0 -H 3 -G ./tools/marvell/bin_hdr/bin_hdr.debug.bin u-boot.bin u-boot-$boardID-$opt_v-$flash_name$targetBoard-debug.bin");
 $fail = system("./tools/marvell/doimage -T $img_type -D 0x0 -E 0x0 $img_opts $rsa_opts $id_opts $extra_opt -G ./tools/marvell/bin_hdr/$bin_hdr_n u-boot.bin u-boot-$boardID-$opt_v-$flash_name$targetBoard.bin");
 
 if($fail){
@@ -440,6 +441,10 @@
 	print "\n *** Error: Doimage for uart image failed\n\n";
 	exit 1;
 }
+if($failDebug){
+	print "\n *** Error: Doimage for debug image failed\n\n";
+	exit 1;
+}
 
 if(defined $opt_o)
 {
diff --git a/tools/marvell/bin_hdr/Makefile b/tools/marvell/bin_hdr/Makefile
index f2e0434..2643fe2 100755
--- a/tools/marvell/bin_hdr/Makefile
+++ b/tools/marvell/bin_hdr/Makefile
@@ -85,6 +85,8 @@
 AOBJ = $(subst .s,.o,$(ASRC))
 COBJ = $(subst .c,.o,$(CSRC))
 CUART_OBJ = $(subst .c,.uart.o,$(CSRC))
+CDEBUG_OBJ = $(subst .c,.debug.o,$(CSRC)) # debug object for mvdispatcher
+
 
 LIB_PHY = phy_$(BOARD).a
 LIB_DDR = ddr_$(BOARD).a
@@ -98,6 +100,8 @@
 LIB_SWUP_UART = suspendWUP.uart.a
 LIB_GENERAL_INIT_UART = generalInit.uart.a
 
+LIB_PLAT_DEBUG = plat.debug.a # specific platform library with bin header debug tool
+
 LIBGCC = $(MAIN)/libgcc.lib
 
 ifeq ($(DDRTYPE),)
@@ -109,6 +113,7 @@
 COMPONENT_SUBDIRS = platform src_phy src_ddr src_pm src_init
 HDR_COMPONENTS = $(LIB_PLAT) $(LIB_GENERAL_INIT) $(LIB_PHY) $(LIB_DDR) $(TLIB) $(LIB_SWUP)
 HDR_COMPONENTS_UART = $(LIB_PLAT_UART) $(LIB_GENERAL_INIT_UART) $(LIB_PHY_UART) $(LIB_DDR_UART) $(TLIB) $(LIB_SWUP_UART)
+HDR_COMPONENTS_DEBUG = $(LIB_PLAT_DEBUG) $(LIB_GENERAL_INIT) $(LIB_PHY) $(LIB_DDR) $(TLIB) $(LIB_SWUP)
 
 #how to add new component to binary header:
 #EXAMPLE_COMPONENT=no
@@ -125,7 +130,7 @@
 $(info )
 endif
 
-all:   subdirs $(TGT).bin $(TGT)_sec.bin $(TGT).uart.bin  $(TGT).dis $(TGT)_sec.dis $(TGT).uart.dis $(TGT).srec $(TGT)_sec.srec $(TGT).uart.srec
+all:   subdirs $(TGT).bin $(TGT)_sec.bin $(TGT).uart.bin  $(TGT).dis $(TGT)_sec.dis $(TGT).uart.dis $(TGT).srec $(TGT)_sec.srec $(TGT).uart.srec $(TGT).debug.bin
 
 %.o: %.c
 	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
@@ -133,6 +138,9 @@
 %.uart.o: %.c
 	$(CC) $(CFLAGS) -DNOT_USE_UART -DMV_NO_INPUT -DMV_NO_PRINT  $(CPPFLAGS) -c -o  $@ $<
 
+%.debug.o: %.c
+	$(CC) $(CFLAGS) -DMV_DEBUG_MODE $(CPPFLAGS) -c -o  $@ $<
+
 $(TGT).bin: $(TGT).elf
 	$(OBJCOPY) -S -O binary $< $(addsuffix .tmp, $@)
 	$(CAT) $(PARAMSFILE).raw $(addsuffix .tmp, $@) > $@
@@ -148,6 +156,11 @@
 	$(CAT) $(PARAMSFILE).raw $(addsuffix .tmp, $@) > $@
 	$(RM) $(addsuffix .tmp, $@)
 
+$(TGT).debug.bin: $(TGT).debug.elf
+	$(OBJCOPY) -S -O binary $< $(addsuffix .tmp, $@)
+	$(CAT) $(PARAMSFILE).raw $(addsuffix .tmp, $@) > $@
+	$(RM) $(addsuffix .tmp, $@)
+
 $(TGT).srec: $(TGT).elf
 	$(OBJCOPY) -O srec $< $@
 
@@ -175,6 +188,9 @@
 $(TGT).uart.elf: $(AOBJ) $(CUART_OBJ) subdirs
 	$(CC) $(LDFLAGSBIN) $(AOBJ) $(CUART_OBJ) $(HDR_COMPONENTS_UART) $(LIB_PLAT_UART) $(LIBGCC) -o $@
 
+$(TGT).debug.elf: $(AOBJ) $(CDEBUG_OBJ) subdirs
+	$(CC) $(LDFLAGSBIN) $(AOBJ) $(CDEBUG_OBJ) $(HDR_COMPONENTS_DEBUG) $(LIB_PLAT_DEBUG) $(LIBGCC) -o $@
+
 $(LDSCRIPT): $(SETPARAMS)
 	./$(SETPARAMS) -B $(BOARD) -P $(PARAMSFILE).txt -R $(DRAMREGS) -d $(DEBUG_MODE_FLAG) $(PARAMSFILE).raw $@
 
@@ -196,7 +212,7 @@
 	done
 
 clean:
-	$(RM) *.raw *.elf *.srec *.dis *.bin *.a *.uart.bin *.uart.elf ./src/*.o  $(LDSCRIPT) $(LDSECSCRIPT) $(SETPARAMS)
+	$(RM) *.raw *.elf *.srec *.dis *.bin *.a *.uart.bin *.uart.elf *.debug.bin ./src/*.o  $(LDSCRIPT) $(LDSECSCRIPT) $(SETPARAMS)
 	@for dir in $(COMPONENT_SUBDIRS) ; do \
 	    $(MAKE) clean -s -C $$dir || exit 1 ; \
 	done
diff --git a/tools/marvell/bin_hdr/platform/Makefile b/tools/marvell/bin_hdr/platform/Makefile
index 9ba1eb0..2b6db42 100755
--- a/tools/marvell/bin_hdr/platform/Makefile
+++ b/tools/marvell/bin_hdr/platform/Makefile
@@ -70,6 +70,7 @@
 
 TGT = plat.a
 TGT_UART = plat.uart.a
+TGT_DEBUG = plat.debug.a
 
 DRV = drivers
 UTILS = utils
@@ -101,8 +102,10 @@
 
 COBJ = $(subst .c,.o,$(CSRC))
 CUART_OBJ = $(subst .c,.uart.o,$(CSRC))
+CDEBUG_OBJ = $(subst .c,.debug.o,$(CSRC))
 
-all:   $(TGT) $(TGT_UART)
+
+all:   $(TGT) $(TGT_UART) $(TGT_DEBUG)
 
 %.o: %.c
 	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
@@ -110,6 +113,9 @@
 %.uart.o: %.c
 	$(CC) $(CFLAGS) -DNOT_USE_UART -DMV_NO_INPUT -DMV_NO_PRINT  $(CPPFLAGS) -c -o  $@ $<
 
+%.debug.o: %.c
+	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o  $@ $<
+
 $(TGT): $(COBJ)
 	ar rcs $(TGT)  $(COBJ)
 	$(CP) ./$@ ../
@@ -118,6 +124,10 @@
 	ar rcs $(TGT_UART)  $(CUART_OBJ)
 	$(CP) ./$@ ../
 
+$(TGT_DEBUG): $(CDEBUG_OBJ)
+	ar rcs $(TGT_DEBUG)  $(CDEBUG_OBJ)
+	$(CP) ./$@ ../
+
 setparams:
 	$(HOSTCC) $(BOARDFLAG) -Wall $(INCLUDE) $(CPPFLAGS) -o $@  $(addsuffix .c, $(UTILS)/$@)
 	$(CP) $@ ../