bl2_plat_setup.c 3.67 KB
Newer Older
1
2
3
4
5
6
7
/*
 * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <assert.h>
8
9
#include <string.h>

10
#include <platform_def.h>
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

#include <arch_helpers.h>
#include <common/bl_common.h>
#include <common/debug.h>
#include <common/desc_image_load.h>
#include <drivers/delay_timer.h>
#include <drivers/generic_delay_timer.h>
#include <drivers/st/stm32_console.h>
#include <drivers/st/stm32mp1_clk.h>
#include <drivers/st/stm32mp1_pmic.h>
#include <drivers/st/stm32mp1_pwr.h>
#include <drivers/st/stm32mp1_ram.h>
#include <drivers/st/stm32mp1_rcc.h>
#include <drivers/st/stm32mp1_reset.h>
#include <lib/mmio.h>
#include <lib/xlat_tables/xlat_tables_v2.h>
#include <plat/common/platform.h>

#include <boot_api.h>
Yann Gautier's avatar
Yann Gautier committed
30
#include <stm32mp1_context.h>
31
#include <stm32mp1_dt.h>
32
33
#include <stm32mp1_private.h>

Yann Gautier's avatar
Yann Gautier committed
34
35
static struct console_stm32 console;

36
37
38
39
40
41
42
43
void bl2_el3_early_platform_setup(u_register_t arg0, u_register_t arg1,
				  u_register_t arg2, u_register_t arg3)
{
	stm32mp1_save_boot_ctx_address(arg0);
}

void bl2_platform_setup(void)
{
44
45
	int ret;

Yann Gautier's avatar
Yann Gautier committed
46
47
48
49
	if (dt_check_pmic()) {
		initialize_pmic();
	}

50
51
52
53
54
55
	ret = stm32mp1_ddr_probe();
	if (ret < 0) {
		ERROR("Invalid DDR init: error %d\n", ret);
		panic();
	}

56
57
58
59
60
	INFO("BL2 runs SP_MIN setup\n");
}

void bl2_el3_plat_arch_setup(void)
{
Yann Gautier's avatar
Yann Gautier committed
61
62
63
	int32_t result;
	struct dt_node_info dt_dev_info;
	const char *board_model;
64
65
	boot_api_context_t *boot_context =
		(boot_api_context_t *)stm32mp1_get_boot_ctx_address();
Yann Gautier's avatar
Yann Gautier committed
66
	uint32_t clk_rate;
67

68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
	/*
	 * Disable the backup domain write protection.
	 * The protection is enable at each reset by hardware
	 * and must be disabled by software.
	 */
	mmio_setbits_32(PWR_BASE + PWR_CR1, PWR_CR1_DBP);

	while ((mmio_read_32(PWR_BASE + PWR_CR1) & PWR_CR1_DBP) == 0U) {
		;
	}

	/* Reset backup domain on cold boot cases */
	if ((mmio_read_32(RCC_BASE + RCC_BDCR) & RCC_BDCR_RTCSRC_MASK) == 0U) {
		mmio_setbits_32(RCC_BASE + RCC_BDCR, RCC_BDCR_VSWRST);

		while ((mmio_read_32(RCC_BASE + RCC_BDCR) & RCC_BDCR_VSWRST) ==
		       0U) {
			;
		}

		mmio_clrbits_32(RCC_BASE + RCC_BDCR, RCC_BDCR_VSWRST);
	}

	mmap_add_region(BL_CODE_BASE, BL_CODE_BASE,
			BL_CODE_END - BL_CODE_BASE,
			MT_CODE | MT_SECURE);

	/* Prevent corruption of preloaded BL32 */
	mmap_add_region(BL32_BASE, BL32_BASE,
			BL32_LIMIT - BL32_BASE,
			MT_MEMORY | MT_RO | MT_SECURE);

	/* Prevent corruption of preloaded Device Tree */
	mmap_add_region(DTB_BASE, DTB_BASE,
			DTB_LIMIT - DTB_BASE,
			MT_MEMORY | MT_RO | MT_SECURE);

	configure_mmu();

	generic_delay_timer_init();

109
110
111
112
113
114
115
116
117
118
119
120
	if (dt_open_and_check() < 0) {
		panic();
	}

	if (stm32mp1_clk_probe() < 0) {
		panic();
	}

	if (stm32mp1_clk_init() < 0) {
		panic();
	}

Yann Gautier's avatar
Yann Gautier committed
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
	result = dt_get_stdout_uart_info(&dt_dev_info);

	if ((result <= 0) ||
	    (dt_dev_info.status == 0U) ||
	    (dt_dev_info.clock < 0) ||
	    (dt_dev_info.reset < 0)) {
		goto skip_console_init;
	}

	if (dt_set_stdout_pinctrl() != 0) {
		goto skip_console_init;
	}

	if (stm32mp1_clk_enable((unsigned long)dt_dev_info.clock) != 0) {
		goto skip_console_init;
	}

	stm32mp1_reset_assert((uint32_t)dt_dev_info.reset);
	udelay(2);
	stm32mp1_reset_deassert((uint32_t)dt_dev_info.reset);
	mdelay(1);

	clk_rate = stm32mp1_clk_get_rate((unsigned long)dt_dev_info.clock);

Yann Gautier's avatar
Yann Gautier committed
145
146
	if (console_stm32_register(dt_dev_info.base, clk_rate,
				   STM32MP1_UART_BAUDRATE, &console) == 0) {
Yann Gautier's avatar
Yann Gautier committed
147
148
149
150
151
152
153
154
155
156
		panic();
	}

	board_model = dt_get_board_model();
	if (board_model != NULL) {
		NOTICE("%s\n", board_model);
	}

skip_console_init:

157
158
159
160
161
162
	if (stm32_save_boot_interface(boot_context->boot_interface_selected,
				      boot_context->boot_interface_instance) !=
	    0) {
		ERROR("Cannot save boot interface\n");
	}

163
164
	stm32mp1_arch_security_setup();

165
166
	stm32mp1_io_setup();
}