apq8064: Initial support
Change-Id: I98dc5d4d3e3270e1896375a31a3fbe1abbc10773
diff --git a/app/aboot/aboot.c b/app/aboot/aboot.c
index dad3cb6..264adbe 100644
--- a/app/aboot/aboot.c
+++ b/app/aboot/aboot.c
@@ -491,7 +491,7 @@
fastboot_okay("");
udc_stop();
- boot_linux((void*) hdr.kernel_addr, (void*) TAGS_ADDR,
+ boot_linux((void*) hdr.kernel_addr, (void*) hdr.tags_addr,
(const char*) hdr.cmdline, board_machtype(),
(void*) hdr.ramdisk_addr, hdr.ramdisk_size);
}
diff --git a/platform/apq8064/clock.c b/platform/apq8064/clock.c
new file mode 100644
index 0000000..76e50f5
--- /dev/null
+++ b/platform/apq8064/clock.c
@@ -0,0 +1,140 @@
+/*
+ * 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 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 <platform/iomap.h>
+#include <platform/clock.h>
+#include <gsbi.h>
+#include <mmc.h>
+#include <uart_dm.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 */
+ 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 hsusb_clock_init(void)
+{
+ /* Setup XCVR clock */
+ clock_config(USB_XCVR_CLK_NS_VAL,
+ USB_XCVR_CLK_MD_VAL,
+ USB_HS1_XCVR_FS_CLK_NS,
+ USB_HS1_XCVR_FS_CLK_MD);
+}
+
+/* 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_QUP_APPS_NS(id),
+ GSBIn_QUP_APPS_MD(id));
+
+ /* Configure clock selection register for tx and rx rates.
+ * Selecting 115.2k for both RX and TX.
+ */
+ writel(UART_DM_CLK_RX_TX_BIT_RATE, MSM_BOOT_UART_DM_CSR(id));
+
+ /* Enable gsbi_pclk */
+ writel(GSBI_HCLK_CTL_CLK_ENA << GSBI_HCLK_CTL_S, GSBIn_HCLK_CTL(id));
+}
+
+
+/* Intialize MMC clock */
+void clock_init_mmc(uint32_t interface)
+{
+ /* Nothing to be done. */
+}
+
+/* Configure MMC clock */
+void clock_config_mmc(uint32_t interface, uint32_t freq)
+{
+ uint32_t reg = 0;
+
+ switch(freq)
+ {
+ case MMC_CLK_400KHZ:
+ clock_config(SDC_CLK_NS_400KHZ,
+ SDC_CLK_MD_400KHZ,
+ SDC_NS(interface),
+ SDC_MD(interface));
+ break;
+ case MMC_CLK_48MHZ:
+ case MMC_CLK_50MHZ: /* Max supported is 48MHZ */
+ clock_config(SDC_CLK_NS_48MHZ,
+ SDC_CLK_MD_48MHZ,
+ SDC_NS(interface),
+ SDC_MD(interface));
+ break;
+ default:
+ ASSERT(0);
+
+ }
+
+ reg |= MMC_BOOT_MCI_CLK_ENABLE;
+ reg |= MMC_BOOT_MCI_CLK_ENA_FLOW;
+ reg |= MMC_BOOT_MCI_CLK_IN_FEEDBACK;
+ writel( reg, MMC_BOOT_MCI_CLK );
+}
+
diff --git a/platform/apq8064/gpio.c b/platform/apq8064/gpio.c
new file mode 100644
index 0000000..2a10c8d
--- /dev/null
+++ b/platform/apq8064/gpio.c
@@ -0,0 +1,77 @@
+/* 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 <reg.h>
+#include <debug.h>
+#include <gsbi.h>
+#include <platform/iomap.h>
+#include <platform/gpio.h>
+
+void gpio_tlmm_config(uint32_t gpio,
+ uint8_t func,
+ uint8_t dir,
+ uint8_t pull,
+ uint8_t drvstr,
+ uint32_t enable)
+{
+ uint32_t val = 0;
+
+ val |= pull;
+ val |= func << 2;
+ val |= drvstr << 6;
+ val |= enable << 9;
+
+ writel(val, GPIO_CONFIG_ADDR(gpio));
+}
+
+void gpio_set(uint32_t gpio, uint32_t dir)
+{
+ writel(dir, GPIO_IN_OUT_ADDR(gpio));
+}
+
+/* Configure gpio for uart - based on gsbi id */
+void gpio_config_uart_dm(uint8_t id)
+{
+ switch (id)
+ {
+ case GSBI_ID_3:
+
+ /* configure rx gpio */
+ gpio_tlmm_config(15, 1, GPIO_INPUT, GPIO_NO_PULL,
+ GPIO_8MA, GPIO_DISABLE);
+
+ /* configure tx gpio */
+ gpio_tlmm_config(14, 1, GPIO_OUTPUT, GPIO_NO_PULL,
+ GPIO_8MA, GPIO_DISABLE);
+ break;
+
+ default:
+ ASSERT(0);
+ }
+}
+
diff --git a/platform/apq8064/include/platform/clock.h b/platform/apq8064/include/platform/clock.h
new file mode 100644
index 0000000..6267940
--- /dev/null
+++ b/platform/apq8064/include/platform/clock.h
@@ -0,0 +1,49 @@
+/*
+ * * 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_APQ8064_CLOCK_H
+#define __PLATFORM_APQ8064_CLOCK_H
+
+/* NS/MD value for USB XCVR */
+#define USB_XCVR_CLK_NS_VAL 0x00E400C3
+#define USB_XCVR_CLK_MD_VAL 0x000500DF
+
+/* NS/MD value for UART */
+#define UART_DM_CLK_NS_115200 0xFFE40040
+#define UART_DM_CLK_MD_115200 0x0002FFE2
+
+#define UART_DM_CLK_RX_TX_BIT_RATE 0xFF
+
+/* NS/MD value for MMC */
+#define SDC_CLK_NS_400KHZ 0x00440040
+#define SDC_CLK_MD_400KHZ 0x00010043
+
+#define SDC_CLK_NS_48MHZ 0x00FE005B
+#define SDC_CLK_MD_48MHZ 0x000100FD
+
+#endif
diff --git a/platform/apq8064/include/platform/gpio.h b/platform/apq8064/include/platform/gpio.h
new file mode 100644
index 0000000..93d81de
--- /dev/null
+++ b/platform/apq8064/include/platform/gpio.h
@@ -0,0 +1,60 @@
+/* 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_APQ8064_GPIO_H
+#define __PLATFORM_APQ8064_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/apq8064/include/platform/iomap.h b/platform/apq8064/include/platform/iomap.h
new file mode 100644
index 0000000..b86b7ac
--- /dev/null
+++ b/platform/apq8064/include/platform/iomap.h
@@ -0,0 +1,109 @@
+/*
+ * 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_APQ8064_IOMAP_H_
+#define _PLATFORM_APQ8064_IOMAP_H_
+
+#define MSM_IOMAP_BASE 0x00100000
+#define MSM_IOMAP_END 0x28000000
+
+/* Shared memory */
+#define MSM_SHARED_BASE 0x80000000
+#define MSM_SHARED_IMEM_BASE 0x2A03F000
+#define RESTART_REASON_ADDR (MSM_SHARED_IMEM_BASE + 0x65C)
+
+/* Peripherals */
+#define TLMM_BASE_ADDR 0x00800000
+
+/* GPIO */
+#define GPIO_CONFIG_ADDR(x) (TLMM_BASE_ADDR + 0x1000 + (x)*0x10)
+#define GPIO_IN_OUT_ADDR(x) (TLMM_BASE_ADDR + 0x1004 + (x)*0x10)
+
+/* CLK CTL */
+#define CLK_CTL_BASE 0x00900000
+#define SDC_MD(n) (CLK_CTL_BASE + 0x2828 + (32 * ((n) - 1)))
+#define SDC_NS(n) (CLK_CTL_BASE + 0x282C + (32 * ((n) - 1)))
+#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 GSBIn_HCLK_CTL(n) (CLK_CTL_BASE + 0x29C0 + (32 * ((n) - 1)))
+#define GSBIn_HCLK_FS(n) (CLK_CTL_BASE + 0x29C4 + (32 * ((n) - 1)))
+#define GSBIn_QUP_APPS_MD(n) (CLK_CTL_BASE + 0x29C8 + (32 * ((n) - 1)))
+#define GSBIn_QUP_APPS_NS(n) (CLK_CTL_BASE + 0x29CC + (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)
+
+/* GIC */
+#define MSM_GIC_DIST_BASE 0x02000000
+#define MSM_GIC_CPU_BASE 0x02002000
+
+/* TMR */
+#define MSM_TMR_BASE 0x0200A000
+#define MSM_GPT_BASE (MSM_TMR_BASE + 0x04)
+#define MSM_DGT_BASE (MSM_TMR_BASE + 0x24)
+#define MSM_WDT0_RST (MSM_TMR_BASE + 0x38)
+#define MSM_WDT0_EN (MSM_TMR_BASE + 0x40)
+#define MSM_WDT0_BT (MSM_TMR_BASE + 0x4C)
+#define SPSS_TIMER_STATUS (MSM_TMR_BASE + 0x88)
+
+#define GPT_REG(off) (MSM_GPT_BASE + (off))
+#define DGT_REG(off) (MSM_DGT_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 DGT_REG(0x0000)
+#define DGT_COUNT_VAL DGT_REG(0x0004)
+#define DGT_ENABLE DGT_REG(0x0008)
+#define DGT_CLEAR DGT_REG(0x000C)
+#define DGT_CLK_CTL DGT_REG(0x0010)
+
+#define MSM_USB_BASE 0x12500000
+#define MSM_TCSR_BASE 0x1A400000
+#define MSM_TCSR_WDOG_CFG (MSM_TCSR_BASE + 0x30)
+
+/* SDCC */
+#define MSM_SDC1_BASE 0x12400000
+#define MSM_SDC2_BASE 0x12140000
+#define MSM_SDC3_BASE 0x12180000
+#define MSM_SDC4_BASE 0x121C0000
+
+
+/* GSBI/QUP/UART_DM */
+#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 QUP_BASE(id) (GSBI_BASE(id) + 0x80000)
+
+#endif
diff --git a/platform/apq8064/include/platform/irqs.h b/platform/apq8064/include/platform/irqs.h
new file mode 100644
index 0000000..48a8a96
--- /dev/null
+++ b/platform/apq8064/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_APQ8064_H
+#define __IRQS_APQ8064_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
diff --git a/platform/apq8064/platform.c b/platform/apq8064/platform.c
new file mode 100644
index 0000000..af1e2f4
--- /dev/null
+++ b/platform/apq8064/platform.c
@@ -0,0 +1,113 @@
+/*
+ * 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.
+ */
+
+#include <reg.h>
+#include <debug.h>
+#include <uart_dm.h>
+#include <qgic.h>
+#include <platform/iomap.h>
+#include <mmu.h>
+#include <qgic.h>
+#include <arch/arm/mmu.h>
+
+extern void platform_init_timer(void);
+extern uint8_t target_uart_gsbi(void);
+
+static uint32_t ticks_per_sec = 0;
+
+#define MB (1024*1024)
+#define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB)
+
+/* Scratch region - cacheable, write through */
+#define CACHEABLE_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
+ MMU_MEMORY_AP_READ_WRITE)
+
+/* Peripherals - non-shared device */
+#define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_NON_SHARED | \
+ MMU_MEMORY_AP_READ_WRITE)
+
+mmu_section_t mmu_section_table[] = {
+/* Physical addr, Virtual addr, Size (in MB), Flags */
+ {MEMBASE, MEMBASE, (MEMSIZE/MB), CACHEABLE_MEMORY},
+ {SCRATCH_ADDR, SCRATCH_ADDR, SCRATCH_SIZE, CACHEABLE_MEMORY},
+ {MSM_IOMAP_BASE, MSM_IOMAP_BASE, MSM_IOMAP_SIZE, IOMAP_MEMORY},
+};
+
+void platform_early_init(void)
+{
+ uart_init(target_uart_gsbi());
+ qgic_init();
+ platform_init_timer();
+}
+
+void platform_init(void)
+{
+ dprintf(INFO, "platform_init()\n");
+}
+
+/* Setup memory for this platform */
+void platform_init_mmu_mappings(void)
+{
+ uint32_t i;
+ uint32_t sections;
+ uint32_t table_size = ARRAY_SIZE(mmu_section_table);
+
+ for (i = 0; i < table_size; i++)
+ {
+ sections = mmu_section_table[i].num_of_sections;
+
+ while (sections--)
+ {
+ arm_mmu_map_section(mmu_section_table[i].paddress + sections*MB,
+ mmu_section_table[i].vaddress + sections*MB,
+ mmu_section_table[i].flags);
+ }
+ }
+}
+
+/* Initialize DGT timer */
+void platform_init_timer(void)
+{
+ /* disable timer */
+ writel(0, DGT_ENABLE);
+
+ /* DGT uses LPXO source which is 27MHz.
+ * Set clock divider to 4.
+ */
+ writel(3, DGT_CLK_CTL);
+
+ ticks_per_sec = 6750000; /* (27 MHz / 4) */
+}
+
+/* Returns timer ticks per sec */
+uint32_t platform_tick_rate(void)
+{
+ return ticks_per_sec;
+}
diff --git a/platform/apq8064/rules.mk b/platform/apq8064/rules.mk
new file mode 100644
index 0000000..9447f04
--- /dev/null
+++ b/platform/apq8064/rules.mk
@@ -0,0 +1,22 @@
+LOCAL_DIR := $(GET_LOCAL_DIR)
+
+ARCH := arm
+ARM_CPU := cortex-a8
+CPU := generic
+
+DEFINES += ARM_CPU_CORE_KRAIT
+
+INCLUDES += -I$(LOCAL_DIR)/include -I$(LK_TOP_DIR)/platform/msm_shared/include
+
+DEVS += fbcon
+MODULES += dev/fbcon
+
+OBJS += \
+ $(LOCAL_DIR)/platform.o \
+ $(LOCAL_DIR)/clock.o \
+ $(LOCAL_DIR)/gpio.o \
+
+LINKER_SCRIPT += $(BUILDDIR)/system-onesegment.ld
+
+include platform/msm_shared/rules.mk
+
diff --git a/platform/msm_shared/rules.mk b/platform/msm_shared/rules.mk
index 7d3aad9..a170109 100644
--- a/platform/msm_shared/rules.mk
+++ b/platform/msm_shared/rules.mk
@@ -31,6 +31,11 @@
$(LOCAL_DIR)/mdp4.o
endif
+ifeq ($(PLATFORM),apq8064)
+ OBJS += $(LOCAL_DIR)/qgic.o \
+ $(LOCAL_DIR)/uart_dm.o
+endif
+
ifeq ($(PLATFORM),msm8960)
OBJS += $(LOCAL_DIR)/mipi_dsi.o \
$(LOCAL_DIR)/i2c_qup.o \
diff --git a/project/apq8064.mk b/project/apq8064.mk
new file mode 100644
index 0000000..1c483dd
--- /dev/null
+++ b/project/apq8064.mk
@@ -0,0 +1,13 @@
+# top level project rules for the apq8064 project
+#
+LOCAL_DIR := $(GET_LOCAL_DIR)
+
+TARGET := apq8064
+
+MODULES += app/aboot
+
+DEBUG := 1
+
+#DEFINES += WITH_DEBUG_DCC=1
+DEFINES += WITH_DEBUG_UART=1
+#DEFINES += WITH_DEBUG_FBCON=1
diff --git a/target/apq8064/atags.c b/target/apq8064/atags.c
new file mode 100644
index 0000000..f686bf6
--- /dev/null
+++ b/target/apq8064/atags.c
@@ -0,0 +1,54 @@
+/* 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 <sys/types.h>
+
+#define SIZE_1M (1024*1024)
+#define SIZE_141M (141*SIZE_1M)
+
+#define KERNEL_MEM_ADDR_1 0x80200000
+
+uint32_t* target_atag_mem(uint32_t* ptr)
+{
+ /* ATAG_MEM */
+ *ptr++ = 4;
+ *ptr++ = 0x54410002;
+ *ptr++ = SIZE_141M;
+ *ptr++ = KERNEL_MEM_ADDR_1;
+
+ return ptr;
+}
+
+void *target_get_scratch_address(void)
+{
+ return((void *)KERNEL_MEM_ADDR_1);
+}
+
+uint32_t target_get_max_flash_size(void)
+{
+ return (SIZE_141M);
+}
diff --git a/target/apq8064/init.c b/target/apq8064/init.c
new file mode 100644
index 0000000..c5f475c
--- /dev/null
+++ b/target/apq8064/init.c
@@ -0,0 +1,179 @@
+/*
+ * 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.
+ */
+
+#include <reg.h>
+#include <debug.h>
+#include <smem.h>
+#include <uart_dm.h>
+#include <gsbi.h>
+#include <baseband.h>
+#include <dev/keys.h>
+#include <dev/pm8921.h>
+#include <dev/gpio_keypad.h>
+#include <platform/iomap.h>
+#include <lib/ptable.h>
+
+#define LINUX_MACHTYPE_APQ8064_SIM 3572
+
+extern unsigned int mmc_boot_main(unsigned char slot, unsigned int base);
+extern void mdelay(unsigned msecs);
+extern void keypad_init(void);
+
+static unsigned mmc_sdc_base[] =
+{
+ MSM_SDC1_BASE,
+ MSM_SDC2_BASE,
+ MSM_SDC3_BASE,
+ MSM_SDC4_BASE
+};
+
+static pm8921_dev_t pmic;
+static const uint8_t uart_gsbi_id = GSBI_ID_3;
+
+void target_init(void)
+{
+ uint32_t base_addr;
+ uint8_t slot;
+ dprintf(INFO, "target_init()\n");
+
+ /* Initialize PMIC driver */
+ pmic.read = pa1_ssbi2_read_bytes;
+ pmic.write = pa1_ssbi2_write_bytes;
+
+ pm8921_init(&pmic);
+
+ /* Keypad init */
+ keys_init();
+ keypad_init();
+
+ /* Trying Slot 1 first */
+ slot = 1;
+ base_addr = mmc_sdc_base[slot-1];
+ if(mmc_boot_main(slot, base_addr))
+ {
+ /* Trying Slot 3 next */
+ slot = 3;
+ base_addr = mmc_sdc_base[slot-1];
+ if(mmc_boot_main(slot, base_addr))
+ {
+ dprintf(CRITICAL, "mmc init failed!");
+ ASSERT(0);
+ }
+ }
+}
+
+uint32_t board_machtype(void)
+{
+ struct smem_board_info_v6 board_info_v6;
+ uint32_t board_info_len = 0;
+ uint32_t smem_status = 0;
+ uint32_t format = 0;
+ uint32_t id = HW_PLATFORM_UNKNOWN;
+ uint32_t mach_id;
+
+
+ smem_status = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION,
+ &format, sizeof(format), 0);
+ if(!smem_status)
+ {
+ if (format == 6)
+ {
+ board_info_len = sizeof(board_info_v6);
+
+ smem_status = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
+ &board_info_v6, board_info_len);
+ if(!smem_status)
+ {
+ id = board_info_v6.board_info_v3.hw_platform;
+ }
+ }
+ }
+
+ /* Detect the board we are running on */
+ switch(id)
+ {
+ /* APQ8064 machine id not yet defined for CDP etc.
+ * default to simulator.
+ */
+ case HW_PLATFORM_SURF:
+ case HW_PLATFORM_FFA:
+ case HW_PLATFORM_FLUID:
+ default:
+ mach_id = LINUX_MACHTYPE_APQ8064_SIM;
+ };
+
+ return mach_id;
+}
+
+void reboot_device(uint32_t reboot_reason)
+{
+ /* TODO: Not implemented yet. */
+ ASSERT(0);
+}
+
+uint32_t check_reboot_mode(void)
+{
+ uint32_t restart_reason = 0;
+
+ /* Read reboot reason and scrub it */
+ restart_reason = readl(RESTART_REASON_ADDR);
+ writel(0x00, RESTART_REASON_ADDR);
+
+ return restart_reason;
+}
+
+void target_serialno(unsigned char *buf)
+{
+ uint32_t serialno;
+ if(target_is_emmc_boot())
+ {
+ serialno = mmc_get_psn();
+ sprintf(buf,"%x",serialno);
+ }
+}
+
+/* Do any target specific intialization needed before entering fastboot mode */
+void target_fastboot_init(void)
+{
+ /* Set the BOOT_DONE flag in PM8921 */
+ pm8921_boot_done();
+}
+
+/* GSBI to be used for UART */
+uint8_t target_uart_gsbi(void)
+{
+ return uart_gsbi_id;
+}
+
+/* Returns type of baseband. APQ for APPs only proc. */
+unsigned target_baseband()
+{
+ return BASEBAND_APQ;
+}
diff --git a/target/apq8064/keypad.c b/target/apq8064/keypad.c
new file mode 100644
index 0000000..c2d01fe
--- /dev/null
+++ b/target/apq8064/keypad.c
@@ -0,0 +1,69 @@
+/*
+ * 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 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 <string.h>
+#include <dev/keys.h>
+#include <dev/gpio_keypad.h>
+
+#define NUM_OF_ROWS 1
+#define NUM_OF_COLS 5
+
+#define BITS_IN_ELEMENT(x) (sizeof(x)[0] * 8)
+
+static unsigned char qwerty_keys_old[NUM_OF_ROWS];
+static unsigned char qwerty_keys_new[NUM_OF_ROWS];
+
+#define KEYMAP_INDEX(row, col) (row)* BITS_IN_ELEMENT(qwerty_keys_new) + (col)
+
+unsigned int qwerty_keymap[] = {
+ [KEYMAP_INDEX(0, 0)] = KEY_VOLUMEUP,
+ [KEYMAP_INDEX(0, 1)] = KEY_VOLUMEDOWN,
+};
+
+
+struct qwerty_keypad_info qwerty_keypad = {
+ .keymap = qwerty_keymap,
+ .old_keys = qwerty_keys_old,
+ .rec_keys = qwerty_keys_new,
+ .rows = NUM_OF_ROWS,
+ .columns = NUM_OF_COLS,
+ .num_of_reads = NUM_OF_ROWS,
+ .rd_func = &pa1_ssbi2_read_bytes,
+ .wr_func = &pa1_ssbi2_write_bytes,
+ .settle_time = 5 /* msec */,
+ .poll_time = 20 /* msec */,
+};
+
+void keypad_init(void)
+{
+ memset(qwerty_keys_old, 0, sizeof(qwerty_keys_old));
+ memset(qwerty_keys_new, 0, sizeof(qwerty_keys_new));
+
+ ssbi_keypad_init(&qwerty_keypad);
+}
diff --git a/target/apq8064/rules.mk b/target/apq8064/rules.mk
new file mode 100644
index 0000000..9e54d77
--- /dev/null
+++ b/target/apq8064/rules.mk
@@ -0,0 +1,29 @@
+LOCAL_DIR := $(GET_LOCAL_DIR)
+
+INCLUDES += -I$(LOCAL_DIR)/include -I$(LK_TOP_DIR)/platform/msm_shared
+
+PLATFORM := apq8064
+
+MEMBASE := 0x88F00000 # SDRAM
+MEMSIZE := 0x00100000 # 1MB
+
+SCRATCH_ADDR := 0x90000000
+SCRATCH_SIZE := 128 #size in MB
+
+KEYS_USE_GPIO_KEYPAD := 1
+
+MODULES += \
+ dev/keys \
+ dev/pmic/pm8921 \
+ lib/ptable
+
+DEFINES += \
+ MEMSIZE=$(MEMSIZE) \
+ MEMBASE=$(MEMBASE) \
+ SCRATCH_ADDR=$(SCRATCH_ADDR) \
+ SCRATCH_SIZE=$(SCRATCH_SIZE)
+
+OBJS += \
+ $(LOCAL_DIR)/init.o \
+ $(LOCAL_DIR)/atags.o \
+ $(LOCAL_DIR)/keypad.o
diff --git a/target/apq8064/tools/makefile b/target/apq8064/tools/makefile
new file mode 100644
index 0000000..7da7c6d
--- /dev/null
+++ b/target/apq8064/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/apq8064/tools/mkheader.c b/target/apq8064/tools/mkheader.c
new file mode 100644
index 0000000..cd11810
--- /dev/null
+++ b/target/apq8064/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;
+}