M7350v1_en_gpl

This commit is contained in:
T
2024-09-09 08:52:07 +00:00
commit f9cc65cfda
65988 changed files with 26357421 additions and 0 deletions

View File

@ -0,0 +1,74 @@
/* Copyright (c) 2009-2011, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of The Linux Foundation nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED 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 SIZE_1M 0x00100000
#define ROUND_TO_MB(x) ((x >> 20) << 20)
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].start != 0x0)
&&
(!(ROUND_TO_MB(ram_ptable.parts[i].size) <=
SIZE_1M))) {
/* ATAG_MEM */
*ptr++ = 4;
*ptr++ = 0x54410002;
/* RAM parition are reported correctly by NON-HLOS
Use the size passed directly */
if (target_is_emmc_boot())
*ptr++ =
ROUND_TO_MB(ram_ptable.parts[i].
size);
else
*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;
}
unsigned target_get_max_flash_size(void)
{
return (253 * 1024 * 1024);
}

View File

@ -0,0 +1,47 @@
/* Copyright (c) 2012, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#define MSM7X27A_FFA 3351
#define MSM7X27A_SURF 3352
#define MSM7X27A_RUMI3 3353
#define MSM7X27A_QRD1 3756
#define MSM7X25A_SURF 3772
#define MSM7X25A_FFA 3771
#define MSM7X27A_EVB 3934
#define MSM7X27A_QRD3 4005
#define MSM8X25_RUMI3 3871
#define MSM8X25_SURF 4037
#define MSM8X25_EVB 4042
#define MSM8X25_QRD7 4095
#define MSM8X25_FFA 4166
#define MSM8X25_EVT 4193
#define MSM8X25Q_SKUD 4393
#define LINUX_MACHTYPE MSM7X27A_SURF

View File

@ -0,0 +1,81 @@
/* Copyright (c) 2010-2011, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef _TARGET_MSM7627_SURF_DISPLAY_H
#define _TARGET_MSM7627_SURF_DISPLAY_H
#define TARGET_XRES 800
#define TARGET_YRES 480
#define LCDC_FB_WIDTH 800
#define LCDC_FB_HEIGHT 480
#define LCDC_HSYNC_PULSE_WIDTH_DCLK 60
#define LCDC_HSYNC_BACK_PORCH_DCLK 81
#define LCDC_HSYNC_FRONT_PORCH_DCLK 81
#define LCDC_HSYNC_SKEW_DCLK 0
#define LCDC_VSYNC_PULSE_WIDTH_LINES 2
#define LCDC_VSYNC_BACK_PORCH_LINES 20
#define LCDC_VSYNC_FRONT_PORCH_LINES 27
/* RENESAS MIPI panel */
#define REN_MIPI_FB_WIDTH 480
#define REN_MIPI_FB_HEIGHT 864
#define MIPI_HSYNC_PULSE_WIDTH 8
#define MIPI_HSYNC_BACK_PORCH_DCLK 100
#define MIPI_HSYNC_FRONT_PORCH_DCLK 100
#define MIPI_VSYNC_PULSE_WIDTH 1
#define MIPI_VSYNC_BACK_PORCH_LINES 20
#define MIPI_VSYNC_FRONT_PORCH_LINES 20
/* RENESAS MIPI HVGA panel */
#define REN_MIPI_FB_WIDTH_HVGA 480
#define REN_MIPI_FB_HEIGHT_HVGA 320
#define MIPI_HSYNC_PULSE_WIDTH_HVGA 5
#define MIPI_HSYNC_BACK_PORCH_DCLK_HVGA 21
#define MIPI_HSYNC_FRONT_PORCH_DCLK_HVGA 15
#define MIPI_VSYNC_PULSE_WIDTH_HVGA 50
#define MIPI_VSYNC_BACK_PORCH_LINES_HVGA 50
#define MIPI_VSYNC_FRONT_PORCH_LINES_HVGA 101
/* NT35510 MIPI WVGA panel */
#define NT35510_MIPI_FB_WIDTH 480
#define NT35510_MIPI_FB_HEIGHT 800
#define MIPI_FB_ADDR 0x2C800000
#define LCDC_FB_ADDR 0x2C800000
extern int mipi_dsi_phy_init(struct mipi_dsi_panel_config *);
extern void config_renesas_dsi_video_mode(void);
int target_cont_splash_screen(void);
#endif

View File

@ -0,0 +1,733 @@
/*
* Copyright (c) 2009, Google Inc.
* All rights reserved.
* Copyright (c) 2009-2013, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google, Inc. nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <reg.h>
#include <debug.h>
#include <dev/keys.h>
#include <dev/ssbi.h>
#include <lib/ptable.h>
#include <dev/flash.h>
#include <smem.h>
#include <mmc.h>
#include <platform/iomap.h>
#include <target/board.h>
#include <platform.h>
#include <crypto_hash.h>
#define VARIABLE_LENGTH 0x10101010
#define DIFF_START_ADDR 0xF0F0F0F0
#define NUM_PAGES_PER_BLOCK 0x40
#define RECOVERY_MODE 0x77665502
#define FOTA_COOKIE 0x64645343
unsigned int fota_cookie[1];
static struct ptable flash_ptable;
unsigned hw_platform = 0;
unsigned target_msm_id = 0;
unsigned msm_version = 0;
/* Setting this variable to different values defines the
* behavior of CE engine:
* platform_ce_type = CRYPTO_ENGINE_TYPE_NONE : No CE engine
* platform_ce_type = CRYPTO_ENGINE_TYPE_SW : Software CE engine
* platform_ce_type = CRYPTO_ENGINE_TYPE_HW : Hardware CE engine
* Behavior is determined in the target code.
*/
static crypto_engine_type platform_ce_type = CRYPTO_ENGINE_TYPE_SW;
int machine_is_evb();
/* for these partitions, start will be offset by either what we get from
* smem, or from the above offset if smem is not useful. Also, we should
* probably have smem_ptable code populate our flash_ptable.
*
* When smem provides us with a full partition table, we can get rid of
* this altogether.
*
*/
static struct ptentry board_part_list_default[] = {
{
.start = 0,
.length = 10 /* In MB */ ,
.name = "boot",
},
{
.start = DIFF_START_ADDR,
.length = 253 /* In MB */ ,
.name = "system",
},
{
.start = DIFF_START_ADDR,
.length = 80 /* In MB */ ,
.name = "cache",
},
{
.start = DIFF_START_ADDR,
.length = 4 /* In MB */ ,
.name = "misc",
},
{
.start = DIFF_START_ADDR,
.length = VARIABLE_LENGTH,
.name = "userdata",
},
{
.start = DIFF_START_ADDR,
.length = 4 /* In MB */ ,
.name = "persist",
},
{
.start = DIFF_START_ADDR,
.length = 10 /* In MB */ ,
.name = "recovery",
},
};
/*
* SKU3 & SKU PVT devices use the same micron NAND device with different density,
* due to this SKU3 partition creation fails as the number of blocks calculated
* from flash density is wrong, To avoid this use a different partition table &
* move the variable length partition to the end, this way kernel will truncate
* the variable length partition & we need not add target checks in the shared
* nand driver code.
*/
static struct ptentry board_part_list_sku3[] = {
{
.start = 0,
.length = 10 /* In MB */ ,
.name = "boot",
},
{
.start = DIFF_START_ADDR,
.length = 253 /* In MB */ ,
.name = "system",
},
{
.start = DIFF_START_ADDR,
.length = 80 /* In MB */ ,
.name = "cache",
},
{
.start = DIFF_START_ADDR,
.length = 4 /* In MB */ ,
.name = "misc",
},
{
.start = DIFF_START_ADDR,
.length = 4 /* In MB */ ,
.name = "persist",
},
{
.start = DIFF_START_ADDR,
.length = 10 /* In MB */ ,
.name = "recovery",
},
{
.start = DIFF_START_ADDR,
.length = VARIABLE_LENGTH,
.name = "userdata",
},
};
static int num_parts = sizeof(board_part_list_default) / sizeof(struct ptentry);
void smem_ptable_init(void);
unsigned smem_get_apps_flash_start(void);
void keypad_init(void);
int target_is_emmc_boot(void);
void target_init(void)
{
unsigned offset;
struct flash_info *flash_info;
struct ptentry *board_part_list;
unsigned total_num_of_blocks;
unsigned next_ptr_start_adr = 0;
unsigned blocks_per_1MB = 8; /* Default value of 2k page size on 256MB flash drive */
int i;
dprintf(INFO, "target_init()\n");
#if (!ENABLE_NANDWRITE)
keys_init();
keypad_init();
#endif
/* Display splash screen if enabled */
#if DISPLAY_SPLASH_SCREEN
display_init();
dprintf(SPEW, "Diplay initialized\n");
#endif
if (target_is_emmc_boot()) {
/* Must wait for modem-up before we can intialize MMC.
*/
while (readl(MSM_SHARED_BASE + 0x14) != 1) ;
if (mmc_boot_main(MMC_SLOT, MSM_SDC3_BASE)) {
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);
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);
if (target_is_sku3())
board_part_list = board_part_list_sku3;
else
board_part_list = board_part_list_default;
for (i = 0; i < num_parts; i++) {
struct ptentry *ptn = &board_part_list[i];
unsigned len = ((ptn->length) * blocks_per_1MB);
if (ptn->start != 0)
ASSERT(ptn->start == DIFF_START_ADDR);
ptn->start = next_ptr_start_adr;
if (ptn->length == VARIABLE_LENGTH) {
unsigned length_for_prt = 0;
unsigned j;
for (j = i + 1; j < num_parts; j++) {
struct ptentry *temp_ptn = &board_part_list[j];
ASSERT(temp_ptn->length != VARIABLE_LENGTH);
length_for_prt +=
((temp_ptn->length) * blocks_per_1MB);
}
len =
(total_num_of_blocks - 1) - (offset + ptn->start +
length_for_prt);
ASSERT(len >= 0);
}
next_ptr_start_adr = ptn->start + len;
ptable_add(&flash_ptable, ptn->name, offset + ptn->start,
len, ptn->flags, TYPE_APPS_PARTITION,
PERM_WRITEABLE);
}
smem_add_modem_partitions(&flash_ptable);
ptable_dump(&flash_ptable);
flash_set_ptable(&flash_ptable);
}
void board_info(void)
{
struct smem_board_info_v4 board_info_v4;
unsigned int board_info_len = 0;
unsigned smem_status;
unsigned format = 0;
unsigned id = 0;
if (hw_platform && target_msm_id)
return;
hw_platform = MSM7X27A_SURF;
target_msm_id = MSM7225A;
smem_status = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION,
&format, sizeof(format), 0);
if (!smem_status) {
if (format == 4) {
board_info_len = sizeof(board_info_v4);
smem_status =
smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
&board_info_v4,
board_info_len);
if (!smem_status) {
id = board_info_v4.board_info_v3.hw_platform;
target_msm_id =
board_info_v4.board_info_v3.msm_id;
msm_version =
board_info_v4.board_info_v3.msm_version;
}
}
/* Detect SURF v/s FFA v/s QRD */
if (target_msm_id >= MSM8225 && target_msm_id <= MSM8625
|| (target_msm_id == MSM8125A)
|| (target_msm_id == MSM8125)) {
switch (id) {
case 0x1:
hw_platform = MSM8X25_SURF;
break;
case 0x2:
hw_platform = MSM8X25_FFA;
break;
case 0x10:
hw_platform = MSM8X25_EVT;
break;
case 0x11:
hw_platform = MSM8X25Q_SKUD;
break;
case 0xC:
hw_platform = MSM8X25_EVB;
break;
case 0xF:
hw_platform = MSM8X25_QRD7;
break;
default:
hw_platform = MSM8X25_SURF;
}
} else {
switch (id) {
case 0x1:
/* Set the machine type based on msm ID */
if (msm_is_7x25a(target_msm_id))
hw_platform = MSM7X25A_SURF;
else
hw_platform = MSM7X27A_SURF;
break;
case 0x2:
if (msm_is_7x25a(target_msm_id))
hw_platform = MSM7X25A_FFA;
else
hw_platform = MSM7X27A_FFA;
break;
case 0xB:
if(target_is_emmc_boot())
hw_platform = MSM7X27A_QRD1;
else
hw_platform = MSM7X27A_QRD3;
break;
case 0xC:
hw_platform = MSM7X27A_EVB;
break;
case 0xF:
hw_platform = MSM7X27A_QRD3;
break;
default:
if (msm_is_7x25a(target_msm_id))
hw_platform = MSM7X25A_SURF;
else
hw_platform = MSM7X27A_SURF;
};
}
/* Set msm ID for target variants based on values read from smem */
switch (target_msm_id) {
case MSM7225A:
case MSM7625A:
case ESM7225A:
case MSM7225AA:
case MSM7625AA:
case ESM7225AA:
case MSM7225AB:
case MSM7625AB:
case ESM7225AB:
case MSM7125A:
target_msm_id = MSM7625A;
break;
case MSM8225:
case MSM8625:
case MSM8125A:
case MSM8125:
target_msm_id = MSM8625;
break;
default:
target_msm_id = MSM7627A;
}
}
return;
}
unsigned board_machtype(void)
{
board_info();
return hw_platform;
}
unsigned board_msm_id(void)
{
board_info();
return target_msm_id;
}
unsigned board_msm_version(void)
{
board_info();
msm_version = (msm_version & 0xffff0000) >> 16;
return msm_version;
}
crypto_engine_type board_ce_type(void)
{
return platform_ce_type;
}
void reboot_device(unsigned reboot_reason)
{
reboot(reboot_reason);
}
static int read_from_flash(struct ptentry* ptn, int offset, int size, void *dest)
{
void *buffer = NULL;
unsigned page_size = flash_page_size();
unsigned page_mask = page_size - 1;
int read_size = (size + page_mask) & (~page_mask);
buffer = malloc(read_size);
if(!buffer){
dprintf(CRITICAL, "ERROR : Malloc failed for read_from_flash \n");
return -1;
}
if(flash_read(ptn, offset, buffer, read_size)){
dprintf(CRITICAL, "ERROR : Flash read failed \n");
return -1;
}
memcpy(dest, buffer, size);
free(buffer);
return 0;
}
static unsigned int get_fota_cookie_mtd(void)
{
struct ptentry *ptn;
struct ptable *ptable;
unsigned int cookie = 0;
ptable = flash_get_ptable();
if (ptable == NULL) {
dprintf(CRITICAL, "ERROR: Partition table not found\n");
return 0;
}
ptn = ptable_find(ptable, "FOTA");
if (ptn == NULL) {
dprintf(CRITICAL, "ERROR: No FOTA partition found\n");
return 0;
}
if (read_from_flash(ptn, 0, sizeof(unsigned int), &cookie) == -1) {
dprintf(CRITICAL, "ERROR: failed to read fota cookie from flash\n");
return 0;
}
return cookie;
}
static int read_from_mmc(struct ptentry* ptn, int size, void *dest)
{
void *buffer = NULL;
unsigned sector_mask = 511;
int read_size = (size + sector_mask) & (~sector_mask);
buffer = malloc(read_size);
if(!buffer){
dprintf(CRITICAL, "ERROR : Malloc failed for read_from_flash \n");
return -1;
}
if(mmc_read(ptn, buffer, read_size)) {
dprintf(CRITICAL, "ERROR : Flash read failed \n");
return -1;
}
memcpy(dest, buffer, size);
free(buffer);
return 0;
}
static int get_fota_cookie_mmc(void)
{
unsigned long long ptn = 0;
int index = -1;
unsigned int cookie = 0;
index = partition_get_index("FOTA");
ptn = partition_get_offset(index);
if(ptn == 0) {
dprintf(CRITICAL,"ERROR: FOTA partition not found\n");
return 0;
}
if(read_from_mmc(ptn, sizeof(unsigned int), &cookie)) {
dprintf(CRITICAL, "ERROR: Cannot read cookie info\n");
return 0;
}
return cookie;
}
unsigned check_reboot_mode(void)
{
unsigned mode[2] = { 0, 0 };
unsigned int mode_len = sizeof(mode);
unsigned smem_status;
unsigned int cookie = 0;
smem_status = smem_read_alloc_entry(SMEM_APPS_BOOT_MODE,
&mode, mode_len);
/*
* SMEM value is relied upon on power shutdown. Check either of SMEM
* or FOTA update cookie is set
*/
if (target_is_emmc_boot())
cookie = get_fota_cookie_mmc();
else
cookie = get_fota_cookie_mtd();
if ((mode[0] == RECOVERY_MODE) || (cookie == FOTA_COOKIE))
return RECOVERY_MODE;
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)
{
if (target_check_power_on_reason() == PWR_ON_EVENT_WALL_CHG)
return 1;
return 0;
}
void target_battery_charging_enable(unsigned enable, unsigned disconnect)
{
}
#if _EMMC_BOOT
void target_serialno(unsigned char *buf)
{
unsigned int serialno;
serialno = mmc_get_psn();
sprintf(buf, "%x", serialno);
}
int emmc_recovery_init(void)
{
int rc;
rc = _emmc_recovery_init();
return rc;
}
#endif
int machine_is_evb()
{
int ret = 0;
unsigned mach_type = board_machtype();
switch(mach_type) {
case MSM7X27A_EVB:
case MSM8X25_EVB:
case MSM8X25_EVT:
ret = 1;
break;
default:
ret = 0;
}
return ret;
}
int machine_is_qrd()
{
int ret = 0;
unsigned mach_type = board_machtype();
switch(mach_type) {
case MSM7X27A_QRD1:
case MSM7X27A_QRD3:
case MSM8X25_QRD7:
ret = 1;
break;
default:
ret = 0;
}
return ret;
}
int machine_is_skud()
{
int ret = 0;
unsigned mach_type = board_machtype();
switch(mach_type) {
case MSM8X25Q_SKUD:
ret = 1;
break;
default:
ret = 0;
}
return ret;
}
int machine_is_8x25()
{
int ret = 0;
unsigned mach_type = board_machtype();
switch(mach_type) {
case MSM8X25_SURF:
case MSM8X25_FFA:
case MSM8X25_EVB:
case MSM8X25_EVT:
case MSM8X25_QRD7:
case MSM8X25Q_SKUD:
ret = 1;
break;
default:
ret = 0;
}
return ret;
}
int msm_is_7x25a(int msm_id)
{
int ret = 0;
switch (msm_id) {
case MSM7225A:
case MSM7625A:
case ESM7225A:
case MSM7225AA:
case MSM7625AA:
case ESM7225AA:
case MSM7225AB:
case MSM7625AB:
case ESM7225AB:
case MSM7125A:
ret = 1;
break;
default:
ret = 0;
};
return ret;
}
static void target_ulpi_init(void)
{
unsigned int reg;
ulpi_read(0x31);
dprintf(INFO, " Value of ulpi read 0x31 is %08x\n", reg);
/* todo : the write back value should be calculated according to
* reg &= 0xF3 but sometimes the value that is read initially
* doesnt look right
*/
ulpi_write(0x4A, 0x31);
reg = ulpi_read(0x31);
dprintf(INFO, " Value of ulpi read 0x31 after write is %08x\n", reg);
reg = ulpi_read(0x32);
dprintf(INFO, " Value of ulpi read 0x32 is %08x\n", reg);
ulpi_write(0x30, 0x32);
reg = ulpi_read(0x32);
dprintf(INFO, " Value of ulpi read 0x32 after write is %08x\n", reg);
reg = ulpi_read(0x36);
dprintf(INFO, " Value of ulpi read 0x36 is %08x\n", reg);
ulpi_write(reg | 0x2, 0x36);
reg = ulpi_read(0x36);
dprintf(INFO, " Value of ulpi read 0x36 after write is %08x\n", reg);
}
void target_usb_init(void)
{
target_ulpi_init();
}
int target_cont_splash_screen()
{
int ret = 0;
unsigned mach_type = 0;
mach_type = board_machtype();
switch(mach_type) {
case MSM8X25_EVB:
case MSM8X25_EVT:
case MSM8X25_QRD7:
ret = 1;
break;
default:
ret = 0;
};
return ret;
}
int target_is_sku3()
{
int ret = 0;
unsigned mach_type = 0;
mach_type = board_machtype();
switch(mach_type) {
case MSM7X27A_QRD3:
ret = 1;
break;
default:
ret = 0;
};
return ret;
}
/* Function to set the capabilities for the host */
void target_mmc_caps(struct mmc_host *host)
{
host->caps.ddr_mode = 0;
host->caps.hs200_mode = 0;
host->caps.bus_width = MMC_BOOT_BUS_WIDTH_4_BIT;
host->caps.hs_clk_rate = MMC_CLK_50MHZ;
}

View File

@ -0,0 +1,160 @@
/*
* Copyright (c) 2009, Google Inc.
* All rights reserved.
* Copyright (c) 2009-2012, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of 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/ssbi.h>
#include <dev/gpio_keypad.h>
#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
/* don't turn this on without updating the ffa support */
#define SCAN_FUNCTION_KEYS 0
static unsigned int halibut_row_gpios[] = { 31, 32, 33, 34, 35 };
static unsigned int halibut_col_gpios[] = { 36, 37, 38, 39, 40 };
static unsigned int halibut_row_gpios_qrd[] = { 31, 32 };
static unsigned int halibut_col_gpios_qrd[] = { 36, 37 };
static unsigned int halibut_row_gpios_skud[] = { 31, 32 };
static unsigned int halibut_col_gpios_skud[] = { 37 };
static unsigned int halibut_row_gpios_evb[] = { 31 };
static unsigned int halibut_col_gpios_evb[] = { 36, 37 };
#define KEYMAP_INDEX(row, col) ((row)*ARRAY_SIZE(halibut_col_gpios) + (col))
#define KEYMAP_INDEX_QRD(row, col) ((row)*ARRAY_SIZE(halibut_col_gpios_qrd) + (col))
#define KEYMAP_INDEX_EVB(row, col) ((row)*ARRAY_SIZE(halibut_col_gpios_evb) + (col))
static const unsigned short halibut_keymap[ARRAY_SIZE(halibut_col_gpios) *
ARRAY_SIZE(halibut_row_gpios)] = {
[KEYMAP_INDEX(0, 0)] = KEY_7,
[KEYMAP_INDEX(0, 1)] = KEY_DOWN,
[KEYMAP_INDEX(0, 2)] = KEY_UP,
[KEYMAP_INDEX(0, 3)] = KEY_RIGHT,
[KEYMAP_INDEX(0, 4)] = KEY_CENTER,
[KEYMAP_INDEX(1, 0)] = KEY_LEFT,
[KEYMAP_INDEX(1, 1)] = KEY_SEND,
[KEYMAP_INDEX(1, 2)] = KEY_1,
[KEYMAP_INDEX(1, 3)] = KEY_4,
[KEYMAP_INDEX(1, 4)] = KEY_CLEAR,
[KEYMAP_INDEX(2, 0)] = KEY_6,
[KEYMAP_INDEX(2, 1)] = KEY_5,
[KEYMAP_INDEX(2, 2)] = KEY_8,
[KEYMAP_INDEX(2, 3)] = KEY_3,
[KEYMAP_INDEX(2, 4)] = KEY_STAR,
[KEYMAP_INDEX(3, 0)] = KEY_9,
[KEYMAP_INDEX(3, 1)] = KEY_SOFT1,
[KEYMAP_INDEX(3, 2)] = KEY_0,
[KEYMAP_INDEX(3, 3)] = KEY_2,
[KEYMAP_INDEX(3, 4)] = KEY_SOFT2,
[KEYMAP_INDEX(4, 0)] = KEY_MENU, /*R- */
[KEYMAP_INDEX(4, 1)] = KEY_HOME, /*L+ */
[KEYMAP_INDEX(4, 2)] = KEY_BACK, /*L- */
[KEYMAP_INDEX(4, 3)] = KEY_VOLUMEUP,
[KEYMAP_INDEX(4, 4)] = KEY_VOLUMEDOWN,
};
static const unsigned short halibut_keymap_qrd[ARRAY_SIZE(halibut_col_gpios_qrd)
*
ARRAY_SIZE
(halibut_row_gpios_qrd)] = {
[KEYMAP_INDEX_QRD(0, 0)] = KEY_VOLUMEUP,
[KEYMAP_INDEX_QRD(0, 1)] = KEY_VOLUMEDOWN,
};
static const unsigned short halibut_keymap_evb[ARRAY_SIZE(halibut_col_gpios_evb)
*
ARRAY_SIZE
(halibut_row_gpios_evb)] = {
[KEYMAP_INDEX_EVB(0, 0)] = KEY_VOLUMEUP,
[KEYMAP_INDEX_EVB(0, 1)] = KEY_VOLUMEDOWN,
};
static struct gpio_keypad_info halibut_keypad_info_surf = {
.keymap = halibut_keymap,
.output_gpios = halibut_row_gpios,
.input_gpios = halibut_col_gpios,
.noutputs = ARRAY_SIZE(halibut_row_gpios),
.ninputs = ARRAY_SIZE(halibut_col_gpios),
.settle_time = 5 /* msec */ ,
.poll_time = 20 /* msec */ ,
.flags = GPIOKPF_DRIVE_INACTIVE,
};
static struct gpio_keypad_info halibut_keypad_info_qrd = {
.keymap = halibut_keymap_qrd,
.output_gpios = halibut_row_gpios_qrd,
.input_gpios = halibut_col_gpios_qrd,
.noutputs = ARRAY_SIZE(halibut_row_gpios_qrd),
.ninputs = ARRAY_SIZE(halibut_col_gpios_qrd),
.settle_time = 5 /* msec */ ,
.poll_time = 20 /* msec */ ,
.flags = GPIOKPF_DRIVE_INACTIVE,
};
static struct gpio_keypad_info halibut_keypad_info_skud = {
.keymap = halibut_keymap_qrd,
.output_gpios = halibut_row_gpios_skud,
.input_gpios = halibut_col_gpios_skud,
.noutputs = ARRAY_SIZE(halibut_row_gpios_skud),
.ninputs = ARRAY_SIZE(halibut_col_gpios_skud),
.settle_time = 5 /* msec */ ,
.poll_time = 20 /* msec */ ,
.flags = GPIOKPF_DRIVE_INACTIVE,
};
static struct gpio_keypad_info halibut_keypad_info_evb = {
.keymap = halibut_keymap_evb,
.output_gpios = halibut_row_gpios_evb,
.input_gpios = halibut_col_gpios_evb,
.noutputs = ARRAY_SIZE(halibut_row_gpios_evb),
.ninputs = ARRAY_SIZE(halibut_col_gpios_evb),
.settle_time = 5 /* msec */ ,
.poll_time = 20 /* msec */ ,
.flags = GPIOKPF_DRIVE_INACTIVE,
};
void keypad_init(void)
{
if (machine_is_qrd())
gpio_keypad_init(&halibut_keypad_info_qrd);
else if (machine_is_skud())
gpio_keypad_init(&halibut_keypad_info_skud);
else if (machine_is_evb())
gpio_keypad_init(&halibut_keypad_info_evb);
else
gpio_keypad_init(&halibut_keypad_info_surf);
}

View File

@ -0,0 +1,48 @@
LOCAL_DIR := $(GET_LOCAL_DIR)
INCLUDES += -I$(LOCAL_DIR)/include -I$(LK_TOP_DIR)/platform/msm_shared
PLATFORM := msm7x27a
MEMBASE := 0x00000000 # SMI
MEMSIZE := 0x00100000 # 1MB
BASE_ADDR := 0x00200000
TAGS_ADDR := BASE_ADDR+0x00000100
KERNEL_ADDR := BASE_ADDR+0x00008000
RAMDISK_ADDR := BASE_ADDR+0x01000000
SCRATCH_ADDR := BASE_ADDR+0x000A0000
KEYS_USE_GPIO_KEYPAD := 1
DEFINES += DISPLAY_TYPE_MDDI=0
DEFINES += DISPLAY_TYPE_LCDC=0
DEFINES += DISPLAY_SPLASH_SCREEN=1
DEFINES += DISPLAY_TYPE_MIPI=1
DEFINES += DISPLAY_MIPI_PANEL_RENESAS=1
DEFINES += USE_PCOM_SECBOOT=1
DEFINES += TARGET_USES_GIC_VIC=1
DEFINES += MIPI_VIDEO_MODE=0
MODULES += \
dev/keys \
dev/ssbi \
lib/ptable \
dev/panel/msm
DEFINES += \
SDRAM_SIZE=$(MEMSIZE) \
MEMBASE=$(MEMBASE) \
BASE_ADDR=$(BASE_ADDR) \
TAGS_ADDR=$(TAGS_ADDR) \
KERNEL_ADDR=$(KERNEL_ADDR) \
RAMDISK_ADDR=$(RAMDISK_ADDR) \
SCRATCH_ADDR=$(SCRATCH_ADDR)
OBJS += \
$(LOCAL_DIR)/init.o \
$(LOCAL_DIR)/keypad.o \
$(LOCAL_DIR)/atags.o \
$(LOCAL_DIR)/target_display.o

View File

@ -0,0 +1,163 @@
/* Copyright (c) 2012, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <debug.h>
#include <msm_panel.h>
#include <target/display.h>
#include <target/board.h>
#include <dev/lcdc.h>
static struct msm_fb_panel_data panel;
static uint8_t display_enabled;
extern int msm_display_init(struct msm_fb_panel_data *pdata);
extern int msm_display_off();
extern int mipi_renesas_panel_dsi_config(int);
extern int mipi_nt35510_panel_dsi_config(int);
extern int lcdc_truly_panel_on(int);
static int msm7627a_mdp_clock_init(int enable)
{
int ret = 0;
unsigned rate = 0;
rate = panel.panel_info.clk_rate;
if (enable)
mdp_clock_init(rate);
else
mdp_clock_disable();
return ret;
}
static int msm7627a_lcdc_clock_init(int enable)
{
int ret = 0;
unsigned rate = panel.panel_info.clk_rate;
if (enable) {
mdp_clock_init(rate);
lcdc_clock_init(rate);
} else {
mdp_clock_disable();
lcdc_clock_disable();
}
return ret;
}
void display_init(void)
{
unsigned mach_type;
mach_type = board_machtype();
dprintf(SPEW, "display_init\n");
switch (mach_type) {
case MSM7X27A_SURF:
case MSM8X25_SURF:
case MSM7X27A_FFA:
#if MIPI_VIDEO_MODE
mipi_renesas_video_fwvga_init(&(panel.panel_info));
#else
mipi_renesas_cmd_fwvga_init(&(panel.panel_info));
#endif
panel.clk_func = msm7627a_mdp_clock_init;
panel.power_func = mipi_renesas_panel_dsi_config;
panel.fb.base = MIPI_FB_ADDR;
panel.fb.width = panel.panel_info.xres;
panel.fb.height = panel.panel_info.yres;
panel.fb.stride = panel.panel_info.xres;
panel.fb.bpp = panel.panel_info.bpp;
panel.fb.format = FB_FORMAT_RGB888;
panel.mdp_rev = MDP_REV_303;
break;
case MSM7X25A_SURF:
case MSM7X25A_FFA:
#if MIPI_VIDEO_MODE
mipi_renesas_video_hvga_init(&(panel.panel_info));
#else
mipi_renesas_cmd_hvga_init(&(panel.panel_info));
#endif
panel.clk_func = msm7627a_mdp_clock_init;
panel.power_func = mipi_renesas_panel_dsi_config;
panel.fb.base = MIPI_FB_ADDR;
panel.fb.width = panel.panel_info.xres;
panel.fb.height = panel.panel_info.yres;
panel.fb.stride = panel.panel_info.xres;
panel.fb.bpp = panel.panel_info.bpp;
panel.fb.format = FB_FORMAT_RGB888;
panel.mdp_rev = MDP_REV_303;
break;
case MSM7X27A_EVB:
case MSM8X25_EVB:
case MSM8X25_EVT:
#if MIPI_VIDEO_MODE
mipi_nt35510_video_wvga_init(&(panel.panel_info));
#else
mipi_nt35510_cmd_wvga_init(&(panel.panel_info));
#endif
panel.clk_func = msm7627a_mdp_clock_init;
panel.power_func = mipi_nt35510_panel_dsi_config;
panel.fb.base = MIPI_FB_ADDR;
panel.fb.width = panel.panel_info.xres;
panel.fb.height = panel.panel_info.yres;
panel.fb.stride = panel.panel_info.xres;
panel.fb.bpp = panel.panel_info.bpp;
panel.fb.format = FB_FORMAT_RGB888;
panel.mdp_rev = MDP_REV_303;
if (mach_type == MSM8X25_EVT)
panel.rotate = 1;
break;
case MSM8X25_QRD7:
lcdc_truly_hvga_init(&(panel.panel_info));
panel.clk_func = msm7627a_lcdc_clock_init;
panel.power_func = lcdc_truly_panel_on;
panel.fb.base = LCDC_FB_ADDR;
panel.fb.width = panel.panel_info.xres;
panel.fb.height = panel.panel_info.yres;
panel.fb.stride = panel.panel_info.xres;
panel.fb.bpp = panel.panel_info.bpp;
panel.fb.format = FB_FORMAT_RGB565;
panel.mdp_rev = MDP_REV_303;
break;
default:
return;
};
if (msm_display_init(&panel)) {
dprintf(CRITICAL, "Display init failed!\n");
return;
}
display_enabled = 1;
}
void display_shutdown(void)
{
dprintf(SPEW, "display_shutdown()\n");
if (display_enabled)
msm_display_off();
}

View File

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

View File

@ -0,0 +1,306 @@
/*
* Copyright (c) 2007, Google Inc.
* All rights reserved.
*
* Copyright (c) 2010-2011, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of 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> <emmc>\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,
"emmc: This flag takes value 1 or 0, 1 - emmc 0 - nand\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 emmc = 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 != 7) {
fprintf(stderr,
"ERROR: Missing argument(s): [outbin maxsize] | [outbin, maxsize, certchain, signature + certifcate(s)]\n");
return print_usage();
}
if (argc == 7 && atoi(argv[6]) == 1) {
emmc = 1;
}
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 || emmc) {
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;
base = 0;
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 || emmc == 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 > 7) {
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;
}
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;
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 [RAW APPSBOOT][PADDED CERT CHAIN]
if ((output_file = fopen(argv[4], "wb")) == NULL) {
perror("ERROR: Occured during fopen");
return -1;
}
//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 == 7) {
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;
}
//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);
}
return 0;
}