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> |
| 14 | #include <mapmem.h> |
Stefan Agner | 22802f4 | 2016-12-23 07:51:53 +0100 | [diff] [blame] | 15 | #include <spl.h> |
Masahiro Yamada | b08c8c4 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 16 | #include <linux/libfdt.h> |
Stefan Agner | 22802f4 | 2016-12-23 07:51:53 +0100 | [diff] [blame] | 17 | |
| 18 | #ifndef CONFIG_SPL_LOAD_FIT_ADDRESS |
| 19 | # define CONFIG_SPL_LOAD_FIT_ADDRESS 0 |
| 20 | #endif |
| 21 | |
| 22 | static ulong spl_ram_load_read(struct spl_load_info *load, ulong sector, |
| 23 | ulong count, void *buf) |
| 24 | { |
| 25 | debug("%s: sector %lx, count %lx, buf %lx\n", |
| 26 | __func__, sector, count, (ulong)buf); |
| 27 | memcpy(buf, (void *)(CONFIG_SPL_LOAD_FIT_ADDRESS + sector), count); |
| 28 | return count; |
| 29 | } |
| 30 | |
| 31 | static int spl_ram_load_image(struct spl_image_info *spl_image, |
| 32 | struct spl_boot_device *bootdev) |
| 33 | { |
| 34 | struct image_header *header; |
| 35 | |
| 36 | header = (struct image_header *)CONFIG_SPL_LOAD_FIT_ADDRESS; |
| 37 | |
Marek Vasut | 4913261 | 2018-04-07 17:03:28 +0200 | [diff] [blame] | 38 | #if CONFIG_IS_ENABLED(DFU_SUPPORT) |
Stefan Agner | 22802f4 | 2016-12-23 07:51:53 +0100 | [diff] [blame] | 39 | if (bootdev->boot_device == BOOT_DEVICE_DFU) |
| 40 | spl_dfu_cmd(0, "dfu_alt_info_ram", "ram", "0"); |
| 41 | #endif |
| 42 | |
| 43 | if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) && |
| 44 | image_get_magic(header) == FDT_MAGIC) { |
| 45 | struct spl_load_info load; |
| 46 | |
| 47 | debug("Found FIT\n"); |
| 48 | load.bl_len = 1; |
| 49 | load.read = spl_ram_load_read; |
| 50 | spl_load_simple_fit(spl_image, &load, 0, header); |
| 51 | } else { |
Simon Glass | dfce179 | 2017-11-13 18:55:04 -0700 | [diff] [blame] | 52 | ulong u_boot_pos = binman_sym(ulong, u_boot_any, pos); |
| 53 | |
Stefan Agner | 22802f4 | 2016-12-23 07:51:53 +0100 | [diff] [blame] | 54 | debug("Legacy image\n"); |
| 55 | /* |
| 56 | * Get the header. It will point to an address defined by |
| 57 | * handoff which will tell where the image located inside |
Simon Glass | dfce179 | 2017-11-13 18:55:04 -0700 | [diff] [blame] | 58 | * the flash. |
Stefan Agner | 22802f4 | 2016-12-23 07:51:53 +0100 | [diff] [blame] | 59 | */ |
Simon Glass | dfce179 | 2017-11-13 18:55:04 -0700 | [diff] [blame] | 60 | debug("u_boot_pos = %lx\n", u_boot_pos); |
| 61 | if (u_boot_pos == BINMAN_SYM_MISSING) { |
| 62 | /* |
| 63 | * No binman support or no information. For now, fix it |
| 64 | * to the address pointed to by U-Boot. |
| 65 | */ |
| 66 | u_boot_pos = CONFIG_SYS_TEXT_BASE - |
| 67 | sizeof(struct image_header); |
| 68 | } |
| 69 | header = (struct image_header *)map_sysmem(u_boot_pos, 0); |
Stefan Agner | 22802f4 | 2016-12-23 07:51:53 +0100 | [diff] [blame] | 70 | |
| 71 | spl_parse_image_header(spl_image, header); |
| 72 | } |
| 73 | |
| 74 | return 0; |
| 75 | } |
Marek Vasut | 4913261 | 2018-04-07 17:03:28 +0200 | [diff] [blame] | 76 | #if CONFIG_IS_ENABLED(RAM_DEVICE) |
Stefan Agner | 22802f4 | 2016-12-23 07:51:53 +0100 | [diff] [blame] | 77 | SPL_LOAD_IMAGE_METHOD("RAM", 0, BOOT_DEVICE_RAM, spl_ram_load_image); |
| 78 | #endif |
Marek Vasut | 4913261 | 2018-04-07 17:03:28 +0200 | [diff] [blame] | 79 | #if CONFIG_IS_ENABLED(DFU_SUPPORT) |
Stefan Agner | 22802f4 | 2016-12-23 07:51:53 +0100 | [diff] [blame] | 80 | SPL_LOAD_IMAGE_METHOD("DFU", 0, BOOT_DEVICE_DFU, spl_ram_load_image); |
| 81 | #endif |
| 82 | |
| 83 | |