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