plat_bl_common.c 2.5 KB
Newer Older
1
/*
2
 * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
3
4
5
6
7
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <arch_helpers.h>
8
9
10
11
#include <assert.h>
#include <bl_common.h>
#include <debug.h>
#include <errno.h>
12
13
14
#if TRUSTED_BOARD_BOOT
#include <mbedtls_config.h>
#endif
15
#include <platform.h>
16
#include <xlat_tables_compat.h>
17
18

/*
19
20
 * The following platform functions are weakly defined. The Platforms
 * may redefine with strong definition.
21
 */
22
#pragma weak bl2_el3_plat_prepare_exit
23
24
#pragma weak plat_error_handler
#pragma weak bl2_plat_preload_setup
25
26
#pragma weak bl2_plat_handle_pre_image_load
#pragma weak bl2_plat_handle_post_image_load
27
#pragma weak plat_try_next_boot_source
28
#pragma weak plat_get_mbedtls_heap
29

30
void bl2_el3_plat_prepare_exit(void)
31
32
33
{
}

34
void __dead2 plat_error_handler(int err)
35
{
36
37
	while (1)
		wfi();
38
39
}

40
41
42
43
void bl2_plat_preload_setup(void)
{
}

44
45
46
47
48
49
50
51
52
53
int bl2_plat_handle_pre_image_load(unsigned int image_id)
{
	return 0;
}

int bl2_plat_handle_post_image_load(unsigned int image_id)
{
	return 0;
}

54
55
56
57
int plat_try_next_boot_source(void)
{
	return 0;
}
58

59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#if TRUSTED_BOARD_BOOT
/*
 * The following default implementation of the function simply returns the
 * by-default allocated heap.
 */
int plat_get_mbedtls_heap(void **heap_addr, size_t *heap_size)
{
	static unsigned char heap[TF_MBEDTLS_HEAP_SIZE];

	assert(heap_addr != NULL);
	assert(heap_size != NULL);

	*heap_addr = heap;
	*heap_size = sizeof(heap);
	return 0;
}
#endif /* TRUSTED_BOARD_BOOT */
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112

/*
 * Set up the page tables for the generic and platform-specific memory regions.
 * The size of the Trusted SRAM seen by the BL image must be specified as well
 * as an array specifying the generic memory regions which can be;
 * - Code section;
 * - Read-only data section;
 * - Init code section, if applicable
 * - Coherent memory region, if applicable.
 */

void __init setup_page_tables(const mmap_region_t *bl_regions,
			      const mmap_region_t *plat_regions)
{
#if LOG_LEVEL >= LOG_LEVEL_VERBOSE
	const mmap_region_t *regions = bl_regions;

	while (regions->size != 0U) {
		VERBOSE("Region: 0x%lx - 0x%lx has attributes 0x%x\n",
				regions->base_va,
				regions->base_va + regions->size,
				regions->attr);
		regions++;
	}
#endif
	/*
	 * Map the Trusted SRAM with appropriate memory attributes.
	 * Subsequent mappings will adjust the attributes for specific regions.
	 */
	mmap_add(bl_regions);

	/* Now (re-)map the platform-specific memory regions */
	mmap_add(plat_regions);

	/* Create the page tables to reflect the above mappings */
	init_xlat_tables();
}