[msm8655_surf]: Add msm8655 target to LK
Change-Id: I9ccc8df8645a67a5d3dde8b0c5366d8012225440
diff --git a/project/msm8655_surf.mk b/project/msm8655_surf.mk
index d107e94..8a2649f 100644
--- a/project/msm8655_surf.mk
+++ b/project/msm8655_surf.mk
@@ -2,7 +2,7 @@
#
LOCAL_DIR := $(GET_LOCAL_DIR)
-TARGET := msm7630_surf
+TARGET := msm8655_surf
MODULES += app/aboot
diff --git a/project/msm8655_surf_nandwrite.mk b/project/msm8655_surf_nandwrite.mk
index 2efe688..62ae02a 100644
--- a/project/msm8655_surf_nandwrite.mk
+++ b/project/msm8655_surf_nandwrite.mk
@@ -2,7 +2,7 @@
#
LOCAL_DIR := $(GET_LOCAL_DIR)
-TARGET := msm7630_surf
+TARGET := msm8655_surf
MODULES += app/nandwrite
diff --git a/target/msm8655_surf/atags.c b/target/msm8655_surf/atags.c
new file mode 100644
index 0000000..4d79e76
--- /dev/null
+++ b/target/msm8655_surf/atags.c
@@ -0,0 +1,131 @@
+/* Copyright (c) 2009, 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>
+
+#define EBI1_ADDR_128M 0x08000000
+#define SIZE_256M 0x10000000
+#define SIZE_128M 0x08000000
+#define SIZE_1M 0x00100000
+
+static int scratch_addr = -1;
+int smem_ram_ptable_init(struct smem_ram_ptable *);
+
+unsigned* target_atag_mem(unsigned* ptr)
+{
+ struct smem_ram_ptable ram_ptable;
+ unsigned i = 0;
+
+ if (smem_ram_ptable_init(&ram_ptable))
+ {
+ for (i = 0; i < ram_ptable.len; i++)
+ {
+ if ((ram_ptable.parts[i].attr == READWRITE)
+ && (ram_ptable.parts[i].domain == APPS_DOMAIN)
+ && (ram_ptable.parts[i].type == APPS_MEMORY)
+ && (ram_ptable.parts[i].category != IMEM))
+ {
+ /* ATAG_MEM */
+ *ptr++ = 4;
+ // Tag EBI-1 memory as unstable.
+ if(ram_ptable.parts[i].category == EBI1_CS0) {
+ // if EBI-1 CS-0 is 256Mb then this is a 2x256 target and
+ // the kernel can reserve this mem region as unstable.
+ // This memory region can be activated when the kernel
+ // receives a request from Android init scripts.
+ if(ram_ptable.parts[i].size == SIZE_256M)
+ *ptr++ = 0x5441000A; //Deep-Power-Down Tag.
+
+ //if EBI-1 CS-0 s 128Mb then this is a 2x128 target.
+ //Android + Kernel + PMEM regions account for more than
+ //128Mb and the target will not be able to boot with just
+ //one memory bank active and the second memory bank is reserved.
+ //In the case of 2x128 the tag is set to SelfRefresh Only.
+ else if(ram_ptable.parts[i].size == SIZE_128M)
+ *ptr++ = 0x5441000B; //Self-Refresh Tag.
+ }
+ else
+ *ptr++ = 0x54410002;
+
+ *ptr++ = ram_ptable.parts[i].size;
+ *ptr++ = ram_ptable.parts[i].start;
+ }
+
+ /* Check for modem bootloader memory that can be reclaimed */
+ if ((ram_ptable.parts[i].attr == READWRITE)
+ && (ram_ptable.parts[i].domain == APPS_DOMAIN)
+ && (ram_ptable.parts[i].type == BOOT_REGION_MEMORY1))
+ {
+ /* ATAG_MEM_OSBL */
+ *ptr++ = 4;
+ *ptr++ = 0x5441000C;
+ *ptr++ = ram_ptable.parts[i].size;
+ *ptr++ = ram_ptable.parts[i].start;
+ }
+ }
+ }
+ else
+ {
+ dprintf(CRITICAL, "ERROR: Unable to read RAM partition\n");
+ ASSERT(0);
+ }
+
+ return ptr;
+}
+
+void *target_get_scratch_address(void)
+{
+ struct smem_ram_ptable ram_ptable;
+ unsigned i = 0;
+
+ if (smem_ram_ptable_init(&ram_ptable))
+ {
+ for (i = 0; i < ram_ptable.len; i++)
+ {
+ if ((ram_ptable.parts[i].attr == READWRITE)
+ && (ram_ptable.parts[i].domain == APPS_DOMAIN)
+ && (ram_ptable.parts[i].start != 0x0))
+ {
+ if (ram_ptable.parts[i].size >= FASTBOOT_BUF_SIZE)
+ {
+ scratch_addr = ram_ptable.parts[i].start;
+ break;
+ }
+ }
+ }
+ }
+ else
+ {
+ dprintf(CRITICAL, "ERROR: Unable to read RAM partition\n");
+ ASSERT(0);
+ }
+
+ return (void *)((scratch_addr == -1) ? EBI1_ADDR_128M : scratch_addr);
+}
diff --git a/target/msm8655_surf/include/target/display.h b/target/msm8655_surf/include/target/display.h
new file mode 100644
index 0000000..69cd4ac
--- /dev/null
+++ b/target/msm8655_surf/include/target/display.h
@@ -0,0 +1,47 @@
+/* Copyright (c) 2010, 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 _TARGET_MSM7630_SURF_DISPLAY_H
+#define _TARGET_MSM7630_SURF_DISPLAY_H
+
+#define TARGET_XRES 480
+#define TARGET_YRES 800
+
+#define LCDC_FB_WIDTH 480
+#define LCDC_FB_HEIGHT 800
+
+#define LCDC_HSYNC_PULSE_WIDTH_DCLK 8
+#define LCDC_HSYNC_BACK_PORCH_DCLK 184
+#define LCDC_HSYNC_FRONT_PORCH_DCLK 4
+#define LCDC_HSYNC_SKEW_DCLK 0
+
+#define LCDC_VSYNC_PULSE_WIDTH_LINES 1
+#define LCDC_VSYNC_BACK_PORCH_LINES 2
+#define LCDC_VSYNC_FRONT_PORCH_LINES 3
+
+#endif
diff --git a/target/msm8655_surf/init.c b/target/msm8655_surf/init.c
new file mode 100644
index 0000000..28dd553
--- /dev/null
+++ b/target/msm8655_surf/init.c
@@ -0,0 +1,378 @@
+/*
+ * Copyright (c) 2009, Google Inc.
+ * All rights reserved.
+ * Copyright (c) 2009-2010, 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 <debug.h>
+#include <dev/keys.h>
+#include <dev/gpio.h>
+#include <dev/gpio_keypad.h>
+#include <lib/ptable.h>
+#include <dev/flash.h>
+#include <smem.h>
+#include <reg.h>
+#include <platform/iomap.h>
+
+#define LINUX_MACHTYPE_7x30_SURF 2679
+#define LINUX_MACHTYPE_7x30_FFA 2707
+#define LINUX_MACHTYPE_7x30_FLUID 2741
+#define LINUX_MACHTYPE_8x55_SURF 2768
+#define LINUX_MACHTYPE_8x55_FFA 2769
+#define LINUX_MACHTYPE_8x55_SVLTE_FFA 2863
+#define LINUX_MACHTYPE_8x55_SVLTE_SURF 2864
+
+#define MSM8255_ID 74
+#define MSM8655_ID 75
+#define APQ8055_ID 85
+
+#define VARIABLE_LENGTH 0x10101010
+#define DIFF_START_ADDR 0xF0F0F0F0
+#define NUM_PAGES_PER_BLOCK 0x40
+
+static unsigned mmc_sdc_base[] = { MSM_SDC1_BASE, MSM_SDC2_BASE, MSM_SDC3_BASE, MSM_SDC4_BASE};
+
+static struct ptable flash_ptable;
+static int hw_platform_type = -1;
+
+/* 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[] = {
+ {
+ .start = 0,
+ .length = 5 /* In MB */,
+ .name = "boot",
+ },
+ {
+ .start = DIFF_START_ADDR,
+ .length = 120 /* In MB */,
+ .name = "system",
+ },
+ {
+ .start = DIFF_START_ADDR,
+ .length = 30 /* In MB */,
+ .name = "cache",
+ },
+ {
+ .start = DIFF_START_ADDR,
+ .length = 1 /* In MB */,
+ .name = "misc",
+ },
+ {
+ .start = DIFF_START_ADDR,
+ .length = VARIABLE_LENGTH,
+ .name = "userdata",
+ },
+ {
+ .start = DIFF_START_ADDR,
+ .length = 3 /* In MB */,
+ .name = "persist",
+ },
+ {
+ .start = DIFF_START_ADDR,
+ .length = 5 /* In MB */,
+ .name = "recovery",
+ },
+};
+static int num_parts = sizeof(board_part_list)/sizeof(struct ptentry);
+
+void smem_ptable_init(void);
+unsigned smem_get_apps_flash_start(void);
+unsigned smem_read_alloc_entry_offset(smem_mem_type_t, void *, int, int);
+
+void keypad_init(void);
+
+static int emmc_boot = -1; /* set to uninitialized */
+int target_is_emmc_boot(void);
+static int platform_version = -1;
+static int target_msm_id = -1;
+static int interleaved_mode_enabled = -1;
+void enable_interleave_mode(int);
+
+int target_is_interleaved_mode(void)
+{
+ struct smem_board_info_v4 board_info_v4;
+ unsigned int board_info_len = 0;
+ unsigned smem_status;
+ char *build_type;
+ unsigned format = 0;
+
+ if (interleaved_mode_enabled != -1)
+ {
+ return interleaved_mode_enabled;
+ }
+
+ smem_status = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION,
+ &format, sizeof(format), 0);
+ if(!smem_status)
+ {
+ if ((format == 3) || (format == 4))
+ {
+ if (format == 4)
+ board_info_len = sizeof(board_info_v4);
+ else
+ board_info_len = sizeof(board_info_v4.board_info_v3);
+
+ smem_status = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
+ &board_info_v4, board_info_len);
+ if(!smem_status)
+ {
+ build_type = (char *)(board_info_v4.board_info_v3.build_id) + 9;
+
+ interleaved_mode_enabled = 0;
+
+ if (*build_type == 'C')
+ {
+ interleaved_mode_enabled = 1;
+ }
+ }
+ }
+ }
+
+ return interleaved_mode_enabled;
+}
+
+void target_init(void)
+{
+ unsigned offset;
+ struct flash_info *flash_info;
+ 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*/
+ unsigned base_addr;
+ unsigned char slot;
+ int i;
+
+ dprintf(INFO, "target_init()\n");
+
+#if (!ENABLE_NANDWRITE)
+ keys_init();
+ keypad_init();
+#endif
+
+ if (target_is_emmc_boot())
+ {
+ /* Trying Slot 2 first */
+ slot = 2;
+ base_addr = mmc_sdc_base[slot-1];
+ if(mmc_boot_main(slot, base_addr))
+ {
+ /* Trying Slot 4 next */
+ slot = 4;
+ base_addr = mmc_sdc_base[slot-1];
+ if(mmc_boot_main(slot, base_addr))
+ {
+ dprintf(CRITICAL, "mmc init failed!");
+ ASSERT(0);
+ }
+ }
+ return;
+ }
+
+ ptable_init(&flash_ptable);
+ smem_ptable_init();
+
+ flash_init();
+ flash_info = flash_get_info();
+ ASSERT(flash_info);
+ enable_interleave_mode(target_is_interleaved_mode());
+
+ 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);
+
+ 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;
+ if(target_is_interleaved_mode()) {
+ ptable_add(&flash_ptable, ptn->name, offset + (ptn->start / 2),
+ (len / 2), ptn->flags, TYPE_APPS_PARTITION, PERM_WRITEABLE);
+ }
+ else {
+ 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);
+}
+
+int target_platform_version(void)
+{
+ return platform_version;
+}
+
+int target_is_msm8x55(void)
+{
+ if ((target_msm_id == MSM8255_ID) ||
+ (target_msm_id == MSM8655_ID) ||
+ (target_msm_id == APQ8055_ID))
+ return 1;
+ else
+ return 0;
+}
+
+unsigned board_machtype(void)
+{
+ struct smem_board_info_v4 board_info_v4;
+ unsigned int board_info_len = 0;
+ enum platform platform_type = 0;
+ unsigned smem_status;
+ unsigned format = 0;
+ if(hw_platform_type != -1)
+ return hw_platform_type;
+
+ smem_status = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION,
+ &format, sizeof(format), 0);
+ if(!smem_status)
+ {
+ if ((format == 3) || (format == 4))
+ {
+ if (format == 4)
+ board_info_len = sizeof(board_info_v4);
+ else
+ board_info_len = sizeof(board_info_v4.board_info_v3);
+
+ smem_status = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
+ &board_info_v4, board_info_len);
+ if(!smem_status)
+ {
+ if(format == 4)
+ platform_version = board_info_v4.platform_version;
+
+ platform_type = board_info_v4.board_info_v3.hw_platform;
+ target_msm_id = board_info_v4.board_info_v3.msm_id;
+ switch (platform_type)
+ {
+ case HW_PLATFORM_SURF:
+ hw_platform_type = ((target_is_msm8x55()) ?
+ LINUX_MACHTYPE_8x55_SURF : LINUX_MACHTYPE_7x30_SURF); break;
+ case HW_PLATFORM_FFA:
+ hw_platform_type = ((target_is_msm8x55()) ?
+ LINUX_MACHTYPE_8x55_FFA : LINUX_MACHTYPE_7x30_FFA); break;
+ case HW_PLATFORM_FLUID:
+ hw_platform_type = LINUX_MACHTYPE_7x30_FLUID; break;
+ case HW_PLATFORM_SVLTE:
+ hw_platform_type = LINUX_MACHTYPE_8x55_SVLTE_FFA; break;
+ default:
+ hw_platform_type = ((target_is_msm8x55()) ?
+ LINUX_MACHTYPE_8x55_SURF : LINUX_MACHTYPE_7x30_SURF); break;
+ }
+ return hw_platform_type;
+ }
+ }
+ }
+ hw_platform_type = LINUX_MACHTYPE_7x30_SURF;
+ return hw_platform_type;
+}
+
+void reboot_device(unsigned reboot_reason)
+{
+ reboot(reboot_reason);
+}
+
+unsigned check_reboot_mode(void)
+{
+ unsigned mode[2] = {0, 0};
+ unsigned int mode_len = sizeof(mode);
+ unsigned smem_status;
+
+ smem_status = smem_read_alloc_entry(SMEM_APPS_BOOT_MODE,
+ &mode, mode_len );
+ if(smem_status)
+ {
+ dprintf(CRITICAL, "ERROR: unable to read shared memory for reboot mode\n");
+ return 0;
+ }
+ return mode[0];
+}
+
+static unsigned target_check_power_on_reason(void)
+{
+ unsigned power_on_status = 0;
+ unsigned int status_len = sizeof(power_on_status);
+ unsigned smem_status;
+
+ smem_status = smem_read_alloc_entry(SMEM_POWER_ON_STATUS_INFO,
+ &power_on_status, status_len);
+
+ if (!smem_status)
+ {
+ dprintf(CRITICAL, "ERROR: unable to read shared memory for power on reason\n");
+ }
+
+ return power_on_status;
+}
+
+unsigned target_pause_for_battery_charge(void)
+{
+ //check power on reason only for fluid devices
+ if( hw_platform_type != LINUX_MACHTYPE_7x30_FLUID)
+ return 0;
+
+ if (target_check_power_on_reason() == PWR_ON_EVENT_USB_CHG)
+ return 1;
+ return 0;
+}
+
+void target_battery_charging_enable(unsigned enable, unsigned disconnect)
+{
+}
diff --git a/target/msm8655_surf/keypad.c b/target/msm8655_surf/keypad.c
new file mode 100644
index 0000000..46c51c8
--- /dev/null
+++ b/target/msm8655_surf/keypad.c
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2009, Google Inc.
+ * All rights reserved.
+ * Copyright (c) 2009-2010, 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 <dev/keys.h>
+#include <dev/gpio_keypad.h>
+
+#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
+#define BITS_IN_ELEMENT(x) (sizeof(x)[0] * 8)
+
+static unsigned char qwerty_keys_old[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+static unsigned char qwerty_keys_new[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+
+#define KEYMAP_INDEX(row, col) (row)* BITS_IN_ELEMENT(qwerty_keys_new) + (col)
+
+static unsigned int qwerty_keymap[] = {
+ [KEYMAP_INDEX(4, 2)] = KEY_BACK, /* -L on SURF & FFA */
+ [KEYMAP_INDEX(3, 4)] = KEY_HOME, /* +R on SURF & FFA */
+ [KEYMAP_INDEX(1, 3)] = KEY_VOLUMEUP, /* '+' of left side switch on FLUID */
+ [KEYMAP_INDEX(1, 4)] = KEY_VOLUMEDOWN, /* '-' of left side switch on FLUID */
+};
+
+static struct qwerty_keypad_info qwerty_keypad = {
+ .keymap = qwerty_keymap,
+ .old_keys = qwerty_keys_old,
+ .rec_keys = qwerty_keys_new,
+ .rows = 5,
+ .columns = 5,
+ .num_of_reads = 6,
+ .rd_func = &i2c_ssbi_read_bytes,
+ .wr_func = &i2c_ssbi_write_bytes,
+ .settle_time = 5 /* msec */,
+ .poll_time = 20 /* msec */,
+};
+
+void keypad_init(void)
+{
+ ssbi_keypad_init(&qwerty_keypad);
+}
diff --git a/target/msm8655_surf/rules.mk b/target/msm8655_surf/rules.mk
new file mode 100644
index 0000000..e318b14
--- /dev/null
+++ b/target/msm8655_surf/rules.mk
@@ -0,0 +1,42 @@
+LOCAL_DIR := $(GET_LOCAL_DIR)
+
+INCLUDES += -I$(LOCAL_DIR)/include -I$(LK_TOP_DIR)/platform/msm_shared -I$(LK_TOP_DIR)/platform/msm7x30
+
+PLATFORM := msm7x30
+
+MEMBASE := 0x00000000 # EBI
+MEMSIZE := 0x00100000 # 1MB
+
+BASE_ADDR := 0x00200000
+
+TAGS_ADDR := BASE_ADDR+0x00000100
+KERNEL_ADDR := BASE_ADDR+0x00008000
+RAMDISK_ADDR := BASE_ADDR+0x01000000
+SCRATCH_ADDR := 0x08008000
+FASTBOOT_BUF_SIZE := 0x07800000
+
+KEYS_USE_GPIO_KEYPAD := 1
+
+DEFINES += DISPLAY_SPLASH_SCREEN=0
+DEFINES += DISPLAY_TYPE_MDDI=0
+DEFINES += DISPLAY_TYPE_LCDC=0
+
+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) \
+ FASTBOOT_BUF_SIZE=$(FASTBOOT_BUF_SIZE)
+
+
+OBJS += \
+ $(LOCAL_DIR)/init.o \
+ $(LOCAL_DIR)/atags.o \
+ $(LOCAL_DIR)/keypad.o \
diff --git a/target/msm8655_surf/tools/makefile b/target/msm8655_surf/tools/makefile
new file mode 100644
index 0000000..94f47ca
--- /dev/null
+++ b/target/msm8655_surf/tools/makefile
@@ -0,0 +1,45 @@
+#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/msm8655_surf/tools/mkheader.c b/target/msm8655_surf/tools/mkheader.c
new file mode 100644
index 0000000..fda8b67
--- /dev/null
+++ b/target/msm8655_surf/tools/mkheader.c
@@ -0,0 +1,316 @@
+/*
+ * Copyright (c) 2007, Google Inc.
+ * All rights reserved.
+ *
+ * Copyright (c) 2009-2010, 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;
+}