Commit c630e0ad3bc87f962ba7ce6038a78d99b9d1ff5c
1 parent
cd11afb01f
Exists in
smarc-imx_v2018.03_4.14.78_1.0.0_ga
MA-13588 Fix build warning caused by previous android SPL+CONTAINER patch
compile waring info is as below: arch/arm/mach-imx/imx8/parser.c: In function ‘mmc_load_image_parse_container’: arch/arm/mach-imx/imx8/parser.c:244:1: warning: control reaches end of non-void function [-Wreturn-type] } ^ previouse patch change ID: I40a791d5b5b1eba6a0170d6853626fb546be4b2c Change-Id: Ia605df11beab42e720fff6442a11b1e4b25ac209 Signed-off-by: faqiang.zhu <faqiang.zhu@nxp.com>
Showing 2 changed files with 7 additions and 7 deletions Inline Diff
arch/arm/mach-imx/imx8/parser.c
1 | // SPDX-License-Identifier: GPL-2.0+ | 1 | // SPDX-License-Identifier: GPL-2.0+ |
2 | /* | 2 | /* |
3 | * Copyright 2018 NXP | 3 | * Copyright 2018 NXP |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #include <common.h> | 6 | #include <common.h> |
7 | #include <spl.h> | 7 | #include <spl.h> |
8 | #include <errno.h> | 8 | #include <errno.h> |
9 | #include <asm/io.h> | 9 | #include <asm/io.h> |
10 | #include <dm.h> | 10 | #include <dm.h> |
11 | #include <mmc.h> | 11 | #include <mmc.h> |
12 | #include <spi_flash.h> | 12 | #include <spi_flash.h> |
13 | #include <asm/arch/image.h> | 13 | #include <asm/arch/image.h> |
14 | #include <asm/arch/sys_proto.h> | 14 | #include <asm/arch/sys_proto.h> |
15 | #include <asm/mach-imx/sci/sci.h> | 15 | #include <asm/mach-imx/sci/sci.h> |
16 | #include <asm/mach-imx/boot_mode.h> | 16 | #include <asm/mach-imx/boot_mode.h> |
17 | 17 | ||
18 | #define MMC_DEV 0 | 18 | #define MMC_DEV 0 |
19 | #define QSPI_DEV 1 | 19 | #define QSPI_DEV 1 |
20 | 20 | ||
21 | #define SEC_SECURE_RAM_BASE (0x31800000UL) | 21 | #define SEC_SECURE_RAM_BASE (0x31800000UL) |
22 | #define SEC_SECURE_RAM_END_BASE (SEC_SECURE_RAM_BASE + 0xFFFFUL) | 22 | #define SEC_SECURE_RAM_END_BASE (SEC_SECURE_RAM_BASE + 0xFFFFUL) |
23 | #define SECO_LOCAL_SEC_SEC_SECURE_RAM_BASE (0x60000000UL) | 23 | #define SECO_LOCAL_SEC_SEC_SECURE_RAM_BASE (0x60000000UL) |
24 | 24 | ||
25 | #define SECO_PT 2U | 25 | #define SECO_PT 2U |
26 | 26 | ||
27 | DECLARE_GLOBAL_DATA_PTR; | 27 | DECLARE_GLOBAL_DATA_PTR; |
28 | 28 | ||
29 | #if defined(CONFIG_IMX_TRUSTY_OS) | 29 | #if defined(CONFIG_IMX_TRUSTY_OS) |
30 | /* Pre-declaration of check_rpmb_blob. */ | 30 | /* Pre-declaration of check_rpmb_blob. */ |
31 | int check_rpmb_blob(struct mmc *mmc); | 31 | int check_rpmb_blob(struct mmc *mmc); |
32 | #endif | 32 | #endif |
33 | 33 | ||
34 | static int current_dev_type = MMC_DEV; | 34 | static int current_dev_type = MMC_DEV; |
35 | static int start_offset; | 35 | static int start_offset; |
36 | static void *device; | 36 | static void *device; |
37 | 37 | ||
38 | static int read(int start, int len, void *load_addr) | 38 | static int read(int start, int len, void *load_addr) |
39 | { | 39 | { |
40 | int ret = -ENODEV; | 40 | int ret = -ENODEV; |
41 | 41 | ||
42 | if (!device) { | 42 | if (!device) { |
43 | debug("No device selected\n"); | 43 | debug("No device selected\n"); |
44 | return ret; | 44 | return ret; |
45 | } | 45 | } |
46 | 46 | ||
47 | #ifdef CONFIG_SPL_MMC_SUPPORT | 47 | #ifdef CONFIG_SPL_MMC_SUPPORT |
48 | if (current_dev_type == MMC_DEV) { | 48 | if (current_dev_type == MMC_DEV) { |
49 | struct mmc *mmc = (struct mmc *)device; | 49 | struct mmc *mmc = (struct mmc *)device; |
50 | unsigned long count; | 50 | unsigned long count; |
51 | 51 | ||
52 | ret = 0; | 52 | ret = 0; |
53 | 53 | ||
54 | count = blk_dread(mmc_get_blk_desc(mmc), | 54 | count = blk_dread(mmc_get_blk_desc(mmc), |
55 | start / mmc->read_bl_len, | 55 | start / mmc->read_bl_len, |
56 | len / mmc->read_bl_len, | 56 | len / mmc->read_bl_len, |
57 | load_addr); | 57 | load_addr); |
58 | if (count == 0) { | 58 | if (count == 0) { |
59 | debug("Read container image failed\n"); | 59 | debug("Read container image failed\n"); |
60 | return -EIO; | 60 | return -EIO; |
61 | } | 61 | } |
62 | } | 62 | } |
63 | #endif | 63 | #endif |
64 | #ifdef CONFIG_SPL_SPI_LOAD | 64 | #ifdef CONFIG_SPL_SPI_LOAD |
65 | if (current_dev_type == QSPI_DEV) { | 65 | if (current_dev_type == QSPI_DEV) { |
66 | struct spi_flash *flash = (struct spi_flash *)device; | 66 | struct spi_flash *flash = (struct spi_flash *)device; |
67 | 67 | ||
68 | ret = spi_flash_read(flash, start, | 68 | ret = spi_flash_read(flash, start, |
69 | len, load_addr); | 69 | len, load_addr); |
70 | if (ret != 0) { | 70 | if (ret != 0) { |
71 | debug("Read container image from QSPI failed\n"); | 71 | debug("Read container image from QSPI failed\n"); |
72 | return -EIO; | 72 | return -EIO; |
73 | } | 73 | } |
74 | } | 74 | } |
75 | #endif | 75 | #endif |
76 | 76 | ||
77 | return ret; | 77 | return ret; |
78 | } | 78 | } |
79 | 79 | ||
80 | static int authenticate_image(struct boot_img_t *img, int image_index) | 80 | static int authenticate_image(struct boot_img_t *img, int image_index) |
81 | { | 81 | { |
82 | sc_ipc_t ipcHndl = gd->arch.ipc_channel_handle; | 82 | sc_ipc_t ipcHndl = gd->arch.ipc_channel_handle; |
83 | sc_faddr_t start, end; | 83 | sc_faddr_t start, end; |
84 | sc_rm_mr_t mr; | 84 | sc_rm_mr_t mr; |
85 | sc_err_t err; | 85 | sc_err_t err; |
86 | int ret = 0; | 86 | int ret = 0; |
87 | 87 | ||
88 | debug("img %d, dst 0x%llx, src 0x%x, size 0x%x\n", | 88 | debug("img %d, dst 0x%llx, src 0x%x, size 0x%x\n", |
89 | image_index, img->dst, img->offset, img->size); | 89 | image_index, img->dst, img->offset, img->size); |
90 | 90 | ||
91 | /* Find the memreg and set permission for seco pt */ | 91 | /* Find the memreg and set permission for seco pt */ |
92 | err = sc_rm_find_memreg(ipcHndl, &mr, | 92 | err = sc_rm_find_memreg(ipcHndl, &mr, |
93 | img->dst & ~(CONFIG_SYS_CACHELINE_SIZE - 1), | 93 | img->dst & ~(CONFIG_SYS_CACHELINE_SIZE - 1), |
94 | ALIGN(img->dst + img->size, CONFIG_SYS_CACHELINE_SIZE)); | 94 | ALIGN(img->dst + img->size, CONFIG_SYS_CACHELINE_SIZE)); |
95 | 95 | ||
96 | if (err) { | 96 | if (err) { |
97 | printf("can't find memreg for image load address %d, error %d\n", | 97 | printf("can't find memreg for image load address %d, error %d\n", |
98 | image_index, err); | 98 | image_index, err); |
99 | return -ENOMEM; | 99 | return -ENOMEM; |
100 | } | 100 | } |
101 | 101 | ||
102 | err = sc_rm_get_memreg_info(ipcHndl, mr, &start, &end); | 102 | err = sc_rm_get_memreg_info(ipcHndl, mr, &start, &end); |
103 | if (!err) | 103 | if (!err) |
104 | debug("memreg %u 0x%llx -- 0x%llx\n", mr, start, end); | 104 | debug("memreg %u 0x%llx -- 0x%llx\n", mr, start, end); |
105 | 105 | ||
106 | err = sc_rm_set_memreg_permissions(ipcHndl, mr, | 106 | err = sc_rm_set_memreg_permissions(ipcHndl, mr, |
107 | SECO_PT, SC_RM_PERM_FULL); | 107 | SECO_PT, SC_RM_PERM_FULL); |
108 | if (err) { | 108 | if (err) { |
109 | printf("set permission failed for img %d, error %d\n", | 109 | printf("set permission failed for img %d, error %d\n", |
110 | image_index, err); | 110 | image_index, err); |
111 | return -EPERM; | 111 | return -EPERM; |
112 | } | 112 | } |
113 | 113 | ||
114 | err = sc_misc_seco_authenticate(ipcHndl, SC_MISC_VERIFY_IMAGE, | 114 | err = sc_misc_seco_authenticate(ipcHndl, SC_MISC_VERIFY_IMAGE, |
115 | 1 << image_index); | 115 | 1 << image_index); |
116 | if (err) { | 116 | if (err) { |
117 | printf("authenticate img %d failed, return %d\n", | 117 | printf("authenticate img %d failed, return %d\n", |
118 | image_index, err); | 118 | image_index, err); |
119 | ret = -EIO; | 119 | ret = -EIO; |
120 | } | 120 | } |
121 | 121 | ||
122 | err = sc_rm_set_memreg_permissions(ipcHndl, mr, | 122 | err = sc_rm_set_memreg_permissions(ipcHndl, mr, |
123 | SECO_PT, SC_RM_PERM_NONE); | 123 | SECO_PT, SC_RM_PERM_NONE); |
124 | if (err) { | 124 | if (err) { |
125 | printf("remove permission failed for img %d, error %d\n", | 125 | printf("remove permission failed for img %d, error %d\n", |
126 | image_index, err); | 126 | image_index, err); |
127 | ret = -EPERM; | 127 | ret = -EPERM; |
128 | } | 128 | } |
129 | 129 | ||
130 | return ret; | 130 | return ret; |
131 | } | 131 | } |
132 | 132 | ||
133 | static struct boot_img_t *read_auth_image(struct container_hdr *container, | 133 | static struct boot_img_t *read_auth_image(struct container_hdr *container, |
134 | int image_index) | 134 | int image_index) |
135 | { | 135 | { |
136 | struct boot_img_t *images; | 136 | struct boot_img_t *images; |
137 | 137 | ||
138 | if (image_index > container->num_images) { | 138 | if (image_index > container->num_images) { |
139 | debug("Invalid image number\n"); | 139 | debug("Invalid image number\n"); |
140 | return NULL; | 140 | return NULL; |
141 | } | 141 | } |
142 | 142 | ||
143 | images = (struct boot_img_t *) | 143 | images = (struct boot_img_t *) |
144 | ((uint8_t *)container + sizeof(struct container_hdr)); | 144 | ((uint8_t *)container + sizeof(struct container_hdr)); |
145 | 145 | ||
146 | if (read(images[image_index].offset + start_offset, | 146 | if (read(images[image_index].offset + start_offset, |
147 | images[image_index].size, | 147 | images[image_index].size, |
148 | (void *)images[image_index].entry) < 0) { | 148 | (void *)images[image_index].entry) < 0) { |
149 | return NULL; | 149 | return NULL; |
150 | } | 150 | } |
151 | 151 | ||
152 | if (authenticate_image(&images[image_index], image_index)) { | 152 | if (authenticate_image(&images[image_index], image_index)) { |
153 | printf("Failed to authenticate image %d\n", image_index); | 153 | printf("Failed to authenticate image %d\n", image_index); |
154 | return NULL; | 154 | return NULL; |
155 | } | 155 | } |
156 | 156 | ||
157 | return &images[image_index]; | 157 | return &images[image_index]; |
158 | } | 158 | } |
159 | 159 | ||
160 | static int read_auth_container(struct spl_image_info *spl_image) | 160 | static int read_auth_container(struct spl_image_info *spl_image) |
161 | { | 161 | { |
162 | sc_ipc_t ipcHndl = gd->arch.ipc_channel_handle; | 162 | sc_ipc_t ipcHndl = gd->arch.ipc_channel_handle; |
163 | struct container_hdr *container = NULL; | 163 | struct container_hdr *container = NULL; |
164 | uint16_t length; | 164 | uint16_t length; |
165 | int ret; | 165 | int ret; |
166 | int i; | 166 | int i; |
167 | 167 | ||
168 | container = malloc(sizeof(struct container_hdr)); | 168 | container = malloc(sizeof(struct container_hdr)); |
169 | if (!container) | 169 | if (!container) |
170 | return -ENOMEM; | 170 | return -ENOMEM; |
171 | 171 | ||
172 | ret = read(start_offset, CONTAINER_HDR_ALIGNMENT, (void *)container); | 172 | ret = read(start_offset, CONTAINER_HDR_ALIGNMENT, (void *)container); |
173 | if (ret) | 173 | if (ret) |
174 | return ret; | 174 | return ret; |
175 | 175 | ||
176 | if (container->tag != 0x87 && container->version != 0x0) { | 176 | if (container->tag != 0x87 && container->version != 0x0) { |
177 | printf("Wrong container header\n"); | 177 | printf("Wrong container header\n"); |
178 | ret = -EFAULT; | 178 | ret = -EFAULT; |
179 | goto out; | 179 | goto out; |
180 | } | 180 | } |
181 | 181 | ||
182 | if (!container->num_images) { | 182 | if (!container->num_images) { |
183 | printf("Wrong container, no image found\n"); | 183 | printf("Wrong container, no image found\n"); |
184 | ret = -EFAULT; | 184 | ret = -EFAULT; |
185 | goto out; | 185 | goto out; |
186 | } | 186 | } |
187 | 187 | ||
188 | length = container->length_lsb + (container->length_msb << 8); | 188 | length = container->length_lsb + (container->length_msb << 8); |
189 | 189 | ||
190 | debug("container length %u\n", length); | 190 | debug("container length %u\n", length); |
191 | memcpy((void *)SEC_SECURE_RAM_BASE, (const void *)container, | 191 | memcpy((void *)SEC_SECURE_RAM_BASE, (const void *)container, |
192 | ALIGN(length, CONFIG_SYS_CACHELINE_SIZE)); | 192 | ALIGN(length, CONFIG_SYS_CACHELINE_SIZE)); |
193 | 193 | ||
194 | ret = sc_misc_seco_authenticate(ipcHndl, SC_MISC_AUTH_CONTAINER, | 194 | ret = sc_misc_seco_authenticate(ipcHndl, SC_MISC_AUTH_CONTAINER, |
195 | SECO_LOCAL_SEC_SEC_SECURE_RAM_BASE); | 195 | SECO_LOCAL_SEC_SEC_SECURE_RAM_BASE); |
196 | if (ret) { | 196 | if (ret) { |
197 | printf("authenticate container hdr failed, return %d\n", ret); | 197 | printf("authenticate container hdr failed, return %d\n", ret); |
198 | ret = -EFAULT; | 198 | ret = -EFAULT; |
199 | goto out; | 199 | goto out; |
200 | } | 200 | } |
201 | 201 | ||
202 | for (i = 0; i < container->num_images; i++) { | 202 | for (i = 0; i < container->num_images; i++) { |
203 | struct boot_img_t *image = read_auth_image(container, i); | 203 | struct boot_img_t *image = read_auth_image(container, i); |
204 | 204 | ||
205 | if (!image) { | 205 | if (!image) { |
206 | ret = -EINVAL; | 206 | ret = -EINVAL; |
207 | goto out; | 207 | goto out; |
208 | } | 208 | } |
209 | 209 | ||
210 | if (i == 0) { | 210 | if (i == 0) { |
211 | spl_image->load_addr = image->dst; | 211 | spl_image->load_addr = image->dst; |
212 | spl_image->entry_point = image->entry; | 212 | spl_image->entry_point = image->entry; |
213 | } | 213 | } |
214 | } | 214 | } |
215 | 215 | ||
216 | sc_misc_seco_authenticate(ipcHndl, SC_MISC_REL_CONTAINER, 0); | 216 | sc_misc_seco_authenticate(ipcHndl, SC_MISC_REL_CONTAINER, 0); |
217 | 217 | ||
218 | out: | 218 | out: |
219 | free(container); | 219 | free(container); |
220 | 220 | ||
221 | return ret; | 221 | return ret; |
222 | } | 222 | } |
223 | 223 | ||
224 | int mmc_load_image_parse_container(struct spl_image_info *spl_image, | 224 | int mmc_load_image_parse_container(struct spl_image_info *spl_image, |
225 | struct mmc *mmc, unsigned long sector) | 225 | struct mmc *mmc, unsigned long sector) |
226 | { | 226 | { |
227 | int ret = 0; | 227 | int ret = 0; |
228 | 228 | ||
229 | current_dev_type = MMC_DEV; | 229 | current_dev_type = MMC_DEV; |
230 | device = mmc; | 230 | device = mmc; |
231 | 231 | ||
232 | start_offset = sector * mmc->read_bl_len; | 232 | start_offset = sector * mmc->read_bl_len; |
233 | 233 | ||
234 | ret = read_auth_container(spl_image); | 234 | ret = read_auth_container(spl_image); |
235 | 235 | ||
236 | if (ret) | 236 | if (!ret) |
237 | return ret; | 237 | { |
238 | 238 | /* Images loaded, now check the rpmb keyblob for Trusty OS. */ | |
239 | /* Images loaded, now check the rpmb keyblob for Trusty OS. */ | ||
240 | #if defined(CONFIG_IMX_TRUSTY_OS) | 239 | #if defined(CONFIG_IMX_TRUSTY_OS) |
241 | ret = check_rpmb_blob(mmc); | 240 | ret = check_rpmb_blob(mmc); |
242 | return ret; | ||
243 | #endif | 241 | #endif |
242 | } | ||
243 | return ret; | ||
244 | } | 244 | } |
245 | 245 | ||
246 | int spi_load_image_parse_container(struct spl_image_info *spl_image, | 246 | int spi_load_image_parse_container(struct spl_image_info *spl_image, |
247 | struct spi_flash *flash, | 247 | struct spi_flash *flash, |
248 | unsigned long offset) | 248 | unsigned long offset) |
249 | { | 249 | { |
250 | int ret = 0; | 250 | int ret = 0; |
251 | 251 | ||
252 | current_dev_type = QSPI_DEV; | 252 | current_dev_type = QSPI_DEV; |
253 | device = flash; | 253 | device = flash; |
254 | 254 | ||
255 | start_offset = offset; | 255 | start_offset = offset; |
256 | 256 | ||
257 | ret = read_auth_container(spl_image); | 257 | ret = read_auth_container(spl_image); |
258 | 258 | ||
259 | return ret; | 259 | return ret; |
common/spl/spl_mmc.c
1 | /* | 1 | /* |
2 | * (C) Copyright 2010 | 2 | * (C) Copyright 2010 |
3 | * Texas Instruments, <www.ti.com> | 3 | * Texas Instruments, <www.ti.com> |
4 | * | 4 | * |
5 | * Aneesh V <aneesh@ti.com> | 5 | * Aneesh V <aneesh@ti.com> |
6 | * | 6 | * |
7 | * Copyright 2018 NXP | 7 | * Copyright 2018 NXP |
8 | * | 8 | * |
9 | * SPDX-License-Identifier: GPL-2.0+ | 9 | * SPDX-License-Identifier: GPL-2.0+ |
10 | */ | 10 | */ |
11 | #include <common.h> | 11 | #include <common.h> |
12 | #include <dm.h> | 12 | #include <dm.h> |
13 | #include <spl.h> | 13 | #include <spl.h> |
14 | #include <linux/compiler.h> | 14 | #include <linux/compiler.h> |
15 | #include <errno.h> | 15 | #include <errno.h> |
16 | #include <asm/u-boot.h> | 16 | #include <asm/u-boot.h> |
17 | #include <errno.h> | 17 | #include <errno.h> |
18 | #include <mmc.h> | 18 | #include <mmc.h> |
19 | #include <image.h> | 19 | #include <image.h> |
20 | 20 | ||
21 | DECLARE_GLOBAL_DATA_PTR; | 21 | DECLARE_GLOBAL_DATA_PTR; |
22 | 22 | ||
23 | int mmc_load_legacy(struct spl_image_info *spl_image, struct mmc *mmc, | 23 | int mmc_load_legacy(struct spl_image_info *spl_image, struct mmc *mmc, |
24 | ulong sector, struct image_header *header) | 24 | ulong sector, struct image_header *header) |
25 | { | 25 | { |
26 | u32 image_size_sectors; | 26 | u32 image_size_sectors; |
27 | unsigned long count; | 27 | unsigned long count; |
28 | int ret; | 28 | int ret; |
29 | 29 | ||
30 | ret = spl_parse_image_header(spl_image, header); | 30 | ret = spl_parse_image_header(spl_image, header); |
31 | if (ret) | 31 | if (ret) |
32 | return ret; | 32 | return ret; |
33 | 33 | ||
34 | /* convert size to sectors - round up */ | 34 | /* convert size to sectors - round up */ |
35 | image_size_sectors = (spl_image->size + mmc->read_bl_len - 1) / | 35 | image_size_sectors = (spl_image->size + mmc->read_bl_len - 1) / |
36 | mmc->read_bl_len; | 36 | mmc->read_bl_len; |
37 | 37 | ||
38 | /* Read the header too to avoid extra memcpy */ | 38 | /* Read the header too to avoid extra memcpy */ |
39 | count = blk_dread(mmc_get_blk_desc(mmc), sector, image_size_sectors, | 39 | count = blk_dread(mmc_get_blk_desc(mmc), sector, image_size_sectors, |
40 | (void *)(ulong)spl_image->load_addr); | 40 | (void *)(ulong)spl_image->load_addr); |
41 | debug("read %x sectors to %lx\n", image_size_sectors, | 41 | debug("read %x sectors to %lx\n", image_size_sectors, |
42 | spl_image->load_addr); | 42 | spl_image->load_addr); |
43 | if (count != image_size_sectors) | 43 | if (count != image_size_sectors) |
44 | return -EIO; | 44 | return -EIO; |
45 | 45 | ||
46 | return 0; | 46 | return 0; |
47 | } | 47 | } |
48 | 48 | ||
49 | ulong h_spl_load_read(struct spl_load_info *load, ulong sector, | 49 | ulong h_spl_load_read(struct spl_load_info *load, ulong sector, |
50 | ulong count, void *buf) | 50 | ulong count, void *buf) |
51 | { | 51 | { |
52 | struct mmc *mmc = load->dev; | 52 | struct mmc *mmc = load->dev; |
53 | 53 | ||
54 | return blk_dread(mmc_get_blk_desc(mmc), sector, count, buf); | 54 | return blk_dread(mmc_get_blk_desc(mmc), sector, count, buf); |
55 | } | 55 | } |
56 | 56 | ||
57 | #if defined(CONFIG_IMX_TRUSTY_OS) && defined(CONFIG_ANDROID_AUTO_SUPPORT) | 57 | #if defined(CONFIG_IMX_TRUSTY_OS) && defined(CONFIG_ANDROID_AUTO_SUPPORT) |
58 | /* Pre-declaration of check_rpmb_blob. */ | 58 | /* Pre-declaration of check_rpmb_blob. */ |
59 | int check_rpmb_blob(struct mmc *mmc); | 59 | int check_rpmb_blob(struct mmc *mmc); |
60 | #endif | 60 | #endif |
61 | 61 | ||
62 | #ifdef CONFIG_DUAL_BOOTLOADER | 62 | #ifdef CONFIG_DUAL_BOOTLOADER |
63 | /* Pre-declaration of mmc_load_image_raw_sector_dual_uboot(). | 63 | /* Pre-declaration of mmc_load_image_raw_sector_dual_uboot(). |
64 | */ | 64 | */ |
65 | extern int mmc_load_image_raw_sector_dual_uboot(struct spl_image_info *spl_image, | 65 | extern int mmc_load_image_raw_sector_dual_uboot(struct spl_image_info *spl_image, |
66 | struct mmc *mmc); | 66 | struct mmc *mmc); |
67 | #else | 67 | #else |
68 | static __maybe_unused | 68 | static __maybe_unused |
69 | int mmc_load_image_raw_sector(struct spl_image_info *spl_image, | 69 | int mmc_load_image_raw_sector(struct spl_image_info *spl_image, |
70 | struct mmc *mmc, unsigned long sector) | 70 | struct mmc *mmc, unsigned long sector) |
71 | { | 71 | { |
72 | struct image_header *header = (struct image_header *)(CONFIG_SYS_TEXT_BASE - | 72 | struct image_header *header = (struct image_header *)(CONFIG_SYS_TEXT_BASE - |
73 | sizeof(struct image_header)); | 73 | sizeof(struct image_header)); |
74 | int ret = 0; | 74 | int ret = 0; |
75 | 75 | ||
76 | #if !defined(CONFIG_SPL_RAW_IMAGE_ARM_TRUSTED_FIRMWARE) || defined(CONFIG_SPL_LOAD_FIT) | 76 | #if !defined(CONFIG_SPL_RAW_IMAGE_ARM_TRUSTED_FIRMWARE) || defined(CONFIG_SPL_LOAD_FIT) |
77 | unsigned long count = 0; | 77 | unsigned long count = 0; |
78 | 78 | ||
79 | /* read image header to find the image size & load address */ | 79 | /* read image header to find the image size & load address */ |
80 | count = blk_dread(mmc_get_blk_desc(mmc), sector, 1, header); | 80 | count = blk_dread(mmc_get_blk_desc(mmc), sector, 1, header); |
81 | debug("hdr read sector %lx, count=%lu\n", sector, count); | 81 | debug("hdr read sector %lx, count=%lu\n", sector, count); |
82 | if (count == 0) { | 82 | if (count == 0) { |
83 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT | 83 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
84 | puts("mmc_load_image_raw_sector: mmc block read error\n"); | 84 | puts("mmc_load_image_raw_sector: mmc block read error\n"); |
85 | #endif | 85 | #endif |
86 | return -1; | 86 | return -1; |
87 | } | 87 | } |
88 | #endif | 88 | #endif |
89 | if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) && | 89 | if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) && |
90 | image_get_magic(header) == FDT_MAGIC) { | 90 | image_get_magic(header) == FDT_MAGIC) { |
91 | struct spl_load_info load; | 91 | struct spl_load_info load; |
92 | 92 | ||
93 | debug("Found FIT\n"); | 93 | debug("Found FIT\n"); |
94 | load.dev = mmc; | 94 | load.dev = mmc; |
95 | load.priv = NULL; | 95 | load.priv = NULL; |
96 | load.filename = NULL; | 96 | load.filename = NULL; |
97 | load.bl_len = mmc->read_bl_len; | 97 | load.bl_len = mmc->read_bl_len; |
98 | load.read = h_spl_load_read; | 98 | load.read = h_spl_load_read; |
99 | ret = spl_load_simple_fit(spl_image, &load, sector, header); | 99 | ret = spl_load_simple_fit(spl_image, &load, sector, header); |
100 | } else { | 100 | } else { |
101 | ret = mmc_load_legacy(spl_image, mmc, sector, header); | 101 | ret = mmc_load_legacy(spl_image, mmc, sector, header); |
102 | } | 102 | } |
103 | 103 | ||
104 | if (ret) { | 104 | if (ret) { |
105 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT | 105 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
106 | puts("mmc_load_image_raw_sector: mmc block read error\n"); | 106 | puts("mmc_load_image_raw_sector: mmc block read error\n"); |
107 | #endif | 107 | #endif |
108 | return -1; | 108 | return -1; |
109 | } | 109 | } |
110 | 110 | ||
111 | /* Images loaded, now check the rpmb keyblob for Trusty OS. */ | 111 | /* Images loaded, now check the rpmb keyblob for Trusty OS. */ |
112 | #if defined(CONFIG_IMX_TRUSTY_OS) && defined(CONFIG_ANDROID_AUTO_SUPPORT) | 112 | #if defined(CONFIG_IMX_TRUSTY_OS) && defined(CONFIG_ANDROID_AUTO_SUPPORT) |
113 | ret = check_rpmb_blob(mmc); | 113 | ret = check_rpmb_blob(mmc); |
114 | #endif | 114 | #endif |
115 | return 0; | 115 | return ret; |
116 | } | 116 | } |
117 | 117 | ||
118 | #endif /* CONFIG_DUAL_BOOTLOADER */ | 118 | #endif /* CONFIG_DUAL_BOOTLOADER */ |
119 | 119 | ||
120 | static int spl_mmc_get_device_index(u32 boot_device) | 120 | static int spl_mmc_get_device_index(u32 boot_device) |
121 | { | 121 | { |
122 | switch (boot_device) { | 122 | switch (boot_device) { |
123 | case BOOT_DEVICE_MMC1: | 123 | case BOOT_DEVICE_MMC1: |
124 | return 0; | 124 | return 0; |
125 | case BOOT_DEVICE_MMC2: | 125 | case BOOT_DEVICE_MMC2: |
126 | case BOOT_DEVICE_MMC2_2: | 126 | case BOOT_DEVICE_MMC2_2: |
127 | return 1; | 127 | return 1; |
128 | } | 128 | } |
129 | 129 | ||
130 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT | 130 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
131 | printf("spl: unsupported mmc boot device.\n"); | 131 | printf("spl: unsupported mmc boot device.\n"); |
132 | #endif | 132 | #endif |
133 | 133 | ||
134 | return -ENODEV; | 134 | return -ENODEV; |
135 | } | 135 | } |
136 | 136 | ||
137 | static int spl_mmc_find_device(struct mmc **mmcp, u32 boot_device) | 137 | static int spl_mmc_find_device(struct mmc **mmcp, u32 boot_device) |
138 | { | 138 | { |
139 | #if CONFIG_IS_ENABLED(DM_MMC) | 139 | #if CONFIG_IS_ENABLED(DM_MMC) |
140 | struct udevice *dev; | 140 | struct udevice *dev; |
141 | #endif | 141 | #endif |
142 | int err, mmc_dev; | 142 | int err, mmc_dev; |
143 | 143 | ||
144 | mmc_dev = spl_mmc_get_device_index(boot_device); | 144 | mmc_dev = spl_mmc_get_device_index(boot_device); |
145 | if (mmc_dev < 0) | 145 | if (mmc_dev < 0) |
146 | return mmc_dev; | 146 | return mmc_dev; |
147 | 147 | ||
148 | err = mmc_initialize(NULL); | 148 | err = mmc_initialize(NULL); |
149 | if (err) { | 149 | if (err) { |
150 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT | 150 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
151 | printf("spl: could not initialize mmc. error: %d\n", err); | 151 | printf("spl: could not initialize mmc. error: %d\n", err); |
152 | #endif | 152 | #endif |
153 | return err; | 153 | return err; |
154 | } | 154 | } |
155 | 155 | ||
156 | #if CONFIG_IS_ENABLED(DM_MMC) | 156 | #if CONFIG_IS_ENABLED(DM_MMC) |
157 | err = uclass_get_device(UCLASS_MMC, mmc_dev, &dev); | 157 | err = uclass_get_device(UCLASS_MMC, mmc_dev, &dev); |
158 | if (!err) | 158 | if (!err) |
159 | *mmcp = mmc_get_mmc_dev(dev); | 159 | *mmcp = mmc_get_mmc_dev(dev); |
160 | #else | 160 | #else |
161 | *mmcp = find_mmc_device(mmc_dev); | 161 | *mmcp = find_mmc_device(mmc_dev); |
162 | err = *mmcp ? 0 : -ENODEV; | 162 | err = *mmcp ? 0 : -ENODEV; |
163 | #endif | 163 | #endif |
164 | if (err) { | 164 | if (err) { |
165 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT | 165 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
166 | printf("spl: could not find mmc device. error: %d\n", err); | 166 | printf("spl: could not find mmc device. error: %d\n", err); |
167 | #endif | 167 | #endif |
168 | return err; | 168 | return err; |
169 | } | 169 | } |
170 | 170 | ||
171 | return 0; | 171 | return 0; |
172 | } | 172 | } |
173 | 173 | ||
174 | #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION | 174 | #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION |
175 | static int mmc_load_image_raw_partition(struct spl_image_info *spl_image, | 175 | static int mmc_load_image_raw_partition(struct spl_image_info *spl_image, |
176 | struct mmc *mmc, int partition) | 176 | struct mmc *mmc, int partition) |
177 | { | 177 | { |
178 | disk_partition_t info; | 178 | disk_partition_t info; |
179 | int err; | 179 | int err; |
180 | 180 | ||
181 | #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION_TYPE | 181 | #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION_TYPE |
182 | int type_part; | 182 | int type_part; |
183 | /* Only support MBR so DOS_ENTRY_NUMBERS */ | 183 | /* Only support MBR so DOS_ENTRY_NUMBERS */ |
184 | for (type_part = 1; type_part <= DOS_ENTRY_NUMBERS; type_part++) { | 184 | for (type_part = 1; type_part <= DOS_ENTRY_NUMBERS; type_part++) { |
185 | err = part_get_info(mmc_get_blk_desc(mmc), type_part, &info); | 185 | err = part_get_info(mmc_get_blk_desc(mmc), type_part, &info); |
186 | if (err) | 186 | if (err) |
187 | continue; | 187 | continue; |
188 | if (info.sys_ind == | 188 | if (info.sys_ind == |
189 | CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION_TYPE) { | 189 | CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION_TYPE) { |
190 | partition = type_part; | 190 | partition = type_part; |
191 | break; | 191 | break; |
192 | } | 192 | } |
193 | } | 193 | } |
194 | #endif | 194 | #endif |
195 | 195 | ||
196 | err = part_get_info(mmc_get_blk_desc(mmc), partition, &info); | 196 | err = part_get_info(mmc_get_blk_desc(mmc), partition, &info); |
197 | if (err) { | 197 | if (err) { |
198 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT | 198 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
199 | puts("spl: partition error\n"); | 199 | puts("spl: partition error\n"); |
200 | #endif | 200 | #endif |
201 | return -1; | 201 | return -1; |
202 | } | 202 | } |
203 | 203 | ||
204 | #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR | 204 | #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR |
205 | return mmc_load_image_raw_sector(spl_image, mmc, | 205 | return mmc_load_image_raw_sector(spl_image, mmc, |
206 | info.start + CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR); | 206 | info.start + CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR); |
207 | #else | 207 | #else |
208 | return mmc_load_image_raw_sector(spl_image, mmc, info.start); | 208 | return mmc_load_image_raw_sector(spl_image, mmc, info.start); |
209 | #endif | 209 | #endif |
210 | } | 210 | } |
211 | #endif | 211 | #endif |
212 | 212 | ||
213 | #ifdef CONFIG_SPL_OS_BOOT | 213 | #ifdef CONFIG_SPL_OS_BOOT |
214 | static int mmc_load_image_raw_os(struct spl_image_info *spl_image, | 214 | static int mmc_load_image_raw_os(struct spl_image_info *spl_image, |
215 | struct mmc *mmc) | 215 | struct mmc *mmc) |
216 | { | 216 | { |
217 | unsigned long count; | 217 | unsigned long count; |
218 | int ret; | 218 | int ret; |
219 | 219 | ||
220 | count = blk_dread(mmc_get_blk_desc(mmc), | 220 | count = blk_dread(mmc_get_blk_desc(mmc), |
221 | CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR, | 221 | CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR, |
222 | CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTORS, | 222 | CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTORS, |
223 | (void *) CONFIG_SYS_SPL_ARGS_ADDR); | 223 | (void *) CONFIG_SYS_SPL_ARGS_ADDR); |
224 | if (count != CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTORS) { | 224 | if (count != CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTORS) { |
225 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT | 225 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
226 | puts("mmc_load_image_raw_os: mmc block read error\n"); | 226 | puts("mmc_load_image_raw_os: mmc block read error\n"); |
227 | #endif | 227 | #endif |
228 | return -1; | 228 | return -1; |
229 | } | 229 | } |
230 | 230 | ||
231 | ret = mmc_load_image_raw_sector(spl_image, mmc, | 231 | ret = mmc_load_image_raw_sector(spl_image, mmc, |
232 | CONFIG_SYS_MMCSD_RAW_MODE_KERNEL_SECTOR); | 232 | CONFIG_SYS_MMCSD_RAW_MODE_KERNEL_SECTOR); |
233 | if (ret) | 233 | if (ret) |
234 | return ret; | 234 | return ret; |
235 | 235 | ||
236 | if (spl_image->os != IH_OS_LINUX) { | 236 | if (spl_image->os != IH_OS_LINUX) { |
237 | puts("Expected Linux image is not found. Trying to start U-boot\n"); | 237 | puts("Expected Linux image is not found. Trying to start U-boot\n"); |
238 | return -ENOENT; | 238 | return -ENOENT; |
239 | } | 239 | } |
240 | 240 | ||
241 | return 0; | 241 | return 0; |
242 | } | 242 | } |
243 | #else | 243 | #else |
244 | int spl_start_uboot(void) | 244 | int spl_start_uboot(void) |
245 | { | 245 | { |
246 | return 1; | 246 | return 1; |
247 | } | 247 | } |
248 | static int mmc_load_image_raw_os(struct spl_image_info *spl_image, | 248 | static int mmc_load_image_raw_os(struct spl_image_info *spl_image, |
249 | struct mmc *mmc) | 249 | struct mmc *mmc) |
250 | { | 250 | { |
251 | return -ENOSYS; | 251 | return -ENOSYS; |
252 | } | 252 | } |
253 | #endif | 253 | #endif |
254 | 254 | ||
255 | #ifdef CONFIG_SYS_MMCSD_FS_BOOT_PARTITION | 255 | #ifdef CONFIG_SYS_MMCSD_FS_BOOT_PARTITION |
256 | static int spl_mmc_do_fs_boot(struct spl_image_info *spl_image, struct mmc *mmc) | 256 | static int spl_mmc_do_fs_boot(struct spl_image_info *spl_image, struct mmc *mmc) |
257 | { | 257 | { |
258 | int err = -ENOSYS; | 258 | int err = -ENOSYS; |
259 | 259 | ||
260 | #ifdef CONFIG_SPL_FAT_SUPPORT | 260 | #ifdef CONFIG_SPL_FAT_SUPPORT |
261 | if (!spl_start_uboot()) { | 261 | if (!spl_start_uboot()) { |
262 | err = spl_load_image_fat_os(spl_image, mmc_get_blk_desc(mmc), | 262 | err = spl_load_image_fat_os(spl_image, mmc_get_blk_desc(mmc), |
263 | CONFIG_SYS_MMCSD_FS_BOOT_PARTITION); | 263 | CONFIG_SYS_MMCSD_FS_BOOT_PARTITION); |
264 | if (!err) | 264 | if (!err) |
265 | return err; | 265 | return err; |
266 | } | 266 | } |
267 | #ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME | 267 | #ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME |
268 | err = spl_load_image_fat(spl_image, mmc_get_blk_desc(mmc), | 268 | err = spl_load_image_fat(spl_image, mmc_get_blk_desc(mmc), |
269 | CONFIG_SYS_MMCSD_FS_BOOT_PARTITION, | 269 | CONFIG_SYS_MMCSD_FS_BOOT_PARTITION, |
270 | CONFIG_SPL_FS_LOAD_PAYLOAD_NAME); | 270 | CONFIG_SPL_FS_LOAD_PAYLOAD_NAME); |
271 | if (!err) | 271 | if (!err) |
272 | return err; | 272 | return err; |
273 | #endif | 273 | #endif |
274 | #endif | 274 | #endif |
275 | #ifdef CONFIG_SPL_EXT_SUPPORT | 275 | #ifdef CONFIG_SPL_EXT_SUPPORT |
276 | if (!spl_start_uboot()) { | 276 | if (!spl_start_uboot()) { |
277 | err = spl_load_image_ext_os(spl_image, mmc_get_blk_desc(mmc), | 277 | err = spl_load_image_ext_os(spl_image, mmc_get_blk_desc(mmc), |
278 | CONFIG_SYS_MMCSD_FS_BOOT_PARTITION); | 278 | CONFIG_SYS_MMCSD_FS_BOOT_PARTITION); |
279 | if (!err) | 279 | if (!err) |
280 | return err; | 280 | return err; |
281 | } | 281 | } |
282 | #ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME | 282 | #ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME |
283 | err = spl_load_image_ext(spl_image, mmc_get_blk_desc(mmc), | 283 | err = spl_load_image_ext(spl_image, mmc_get_blk_desc(mmc), |
284 | CONFIG_SYS_MMCSD_FS_BOOT_PARTITION, | 284 | CONFIG_SYS_MMCSD_FS_BOOT_PARTITION, |
285 | CONFIG_SPL_FS_LOAD_PAYLOAD_NAME); | 285 | CONFIG_SPL_FS_LOAD_PAYLOAD_NAME); |
286 | if (!err) | 286 | if (!err) |
287 | return err; | 287 | return err; |
288 | #endif | 288 | #endif |
289 | #endif | 289 | #endif |
290 | 290 | ||
291 | #if defined(CONFIG_SPL_FAT_SUPPORT) || defined(CONFIG_SPL_EXT_SUPPORT) | 291 | #if defined(CONFIG_SPL_FAT_SUPPORT) || defined(CONFIG_SPL_EXT_SUPPORT) |
292 | err = -ENOENT; | 292 | err = -ENOENT; |
293 | #endif | 293 | #endif |
294 | 294 | ||
295 | return err; | 295 | return err; |
296 | } | 296 | } |
297 | #else | 297 | #else |
298 | static int spl_mmc_do_fs_boot(struct spl_image_info *spl_image, struct mmc *mmc) | 298 | static int spl_mmc_do_fs_boot(struct spl_image_info *spl_image, struct mmc *mmc) |
299 | { | 299 | { |
300 | return -ENOSYS; | 300 | return -ENOSYS; |
301 | } | 301 | } |
302 | #endif | 302 | #endif |
303 | 303 | ||
304 | u32 __weak spl_boot_mode(const u32 boot_device) | 304 | u32 __weak spl_boot_mode(const u32 boot_device) |
305 | { | 305 | { |
306 | #if defined(CONFIG_SPL_FAT_SUPPORT) || defined(CONFIG_SPL_EXT_SUPPORT) | 306 | #if defined(CONFIG_SPL_FAT_SUPPORT) || defined(CONFIG_SPL_EXT_SUPPORT) |
307 | return MMCSD_MODE_FS; | 307 | return MMCSD_MODE_FS; |
308 | #elif defined(CONFIG_SUPPORT_EMMC_BOOT) | 308 | #elif defined(CONFIG_SUPPORT_EMMC_BOOT) |
309 | return MMCSD_MODE_EMMCBOOT; | 309 | return MMCSD_MODE_EMMCBOOT; |
310 | #else | 310 | #else |
311 | return MMCSD_MODE_RAW; | 311 | return MMCSD_MODE_RAW; |
312 | #endif | 312 | #endif |
313 | } | 313 | } |
314 | 314 | ||
315 | #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR | 315 | #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR |
316 | unsigned long __weak spl_mmc_get_uboot_raw_sector(struct mmc *mmc) | 316 | unsigned long __weak spl_mmc_get_uboot_raw_sector(struct mmc *mmc) |
317 | { | 317 | { |
318 | return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR; | 318 | return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR; |
319 | } | 319 | } |
320 | #endif | 320 | #endif |
321 | 321 | ||
322 | #ifdef CONFIG_PARSE_CONTAINER | 322 | #ifdef CONFIG_PARSE_CONTAINER |
323 | int __weak mmc_load_image_parse_container(struct spl_image_info *spl_image, | 323 | int __weak mmc_load_image_parse_container(struct spl_image_info *spl_image, |
324 | struct mmc *mmc, unsigned long sector) | 324 | struct mmc *mmc, unsigned long sector) |
325 | { | 325 | { |
326 | return -ENODEV; | 326 | return -ENODEV; |
327 | }; | 327 | }; |
328 | #endif | 328 | #endif |
329 | 329 | ||
330 | int spl_mmc_load_image(struct spl_image_info *spl_image, | 330 | int spl_mmc_load_image(struct spl_image_info *spl_image, |
331 | struct spl_boot_device *bootdev) | 331 | struct spl_boot_device *bootdev) |
332 | { | 332 | { |
333 | struct mmc *mmc = NULL; | 333 | struct mmc *mmc = NULL; |
334 | u32 boot_mode; | 334 | u32 boot_mode; |
335 | int err = 0; | 335 | int err = 0; |
336 | __maybe_unused int part; | 336 | __maybe_unused int part; |
337 | 337 | ||
338 | err = spl_mmc_find_device(&mmc, bootdev->boot_device); | 338 | err = spl_mmc_find_device(&mmc, bootdev->boot_device); |
339 | if (err) | 339 | if (err) |
340 | return err; | 340 | return err; |
341 | 341 | ||
342 | err = mmc_init(mmc); | 342 | err = mmc_init(mmc); |
343 | if (err) { | 343 | if (err) { |
344 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT | 344 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
345 | printf("spl: mmc init failed with error: %d\n", err); | 345 | printf("spl: mmc init failed with error: %d\n", err); |
346 | #endif | 346 | #endif |
347 | return err; | 347 | return err; |
348 | } | 348 | } |
349 | 349 | ||
350 | boot_mode = spl_boot_mode(bootdev->boot_device); | 350 | boot_mode = spl_boot_mode(bootdev->boot_device); |
351 | err = -EINVAL; | 351 | err = -EINVAL; |
352 | switch (boot_mode) { | 352 | switch (boot_mode) { |
353 | case MMCSD_MODE_EMMCBOOT: | 353 | case MMCSD_MODE_EMMCBOOT: |
354 | /* | 354 | /* |
355 | * We need to check what the partition is configured to. | 355 | * We need to check what the partition is configured to. |
356 | * 1 and 2 match up to boot0 / boot1 and 7 is user data | 356 | * 1 and 2 match up to boot0 / boot1 and 7 is user data |
357 | * which is the first physical partition (0). | 357 | * which is the first physical partition (0). |
358 | */ | 358 | */ |
359 | #ifdef CONFIG_DUAL_BOOTLOADER | 359 | #ifdef CONFIG_DUAL_BOOTLOADER |
360 | /* Bootloader is stored in eMMC user partition for dual bootloader */ | 360 | /* Bootloader is stored in eMMC user partition for dual bootloader */ |
361 | part = 0; | 361 | part = 0; |
362 | #else | 362 | #else |
363 | part = (mmc->part_config >> 3) & PART_ACCESS_MASK; | 363 | part = (mmc->part_config >> 3) & PART_ACCESS_MASK; |
364 | 364 | ||
365 | if (part == 7) | 365 | if (part == 7) |
366 | part = 0; | 366 | part = 0; |
367 | #endif | 367 | #endif |
368 | 368 | ||
369 | if (CONFIG_IS_ENABLED(MMC_TINY)) | 369 | if (CONFIG_IS_ENABLED(MMC_TINY)) |
370 | err = mmc_switch_part(mmc, part); | 370 | err = mmc_switch_part(mmc, part); |
371 | else | 371 | else |
372 | err = blk_dselect_hwpart(mmc_get_blk_desc(mmc), part); | 372 | err = blk_dselect_hwpart(mmc_get_blk_desc(mmc), part); |
373 | 373 | ||
374 | if (err) { | 374 | if (err) { |
375 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT | 375 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
376 | puts("spl: mmc partition switch failed\n"); | 376 | puts("spl: mmc partition switch failed\n"); |
377 | #endif | 377 | #endif |
378 | return err; | 378 | return err; |
379 | } | 379 | } |
380 | /* Fall through */ | 380 | /* Fall through */ |
381 | case MMCSD_MODE_RAW: | 381 | case MMCSD_MODE_RAW: |
382 | debug("spl: mmc boot mode: raw\n"); | 382 | debug("spl: mmc boot mode: raw\n"); |
383 | 383 | ||
384 | if (!spl_start_uboot()) { | 384 | if (!spl_start_uboot()) { |
385 | err = mmc_load_image_raw_os(spl_image, mmc); | 385 | err = mmc_load_image_raw_os(spl_image, mmc); |
386 | if (!err) | 386 | if (!err) |
387 | return err; | 387 | return err; |
388 | } | 388 | } |
389 | #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION | 389 | #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION |
390 | err = mmc_load_image_raw_partition(spl_image, mmc, | 390 | err = mmc_load_image_raw_partition(spl_image, mmc, |
391 | CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION); | 391 | CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION); |
392 | if (!err) | 392 | if (!err) |
393 | return err; | 393 | return err; |
394 | #endif | 394 | #endif |
395 | #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR | 395 | #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR |
396 | #ifdef CONFIG_DUAL_BOOTLOADER | 396 | #ifdef CONFIG_DUAL_BOOTLOADER |
397 | err = mmc_load_image_raw_sector_dual_uboot(spl_image, | 397 | err = mmc_load_image_raw_sector_dual_uboot(spl_image, |
398 | mmc); | 398 | mmc); |
399 | #else | 399 | #else |
400 | #ifdef CONFIG_PARSE_CONTAINER | 400 | #ifdef CONFIG_PARSE_CONTAINER |
401 | err = mmc_load_image_parse_container(spl_image, mmc, | 401 | err = mmc_load_image_parse_container(spl_image, mmc, |
402 | spl_mmc_get_uboot_raw_sector(mmc)); | 402 | spl_mmc_get_uboot_raw_sector(mmc)); |
403 | #else | 403 | #else |
404 | err = mmc_load_image_raw_sector(spl_image, mmc, | 404 | err = mmc_load_image_raw_sector(spl_image, mmc, |
405 | spl_mmc_get_uboot_raw_sector(mmc)); | 405 | spl_mmc_get_uboot_raw_sector(mmc)); |
406 | #endif | 406 | #endif |
407 | #endif | 407 | #endif |
408 | if (!err) | 408 | if (!err) |
409 | return err; | 409 | return err; |
410 | #endif | 410 | #endif |
411 | /* If RAW mode fails, try FS mode. */ | 411 | /* If RAW mode fails, try FS mode. */ |
412 | case MMCSD_MODE_FS: | 412 | case MMCSD_MODE_FS: |
413 | debug("spl: mmc boot mode: fs\n"); | 413 | debug("spl: mmc boot mode: fs\n"); |
414 | 414 | ||
415 | err = spl_mmc_do_fs_boot(spl_image, mmc); | 415 | err = spl_mmc_do_fs_boot(spl_image, mmc); |
416 | if (!err) | 416 | if (!err) |
417 | return err; | 417 | return err; |
418 | 418 | ||
419 | break; | 419 | break; |
420 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT | 420 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
421 | default: | 421 | default: |
422 | puts("spl: mmc: wrong boot mode\n"); | 422 | puts("spl: mmc: wrong boot mode\n"); |
423 | #endif | 423 | #endif |
424 | } | 424 | } |
425 | 425 | ||
426 | return err; | 426 | return err; |
427 | } | 427 | } |
428 | 428 | ||
429 | SPL_LOAD_IMAGE_METHOD("MMC1", 0, BOOT_DEVICE_MMC1, spl_mmc_load_image); | 429 | SPL_LOAD_IMAGE_METHOD("MMC1", 0, BOOT_DEVICE_MMC1, spl_mmc_load_image); |
430 | SPL_LOAD_IMAGE_METHOD("MMC2", 0, BOOT_DEVICE_MMC2, spl_mmc_load_image); | 430 | SPL_LOAD_IMAGE_METHOD("MMC2", 0, BOOT_DEVICE_MMC2, spl_mmc_load_image); |
431 | SPL_LOAD_IMAGE_METHOD("MMC2_2", 0, BOOT_DEVICE_MMC2_2, spl_mmc_load_image); | 431 | SPL_LOAD_IMAGE_METHOD("MMC2_2", 0, BOOT_DEVICE_MMC2_2, spl_mmc_load_image); |
432 | 432 |