blob: 0ffa03ac01a8edc430b2f3b4c7e9178efedbdaf9 [file] [log] [blame]
Chandan Nath77a73fe2012-01-09 20:38:59 +00001/*
2 * boot-common.c
3 *
4 * Common bootmode functions for omap based boards
5 *
6 * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
7 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
Chandan Nath77a73fe2012-01-09 20:38:59 +00009 */
10
11#include <common.h>
Tom Rini28591df2012-08-13 12:03:19 -070012#include <spl.h>
Chandan Nath77a73fe2012-01-09 20:38:59 +000013#include <asm/omap_common.h>
14#include <asm/arch/omap.h>
Tom Rinia0b9fa52012-08-14 10:25:15 -070015#include <asm/arch/mmc_host_def.h>
Ilya Yanok741c57f2012-11-06 13:06:28 +000016#include <asm/arch/sys_proto.h>
Chandan Nath77a73fe2012-01-09 20:38:59 +000017
SRICHARAN R3f30b0a2013-04-24 00:41:24 +000018DECLARE_GLOBAL_DATA_PTR;
Chandan Nath77a73fe2012-01-09 20:38:59 +000019
Tom Rini51df26c2013-05-31 12:31:59 -040020void save_omap_boot_params(void)
21{
22 u32 rom_params = *((u32 *)OMAP_SRAM_SCRATCH_BOOT_PARAMS);
23 u8 boot_device;
24 u32 dev_desc, dev_data;
25
26 if ((rom_params < NON_SECURE_SRAM_START) ||
27 (rom_params > NON_SECURE_SRAM_END))
28 return;
29
30 /*
31 * rom_params can be type casted to omap_boot_parameters and
32 * used. But it not correct to assume that romcode structure
33 * encoding would be same as u-boot. So use the defined offsets.
34 */
35 gd->arch.omap_boot_params.omap_bootdevice = boot_device =
36 *((u8 *)(rom_params + BOOT_DEVICE_OFFSET));
37
38 gd->arch.omap_boot_params.ch_flags =
39 *((u8 *)(rom_params + CH_FLAGS_OFFSET));
40
41 if ((boot_device >= MMC_BOOT_DEVICES_START) &&
42 (boot_device <= MMC_BOOT_DEVICES_END)) {
Lokesh Vutla3d3ac352013-07-30 11:36:31 +053043#if !defined(CONFIG_AM33XX) && !defined(CONFIG_TI81XX) && \
44 !defined(CONFIG_AM43XX)
Tom Rini51df26c2013-05-31 12:31:59 -040045 if ((omap_hw_init_context() ==
46 OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL)) {
47 gd->arch.omap_boot_params.omap_bootmode =
48 *((u8 *)(rom_params + BOOT_MODE_OFFSET));
49 } else
50#endif
51 {
52 dev_desc = *((u32 *)(rom_params + DEV_DESC_PTR_OFFSET));
53 dev_data = *((u32 *)(dev_desc + DEV_DATA_PTR_OFFSET));
54 gd->arch.omap_boot_params.omap_bootmode =
55 *((u32 *)(dev_data + BOOT_MODE_OFFSET));
56 }
57 }
58}
59
Chandan Nath77a73fe2012-01-09 20:38:59 +000060#ifdef CONFIG_SPL_BUILD
Tom Rini0be93ff2012-08-13 12:53:23 -070061u32 spl_boot_device(void)
Chandan Nath77a73fe2012-01-09 20:38:59 +000062{
SRICHARAN R3f30b0a2013-04-24 00:41:24 +000063 return (u32) (gd->arch.omap_boot_params.omap_bootdevice);
Chandan Nath77a73fe2012-01-09 20:38:59 +000064}
65
Tom Rinia76ff952012-08-14 09:19:44 -070066u32 spl_boot_mode(void)
Chandan Nath77a73fe2012-01-09 20:38:59 +000067{
SRICHARAN R3f30b0a2013-04-24 00:41:24 +000068 return gd->arch.omap_boot_params.omap_bootmode;
Chandan Nath77a73fe2012-01-09 20:38:59 +000069}
Tom Rinia0b9fa52012-08-14 10:25:15 -070070
Tom Rini9e0c2602012-08-14 12:26:08 -070071void spl_board_init(void)
72{
73#ifdef CONFIG_SPL_NAND_SUPPORT
74 gpmc_init();
75#endif
Ilya Yanok87b82cc2013-02-05 11:36:25 +000076#if defined(CONFIG_AM33XX) && defined(CONFIG_SPL_MUSB_NEW_SUPPORT)
77 arch_misc_init();
78#endif
Tom Riniac8fdf92013-08-30 16:28:44 -040079#ifdef CONFIG_AM33XX
80 am33xx_spl_board_init();
81#endif
Tom Rini9e0c2602012-08-14 12:26:08 -070082}
83
Tom Rinia0b9fa52012-08-14 10:25:15 -070084int board_mmc_init(bd_t *bis)
85{
86 switch (spl_boot_device()) {
87 case BOOT_DEVICE_MMC1:
Nikita Kiryanov4be9dbc2012-12-03 02:19:47 +000088 omap_mmc_init(0, 0, 0, -1, -1);
Tom Rinia0b9fa52012-08-14 10:25:15 -070089 break;
90 case BOOT_DEVICE_MMC2:
91 case BOOT_DEVICE_MMC2_2:
Nikita Kiryanov4be9dbc2012-12-03 02:19:47 +000092 omap_mmc_init(1, 0, 0, -1, -1);
Tom Rinia0b9fa52012-08-14 10:25:15 -070093 break;
94 }
95 return 0;
96}
SRICHARAN R3f30b0a2013-04-24 00:41:24 +000097
98void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
99{
100 typedef void __noreturn (*image_entry_noargs_t)(u32 *);
101 image_entry_noargs_t image_entry =
102 (image_entry_noargs_t) spl_image->entry_point;
103
104 debug("image entry point: 0x%X\n", spl_image->entry_point);
105 /* Pass the saved boot_params from rom code */
106 image_entry((u32 *)&gd->arch.omap_boot_params);
107}
Chandan Nath77a73fe2012-01-09 20:38:59 +0000108#endif