Yatharth Kochar | a65be2f | 2015-10-09 18:06:13 +0100 | [diff] [blame] | 1 | /* |
Soby Mathew | 6e16a33 | 2018-01-10 12:51:34 +0000 | [diff] [blame] | 2 | * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved. |
Yatharth Kochar | a65be2f | 2015-10-09 18:06:13 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Yatharth Kochar | a65be2f | 2015-10-09 18:06:13 +0100 | [diff] [blame] | 5 | */ |
Yatharth Kochar | 71c9a5e | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 6 | |
| 7 | #include <arch_helpers.h> |
| 8 | #include <assert.h> |
Yatharth Kochar | a65be2f | 2015-10-09 18:06:13 +0100 | [diff] [blame] | 9 | #include <bl_common.h> |
Soby Mathew | 6e16a33 | 2018-01-10 12:51:34 +0000 | [diff] [blame] | 10 | #include <bl1.h> |
Yatharth Kochar | a65be2f | 2015-10-09 18:06:13 +0100 | [diff] [blame] | 11 | #include <debug.h> |
Yatharth Kochar | 71c9a5e | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 12 | #include <errno.h> |
Soby Mathew | 2f38ce3 | 2018-02-08 17:45:12 +0000 | [diff] [blame] | 13 | #include <platform.h> |
Yatharth Kochar | a65be2f | 2015-10-09 18:06:13 +0100 | [diff] [blame] | 14 | #include <platform_def.h> |
| 15 | |
| 16 | /* |
| 17 | * The following platform functions are weakly defined. They |
Yatharth Kochar | 71c9a5e | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 18 | * are default implementations that allow BL1 to compile in |
Yatharth Kochar | a65be2f | 2015-10-09 18:06:13 +0100 | [diff] [blame] | 19 | * absence of real definitions. The Platforms may override |
| 20 | * with more complex definitions. |
| 21 | */ |
| 22 | #pragma weak bl1_plat_get_next_image_id |
| 23 | #pragma weak bl1_plat_set_ep_info |
| 24 | #pragma weak bl1_plat_get_image_desc |
Yatharth Kochar | 71c9a5e | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 25 | #pragma weak bl1_plat_fwu_done |
Soby Mathew | 2f38ce3 | 2018-02-08 17:45:12 +0000 | [diff] [blame] | 26 | #pragma weak bl1_plat_handle_pre_image_load |
| 27 | #pragma weak bl1_plat_handle_post_image_load |
Yatharth Kochar | a65be2f | 2015-10-09 18:06:13 +0100 | [diff] [blame] | 28 | |
| 29 | |
| 30 | unsigned int bl1_plat_get_next_image_id(void) |
| 31 | { |
| 32 | /* BL2 load will be done by default. */ |
| 33 | return BL2_IMAGE_ID; |
| 34 | } |
| 35 | |
| 36 | void bl1_plat_set_ep_info(unsigned int image_id, |
| 37 | entry_point_info_t *ep_info) |
| 38 | { |
| 39 | |
| 40 | } |
| 41 | |
Soby Mathew | 2f38ce3 | 2018-02-08 17:45:12 +0000 | [diff] [blame] | 42 | int bl1_plat_handle_pre_image_load(unsigned int image_id) |
| 43 | { |
| 44 | return 0; |
| 45 | } |
| 46 | |
Yatharth Kochar | a65be2f | 2015-10-09 18:06:13 +0100 | [diff] [blame] | 47 | /* |
| 48 | * Following is the default definition that always |
| 49 | * returns BL2 image details. |
| 50 | */ |
| 51 | image_desc_t *bl1_plat_get_image_desc(unsigned int image_id) |
| 52 | { |
| 53 | static image_desc_t bl2_img_desc = BL2_IMAGE_DESC; |
| 54 | return &bl2_img_desc; |
| 55 | } |
Yatharth Kochar | 71c9a5e | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 56 | |
Dan Handley | 89f8f33 | 2015-12-15 14:28:24 +0000 | [diff] [blame] | 57 | __dead2 void bl1_plat_fwu_done(void *client_cookie, void *reserved) |
Yatharth Kochar | 71c9a5e | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 58 | { |
| 59 | while (1) |
| 60 | wfi(); |
| 61 | } |
| 62 | |
| 63 | /* |
| 64 | * The Platforms must override with real definition. |
| 65 | */ |
| 66 | #pragma weak bl1_plat_mem_check |
| 67 | |
| 68 | int bl1_plat_mem_check(uintptr_t mem_base, unsigned int mem_size, |
| 69 | unsigned int flags) |
| 70 | { |
| 71 | assert(0); |
| 72 | return -ENOMEM; |
| 73 | } |
Soby Mathew | 6e16a33 | 2018-01-10 12:51:34 +0000 | [diff] [blame] | 74 | |
| 75 | /* |
| 76 | * Default implementation for bl1_plat_handle_post_image_load(). This function |
| 77 | * populates the default arguments to BL2. The BL2 memory layout structure |
| 78 | * is allocated and the calculated layout is populated in arg1 to BL2. |
| 79 | */ |
| 80 | int bl1_plat_handle_post_image_load(unsigned int image_id) |
| 81 | { |
| 82 | meminfo_t *bl2_tzram_layout; |
| 83 | meminfo_t *bl1_tzram_layout; |
| 84 | image_desc_t *image_desc; |
| 85 | entry_point_info_t *ep_info; |
| 86 | |
| 87 | if (image_id != BL2_IMAGE_ID) |
| 88 | return 0; |
| 89 | |
| 90 | /* Get the image descriptor */ |
| 91 | image_desc = bl1_plat_get_image_desc(BL2_IMAGE_ID); |
Soby Mathew | cc36484 | 2018-02-21 01:16:39 +0000 | [diff] [blame] | 92 | assert(image_desc != NULL); |
Soby Mathew | 6e16a33 | 2018-01-10 12:51:34 +0000 | [diff] [blame] | 93 | |
| 94 | /* Get the entry point info */ |
| 95 | ep_info = &image_desc->ep_info; |
| 96 | |
| 97 | /* Find out how much free trusted ram remains after BL1 load */ |
| 98 | bl1_tzram_layout = bl1_plat_sec_mem_layout(); |
| 99 | |
| 100 | /* |
| 101 | * Create a new layout of memory for BL2 as seen by BL1 i.e. |
| 102 | * tell it the amount of total and free memory available. |
| 103 | * This layout is created at the first free address visible |
| 104 | * to BL2. BL2 will read the memory layout before using its |
| 105 | * memory for other purposes. |
| 106 | */ |
| 107 | #if LOAD_IMAGE_V2 |
| 108 | bl2_tzram_layout = (meminfo_t *) bl1_tzram_layout->total_base; |
| 109 | #else |
Antonio Nino Diaz | 6e0b102 | 2018-05-14 15:45:31 +0100 | [diff] [blame] | 110 | bl2_tzram_layout = (meminfo_t *) round_up(bl1_tzram_layout->free_base, |
| 111 | sizeof(uint64_t)); |
Soby Mathew | 6e16a33 | 2018-01-10 12:51:34 +0000 | [diff] [blame] | 112 | #endif /* LOAD_IMAGE_V2 */ |
| 113 | |
| 114 | #if !ERROR_DEPRECATED |
| 115 | bl1_init_bl2_mem_layout(bl1_tzram_layout, bl2_tzram_layout); |
| 116 | #else |
| 117 | bl1_calc_bl2_mem_layout(bl1_tzram_layout, bl2_tzram_layout); |
| 118 | #endif |
| 119 | |
| 120 | ep_info->args.arg1 = (uintptr_t)bl2_tzram_layout; |
| 121 | |
| 122 | VERBOSE("BL1: BL2 memory layout address = %p\n", |
| 123 | (void *) bl2_tzram_layout); |
| 124 | return 0; |
| 125 | } |