a3b83694345f3f98540f8fa2ec67a315d1a1cfce
[pandora-x-loader.git] / lib / board.c
1 /*
2  * Copyright (C) 2005 Texas Instruments.
3  *
4  * (C) Copyright 2004
5  * Jian Zhang, Texas Instruments, jzhang@ti.com.
6  *
7  * (C) Copyright 2002
8  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
9  *
10  * (C) Copyright 2002
11  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
12  * Marius Groeger <mgroeger@sysgo.de>
13  *
14  * See file CREDITS for list of people who contributed to this
15  * project.
16  *
17  * This program is free software; you can redistribute it and/or
18  * modify it under the terms of the GNU General Public License as
19  * published by the Free Software Foundation; either version 2 of
20  * the License, or (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30  * MA 02111-1307 USA
31  */
32
33 #include <common.h>
34 #include <part.h>
35 #include <fat.h>
36 #include <asm/arch/mem.h>
37
38 const char version_string[] =
39         "Texas Instruments X-Loader 1.4.2 (" __DATE__ " - " __TIME__ ")";
40
41 #ifdef CFG_PRINTF
42 int print_info(void)
43 {
44         printf("\n\n%s\n", version_string);
45         return 0;
46 }
47 #endif
48
49 static int init_func_i2c (void)
50 {
51 #ifdef CONFIG_MMC
52         i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
53 #endif
54         return 0;
55 }
56
57 typedef int (init_fnc_t) (void);
58
59 init_fnc_t *init_sequence[] = {
60         cpu_init,               /* basic cpu dependent setup */
61         board_init,             /* basic board dependent setup */
62 #ifdef CFG_PRINTF
63         serial_init,            /* serial communications setup */
64         print_info,
65 #endif
66         nand_init,              /* board specific nand init */
67 #ifdef CONFIG_MMC
68         init_func_i2c,
69 #endif
70         NULL,
71 };
72
73 void start_armboot (void)
74 {
75         init_fnc_t **init_fnc_ptr;
76         int i, size;
77         uchar *buf;
78         block_dev_desc_t *dev_desc = NULL;
79
80         for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
81                 if ((*init_fnc_ptr)() != 0) {
82                         hang ();
83                 }
84         }
85
86         misc_init_r();
87
88         buf =  (uchar*) CFG_LOADADDR;
89
90 #ifdef CONFIG_MMC
91         /* first try mmc */
92         if (mmc_init(1)) {
93                 size = file_fat_read("u-boot.bin", buf, 0);
94                 if (size > 0) {
95 #ifdef CFG_PRINTF
96                         printf("Loading u-boot.bin from mmc\n");
97 #endif
98                         buf += size;
99                 }
100         }
101 #endif
102
103         if (buf == (uchar *)CFG_LOADADDR) {
104                 /* if no u-boot on mmc, try onenand or nand, depending upon sysboot */
105                 if (get_mem_type() == GPMC_ONENAND){
106 #ifdef CFG_PRINTF
107                         printf("Loading u-boot.bin from onenand\n");
108 #endif
109                         for (i = ONENAND_START_BLOCK; i < ONENAND_END_BLOCK; i++){
110                                 if (!onenand_read_block(buf, i))
111                                         buf += ONENAND_BLOCK_SIZE;
112                         }
113                 } else if (get_mem_type() == GPMC_NAND){
114 #ifdef CFG_PRINTF
115                         printf("Loading u-boot.bin from nand\n");
116 #endif
117                         for (i = NAND_UBOOT_START; i < NAND_UBOOT_END; i+= NAND_BLOCK_SIZE){
118                                 if (!nand_read_block(buf, i))
119                                         buf += NAND_BLOCK_SIZE; /* advance buf ptr */
120                         }
121                 }
122         }
123
124
125         if (buf == (uchar *)CFG_LOADADDR)
126                 hang();
127
128         /* go run U-Boot and never return */
129         ((init_fnc_t *)CFG_LOADADDR)();
130
131         /* should never come here */
132 }
133
134 void hang (void)
135 {
136         /* call board specific hang function */
137         board_hang();
138
139         /* if board_hang() returns, hange here */
140 #ifdef CFG_PRINTF
141         printf("X-Loader hangs\n");
142 #endif
143         for (;;);
144 }