forked from linux4sam/at91bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
163 lines (140 loc) · 4.02 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
162
163
/* ----------------------------------------------------------------------------
* 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 "hardware.h"
#include "board.h"
#include "dbgu.h"
#include "debug.h"
#include "slowclk.h"
#include "dataflash.h"
#include "nandflash.h"
#include "sdcard.h"
#include "flash.h"
#include "string.h"
#include "onewire_info.h"
extern int load_kernel(struct image_info *img_info);
typedef int (*load_function)(struct image_info *img_info);
static load_function load_image;
void (*sdcard_set_of_name)(char *) = NULL;
static int init_loadfunction(void)
{
#if defined(CONFIG_LOAD_LINUX) || defined(CONFIG_LOAD_ANDROID)
load_image = &load_kernel;
#else
#if defined (CONFIG_DATAFLASH)
load_image = &load_dataflash;
#elif defined(CONFIG_NANDFLASH)
load_image = &load_nandflash;
#elif defined(CONFIG_SDCARD)
load_image = &load_sdcard;
#else
#error "No booting media_str specified!"
#endif
#endif
return 0;
}
static void display_banner (void)
{
char *version = "AT91Bootstrap";
char *ver_num = " "AT91BOOTSTRAP_VERSION" ("COMPILE_TIME")";
dbgu_print("\n\r");
dbgu_print("\n\r");
dbgu_print(version);
dbgu_print(ver_num);
dbgu_print("\n\r");
dbgu_print("\n\r");
}
int main(void)
{
struct image_info image;
char *media_str = NULL;
int ret;
char filename[FILENAME_BUF_LEN];
char of_filename[FILENAME_BUF_LEN];
memset(&image, 0, sizeof(image));
memset(filename, 0, FILENAME_BUF_LEN);
memset(of_filename, 0, FILENAME_BUF_LEN);
image.dest = (unsigned char *)JUMP_ADDR;
#ifdef CONFIG_OF_LIBFDT
image.of = 1;
image.of_dest = (unsigned char *)OF_ADDRESS;
#endif
#ifdef CONFIG_NANDFLASH
media_str = "NAND: ";
image.offset = IMG_ADDRESS;
image.length = IMG_SIZE;
#ifdef CONFIG_OF_LIBFDT
image.of_offset = OF_OFFSET;
image.of_length = OF_LENGTH;
#endif
#endif
#ifdef CONFIG_DATAFLASH
media_str = "SF: ";
image.offset = IMG_ADDRESS;
image.length = IMG_SIZE;
#ifdef CONFIG_OF_LIBFDT
image.of_offset = OF_OFFSET;
image.of_length = OF_LENGTH;
#endif
#endif
#ifdef CONFIG_SDCARD
media_str = "SD/MMC: ";
image.filename = filename;
strcpy(image.filename, OS_IMAGE_NAME);
#ifdef CONFIG_OF_LIBFDT
image.of_filename = of_filename;
strcpy(image.of_filename, OF_FILENAME);
#endif
#endif
#ifdef CONFIG_HW_INIT
hw_init();
#endif
display_banner();
#ifdef CONFIG_LOAD_ONE_WIRE
/* Load one wire informaion */
load_1wire_info();
#endif
init_loadfunction();
ret = (*load_image)(&image);
if (media_str)
dbgu_print(media_str);
if (ret == 0){
dbgu_print("Done to load image\n\r");
}
if (ret == -1) {
dbgu_print("Failed to load image\n\r");
while(1);
}
if (ret == -2) {
dbgu_print("Success to recovery\n\r");
while (1);
}
#ifdef CONFIG_SCLK
slowclk_switch_osc32();
#endif
return JUMP_ADDR;
}