2017-05-24 01:45:05 +01:00
|
|
|
/*
|
2018-01-25 08:10:14 +00:00
|
|
|
* Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
|
2017-05-24 01:45:05 +01:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
2018-12-14 00:18:21 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <arch_helpers.h>
|
|
|
|
#include <bl1/tbbr/tbbr_img_desc.h>
|
|
|
|
#include <common/bl_common.h>
|
|
|
|
#include <common/debug.h>
|
|
|
|
#include <drivers/arm/pl011.h>
|
|
|
|
#include <drivers/mmc.h>
|
|
|
|
#include <drivers/synopsys/dw_mmc.h>
|
|
|
|
#include <lib/mmio.h>
|
|
|
|
#include <plat/common/platform.h>
|
|
|
|
|
2017-05-24 01:45:05 +01:00
|
|
|
#include <hi6220.h>
|
2018-02-22 15:30:30 +00:00
|
|
|
#include <hikey_def.h>
|
|
|
|
#include <hikey_layout.h>
|
2017-05-24 01:45:05 +01:00
|
|
|
|
|
|
|
#include "hikey_private.h"
|
|
|
|
|
|
|
|
/* Data structure which holds the extents of the trusted RAM for BL1 */
|
|
|
|
static meminfo_t bl1_tzram_layout;
|
2020-01-25 00:58:35 +00:00
|
|
|
static console_t console;
|
2017-05-24 01:45:05 +01:00
|
|
|
|
|
|
|
enum {
|
|
|
|
BOOT_NORMAL = 0,
|
|
|
|
BOOT_USB_DOWNLOAD,
|
|
|
|
BOOT_UART_DOWNLOAD,
|
|
|
|
};
|
|
|
|
|
|
|
|
meminfo_t *bl1_plat_sec_mem_layout(void)
|
|
|
|
{
|
|
|
|
return &bl1_tzram_layout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Perform any BL1 specific platform actions.
|
|
|
|
*/
|
|
|
|
void bl1_early_platform_setup(void)
|
|
|
|
{
|
|
|
|
/* Initialize the console to provide early debug support */
|
2018-11-08 10:17:47 +00:00
|
|
|
console_pl011_register(CONSOLE_BASE, PL011_UART_CLK_IN_HZ,
|
|
|
|
PL011_BAUDRATE, &console);
|
2017-05-24 01:45:05 +01:00
|
|
|
|
|
|
|
/* Allow BL1 to see the whole Trusted RAM */
|
|
|
|
bl1_tzram_layout.total_base = BL1_RW_BASE;
|
|
|
|
bl1_tzram_layout.total_size = BL1_RW_SIZE;
|
|
|
|
|
|
|
|
INFO("BL1: 0x%lx - 0x%lx [size = %lu]\n", BL1_RAM_BASE, BL1_RAM_LIMIT,
|
2017-08-17 07:21:10 +01:00
|
|
|
BL1_RAM_LIMIT - BL1_RAM_BASE); /* bl1_size */
|
2017-05-24 01:45:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Perform the very early platform specific architecture setup here. At the
|
|
|
|
* moment this only does basic initialization. Later architectural setup
|
|
|
|
* (bl1_arch_setup()) does not do anything platform specific.
|
|
|
|
*/
|
|
|
|
void bl1_plat_arch_setup(void)
|
|
|
|
{
|
|
|
|
hikey_init_mmu_el3(bl1_tzram_layout.total_base,
|
|
|
|
bl1_tzram_layout.total_size,
|
|
|
|
BL1_RO_BASE,
|
|
|
|
BL1_RO_LIMIT,
|
2018-03-21 11:40:57 +00:00
|
|
|
BL_COHERENT_RAM_BASE,
|
|
|
|
BL_COHERENT_RAM_END);
|
2017-05-24 01:45:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function which will perform any remaining platform-specific setup that can
|
|
|
|
* occur after the MMU and data cache have been enabled.
|
|
|
|
*/
|
|
|
|
void bl1_platform_setup(void)
|
|
|
|
{
|
|
|
|
dw_mmc_params_t params;
|
2018-08-04 11:07:10 +01:00
|
|
|
struct mmc_device_info info;
|
2017-05-24 01:45:05 +01:00
|
|
|
|
|
|
|
assert((HIKEY_BL1_MMC_DESC_BASE >= SRAM_BASE) &&
|
|
|
|
((SRAM_BASE + SRAM_SIZE) >=
|
|
|
|
(HIKEY_BL1_MMC_DATA_BASE + HIKEY_BL1_MMC_DATA_SIZE)));
|
|
|
|
hikey_sp804_init();
|
|
|
|
hikey_gpio_init();
|
|
|
|
hikey_pmussi_init();
|
|
|
|
hikey_hi6553_init();
|
|
|
|
|
2017-10-18 12:56:02 +01:00
|
|
|
hikey_rtc_init();
|
|
|
|
|
2017-05-24 01:45:05 +01:00
|
|
|
hikey_mmc_pll_init();
|
|
|
|
|
|
|
|
memset(¶ms, 0, sizeof(dw_mmc_params_t));
|
|
|
|
params.reg_base = DWMMC0_BASE;
|
|
|
|
params.desc_base = HIKEY_BL1_MMC_DESC_BASE;
|
|
|
|
params.desc_size = 1 << 20;
|
|
|
|
params.clk_rate = 24 * 1000 * 1000;
|
2018-08-04 11:07:10 +01:00
|
|
|
params.bus_width = MMC_BUS_WIDTH_8;
|
|
|
|
params.flags = MMC_FLAG_CMD23;
|
|
|
|
info.mmc_dev_type = MMC_IS_EMMC;
|
|
|
|
dw_mmc_init(¶ms, &info);
|
2017-05-24 01:45:05 +01:00
|
|
|
|
|
|
|
hikey_io_setup();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following function checks if Firmware update is needed,
|
|
|
|
* by checking if TOC in FIP image is valid or not.
|
|
|
|
*/
|
|
|
|
unsigned int bl1_plat_get_next_image_id(void)
|
|
|
|
{
|
|
|
|
int32_t boot_mode;
|
|
|
|
unsigned int ret;
|
|
|
|
|
|
|
|
boot_mode = mmio_read_32(ONCHIPROM_PARAM_BASE);
|
|
|
|
switch (boot_mode) {
|
|
|
|
case BOOT_USB_DOWNLOAD:
|
|
|
|
case BOOT_UART_DOWNLOAD:
|
|
|
|
ret = NS_BL1U_IMAGE_ID;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARN("Invalid boot mode is found:%d\n", boot_mode);
|
|
|
|
panic();
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
image_desc_t *bl1_plat_get_image_desc(unsigned int image_id)
|
|
|
|
{
|
|
|
|
unsigned int index = 0;
|
|
|
|
|
|
|
|
while (bl1_tbbr_image_descs[index].image_id != INVALID_IMAGE_ID) {
|
|
|
|
if (bl1_tbbr_image_descs[index].image_id == image_id)
|
|
|
|
return &bl1_tbbr_image_descs[index];
|
|
|
|
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void bl1_plat_set_ep_info(unsigned int image_id,
|
|
|
|
entry_point_info_t *ep_info)
|
|
|
|
{
|
2018-03-02 06:25:41 +00:00
|
|
|
uint64_t data = 0;
|
2017-05-24 01:45:05 +01:00
|
|
|
|
|
|
|
if (image_id == BL2_IMAGE_ID)
|
2018-01-25 08:10:14 +00:00
|
|
|
panic();
|
2017-05-24 01:45:05 +01:00
|
|
|
inv_dcache_range(NS_BL1U_BASE, NS_BL1U_SIZE);
|
|
|
|
__asm__ volatile ("mrs %0, cpacr_el1" : "=r"(data));
|
|
|
|
do {
|
|
|
|
data |= 3 << 20;
|
|
|
|
__asm__ volatile ("msr cpacr_el1, %0" : : "r"(data));
|
|
|
|
__asm__ volatile ("mrs %0, cpacr_el1" : "=r"(data));
|
|
|
|
} while ((data & (3 << 20)) != (3 << 20));
|
types: use int-ll64 for both aarch32 and aarch64
Since commit 031dbb122472 ("AArch32: Add essential Arch helpers"),
it is difficult to use consistent format strings for printf() family
between aarch32 and aarch64.
For example, uint64_t is defined as 'unsigned long long' for aarch32
and as 'unsigned long' for aarch64. Likewise, uintptr_t is defined
as 'unsigned int' for aarch32, and as 'unsigned long' for aarch64.
A problem typically arises when you use printf() in common code.
One solution could be, to cast the arguments to a type long enough
for both architectures. For example, if 'val' is uint64_t type,
like this:
printf("val = %llx\n", (unsigned long long)val);
Or, somebody may suggest to use a macro provided by <inttypes.h>,
like this:
printf("val = %" PRIx64 "\n", val);
But, both would make the code ugly.
The solution adopted in Linux kernel is to use the same typedefs for
all architectures. The fixed integer types in the kernel-space have
been unified into int-ll64, like follows:
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef signed short int16_t;
typedef unsigned short uint16_t;
typedef signed int int32_t;
typedef unsigned int uint32_t;
typedef signed long long int64_t;
typedef unsigned long long uint64_t;
[ Linux commit: 0c79a8e29b5fcbcbfd611daf9d500cfad8370fcf ]
This gets along with the codebase shared between 32 bit and 64 bit,
with the data model called ILP32, LP64, respectively.
The width for primitive types is defined as follows:
ILP32 LP64
int 32 32
long 32 64
long long 64 64
pointer 32 64
'long long' is 64 bit for both, so it is used for defining uint64_t.
'long' has the same width as pointer, so for uintptr_t.
We still need an ifdef conditional for (s)size_t.
All 64 bit architectures use "unsigned long" size_t, and most 32 bit
architectures use "unsigned int" size_t. H8/300, S/390 are known as
exceptions; they use "unsigned long" size_t despite their architecture
is 32 bit.
One idea for simplification might be to define size_t as 'unsigned long'
across architectures, then forbid the use of "%z" string format.
However, this would cause a distortion between size_t and sizeof()
operator. We have unknowledge about the native type of sizeof(), so
we need a guess of it anyway. I want the following formula to always
return 1:
__builtin_types_compatible_p(size_t, typeof(sizeof(int)))
Fortunately, ARM is probably a majority case. As far as I know, all
32 bit ARM compilers use "unsigned int" size_t.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2018-02-02 06:09:36 +00:00
|
|
|
INFO("cpacr_el1:0x%llx\n", data);
|
2017-05-24 01:45:05 +01:00
|
|
|
|
|
|
|
ep_info->args.arg0 = 0xffff & read_mpidr();
|
|
|
|
ep_info->spsr = SPSR_64(MODE_EL1, MODE_SP_ELX,
|
|
|
|
DISABLE_ALL_EXCEPTIONS);
|
|
|
|
}
|