]>
Commit | Line | Data |
---|---|---|
9ea5c6ef SS |
1 | /* |
2 | * (C) Copyright 2010 | |
3 | * Texas Instruments, <www.ti.com> | |
4 | * | |
5 | * Aneesh V <aneesh@ti.com> | |
6 | * | |
7 | * See file CREDITS for list of people who contributed to this | |
8 | * project. | |
9 | * | |
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. | |
14 | * | |
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. | |
19 | * | |
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, | |
23 | * MA 02111-1307 USA | |
24 | */ | |
25 | #include <common.h> | |
26 | #include <asm/u-boot.h> | |
27 | #include <asm/utils.h> | |
28 | #include <asm/arch/sys_proto.h> | |
29 | #include <mmc.h> | |
30 | #include <fat.h> | |
efb2172e | 31 | #include <version.h> |
9ea5c6ef SS |
32 | #include <asm/omap_common.h> |
33 | #include <asm/arch/mmc_host_def.h> | |
34 | ||
35 | DECLARE_GLOBAL_DATA_PTR; | |
36 | ||
37 | #ifdef CONFIG_GENERIC_MMC | |
38 | int board_mmc_init(bd_t *bis) | |
39 | { | |
8e1b836e | 40 | switch (spl_boot_device()) { |
9ea5c6ef | 41 | case BOOT_DEVICE_MMC1: |
bbbc1ae9 | 42 | omap_mmc_init(0, 0, 0); |
9ea5c6ef SS |
43 | break; |
44 | case BOOT_DEVICE_MMC2: | |
f75231b7 | 45 | case BOOT_DEVICE_MMC2_2: |
bbbc1ae9 | 46 | omap_mmc_init(1, 0, 0); |
9ea5c6ef SS |
47 | break; |
48 | } | |
49 | return 0; | |
50 | } | |
51 | #endif | |
52 | ||
53 | static void mmc_load_image_raw(struct mmc *mmc) | |
54 | { | |
55 | u32 image_size_sectors, err; | |
56 | const struct image_header *header; | |
57 | ||
58 | header = (struct image_header *)(CONFIG_SYS_TEXT_BASE - | |
59 | sizeof(struct image_header)); | |
60 | ||
61 | /* read image header to find the image size & load address */ | |
62 | err = mmc->block_dev.block_read(0, | |
63 | CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR, 1, | |
64 | (void *)header); | |
65 | ||
66 | if (err <= 0) | |
67 | goto end; | |
68 | ||
69 | spl_parse_image_header(header); | |
70 | ||
71 | /* convert size to sectors - round up */ | |
72 | image_size_sectors = (spl_image.size + MMCSD_SECTOR_SIZE - 1) / | |
73 | MMCSD_SECTOR_SIZE; | |
74 | ||
75 | /* Read the header too to avoid extra memcpy */ | |
76 | err = mmc->block_dev.block_read(0, | |
77 | CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR, | |
78 | image_size_sectors, (void *)spl_image.load_addr); | |
79 | ||
80 | end: | |
81 | if (err <= 0) { | |
82 | printf("spl: mmc blk read err - %d\n", err); | |
83 | hang(); | |
84 | } | |
85 | } | |
86 | ||
0da113e9 | 87 | #ifdef CONFIG_SPL_FAT_SUPPORT |
9ea5c6ef SS |
88 | static void mmc_load_image_fat(struct mmc *mmc) |
89 | { | |
90 | s32 err; | |
91 | struct image_header *header; | |
92 | ||
93 | header = (struct image_header *)(CONFIG_SYS_TEXT_BASE - | |
94 | sizeof(struct image_header)); | |
95 | ||
96 | err = fat_register_device(&mmc->block_dev, | |
97 | CONFIG_SYS_MMC_SD_FAT_BOOT_PARTITION); | |
98 | if (err) { | |
99 | printf("spl: fat register err - %d\n", err); | |
100 | hang(); | |
101 | } | |
102 | ||
103 | err = file_fat_read(CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME, | |
104 | (u8 *)header, sizeof(struct image_header)); | |
105 | if (err <= 0) | |
106 | goto end; | |
107 | ||
108 | spl_parse_image_header(header); | |
109 | ||
110 | err = file_fat_read(CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME, | |
111 | (u8 *)spl_image.load_addr, 0); | |
112 | ||
113 | end: | |
114 | if (err <= 0) { | |
115 | printf("spl: error reading image %s, err - %d\n", | |
116 | CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME, err); | |
117 | hang(); | |
118 | } | |
119 | } | |
0da113e9 | 120 | #endif |
9ea5c6ef SS |
121 | |
122 | void spl_mmc_load_image(void) | |
123 | { | |
124 | struct mmc *mmc; | |
125 | int err; | |
126 | u32 boot_mode; | |
127 | ||
128 | mmc_initialize(gd->bd); | |
129 | /* We register only one device. So, the dev id is always 0 */ | |
130 | mmc = find_mmc_device(0); | |
131 | if (!mmc) { | |
132 | puts("spl: mmc device not found!!\n"); | |
133 | hang(); | |
134 | } | |
135 | ||
136 | err = mmc_init(mmc); | |
137 | if (err) { | |
138 | printf("spl: mmc init failed: err - %d\n", err); | |
139 | hang(); | |
140 | } | |
37189a19 | 141 | boot_mode = spl_boot_mode(); |
9ea5c6ef SS |
142 | if (boot_mode == MMCSD_MODE_RAW) { |
143 | debug("boot mode - RAW\n"); | |
144 | mmc_load_image_raw(mmc); | |
0da113e9 | 145 | #ifdef CONFIG_SPL_FAT_SUPPORT |
9ea5c6ef SS |
146 | } else if (boot_mode == MMCSD_MODE_FAT) { |
147 | debug("boot mode - FAT\n"); | |
148 | mmc_load_image_fat(mmc); | |
0da113e9 | 149 | #endif |
9ea5c6ef SS |
150 | } else { |
151 | puts("spl: wrong MMC boot mode\n"); | |
152 | hang(); | |
153 | } | |
154 | } |