Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stefan Agner | 22802f4 | 2016-12-23 07:51:53 +0100 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2016 |
| 4 | * Xilinx, Inc. |
| 5 | * |
| 6 | * (C) Copyright 2016 |
| 7 | * Toradex AG |
| 8 | * |
| 9 | * Michal Simek <michal.simek@xilinx.com> |
| 10 | * Stefan Agner <stefan.agner@toradex.com> |
Stefan Agner | 22802f4 | 2016-12-23 07:51:53 +0100 | [diff] [blame] | 11 | */ |
| 12 | #include <common.h> |
Simon Glass | dfce179 | 2017-11-13 18:55:04 -0700 | [diff] [blame] | 13 | #include <binman_sym.h> |
Simon Glass | 4d72caa | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 14 | #include <image.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 15 | #include <log.h> |
Simon Glass | dfce179 | 2017-11-13 18:55:04 -0700 | [diff] [blame] | 16 | #include <mapmem.h> |
Stefan Agner | 22802f4 | 2016-12-23 07:51:53 +0100 | [diff] [blame] | 17 | #include <spl.h> |
Masahiro Yamada | b08c8c4 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 18 | #include <linux/libfdt.h> |
Stefan Agner | 22802f4 | 2016-12-23 07:51:53 +0100 | [diff] [blame] | 19 | |
| 20 | #ifndef CONFIG_SPL_LOAD_FIT_ADDRESS |
| 21 | # define CONFIG_SPL_LOAD_FIT_ADDRESS 0 |
| 22 | #endif |
| 23 | |
| 24 | static ulong spl_ram_load_read(struct spl_load_info *load, ulong sector, |
| 25 | ulong count, void *buf) |
| 26 | { |
| 27 | debug("%s: sector %lx, count %lx, buf %lx\n", |
| 28 | __func__, sector, count, (ulong)buf); |
| 29 | memcpy(buf, (void *)(CONFIG_SPL_LOAD_FIT_ADDRESS + sector), count); |
| 30 | return count; |
| 31 | } |
| 32 | |
| 33 | static int spl_ram_load_image(struct spl_image_info *spl_image, |
| 34 | struct spl_boot_device *bootdev) |
| 35 | { |
| 36 | struct image_header *header; |
| 37 | |
| 38 | header = (struct image_header *)CONFIG_SPL_LOAD_FIT_ADDRESS; |
| 39 | |
Andrew F. Davis | 6536ca4 | 2019-01-17 13:43:02 -0600 | [diff] [blame] | 40 | #if CONFIG_IS_ENABLED(DFU) |
Stefan Agner | 22802f4 | 2016-12-23 07:51:53 +0100 | [diff] [blame] | 41 | if (bootdev->boot_device == BOOT_DEVICE_DFU) |
| 42 | spl_dfu_cmd(0, "dfu_alt_info_ram", "ram", "0"); |
| 43 | #endif |
| 44 | |
| 45 | if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) && |
| 46 | image_get_magic(header) == FDT_MAGIC) { |
| 47 | struct spl_load_info load; |
| 48 | |
| 49 | debug("Found FIT\n"); |
| 50 | load.bl_len = 1; |
| 51 | load.read = spl_ram_load_read; |
| 52 | spl_load_simple_fit(spl_image, &load, 0, header); |
| 53 | } else { |
Simon Glass | dbf6be9 | 2018-08-01 15:22:42 -0600 | [diff] [blame] | 54 | ulong u_boot_pos = binman_sym(ulong, u_boot_any, image_pos); |
Simon Glass | dfce179 | 2017-11-13 18:55:04 -0700 | [diff] [blame] | 55 | |
Stefan Agner | 22802f4 | 2016-12-23 07:51:53 +0100 | [diff] [blame] | 56 | debug("Legacy image\n"); |
| 57 | /* |
| 58 | * Get the header. It will point to an address defined by |
| 59 | * handoff which will tell where the image located inside |
Simon Glass | dfce179 | 2017-11-13 18:55:04 -0700 | [diff] [blame] | 60 | * the flash. |
Stefan Agner | 22802f4 | 2016-12-23 07:51:53 +0100 | [diff] [blame] | 61 | */ |
Simon Glass | dfce179 | 2017-11-13 18:55:04 -0700 | [diff] [blame] | 62 | debug("u_boot_pos = %lx\n", u_boot_pos); |
| 63 | if (u_boot_pos == BINMAN_SYM_MISSING) { |
| 64 | /* |
| 65 | * No binman support or no information. For now, fix it |
| 66 | * to the address pointed to by U-Boot. |
| 67 | */ |
Michal Simek | 83a6456 | 2018-10-04 09:29:20 +0200 | [diff] [blame] | 68 | u_boot_pos = (ulong)spl_get_load_buffer(-sizeof(*header), |
| 69 | sizeof(*header)); |
Simon Glass | dfce179 | 2017-11-13 18:55:04 -0700 | [diff] [blame] | 70 | } |
| 71 | header = (struct image_header *)map_sysmem(u_boot_pos, 0); |
Stefan Agner | 22802f4 | 2016-12-23 07:51:53 +0100 | [diff] [blame] | 72 | |
| 73 | spl_parse_image_header(spl_image, header); |
| 74 | } |
| 75 | |
| 76 | return 0; |
| 77 | } |
Marek Vasut | 4913261 | 2018-04-07 17:03:28 +0200 | [diff] [blame] | 78 | #if CONFIG_IS_ENABLED(RAM_DEVICE) |
Stefan Agner | 22802f4 | 2016-12-23 07:51:53 +0100 | [diff] [blame] | 79 | SPL_LOAD_IMAGE_METHOD("RAM", 0, BOOT_DEVICE_RAM, spl_ram_load_image); |
| 80 | #endif |
Andrew F. Davis | 6536ca4 | 2019-01-17 13:43:02 -0600 | [diff] [blame] | 81 | #if CONFIG_IS_ENABLED(DFU) |
Stefan Agner | 22802f4 | 2016-12-23 07:51:53 +0100 | [diff] [blame] | 82 | SPL_LOAD_IMAGE_METHOD("DFU", 0, BOOT_DEVICE_DFU, spl_ram_load_image); |
| 83 | #endif |
| 84 | |
| 85 | |