Initial checkin
[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 <asm/arch/mem.h>
35
36 #ifdef CFG_PRINTF
37 int print_info(void)
38 {
39         printf("\n\nTexas Instruments X-Loader 1.41\n");
40         return 0;
41 }
42 #endif
43
44 typedef int (init_fnc_t) (void);
45
46 init_fnc_t *init_sequence[] = {
47         cpu_init,               /* basic cpu dependent setup */
48         board_init,             /* basic board dependent setup */
49 #ifdef CFG_PRINTF
50         serial_init,            /* serial communications setup */
51         print_info,
52 #endif
53         nand_init,              /* board specific nand init */
54         NULL,
55 };
56
57 void start_armboot (void)
58 {
59         init_fnc_t **init_fnc_ptr;
60         int i;
61         uchar *buf;
62
63         for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
64                 if ((*init_fnc_ptr)() != 0) {
65                         hang ();
66                 }
67         }
68
69         buf =  (uchar*) CFG_LOADADDR;
70
71         if ((get_mem_type() == MMC_ONENAND) || (get_mem_type() == MMC_NAND)){
72                 buf += mmc_boot(buf);
73         }
74
75         if (get_mem_type() == GPMC_ONENAND){
76                 for (i = ONENAND_START_BLOCK; i < ONENAND_END_BLOCK; i++){
77                         if (!onenand_read_block(buf, i))
78                                 buf += ONENAND_BLOCK_SIZE;
79                 }
80         }
81
82         if (get_mem_type() == GPMC_NAND){
83                 for (i = NAND_UBOOT_START; i < NAND_UBOOT_END; i+= NAND_BLOCK_SIZE){
84                         if (!nand_read_block(buf, i))
85                                 buf += NAND_BLOCK_SIZE; /* advance buf ptr */
86                 }
87         }
88
89
90
91         if (buf == (uchar *)CFG_LOADADDR)
92                 hang();
93
94         /* go run U-Boot and never return */
95         printf("Starting OS Bootloader...\n");
96         ((init_fnc_t *)CFG_LOADADDR)();
97
98         /* should never come here */
99 }
100
101 void hang (void)
102 {
103         /* call board specific hang function */
104         board_hang();
105
106         /* if board_hang() returns, hange here */
107         printf("X-Loader hangs\n");
108         for (;;);
109 }