more verbose logging
[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 <i2c.h>
35 #include <part.h>
36 #include <fat.h>
37 #include <asm/arch/mem.h>
38
39 #define END_MARK 0x646e65ff     /* end */
40
41 const char version_string[] =
42         "Texas Instruments X-Loader 1.5.1 (" __DATE__ " - " __TIME__ ")";
43
44 int print_info(void)
45 {
46 #ifdef CFG_PRINTF
47         printf("\n\n%s\n", version_string);
48 #endif
49         return 0;
50 }
51
52 #ifdef CONFIG_DRIVER_OMAP34XX_I2C
53 static int init_func_i2c (void)
54 {
55         i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
56         return 0;
57 }
58 #endif
59
60 typedef int (init_fnc_t) (void);
61
62 init_fnc_t *init_sequence[] = {
63         cpu_init,               /* basic cpu dependent setup */
64 #ifdef CONFIG_DRIVER_OMAP34XX_I2C
65         init_func_i2c,
66 #endif
67         board_init,             /* basic board dependent setup */
68 #ifdef CFG_NS16550_SERIAL
69         serial_init,            /* serial communications setup */
70 #endif
71         print_info,
72         nand_init,              /* board specific nand init */
73         NULL,
74 };
75
76 void start_armboot (void)
77 {
78         init_fnc_t **init_fnc_ptr;
79         int size;
80         uchar *buf;
81         int *first_instruction;
82 #if defined(CFG_ONENAND) || defined(CFG_NAND_K9F1G08R0A)
83         int i;
84 #endif
85
86         for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr)
87                 if ((*init_fnc_ptr)())
88                         hang ();
89
90         misc_init_r();
91
92         buf =  (uchar*) CFG_LOADADDR;
93         *(int *)buf = 0xffffffff;
94
95 #ifdef CONFIG_MMC
96         /* first try mmc */
97         if (mmc_init(1)) {
98                 size = file_fat_read("u-boot.bin", buf, 0);
99                 if (size > 0) {
100 #ifdef CFG_PRINTF
101                         printf("Loading u-boot.bin from mmc\n");
102 #endif
103                         buf += size;
104                 }
105         }
106 #endif
107
108         if (buf == (uchar *)CFG_LOADADDR) {
109                 /* if no u-boot on mmc, try onenand or nand, depending upon sysboot */
110                 if (get_mem_type() == GPMC_ONENAND){
111 #ifdef CFG_ONENAND
112 #ifdef CFG_PRINTF
113                         printf("Loading u-boot.bin from onenand\n");
114 #endif
115                         for (i = ONENAND_START_BLOCK; i < ONENAND_END_BLOCK; i++){
116                                 if (!onenand_read_block(buf, i))
117                                         buf += ONENAND_BLOCK_SIZE;
118                         }
119 #endif
120                 } else if (get_mem_type() == GPMC_NAND){
121 #ifdef CFG_NAND_K9F1G08R0A
122 #ifdef CFG_PRINTF
123                         printf("Loading u-boot.bin from nand\n");
124 #endif
125                         for (i = NAND_UBOOT_START; i < NAND_UBOOT_END; i+= NAND_BLOCK_SIZE){
126                                 if (!nand_read_block(buf, i)){
127                                         buf += NAND_BLOCK_SIZE; /* advance buf ptr */
128                                         if (*(int *)(buf - 8) == END_MARK && *(int *)(buf - 4) == END_MARK)
129                                                 break;
130                                 }
131                         }
132 #endif
133                 }
134         }
135
136         /* if u-boot not found on mmc or
137          * nand read result is erased data
138          * then serial boot 
139          */
140         first_instruction = (int *)CFG_LOADADDR;
141         if((buf == (uchar *)CFG_LOADADDR) || (*first_instruction == 0xffffffff)) {
142                 printf("u-boot.bin not found or blank nand contents - attempting serial boot . . .\n");
143                 do_load_serial_bin(CFG_LOADADDR, 115200);
144         }
145
146         /* go run U-Boot and never return */
147         ((init_fnc_t *)CFG_LOADADDR)();
148
149         /* should never come here */
150 }
151
152 void hang (void)
153 {
154         /* call board specific hang function */
155         board_hang();
156
157         /* if board_hang() returns, hang here */
158 #ifdef CFG_PRINTF
159         printf("X-Loader hangs\n");
160 #endif
161         for (;;);
162 }