blob: bd64cccd0c9a9029cc3902dc380a02b9eeeee758 [file] [log] [blame]
Antonio Nino Diazf2218e72019-03-19 10:59:11 +00001/*
2 * Copyright (c) 2018, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <assert.h>
8#include <console.h>
9#include <debug.h>
10#include <pl011.h>
11#include <platform_def.h>
12#include <secure_partition.h>
13#include <sp_helpers.h>
14#include <spm_svc.h>
15#include <std_svc.h>
16
17#include "cactus_mm.h"
18#include "cactus_mm_tests.h"
19
20
21/* Host machine information injected by the build system in the ELF file. */
22extern const char build_message[];
23extern const char version_string[];
24
25/*
26 * The ARM Trusted Firmware passes a description of the memory resources
27 * allocated to the secure partition through the x0 register. This maps to
28 * a secure_partition_boot_info_t structure type.
29 *
30 * This functions prints the information stored in this structure.
31 */
32static void cactus_print_memory_layout(const secure_partition_boot_info_t *boot_info)
33{
34 NOTICE("Secure Partition memory layout:\n");
35
36 NOTICE(" Secure Partition image : %p - %p\n",
37 (void *) boot_info->sp_image_base,
38 (void *)(boot_info->sp_image_base + boot_info->sp_image_size));
39 NOTICE(" Text region : %p - %p\n",
40 (void *) CACTUS_TEXT_START, (void *) CACTUS_TEXT_END);
41 NOTICE(" Read-only data region : %p - %p\n",
42 (void *) CACTUS_RODATA_START, (void *) CACTUS_RODATA_END);
43 NOTICE(" Read-write data region : %p - %p\n",
44 (void *) CACTUS_RWDATA_START, (void *) CACTUS_RWDATA_END);
45 NOTICE(" BSS region : %p - %p\n",
46 (void *) CACTUS_BSS_START, (void *) CACTUS_BSS_END);
47 NOTICE(" Unused SP image space : %p - %p\n",
48 (void *) CACTUS_BSS_END,
49 (void *)(boot_info->sp_image_base + boot_info->sp_image_size));
50
51 NOTICE(" EL3-EL0 shared buffer : %p - %p\n",
52 (void *) boot_info->sp_shared_buf_base,
53 (void *)(boot_info->sp_shared_buf_base + boot_info->sp_shared_buf_size));
54
55 NOTICE(" S-NS shared buffer : %p - %p\n",
56 (void *) boot_info->sp_ns_comm_buf_base,
57 (void *)(boot_info->sp_ns_comm_buf_base + boot_info->sp_ns_comm_buf_size));
58
59 assert(boot_info->sp_ns_comm_buf_base == ARM_SECURE_SERVICE_BUFFER_BASE);
60 assert(boot_info->sp_ns_comm_buf_size == ARM_SECURE_SERVICE_BUFFER_SIZE);
61
62 NOTICE(" Stacks region (%u CPUS) : %p - %p\n",
63 boot_info->num_cpus,
64 (void *) boot_info->sp_stack_base,
65 (void *)(boot_info->sp_stack_base +
66 (boot_info->sp_pcpu_stack_size * boot_info->num_cpus)));
67
68 NOTICE(" Heap region : %p - %p\n",
69 (void *) boot_info->sp_heap_base,
70 (void *)(boot_info->sp_heap_base + boot_info->sp_heap_size));
71
72 NOTICE("Total memory : %p - %p\n",
73 (void *) boot_info->sp_mem_base, (void *) boot_info->sp_mem_limit);
74}
75
76
77void __dead2 cactus_main(void *el3_el0_buffer, size_t el3_el0_buffer_size)
78{
79 console_init(PL011_UART2_BASE,
80 PL011_UART2_CLK_IN_HZ,
81 PL011_BAUDRATE);
82
83 NOTICE("Booting test Secure Partition Cactus\n");
84 NOTICE("%s\n", build_message);
85 NOTICE("%s\n", version_string);
86 NOTICE("Running at S-EL0\n");
87
88 const secure_partition_boot_info_t *boot_info =
89 (const secure_partition_boot_info_t *) el3_el0_buffer;
90
91 if (el3_el0_buffer_size < sizeof(secure_partition_boot_info_t)) {
92 ERROR("The memory buffer shared between EL3/S-EL0 is too small\n");
93 ERROR("It is %lu bytes, it should be at least %lu bytes\n",
94 el3_el0_buffer_size,
95 sizeof(secure_partition_boot_info_t));
96 panic();
97 }
98
99 if ((CACTUS_TEXT_START != boot_info->sp_image_base) ||
100 (CACTUS_RWDATA_END > boot_info->sp_image_base
101 + boot_info->sp_image_size)) {
102 ERROR("Cactus does not fit in the buffer allocated for the secure partition\n");
103 panic();
104 }
105
106 cactus_print_memory_layout(boot_info);
107
108
109 /*
110 * Run some initial tests.
111 *
112 * These are executed when the system is still booting, just after SPM
113 * has handed over to Cactus.
114 */
115 misc_tests();
116 system_setup_tests();
Antonio Nino Diazeb1a4162019-03-20 16:03:49 +0000117 mem_attr_changes_tests(boot_info);
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000118
119 /*
120 * Handle secure service requests.
121 */
122 secure_services_loop();
123}