-
Notifications
You must be signed in to change notification settings - Fork 232
/
main.c
161 lines (133 loc) · 2.69 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// Copyright (C) 2006 Microchip Technology Inc. and its subsidiaries
//
// SPDX-License-Identifier: MIT
#include "common.h"
#include "board.h"
#include "usart.h"
#include "slowclk.h"
#include "board_hw_info.h"
#include "tz_utils.h"
#include "pm.h"
#include "act8865.h"
#include "mcp16502.h"
#include "backup.h"
#include "secure.h"
#include "autoconf.h"
#include "optee.h"
#include "sfr_aicredir.h"
#ifdef CONFIG_CACHES
#include "l1cache.h"
#endif
#ifdef CONFIG_MMU
#include "mmu.h"
static unsigned int *tlb = (unsigned int *)MMU_TABLE_BASE_ADDR;
#endif
#ifdef CONFIG_HW_DISPLAY_BANNER
static void display_banner (void)
{
usart_puts(BANNER);
}
#endif
int main(void)
{
#ifdef CONFIG_LOAD_SW
struct image_info image;
#endif
int ret = 0;
hw_init();
#ifdef CONFIG_OCMS_STATIC
ocms_init_keys();
ocms_enable();
#endif
#if defined(CONFIG_SCLK)
#if !defined(CONFIG_SCLK_BYPASS)
slowclk_enable_osc32();
#endif
#elif defined(CONFIG_SCLK_INTRC)
slowclk_switch_rc32();
#endif
#ifdef CONFIG_BACKUP_MODE
ret = backup_mode_resume();
if (ret) {
/* Backup+Self-Refresh mode detected... */
#ifdef CONFIG_REDIRECT_ALL_INTS_AIC
redirect_interrupts_to_nsaic();
#endif
slowclk_switch_osc32();
/* ...jump to Linux here */
return ret;
}
usart_puts("Backup mode enabled\n");
#endif
#ifdef CONFIG_HW_DISPLAY_BANNER
display_banner();
#endif
#ifdef CONFIG_REDIRECT_ALL_INTS_AIC
redirect_interrupts_to_nsaic();
#endif
#ifdef CONFIG_LOAD_HW_INFO
load_board_hw_info();
#endif
#ifdef CONFIG_PM
at91_board_pm();
#endif
#ifdef CONFIG_ACT8865
act8865_workaround();
act8945a_suspend_charger();
#endif
#ifdef CONFIG_MCP16502_SET_VOLTAGE
mcp16502_voltage_select();
#endif
#if defined(CONFIG_SAMA7G5) || defined(CONFIG_SAMA7D65)
hw_postinit();
#endif
#ifdef CONFIG_LOAD_SW
init_load_image(&image);
#if defined(CONFIG_SECURE)
image.dest -= sizeof(at91_secure_header_t);
#endif
#ifdef CONFIG_MMU
mmu_tlb_init(tlb);
mmu_configure(tlb);
mmu_enable();
#endif
#ifdef CONFIG_CACHES
icache_enable();
dcache_enable();
#endif
ret = (*load_image)(&image);
#ifdef CONFIG_CACHES
icache_disable();
dcache_disable();
#endif
#ifdef CONFIG_MMU
mmu_disable();
#endif
#if defined(CONFIG_SECURE)
if (!ret)
ret = secure_check(image.dest);
image.dest += sizeof(at91_secure_header_t);
#endif
#endif
load_image_done(ret);
#ifdef CONFIG_SCLK
#ifdef CONFIG_SCLK_BYPASS
slowclk_switch_osc32_bypass();
#else
slowclk_switch_osc32();
#endif
#endif
#if defined(CONFIG_LOAD_OPTEE)
/* Will never return since we will jump to OP-TEE in secure mode */
optee_load();
#endif
#if defined(CONFIG_ENTER_NWD)
switch_normal_world();
/* point never reached with TZ support */
#endif
#ifdef CONFIG_JUMP_TO_SW
return JUMP_ADDR;
#else
return 0;
#endif
}