blob: 9f2d8bd0f2c65c1fe402283c0a7b090f3b9730a6 [file] [log] [blame]
Yann Gautier4b0c72a2018-07-16 10:54:09 +02001/*
2 * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
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 <boot_api.h>
11#include <console.h>
12#include <debug.h>
13#include <delay_timer.h>
14#include <desc_image_load.h>
15#include <generic_delay_timer.h>
16#include <mmio.h>
17#include <platform.h>
18#include <platform_def.h>
Yann Gautier9aea69e2018-07-24 17:13:36 +020019#include <stm32mp1_clk.h>
20#include <stm32mp1_dt.h>
Yann Gautierbb836ee2018-07-16 17:55:07 +020021#include <stm32mp1_pmic.h>
Yann Gautier4b0c72a2018-07-16 10:54:09 +020022#include <stm32mp1_private.h>
Yann Gautier41934662018-07-20 11:36:05 +020023#include <stm32mp1_context.h>
Yann Gautier4b0c72a2018-07-16 10:54:09 +020024#include <stm32mp1_pwr.h>
Yann Gautiercaf575b2018-07-24 17:18:19 +020025#include <stm32mp1_ram.h>
Yann Gautier4b0c72a2018-07-16 10:54:09 +020026#include <stm32mp1_rcc.h>
Yann Gautier69035a82018-07-05 16:48:16 +020027#include <stm32mp1_reset.h>
Yann Gautier4b0c72a2018-07-16 10:54:09 +020028#include <string.h>
29#include <xlat_tables_v2.h>
30
31void bl2_el3_early_platform_setup(u_register_t arg0, u_register_t arg1,
32 u_register_t arg2, u_register_t arg3)
33{
34 stm32mp1_save_boot_ctx_address(arg0);
35}
36
37void bl2_platform_setup(void)
38{
Yann Gautiercaf575b2018-07-24 17:18:19 +020039 int ret;
40
Yann Gautierbb836ee2018-07-16 17:55:07 +020041 if (dt_check_pmic()) {
42 initialize_pmic();
43 }
44
Yann Gautiercaf575b2018-07-24 17:18:19 +020045 ret = stm32mp1_ddr_probe();
46 if (ret < 0) {
47 ERROR("Invalid DDR init: error %d\n", ret);
48 panic();
49 }
50
Yann Gautier4b0c72a2018-07-16 10:54:09 +020051 INFO("BL2 runs SP_MIN setup\n");
52}
53
54void bl2_el3_plat_arch_setup(void)
55{
Yann Gautier69035a82018-07-05 16:48:16 +020056 int32_t result;
57 struct dt_node_info dt_dev_info;
58 const char *board_model;
Yann Gautier41934662018-07-20 11:36:05 +020059 boot_api_context_t *boot_context =
60 (boot_api_context_t *)stm32mp1_get_boot_ctx_address();
Yann Gautier69035a82018-07-05 16:48:16 +020061 uint32_t clk_rate;
Yann Gautier41934662018-07-20 11:36:05 +020062
Yann Gautier4b0c72a2018-07-16 10:54:09 +020063 /*
64 * Disable the backup domain write protection.
65 * The protection is enable at each reset by hardware
66 * and must be disabled by software.
67 */
68 mmio_setbits_32(PWR_BASE + PWR_CR1, PWR_CR1_DBP);
69
70 while ((mmio_read_32(PWR_BASE + PWR_CR1) & PWR_CR1_DBP) == 0U) {
71 ;
72 }
73
74 /* Reset backup domain on cold boot cases */
75 if ((mmio_read_32(RCC_BASE + RCC_BDCR) & RCC_BDCR_RTCSRC_MASK) == 0U) {
76 mmio_setbits_32(RCC_BASE + RCC_BDCR, RCC_BDCR_VSWRST);
77
78 while ((mmio_read_32(RCC_BASE + RCC_BDCR) & RCC_BDCR_VSWRST) ==
79 0U) {
80 ;
81 }
82
83 mmio_clrbits_32(RCC_BASE + RCC_BDCR, RCC_BDCR_VSWRST);
84 }
85
86 mmap_add_region(BL_CODE_BASE, BL_CODE_BASE,
87 BL_CODE_END - BL_CODE_BASE,
88 MT_CODE | MT_SECURE);
89
90 /* Prevent corruption of preloaded BL32 */
91 mmap_add_region(BL32_BASE, BL32_BASE,
92 BL32_LIMIT - BL32_BASE,
93 MT_MEMORY | MT_RO | MT_SECURE);
94
95 /* Prevent corruption of preloaded Device Tree */
96 mmap_add_region(DTB_BASE, DTB_BASE,
97 DTB_LIMIT - DTB_BASE,
98 MT_MEMORY | MT_RO | MT_SECURE);
99
100 configure_mmu();
101
102 generic_delay_timer_init();
103
Yann Gautier9aea69e2018-07-24 17:13:36 +0200104 if (dt_open_and_check() < 0) {
105 panic();
106 }
107
108 if (stm32mp1_clk_probe() < 0) {
109 panic();
110 }
111
112 if (stm32mp1_clk_init() < 0) {
113 panic();
114 }
115
Yann Gautier69035a82018-07-05 16:48:16 +0200116 result = dt_get_stdout_uart_info(&dt_dev_info);
117
118 if ((result <= 0) ||
119 (dt_dev_info.status == 0U) ||
120 (dt_dev_info.clock < 0) ||
121 (dt_dev_info.reset < 0)) {
122 goto skip_console_init;
123 }
124
125 if (dt_set_stdout_pinctrl() != 0) {
126 goto skip_console_init;
127 }
128
129 if (stm32mp1_clk_enable((unsigned long)dt_dev_info.clock) != 0) {
130 goto skip_console_init;
131 }
132
133 stm32mp1_reset_assert((uint32_t)dt_dev_info.reset);
134 udelay(2);
135 stm32mp1_reset_deassert((uint32_t)dt_dev_info.reset);
136 mdelay(1);
137
138 clk_rate = stm32mp1_clk_get_rate((unsigned long)dt_dev_info.clock);
139
140 if (console_init(dt_dev_info.base, clk_rate,
141 STM32MP1_UART_BAUDRATE) == 0) {
142 panic();
143 }
144
145 board_model = dt_get_board_model();
146 if (board_model != NULL) {
147 NOTICE("%s\n", board_model);
148 }
149
150skip_console_init:
151
Yann Gautier41934662018-07-20 11:36:05 +0200152 if (stm32_save_boot_interface(boot_context->boot_interface_selected,
153 boot_context->boot_interface_instance) !=
154 0) {
155 ERROR("Cannot save boot interface\n");
156 }
157
Yann Gautiercaf575b2018-07-24 17:18:19 +0200158 stm32mp1_arch_security_setup();
159
Yann Gautier4b0c72a2018-07-16 10:54:09 +0200160 stm32mp1_io_setup();
161}