Commit 0281e60c authored by Soby Mathew's avatar Soby Mathew Committed by TrustedFirmware Code Review
Browse files

Merge changes from topic "pie" into integration

* changes:
  uniphier: make all BL images completely position-independent
  uniphier: make uniphier_mmap_setup() work with PIE
  uniphier: pass SCP base address as a function parameter
  uniphier: set buffer offset and length for io_block dynamically
  uniphier: use more mmap_add_dynamic_region() for loading images
  bl_common: add BL_END macro
  uniphier: turn on ENABLE_PIE
  TSP: add PIE support
  BL2_AT_EL3: add PIE support
  BL31: discard .dynsym .dynstr .hash sections to make ENABLE_PIE work
  PIE: pass PIE options only to BL31
  Build: support per-BL LDFLAGS
parents 432e9ee2 7af21317
......@@ -452,18 +452,30 @@ ifeq (${ARM_ARCH_MAJOR},7)
include make_helpers/armv7-a-cpus.mk
endif
ifeq ($(ENABLE_PIE),1)
TF_CFLAGS += -fpie
ifneq ($(findstring gcc,$(notdir $(LD))),)
TF_LDFLAGS += -Wl,-pie -Wl,--no-dynamic-linker
else
TF_LDFLAGS += -pie --no-dynamic-linker
endif
else
PIE_FOUND := $(findstring --enable-default-pie,${GCC_V_OUTPUT})
ifneq ($(PIE_FOUND),)
PIE_FOUND := $(findstring --enable-default-pie,${GCC_V_OUTPUT})
ifneq ($(PIE_FOUND),)
TF_CFLAGS += -fno-PIE
endif
endif
ifneq ($(findstring gcc,$(notdir $(LD))),)
PIE_LDFLAGS += -Wl,-pie -Wl,--no-dynamic-linker
else
PIE_LDFLAGS += -pie --no-dynamic-linker
endif
ifeq ($(ENABLE_PIE),1)
ifeq ($(BL2_AT_EL3),1)
ifneq ($(BL2_IN_XIP_MEM),1)
BL2_CFLAGS += -fpie
BL2_LDFLAGS += $(PIE_LDFLAGS)
endif
endif
BL31_CFLAGS += -fpie
BL31_LDFLAGS += $(PIE_LDFLAGS)
ifeq ($(ARCH),aarch64)
BL32_CFLAGS += -fpie
BL32_LDFLAGS += $(PIE_LDFLAGS)
endif
endif
# Include the CPU specific operations makefile, which provides default
......
......@@ -4,6 +4,8 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <platform_def.h>
#include <arch.h>
#include <asm_macros.S>
#include <common/bl_common.h>
......@@ -13,6 +15,12 @@
.globl bl2_el3_run_image
.globl bl2_run_next_image
#if BL2_IN_XIP_MEM
#define FIXUP_SIZE 0
#else
#define FIXUP_SIZE ((BL2_LIMIT) - (BL2_BASE))
#endif
func bl2_entrypoint
/* Save arguments x0-x3 from previous Boot loader */
mov x20, x0
......@@ -27,7 +35,7 @@ func bl2_entrypoint
_init_memory=1 \
_init_c_runtime=1 \
_exception_vectors=bl2_el3_exceptions \
_pie_fixup_size=0
_pie_fixup_size=FIXUP_SIZE
/* ---------------------------------------------
* Restore parameters of boot rom
......
......@@ -69,6 +69,16 @@ SECTIONS
KEEP(*(cpu_ops))
__CPU_OPS_END__ = .;
/*
* Keep the .got section in the RO section as it is patched
* prior to enabling the MMU and having the .got in RO is better for
* security. GOT is a table of addresses so ensure 8-byte alignment.
*/
. = ALIGN(8);
__GOT_START__ = .;
*(.got)
__GOT_END__ = .;
. = ALIGN(PAGE_SIZE);
__RODATA_END__ = .;
} >ROM
......@@ -100,6 +110,16 @@ SECTIONS
KEEP(*(.img_parser_lib_descs))
__PARSER_LIB_DESCS_END__ = .;
/*
* Keep the .got section in the RO section as it is patched
* prior to enabling the MMU and having the .got in RO is better for
* security. GOT is a table of addresses so ensure 8-byte alignment.
*/
. = ALIGN(8);
__GOT_START__ = .;
*(.got)
__GOT_END__ = .;
*(.vectors)
__RO_END_UNALIGNED__ = .;
/*
......@@ -139,6 +159,17 @@ SECTIONS
__DATA_RAM_END__ = .;
} >RAM AT>ROM
/*
* .rela.dyn needs to come after .data for the read-elf utility to parse
* this section correctly. Ensure 8-byte alignment so that the fields of
* RELA data structure are aligned.
*/
. = ALIGN(8);
__RELA_START__ = .;
.rela.dyn . : {
} >RAM
__RELA_END__ = .;
stacks (NOLOAD) : {
__STACKS_START__ = .;
*(tzfw_normal_stacks)
......@@ -195,6 +226,10 @@ SECTIONS
__RW_END__ = .;
__BL2_END__ = .;
/DISCARD/ : {
*(.dynsym .dynstr .hash .gnu.hash)
}
#if BL2_IN_XIP_MEM
__BL2_RAM_START__ = ADDR(.data);
__BL2_RAM_END__ = .;
......
......@@ -339,6 +339,10 @@ SECTIONS
__RW_END__ = .;
__BL31_END__ = .;
/DISCARD/ : {
*(.dynsym .dynstr .hash .gnu.hash)
}
ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.")
#endif
}
/*
* Copyright (c) 2013-2019, ARM Limited and Contributors. All rights reserved.
* Copyright (c) 2013-2020, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <platform_def.h>
#include <arch.h>
#include <asm_macros.S>
#include <bl32/tsp/tsp.h>
......@@ -46,6 +48,24 @@
func tsp_entrypoint _align=3
#if ENABLE_PIE
/*
* ------------------------------------------------------------
* If PIE is enabled fixup the Global descriptor Table only
* once during primary core cold boot path.
*
* Compile time base address, required for fixup, is calculated
* using "pie_fixup" label present within first page.
* ------------------------------------------------------------
*/
pie_fixup:
ldr x0, =pie_fixup
and x0, x0, #~(PAGE_SIZE - 1)
mov_imm x1, (BL32_LIMIT - BL32_BASE)
add x1, x1, x0
bl fixup_gdt_reloc
#endif /* ENABLE_PIE */
/* ---------------------------------------------
* Set the exception vector to something sane.
* ---------------------------------------------
......
/*
* Copyright (c) 2013-2018, ARM Limited and Contributors. All rights reserved.
* Copyright (c) 2013-2020, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
......@@ -36,6 +36,17 @@ SECTIONS
.rodata . : {
__RODATA_START__ = .;
*(.rodata*)
/*
* Keep the .got section in the RO section as it is patched
* prior to enabling the MMU and having the .got in RO is better for
* security. GOT is a table of addresses so ensure 8-byte alignment.
*/
. = ALIGN(8);
__GOT_START__ = .;
*(.got)
__GOT_END__ = .;
. = ALIGN(PAGE_SIZE);
__RODATA_END__ = .;
} >RAM
......@@ -45,7 +56,19 @@ SECTIONS
*tsp_entrypoint.o(.text*)
*(.text*)
*(.rodata*)
/*
* Keep the .got section in the RO section as it is patched
* prior to enabling the MMU and having the .got in RO is better for
* security. GOT is a table of addresses so ensure 8-byte alignment.
*/
. = ALIGN(8);
__GOT_START__ = .;
*(.got)
__GOT_END__ = .;
*(.vectors)
__RO_END_UNALIGNED__ = .;
/*
* Memory page(s) mapped to this section will be marked as
......@@ -69,6 +92,17 @@ SECTIONS
__DATA_END__ = .;
} >RAM
/*
* .rela.dyn needs to come after .data for the read-elf utility to parse
* this section correctly. Ensure 8-byte alignment so that the fields of
* RELA data structure are aligned.
*/
. = ALIGN(8);
__RELA_START__ = .;
.rela.dyn . : {
} >RAM
__RELA_END__ = .;
#ifdef TSP_PROGBITS_LIMIT
ASSERT(. <= TSP_PROGBITS_LIMIT, "TSP progbits has exceeded its limit.")
#endif
......@@ -129,6 +163,10 @@ SECTIONS
__RW_END__ = .;
__BL32_END__ = .;
/DISCARD/ : {
*(.dynsym .dynstr .hash .gnu.hash)
}
__BSS_SIZE__ = SIZEOF(.bss);
#if USE_COHERENT_MEM
__COHERENT_RAM_UNALIGNED_SIZE__ =
......
......@@ -213,7 +213,7 @@ Common build options
- ``ENABLE_PIE``: Boolean option to enable Position Independent Executable(PIE)
support within generic code in TF-A. This option is currently only supported
in BL31. Default is 0.
in BL2_AT_EL3, BL31, and BL32 (TSP). Default is 0.
- ``ENABLE_PMF``: Boolean option to enable support for optional Performance
Measurement Framework(PMF). Default is 0.
......
/*
* Copyright (c) 2013-2019, ARM Limited and Contributors. All rights reserved.
* Copyright (c) 2013-2020, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
......@@ -106,6 +106,7 @@ IMPORT_SYM(uintptr_t, __RODATA_END__, BL_RO_DATA_END);
IMPORT_SYM(uintptr_t, __RO_START__, BL_CODE_BASE);
IMPORT_SYM(uintptr_t, __RO_END__, BL_CODE_END);
#endif
IMPORT_SYM(uintptr_t, __RW_END__, BL_END);
#if defined(IMAGE_BL1)
IMPORT_SYM(uintptr_t, __BL1_ROM_END__, BL1_ROM_END);
......
......@@ -412,6 +412,7 @@ bl${1}_dirs: | ${OBJ_DIRS}
$(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),$(1)))
$(eval $(call MAKE_LD,$(LINKERFILE),$(BL_LINKERFILE),$(1)))
$(eval BL_LDFLAGS := $(BL$(call uppercase,$(1))_LDFLAGS))
ifeq ($(USE_ROMLIB),1)
$(ELF): romlib.bin
......@@ -427,7 +428,7 @@ else
$$(CC) $$(TF_CFLAGS) $$(CFLAGS) -xc -c - -o $(BUILD_DIR)/build_message.o
endif
ifneq ($(findstring armlink,$(notdir $(LD))),)
$$(Q)$$(LD) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) --entry=bl${1}_entrypoint \
$$(Q)$$(LD) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $(BL_LDFLAGS) --entry=bl${1}_entrypoint \
--predefine="-D__LINKER__=$(__LINKER__)" \
--predefine="-DTF_CFLAGS=$(TF_CFLAGS)" \
--map --list="$(MAPFILE)" --scatter=${PLAT_DIR}/scat/bl${1}.scat \
......@@ -438,7 +439,7 @@ else ifneq ($(findstring gcc,$(notdir $(LD))),)
-Wl,-T$(LINKERFILE) $(BUILD_DIR)/build_message.o \
$(OBJS) $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS)
else
$$(Q)$$(LD) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) -Map=$(MAPFILE) \
$$(Q)$$(LD) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $(BL_LDFLAGS) -Map=$(MAPFILE) \
--script $(LINKERFILE) $(BUILD_DIR)/build_message.o \
$(OBJS) $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS)
endif
......
/*
* Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
* Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
......@@ -28,28 +28,43 @@
#define PLAT_MAX_OFF_STATE U(2)
#define PLAT_MAX_RET_STATE U(1)
#define BL2_BASE ULL(0x80000000)
#define BL2_LIMIT ULL(0x80080000)
#define UNIPHIER_BL2_OFFSET UL(0x00000000)
#define UNIPHIER_BL2_MAX_SIZE UL(0x00080000)
/* 0x80080000-0x81000000: reserved for DSP */
/* 0x00080000-0x01000000: reserved for DSP */
#define UNIPHIER_SEC_DRAM_BASE 0x81000000ULL
#define UNIPHIER_SEC_DRAM_LIMIT 0x82000000ULL
#define UNIPHIER_SEC_DRAM_SIZE ((UNIPHIER_SEC_DRAM_LIMIT) - \
(UNIPHIER_SEC_DRAM_BASE))
#define UNIPHIER_BL31_OFFSET UL(0x01000000)
#define UNIPHIER_BL31_MAX_SIZE UL(0x00080000)
#define BL31_BASE ULL(0x81000000)
#define BL31_LIMIT ULL(0x81080000)
#define UNIPHIER_BL32_OFFSET UL(0x01080000)
#define UNIPHIER_BL32_MAX_SIZE UL(0x00100000)
#define BL32_BASE ULL(0x81080000)
#define BL32_LIMIT ULL(0x81180000)
/*
* The link addresses are determined by UNIPHIER_MEM_BASE + offset.
* When ENABLE_PIE is set, all the TF images can be loaded anywhere, so
* UNIPHIER_MEM_BASE is arbitrary.
*
* When ENABLE_PIE is unset, UNIPHIER_MEM_BASE should be chosen so that
* BL2_BASE matches to the physical address where BL2 is loaded, that is,
* UNIPHIER_MEM_BASE should be the base address of the DRAM region.
*/
#define UNIPHIER_MEM_BASE UL(0x00000000)
#define BL2_BASE (UNIPHIER_MEM_BASE + UNIPHIER_BL2_OFFSET)
#define BL2_LIMIT (BL2_BASE + UNIPHIER_BL2_MAX_SIZE)
#define BL31_BASE (UNIPHIER_MEM_BASE + UNIPHIER_BL31_OFFSET)
#define BL31_LIMIT (BL31_BASE + UNIPHIER_BL31_MAX_SIZE)
#define BL32_BASE (UNIPHIER_MEM_BASE + UNIPHIER_BL32_OFFSET)
#define BL32_LIMIT (BL32_BASE + UNIPHIER_BL32_MAX_SIZE)
#define PLAT_PHY_ADDR_SPACE_SIZE (1ULL << 32)
#define PLAT_VIRT_ADDR_SPACE_SIZE (1ULL << 32)
#define PLAT_XLAT_TABLES_DYNAMIC 1
#define MAX_XLAT_TABLES 7
#define MAX_MMAP_REGIONS 7
#define MAX_XLAT_TABLES 9
#define MAX_MMAP_REGIONS 13
#define MAX_IO_HANDLES 2
#define MAX_IO_DEVICES 2
......
#
# Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
# Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
......@@ -10,6 +10,10 @@ override PROGRAMMABLE_RESET_ADDRESS := 1
override USE_COHERENT_MEM := 1
override ENABLE_SVE_FOR_NS := 0
# Disabling ENABLE_PIE saves memory footprint a lot, but you need to adjust
# UNIPHIER_MEM_BASE so that all TF images are loaded at their link addresses.
override ENABLE_PIE := 1
# Cortex-A53 revision r0p4-51rel0
# needed for LD20, unneeded for LD11, PXs3 (no ACE)
ERRATA_A53_855873 := 1
......
/*
* Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
* Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
......@@ -11,8 +11,6 @@
#include "../uniphier.h"
#define BL32_SIZE ((BL32_END) - (BL32_BASE))
void tsp_early_platform_setup(void)
{
uniphier_console_setup();
......@@ -24,6 +22,6 @@ void tsp_platform_setup(void)
void tsp_plat_arch_setup(void)
{
uniphier_mmap_setup(BL32_BASE, BL32_SIZE, NULL);
uniphier_mmap_setup();
enable_mmu_el1(0);
}
/*
* Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
* Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
......@@ -36,24 +36,25 @@ unsigned int uniphier_get_boot_master(unsigned int soc);
void uniphier_console_setup(void);
int uniphier_emmc_init(uintptr_t *block_dev_spec);
int uniphier_nand_init(uintptr_t *block_dev_spec);
int uniphier_usb_init(unsigned int soc, uintptr_t *block_dev_spec);
struct io_block_dev_spec;
int uniphier_emmc_init(struct io_block_dev_spec **block_dev_spec);
int uniphier_nand_init(struct io_block_dev_spec **block_dev_spec);
int uniphier_usb_init(unsigned int soc,
struct io_block_dev_spec **block_dev_spec);
int uniphier_io_setup(unsigned int soc);
int uniphier_io_setup(unsigned int soc, uintptr_t mem_base);
void uniphier_init_image_descs(uintptr_t mem_base);
struct image_info;
struct image_info *uniphier_get_image_info(unsigned int image_id);
int uniphier_scp_is_running(void);
void uniphier_scp_start(void);
void uniphier_scp_start(uint32_t scp_base);
void uniphier_scp_open_com(void);
void uniphier_scp_system_off(void);
void uniphier_scp_system_reset(void);
struct mmap_region;
void uniphier_mmap_setup(uintptr_t total_base, size_t total_size,
const struct mmap_region *mmap);
void uniphier_mmap_setup(void);
void uniphier_cci_init(unsigned int soc);
void uniphier_cci_enable(void);
......@@ -67,25 +68,4 @@ void uniphier_gic_pcpu_init(void);
unsigned int uniphier_calc_core_pos(u_register_t mpidr);
#define UNIPHIER_NS_DRAM_BASE 0x84000000
#define UNIPHIER_NS_DRAM_LIMIT 0x85000000
#define UNIPHIER_NS_DRAM_SIZE ((UNIPHIER_NS_DRAM_LIMIT) - \
(UNIPHIER_NS_DRAM_BASE))
#define UNIPHIER_BL33_BASE (UNIPHIER_NS_DRAM_BASE)
#define UNIPHIER_BL33_MAX_SIZE 0x00100000
#define UNIPHIER_SCP_BASE ((UNIPHIER_BL33_BASE) + \
(UNIPHIER_BL33_MAX_SIZE))
#define UNIPHIER_SCP_MAX_SIZE 0x00020000
#define UNIPHIER_BLOCK_BUF_BASE ((UNIPHIER_SCP_BASE) + \
(UNIPHIER_SCP_MAX_SIZE))
#define UNIPHIER_BLOCK_BUF_SIZE 0x00100000
#define UNIPHIER_IMAGE_BUF_BASE ((UNIPHIER_BLOCK_BUF_BASE) + \
(UNIPHIER_BLOCK_BUF_SIZE))
#define UNIPHIER_IMAGE_BUF_SIZE ((UNIPHIER_NS_DRAM_LIMIT) - \
(UNIPHIER_IMAGE_BUF_BASE))
#endif /* UNIPHIER_H */
/*
* Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
* Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
......@@ -21,8 +21,10 @@
#include "uniphier.h"
#define BL2_SIZE ((BL2_END) - (BL2_BASE))
#define UNIPHIER_IMAGE_BUF_OFFSET 0x04300000UL
#define UNIPHIER_IMAGE_BUF_SIZE 0x00100000UL
static uintptr_t uniphier_mem_base = UNIPHIER_MEM_BASE;
static int uniphier_bl2_kick_scp;
void bl2_el3_early_platform_setup(u_register_t x0, u_register_t x1,
......@@ -31,32 +33,25 @@ void bl2_el3_early_platform_setup(u_register_t x0, u_register_t x1,
uniphier_console_setup();
}
static const struct mmap_region uniphier_bl2_mmap[] = {
/* for BL31, BL32 */
MAP_REGION_FLAT(UNIPHIER_SEC_DRAM_BASE, UNIPHIER_SEC_DRAM_SIZE,
MT_MEMORY | MT_RW | MT_SECURE),
/* for SCP, BL33 */
MAP_REGION_FLAT(UNIPHIER_NS_DRAM_BASE, UNIPHIER_NS_DRAM_SIZE,
MT_MEMORY | MT_RW | MT_NS),
{ .size = 0 },
};
void bl2_el3_plat_arch_setup(void)
{
unsigned int soc;
int skip_scp = 0;
int ret;
uniphier_mmap_setup(BL2_BASE, BL2_SIZE, uniphier_bl2_mmap);
uniphier_mmap_setup();
enable_mmu_el3(0);
/* add relocation offset (run-time-address - link-address) */
uniphier_mem_base += BL_CODE_BASE - BL2_BASE;
soc = uniphier_get_soc_id();
if (soc == UNIPHIER_SOC_UNKNOWN) {
ERROR("unsupported SoC\n");
plat_error_handler(-ENOTSUP);
}
ret = uniphier_io_setup(soc);
ret = uniphier_io_setup(soc, uniphier_mem_base);
if (ret) {
ERROR("failed to setup io devices\n");
plat_error_handler(ret);
......@@ -119,28 +114,47 @@ bl_params_t *plat_get_next_bl_params(void)
void bl2_plat_preload_setup(void)
{
#ifdef UNIPHIER_DECOMPRESS_GZIP
image_decompress_init(UNIPHIER_IMAGE_BUF_BASE,
uintptr_t buf_base = uniphier_mem_base + UNIPHIER_IMAGE_BUF_OFFSET;
int ret;
ret = mmap_add_dynamic_region(buf_base, buf_base,
UNIPHIER_IMAGE_BUF_SIZE,
gunzip);
MT_MEMORY | MT_RW | MT_NS);
if (ret)
plat_error_handler(ret);
image_decompress_init(buf_base, UNIPHIER_IMAGE_BUF_SIZE, gunzip);
#endif
uniphier_init_image_descs(uniphier_mem_base);
}
int bl2_plat_handle_pre_image_load(unsigned int image_id)
{
struct image_info *image_info;
int ret;
image_info = uniphier_get_image_info(image_id);
ret = mmap_add_dynamic_region(image_info->image_base,
image_info->image_base,
image_info->image_max_size,
MT_MEMORY | MT_RW | MT_NS);
if (ret)
return ret;
#ifdef UNIPHIER_DECOMPRESS_GZIP
image_decompress_prepare(uniphier_get_image_info(image_id));
image_decompress_prepare(image_info);
#endif
return 0;
}
int bl2_plat_handle_post_image_load(unsigned int image_id)
{
struct image_info *image_info = uniphier_get_image_info(image_id);
#ifdef UNIPHIER_DECOMPRESS_GZIP
struct image_info *image_info;
int ret;
image_info = uniphier_get_image_info(image_id);
if (!(image_info->h.attr & IMAGE_ATTRIB_SKIP_LOADING)) {
ret = image_decompress(uniphier_get_image_info(image_id));
if (ret)
......@@ -149,7 +163,7 @@ int bl2_plat_handle_post_image_load(unsigned int image_id)
#endif
if (image_id == SCP_BL2_IMAGE_ID && uniphier_bl2_kick_scp)
uniphier_scp_start();
uniphier_scp_start(image_info->image_base);
return 0;
}
/*
* Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
* Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
......@@ -19,8 +19,6 @@
#include "uniphier.h"
#define BL31_SIZE ((BL31_END) - (BL31_BASE))
static entry_point_info_t bl32_image_ep_info;
static entry_point_info_t bl33_image_ep_info;
......@@ -81,6 +79,6 @@ void bl31_platform_setup(void)
void bl31_plat_arch_setup(void)
{
uniphier_mmap_setup(BL31_BASE, BL31_SIZE, NULL);
uniphier_mmap_setup();
enable_mmu_el3(0);
}
/*
* Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
* Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
......@@ -225,11 +225,7 @@ static size_t uniphier_emmc_read(int lba, uintptr_t buf, size_t size)
return ret ? 0 : size;
}
static const struct io_block_dev_spec uniphier_emmc_dev_spec = {
.buffer = {
.offset = UNIPHIER_BLOCK_BUF_BASE,
.length = UNIPHIER_BLOCK_BUF_SIZE,
},
static struct io_block_dev_spec uniphier_emmc_dev_spec = {
.ops = {
.read = uniphier_emmc_read,
},
......@@ -278,7 +274,7 @@ static int uniphier_emmc_hw_init(void)
return 0;
}
int uniphier_emmc_init(uintptr_t *block_dev_spec)
int uniphier_emmc_init(struct io_block_dev_spec **block_dev_spec)
{
int ret;
......@@ -286,7 +282,7 @@ int uniphier_emmc_init(uintptr_t *block_dev_spec)
if (ret)
return ret;
*block_dev_spec = (uintptr_t)&uniphier_emmc_dev_spec;
*block_dev_spec = &uniphier_emmc_dev_spec;
return 0;
}
/*
* Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
* Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
......@@ -13,13 +13,19 @@
#include "uniphier.h"
#define UNIPHIER_BL33_OFFSET 0x04000000UL
#define UNIPHIER_BL33_MAX_SIZE 0x00100000UL
#define UNIPHIER_SCP_OFFSET 0x04100000UL
#define UNIPHIER_SCP_MAX_SIZE 0x00020000UL
static struct bl_mem_params_node uniphier_image_descs[] = {
{
.image_id = SCP_BL2_IMAGE_ID,
SET_STATIC_PARAM_HEAD(image_info, PARAM_EP,
VERSION_2, image_info_t, 0),
.image_info.image_base = UNIPHIER_SCP_BASE,
.image_info.image_base = UNIPHIER_SCP_OFFSET,
.image_info.image_max_size = UNIPHIER_SCP_MAX_SIZE,
SET_STATIC_PARAM_HEAD(ep_info, PARAM_EP,
......@@ -33,13 +39,13 @@ static struct bl_mem_params_node uniphier_image_descs[] = {
SET_STATIC_PARAM_HEAD(image_info, PARAM_EP,
VERSION_2, image_info_t, 0),
.image_info.image_base = BL31_BASE,
.image_info.image_max_size = BL31_LIMIT - BL31_BASE,
.image_info.image_base = UNIPHIER_BL31_OFFSET,
.image_info.image_max_size = UNIPHIER_BL31_MAX_SIZE,
SET_STATIC_PARAM_HEAD(ep_info, PARAM_EP,
VERSION_2, entry_point_info_t,
SECURE | EXECUTABLE | EP_FIRST_EXE),
.ep_info.pc = BL31_BASE,
.ep_info.pc = UNIPHIER_BL31_OFFSET,
.ep_info.spsr = SPSR_64(MODE_EL3, MODE_SP_ELX,
DISABLE_ALL_EXCEPTIONS),
......@@ -55,13 +61,13 @@ static struct bl_mem_params_node uniphier_image_descs[] = {
SET_STATIC_PARAM_HEAD(image_info, PARAM_EP,
VERSION_2, image_info_t, 0),
.image_info.image_base = BL32_BASE,
.image_info.image_max_size = BL32_LIMIT - BL32_BASE,
.image_info.image_base = UNIPHIER_BL32_OFFSET,
.image_info.image_max_size = UNIPHIER_BL32_MAX_SIZE,
SET_STATIC_PARAM_HEAD(ep_info, PARAM_EP,
VERSION_2, entry_point_info_t,
SECURE | EXECUTABLE),
.ep_info.pc = BL32_BASE,
.ep_info.pc = UNIPHIER_BL32_OFFSET,
.ep_info.spsr = SPSR_64(MODE_EL3, MODE_SP_ELX,
DISABLE_ALL_EXCEPTIONS),
......@@ -73,13 +79,13 @@ static struct bl_mem_params_node uniphier_image_descs[] = {
SET_STATIC_PARAM_HEAD(image_info, PARAM_EP,
VERSION_2, image_info_t, 0),
.image_info.image_base = UNIPHIER_BL33_BASE,
.image_info.image_base = UNIPHIER_BL33_OFFSET,
.image_info.image_max_size = UNIPHIER_BL33_MAX_SIZE,
SET_STATIC_PARAM_HEAD(ep_info, PARAM_EP,
VERSION_2, entry_point_info_t,
NON_SECURE | EXECUTABLE),
.ep_info.pc = UNIPHIER_BL33_BASE,
.ep_info.pc = UNIPHIER_BL33_OFFSET,
.ep_info.spsr = SPSR_64(MODE_EL2, MODE_SP_ELX,
DISABLE_ALL_EXCEPTIONS),
......@@ -88,6 +94,21 @@ static struct bl_mem_params_node uniphier_image_descs[] = {
};
REGISTER_BL_IMAGE_DESCS(uniphier_image_descs)
/*
* image_info.image_base and ep_info.pc are the offset from the memory base.
* When ENABLE_PIE is set, we never know the real memory base at link-time.
* Fix-up the addresses by adding the run-time detected base.
*/
void uniphier_init_image_descs(uintptr_t mem_base)
{
int i;
for (i = 0; i < ARRAY_SIZE(uniphier_image_descs); i++) {
uniphier_image_descs[i].image_info.image_base += mem_base;
uniphier_image_descs[i].ep_info.pc += mem_base;
}
}
struct image_info *uniphier_get_image_info(unsigned int image_id)
{
struct bl_mem_params_node *desc;
......
/*
* Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
* Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
......@@ -26,6 +26,9 @@
#define UNIPHIER_OCM_REGION_BASE 0x30000000ULL
#define UNIPHIER_OCM_REGION_SIZE 0x00040000ULL
#define UNIPHIER_BLOCK_BUF_OFFSET 0x04200000UL
#define UNIPHIER_BLOCK_BUF_SIZE 0x00100000UL
static const io_dev_connector_t *uniphier_fip_dev_con;
static uintptr_t uniphier_fip_dev_handle;
......@@ -189,17 +192,29 @@ static const struct uniphier_io_policy uniphier_io_policies[] = {
#endif
};
static int uniphier_io_block_setup(size_t fip_offset, uintptr_t block_dev_spec)
static int uniphier_io_block_setup(size_t fip_offset,
struct io_block_dev_spec *block_dev_spec,
size_t buffer_offset)
{
int ret;
uniphier_fip_spec.offset = fip_offset;
block_dev_spec->buffer.offset = buffer_offset;
block_dev_spec->buffer.length = UNIPHIER_BLOCK_BUF_SIZE;
ret = mmap_add_dynamic_region(block_dev_spec->buffer.offset,
block_dev_spec->buffer.offset,
block_dev_spec->buffer.length,
MT_MEMORY | MT_RW | MT_NS);
if (ret)
return ret;
ret = register_io_dev_block(&uniphier_backend_dev_con);
if (ret)
return ret;
return io_dev_open(uniphier_backend_dev_con, block_dev_spec,
return io_dev_open(uniphier_backend_dev_con, (uintptr_t)block_dev_spec,
&uniphier_backend_dev_handle);
}
......@@ -234,38 +249,38 @@ static int uniphier_io_fip_setup(void)
return io_dev_open(uniphier_fip_dev_con, 0, &uniphier_fip_dev_handle);
}
static int uniphier_io_emmc_setup(unsigned int soc_id)
static int uniphier_io_emmc_setup(unsigned int soc_id, size_t buffer_offset)
{
uintptr_t block_dev_spec;
struct io_block_dev_spec *block_dev_spec;
int ret;
ret = uniphier_emmc_init(&block_dev_spec);
if (ret)
return ret;
return uniphier_io_block_setup(0x20000, block_dev_spec);
return uniphier_io_block_setup(0x20000, block_dev_spec, buffer_offset);
}
static int uniphier_io_nand_setup(unsigned int soc_id)
static int uniphier_io_nand_setup(unsigned int soc_id, size_t buffer_offset)
{
uintptr_t block_dev_spec;
struct io_block_dev_spec *block_dev_spec;
int ret;
ret = uniphier_nand_init(&block_dev_spec);
if (ret)
return ret;
return uniphier_io_block_setup(0x20000, block_dev_spec);
return uniphier_io_block_setup(0x20000, block_dev_spec, buffer_offset);
}
static int uniphier_io_nor_setup(unsigned int soc_id)
static int uniphier_io_nor_setup(unsigned int soc_id, size_t buffer_offset)
{
return uniphier_io_memmap_setup(0x70000);
}
static int uniphier_io_usb_setup(unsigned int soc_id)
static int uniphier_io_usb_setup(unsigned int soc_id, size_t buffer_offset)
{
uintptr_t block_dev_spec;
struct io_block_dev_spec *block_dev_spec;
int ret;
/* use ROM API for loading images from USB storage */
......@@ -292,19 +307,19 @@ static int uniphier_io_usb_setup(unsigned int soc_id)
if (ret)
return ret;
return uniphier_io_block_setup(0x20000, block_dev_spec);
return uniphier_io_block_setup(0x20000, block_dev_spec, buffer_offset);
}
static int (* const uniphier_io_setup_table[])(unsigned int) = {
static int (* const uniphier_io_setup_table[])(unsigned int, size_t) = {
[UNIPHIER_BOOT_DEVICE_EMMC] = uniphier_io_emmc_setup,
[UNIPHIER_BOOT_DEVICE_NAND] = uniphier_io_nand_setup,
[UNIPHIER_BOOT_DEVICE_NOR] = uniphier_io_nor_setup,
[UNIPHIER_BOOT_DEVICE_USB] = uniphier_io_usb_setup,
};
int uniphier_io_setup(unsigned int soc_id)
int uniphier_io_setup(unsigned int soc_id, uintptr_t mem_base)
{
int (*io_setup)(unsigned int soc_id);
int (*io_setup)(unsigned int soc_id, size_t buffer_offset);
unsigned int boot_dev;
int ret;
......@@ -313,7 +328,7 @@ int uniphier_io_setup(unsigned int soc_id)
return -EINVAL;
io_setup = uniphier_io_setup_table[boot_dev];
ret = io_setup(soc_id);
ret = io_setup(soc_id, mem_base + UNIPHIER_BLOCK_BUF_OFFSET);
if (ret)
return ret;
......
/*
* Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
* Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
......@@ -224,10 +224,6 @@ static size_t uniphier_nand_read(int lba, uintptr_t buf, size_t size)
}
static struct io_block_dev_spec uniphier_nand_dev_spec = {
.buffer = {
.offset = UNIPHIER_BLOCK_BUF_BASE,
.length = UNIPHIER_BLOCK_BUF_SIZE,
},
.ops = {
.read = uniphier_nand_read,
},
......@@ -259,7 +255,7 @@ static int uniphier_nand_hw_init(struct uniphier_nand *nand)
return 0;
}
int uniphier_nand_init(uintptr_t *block_dev_spec)
int uniphier_nand_init(struct io_block_dev_spec **block_dev_spec)
{
int ret;
......@@ -269,7 +265,7 @@ int uniphier_nand_init(uintptr_t *block_dev_spec)
uniphier_nand_dev_spec.block_size = uniphier_nand.page_size;
*block_dev_spec = (uintptr_t)&uniphier_nand_dev_spec;
*block_dev_spec = &uniphier_nand_dev_spec;
return 0;
}
/*
* Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
* Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
......@@ -28,11 +28,11 @@ int uniphier_scp_is_running(void)
return mmio_read_32(UNIPHIER_STMBE2COM) == UNIPHIER_SCP_READY_MAGIC;
}
void uniphier_scp_start(void)
void uniphier_scp_start(uint32_t scp_base)
{
uint32_t tmp;
mmio_write_32(UNIPHIER_STMBE2COM + 4, UNIPHIER_SCP_BASE);
mmio_write_32(UNIPHIER_STMBE2COM + 4, scp_base);
mmio_write_32(UNIPHIER_STMBE2COM, UNIPHIER_SCP_READY_MAGIC);
do {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment