1 // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
4 * Ladislav Michl <ladis@linux-mips.org>
10 #include <onenand_uboot.h>
14 int spl_ubi_load_image(struct spl_image_info *spl_image,
15 struct spl_boot_device *bootdev)
17 struct image_header *header;
18 struct ubispl_info info;
19 struct ubispl_load volumes[2];
22 switch (bootdev->boot_device) {
23 #ifdef CONFIG_SPL_NAND_SUPPORT
24 case BOOT_DEVICE_NAND:
26 info.read = nand_spl_read_block;
27 info.peb_size = CONFIG_SYS_NAND_BLOCK_SIZE;
30 #ifdef CONFIG_SPL_ONENAND_SUPPORT
31 case BOOT_DEVICE_ONENAND:
32 info.read = onenand_spl_read_block;
33 info.peb_size = CONFIG_SYS_ONENAND_BLOCK_SIZE;
39 info.ubi = (struct ubi_scan_info *)CONFIG_SPL_UBI_INFO_ADDR;
40 info.fastmap = IS_ENABLED(CONFIG_MTD_UBI_FASTMAP);
42 info.peb_offset = CONFIG_SPL_UBI_PEB_OFFSET;
43 info.vid_offset = CONFIG_SPL_UBI_VID_OFFSET;
44 info.leb_start = CONFIG_SPL_UBI_LEB_START;
45 info.peb_count = CONFIG_SPL_UBI_MAX_PEBS - info.peb_offset;
47 #ifdef CONFIG_SPL_OS_BOOT
48 if (!spl_start_uboot()) {
49 volumes[0].vol_id = CONFIG_SPL_UBI_LOAD_KERNEL_ID;
50 volumes[0].load_addr = (void *)CONFIG_SYS_LOAD_ADDR;
51 volumes[1].vol_id = CONFIG_SPL_UBI_LOAD_ARGS_ID;
52 volumes[1].load_addr = (void *)CONFIG_SYS_SPL_ARGS_ADDR;
54 ret = ubispl_load_volumes(&info, volumes, 2);
56 header = (struct image_header *)volumes[0].load_addr;
57 spl_parse_image_header(spl_image, header);
58 puts("Linux loaded.\n");
61 puts("Loading Linux failed, falling back to U-Boot.\n");
64 header = spl_get_load_buffer(-sizeof(*header), sizeof(header));
65 volumes[0].vol_id = CONFIG_SPL_UBI_LOAD_MONITOR_ID;
66 volumes[0].load_addr = (void *)header;
68 ret = ubispl_load_volumes(&info, volumes, 1);
70 spl_parse_image_header(spl_image, header);
72 #ifdef CONFIG_SPL_NAND_SUPPORT
73 if (bootdev->boot_device == BOOT_DEVICE_NAND)
78 /* Use priorty 0 so that Ubi will override NAND and ONENAND methods */
79 SPL_LOAD_IMAGE_METHOD("NAND", 0, BOOT_DEVICE_NAND, spl_ubi_load_image);
80 SPL_LOAD_IMAGE_METHOD("OneNAND", 0, BOOT_DEVICE_ONENAND, spl_ubi_load_image);