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);
197 /* For OMAP3 there is no automatic boot mode detection */
198 #ifdef CONFIG_OMAP34XX
199 boot_mode = CONFIG_SYS_MMC_SD_BOOTMODE;
201 boot_mode = omap_boot_mode();
203 if (boot_mode == MMCSD_MODE_RAW) {
204 debug("boot mode - RAW\n");
205 mmc_load_image_raw(mmc);
206 } else if (boot_mode == MMCSD_MODE_FAT) {
207 debug("boot mode - FAT\n");
208 mmc_load_image_fat(mmc);
210 puts("spl: wrong MMC boot mode\n");
215 #ifdef CONFIG_SPL_NAND_SUPPORT
216 static void nand_load_image(void) __attribute__ ((unused));
217 static void nand_load_image(void)
219 struct image_header *header;
224 /*use CONFIG_SYS_TEXT_BASE as temporary storage area */
225 header = (struct image_header *)(CONFIG_SYS_TEXT_BASE);
227 #ifdef CONFIG_NAND_ENV_DST
228 nand_spl_load_image(CONFIG_ENV_OFFSET,
229 CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
230 parse_image_header(header);
231 nand_spl_load_image(CONFIG_ENV_OFFSET, image_size,
232 (void *)image_load_addr);
233 #ifdef CONFIG_ENV_OFFSET_REDUND
234 nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND,
235 CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
236 parse_image_header(header);
237 nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND, image_size,
238 (void *)image_load_addr);
242 nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
243 CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
244 parse_image_header(header);
245 nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
246 image_size, (void *)image_load_addr);
249 #endif /* CONFIG_SPL_NAND_SUPPORT */
250 void jump_to_image_no_args(void)
252 typedef void (*image_entry_noargs_t)(void)__attribute__ ((noreturn));
253 image_entry_noargs_t image_entry =
254 (image_entry_noargs_t) image_entry_point;
256 debug("image entry point: 0x%X\n", image_entry_point);
260 void jump_to_image_no_args(void) __attribute__ ((noreturn));
261 void board_init_r(gd_t *id, ulong dummy)
264 debug(">>spl:board_init_r()\n");
267 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
269 boot_device = omap_boot_device();
270 debug("boot device - %d\n", boot_device);
271 switch (boot_device) {
272 #ifdef CONFIG_SPL_MMC_SUPPORT
273 case BOOT_DEVICE_MMC1:
274 case BOOT_DEVICE_MMC2:
278 #ifdef CONFIG_SPL_NAND_SUPPORT
279 case BOOT_DEVICE_NAND:
284 printf("SPL: Un-supported Boot Device - %d!!!\n", boot_device);
291 debug("Jumping to U-Boot\n");
292 jump_to_image_no_args();
295 puts("Unsupported OS image.. Jumping nevertheless..\n");
296 jump_to_image_no_args();
300 /* This requires UART clocks to be enabled */
301 void preloader_console_init(void)
303 const char *u_boot_rev = U_BOOT_VERSION;
304 char rev_string_buffer[50];
308 gd->flags |= GD_FLG_RELOC;
309 gd->baudrate = CONFIG_BAUDRATE;
311 serial_init(); /* serial communications setup */
313 /* Avoid a second "U-Boot" coming from this string */
314 u_boot_rev = &u_boot_rev[7];
316 printf("\nU-Boot SPL %s (%s - %s)\n", u_boot_rev, U_BOOT_DATE,
318 omap_rev_string(rev_string_buffer);
319 printf("Texas Instruments %s\n", rev_string_buffer);