-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.c
151 lines (123 loc) · 2.86 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
/*
* Copyright (C) 2016 Ingenic Semiconductor Co.,Ltd
*
* X1000 series bootloader for u-boot/rtos/linux
*
* Zhang YanMing <yanming.zhang@ingenic.com, jamincheung@126.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include <common.h>
#ifdef CONFIG_BOOT_MMC
uint32_t cpu_freq = CONFIG_CPU_SEL_PLL == APLL ? CONFIG_APLL_FREQ : CONFIG_MPLL_FREQ;
#elif (defined CONFIG_BOOT_USB)
/*
* Bootrom set apll freq for usb boot
*/
#if (CONFIG_EXTAL_FREQ == 24)
uint32_t cpu_freq = 576;
#elif (CONFIG_EXTAL_FREQ == 26)
uint32_t cpu_freq = 624;
#endif
#else
uint32_t cpu_freq = CONFIG_EXTAL_FREQ;
#endif
__attribute__((weak, alias("board_init"))) void board_init(void) {}
__attribute__((weak, alias("board_early_init"))) void board_early_init(void) {}
void x_loader_main(void) {
#ifdef CONFIG_SOFT_BURN
jump_to_usbboot();
#endif
/*
* Open CPU AHB0 APB RTC TCU EFUSE NEMC clock gate
*/
cpm_outl(0x87fbfffc, CPM_CLKGR);
/*
* Don't ask, it's magic...
*/
cpm_outl(0, CPM_PSWC0ST);
cpm_outl(16, CPM_PSWC1ST);
cpm_outl(24, CPM_PSWC2ST);
cpm_outl(8, CPM_PSWC3ST);
/*
* Init board early
*/
board_early_init();
/*
* Init uart
*/
uart_init();
/*
* check SOC id
*/
#ifdef CONFIG_CHECK_SOC_ID
check_socid();
#endif
uart_puts("\n\nX-Loader Build: " X_LOADER_DATE " - " X_LOADER_TIME);
/*
* Print error pc register
*/
uint32_t errorpc;
__asm__ __volatile__ (
"mfc0 %0, $30, 0\n\t"
"nop \n\t"
:"=r"(errorpc)
:);
printf("\nreset errorpc: 0x%x\n", errorpc);
/*
* Init clock
*/
clk_init();
#ifdef CONFIG_WDT
/*
* Init wdt
*/
wdt_init();
#endif
/*
* Init lpddr
*/
lpddr_init();
#ifdef CONFIG_DDR_ACCESS_TEST
/*
* DDR R/W test
*/
ddr_access_test();
hang_reason("Memory test done.\n");
#endif
#ifdef CONFIG_RTCCLK_SRC_EXT
/*
* RTC clock source change to external main crystal
*/
rtc_clk_src_to_ext();
#endif
/*
* Init board
*/
board_init();
#ifndef CONFIG_BOOT_USB
uart_puts("Going to boot next stage.\n");
/*
* Boot next stage(kernel/u-boot/rtos)
*/
boot_next_stage();
#else /* CONFIG_BOOT_USB */
#ifdef CONFIG_PM_SUSPEND
suspend_enter(CONFIG_PM_SUSPEND_STATE);
#endif
pass_params_to_uboot();
uart_puts("Going to start burner.\n");
/*
* Return to rom
*/
return;
#endif
}