Add Pandora support to the public X-Loader OMAP3 tree.
[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                         printf("\n%ld Bytes Read from MMC \n", size);
98 #endif
99                         buf += size;
100                 }
101         }
102 #endif
103
104         if (buf == (uchar *)CFG_LOADADDR) {
105                 /* if no u-boot on mmc, try onenand or nand, depending upon sysboot */
106                 if (get_mem_type() == GPMC_ONENAND){
107 #ifdef CFG_PRINTF
108                         printf("Loading u-boot.bin from onenand\n");
109 #endif
110                         for (i = ONENAND_START_BLOCK; i < ONENAND_END_BLOCK; i++){
111                                 if (!onenand_read_block(buf, i))
112                                         buf += ONENAND_BLOCK_SIZE;
113                         }
114                 } else if (get_mem_type() == GPMC_NAND){
115 #ifdef CFG_PRINTF
116                         printf("Loading u-boot.bin from NAND\n");
117 #endif
118                         for (i = NAND_UBOOT_START; i < NAND_UBOOT_END; i+= NAND_BLOCK_SIZE){
119                                 if (!nand_read_block(buf, i))
120                                         buf += NAND_BLOCK_SIZE; /* advance buf ptr */
121                         }
122                 }
123         }
124
125
126         if (buf == (uchar *)CFG_LOADADDR)
127                 hang();
128
129 #ifdef CFG_PRINTF
130         printf("Starting Stage 2 Bootloader...\n");
131 #endif
132
133         /* go run U-Boot and never return */
134         ((init_fnc_t *)CFG_LOADADDR)();
135
136         /* should never come here */
137 }
138
139 void hang (void)
140 {
141         /* call board specific hang function */
142         board_hang();
143
144         /* if board_hang() returns, hange here */
145 #ifdef CFG_PRINTF
146         printf("X-Loader hangs\n");
147 #endif
148         for (;;);
149 }