[mdm9x15]: Initial support for mdm9x15 target

Change-Id: I0d7f2899cacacd81594c09d688bfd0e5aa0c43b6
diff --git a/platform/mdm9x15/acpuclock.c b/platform/mdm9x15/acpuclock.c
new file mode 100644
index 0000000..d29055b
--- /dev/null
+++ b/platform/mdm9x15/acpuclock.c
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2008, Google Inc.
+ * All rights reserved.
+ * Copyright (c) 2009-2011, 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.
+ *
+ * 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 AND FITNESS
+ * FOR A PARTICULAR PURPOSE 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 <reg.h>
+#include <stdint.h>
+#include <debug.h>
+#include <gsbi.h>
+#include <platform/iomap.h>
+#include <platform/clock.h>
+
+/* Set rate and enable the clock */
+void clock_config(uint32_t ns, uint32_t md, uint32_t ns_addr, uint32_t md_addr)
+{
+	unsigned int val = 0;
+
+	/* Activate the reset for the M/N Counter */
+	val = 1 << 7;
+	writel(val, ns_addr);
+
+	/* Write the MD value into the MD register */
+	if (md_addr != 0x0)
+		writel(md, md_addr);
+
+	/* Write the ns value, and active reset for M/N Counter, again */
+	val = 1 << 7;
+	val |= ns;
+	writel(val, ns_addr);
+
+	/* De-activate the reset for M/N Counter */
+	val = 1 << 7;
+	val = ~val;
+	val = val & readl(ns_addr);
+	writel(val, ns_addr);
+
+	/* Enable the Clock Root */
+	val = 1 << 11;
+	val = val | readl(ns_addr);
+	writel(val, ns_addr);
+
+	/* Enable the Clock Branch */
+	val = 1 << 9;
+	val = val | readl(ns_addr);
+	writel(val, ns_addr);
+
+	/* Enable the M/N Counter */
+	val = 1 << 8;
+	val = val | readl(ns_addr);
+	writel(val, ns_addr);
+}
+
+void pll8_enable(void)
+{
+	unsigned int curr_value = 0;
+
+	/* Vote for PLL8 to be enabled */
+	curr_value = readl(MSM_BOOT_PLL_ENABLE_SC0);
+	curr_value |= (1 << 8);
+	writel(curr_value, MSM_BOOT_PLL_ENABLE_SC0);
+
+	/* Proceed only after PLL is enabled */
+	while (!(readl(MSM_BOOT_PLL8_STATUS) & (1<<16)));
+}
+
+void acpu_clock_init(void)
+{
+	/* ADM3: enable cc_adm0_clk */
+	writel( (1 << SC0_U_BRANCH_ENA_VOTE_ADM0) |
+		(1 << SC0_U_BRANCH_ENA_VOTE_ADM0_PBUS), SC0_U_BRANCH_ENA_VOTE);
+}
+
+void hsusb_clock_init(void)
+{
+	pll8_enable();
+
+	/* Setup USB HS1 System clock - 60 Mhz */
+	//TODO: Remove this when verify that this is already configured
+	if (!(readl(USB_HS1_SYSTEM_CLK_NS))){
+		clock_config(USB_XCVR_CLK_NS,
+					USB_XCVR_CLK_MD,
+					USB_HS1_SYSTEM_CLK_NS,
+					USB_HS1_SYSTEM_CLK_MD);
+	}
+
+	/* Setup USB HS1 XCVR clock - 60 Mhz */
+	clock_config(USB_XCVR_CLK_NS,
+				USB_XCVR_CLK_MD,
+				USB_HS1_XCVR_FS_CLK_NS,
+				USB_HS1_XCVR_FS_CLK_MD);
+
+	/* HS-USB: enable cc_usb_hs1_hs_clk */
+	writel( 0x1 << 4, USB_HS1_HCLK_CTL);
+}
+
+/* Configure UART clock - based on the gsbi id */
+void clock_config_uart_dm(uint8_t id)
+{
+	/* Enable gsbi_uart_clk */
+	clock_config(UART_DM_CLK_NS_115200,
+				UART_DM_CLK_MD_115200,
+				GSBIn_UART_APPS_NS(id),
+				GSBIn_UART_APPS_MD(id));
+
+	/* Enable gsbi_pclk */
+	writel(GSBI_HCLK_CTL_CLK_ENA << GSBI_HCLK_CTL_S, GSBIn_HCLK_CTL(id));
+}
diff --git a/platform/mdm9x15/gpio.c b/platform/mdm9x15/gpio.c
new file mode 100644
index 0000000..e8ad188
--- /dev/null
+++ b/platform/mdm9x15/gpio.c
@@ -0,0 +1,73 @@
+/* Copyright (c) 2011, 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 Forum, Inc. 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 <debug.h>
+#include <reg.h>
+#include <platform/iomap.h>
+#include <platform/gpio.h>
+#include <gsbi.h>
+
+void gpio_tlmm_config(uint32_t gpio, uint8_t func,
+                      uint8_t dir, uint8_t pull,
+                      uint8_t drvstr, uint32_t enable)
+{
+    unsigned int val = 0;
+    val |= pull;
+    val |= func << 2;
+    val |= drvstr << 6;
+    val |= enable << 9;
+    unsigned int *addr = (unsigned int *)GPIO_CONFIG_ADDR(gpio);
+    writel(val, addr);
+    return;
+}
+
+void gpio_set(uint32_t gpio, uint32_t dir)
+{
+    unsigned int *addr = (unsigned int *)GPIO_IN_OUT_ADDR(gpio);
+    writel(dir, addr);
+    return;
+}
+
+/* Configure gpio for uart - based on gsbi id */
+void gpio_config_uart_dm(uint8_t id)
+{
+	switch (id)
+	{
+	case GSBI_ID_4:
+		/* Enable GSBI4 through gpio */
+		/* configure rx gpio -- gsbi4(2) */
+		gpio_tlmm_config(14, 1, GPIO_INPUT, GPIO_NO_PULL,
+						GPIO_8MA, GPIO_DISABLE);
+		/* configure tx gpio -- gsbi4(3) */
+		gpio_tlmm_config(15, 1, GPIO_OUTPUT, GPIO_NO_PULL,
+						GPIO_8MA, GPIO_DISABLE);
+		break;
+	default:
+		ASSERT(0);
+	}
+}
diff --git a/platform/mdm9x15/include/platform/clock.h b/platform/mdm9x15/include/platform/clock.h
new file mode 100644
index 0000000..4ab0dca
--- /dev/null
+++ b/platform/mdm9x15/include/platform/clock.h
@@ -0,0 +1,50 @@
+/*
+ * * Copyright (c) 2011, 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 Forum, Inc. 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.
+ */
+#ifndef __PLATFORM_MDM9615_CLOCK_H
+#define __PLATFORM_MDM9615_CLOCK_H
+
+/* NS/MD value for USB XCVR */
+#define USB_XCVR_CLK_NS        0x00E400C3
+#define USB_XCVR_CLK_MD        0x000500DF
+
+/* NS/MD value for UART */
+/* Target is 1.8 MHz with cxo source */
+#define UART_DM_CLK_NS_115200  0xFFEC0040
+#define UART_DM_CLK_MD_115200  0x0002FFEA
+
+#define UART_DM_CLK_RX_TX_BIT_RATE 0xFF
+
+#define SC0_U_BRANCH_ENA_VOTE            0x903080
+#define SC0_U_BRANCH_ENA_VOTE_ADM0       2
+#define SC0_U_BRANCH_ENA_VOTE_ADM0_PBUS  3
+
+void hsusb_clock_init(void);
+void clock_config_uart_dm(uint8_t id);
+
+#endif
diff --git a/platform/mdm9x15/include/platform/gpio.h b/platform/mdm9x15/include/platform/gpio.h
new file mode 100644
index 0000000..7d7ec92
--- /dev/null
+++ b/platform/mdm9x15/include/platform/gpio.h
@@ -0,0 +1,58 @@
+/* Copyright (c) 2011, 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 Forum, Inc. 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.
+ */
+
+#ifndef __PLATFORM_MDM9615_GPIO_H
+#define __PLATFORM_MDM9615_GPIO_H
+
+/* GPIO TLMM: Direction */
+#define GPIO_INPUT      0
+#define GPIO_OUTPUT     1
+
+/* GPIO TLMM: Pullup/Pulldown */
+#define GPIO_NO_PULL    0
+#define GPIO_PULL_DOWN  1
+#define GPIO_KEEPER     2
+#define GPIO_PULL_UP    3
+
+/* GPIO TLMM: Drive Strength */
+#define GPIO_2MA        0
+#define GPIO_4MA        1
+#define GPIO_6MA        2
+#define GPIO_8MA        3
+#define GPIO_10MA       4
+#define GPIO_12MA       5
+#define GPIO_14MA       6
+#define GPIO_16MA       7
+
+/* GPIO TLMM: Status */
+#define GPIO_ENABLE     0
+#define GPIO_DISABLE    1
+
+void gpio_config_uart_dm(uint8_t id);
+
+#endif
diff --git a/platform/mdm9x15/include/platform/iomap.h b/platform/mdm9x15/include/platform/iomap.h
new file mode 100644
index 0000000..b19e036
--- /dev/null
+++ b/platform/mdm9x15/include/platform/iomap.h
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2008, Google Inc.
+ * All rights reserved.
+ *
+ * Copyright (c) 2011, 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 Google, Inc. 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 AND FITNESS
+ * FOR A PARTICULAR PURPOSE 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.
+ */
+
+#ifndef _PLATFORM_MDM9615_IOMAP_H_
+#define _PLATFORM_MDM9615_IOMAP_H_
+
+#define GSBI_BASE(id)         ((id) <= 7 ? (0x16000000 + (((id)-1) << 20)) : \
+                                           (0x1A000000 + (((id)-8) << 20)))
+#define GSBI_UART_DM_BASE(id) (GSBI_BASE(id) + 0x40000)
+
+#define TLMM_BASE_ADDR      0x00800000
+#define GPIO_CONFIG_ADDR(x) (TLMM_BASE_ADDR + 0x1000 + (x)*0x10)
+#define GPIO_IN_OUT_ADDR(x) (TLMM_BASE_ADDR + 0x1004 + (x)*0x10)
+
+/* QGIC2 */
+#define MSM_GIC_DIST_BASE   0x02000000
+#define MSM_GIC_CPU_BASE    0x02002000
+
+#define APCS_GLBSECURE_BASE 0x02010000
+#define APCS_GLB_REG(x)     (APCS_GLBSECURE_BASE + (x))
+#define APCS_GLB_QGIC_CFG   APCS_GLB_REG(0x38)
+
+#define MSM_TMR_BASE   0x0200A000
+#define TMR_REG(off)   (MSM_TMR_BASE + (off))
+
+#define MSM_GPT_BASE   TMR_REG(0x4)
+#define GPT_REG(off)   (MSM_GPT_BASE + (off))
+
+#define GPT_MATCH_VAL     GPT_REG(0x0000)
+#define GPT_COUNT_VAL     GPT_REG(0x0004)
+#define GPT_ENABLE        GPT_REG(0x0008)
+#define GPT_CLEAR         GPT_REG(0x000C)
+#define DGT_MATCH_VAL     TMR_REG(0x0024)
+#define DGT_COUNT_VAL     TMR_REG(0x0028)
+#define DGT_ENABLE        TMR_REG(0x002C)
+#define DGT_CLEAR         TMR_REG(0x0030)
+/* TMR_STS - status of SCSS timers */
+#define SPSS_TIMER_STATUS TMR_REG(0x0088)
+
+#define MSM_USB_BASE      0x12500000
+
+#define CLK_CTL_BASE      0x00900000
+#define USB_HS1_HCLK_CTL        (CLK_CTL_BASE + 0x2900)
+#define USB_HS1_XCVR_FS_CLK_MD  (CLK_CTL_BASE + 0x2908)
+#define USB_HS1_XCVR_FS_CLK_NS  (CLK_CTL_BASE + 0x290C)
+#define USB_HS1_SYSTEM_CLK_NS   (CLK_CTL_BASE + 0x36A4)
+#define USB_HS1_SYSTEM_CLK_MD   (CLK_CTL_BASE + 0x36A0)
+#define GSBIn_HCLK_CTL(n)       (CLK_CTL_BASE + 0x29C0 + (32 * ((n) - 1)))
+#define GSBIn_UART_APPS_MD(n)   (CLK_CTL_BASE + 0x29D0 + (32 * ((n) - 1)))
+#define GSBIn_UART_APPS_NS(n)   (CLK_CTL_BASE + 0x29D4 + (32 * ((n) - 1)))
+#define MSM_BOOT_PLL8_STATUS    (CLK_CTL_BASE + 0x3158)
+#define MSM_BOOT_PLL_ENABLE_SC0 (CLK_CTL_BASE + 0x34C0)
+
+#define MSM_SHARED_BASE   0x40000000
+
+#endif
diff --git a/platform/mdm9x15/include/platform/irqs.h b/platform/mdm9x15/include/platform/irqs.h
new file mode 100644
index 0000000..32230f7
--- /dev/null
+++ b/platform/mdm9x15/include/platform/irqs.h
@@ -0,0 +1,62 @@
+/* Copyright (c) 2009-2011, 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.
+ *
+ */
+
+#ifndef __IRQS_9615_H
+#define __IRQS_9615_H
+
+/* MSM ACPU Interrupt Numbers */
+
+/* 0-15:  STI/SGI (software triggered/generated interrupts)
+ * 16-31: PPI (private peripheral interrupts)
+ * 32+:   SPI (shared peripheral interrupts)
+ */
+
+#define GIC_PPI_START 16
+#define GIC_SPI_START 32
+
+#define INT_DEBUG_TIMER_EXP     (GIC_PPI_START + 1)
+
+#define USB1_HS_BAM_IRQ         (GIC_SPI_START + 94)
+#define USB1_HS_IRQ             (GIC_SPI_START + 100)
+#define USB2_IRQ                (GIC_SPI_START + 141)
+#define USB1_IRQ                (GIC_SPI_START + 142)
+
+#define GSBI_QUP_IRQ(id)       ((id) <= 8 ? (GIC_SPI_START + 145 + 2*((id))) : \
+                                            (GIC_SPI_START + 187 + 2*((id)-8)))
+
+
+/* Retrofit universal macro names */
+#define INT_USB_HS                  USB1_HS_IRQ
+
+#define NR_MSM_IRQS                 256
+#define NR_GPIO_IRQS                173
+#define NR_BOARD_IRQS               0
+
+#define NR_IRQS (NR_MSM_IRQS + NR_GPIO_IRQS + NR_BOARD_IRQS)
+
+#endif /* __IRQS_9615_H */
diff --git a/platform/mdm9x15/platform.c b/platform/mdm9x15/platform.c
new file mode 100644
index 0000000..99e1ad4
--- /dev/null
+++ b/platform/mdm9x15/platform.c
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2008, Google Inc.
+ * All rights reserved.
+ *
+ * Copyright (c) 2009-2011, 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 Google, Inc. 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 AND FITNESS
+ * FOR A PARTICULAR PURPOSE 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 <reg.h>
+#include <debug.h>
+#include <kernel/thread.h>
+#include <platform/debug.h>
+#include <platform/iomap.h>
+#include <smem.h>
+#include <qgic.h>
+
+static uint32_t ticks_per_sec = 0;
+
+extern void platform_uninit_timer(void);
+
+void platform_init_timer();
+
+void platform_early_init(void)
+{
+	uint8_t cfg_bid = 0x1;
+	uint8_t cfg_pid = 0x1;
+
+	uart_init(target_uart_gsbi());
+	/* Timers - QGIC Config */
+	writel((cfg_bid << 7 | cfg_pid << 10), APCS_GLB_QGIC_CFG);
+	qgic_init();
+	platform_init_timer();
+}
+
+void platform_init(void)
+{
+	dprintf(INFO, "platform_init()\n");
+	acpu_clock_init();
+}
+
+void platform_uninit(void)
+{
+	platform_uninit_timer();
+}
+
+/* Initialize DGT timer */
+void platform_init_timer(void)
+{
+	/* disable timer */
+	writel(0, DGT_ENABLE);
+
+	ticks_per_sec = 19200000; /* Uses CXO (19.2 MHz) */
+}
+
+/* Returns timer ticks per sec */
+uint32_t platform_tick_rate(void)
+{
+	return ticks_per_sec;
+}
diff --git a/platform/mdm9x15/rules.mk b/platform/mdm9x15/rules.mk
new file mode 100644
index 0000000..1990d1b
--- /dev/null
+++ b/platform/mdm9x15/rules.mk
@@ -0,0 +1,20 @@
+LOCAL_DIR := $(GET_LOCAL_DIR)
+
+ARCH    := arm
+# Cann't use cortex-a5 as its not supported by gcc 4.4.0
+ARM_CPU := cortex-a8
+CPU     := generic
+
+DEFINES += ARM_CPU_CORE_A5
+
+INCLUDES += -I$(LOCAL_DIR)/include -I$(LK_TOP_DIR)/platform/msm_shared/include
+
+OBJS += \
+	$(LOCAL_DIR)/platform.o \
+	$(LOCAL_DIR)/acpuclock.o \
+	$(LOCAL_DIR)/gpio.o \
+
+LINKER_SCRIPT += $(BUILDDIR)/system-onesegment.ld
+
+include platform/msm_shared/rules.mk
+
diff --git a/platform/msm_shared/dmov.h b/platform/msm_shared/dmov.h
index 76ebf56..0f8008f 100644
--- a/platform/msm_shared/dmov.h
+++ b/platform/msm_shared/dmov.h
@@ -32,22 +32,36 @@
 #ifdef PLATFORM_MSM7X30
 #define MSM_DMOV_BASE 0xAC400000
 #else
+#ifdef PLATFORM_MDM9X15 //TODO: Move to IOMAP
+#define MSM_DMOV_BASE 0x18300000
+#else
 #define MSM_DMOV_BASE 0xA9700000
 #endif
+#endif
 
+
+#ifdef PLATFORM_MDM9X15
+#define DMOV_SD0(off, ch) (MSM_DMOV_BASE + 0x00000 + (off) + ((ch) << 2))
+#define DMOV_SD1(off, ch) (MSM_DMOV_BASE + 0x20800 + (off) + ((ch) << 2))
+#define DMOV_SD2(off, ch) (MSM_DMOV_BASE + 0x41000 + (off) + ((ch) << 2))
+#define DMOV_SD3(off, ch) (MSM_DMOV_BASE + 0x81800 + (off) + ((ch) << 2))
+#else
 /* see 80-VA736-2 C pp 415-439 */
-
 #define DMOV_SD0(off, ch) (MSM_DMOV_BASE + 0x0000 + (off) + ((ch) << 2))
 #define DMOV_SD1(off, ch) (MSM_DMOV_BASE + 0x0400 + (off) + ((ch) << 2))
 #define DMOV_SD2(off, ch) (MSM_DMOV_BASE + 0x0800 + (off) + ((ch) << 2))
 #define DMOV_SD3(off, ch) (MSM_DMOV_BASE + 0x0C00 + (off) + ((ch) << 2))
+#endif
 
 #ifdef PLATFORM_MSM7X30
 #define DMOV_SDn DMOV_SD2
 #else
+#ifdef PLATFORM_MDM9X15
+#define DMOV_SDn DMOV_SD1
+#else
 #define DMOV_SDn DMOV_SD3
 #endif
-
+#endif
 
 
 /* only security domain 3 is available to the ARM11
@@ -92,9 +106,15 @@
 
 /* channel assignments - from qc/dmov_7500.h */
 
+#ifdef PLATFORM_MDM9X15
+#define DMOV_NAND_CHAN        3
+#define DMOV_NAND_CRCI_CMD    15
+#define DMOV_NAND_CRCI_DATA   3
+#else
 #define DMOV_NAND_CHAN        7
 #define DMOV_NAND_CRCI_CMD    5
 #define DMOV_NAND_CRCI_DATA   4
+#endif
 
 #define DMOV_SDC1_CHAN        8
 #define DMOV_SDC1_CRCI        6
diff --git a/platform/msm_shared/include/nand.h b/platform/msm_shared/include/nand.h
index e8df423..b3ae1a1 100644
--- a/platform/msm_shared/include/nand.h
+++ b/platform/msm_shared/include/nand.h
@@ -31,6 +31,8 @@
 
 #ifdef PLATFORM_MSM7X30
 #define MSM_NAND_BASE 0xA0200000
+#elif PLATFORM_MDM9X15
+#define MSM_NAND_BASE 0x1B400000
 #else
 #define MSM_NAND_BASE 0xA0A00000
 #endif
diff --git a/platform/msm_shared/rules.mk b/platform/msm_shared/rules.mk
index f2edb0e..55a3ed8 100644
--- a/platform/msm_shared/rules.mk
+++ b/platform/msm_shared/rules.mk
@@ -75,3 +75,8 @@
 			$(LOCAL_DIR)/certificate.o \
 			$(LOCAL_DIR)/image_verify.o
 endif
+
+ifeq ($(PLATFORM),mdm9x15)
+	OBJS += $(LOCAL_DIR)/qgic.o \
+			$(LOCAL_DIR)/uart_dm.o
+endif
diff --git a/project/mdm9615.mk b/project/mdm9615.mk
new file mode 100644
index 0000000..da0b34e
--- /dev/null
+++ b/project/mdm9615.mk
@@ -0,0 +1,11 @@
+# top level project rules for the mdm9615 project
+#
+LOCAL_DIR := $(GET_LOCAL_DIR)
+
+TARGET := mdm9615
+
+MODULES += app/aboot
+
+#DEFINES += WITH_DEBUG_DCC=1
+DEFINES += WITH_DEBUG_UART=1
+#DEFINES += WITH_DEBUG_FBCON=1
diff --git a/project/mdm9615_nandwrite.mk b/project/mdm9615_nandwrite.mk
new file mode 100644
index 0000000..98a65d5
--- /dev/null
+++ b/project/mdm9615_nandwrite.mk
@@ -0,0 +1,15 @@
+# top level project rules for the mdm9615_nandwrite project
+#
+LOCAL_DIR := $(GET_LOCAL_DIR)
+
+TARGET := mdm9615
+
+MODULES += app/nandwrite
+
+#DEFINES += WITH_DEBUG_JTAG=1
+
+DEFINES += ENABLE_NANDWRITE=1
+DEFINES += WITH_DEBUG_DCC=1
+#DEFINES += WITH_DEBUG_UART=1
+#DEFINES += WITH_DEBUG_FBCON=1
+
diff --git a/target/mdm9615/atags.c b/target/mdm9615/atags.c
new file mode 100644
index 0000000..08e4d59
--- /dev/null
+++ b/target/mdm9615/atags.c
@@ -0,0 +1,73 @@
+/* Copyright (c) 2009-2011, 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.
+ *
+ */
+
+#include <reg.h>
+#include <debug.h>
+#include <smem.h>
+#include <stdint.h>
+
+#define SIZE_1M     (1024 * 1024)
+#define SIZE_8M     (8 * SIZE_1M)
+#define SIZE_10M    (10 * SIZE_1M)
+#define SIZE_512M   (512 * SIZE_1M)
+
+unsigned* target_atag_mem(unsigned* ptr)
+{
+	struct smem_ram_ptable ram_ptable;
+	uint8_t i = 0;
+
+	if (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 == 0x40000000)
+			{
+				ASSERT(ram_ptable.parts[i].size >= SIZE_10M);
+
+				*ptr++ = 4;
+				*ptr++ = 0x54410002;
+				*ptr++ = SIZE_10M;
+				*ptr++ = ram_ptable.parts[i].start + SIZE_8M;
+			}
+		}
+	}
+	else
+	{
+		dprintf(CRITICAL, "ERROR: Unable to read RAM partition\n");
+		ASSERT(0);
+	}
+
+	return ptr;
+}
+
+unsigned target_get_max_flash_size(void)
+{
+	return (SIZE_512M);
+}
diff --git a/target/mdm9615/init.c b/target/mdm9615/init.c
new file mode 100644
index 0000000..ded6aec
--- /dev/null
+++ b/target/mdm9615/init.c
@@ -0,0 +1,196 @@
+/*
+ * Copyright (c) 2009, Google Inc.
+ * All rights reserved.
+ *
+ * Copyright (c) 2009-2011, 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 Google, Inc. 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 AND FITNESS
+ * FOR A PARTICULAR PURPOSE 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 <reg.h>
+#include <debug.h>
+#include <lib/ptable.h>
+#include <dev/flash.h>
+#include <smem.h>
+#include <gsbi.h>
+#include <platform/iomap.h>
+#include <platform.h>
+
+#define MDM9X15_CDP	3675
+#define MDM9X15_MTP	3681
+#define LINUX_MACHTYPE  MDM9X15_CDP
+
+//TODO: Update with partitions needed
+#define VARIABLE_LENGTH		0x10101010
+#define DIFF_START_ADDR		0xF0F0F0F0
+#define NUM_PAGES_PER_BLOCK	0x40
+
+static struct ptable flash_ptable;
+unsigned hw_platform = 0;
+unsigned target_msm_id = 0;
+
+static const uint8_t uart_gsbi_id = GSBI_ID_4;
+
+/* for these partitions, start will be offset by either what we get from
+ * smem, or from the above offset if smem is not useful. Also, we should
+ * probably have smem_ptable code populate our flash_ptable.
+ *
+ * When smem provides us with a full partition table, we can get rid of
+ * this altogether.
+ *
+ */
+static struct ptentry board_part_list_default[] = {
+	{
+		.start = 0,
+		.length = 10 /* In MB */,
+		.name = "boot",
+	},
+};
+static int num_parts = sizeof(board_part_list_default)/sizeof(struct ptentry);
+
+void smem_ptable_init(void);
+unsigned smem_get_apps_flash_start(void);
+extern void reboot(unsigned reboot_reason);
+
+void target_init(void)
+{
+	unsigned offset;
+	struct flash_info *flash_info;
+	struct ptentry *board_part_list;
+	unsigned total_num_of_blocks;
+	unsigned next_ptr_start_adr = 0;
+	unsigned blocks_per_1MB = 8; /* Default value of 2k page size on 256MB flash drive*/
+	int i;
+
+	dprintf(INFO, "target_init()\n");
+	ptable_init(&flash_ptable);
+	smem_ptable_init();
+
+	flash_init();
+	flash_info = flash_get_info();
+	ASSERT(flash_info);
+
+	offset = smem_get_apps_flash_start();
+	if (offset == 0xffffffff)
+			while(1);
+
+	total_num_of_blocks = flash_info->num_blocks;
+	blocks_per_1MB = (1 << 20) / (flash_info->block_size);
+
+	//TODO: Remove this if no need for other board types
+	board_part_list = board_part_list_default;
+
+	for (i = 0; i < num_parts; i++) {
+		struct ptentry *ptn = &board_part_list[i];
+		unsigned len = ((ptn->length) * blocks_per_1MB);
+
+		if(ptn->start != 0)
+				ASSERT(ptn->start == DIFF_START_ADDR);
+
+		ptn->start = next_ptr_start_adr;
+
+		if(ptn->length == VARIABLE_LENGTH)
+		{
+			unsigned length_for_prt = 0;
+			unsigned j;
+			for (j = i+1; j < num_parts; j++)
+			{
+					struct ptentry *temp_ptn = &board_part_list[j];
+					ASSERT(temp_ptn->length != VARIABLE_LENGTH);
+					length_for_prt += ((temp_ptn->length) * blocks_per_1MB);
+			}
+				len = (total_num_of_blocks - 1) - (offset + ptn->start + length_for_prt);
+			ASSERT(len >= 0);
+		}
+		next_ptr_start_adr = ptn->start + len;
+		ptable_add(&flash_ptable, ptn->name, offset + ptn->start,
+			   len, ptn->flags, TYPE_APPS_PARTITION, PERM_WRITEABLE);
+	}
+
+	smem_add_modem_partitions(&flash_ptable);
+
+	ptable_dump(&flash_ptable);
+	flash_set_ptable(&flash_ptable);
+}
+
+void board_info(void)
+{
+	struct smem_board_info_v4 board_info_v4;
+	unsigned int board_info_len = 0;
+	unsigned smem_status;
+	unsigned format = 0;
+	unsigned id = 0;
+
+	if (hw_platform && target_msm_id)
+		return;
+
+	hw_platform = MDM9X15_CDP;
+	target_msm_id = MDM9600;
+
+	smem_status = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION,
+						&format, sizeof(format), 0);
+	if(!smem_status)
+	{
+		if(format == 4)
+		{
+			board_info_len = sizeof(board_info_v4);
+			smem_status = smem_read_alloc_entry(
+						SMEM_BOARD_INFO_LOCATION,
+						&board_info_v4, board_info_len);
+			if(!smem_status)
+			{
+				id = board_info_v4.board_info_v3.hw_platform;
+				target_msm_id =
+					board_info_v4.board_info_v3.msm_id;
+			}
+		}
+	}
+	return;
+}
+
+unsigned board_machtype(void)
+{
+	board_info();
+	return hw_platform;
+}
+
+void reboot_device(unsigned reboot_reason)
+{
+	//TODO: Implement
+	return;
+}
+
+uint8_t target_uart_gsbi(void)
+{
+	return uart_gsbi_id;
+}
+
+uint32_t usb_cable_status(void) {
+	//TODO: Implement
+	uint32_t ret = 1;
+	return ret;
+}
diff --git a/target/mdm9615/rules.mk b/target/mdm9615/rules.mk
new file mode 100644
index 0000000..facbbd6
--- /dev/null
+++ b/target/mdm9615/rules.mk
@@ -0,0 +1,30 @@
+LOCAL_DIR := $(GET_LOCAL_DIR)
+
+INCLUDES += -I$(LOCAL_DIR)/include -I$(LK_TOP_DIR)/platform/msm_shared
+
+PLATFORM := mdm9x15
+
+MEMBASE := 0x41200000
+MEMSIZE := 0x00100000 # 1MB
+
+BASE_ADDR        := 0x40800000
+SCRATCH_ADDR     := BASE_ADDR+0x04000000
+
+DEFINES += NO_KEYPAD_DRIVER=1
+
+MODULES += \
+	dev/keys \
+	lib/ptable
+
+DEFINES += \
+	SDRAM_SIZE=$(MEMSIZE) \
+	MEMBASE=$(MEMBASE) \
+	BASE_ADDR=$(BASE_ADDR) \
+	TAGS_ADDR=$(TAGS_ADDR) \
+	KERNEL_ADDR=$(KERNEL_ADDR) \
+	RAMDISK_ADDR=$(RAMDISK_ADDR) \
+	SCRATCH_ADDR=$(SCRATCH_ADDR)
+
+OBJS += \
+	$(LOCAL_DIR)/init.o \
+	$(LOCAL_DIR)/atags.o
diff --git a/target/mdm9615/tools/makefile b/target/mdm9615/tools/makefile
new file mode 100644
index 0000000..7da7c6d
--- /dev/null
+++ b/target/mdm9615/tools/makefile
@@ -0,0 +1,44 @@
+#Makefile to generate appsboot.mbn
+
+ifeq ($(BOOTLOADER_OUT),.)
+APPSBOOTHEADER_DIR  := $(BUILDDIR)
+else
+APPSBOOTHEADER_DIR  := $(BOOTLOADER_OUT)/../../
+endif
+
+SRC_DIR  := target/$(TARGET)/tools
+COMPILER := gcc
+
+ifeq ($(EMMC_BOOT), 1)
+  APPSBOOTHDR_FILES := EMMCBOOT.MBN
+else
+  ifeq ($(BUILD_NANDWRITE), 1)
+    APPSBOOTHDR_FILES :=
+  else
+    APPSBOOTHDR_FILES := appsboot.mbn
+  endif
+endif
+
+APPSBOOTHEADER: $(APPSBOOTHDR_FILES)
+
+
+appsboot.mbn: appsboothd.mbn $(OUTBIN)
+	cp $(OUTBIN) $(APPSBOOTHEADER_DIR)/appsboot.raw
+	cat $(APPSBOOTHEADER_DIR)/appsboothd.mbn $(OUTBIN) > $(APPSBOOTHEADER_DIR)/appsboot.mbn
+	rm -f $(APPSBOOTHEADER_DIR)/appsboothd.mbn
+
+appsboothd.mbn: mkheader $(OUTBIN)
+	$(SRC_DIR)/mkheader $(OUTBIN) $(APPSBOOTHEADER_DIR)/appsboothd.mbn
+
+EMMCBOOT.MBN: emmc_appsboothd.mbn $(OUTBIN)
+	cp $(OUTBIN) $(APPSBOOTHEADER_DIR)/emmc_appsboot.raw
+	cat $(APPSBOOTHEADER_DIR)/emmc_appsboothd.mbn $(OUTBIN) > $(APPSBOOTHEADER_DIR)/EMMCBOOT.MBN
+	cat $(APPSBOOTHEADER_DIR)/emmc_appsboothd.mbn $(OUTBIN) > $(APPSBOOTHEADER_DIR)/emmc_appsboot.mbn
+	rm -f $(APPSBOOTHEADER_DIR)/emmc_appsboothd.mbn
+
+emmc_appsboothd.mbn: mkheader $(OUTBIN)
+	$(SRC_DIR)/mkheader $(OUTBIN) $(APPSBOOTHEADER_DIR)/emmc_appsboothd.mbn
+
+mkheader: $(SRC_DIR)/mkheader.c
+	${COMPILER} -DMEMBASE=$(MEMBASE) $(SRC_DIR)/mkheader.c -o $(SRC_DIR)/mkheader
+	cp $(SRC_DIR)/mkheader $(APPSBOOTHEADER_DIR)/mkheader
diff --git a/target/mdm9615/tools/mkheader.c b/target/mdm9615/tools/mkheader.c
new file mode 100644
index 0000000..cd11810
--- /dev/null
+++ b/target/mdm9615/tools/mkheader.c
@@ -0,0 +1,344 @@
+/*
+ * Copyright (c) 2007, Google Inc.
+ * All rights reserved.
+ *
+ * Copyright (c) 2009-2011, 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 Google, Inc. 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 AND FITNESS
+ * FOR A PARTICULAR PURPOSE 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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+
+#include <sys/stat.h>
+
+int print_usage(){
+	fprintf(stderr,"usage: mkheader <bin> <hdr> <none|unified-boot>\n");
+	fprintf(stderr,"       mkheader <bin> <hdr> <unsecure-boot>"
+		       " <outbin>\n");
+	fprintf(stderr,"       mkheader <bin> <hdr> <secure-boot> <outbin>"
+		       " <maxsize>\n");
+	fprintf(stderr,"       mkheader <bin> <hdr> <secure-boot> <outbin>"
+		       " <maxsize> <certchain> <files...>\n\n");
+	fprintf(stderr,"bin:               Input raw appsbl binary\n");
+	fprintf(stderr,"hdr:               Output of appsbl header location\n");
+	fprintf(stderr,"outbin:            Output of the signed or unsigned"
+		       " apps boot location\n");
+	fprintf(stderr,"maxsize:           Maximum size for certificate"
+		       " chain\n");
+	fprintf(stderr,"certchain:         Output of the certchain location\n");
+	fprintf(stderr,"files:             Input format <bin signature>"
+		       " <certifcate file(s) for certificate chain>...\n");
+	fprintf(stderr,"certificate chain: Files will be concatenated in order"
+		       " to create the certificate chain\n\n");
+	return -1;
+}
+
+int cat(FILE * in, FILE * out, unsigned size, unsigned buff_size){
+	unsigned bytes_left = size;
+	char buf[buff_size];
+	int ret = 0;
+
+	while(bytes_left){
+		fread(buf, sizeof(char), buff_size, in);
+		if(!feof(in)){
+			bytes_left -= fwrite(buf, sizeof(char), buff_size, out);
+		}
+		else
+			bytes_left = 0;
+	}
+	ret = ferror(in) | ferror(out);
+	if(ret)
+		fprintf(stderr, "ERROR: Occured during file concatenation\n");
+	return ret;
+}
+
+int main(int argc, char *argv[])
+{
+	struct stat s;
+	unsigned size, base;
+	int unified_boot = 0;
+	unsigned unified_boot_magic[20];
+	unsigned non_unified_boot_magic[10];
+	unsigned magic_len = 0;
+	unsigned *magic;
+	unsigned cert_chain_size = 0;
+	unsigned signature_size = 0;
+	int secure_boot = 0;
+	int fd;
+
+	if(argc < 3) {
+		return print_usage();
+	}
+
+	if(argc == 4) {
+		if(!strcmp("unified-boot",argv[3])) {
+			unified_boot = 1;
+		}
+		else if(!strcmp("secure-boot",argv[3])){
+			fprintf(stderr,
+				"ERROR: Missing arguments: [outbin maxsize] |"
+				" [outbin, maxsize, certchain,"
+				" signature + certifcate(s)]\n");
+			return print_usage();
+		}
+		else if(!strcmp("unsecure-boot",argv[3])){
+			fprintf(stderr,"ERROR: Missing arguments:"
+				       " outbin directory\n");
+			return print_usage();
+		}
+	}
+
+	if(argc > 4) {
+		if(!strcmp("secure-boot",argv[3])) {
+			if(argc < 9 && argc != 6){
+				fprintf(stderr,
+					"ERROR: Missing argument(s):"
+					" [outbin maxsize] | [outbin, maxsize,"
+					" certchain,"
+					" signature + certifcate(s)]\n");
+				return print_usage();
+			}
+			secure_boot = 1;
+			signature_size = 256; //Support SHA 256
+			cert_chain_size = atoi(argv[5]);
+		}
+	}
+
+	if(stat(argv[1], &s)) {
+		perror("cannot stat binary");
+		return -1;
+	}
+
+	if(unified_boot) {
+		magic = unified_boot_magic;
+		magic_len = sizeof(unified_boot_magic);
+	}
+	else {
+		magic = non_unified_boot_magic;
+		magic_len = sizeof(non_unified_boot_magic);
+	}
+
+	size = s.st_size;
+#if MEMBASE
+	base = MEMBASE;
+#else
+	base = 0;
+#endif
+
+	printf("Image Destination Pointer: 0x%x\n", base);
+
+	magic[0] = 0x00000005; /* appsbl */
+	magic[1] = 0x00000003; //Flash_partition_version /* nand */
+	magic[2] = 0x00000000; //image source pointer
+	magic[3] = base;       //image destination pointer
+	magic[4] = size + cert_chain_size + signature_size; //image size
+	magic[5] = size;       //code size
+	magic[6] = base + size;
+	magic[7] = signature_size;
+	magic[8] = size + base + signature_size;
+	magic[9] = cert_chain_size;
+
+	if(unified_boot == 1)
+	{
+		magic[10] = 0x33836685;	/* cookie magic number */
+		magic[11] = 0x00000001;	/* cookie version */
+		magic[12] = 0x00000002;	/* file formats */
+		magic[13] = 0x00000000;
+		magic[14] = 0x00000000;	/* not setting size for boot.img */
+		magic[15] = 0x00000000;
+		magic[16] = 0x00000000;
+		magic[17] = 0x00000000;
+		magic[18] = 0x00000000;
+		magic[19] = 0x00000000;
+	}
+
+	fd = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, 0644);
+	if(fd < 0) {
+		perror("cannot open header for writing");
+		return -1;
+	}
+	if(write(fd, magic, magic_len) != magic_len) {
+		perror("cannot write header");
+		close(fd);
+		unlink(argv[2]);
+		return -1;
+	}
+	close(fd);
+
+	if(secure_boot && argc > 6){
+		FILE * input_file;
+		FILE * output_file;
+		unsigned buff_size = 1;
+		char buf[buff_size];
+		unsigned bytes_left;
+		unsigned current_cert_chain_size = 0;
+		int padding_size = 0;
+		int i;
+
+		if((output_file = fopen(argv[6], "wb"))==NULL){
+			perror("ERROR: Occured during fopen");
+			return -1;
+		}
+		printf("Certificate Chain Output File: %s\n", argv[6]);
+
+		for(i = 8; i < argc; i++){
+			if((input_file = fopen(argv[i], "rb"))==NULL){
+				perror("ERROR: Occured during fopen");
+				return -1;
+			}
+			stat(argv[i], &s);
+			bytes_left = s.st_size;
+			current_cert_chain_size += bytes_left;
+			if(cat(input_file, output_file, bytes_left, buff_size))
+				return -1;
+			fclose(input_file);
+		}
+
+		//Pad certifcate chain to the max expected size from input
+		memset(buf, 0xFF, sizeof(buf));
+		padding_size = cert_chain_size - current_cert_chain_size;
+
+		if(padding_size <0){
+			fprintf(stderr, "ERROR: Input certificate chain"
+					" (Size=%d) is larger than the maximum"
+					" specified (Size=%d)\n",
+				current_cert_chain_size, cert_chain_size);
+			return -1;
+		}
+
+		bytes_left = (padding_size > 0) ? padding_size : 0;
+		while(bytes_left){
+			if(!ferror(output_file))
+				bytes_left -= fwrite(buf,
+						     sizeof(buf),
+						     buff_size,
+						     output_file);
+			else{
+				fprintf(stderr, "ERROR: Occured during"
+						" certifcate chain padding\n");
+				return -1;
+			}
+		}
+		fclose(output_file);
+
+		/* Concat and combine to signed image.
+		 * Format [HDR][RAW APPSBOOT][PADDED CERT CHAIN]
+		 */
+		if((output_file = fopen(argv[4], "wb"))==NULL){
+			perror("ERROR: Occured during fopen");
+			return -1;
+		}
+		printf("Image Output File: %s\n", argv[4]);
+
+		//Header
+		if((input_file = fopen(argv[2], "rb"))==NULL){
+			perror("ERROR: Occured during fopen");
+			return -1;
+		}
+		stat(argv[2], &s);
+		if(cat(input_file, output_file, s.st_size, buff_size))
+			return -1;
+		fclose(input_file);
+
+		//Raw Appsbl
+		if((input_file = fopen(argv[1], "rb"))==NULL){
+			perror("ERROR: Occured during fopen");
+			return -1;
+		}
+		stat(argv[1], &s);
+		if(cat(input_file, output_file, s.st_size, buff_size))
+			return -1;
+		fclose(input_file);
+
+		//Signature
+		if((input_file = fopen(argv[7], "rb"))==NULL){
+			perror("ERROR: Occured during fopen");
+			return -1;
+		}
+		stat(argv[7], &s);
+		if(cat(input_file, output_file, s.st_size, buff_size))
+			return -1;
+		fclose(input_file);
+
+		//Certifcate Chain
+		if((input_file = fopen(argv[6], "rb"))==NULL){
+			perror("ERROR: Occured during fopen");
+			return -1;
+		}
+		if(cat(input_file, output_file,
+		       (current_cert_chain_size + padding_size), buff_size))
+			return -1;
+		fclose(input_file);
+
+		fclose(output_file);
+
+	}
+	else if(argc == 5 || argc == 6){
+		FILE * input_file;
+		FILE * output_file;
+		unsigned buff_size = 1;
+		char buf[buff_size];
+
+		/* Concat and combine to unsigned image.
+		 * Format [HDR][RAW APPSBOOT]
+		 */
+		if((output_file = fopen(argv[4], "wb"))==NULL){
+			perror("ERROR: Occured during fopen");
+			return -1;
+		}
+		printf("Image Output File: %s\n", argv[4]);
+
+		//Header
+		if((input_file = fopen(argv[2], "rb"))==NULL){
+			perror("ERROR: Occured during fopen");
+			return -1;
+		}
+		stat(argv[2], &s);
+		if(cat(input_file, output_file, s.st_size, buff_size))
+			return -1;
+		fclose(input_file);
+
+		//Raw Appsbl
+		if((input_file = fopen(argv[1], "rb"))==NULL){
+			perror("ERROR: Occured during fopen");
+			return -1;
+		}
+		stat(argv[1], &s);
+		if(cat(input_file, output_file, s.st_size, buff_size))
+			return -1;
+		fclose(input_file);
+		fclose(output_file);
+	}
+
+	printf("Done execution\n");
+
+	return 0;
+}