3 * Texas Instruments, <www.ti.com>
5 * Aneesh V <aneesh@ti.com>
7 * See file CREDITS for list of people who contributed to this
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 #include <asm/u-boot.h>
27 #include <asm/utils.h>
28 #include <asm/arch/sys_proto.h>
32 #include <timestamp_autogenerated.h>
33 #include <version_autogenerated.h>
34 #include <asm/omap_common.h>
35 #include <asm/arch/mmc_host_def.h>
39 DECLARE_GLOBAL_DATA_PTR;
41 /* Define global data structure pointer to it*/
42 static gd_t gdata __attribute__ ((section(".data")));
43 static bd_t bdata __attribute__ ((section(".data")));
44 static const char *image_name;
46 static u32 image_load_addr;
47 static u32 image_entry_point;
48 static u32 image_size;
50 inline void hang(void)
52 puts("### ERROR ### Please RESET the board ###\n");
57 void board_init_f(ulong dummy)
60 * We call relocate_code() with relocation target same as the
61 * CONFIG_SYS_SPL_TEXT_BASE. This will result in relocation getting
62 * skipped. Instead, only .bss initialization will happen. That's
65 debug(">>board_init_f()\n");
66 relocate_code(CONFIG_SPL_STACK, &gdata, CONFIG_SPL_TEXT_BASE);
69 #ifdef CONFIG_GENERIC_MMC
70 int board_mmc_init(bd_t *bis)
72 switch (omap_boot_device()) {
73 case BOOT_DEVICE_MMC1:
76 case BOOT_DEVICE_MMC2:
84 static void parse_image_header(const struct image_header *header)
86 u32 header_size = sizeof(struct image_header);
88 if (__be32_to_cpu(header->ih_magic) == IH_MAGIC) {
89 image_size = __be32_to_cpu(header->ih_size) + header_size;
90 image_entry_point = __be32_to_cpu(header->ih_load);
91 /* Load including the header */
92 image_load_addr = image_entry_point - header_size;
93 image_os = header->ih_os;
94 image_name = (const char *)&header->ih_name;
95 debug("spl: payload image: %s load addr: 0x%x size: %d\n",
96 image_name, image_load_addr, image_size);
98 /* Signature not found - assume u-boot.bin */
99 printf("mkimage signature not found - ih_magic = %x\n",
101 puts("Assuming u-boot.bin ..\n");
102 /* Let's assume U-Boot will not be more than 200 KB */
103 image_size = 200 * 1024;
104 image_entry_point = CONFIG_SYS_TEXT_BASE;
105 image_load_addr = CONFIG_SYS_TEXT_BASE;
106 image_os = IH_OS_U_BOOT;
107 image_name = "U-Boot";
111 static void mmc_load_image_raw(struct mmc *mmc)
113 u32 image_size_sectors, err;
114 const struct image_header *header;
116 header = (struct image_header *)(CONFIG_SYS_TEXT_BASE -
117 sizeof(struct image_header));
119 /* read image header to find the image size & load address */
120 err = mmc->block_dev.block_read(0,
121 CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR, 1,
127 parse_image_header(header);
129 /* convert size to sectors - round up */
130 image_size_sectors = (image_size + MMCSD_SECTOR_SIZE - 1) /
133 /* Read the header too to avoid extra memcpy */
134 err = mmc->block_dev.block_read(0,
135 CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR,
136 image_size_sectors, (void *)image_load_addr);
140 printf("spl: mmc blk read err - %d\n", err);
145 static void mmc_load_image_fat(struct mmc *mmc)
148 struct image_header *header;
150 header = (struct image_header *)(CONFIG_SYS_TEXT_BASE -
151 sizeof(struct image_header));
153 err = fat_register_device(&mmc->block_dev,
154 CONFIG_SYS_MMC_SD_FAT_BOOT_PARTITION);
156 printf("spl: fat register err - %d\n", err);
160 err = file_fat_read(CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME,
161 (u8 *)header, sizeof(struct image_header));
165 parse_image_header(header);
167 err = file_fat_read(CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME,
168 (u8 *)image_load_addr, 0);
172 printf("spl: error reading image %s, err - %d\n",
173 CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME, err);
177 static void mmc_load_image(void) __attribute__((unused));
178 static void mmc_load_image(void)
184 mmc_initialize(gd->bd);
185 /* We register only one device. So, the dev id is always 0 */
186 mmc = find_mmc_device(0);
188 puts("spl: mmc device not found!!\n");
194 printf("spl: mmc init failed: err - %d\n", err);
198 boot_mode = omap_boot_mode();
199 if (boot_mode == MMCSD_MODE_RAW) {
200 debug("boot mode - RAW\n");
201 mmc_load_image_raw(mmc);
202 } else if (boot_mode == MMCSD_MODE_FAT) {
203 debug("boot mode - FAT\n");
204 mmc_load_image_fat(mmc);
206 puts("spl: wrong MMC boot mode\n");
211 #ifdef CONFIG_SPL_NAND_SUPPORT
212 static void nand_load_image(void) __attribute__ ((unused));
213 static void nand_load_image(void)
215 struct image_header *header;
220 /*use CONFIG_SYS_TEXT_BASE as temporary storage area */
221 header = (struct image_header *)(CONFIG_SYS_TEXT_BASE);
223 #ifdef CONFIG_NAND_ENV_DST
224 nand_spl_load_image(CONFIG_ENV_OFFSET,
225 CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
226 parse_image_header(header);
227 nand_spl_load_image(CONFIG_ENV_OFFSET, image_size,
228 (void *)image_load_addr);
229 #ifdef CONFIG_ENV_OFFSET_REDUND
230 nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND,
231 CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
232 parse_image_header(header);
233 nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND, image_size,
234 (void *)image_load_addr);
238 nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
239 CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
240 parse_image_header(header);
241 nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
242 image_size, (void *)image_load_addr);
245 #endif /* CONFIG_SPL_NAND_SUPPORT */
246 void jump_to_image_no_args(void)
248 typedef void (*image_entry_noargs_t)(void)__attribute__ ((noreturn));
249 image_entry_noargs_t image_entry =
250 (image_entry_noargs_t) image_entry_point;
252 debug("image entry point: 0x%X\n", image_entry_point);
256 void jump_to_image_no_args(void) __attribute__ ((noreturn));
257 void board_init_r(gd_t *id, ulong dummy)
260 debug(">>spl:board_init_r()\n");
263 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
265 boot_device = omap_boot_device();
266 debug("boot device - %d\n", boot_device);
267 switch (boot_device) {
268 #ifdef CONFIG_SPL_MMC_SUPPORT
269 case BOOT_DEVICE_MMC1:
270 case BOOT_DEVICE_MMC2:
274 #ifdef CONFIG_SPL_NAND_SUPPORT
275 case BOOT_DEVICE_NAND:
280 printf("SPL: Un-supported Boot Device - %d!!!\n", boot_device);
287 debug("Jumping to U-Boot\n");
288 jump_to_image_no_args();
291 puts("Unsupported OS image.. Jumping nevertheless..\n");
292 jump_to_image_no_args();
296 /* This requires UART clocks to be enabled */
297 void preloader_console_init(void)
299 const char *u_boot_rev = U_BOOT_VERSION;
300 char rev_string_buffer[50];
304 gd->flags |= GD_FLG_RELOC;
305 gd->baudrate = CONFIG_BAUDRATE;
307 serial_init(); /* serial communications setup */
309 /* Avoid a second "U-Boot" coming from this string */
310 u_boot_rev = &u_boot_rev[7];
312 printf("\nU-Boot SPL %s (%s - %s)\n", u_boot_rev, U_BOOT_DATE,
314 omap_rev_string(rev_string_buffer);
315 printf("Texas Instruments %s\n", rev_string_buffer);