Jorge Ramirez-Ortiz | a29d9a6 | 2017-06-28 10:11:31 +0200 | [diff] [blame] | 1 | /* |
Joel Hutton | 5cc3bc8 | 2018-03-21 11:40:57 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. |
Jorge Ramirez-Ortiz | a29d9a6 | 2017-06-28 10:11:31 +0200 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <arch_helpers.h> |
| 8 | #include <assert.h> |
| 9 | #include <bl_common.h> |
| 10 | #include <console.h> |
| 11 | #include <debug.h> |
Victor Chong | 539408d | 2018-01-03 01:53:08 +0900 | [diff] [blame] | 12 | #include <dw_mmc.h> |
Jorge Ramirez-Ortiz | a29d9a6 | 2017-06-28 10:11:31 +0200 | [diff] [blame] | 13 | #include <errno.h> |
| 14 | #include <generic_delay_timer.h> |
Haojian Zhuang | 3eff409 | 2018-08-04 18:07:26 +0800 | [diff] [blame] | 15 | #include <mmc.h> |
Jorge Ramirez-Ortiz | a29d9a6 | 2017-06-28 10:11:31 +0200 | [diff] [blame] | 16 | #include <mmio.h> |
| 17 | #include <pl061_gpio.h> |
| 18 | #include <platform.h> |
| 19 | #include <platform_def.h> |
| 20 | #include <string.h> |
| 21 | #include <tbbr_img_def.h> |
| 22 | #include "../../bl1/bl1_private.h" |
| 23 | #include "hi3798cv200.h" |
| 24 | #include "plat_private.h" |
| 25 | |
Jorge Ramirez-Ortiz | a29d9a6 | 2017-06-28 10:11:31 +0200 | [diff] [blame] | 26 | /* Data structure which holds the extents of the trusted RAM for BL1 */ |
| 27 | static meminfo_t bl1_tzram_layout; |
Antonio Nino Diaz | e93cde1 | 2018-09-24 17:15:15 +0100 | [diff] [blame] | 28 | static meminfo_t bl2_tzram_layout; |
Jorge Ramirez-Ortiz | a29d9a6 | 2017-06-28 10:11:31 +0200 | [diff] [blame] | 29 | |
Antonio Nino Diaz | e93cde1 | 2018-09-24 17:15:15 +0100 | [diff] [blame] | 30 | /* |
| 31 | * Cannot use default weak implementation in bl1_main.c because BL1 RW data is |
| 32 | * not at the top of the secure memory. |
| 33 | */ |
| 34 | int bl1_plat_handle_post_image_load(unsigned int image_id) |
Jorge Ramirez-Ortiz | a29d9a6 | 2017-06-28 10:11:31 +0200 | [diff] [blame] | 35 | { |
Antonio Nino Diaz | e93cde1 | 2018-09-24 17:15:15 +0100 | [diff] [blame] | 36 | image_desc_t *image_desc; |
| 37 | entry_point_info_t *ep_info; |
Jorge Ramirez-Ortiz | a29d9a6 | 2017-06-28 10:11:31 +0200 | [diff] [blame] | 38 | |
Antonio Nino Diaz | e93cde1 | 2018-09-24 17:15:15 +0100 | [diff] [blame] | 39 | if (image_id != BL2_IMAGE_ID) |
| 40 | return 0; |
| 41 | |
| 42 | /* Get the image descriptor */ |
| 43 | image_desc = bl1_plat_get_image_desc(BL2_IMAGE_ID); |
| 44 | assert(image_desc != NULL); |
| 45 | |
| 46 | /* Get the entry point info */ |
| 47 | ep_info = &image_desc->ep_info; |
Victor Chong | 175dd8a | 2018-02-01 00:35:22 +0900 | [diff] [blame] | 48 | |
Antonio Nino Diaz | e93cde1 | 2018-09-24 17:15:15 +0100 | [diff] [blame] | 49 | bl2_tzram_layout.total_base = BL2_BASE; |
| 50 | bl2_tzram_layout.total_size = BL32_LIMIT - BL2_BASE; |
Victor Chong | 175dd8a | 2018-02-01 00:35:22 +0900 | [diff] [blame] | 51 | |
Antonio Nino Diaz | e93cde1 | 2018-09-24 17:15:15 +0100 | [diff] [blame] | 52 | flush_dcache_range((uintptr_t)&bl2_tzram_layout, sizeof(meminfo_t)); |
Victor Chong | 175dd8a | 2018-02-01 00:35:22 +0900 | [diff] [blame] | 53 | |
Antonio Nino Diaz | e93cde1 | 2018-09-24 17:15:15 +0100 | [diff] [blame] | 54 | ep_info->args.arg1 = (uintptr_t)&bl2_tzram_layout; |
| 55 | |
| 56 | VERBOSE("BL1: BL2 memory layout address = %p\n", |
| 57 | (void *)&bl2_tzram_layout); |
| 58 | |
| 59 | return 0; |
Victor Chong | 175dd8a | 2018-02-01 00:35:22 +0900 | [diff] [blame] | 60 | } |
Victor Chong | 175dd8a | 2018-02-01 00:35:22 +0900 | [diff] [blame] | 61 | |
Jorge Ramirez-Ortiz | a29d9a6 | 2017-06-28 10:11:31 +0200 | [diff] [blame] | 62 | void bl1_early_platform_setup(void) |
| 63 | { |
| 64 | /* Initialize the console to provide early debug support */ |
| 65 | console_init(PL011_UART0_BASE, PL011_UART0_CLK_IN_HZ, PL011_BAUDRATE); |
| 66 | |
| 67 | /* Allow BL1 to see the whole Trusted RAM */ |
Victor Chong | 175dd8a | 2018-02-01 00:35:22 +0900 | [diff] [blame] | 68 | bl1_tzram_layout.total_base = BL1_RW_BASE; |
| 69 | bl1_tzram_layout.total_size = BL1_RW_SIZE; |
Jorge Ramirez-Ortiz | a29d9a6 | 2017-06-28 10:11:31 +0200 | [diff] [blame] | 70 | |
Jorge Ramirez-Ortiz | a29d9a6 | 2017-06-28 10:11:31 +0200 | [diff] [blame] | 71 | INFO("BL1: 0x%lx - 0x%lx [size = %zu]\n", BL1_RAM_BASE, BL1_RAM_LIMIT, |
| 72 | BL1_RAM_LIMIT - BL1_RAM_BASE); |
| 73 | } |
| 74 | |
| 75 | void bl1_plat_arch_setup(void) |
| 76 | { |
| 77 | plat_configure_mmu_el3(bl1_tzram_layout.total_base, |
| 78 | bl1_tzram_layout.total_size, |
Victor Chong | 175dd8a | 2018-02-01 00:35:22 +0900 | [diff] [blame] | 79 | BL1_RO_BASE, /* l-loader and BL1 ROM */ |
Jorge Ramirez-Ortiz | a29d9a6 | 2017-06-28 10:11:31 +0200 | [diff] [blame] | 80 | BL1_RO_LIMIT, |
Joel Hutton | 5cc3bc8 | 2018-03-21 11:40:57 +0000 | [diff] [blame] | 81 | BL_COHERENT_RAM_BASE, |
| 82 | BL_COHERENT_RAM_END); |
Jorge Ramirez-Ortiz | a29d9a6 | 2017-06-28 10:11:31 +0200 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | void bl1_platform_setup(void) |
| 86 | { |
| 87 | int i; |
Victor Chong | f0c7c61 | 2018-01-16 00:29:47 +0900 | [diff] [blame] | 88 | #if !POPLAR_RECOVERY |
Shawn Guo | d793ff0 | 2018-09-27 16:48:00 +0800 | [diff] [blame] | 89 | struct mmc_device_info info; |
Victor Chong | 539408d | 2018-01-03 01:53:08 +0900 | [diff] [blame] | 90 | dw_mmc_params_t params = EMMC_INIT_PARAMS(POPLAR_EMMC_DESC_BASE); |
Victor Chong | f0c7c61 | 2018-01-16 00:29:47 +0900 | [diff] [blame] | 91 | #endif |
Jorge Ramirez-Ortiz | a29d9a6 | 2017-06-28 10:11:31 +0200 | [diff] [blame] | 92 | |
| 93 | generic_delay_timer_init(); |
| 94 | |
| 95 | pl061_gpio_init(); |
| 96 | for (i = 0; i < GPIO_MAX; i++) |
| 97 | pl061_gpio_register(GPIO_BASE(i), i); |
| 98 | |
Victor Chong | f0c7c61 | 2018-01-16 00:29:47 +0900 | [diff] [blame] | 99 | #if !POPLAR_RECOVERY |
Victor Chong | 539408d | 2018-01-03 01:53:08 +0900 | [diff] [blame] | 100 | /* SoC-specific emmc register are initialized/configured by bootrom */ |
| 101 | INFO("BL1: initializing emmc\n"); |
Haojian Zhuang | 3eff409 | 2018-08-04 18:07:26 +0800 | [diff] [blame] | 102 | info.mmc_dev_type = MMC_IS_EMMC; |
| 103 | dw_mmc_init(¶ms, &info); |
Victor Chong | f0c7c61 | 2018-01-16 00:29:47 +0900 | [diff] [blame] | 104 | #endif |
Victor Chong | 539408d | 2018-01-03 01:53:08 +0900 | [diff] [blame] | 105 | |
Jorge Ramirez-Ortiz | a29d9a6 | 2017-06-28 10:11:31 +0200 | [diff] [blame] | 106 | plat_io_setup(); |
| 107 | } |
| 108 | |
| 109 | unsigned int bl1_plat_get_next_image_id(void) |
| 110 | { |
| 111 | return BL2_IMAGE_ID; |
| 112 | } |