Merge "aboot: Add dtree support for flash targets."
diff --git a/arch/arm/crt0.S b/arch/arm/crt0.S
index ce823c1..7f1ad16 100644
--- a/arch/arm/crt0.S
+++ b/arch/arm/crt0.S
@@ -187,14 +187,3 @@
 abort_stack:
 	.skip 1024
 abort_stack_top:
-
-.rodata:
-.align 2
-
-/* define the heap end as read-only data containing the end defined in the
- * linker script. other archs that use dynamic memory length discovery can make
- * this read-write and update it during init.
- */
-.global _heap_end
-_heap_end:
-	.int _end_of_ram
diff --git a/dev/ssbi/ssbi.c b/dev/ssbi/ssbi.c
index 09ca4c6..5d16935 100644
--- a/dev/ssbi/ssbi.c
+++ b/dev/ssbi/ssbi.c
@@ -79,7 +79,7 @@
 	/*
 	 * Use remote spin locks since SSBI2 controller is shared with nonHLOS proc
 	 */
-#ifdef TARGET_USES_RSPIN_LOCK
+#if TARGET_USES_RSPIN_LOCK
 	remote_spin_lock(rlock);
 #endif
 	read_cmd = SSBI_CMD_READ(addr);
@@ -109,7 +109,7 @@
 		len--;
 	}
 end:
-#ifdef TARGET_USES_RSPIN_LOCK
+#if TARGET_USES_RSPIN_LOCK
 	remote_spin_unlock(rlock);
 #endif
 	return ret;
@@ -128,7 +128,7 @@
 	/*
 	 * Use remote spin locks since SSBI2 controller is shared with nonHLOS proc
 	 */
-#ifdef TARGET_USES_RSPIN_LOCK
+#if TARGET_USES_RSPIN_LOCK
 	remote_spin_lock(rlock);
 #endif
 	mode2 = readl(MSM_SSBI_BASE + SSBI2_MODE2);
@@ -156,10 +156,10 @@
 		len--;
 	}
 end:
-#ifdef TARGET_USES_RSPIN_LOCK
+#if TARGET_USES_RSPIN_LOCK
 	remote_spin_unlock(rlock);
 #endif
-	return 0;
+	return ret;
 }
 
 int pa1_ssbi2_read_bytes(unsigned char  *buffer, unsigned short length,
diff --git a/include/stdlib.h b/include/stdlib.h
index fb1e1de..3052dab 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -34,6 +34,7 @@
 unsigned int atoui(const char *num);
 long atol(const char *num);
 unsigned long atoul(const char *num);
+int itoa(int num, unsigned char* str, int len, int base);
 
 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
@@ -46,4 +47,3 @@
 	uint8_t __##var[(size) + CACHE_LINE]; uint8_t *var = (uint8_t *)(ROUNDUP((addr_t)__##var, CACHE_LINE))
 
 #endif
-
diff --git a/include/string.h b/include/string.h
index 3dccd92..661e746 100644
--- a/include/string.h
+++ b/include/string.h
@@ -54,6 +54,7 @@
 int         strcoll(const char *s1, const char *s2) __PURE;
 size_t      strxfrm(char *dest, const char *src, size_t n) __PURE;
 char       *strdup(const char *str) __MALLOC;
+void        strrev(unsigned char *str) __PURE;
 
 #ifdef __cplusplus
 } /* extern "C" */
diff --git a/lib/heap/heap.c b/lib/heap/heap.c
index 71b6fa4..a3a35fb 100644
--- a/lib/heap/heap.c
+++ b/lib/heap/heap.c
@@ -52,10 +52,10 @@
 extern int _end;
 
 // end of memory
-extern int _heap_end;
+extern int _end_of_ram;
 
 #define HEAP_START ((unsigned long)&_end)
-#define HEAP_LEN ((size_t)_heap_end - (size_t)&_end)
+#define HEAP_LEN ((size_t)&_end_of_ram - (size_t)&_end)
 #endif
 
 struct free_heap_chunk {
diff --git a/lib/libc/itoa.c b/lib/libc/itoa.c
new file mode 100644
index 0000000..6f68565
--- /dev/null
+++ b/lib/libc/itoa.c
@@ -0,0 +1,63 @@
+/* Copyright (c) 2012, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ *  notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ *  with the distribution.
+ *   * Neither the name of The Linux Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+int
+itoa(int num, unsigned char* str, int len, int base)
+{
+	int sum = num;
+	int i = 0;
+	int digit;
+
+	if (len == 0)
+		return -1;
+
+	do
+	{
+		digit = sum % base;
+
+		if (digit < 0xA)
+			str[i++] = '0' + digit;
+		else
+			str[i++] = 'A' + digit - 0xA;
+
+		sum /= base;
+
+	}while (sum && (i < (len - 1)));
+
+	if (i == (len - 1) && sum)
+		return -1;
+
+	str[i] = '\0';
+	strrev(str);
+
+	return 0;
+}
diff --git a/lib/libc/rules.mk b/lib/libc/rules.mk
index e250cfe..0dd0d02 100644
--- a/lib/libc/rules.mk
+++ b/lib/libc/rules.mk
@@ -3,6 +3,7 @@
 OBJS += \
 	$(LOCAL_DIR)/atoi.o \
 	$(LOCAL_DIR)/ctype.o \
+	$(LOCAL_DIR)/itoa.o \
 	$(LOCAL_DIR)/printf.o \
 	$(LOCAL_DIR)/malloc.o \
 	$(LOCAL_DIR)/rand.o \
@@ -17,4 +18,3 @@
 	$(LOCAL_DIR)/atexit.o \
 	$(LOCAL_DIR)/pure_virtual.o
 endif
-
diff --git a/lib/libc/string/rules.mk b/lib/libc/string/rules.mk
index 1d038e6..fc1ceb2 100644
--- a/lib/libc/string/rules.mk
+++ b/lib/libc/string/rules.mk
@@ -25,6 +25,7 @@
 	strnlen \
 	strpbrk \
 	strrchr \
+	strrev \
 	strspn \
 	strstr \
 	strtok \
@@ -39,4 +40,3 @@
 
 OBJS += \
 	$(addprefix $(LIBC_STRING_C_DIR)/,$(addsuffix .o,$(C_STRING_OPS)))
-
diff --git a/lib/libc/string/strrev.c b/lib/libc/string/strrev.c
new file mode 100644
index 0000000..a961d79
--- /dev/null
+++ b/lib/libc/string/strrev.c
@@ -0,0 +1,46 @@
+/* Copyright (c) 2012, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ *  notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ *  with the distribution.
+ *   * Neither the name of The Linux Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <string.h>
+#include <sys/types.h>
+
+void
+strrev(unsigned char *str)
+{
+	int i;
+	int j;
+	unsigned char a;
+	unsigned len = strlen((const char *)str);
+
+	for (i = 0, j = len - 1; i < j; i++, j--)
+	{
+		a = str[i];
+		str[i] = str[j];
+		str[j] = a;
+	}
+}
diff --git a/platform/copper/acpuclock.c b/platform/copper/acpuclock.c
index 3911572..8a9f96d 100644
--- a/platform/copper/acpuclock.c
+++ b/platform/copper/acpuclock.c
@@ -153,11 +153,15 @@
 {
 	int ret;
 
-	/* Enable blsp_uart_clk */
-	/* TODO: Find out correct frequency and UART_DM_CLK_RX_TX_BIT_RATE
-	 * combination for generating 115200 baud rate.
-	 */
-	ret = clk_get_set_enable("uart1_core_clk", 7372800, 1);
+
+    ret = clk_get_set_enable("uart2_iface_clk", 0, 1);
+    if(ret)
+	{
+		dprintf(CRITICAL, "failed to set uart2_iface_clk ret = %d\n", ret);
+		ASSERT(0);
+	}
+
+    ret = clk_get_set_enable("uart2_core_clk", 7372800, 1);
 	if(ret)
 	{
 		dprintf(CRITICAL, "failed to set uart1_core_clk ret = %d\n", ret);
diff --git a/platform/copper/copper-clock.c b/platform/copper/copper-clock.c
index 7fd15bb..ed7ace2 100644
--- a/platform/copper/copper-clock.c
+++ b/platform/copper/copper-clock.c
@@ -77,6 +77,11 @@
 	.is_enabled = pll_vote_clk_is_enabled,
 };
 
+static struct clk_ops clk_ops_vote =
+{
+	.enable     = clock_lib2_vote_clk_enable,
+	.disable    = clock_lib2_vote_clk_disable,
+};
 
 /* Clock Sources */
 static struct fixed_clk cxo_clk_src =
@@ -176,61 +181,43 @@
 	F_END
 };
 
-static struct rcg_clk blsp1_uart1_apps_clk_src =
+static struct rcg_clk blsp1_uart2_apps_clk_src =
 {
-	.cmd_reg      = (uint32_t *) BLSP1_UART1_APPS_CMD_RCGR,
-	.cfg_reg      = (uint32_t *) BLSP1_UART1_APPS_CFG_RCGR,
-	.m_reg        = (uint32_t *) BLSP1_UART1_APPS_M,
-	.n_reg        = (uint32_t *) BLSP1_UART1_APPS_N,
-	.d_reg        = (uint32_t *) BLSP1_UART1_APPS_D,
+	.cmd_reg      = (uint32_t *) BLSP1_UART2_APPS_CMD_RCGR,
+	.cfg_reg      = (uint32_t *) BLSP1_UART2_APPS_CFG_RCGR,
+	.m_reg        = (uint32_t *) BLSP1_UART2_APPS_M,
+	.n_reg        = (uint32_t *) BLSP1_UART2_APPS_N,
+	.d_reg        = (uint32_t *) BLSP1_UART2_APPS_D,
 
 	.set_rate     = clock_lib2_rcg_set_rate_mnd,
 	.freq_tbl     = ftbl_gcc_blsp1_2_uart1_6_apps_clk,
 	.current_freq = &rcg_dummy_freq,
 
 	.c = {
-		.dbg_name = "blsp1_uart1_apps_clk",
+		.dbg_name = "blsp1_uart2_apps_clk",
 		.ops      = &clk_ops_rcg_mnd,
 	},
 };
 
-static struct rcg_clk blsp1_uart3_apps_clk_src =
+static struct branch_clk gcc_blsp1_uart2_apps_clk =
 {
-	.cmd_reg      = (uint32_t *) BLSP1_UART3_APPS_CMD_RCGR,
-	.cfg_reg      = (uint32_t *) BLSP1_UART3_APPS_CFG_RCGR,
-	.m_reg        = (uint32_t *) BLSP1_UART3_APPS_M,
-	.n_reg        = (uint32_t *) BLSP1_UART3_APPS_N,
-	.d_reg        = (uint32_t *) BLSP1_UART3_APPS_D,
-
-	.set_rate     = clock_lib2_rcg_set_rate_mnd,
-	.freq_tbl     = ftbl_gcc_blsp1_2_uart1_6_apps_clk,
-	.current_freq = &rcg_dummy_freq,
+	.cbcr_reg     = (uint32_t *) BLSP1_UART2_APPS_CBCR,
+	.parent       = &blsp1_uart2_apps_clk_src.c,
 
 	.c = {
-		.dbg_name = "blsp1_uart3_apps_clk",
-		.ops      = &clk_ops_rcg_mnd,
-	},
-};
-
-static struct branch_clk gcc_blsp1_uart1_apps_clk =
-{
-	.cbcr_reg     = (uint32_t *) BLSP1_UART1_APPS_CBCR,
-	.parent       = &blsp1_uart1_apps_clk_src.c,
-
-	.c = {
-		.dbg_name = "gcc_blsp1_uart1_apps_clk",
+		.dbg_name = "gcc_blsp1_uart2_apps_clk",
 		.ops      = &clk_ops_branch,
 	},
 };
 
-static struct branch_clk gcc_blsp1_uart3_apps_clk =
-{
-	.cbcr_reg     = (uint32_t *) BLSP1_UART3_APPS_CBCR,
-	.parent       = &blsp1_uart3_apps_clk_src.c,
+static struct vote_clk gcc_blsp1_ahb_clk = {
+	.cbcr_reg     = (uint32_t *) BLSP1_AHB_CBCR,
+	.vote_reg     = APCS_CLOCK_BRANCH_ENA_VOTE,
+	.en_mask      = BIT(17),
 
 	.c = {
-		.dbg_name = "gcc_blsp1_uart3_apps_clk",
-		.ops      = &clk_ops_branch,
+		.dbg_name = "gcc_blsp1_ahb_clk",
+		.ops      = &clk_ops_vote,
 	},
 };
 
@@ -285,8 +272,8 @@
 	CLK_LOOKUP("sdc1_iface_clk", gcc_sdcc1_ahb_clk.c),
 	CLK_LOOKUP("sdc1_core_clk",  gcc_sdcc1_apps_clk.c),
 
-	CLK_LOOKUP("uart1_core_clk", gcc_blsp1_uart1_apps_clk.c),
-	CLK_LOOKUP("uart3_core_clk", gcc_blsp1_uart3_apps_clk.c),
+	CLK_LOOKUP("uart2_iface_clk", gcc_blsp1_ahb_clk.c),
+	CLK_LOOKUP("uart2_core_clk",  gcc_blsp1_uart2_apps_clk.c),
 
 	CLK_LOOKUP("usb_iface_clk",  gcc_usb_hs_ahb_clk.c),
 	CLK_LOOKUP("usb_core_clk",   gcc_usb_hs_system_clk.c),
diff --git a/platform/copper/gpio.c b/platform/copper/gpio.c
index 86b9e40..806aab4 100644
--- a/platform/copper/gpio.c
+++ b/platform/copper/gpio.c
@@ -54,9 +54,11 @@
 /* Configure gpio for blsp uart 2 */
 void gpio_config_uart_dm(uint8_t id)
 {
-	gpio_tlmm_config(0, 2, GPIO_OUTPUT, GPIO_NO_PULL,
+    /* configure rx gpio */
+	gpio_tlmm_config(5, 2, GPIO_INPUT, GPIO_NO_PULL,
 				GPIO_8MA, GPIO_DISABLE);
 
-	gpio_tlmm_config(1, 2, GPIO_INPUT, GPIO_NO_PULL,
+    /* configure tx gpio */
+	gpio_tlmm_config(4, 2, GPIO_OUTPUT, GPIO_NO_PULL,
 				GPIO_8MA, GPIO_DISABLE);
 }
diff --git a/platform/copper/include/platform/clock.h b/platform/copper/include/platform/clock.h
index 0aa8604..7d59b0c 100644
--- a/platform/copper/include/platform/clock.h
+++ b/platform/copper/include/platform/clock.h
@@ -32,7 +32,7 @@
 #include <clock.h>
 #include <clock_lib2.h>
 
-#define UART_DM_CLK_RX_TX_BIT_RATE 0xFF
+#define UART_DM_CLK_RX_TX_BIT_RATE 0xCC
 
 void platform_clock_init(void);
 
diff --git a/platform/copper/include/platform/iomap.h b/platform/copper/include/platform/iomap.h
index d48c7c9..c26f1b5 100644
--- a/platform/copper/include/platform/iomap.h
+++ b/platform/copper/include/platform/iomap.h
@@ -83,7 +83,7 @@
 #define SPMI_GENI_BASE              (SPMI_BASE + 0xA000)
 #define SPMI_PIC_BASE               (SPMI_BASE + 0xB000)
 
-#define TLMM_BASE_ADDR              0xFD500000
+#define TLMM_BASE_ADDR              0xFD510000
 #define GPIO_CONFIG_ADDR(x)         (TLMM_BASE_ADDR + 0x1000 + (x)*0x10)
 #define GPIO_IN_OUT_ADDR(x)         (TLMM_BASE_ADDR + 0x1004 + (x)*0x10)
 
@@ -93,6 +93,7 @@
 /* GPLL */
 #define GPLL0_STATUS                (CLK_CTL_BASE + 0x001C)
 #define APCS_GPLL_ENA_VOTE          (CLK_CTL_BASE + 0x1480)
+#define APCS_CLOCK_BRANCH_ENA_VOTE  (CLK_CTL_BASE + 0x1484)
 
 /* SDCC */
 #define SDCC1_BCR                   (CLK_CTL_BASE + 0x4C0) /* block reset */
@@ -106,19 +107,13 @@
 #define SDCC1_D                     (CLK_CTL_BASE + 0x4E0) /* d */
 
 /* UART */
-#define BLSP1_UART1_APPS_CBCR       (CLK_CTL_BASE + 0x684)
-#define BLSP1_UART1_APPS_CMD_RCGR   (CLK_CTL_BASE + 0x68C)
-#define BLSP1_UART1_APPS_CFG_RCGR   (CLK_CTL_BASE + 0x690)
-#define BLSP1_UART1_APPS_M          (CLK_CTL_BASE + 0x694)
-#define BLSP1_UART1_APPS_N          (CLK_CTL_BASE + 0x698)
-#define BLSP1_UART1_APPS_D          (CLK_CTL_BASE + 0x69C)
-
-#define BLSP1_UART3_APPS_CBCR       (CLK_CTL_BASE + 0x784)
-#define BLSP1_UART3_APPS_CMD_RCGR   (CLK_CTL_BASE + 0x78C)
-#define BLSP1_UART3_APPS_CFG_RCGR   (CLK_CTL_BASE + 0x790)
-#define BLSP1_UART3_APPS_M          (CLK_CTL_BASE + 0x794)
-#define BLSP1_UART3_APPS_N          (CLK_CTL_BASE + 0x798)
-#define BLSP1_UART3_APPS_D          (CLK_CTL_BASE + 0x79C)
+#define BLSP1_AHB_CBCR              (CLK_CTL_BASE + 0x5C4)
+#define BLSP1_UART2_APPS_CBCR       (CLK_CTL_BASE + 0x704)
+#define BLSP1_UART2_APPS_CMD_RCGR   (CLK_CTL_BASE + 0x70C)
+#define BLSP1_UART2_APPS_CFG_RCGR   (CLK_CTL_BASE + 0x710)
+#define BLSP1_UART2_APPS_M          (CLK_CTL_BASE + 0x714)
+#define BLSP1_UART2_APPS_N          (CLK_CTL_BASE + 0x718)
+#define BLSP1_UART2_APPS_D          (CLK_CTL_BASE + 0x71C)
 
 /* USB */
 #define USB_HS_SYSTEM_CBCR          (CLK_CTL_BASE + 0x484)
diff --git a/platform/msm_shared/clock_lib2.c b/platform/msm_shared/clock_lib2.c
index 0aa405c..645755c 100644
--- a/platform/msm_shared/clock_lib2.c
+++ b/platform/msm_shared/clock_lib2.c
@@ -191,3 +191,39 @@
 
 	clock_lib2_rcg_update_config(rclk);
 }
+
+/*=============== Vote clock ops =============*/
+
+/* Vote clock enable */
+int clock_lib2_vote_clk_enable(struct clk *c)
+{
+	uint32_t vote_regval;
+	uint32_t val;
+	struct vote_clk *vclk = to_local_vote_clk(c);
+
+	vote_regval = readl(vclk->vote_reg);
+	vote_regval |= vclk->en_mask;
+	writel_relaxed(vote_regval, vclk->vote_reg);
+	do {
+		val = readl(vclk->cbcr_reg);
+		val &= BRANCH_CHECK_MASK;
+	}
+	/*  wait until status shows it is enabled */
+	while((val != BRANCH_ON_VAL) && (val != BRANCH_NOC_FSM_ON_VAL));
+
+	return 0;
+}
+
+/* Vote clock disable */
+void clock_lib2_vote_clk_disable(struct clk *c)
+{
+	uint32_t vote_regval;
+	struct vote_clk *vclk = to_local_vote_clk(c);
+
+	vote_regval = readl(vclk->vote_reg);
+	vote_regval &= ~vclk->en_mask;
+    writel_relaxed(vote_regval, vclk->vote_reg);
+
+    /* wait until status shows it is disabled */
+	while(!(readl(vclk->cbcr_reg) & CBCR_BRANCH_OFF_BIT));
+}
diff --git a/platform/msm_shared/include/clock_lib2.h b/platform/msm_shared/include/clock_lib2.h
index 0a82c51..2f6deb7 100644
--- a/platform/msm_shared/include/clock_lib2.h
+++ b/platform/msm_shared/include/clock_lib2.h
@@ -62,6 +62,9 @@
 /* Branch Clock Bits */
 #define CBCR_BRANCH_ENABLE_BIT  BIT(0)
 #define CBCR_BRANCH_OFF_BIT     BIT(31)
+#define BRANCH_CHECK_MASK       BM(31, 28)
+#define BRANCH_ON_VAL           BVAL(31, 28, 0x0)
+#define BRANCH_NOC_FSM_ON_VAL   BVAL(31, 28, 0x2)
 
 /* Root Clock Bits */
 #define CMD_UPDATE_BIT          BIT(0)
@@ -138,6 +141,16 @@
 	struct clk c;
 };
 
+/* Vote Clock */
+struct vote_clk {
+
+	uint32_t *const cbcr_reg;
+	uint32_t *const vote_reg;
+	uint32_t en_mask;
+
+    struct clk c;
+};
+
 static inline struct rcg_clk *to_rcg_clk(struct clk *clk)
 {
 	return container_of(clk, struct rcg_clk, c);
@@ -148,6 +161,11 @@
 	return container_of(clk, struct branch_clk, c);
 }
 
+static inline struct vote_clk *to_local_vote_clk(struct clk *clk)
+{
+	return container_of(clk, struct vote_clk, c);
+}
+
 /* RCG clock functions */
 int  clock_lib2_rcg_enable(struct clk *c);
 int  clock_lib2_rcg_set_rate(struct clk *c, unsigned rate);
@@ -163,4 +181,7 @@
 void clock_lib2_branch_clk_disable(struct clk *clk);
 int  clock_lib2_branch_set_rate(struct clk *c, unsigned rate);
 
+/* Vote clock functions*/
+int clock_lib2_vote_clk_enable(struct clk *c);
+void clock_lib2_vote_clk_disable(struct clk *c);
 #endif
diff --git a/platform/msm_shared/mmc.c b/platform/msm_shared/mmc.c
index 0f70b53..b504c35 100644
--- a/platform/msm_shared/mmc.c
+++ b/platform/msm_shared/mmc.c
@@ -2659,45 +2659,49 @@
 	unsigned int mmc_count = 0;
 	unsigned int write_error = MMC_BOOT_MCI_STAT_DATA_CRC_FAIL |
 	    MMC_BOOT_MCI_STAT_DATA_TIMEOUT | MMC_BOOT_MCI_STAT_TX_UNDRUN;
+	unsigned int count = 0;
+	unsigned int sz = 0;
 
 	/* Write the transfer data to SDCC3 FIFO */
 	do {
-		mmc_ret = MMC_BOOT_E_SUCCESS;
 		mmc_status = readl(MMC_BOOT_MCI_STATUS);
 
-		if (mmc_status & write_error) {
-			mmc_ret = mmc_boot_status_error(mmc_status);
-			break;
-		}
+		/* Bytes left to write */
+		count = data_len - mmc_count;
 
-		/* Write the data in MCI_FIFO register as long as TXFIFO_FULL bit of
-		   MCI_STATUS register is 0. Continue the writes until the whole
-		   transfer data is written. */
-		if (((data_len - mmc_count) >= MMC_BOOT_MCI_FIFO_SIZE / 2) &&
-		    (mmc_status & MMC_BOOT_MCI_STAT_TX_FIFO_HFULL)) {
-			for (int i = 0; i < MMC_BOOT_MCI_HFIFO_COUNT; i++) {
-				/* FIFO contains 16 32-bit data buffer on 16 sequential addresses */
-				writel(*mmc_ptr, MMC_BOOT_MCI_FIFO +
-				       (mmc_count % MMC_BOOT_MCI_FIFO_SIZE));
+		/* Break if whole data is transferred */
+		if (!count)
+			break;
+
+		/* Write half FIFO or less (remaining) words in MCI_FIFO as long as either
+		   TX_FIFO_EMPTY or TX_FIFO_HFULL bits of MCI_STATUS register are set. */
+		if ((mmc_status & MMC_BOOT_MCI_STAT_TX_FIFO_EMPTY) ||
+			(mmc_status & MMC_BOOT_MCI_STAT_TX_FIFO_HFULL)) {
+
+			/* Write minimum of half FIFO and remaining words */
+			sz = ((count >> 2) >  MMC_BOOT_MCI_HFIFO_COUNT) \
+				 ? MMC_BOOT_MCI_HFIFO_COUNT : (count >> 2);
+
+			for (int i = 0; i < sz; i++) {
+				writel(*mmc_ptr, MMC_BOOT_MCI_FIFO);
 				mmc_ptr++;
 				/* increase mmc_count by word size */
 				mmc_count += sizeof(unsigned int);
 			}
-
-		} else if (!(mmc_status & MMC_BOOT_MCI_STAT_TX_FIFO_FULL)
-			   && (mmc_count != data_len)) {
-			/* FIFO contains 16 32-bit data buffer on 16 sequential addresses */
-			writel(*mmc_ptr, MMC_BOOT_MCI_FIFO +
-			       (mmc_count % MMC_BOOT_MCI_FIFO_SIZE));
-			mmc_ptr++;
-			/* increase mmc_count by word size */
-			mmc_count += sizeof(unsigned int);
-		} else if ((mmc_status & MMC_BOOT_MCI_STAT_DATA_END)) {
-			break;	//success
 		}
-
 	}
 	while (1);
+
+	do
+	{
+		mmc_status = readl(MMC_BOOT_MCI_STATUS);
+		if (mmc_status & write_error) {
+			mmc_ret = mmc_boot_status_error(mmc_status);
+			break;
+		}
+	}
+	while (!(mmc_status & MMC_BOOT_MCI_STAT_DATA_END));
+
 	return mmc_ret;
 }
 
diff --git a/project/copper.mk b/project/copper.mk
index 79681f0..35e2c15 100644
--- a/project/copper.mk
+++ b/project/copper.mk
@@ -9,7 +9,7 @@
 DEBUG := 1
 
 #DEFINES += WITH_DEBUG_DCC=1
-#DEFINES += WITH_DEBUG_UART=1
+DEFINES += WITH_DEBUG_UART=1
 #DEFINES += WITH_DEBUG_FBCON=1
 DEFINES += DEVICE_TREE=1
 #DEFINES += MMC_BOOT_BAM=1
diff --git a/target/copper/atags.c b/target/copper/atags.c
deleted file mode 100644
index 174ae77..0000000
--- a/target/copper/atags.c
+++ /dev/null
@@ -1,133 +0,0 @@
-/* Copyright (c) 2009-2012, Code Aurora Forum. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in the
- *       documentation and/or other materials provided with the distribution.
- *     * Neither the name of Code Aurora nor
- *       the names of its contributors may be used to endorse or promote
- *       products derived from this software without specific prior written
- *       permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#if !DEVICE_TREE /* If not using device tree */
-
-#include <reg.h>
-#include <debug.h>
-#include <smem.h>
-#include <platform/iomap.h>
-#include <stdint.h>
-
-#define SIZE_1M             (1024 * 1024)
-#define SIZE_2M             (2 * SIZE_1M)
-#define SIZE_256M           (256 * SIZE_1M)
-#define SIZE_512M           (512 * SIZE_1M)
-
-#define ATAG_MEM            0x54410002
-
-typedef struct {
-	uint32_t size;
-	uint32_t start_addr;
-}mem_info;
-
-
-mem_info copper_default_first_512M[] = {
-	{	.size = (250 * SIZE_1M),
-		.start_addr = SDRAM_START_ADDR
-	},
-	{	.size = (240 * SIZE_1M),
-		.start_addr = SDRAM_START_ADDR +
-				(16 * SIZE_1M) +
-				(256 * SIZE_1M)
-	}
-};
-
-unsigned *target_mem_atag_create(unsigned *ptr, uint32_t size, uint32_t addr)
-{
-    *ptr++ = 4;
-    *ptr++ = ATAG_MEM;
-    *ptr++ = size;
-    *ptr++ = addr;
-
-    return ptr;
-}
-
-
-unsigned *target_atag_create(unsigned *ptr,
-	mem_info usable_mem_map[], unsigned num_regions)
-{
-	unsigned int i;
-
-	ASSERT(num_regions);
-
-	dprintf(SPEW, "Number of HLOS regions in 1st bank = %u\n", num_regions);
-
-	for (i = 0; i < num_regions; i++)
-	{
-		ptr = target_mem_atag_create(ptr,
-			usable_mem_map[i].size,
-			usable_mem_map[i].start_addr);
-	}
-	return ptr;
-}
-
-unsigned *target_atag_mem(unsigned *ptr)
-{
-    struct smem_ram_ptable ram_ptable;
-    uint8_t i = 0;
-
-	/* Make sure RAM partition table is initialized */
-	ASSERT(smem_ram_ptable_init(&ram_ptable));
-
-	for (i = 0; i < ram_ptable.len; i++)
-	{
-		if (ram_ptable.parts[i].category == SDRAM &&
-			(ram_ptable.parts[i].type == SYS_MEMORY) &&
-			(ram_ptable.parts[i].start == SDRAM_START_ADDR))
-		{
-			ASSERT(ram_ptable.parts[i].size >= SIZE_512M);
-
-			if (ram_ptable.parts[i].start == SDRAM_START_ADDR)
-				ptr = target_atag_create(ptr,
-					copper_default_first_512M,
-					ARRAY_SIZE(copper_default_first_512M));
-
-		}
-
-		/* Pass along all other usable memory regions to Linux */
-		if (ram_ptable.parts[i].category == SDRAM &&
-			(ram_ptable.parts[i].type == SYS_MEMORY) &&
-			(ram_ptable.parts[i].start != SDRAM_START_ADDR))
-		{
-			ptr = target_mem_atag_create(ptr,
-				ram_ptable.parts[i].size,
-				ram_ptable.parts[i].start);
-		}
-	}
-
-    return ptr;
-}
-
-void *target_get_scratch_address(void)
-{
-	return ((void *)SCRATCH_ADDR);
-}
-
-#endif /* DEVICE_TREE */
-
diff --git a/target/copper/init.c b/target/copper/init.c
index b5922c3..56acf93 100644
--- a/target/copper/init.c
+++ b/target/copper/init.c
@@ -54,7 +54,7 @@
 void target_early_init(void)
 {
 #if WITH_DEBUG_UART
-	uart_dm_init(0, 0, BLSP1_UART0_BASE);
+	uart_dm_init(1, 0, BLSP1_UART1_BASE);
 #endif
 }
 
diff --git a/target/copper/rules.mk b/target/copper/rules.mk
index 238dbe9..73eb416 100644
--- a/target/copper/rules.mk
+++ b/target/copper/rules.mk
@@ -32,5 +32,4 @@
 
 OBJS += \
     $(LOCAL_DIR)/init.o \
-    $(LOCAL_DIR)/atags.o \
     $(LOCAL_DIR)/meminfo.o
diff --git a/target/mdm9615/init.c b/target/mdm9615/init.c
index 653986b..daedbc3 100644
--- a/target/mdm9615/init.c
+++ b/target/mdm9615/init.c
@@ -287,6 +287,7 @@
 			ptentry_ptr[ptn_index].name[i] =
 		    tolower(ptentry_ptr[ptn_index].name[i]);
 		}
+        ptentry_ptr[ptn_index].type = TYPE_APPS_PARTITION;
 	}
 }
 
diff --git a/target/msm7630_surf/init.c b/target/msm7630_surf/init.c
index eb0c525..f74b65f 100644
--- a/target/msm7630_surf/init.c
+++ b/target/msm7630_surf/init.c
@@ -41,7 +41,7 @@
 #include <mmc.h>
 #include <platform/iomap.h>
 #include <platform/machtype.h>
-#ifdef TARGET_USES_RSPIN_LOCK
+#if TARGET_USES_RSPIN_LOCK
 #include <platform/remote_spinlock.h>
 #endif
 #include <platform.h>
@@ -192,7 +192,7 @@
 
 	dprintf(INFO, "target_init()\n");
 
-#ifdef TARGET_USES_RSPIN_LOCK
+#if TARGET_USES_RSPIN_LOCK
 	if(remote_spinlock_init(&rlock))
 		dprintf(SPEW,"Failed to Initialize remote spin locks\n");
 #endif