Procházet zdrojové kódy

X5: add project files

Signed-off-by: svoboda18 <dev.svoboda18@gmail.com>
svoboda18 před 2 roky
rodič
revize
ac0bd5c13f

+ 24 - 0
project/X5.mk

@@ -0,0 +1,24 @@
+LOCAL_DIR := $(GET_LOCAL_DIR)
+TARGET := X5
+MODULES += app/mt_boot \
+           dev/lcm
+MTK_EMMC_SUPPORT = yes
+DEFINES += MTK_NEW_COMBO_EMMC_SUPPORT
+MTK_KERNEL_POWER_OFF_CHARGING = yes
+MTK_LCM_PHYSICAL_ROTATION = 0
+CUSTOM_LK_LCM = "hct_hx8394f_dsi_vdo_hd_cmi hct_rm68200_dsi_vdo_hd_cpt hct_ili9881_dsi_vdo_hd_cpt hct_otm1282_dsi_vdo_hd_auo hct_otm1285a_dsi_vdo_hd_boe hct_nt35521s_dsi_vdo_hd_boe_50_xld hct_hx8394d_dsi_vdo_hd_cmi"
+MTK_SECURITY_SW_SUPPORT = yes
+MTK_SEC_FASTBOOT_UNLOCK_SUPPORT = yes
+MTK_VERIFIED_BOOT_SUPPORT = yes
+BOOT_LOGO := hd720
+#DEFINES += WITH_DEBUG_DCC=1
+#DEFINES += WITH_DEBUG_UART=1
+#DEFINES += WITH_DEBUG_FBCON=1
+#DEFINES += MACH_FPGA=y
+#DEFINES += MACH_FPGA_NO_DISPLAY
+TRUSTONIC_TEE_SUPPORT=no
+MTK_GOOGLE_TRUSTY_SUPPORT=no
+MTK_DM_VERITY_OFF = no
+MTK_AB_OTA_UPDATER = no
+MTK_USERIMAGES_USE_F2FS = yes
+MT6580_USE_FCHR_ENB_KEY = yes

+ 2 - 0
target/X5/README

@@ -0,0 +1,2 @@
+The "mediatek/custom/<project>/lk" directory is intended for Mediatek project specific customization codes of Little Kernel.
+

+ 77 - 0
target/X5/cust_display.c

@@ -0,0 +1,77 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2008
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+//#include <common.h>
+//#include <stdarg.h>
+
+//#include <linux/types.h>
+
+//#include <asm/arch/mt65xx.h>
+//#include <asm/arch/mt65xx_typedefs.h>
+//#include <asm/arch/mt65xx_disp_drv.h>
+//#include <asm/arch/mt65xx_logo.h>
+#include <string.h>
+#include <platform/mt_typedefs.h>
+#include <platform/mt_disp_drv.h>
+#include <platform/mt_logo.h>
+
+#include <target/board.h>
+
+// this is a sample code for how to draw the logo by yourself.
+void cust_show_boot_logo(void)
+{
+    void  *fb_addr = mt_get_fb_addr();
+    UINT32 fb_size = mt_get_fb_size();
+    void  *db_addr = mt_get_logo_db_addr();
+
+    memcpy(fb_addr, (void *)((UINT32)db_addr + fb_size * 0), fb_size);
+
+    mt_disp_update(0, 0, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT);
+}
+
+const LOGO_CUST_IF *LOGO_GetCustomIF(void)
+{
+    static LOGO_CUST_IF CUST_IF;
+
+    memset(&CUST_IF, 0, sizeof(LOGO_CUST_IF));
+   
+    // the CUST_IF is null by default.
+    // if you want to use your routine, please replace the callback like the code below shows:
+    //CUST_IF.show_boot_logo = cust_show_boot_logo;
+
+    return &CUST_IF;
+}
+
+

+ 43 - 0
target/X5/cust_leds.c

@@ -0,0 +1,43 @@
+
+#include <cust_leds.h>
+#include <platform/mt_pwm.h>
+#include <platform/mt_leds.h>
+
+//extern int DISP_SetBacklight(int level);
+
+extern int disp_bls_set_backlight(unsigned int level);
+enum led_brightness backlight_default_level = LED_FULL;
+
+// Only support 64 levels of backlight (when lcd-backlight = MT65XX_LED_MODE_PWM)
+#define BACKLIGHT_LEVEL_PWM_64_FIFO_MODE_SUPPORT 64
+// Support 256 levels of backlight (when lcd-backlight = MT65XX_LED_MODE_PWM)
+#define BACKLIGHT_LEVEL_PWM_256_SUPPORT 256
+
+// Custom can decide the support type "BACKLIGHT_LEVEL_PWM_256_SUPPORT" or "BACKLIGHT_LEVEL_PWM_64_FIFO_MODE_SUPPORT"
+#define BACKLIGHT_LEVEL_PWM_MODE_CONFIG BACKLIGHT_LEVEL_PWM_256_SUPPORT
+
+unsigned int Cust_GetBacklightLevelSupport_byPWM(void)
+{
+	return BACKLIGHT_LEVEL_PWM_MODE_CONFIG;
+}
+
+static struct cust_mt65xx_led cust_led_list[MT65XX_LED_TYPE_TOTAL] = {
+	{"red",               MT65XX_LED_MODE_NONE, -1,{0,0,0,0,0}},
+	{"green",             MT65XX_LED_MODE_NONE, -1,{0,0,0,0,0}},
+	{"blue",              MT65XX_LED_MODE_NONE, -1,{0,0,0,0,0}},
+	{"jogball-backlight", MT65XX_LED_MODE_NONE, -1,{0,0,0,0,0}},
+	{"keyboard-backlight",MT65XX_LED_MODE_NONE, -1,{0,0,0,0,0}},
+	{"button-backlight",  MT65XX_LED_MODE_NONE, -1,{0,0,0,0,0}},
+	{"lcd-backlight",     MT65XX_LED_MODE_CUST_BLS_PWM, (int)disp_bls_set_backlight,{0}},
+};
+
+enum led_brightness get_cust_led_default_level(void)
+{
+	return backlight_default_level;
+}
+
+struct cust_mt65xx_led *get_cust_led_list(void)
+{
+	return cust_led_list;
+}
+

+ 87 - 0
target/X5/cust_msdc.c

@@ -0,0 +1,87 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2010
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+#include "cust_msdc.h"
+#include "msdc.h"
+
+
+struct msdc_cust msdc_cap[MSDC_MAX_NUM] =
+{
+    {
+        MSDC0_CLKSRC_DEFAULT, /* host clock source           */
+        MSDC_SMPL_RISING,   /* command latch edge            */
+        MSDC_SMPL_RISING,   /* data latch edge               */
+        MSDC_DRVN_GEAR2,    /* clock pad driving             */
+        MSDC_DRVN_GEAR2,    /* command pad driving           */
+        MSDC_DRVN_GEAR2,    /* data pad driving              */
+        MSDC_DRVN_GEAR2,    /* rst pad driving               */
+        MSDC_DRVN_GEAR2,    /* ds pad driving                */
+        MSDC_DRVN_DONT_CARE,/* clock pad driving on 1.8V     */
+        MSDC_DRVN_DONT_CARE,/* command pad driving on 1.8V   */
+        MSDC_DRVN_DONT_CARE,/* data pad driving on 1.8V      */
+        8,                  /* data pins                     */
+        0,                  /* data address offset           */
+#if defined(MMC_MSDC_DRV_CTP)
+        MSDC_HIGHSPEED | MSDC_HS200 | MSDC_RST_PIN_EN | MSDC_DDR
+#else
+        MSDC_HIGHSPEED// | MSDC_DDR
+#endif
+    }
+
+#if (defined(MMC_MSDC_DRV_CTP) && !defined(FPGA_PLATFORM))
+    ,
+    {
+        MSDC1_CLKSRC_DEFAULT, /* host clock source           */
+        MSDC_SMPL_RISING,   /* command latch edge            */
+        MSDC_SMPL_RISING,   /* data latch edge               */
+        MSDC_DRVN_GEAR1,    /* clock pad driving             */
+        MSDC_DRVN_GEAR1,    /* command pad driving           */
+        MSDC_DRVN_GEAR1,    /* data pad driving              */
+        MSDC_DRVN_DONT_CARE,/* no need for not-emmc card     */
+        MSDC_DRVN_DONT_CARE,/* no need for not-emmc card     */
+        MSDC_DRVN_GEAR1,    /* clock pad driving on 1.8V     */
+        MSDC_DRVN_GEAR1,    /* command pad driving on 1.8V   */
+        MSDC_DRVN_GEAR1,    /* data pad driving on 1.8V      */
+        4,                  /* data pins                     */
+        0,                  /* data address offset           */
+
+        /* hardware capability flags     */
+        MSDC_HIGHSPEED | MSDC_UHS1 | MSDC_DDR //|MSDC_UHS1|MSDC_SDIO_IRQ|MSDC_DDR
+    }
+#endif
+};
+
+
+

binární
target/X5/dct/dct/codegen.dws


+ 9 - 0
target/X5/fastboot_oem_commands.c

@@ -0,0 +1,9 @@
+#include <debug.h>
+#include <reg.h>
+#include <target.h>
+#include <platform/mt_reg_base.h>
+
+void fastboot_oem_register()
+{
+  
+}

+ 20 - 0
target/X5/inc/avbkey.h

@@ -0,0 +1,20 @@
+#ifndef __AVBKEY__
+#define __AVBKEY__
+#define AVB_PUBK_SZ 256
+#define AVB_PUBK   0xC6, 0x55, 0x51, 0xDD, 0x32, 0x24, 0xA2, 0xE0, 0x0E, 0xBC, 0x7E, 0xFD, 0xBD, 0xA2, 0x53, 0x80, \
+                   0x58, 0x69, 0x7E, 0xF5, 0x4A, 0x40, 0x87, 0x95, 0x90, 0x54, 0x59, 0x3D, 0x55, 0xCA, 0xFF, 0x36, \
+                   0x34, 0x1A, 0xFA, 0xE1, 0xE0, 0x90, 0x2A, 0x1A, 0x32, 0x68, 0x5B, 0xF3, 0xDF, 0xAD, 0x0B, 0xF9, \
+                   0xB1, 0xD0, 0xF7, 0xEA, 0xAB, 0x47, 0x1F, 0x76, 0xBE, 0x1B, 0x98, 0x4B, 0x67, 0xA3, 0x62, 0xFA, \
+                   0xDF, 0xE6, 0xB5, 0xF8, 0xEE, 0x73, 0x16, 0x5F, 0xB8, 0xB1, 0x82, 0xDE, 0x49, 0x89, 0xD5, 0x3D, \
+                   0xD7, 0xA8, 0x42, 0x99, 0x81, 0x75, 0xC8, 0xD8, 0x84, 0x7B, 0xBD, 0x54, 0xA8, 0x22, 0x64, 0x44, \
+                   0xBC, 0x34, 0x06, 0x10, 0x3C, 0x89, 0xC2, 0xD1, 0xF3, 0x2C, 0x03, 0x65, 0x91, 0xB1, 0xA0, 0xD1, \
+                   0xC8, 0x21, 0x56, 0x15, 0x99, 0x48, 0x20, 0x27, 0x74, 0xEF, 0x01, 0x7A, 0x76, 0xA5, 0x0B, 0x6B, \
+                   0xFD, 0xE3, 0xFA, 0xED, 0x0D, 0xF9, 0x0F, 0x7A, 0x41, 0xFA, 0x76, 0x05, 0x37, 0x49, 0xFE, 0x34, \
+                   0x4F, 0x4B, 0x01, 0x49, 0xE4, 0x98, 0xF7, 0x89, 0x8E, 0xCD, 0x36, 0xAA, 0x39, 0x1D, 0xA9, 0x7D, \
+                   0x5D, 0x6B, 0x5A, 0x52, 0xD1, 0x75, 0x69, 0xA8, 0xDF, 0x7C, 0xDE, 0x1C, 0x1B, 0xF9, 0xD9, 0x19, \
+                   0x5B, 0xB7, 0x47, 0x4C, 0xB9, 0x70, 0x2E, 0xAD, 0xE5, 0xD6, 0x88, 0x7C, 0xED, 0x92, 0x6E, 0x46, \
+                   0x08, 0x10, 0xB5, 0x76, 0x03, 0x3E, 0x09, 0xAC, 0x4D, 0xB6, 0x2C, 0xCD, 0x12, 0x00, 0xBD, 0xD4, \
+                   0xA7, 0x03, 0xD3, 0x1B, 0x91, 0x08, 0x23, 0x36, 0x5B, 0x11, 0xFE, 0xAF, 0x59, 0x69, 0xB3, 0x3C, \
+                   0x88, 0x24, 0x37, 0x2D, 0x61, 0xBA, 0xC5, 0x99, 0x51, 0x18, 0x97, 0xF9, 0x23, 0x42, 0x96, 0x9F, \
+                   0x87, 0x2E, 0xCD, 0xB2, 0x4D, 0x5F, 0xA9, 0x24, 0xF2, 0x45, 0xDA, 0xE2, 0x65, 0x26, 0x26, 0x4D
+#endif /*__AVB_KEY__ */

+ 20 - 0
target/X5/inc/avbkey_recovery.h

@@ -0,0 +1,20 @@
+#ifndef __AVBKEY_RECOVERY__
+#define __AVBKEY_RECOVERY__
+#define AVB_RECOVERY_PUBK_SZ 256
+#define AVB_RECOVERY_PUBK   0xB6, 0x00, 0xB1, 0xCE, 0x55, 0xE4, 0x41, 0x3D, 0x51, 0xE1, 0xA8, 0xE8, 0xD9, 0x16, 0x3C, 0x7D, \
+                            0xD2, 0x16, 0x2D, 0x28, 0xAB, 0xD3, 0x1F, 0xEF, 0x69, 0xEF, 0x30, 0xD2, 0xE4, 0xC4, 0x12, 0xD0, \
+                            0x05, 0x38, 0x80, 0x7F, 0x90, 0x33, 0x1D, 0x44, 0x7F, 0x48, 0xA1, 0x35, 0xB0, 0xE7, 0x39, 0x34, \
+                            0x64, 0x82, 0x9D, 0x37, 0xC6, 0x6B, 0xD0, 0x96, 0xEB, 0xE2, 0x3D, 0x06, 0x22, 0x6E, 0x4B, 0xA5, \
+                            0xB0, 0xDA, 0x59, 0x77, 0x6B, 0x7D, 0xA9, 0xEE, 0xA7, 0xAF, 0xB7, 0x99, 0x99, 0xE8, 0x49, 0xE2, \
+                            0x1B, 0xB9, 0x15, 0xCC, 0x72, 0x02, 0x0C, 0x3F, 0x94, 0x77, 0x6C, 0x5C, 0xC0, 0x41, 0x27, 0x41, \
+                            0xD5, 0xD1, 0x6E, 0xE5, 0xD2, 0xB9, 0xBE, 0x12, 0x46, 0x90, 0x8F, 0x9A, 0x76, 0x6F, 0x62, 0xBD, \
+                            0x38, 0x66, 0xC0, 0x48, 0xB8, 0xC2, 0xB5, 0x78, 0xBC, 0x5F, 0x82, 0x9D, 0xA9, 0x00, 0xE4, 0x0B, \
+                            0x93, 0x14, 0xFE, 0x58, 0x5B, 0x02, 0x4B, 0xB9, 0x84, 0x16, 0xE8, 0x97, 0xE5, 0xB2, 0xFB, 0x03, \
+                            0xEE, 0x4B, 0x62, 0xF8, 0x46, 0xC9, 0x3A, 0x98, 0x2F, 0x58, 0xDC, 0x51, 0xB8, 0xDC, 0x6D, 0x72, \
+                            0xE7, 0xFC, 0x91, 0xDD, 0x06, 0xA4, 0x2C, 0x26, 0x32, 0x21, 0x08, 0x20, 0xA8, 0x39, 0x7F, 0x60, \
+                            0x4D, 0x67, 0xB3, 0x7D, 0x51, 0xBE, 0x12, 0x05, 0xAA, 0xE6, 0xCF, 0xB6, 0xC9, 0xE9, 0x77, 0xDE, \
+                            0x35, 0xD0, 0x9F, 0x2E, 0x7F, 0x6F, 0xB4, 0x57, 0xE3, 0xE9, 0xC4, 0xF3, 0xC8, 0xEC, 0xB2, 0x28, \
+                            0x89, 0x49, 0x45, 0x00, 0x01, 0xFE, 0xAB, 0xBD, 0x58, 0xD0, 0x42, 0xED, 0x44, 0x69, 0xC3, 0x8C, \
+                            0x77, 0x1C, 0xC1, 0xC4, 0x6E, 0x66, 0x04, 0x6F, 0x5A, 0xF4, 0x2E, 0x60, 0xA6, 0x61, 0xB5, 0x6B, \
+                            0x46, 0x0A, 0x7B, 0x31, 0xA4, 0x6C, 0xCE, 0x3E, 0xC4, 0xBB, 0x24, 0xB6, 0xBD, 0x0B, 0x17, 0x0F
+#endif /* __AVBKEY_RECOVERY__ */

+ 72 - 0
target/X5/inc/cust_leds.h

@@ -0,0 +1,72 @@
+#ifndef _CUST_LEDS_H
+#define _CUST_LEDS_H
+#include <platform/mt_typedefs.h>
+enum mt65xx_led_type
+{
+	MT65XX_LED_TYPE_RED = 0,
+	MT65XX_LED_TYPE_GREEN,
+	MT65XX_LED_TYPE_BLUE,
+	MT65XX_LED_TYPE_JOGBALL,
+	MT65XX_LED_TYPE_KEYBOARD,
+	MT65XX_LED_TYPE_BUTTON,
+	MT65XX_LED_TYPE_LCD,
+	MT65XX_LED_TYPE_TOTAL,
+};
+
+enum mt65xx_led_mode
+{
+	MT65XX_LED_MODE_NONE,
+	MT65XX_LED_MODE_PWM,
+	MT65XX_LED_MODE_GPIO,
+	MT65XX_LED_MODE_PMIC,
+	MT65XX_LED_MODE_CUST,
+	MT65XX_LED_MODE_CUST_LCM,
+	MT65XX_LED_MODE_CUST_BLS_PWM
+};
+
+enum mt65xx_led_pmic
+{
+	MT65XX_LED_PMIC_BUTTON=0,
+	MT65XX_LED_PMIC_LCD,
+	MT65XX_LED_PMIC_LCD_ISINK,
+	MT65XX_LED_PMIC_LCD_BOOST,
+	MT65XX_LED_PMIC_NLED_ISINK4,
+	MT65XX_LED_PMIC_NLED_ISINK5,
+    MT65XX_LED_PMIC_NLED_ISINK0,
+	MT65XX_LED_PMIC_NLED_ISINK1,
+	MT65XX_LED_PMIC_NLED_ISINK2,
+	MT65XX_LED_PMIC_NLED_ISINK3,
+	MT65XX_LED_PMIC_NLED_ISINK01
+};
+
+typedef int (*cust_brightness_set)(int level);
+struct PWM_config
+{
+	int clock_source;
+	int div;
+	int low_duration;
+	int High_duration;
+	BOOL pmic_pad;
+};
+
+/*
+ * name : must the same as lights HAL
+ * mode : control mode
+ * data :
+ *    PWM:  pwm number
+ *    GPIO: gpio id
+ *    PMIC: enum mt65xx_led_pmic
+ *    CUST: custom set brightness function pointer
+*/
+struct cust_mt65xx_led {
+	char                 *name;
+	enum mt65xx_led_mode  mode;
+	int                   data;
+        struct PWM_config config_data;
+};
+
+extern struct cust_mt65xx_led *get_cust_led_list(void);
+extern enum led_brightness get_cust_led_default_level(void);
+
+#endif
+

+ 12 - 0
target/X5/inc/cust_nand.h

@@ -0,0 +1,12 @@
+#ifndef _CUST_NAND_H_
+#define _CUST_NAND_H_
+
+#ifndef MTK_EMMC_SUPPORT
+#define NFI_DEFAULT_ACCESS_TIMING        (0x44333)
+#define NFI_DEFAULT_CS				(0)
+#define USE_AHB_MODE                	(1)
+#define CONFIG_CMD_NAND
+#define CFG_NAND_BOOT
+#endif
+
+#endif

+ 112 - 0
target/X5/inc/nand_device_list.h

@@ -0,0 +1,112 @@
+
+#ifndef __NAND_DEVICE_LIST_H__
+#define __NAND_DEVICE_LIST_H__
+
+#define NAND_MAX_ID		5
+#define CHIP_CNT		2
+#define P_SIZE		2048
+#define P_PER_BLK		64
+#define C_SIZE		512
+#define RAMDOM_READ		(1<<0)
+#define CACHE_READ		(1<<1)
+
+#define RAND_TYPE_SAMSUNG 0
+#define RAND_TYPE_TOSHIBA 1
+#define RAND_TYPE_NONE 2
+
+#define READ_RETRY_MAX 10
+struct gFeature
+{
+	u32 address;
+	u32 feature;
+};
+
+enum readRetryType
+{
+	RTYPE_FEATURE,
+	RTYPE_PRECMD,
+	RTYPE_PARAPAGE,
+	RTYPE_HYNIX_16NM,
+	RTYPE_HYNIX
+};
+
+struct gFeatureSet
+{
+	u8 sfeatureCmd;
+	u8 gfeatureCmd;
+	u8 readRetryPreCmd;
+	u8 readRetryCnt;
+	u32 readRetryAddress;
+	u32 readRetryDefault;
+	u32 readRetryStart;
+	enum readRetryType rtype;
+	struct gFeature Interface;
+	struct gFeature Async_timing;
+};
+
+struct gRandConfig
+{
+	u8 type;
+	u32 seed[6];
+};
+
+enum pptbl
+{
+	MICRON_8K,
+	HYNIX_8K,
+	SANDISK_16K,
+};
+
+struct MLC_feature_set
+{
+	enum pptbl ptbl_idx;
+	struct gFeatureSet 	 FeatureSet;
+	struct gRandConfig   randConfig;
+};
+
+enum flashdev_vendor
+{
+	VEND_SAMSUNG,
+	VEND_MICRON,
+	VEND_TOSHIBA,
+	VEND_HYNIX,
+	VEND_SANDISK,
+	VEND_NONE,
+};
+
+enum flashdev_IOWidth
+{
+	IO_8BIT = 8,
+	IO_16BIT = 16,
+	IO_TOGGLEDDR = 9,
+	IO_TOGGLESDR = 10,
+	IO_ONFI = 12,
+};
+
+typedef struct
+{
+   u8 id[NAND_MAX_ID];
+   u8 id_length;
+   u8 addr_cycle;
+   enum flashdev_IOWidth iowidth;
+   u16 totalsize;
+   u16 blocksize;
+   u16 pagesize;
+   u16 sparesize;
+   u32 timmingsetting;
+   u32 s_acccon;
+   u32 s_acccon1;
+   u32 freq;
+   enum flashdev_vendor vendor;
+   u16 sectorsize;
+   u8 devciename[30];
+   u32 advancedmode;
+   struct MLC_feature_set feature_set;
+}flashdev_info,*pflashdev_info;
+
+static const flashdev_info gen_FlashTable[]={
+	{{0xAD,0xBC,0x90,0x55,0x54}, 5,5,IO_16BIT,512,128,2048,64,0x21014133, 0,0,0,VEND_NONE,512, "H9DA4GH4JJAMCR_4EM",0}, 
+	{{0xAD,0xBC,0x90,0x55,0x56}, 5,5,IO_16BIT,512,128,2048,64,0x21014133, 0,0,0,VEND_NONE,512, "H9TA4GH2GDMCPR ",0}, 
+};
+
+#endif

+ 25 - 0
target/X5/inc/oemkey.h

@@ -0,0 +1,25 @@
+#ifndef __OEMKEY__
+#define __OEMKEY__
+
+/* OEM_PUBK is set as the same as MTEE public key for convenience, but they can be different */
+/* OEM_PUBK will be used to verify oemkeystore, and use oemkeystore to verify images */
+#define OEM_PUBK_SZ 256
+
+#define OEM_PUBK          0xDA, 0xCD, 0x8B, 0x5F, 0xDA, 0x8A, 0x76, 0x6F, 0xB7, 0xBC, 0xAA, 0x43, 0xF0, 0xB1, 0x69, 0x15, \
+                          0xCE, 0x7B, 0x47, 0x71, 0x4F, 0x13, 0x95, 0xFD, 0xEB, 0xCF, 0x12, 0xA2, 0xD4, 0x11, 0x55, 0xB0, \
+                          0xFB, 0x58, 0x7A, 0x51, 0xFE, 0xCC, 0xCB, 0x4D, 0xDA, 0x1C, 0x8E, 0x5E, 0xB9, 0xEB, 0x69, 0xB8, \
+                          0x6D, 0xAF, 0x2C, 0x62, 0x0F, 0x6C, 0x27, 0x35, 0x21, 0x5A, 0x5F, 0x22, 0xC0, 0xB6, 0xCE, 0x37, \
+                          0x7A, 0xA0, 0xD0, 0x7E, 0xB3, 0x8E, 0xD3, 0x40, 0xB5, 0x62, 0x9F, 0xC2, 0x89, 0x04, 0x94, 0xB0, \
+                          0x78, 0xA6, 0x3D, 0x6D, 0x07, 0xFD, 0xEA, 0xCD, 0xBE, 0x3E, 0x7F, 0x27, 0xFD, 0xE4, 0xB1, 0x43, \
+                          0xF4, 0x9D, 0xB4, 0x97, 0x14, 0x37, 0xE6, 0xD0, 0x0D, 0x9E, 0x18, 0xB5, 0x6F, 0x02, 0xDA, 0xBE, \
+                          0xB0, 0x00, 0x0B, 0x6E, 0x79, 0x51, 0x6D, 0x0C, 0x80, 0x74, 0xB5, 0xA4, 0x25, 0x69, 0xFD, 0x0D, \
+                          0x91, 0x96, 0x65, 0x5D, 0x2A, 0x40, 0x30, 0xD4, 0x2D, 0xFE, 0x05, 0xE9, 0xF6, 0x48, 0x83, 0xE6, \
+                          0xD5, 0xF7, 0x9A, 0x5B, 0xFA, 0x3E, 0x70, 0x14, 0xC9, 0xA6, 0x28, 0x53, 0xDC, 0x1F, 0x21, 0xD5, \
+                          0xD6, 0x26, 0xF4, 0xD0, 0x84, 0x6D, 0xB1, 0x64, 0x52, 0x18, 0x7D, 0xD7, 0x76, 0xE8, 0x88, 0x6B, \
+                          0x48, 0xC2, 0x10, 0xC9, 0xE2, 0x08, 0x05, 0x9E, 0x7C, 0xAF, 0xC9, 0x97, 0xFD, 0x2C, 0xA2, 0x10, \
+                          0x77, 0x5C, 0x1A, 0x5D, 0x9A, 0xA2, 0x61, 0x25, 0x2F, 0xB9, 0x75, 0x26, 0x8D, 0x97, 0x0C, 0x62, \
+                          0x73, 0x38, 0x71, 0xD5, 0x78, 0x14, 0x09, 0x8A, 0x45, 0x3D, 0xF9, 0x2B, 0xC6, 0xCA, 0x19, 0x02, \
+                          0x5C, 0xD9, 0xD4, 0x30, 0xF0, 0x2E, 0xE4, 0x6F, 0x80, 0xDE, 0x6C, 0x63, 0xEA, 0x80, 0x2B, 0xEF, \
+                          0x90, 0x67, 0x3A, 0xAC, 0x4C, 0x66, 0x67, 0xF2, 0x88, 0x3F, 0xB4, 0x50, 0x1F, 0xA7, 0x74, 0x55
+
+#endif /* __OEMKEY__ */

+ 20 - 0
target/X5/include/target/board.h

@@ -0,0 +1,20 @@
+#ifndef __BOARD_H
+#define __BOARD_H
+
+#define CONFIG_CFB_CONSOLE
+#define CFB_CONSOLE_ON
+
+#define CONFIG_SYS_PROMPT               "LK> "
+#define CONFIG_SYS_CBSIZE               256  		 /* Console I/O Buffer Size */
+
+/* Print Buffer Size */
+#define CONFIG_SYS_PBSIZE               (CONFIG_SYS_CBSIZE + sizeof(CONFIG_SYS_PROMPT) + 16)
+
+//Project specific header file
+#define CFG_DISPLAY_WIDTH       (DISP_GetScreenWidth())
+#define CFG_DISPLAY_HEIGHT      (DISP_GetScreenHeight())
+#define CFG_DISPLAY_BPP         (DISP_GetScreenBpp())
+
+//#define CFG_POWER_CHARGING
+
+#endif

+ 97 - 0
target/X5/include/target/cust_battery.h

@@ -0,0 +1,97 @@
+#ifndef _CUST_BAT_H_
+#define _CUST_BAT_H_
+
+#include <platform/mt_typedefs.h>
+
+typedef enum
+{
+	Cust_CC_1600MA = 0x0,
+	Cust_CC_1500MA = 0x1,
+	Cust_CC_1400MA = 0x2,
+	Cust_CC_1300MA = 0x3,
+	Cust_CC_1200MA = 0x4,
+	Cust_CC_1100MA = 0x5,
+	Cust_CC_1000MA = 0x6,
+	Cust_CC_900MA  = 0x7,
+	Cust_CC_800MA  = 0x8,
+	Cust_CC_700MA  = 0x9,
+	Cust_CC_650MA  = 0xA,
+	Cust_CC_550MA  = 0xB,
+	Cust_CC_450MA  = 0xC,
+	Cust_CC_400MA  = 0xD,
+	Cust_CC_200MA  = 0xE,
+	Cust_CC_70MA   = 0xF,
+	Cust_CC_0MA    = 0xDD
+}cust_charging_current_enum;
+
+typedef struct{	
+	unsigned int BattVolt;
+	unsigned int BattPercent;
+}VBAT_TO_PERCENT;
+
+/* Battery Temperature Protection */
+#define MAX_CHARGE_TEMPERATURE  50
+#define MIN_CHARGE_TEMPERATURE  0
+#define ERR_CHARGE_TEMPERATURE  0xFF
+
+/* Recharging Battery Voltage */
+#define RECHARGING_VOLTAGE      4110
+
+/* Charging Current Setting */
+//#define USB_CHARGER_CURRENT					Cust_CC_450MA
+#define USB_CHARGER_CURRENT					Cust_CC_900MA
+//#define AC_CHARGER_CURRENT					Cust_CC_650MA
+#define AC_CHARGER_CURRENT					Cust_CC_1200MA		
+
+/* Battery Meter Solution */
+#define CONFIG_ADC_SOLUTION 	1
+
+/* Battery Voltage and Percentage Mapping Table */
+VBAT_TO_PERCENT Batt_VoltToPercent_Table[] = {
+	/*BattVolt,BattPercent*/
+	{3400,0},
+	{3686,10},
+	{3740,20},
+	{3771,30},
+	{3789,40},
+	{3820,50},
+	{3873,60},
+	{3943,70},
+	{4013,80},
+	{4100,90},
+	{4189,100},
+};
+
+/* Precise Tunning */
+//#define BATTERY_AVERAGE_SIZE 	600
+//#define BATTERY_AVERAGE_SIZE 	60
+#define BATTERY_AVERAGE_SIZE 	30 //fixed value
+#define CHARGING_IDLE_MODE	 1
+#define CHARGING_PICTURE	 1
+
+/* Common setting */
+#define R_CURRENT_SENSE 2				// 0.2 Ohm
+#define R_BAT_SENSE 4					// times of voltage
+#define R_I_SENSE 4						// times of voltage
+#define R_CHARGER_1 330
+#define R_CHARGER_2 39
+#define R_CHARGER_SENSE ((R_CHARGER_1+R_CHARGER_2)/R_CHARGER_2)	// times of voltage
+#define V_CHARGER_MAX 6500				// 6.5 V
+#define V_CHARGER_MIN 4400				// 4.4 V
+#define V_CHARGER_ENABLE 0				// 1:ON , 0:OFF
+#define BACKLIGHT_KEY 10					// camera key
+
+/* Teperature related setting */
+#define RBAT_PULL_UP_R             16900
+#define RBAT_PULL_DOWN_R	   27000
+#define RBAT_PULL_UP_VOLT          1800
+#define TBAT_OVER_CRITICAL_LOW     68237
+//#define TBAT_OVER_CRITICAL_LOW     483954
+#define BAT_TEMP_PROTECT_ENABLE    1
+#define BAT_NTC_10 1
+#define BAT_NTC_47 0
+
+/* The option of new charging animation */
+#define ANIMATION_NEW
+
+#endif /* _CUST_BAT_H_ */ 

+ 712 - 0
target/X5/include/target/cust_display.h

@@ -0,0 +1,712 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2008
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*
+
+// new animation parameters example:WVGA (480*800)
+// A , start point of first number rectangle
+// B , left_top point of battery_capacity fill_in rectangle
+// c , left_bottom point of battery_capacity fill_in rectangle
+
+// battery capacity rectangle
+#define CAPACITY_LEFT                (172) // CAPACITY_LEFT = B.x = 172
+#define CAPACITY_TOP                 (330) // CAPACITY_TOP = B.y = 330
+#define CAPACITY_RIGHT               (307) // CAPACITY_RIGHT = B.x + fill_line.w = 172 + 135
+#define CAPACITY_BOTTOM              (546) // CAPACITY_BOTTOM  = C.y = 546
+
+// first number rectangle
+#define NUMBER_LEFT                  (178) // NUMBER_LEFT = A.x
+#define NUMBER_TOP                   (190) // NUMBER_TOP  = A.y
+#define NUMBER_RIGHT                 (216) // NUMBER_RIGHT = A.x + num.w = 178 + 38
+#define NUMBER_BOTTOM                (244) // NUMBER_BOTTOM = A.y + num.h = 190 + 54
+
+// %  rectangle
+#define PERCENT_LEFT                 (254) // PERCENT_LEFT = A.x + 2*num.w = 178 + 2*38
+#define PERCENT_TOP                  (190) // PERCENT_TOP  = A.y
+#define PERCENT_RIGHT                (302) // PERCENT_LEFT = A.x + 2*num.w +(%).w 
+#define PERCENT_BOTTOM               (244) // PERCENT_BOTTOM = A.y + (%).h = 190 + 54
+
+// top animation part
+#define TOP_ANIMATION_LEFT           (172) // TOP_ANIMATION_LEFT = B.x
+#define TOP_ANIMATION_TOP            (100) // 100 
+#define TOP_ANIMATION_RIGHT          (307) // TOP_ANIMATION_LEFT = B.x + fill_line.w = 172 + 135
+#define TOP_ANIMATION_BOTTOM         (124) // TOP_ANIMATION_BOTTOM = TOP_ANIMATION_TOP + fill_line.h = 100 + 24
+
+*/
+
+
+#ifndef __CUST_DISPLAY_H__
+#define __CUST_DISPLAY_H__
+
+// color
+#define BAR_OCCUPIED_COLOR  (0xFF00FF00)    // Green
+#define BAR_EMPTY_COLOR     (0xFFFFFFFF)    // White
+#define BAR_BG_COLOR        (0xFF000000)    // Black
+
+// LOGO number
+#define ANIM_V0_LOGO_NUM   5            // version 0: show 4 recatangle growing animation without battery number
+#define ANIM_V1_LOGO_NUM   39           // version 1: show wave animation with  battery number 
+#define ANIM_V2_LOGO_NUM   86           // version 2: show wireless charging animation      
+
+// Common LOGO index
+#define BOOT_LOGO_INDEX   0 
+#define KERNEL_LOGO_INDEX   38 
+
+
+#define ANIM_V0_BACKGROUND_INDEX   1 
+#define ANIM_V1_BACKGROUND_INDEX   35
+ 
+ 
+#define LOW_BATTERY_INDEX   2 
+#define CHARGER_OV_INDEX   3 
+#define FULL_BATTERY_INDEX   37 
+
+// version 1: show wave animation with  battery number 
+
+// NUMBER LOGO INDEX
+#define NUMBER_PIC_START_0   4 
+#define NUMBER_PIC_PERCENT   14 
+
+// DYNAMIC ANIMATION LOGO INDEX
+#define BAT_ANIM_START_0   15 
+
+// LOW BATTERY(0~10%) ANIMATION LOGO
+#define LOW_BAT_ANIM_START_0    25 
+
+#define ANIM_LINE_INDEX   36 
+
+
+// version 2: show wireless charging animation logo index
+
+#define V2_NUM_START_0_INDEX  57  
+#define V2_NUM_PERCENT_INDEX  67 
+ 
+#define V2_BAT_0_10_START_INDEX     68  
+#define V2_BAT_10_40_START_INDEX    72 
+#define V2_BAT_40_80_START_INDEX    76 
+#define V2_BAT_80_100_START_NDEX   80
+
+#define V2_BAT_0_INDEX   84
+#define V2_BAT_100_INDEX   85
+
+// show fast charging animation logo index
+
+#define FAST_CHARGING_BAT_100_INDEX   39
+#define FAST_CHARGING_BAT_START_0_INDEX   40
+
+#define FAST_CHARGING_NUM_START_0_INDEX   46
+#define FAST_CHARGING_NUM_PERCENT_INDEX   56
+
+#if defined(FHD) || defined(CU_FHD) || defined(CMCC_FHD) || defined(CT_FHD) || defined(CMCC_LTE_FHD)
+	// fhd 1080*1920
+	
+	// battery capacity rectangle
+	#define CAPACITY_LEFT                (387) // battery capacity center
+	#define CAPACITY_TOP                 (802)
+	#define CAPACITY_RIGHT               (691)
+	#define CAPACITY_BOTTOM              (1292)
+
+	// first number rectangle
+	#define NUMBER_LEFT                  (351+84) // number
+	#define NUMBER_TOP                   (479)
+	#define NUMBER_RIGHT                 (435+84)
+	#define NUMBER_BOTTOM                (600)
+
+	// %  rectangle
+	#define PERCENT_LEFT                 (519+84) // percent number_left + 2*number_width
+	#define PERCENT_TOP                  (479)
+	#define PERCENT_RIGHT                (627+84)
+	#define PERCENT_BOTTOM               (600)
+
+	// top animation part
+	#define TOP_ANIMATION_LEFT           (387) // top animation
+	#define TOP_ANIMATION_TOP            (100)
+	#define TOP_ANIMATION_RIGHT          (691)
+	#define TOP_ANIMATION_BOTTOM         (152)
+
+	// for old animation
+	#define BAR_LEFT            (470)
+	#define BAR_TOP             (356)
+	#define BAR_RIGHT           (610)
+	#define BAR_BOTTOM          (678)
+
+#elif defined(WQHD) || defined(CU_WQHD) || defined(CMCC_WQHD) || defined(CT_WQHD) || defined(CMCC_LTE_WQHD)
+	// wqhd 1440*2560
+
+	// battery capacity rectangle
+	#define CAPACITY_LEFT                (556) // battery capacity center
+	#define CAPACITY_TOP                 (1112)
+	#define CAPACITY_RIGHT               (882)
+	#define CAPACITY_BOTTOM              (1630)
+
+	// first number rectangle
+	#define NUMBER_LEFT                  (570) // number
+	#define NUMBER_TOP                   (770)
+	#define NUMBER_RIGHT                 (660)
+	#define NUMBER_BOTTOM                (898)
+
+	// %  rectangle
+	#define PERCENT_LEFT                 (750) // percent number_left + 2*number_width
+	#define PERCENT_TOP                  (770)
+	#define PERCENT_RIGHT                (864)
+	#define PERCENT_BOTTOM               (898)
+
+	// top animation part
+	#define TOP_ANIMATION_LEFT           (556) // top animation
+	#define TOP_ANIMATION_TOP            (100)
+	#define TOP_ANIMATION_RIGHT          (882)
+	#define TOP_ANIMATION_BOTTOM         (158)
+
+	// for old animation
+	#define BAR_LEFT            (443)
+	#define BAR_TOP             (337)
+	#define BAR_RIGHT           (574)
+	#define BAR_BOTTOM          (641)
+
+#elif defined(HD720) || defined(CU_HD720) || defined(CMCC_HD720) || defined(CT_HD720) || defined(CMCC_LTE_HD720)
+	// hd720 720*1280
+
+	// battery capacity rectangle
+	#define CAPACITY_LEFT                (278) // battery capacity center
+	#define CAPACITY_TOP                 (556)
+	#define CAPACITY_RIGHT               (441)
+	#define CAPACITY_BOTTOM              (817)
+
+	// first number rectangle
+	#define NUMBER_LEFT                  (290) // number
+	#define NUMBER_TOP                   (386)
+	#define NUMBER_RIGHT                 (335)
+	#define NUMBER_BOTTOM                (450)
+
+	// %  rectangle
+	#define PERCENT_LEFT                 (380) // percent number_left + 2*number_width
+	#define PERCENT_TOP                  (386)
+	#define PERCENT_RIGHT                (437)
+	#define PERCENT_BOTTOM               (450)
+
+	// top animation part
+	#define TOP_ANIMATION_LEFT           (278) // top animation
+	#define TOP_ANIMATION_TOP            (100)
+	#define TOP_ANIMATION_RIGHT          (441)
+	#define TOP_ANIMATION_BOTTOM         (129)
+
+	// for old animation
+	#define BAR_LEFT            (313)
+	#define BAR_TOP             (238)
+	#define BAR_RIGHT           (406)
+	#define BAR_BOTTOM          (453)
+
+#elif defined(FWVGA) || defined(CU_FWVGA) || defined(CMCC_FWVGA) || defined(CT_FWVGA) || defined(CMCC_LTE_FWVGA)
+	// fwvga 480*854
+
+	// battery capacity rectangle
+	#define CAPACITY_LEFT                (172) // battery capacity center
+	#define CAPACITY_TOP                 (357)
+	#define CAPACITY_RIGHT               (307)
+	#define CAPACITY_BOTTOM              (573)
+
+	// first number rectangle
+	#define NUMBER_LEFT                  (172) // number
+	#define NUMBER_TOP                   (213)
+	#define NUMBER_RIGHT                 (210)
+	#define NUMBER_BOTTOM                (267)
+
+	// %  rectangle
+	#define PERCENT_LEFT                 (248) // percent number_left + 2*number_width
+	#define PERCENT_TOP                  (213)
+	#define PERCENT_RIGHT                (296)
+	#define PERCENT_BOTTOM               (267)
+
+	// top animation part
+	#define TOP_ANIMATION_LEFT           (172) // top animation
+	#define TOP_ANIMATION_TOP            (100)
+	#define TOP_ANIMATION_RIGHT          (307)
+	#define TOP_ANIMATION_BOTTOM         (124)
+
+	// for old animation
+	#define BAR_LEFT            (184)
+	#define BAR_TOP             (227)
+	#define BAR_RIGHT           (294)
+	#define BAR_BOTTOM          (437)
+
+#elif defined(QHD) || defined(CU_QHD) || defined(CMCC_QHD) || defined(CT_QHD) || defined(CMCC_LTE_QHD)
+	// qhd 540*960
+
+	// battery capacity rectangle
+	#define CAPACITY_LEFT                (202) // battery capacity center
+	#define CAPACITY_TOP                 (410)
+	#define CAPACITY_RIGHT               (337)
+	#define CAPACITY_BOTTOM              (626)
+
+	// first number rectangle
+	#define NUMBER_LEFT                  (202) // number
+	#define NUMBER_TOP                   (266)
+	#define NUMBER_RIGHT                 (240)
+	#define NUMBER_BOTTOM                (320)
+
+	// %  rectangle
+	#define PERCENT_LEFT                 (278) // percent number_left + 2*number_width
+	#define PERCENT_TOP                  (266)
+	#define PERCENT_RIGHT                (326)
+	#define PERCENT_BOTTOM               (320)
+
+	// top animation part
+	#define TOP_ANIMATION_LEFT           (202) // top animation
+	#define TOP_ANIMATION_TOP            (100)
+	#define TOP_ANIMATION_RIGHT          (337)
+	#define TOP_ANIMATION_BOTTOM         (124)
+
+	// for old animation
+	#define BAR_LEFT            (235)
+	#define BAR_TOP             (179)
+	#define BAR_RIGHT           (305)
+	#define BAR_BOTTOM          (340)
+
+#elif defined(WVGA) || defined(CU_WVGA) || defined(CMCC_WVGA) || defined(CT_WVGA) || defined(CMCC_LTE_WVGA)
+	// default wvga 480*800
+
+	// battery capacity rectangle
+	#define CAPACITY_LEFT                (172) // battery capacity center
+	#define CAPACITY_TOP                 (330)
+	#define CAPACITY_RIGHT               (307)
+	#define CAPACITY_BOTTOM              (546)
+
+	// first number rectangle
+	#define NUMBER_LEFT                  (178) // number
+	#define NUMBER_TOP                   (190)
+	#define NUMBER_RIGHT                 (216)
+	#define NUMBER_BOTTOM                (244)
+
+	// %  rectangle
+	#define PERCENT_LEFT                 (254) // percent number_left + 2*number_width
+	#define PERCENT_TOP                  (190)
+	#define PERCENT_RIGHT                (302)
+	#define PERCENT_BOTTOM               (244)
+
+	// top animation part
+	#define TOP_ANIMATION_LEFT           (172) // top animation
+	#define TOP_ANIMATION_TOP            (100)
+	#define TOP_ANIMATION_RIGHT          (307)
+	#define TOP_ANIMATION_BOTTOM         (124)
+
+	// for old animation
+	#define BAR_LEFT            (209)
+	#define BAR_TOP             (149)
+	#define BAR_RIGHT           (271)
+	#define BAR_BOTTOM          (282)
+
+#elif defined(HVGA) || defined(CU_HVGA) || defined(CMCC_HVGA) || defined(CT_HVGA) || defined(CMCC_LTE_HVGA)
+
+	// hvga 320*480
+
+	// battery capacity rectangle
+	#define CAPACITY_LEFT                (109) // battery capacity center
+	#define CAPACITY_TOP                 (189)
+	#define CAPACITY_RIGHT               (211)
+	#define CAPACITY_BOTTOM              (350)
+
+	// first number rectangle
+	#define NUMBER_LEFT                  (126) // number
+	#define NUMBER_TOP                   (95)
+	#define NUMBER_RIGHT                 (153)
+	#define NUMBER_BOTTOM                (131)
+
+	// %  rectangle
+	#define PERCENT_LEFT                 (180) // percent number_left + 2*number_width
+	#define PERCENT_TOP                  (95)
+	#define PERCENT_RIGHT                (212)
+	#define PERCENT_BOTTOM               (131)
+
+	// top animation part
+	#define TOP_ANIMATION_LEFT           (109) // top animation
+	#define TOP_ANIMATION_TOP            (100)
+	#define TOP_ANIMATION_RIGHT          (211)
+	#define TOP_ANIMATION_BOTTOM         (118)
+
+	// for old animation
+	#define BAR_LEFT            (129)
+	#define BAR_TOP             (128)
+	#define BAR_RIGHT           (190)
+	#define BAR_BOTTOM          (245)
+#elif defined(QVGA) || defined(CU_QVGA) || defined(CMCC_QVGA) || defined(CT_QVGA) || defined(CMCC_LTE_QVGA)
+
+	// hvga 320*480
+
+	// battery capacity rectangle
+	#define CAPACITY_LEFT                (82) // battery capacity center
+	#define CAPACITY_TOP                 (124)
+	#define CAPACITY_RIGHT               (158)
+	#define CAPACITY_BOTTOM              (241)
+
+	// first number rectangle
+	#define NUMBER_LEFT                  (93) // number
+	#define NUMBER_TOP                   (50)
+	#define NUMBER_RIGHT                 (109)
+	#define NUMBER_BOTTOM                (73)
+
+	// %  rectangle
+	#define PERCENT_LEFT                 (125) // percent number_left + 2*number_width
+	#define PERCENT_TOP                  (50)
+	#define PERCENT_RIGHT                (145)
+	#define PERCENT_BOTTOM               (73)
+
+	// top animation part
+	#define TOP_ANIMATION_LEFT           (82) // top animation
+	#define TOP_ANIMATION_TOP            (100)
+	#define TOP_ANIMATION_RIGHT          (158)
+	#define TOP_ANIMATION_BOTTOM         (113)
+
+	// for old animation
+	#define BAR_LEFT            (97)
+	#define BAR_TOP             (96)
+	#define BAR_RIGHT           (140)
+	#define BAR_BOTTOM          (184)
+	
+#elif defined(WSVGA)
+	// wsvga 600*1024
+
+	// battery capacity rectangle
+	#define CAPACITY_LEFT                (232) // battery capacity center
+	#define CAPACITY_TOP                 (442)
+	#define CAPACITY_RIGHT               (367)
+	#define CAPACITY_BOTTOM              (658)
+
+	// first number rectangle
+	#define NUMBER_LEFT                  (250) // number
+	#define NUMBER_TOP                   (300)
+	#define NUMBER_RIGHT                 (288)
+	#define NUMBER_BOTTOM                (354)
+
+	// %  rectangle
+	#define PERCENT_LEFT                 (326) // percent number_left + 2*number_width
+	#define PERCENT_TOP                  (300)
+	#define PERCENT_RIGHT                (374)
+	#define PERCENT_BOTTOM               (354)
+
+	// top animation part
+	#define TOP_ANIMATION_LEFT           (232) // top animation
+	#define TOP_ANIMATION_TOP            (100)
+	#define TOP_ANIMATION_RIGHT          (367)
+	#define TOP_ANIMATION_BOTTOM         (124)
+
+	// for old animation
+	#define BAR_LEFT            (260)
+	#define BAR_TOP             (190)
+	#define BAR_RIGHT           (338)
+	#define BAR_BOTTOM          (360)
+
+#elif defined(WSVGANL)
+	// wsvganl 1024*600
+
+	// battery capacity rectangle
+	#define CAPACITY_LEFT                (444) // battery capacity center
+	#define CAPACITY_TOP                 (230)
+	#define CAPACITY_RIGHT               (579) // 444 + 135
+	#define CAPACITY_BOTTOM              (446)
+
+	// first number rectangle
+	#define NUMBER_LEFT                  (466) // number
+	#define NUMBER_TOP                   (90)
+	#define NUMBER_RIGHT                 (504) // 466 + 38
+	#define NUMBER_BOTTOM                (144) // 90 + 54
+
+	// %  rectangle
+	#define PERCENT_LEFT                 (542) // percent number_left + 2*number_width
+	#define PERCENT_TOP                  (90)
+	#define PERCENT_RIGHT                (590)
+	#define PERCENT_BOTTOM               (144)
+
+	// top animation part
+	#define TOP_ANIMATION_LEFT           (444) // top animation
+	#define TOP_ANIMATION_TOP            (100)
+	#define TOP_ANIMATION_RIGHT          (579)
+	#define TOP_ANIMATION_BOTTOM         (124)
+
+	// for old animation
+	#define BAR_LEFT            (414)
+	#define BAR_TOP             (186)
+	#define BAR_RIGHT           (608)
+	#define BAR_BOTTOM          (477)
+
+#elif defined(WXGANL)
+	// wxganl 1280*800
+
+	// battery capacity rectangle
+	#define CAPACITY_LEFT                (558) // battery capacity center
+	#define CAPACITY_TOP                 (265)
+	#define CAPACITY_RIGHT               (721) //558+163
+	#define CAPACITY_BOTTOM              (525)
+
+	#define NUMBER_LEFT                  (585) // number
+	#define NUMBER_TOP                   (95)
+	#define NUMBER_RIGHT                 (630)//585+45
+	#define NUMBER_BOTTOM                (159) //95+64
+
+	#define PERCENT_LEFT                 (675) // percent number_left + 2*number_width
+	#define PERCENT_TOP                  (95)
+	#define PERCENT_RIGHT                (732) //675+57
+	#define PERCENT_BOTTOM               (159)
+
+	#define TOP_ANIMATION_LEFT           (558) // top animation
+	#define TOP_ANIMATION_TOP            (100)
+	#define TOP_ANIMATION_RIGHT          (721)
+	#define TOP_ANIMATION_BOTTOM         (129)
+
+	// for old animation
+	#define BAR_LEFT            (525)
+	#define BAR_TOP             (250)
+	#define BAR_RIGHT           (755)
+	#define BAR_BOTTOM          (640)
+	
+#elif defined(WXGA)
+	// wxga 800*1280
+
+	// battery capacity rectangle
+	#define CAPACITY_LEFT                (318) // battery capacity center
+	#define CAPACITY_TOP                 (556)
+	#define CAPACITY_RIGHT               (481) //318+163
+	#define CAPACITY_BOTTOM              (815)
+
+	#define NUMBER_LEFT                  (345) // number
+	#define NUMBER_TOP                   (385)
+	#define NUMBER_RIGHT                 (390) //345+45
+	#define NUMBER_BOTTOM                (449) //385+64
+
+	#define PERCENT_LEFT                 (435) // percent number_left + 2*number_width
+	#define PERCENT_TOP                  (385)
+	#define PERCENT_RIGHT                (492) //435+57
+	#define PERCENT_BOTTOM               (449)
+
+	#define TOP_ANIMATION_LEFT           (318) // top animation
+	#define TOP_ANIMATION_TOP            (100)
+	#define TOP_ANIMATION_RIGHT          (481)
+	#define TOP_ANIMATION_BOTTOM         (129)
+
+	// for old animation
+	#define BAR_LEFT            (348)
+	#define BAR_TOP             (238)
+	#define BAR_RIGHT           (453)
+	#define BAR_BOTTOM          (452)
+	
+#elif defined(WUXGANL)
+	// wuxganl 1920*1200
+
+	// battery capacity rectangle
+	#define CAPACITY_LEFT                (806) // battery capacity center
+	#define CAPACITY_TOP                 (443)
+	#define CAPACITY_RIGHT               (1110)
+	#define CAPACITY_BOTTOM              (929)
+
+	#define NUMBER_LEFT                  (855) // number
+	#define NUMBER_TOP                   (124)
+	#define NUMBER_RIGHT                 (939) //855+84
+	#define NUMBER_BOTTOM                (245)
+
+	#define PERCENT_LEFT                 (1023) // percent number_left + 2*number_width
+	#define PERCENT_TOP                  (124)
+	#define PERCENT_RIGHT                (1131) //1023+108
+	#define PERCENT_BOTTOM               (245)  //124+121
+
+	#define TOP_ANIMATION_LEFT           (806) // top animation
+	#define TOP_ANIMATION_TOP            (100)
+	#define TOP_ANIMATION_RIGHT          (1110) //806+304
+	#define TOP_ANIMATION_BOTTOM         (152)
+
+	// for old animation
+	#define BAR_LEFT            (890)
+	#define BAR_TOP             (357)
+	#define BAR_RIGHT           (1030)
+	#define BAR_BOTTOM          (678)
+	
+#elif defined(WUXGA) || defined(CU_WUXGA)
+	// wuxga 1200*1920
+
+	// battery capacity rectangle
+	#define CAPACITY_LEFT                (447) // battery capacity center
+	#define CAPACITY_TOP                 (803)
+	#define CAPACITY_RIGHT               (751)
+	#define CAPACITY_BOTTOM              (1289)
+
+	#define NUMBER_LEFT                  (494) // number
+	#define NUMBER_TOP                   (481)
+	#define NUMBER_RIGHT                 (578)//494+84
+	#define NUMBER_BOTTOM                (602) //481+121
+
+	#define PERCENT_LEFT                 (662) // percent number_left + 2*number_width
+	#define PERCENT_TOP                  (481)
+	#define PERCENT_RIGHT                (770) //662+108
+	#define PERCENT_BOTTOM               (602) //481+121
+
+	#define TOP_ANIMATION_LEFT           (447) // top animation
+	#define TOP_ANIMATION_TOP            (100)
+	#define TOP_ANIMATION_RIGHT          (751)
+	#define TOP_ANIMATION_BOTTOM         (152)
+
+	// for old animation
+	#define BAR_LEFT            (529)
+	#define BAR_TOP             (357)
+	#define BAR_RIGHT           (672)
+	#define BAR_BOTTOM          (680)
+	
+#elif defined(XGA)
+	// xga 768*1024
+
+	// battery capacity rectangle
+	#define CAPACITY_LEFT                (316) // battery capacity center
+	#define CAPACITY_TOP                 (442)
+	#define CAPACITY_RIGHT               (451)
+	#define CAPACITY_BOTTOM              (658)
+
+	#define NUMBER_LEFT                  (338) // number
+	#define NUMBER_TOP                   (300)
+	#define NUMBER_RIGHT                 (376)
+	#define NUMBER_BOTTOM                (354)
+
+	#define PERCENT_LEFT                 (414) // percent number_left + 2*number_width
+	#define PERCENT_TOP                  (300)
+	#define PERCENT_RIGHT                (462)
+	#define PERCENT_BOTTOM               (354)
+
+	#define TOP_ANIMATION_LEFT           (316) // top animation
+	#define TOP_ANIMATION_TOP            (100)
+	#define TOP_ANIMATION_RIGHT          (451)
+	#define TOP_ANIMATION_BOTTOM         (124)
+
+	// for old animation
+	#define BAR_LEFT            (334)
+	#define BAR_TOP             (243)
+	#define BAR_RIGHT           (434)
+	#define BAR_BOTTOM          (463)
+	
+#elif defined(XGANL)
+	// xganl 1024*768
+
+	// battery capacity rectangle
+	#define CAPACITY_LEFT                (444) // battery capacity center
+	#define CAPACITY_TOP                 (314)	
+	#define CAPACITY_RIGHT               (579)
+	#define CAPACITY_BOTTOM              (530)
+
+	#define NUMBER_LEFT                  (467) // number
+	#define NUMBER_TOP                   (170)
+	#define NUMBER_RIGHT                 (505)
+	#define NUMBER_BOTTOM                (224)
+
+	#define PERCENT_LEFT                 (543) // percent number_left + 2*number_width
+	#define PERCENT_TOP                  (170)
+	#define PERCENT_RIGHT                (591)
+	#define PERCENT_BOTTOM               (224)
+
+	#define TOP_ANIMATION_LEFT           (444) // top animation
+	#define TOP_ANIMATION_TOP            (100)
+	#define TOP_ANIMATION_RIGHT          (579)
+	#define TOP_ANIMATION_BOTTOM         (124)
+
+	// for old animation
+	#define BAR_LEFT            (486)
+	#define BAR_TOP             (292)
+	#define BAR_RIGHT           (590)
+	#define BAR_BOTTOM          (506) 
+
+#elif defined(QXGA)
+	// qxga 1536x2048
+	
+		// battery capacity rectangle
+	#define CAPACITY_LEFT                (605) // battery capacity center
+	#define CAPACITY_TOP                 (857)	
+	#define CAPACITY_RIGHT               (929)
+	#define CAPACITY_BOTTOM              (1375)
+
+	#define NUMBER_LEFT                  (662) // number
+	#define NUMBER_TOP                   (517)
+	#define NUMBER_RIGHT                 (756)
+	#define NUMBER_BOTTOM                (647)
+
+	#define PERCENT_LEFT                 (850) // percent number_left + 2*number_width
+	#define PERCENT_TOP                  (517)
+	#define PERCENT_RIGHT                (968)
+	#define PERCENT_BOTTOM               (647)
+
+	#define TOP_ANIMATION_LEFT           (605) // top animation
+	#define TOP_ANIMATION_TOP            (100)
+	#define TOP_ANIMATION_RIGHT          (929)
+	#define TOP_ANIMATION_BOTTOM         (155)
+
+	// for old animation
+	#define BAR_LEFT            (693)
+	#define BAR_TOP             (381)
+	#define BAR_RIGHT           (844)
+	#define BAR_BOTTOM          (725) 
+
+#else 
+
+	// default wvga 480*800
+
+	// battery capacity rectangle
+	#define CAPACITY_LEFT                (172) // battery capacity center
+	#define CAPACITY_TOP                 (330)
+	#define CAPACITY_RIGHT               (307)
+	#define CAPACITY_BOTTOM              (546)
+
+	// first number rectangle
+	#define NUMBER_LEFT                  (178) // number
+	#define NUMBER_TOP                   (190)
+	#define NUMBER_RIGHT                 (216)
+	#define NUMBER_BOTTOM                (244)
+
+	// %  rectangle
+	#define PERCENT_LEFT                 (254) // percent number_left + 2*number_width
+	#define PERCENT_TOP                  (190)
+	#define PERCENT_RIGHT                (302)
+	#define PERCENT_BOTTOM               (244)
+
+	// top animation part
+	#define TOP_ANIMATION_LEFT           (172) // top animation
+	#define TOP_ANIMATION_TOP            (100)
+	#define TOP_ANIMATION_RIGHT          (307)
+	#define TOP_ANIMATION_BOTTOM         (124)
+
+	// for old animation
+	#define BAR_LEFT            (209)
+	#define BAR_TOP             (149)
+	#define BAR_RIGHT           (271)
+	#define BAR_BOTTOM          (282)
+
+#endif
+
+/* The option of new charging animation */
+#define ANIMATION_NEW
+
+#endif // __CUST_DISPLAY_H__

+ 28 - 0
target/X5/include/target/cust_key.h

@@ -0,0 +1,28 @@
+#ifndef __CUST_KEY_H__
+#define __CUST_KEY_H__
+
+#include<cust_kpd.h>
+
+#define MT65XX_META_KEY		42	/* KEY_2 */
+/* MTK_PMIC_RST_KEY is defined in cust_kpd.h */
+#define MT_CAMERA_KEY 		9
+
+#ifdef MT65XX_RECOVERY_KEY
+#define MT65XX_BOOT_MENU_KEY       MT65XX_RECOVERY_KEY     /* KEY_VOLUMEUP */
+#else
+#define MT65XX_BOOT_MENU_KEY       17     /* KEY_VOLUMEUP */
+#endif
+
+#define MT65XX_MENU_SELECT_KEY     MT65XX_BOOT_MENU_KEY
+
+#ifdef MT65XX_FACTORY_KEY
+#define MT65XX_MENU_OK_KEY         MT65XX_FACTORY_KEY     /* KEY_VOLUMEDOWN */
+#else
+#ifdef MT6580_USE_FCHR_ENB_KEY		
+#define MT65XX_MENU_OK_KEY         9     /* KEY_VOLUMEDOWN */
+#else
+#define MT65XX_MENU_OK_KEY         0     /* KEY_VOLUMEDOWN */	
+#endif
+#endif
+
+#endif /* __CUST_KEY_H__ */

+ 87 - 0
target/X5/include/target/cust_msdc.h

@@ -0,0 +1,87 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2010
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+#ifndef CUST_MSDC_H
+#define CUST_MSDC_H
+
+#include "msdc_cfg.h"
+
+#if (defined(MMC_MSDC_DRV_CTP) && !defined(FPGA_PLATFORM))
+#define MSDC_MAX_NUM            (2)
+#else
+#define MSDC_MAX_NUM            (1)
+#endif
+
+#define MSDC_CD_PIN_EN      (1 << 0)  /* card detection pin is wired   */
+#define MSDC_WP_PIN_EN      (1 << 1)  /* write protection pin is wired */
+#define MSDC_RST_PIN_EN     (1 << 2)  /* emmc reset pin is wired       */
+#define MSDC_SDIO_IRQ       (1 << 3)  /* use internal sdio irq (bus)   */
+#define MSDC_EXT_SDIO_IRQ   (1 << 4)  /* use external sdio irq         */
+#define MSDC_REMOVABLE      (1 << 5)  /* removable slot                */
+#define MSDC_SYS_SUSPEND    (1 << 6)  /* suspended by system           */
+#define MSDC_HIGHSPEED      (1 << 7)  /* high-speed mode support       */
+#define MSDC_UHS1           (1 << 8)  /* uhs-1 mode support            */
+#define MSDC_DDR            (1 << 9)  /* ddr mode support              */
+#define MSDC_HS200          (1 << 10) /* hs200 mode support(eMMC4.5)   */
+#define MSDC_HS400          (1 << 11) /* hs200 mode support(eMMC5.0)   */
+
+#define MSDC_SMPL_RISING        (0)
+#define MSDC_SMPL_FALLING       (1)
+#define MSDC_SMPL_SEPERATE      (2)
+
+
+struct msdc_cust {
+    unsigned char  clk_src;           /* host clock source             */
+    unsigned char  cmd_edge;          /* command latch edge            */
+    unsigned char  data_edge;         /* data latch edge               */
+    unsigned char  clk_drv;           /* clock pad driving             */
+    unsigned char  cmd_drv;           /* command pad driving           */
+    unsigned char  dat_drv;           /* data pad driving              */
+    unsigned char  rst_drv;           /* reset pin pad driving         */
+    unsigned char  ds_drv;            /* ds pad driving                */
+    unsigned char  clk_18v_drv;       /* clock pad driving             */
+    unsigned char  cmd_18v_drv;       /* command pad driving on 1.8V   */
+    unsigned char  dat_18v_drv;       /* data pad driving on 1.8V      */
+    unsigned char  data_pins;         /* data pins on 1.8V             */
+    unsigned int   data_offset;       /* data address offset           */
+    unsigned int   flags;             /* hardware capability flags     */
+};
+
+extern struct msdc_cust msdc_cap[MSDC_MAX_NUM];
+
+
+
+#endif /* end of _MSDC_CUST_H_ */
+

+ 41 - 0
target/X5/include/target/cust_rtc.h

@@ -0,0 +1,41 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2010. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ *
+ * The following software/firmware and/or related documentation ("MediaTek Software")
+ * have been modified by MediaTek Inc. All revisions are subject to any receiver's
+ * applicable license agreements with MediaTek Inc.
+ */
+
+#ifndef __CUST_RTC_H__
+#define __CUST_RTC_H__
+
+//#define RTC_2SEC_REBOOT_ENABLE     0
+
+#endif /* __CUST_RTC_H__ */

+ 14 - 0
target/X5/include/target/cust_usb.h

@@ -0,0 +1,14 @@
+#ifndef __CUST_USB_H__
+#define __CUST_USB_H__
+
+#define CONFIG_USBD_LANG	"0409"
+
+#define USB_VENDORID		(0x0E8D)
+#define USB_PRODUCTID		(0x201C)
+#define USB_VERSIONID		(0x0100)
+#define USB_MANUFACTURER	"MediaTek"
+#define USB_PRODUCT_NAME	"Android"
+#define FASTBOOT_DEVNAME	"fpga6580"
+#define SN_BUF_LEN		19
+
+#endif /* __CUST_USB_H__ */

+ 28 - 0
target/X5/include/target/debugconfig.h

@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2008 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __TARGET_DEBUGCONFIG_H
+#define __TARGET_DEBUGCONFIG_H
+
+#define DEBUG_UART 2
+
+#endif

+ 100 - 0
target/X5/init.c

@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2009, Google Inc.
+ * All rights reserved.
+ * Copyright (c) 2009-2012, Code Aurora Forum. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *  * Neither the name of 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 <reg.h>
+#include <target.h>
+#include <platform/mt_reg_base.h>
+#include <platform/mmc_core.h>
+#include <platform/boot_mode.h>
+#include <target/cust_key.h>
+#include <platform/mt_gpt.h>        // for get_timer()
+#include <platform/mt_rtc.h>        // for Check_RTC_PDN1_bit13(), Set_Clr_RTC_PDN1_bit13()
+#include <platform/mtk_key.h>       // for mtk_detect_key()
+
+
+extern void dmb(void);
+
+static void target_detect(void);
+
+void target_early_init(void)
+{
+
+}
+
+void target_init(void)
+{
+}
+
+unsigned board_machtype(void)
+{
+    return MACH_TYPE;
+}
+
+/* Do any target specific intialization needed before entering fastboot mode */
+void target_fastboot_init(void)
+{
+
+}
+
+extern BOOTMODE g_boot_mode;
+BOOL fastboot_trigger(void)
+{
+    ulong begin = get_timer(0);
+    dprintf(INFO,"\n Check FASTBOOT\n");
+
+/*Check Fastboot RTC bit*/
+#if 1
+    if(Check_RTC_PDN1_bit13())
+    {
+        dprintf(INFO,"[FASTBOOT] reboot to boot loader\n");
+        g_boot_mode = FASTBOOT;
+        Set_Clr_RTC_PDN1_bit13(false);
+        return TRUE;
+    }
+#endif
+
+    dprintf(INFO,"Wait 50ms for special keys\n");
+
+    while(get_timer(begin)<50)
+    {
+        if(mtk_detect_key(MT_CAMERA_KEY))
+        {
+            dprintf(INFO,"[FASTBOOT]Key Detect\n");
+            g_boot_mode = FASTBOOT;
+            return TRUE;
+        }
+    }
+        
+    return FALSE;
+}
+

+ 26 - 0
target/X5/power_off.c

@@ -0,0 +1,26 @@
+//#include <common.h>
+//#include <asm/arch/mt65xx.h>
+#include <debug.h>
+#include <platform/mt_typedefs.h>
+#include <platform/mt_rtc.h>
+#include <platform/mtk_wdt.h>
+
+extern kal_bool pmic_chrdet_status(void);
+
+#ifndef NO_POWER_OFF
+void mt6575_power_off(void)
+{
+	dprintf(CRITICAL, "mt_power_off\n");
+
+	/* pull PWRBB low */
+	rtc_bbpu_power_down();
+
+	while (1) {
+		dprintf(CRITICAL, "mt_power_off : check charger\n");
+		if (pmic_chrdet_status() == KAL_TRUE) {
+			mtk_arch_reset(0);
+			break;
+		}
+	}
+}
+#endif

+ 103 - 0
target/X5/rules.mk

@@ -0,0 +1,103 @@
+LOCAL_DIR := $(GET_LOCAL_DIR)
+
+DEFINES += BUILD_LK
+
+DEFINES += MTK_GPT_SCHEME_SUPPORT
+
+ifdef MTK_HEADER_SUPPORT
+  ifeq ($(strip $(MTK_HEADER_SUPPORT)),no)
+    DEFINES += SKIP_MTK_PARTITION_HEADER_CHECK
+  endif
+else
+  DEFINES += SKIP_MTK_PARTITION_HEADER_CHECK
+endif
+
+PLATFORM := mt6580
+
+MODULES += \
+	dev/keys \
+	lib/ptable \
+	dev/lcm \
+
+DUMMY_AP := no
+
+ifeq ($(DUMMY_AP), yes)
+MEMBASE := 0x90000000 # SDRAM
+else
+MEMBASE := 0x81E00000 # SDRAM
+endif
+
+ifeq ($(MTK_MLC_NAND_SUPPORT), yes)
+DEFINES += MTK_MLC_NAND_SUPPORT
+MEMSIZE := 0x00900000 # 9MB
+else ifeq ($(MTK_TLC_NAND_SUPPORT), yes)
+DEFINES += MTK_TLC_NAND_SUPPORT
+MEMSIZE := 0x00900000 # 9MB
+else
+MEMSIZE := 0x00400000 # 4MB
+endif
+
+
+SCRATCH_ADDR     := 0x85000000
+SCRATCH_SIZE     := 0x08000000 # 128MB
+
+HAVE_CACHE_PL310 := no
+MTK_LM_MODE := no
+MTK_FASTBOOT_SUPPORT := yes
+LK_PROFILING := yes
+DEVICE_TREE_SUPPORT := yes
+MTK_JTAG_SWITCH_SUPPORT := yes
+
+
+MACH_TYPE := mt6580
+
+DEFINES += \
+	MEMBASE=$(MEMBASE)\
+	SCRATCH_ADDR=$(SCRATCH_ADDR)\
+	SCRATCH_SIZE=$(SCRATCH_SIZE)\
+	MEMSIZE=$(MEMSIZE)
+
+ifneq ($(MTK_GOOGLE_TRUSTY_SUPPORT), yes)
+DEFINES += ENABLE_L2_SHARING
+endif
+
+ifeq ($(DUMMY_AP), yes)
+DEFINES += DUMMY_AP
+endif
+
+ifeq ($(HAVE_CACHE_PL310), yes)
+DEFINES += HAVE_CACHE_PL310
+endif
+
+ifeq ($(MTK_LM_MODE), yes)
+DEFINES += MTK_LM_MODE
+endif
+
+ifeq ($(DEVICE_TREE_SUPPORT), yes)
+DEFINES += DEVICE_TREE_SUPPORT
+endif
+
+ifeq ($(MTK_JTAG_SWITCH_SUPPORT), yes)
+DEFINES += MTK_JTAG_SWITCH_SUPPORT
+endif
+
+ifeq ($(MTK_FASTBOOT_SUPPORT), yes)
+DEFINES += MTK_FASTBOOT_SUPPORT
+endif
+
+ifeq ($(LK_PROFILING), yes)
+DEFINES += LK_PROFILING
+endif
+
+
+INCLUDES += -I$(LOCAL_DIR)/include
+INCLUDES += -I$(LOCAL_DIR)/include/target
+INCLUDES += -I$(LOCAL_DIR)/inc
+
+OBJS += \
+        $(LOCAL_DIR)/init.o \
+        $(LOCAL_DIR)/cust_msdc.o\
+        $(LOCAL_DIR)/cust_display.o\
+        $(LOCAL_DIR)/cust_leds.o\
+        $(LOCAL_DIR)/power_off.o\
+        $(LOCAL_DIR)/fastboot_oem_commands.o\

+ 42 - 0
target/X5/tools/makefile

@@ -0,0 +1,42 @@
+#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 := $(APPSBOOTHEADER_DIR)/EMMCBOOT.MBN
+else
+  ifeq ($(BUILD_NANDWRITE), 1)
+    APPSBOOTHDR_FILES :=
+  else
+    APPSBOOTHDR_FILES := $(APPSBOOTHEADER_DIR)/appsboot.mbn
+  endif
+endif
+
+APPSBOOTHEADER: $(APPSBOOTHDR_FILES)
+
+
+$(APPSBOOTHEADER_DIR)/appsboot.mbn: $(OUTBIN) $(BUILDDIR)/mkheader
+	@mkdir -p $(dir $@)
+	cp $(OUTBIN) $(APPSBOOTHEADER_DIR)/appsboot.raw
+	$(BUILDDIR)/mkheader $(OUTBIN) $(APPSBOOTHEADER_DIR)/appsboothd.mbn
+	cat $(APPSBOOTHEADER_DIR)/appsboothd.mbn $(OUTBIN) > $(APPSBOOTHEADER_DIR)/appsboot.mbn
+	rm -f $(APPSBOOTHEADER_DIR)/appsboothd.mbn
+
+$(APPSBOOTHEADER_DIR)/EMMCBOOT.MBN: $(OUTBIN) $(BUILDDIR)/mkheader
+	@mkdir -p $(dir $@)
+	cp $(OUTBIN) $(APPSBOOTHEADER_DIR)/emmc_appsboot.raw
+	$(BUILDDIR)/mkheader $(OUTBIN) $(APPSBOOTHEADER_DIR)/emmc_appsboothd.mbn
+	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
+
+$(BUILDDIR)/mkheader: $(SRC_DIR)/mkheader.c $(MAKEFILE_LIST)
+	@mkdir -p $(dir $@)
+	$(COMPILER) -DMEMBASE=$(MEMBASE) $< -o $@

+ 344 - 0
target/X5/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;
+}