forked from linux4sam/at91bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
129 lines (108 loc) · 3.04 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
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2006, Atmel Corporation
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#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 "backup.h"
#include "secure.h"
#include "sfr_aicredir.h"
#ifdef CONFIG_HW_DISPLAY_BANNER
static void display_banner (void)
{
usart_puts(BANNER);
}
#endif
int main(void)
{
struct image_info image;
int ret;
#ifdef CONFIG_HW_INIT
hw_init();
#endif
#if defined(CONFIG_SCLK)
#if !defined(CONFIG_SCLK_BYPASS)
slowclk_enable_osc32();
#endif
#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;
}
#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
init_load_image(&image);
#if defined(CONFIG_SECURE)
image.dest -= sizeof(at91_secure_header_t);
#endif
ret = (*load_image)(&image);
#if defined(CONFIG_SECURE)
if (!ret)
ret = secure_check(image.dest);
image.dest += sizeof(at91_secure_header_t);
#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_ENTER_NWD)
switch_normal_world();
/* point never reached with TZ support */
#endif
return JUMP_ADDR;
}