1 // SPDX-License-Identifier: GPL-2.0+
4 * Texas Instruments, <www.ti.com>
6 * Dan Murphy <dmurphy@ti.com>
8 * Derived work from spl_usb.c
13 #include <asm/u-boot.h>
20 #ifndef CONFIG_SYS_SATA_FAT_BOOT_PARTITION
21 #define CONFIG_SYS_SATA_FAT_BOOT_PARTITION 1
24 #ifndef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME
25 #define CONFIG_SPL_FS_LOAD_PAYLOAD_NAME "u-boot.img"
28 #ifndef CONFIG_SPL_SATA_RAW_U_BOOT_SECTOR
29 /* Dummy value to make the compiler happy */
30 #define CONFIG_SPL_SATA_RAW_U_BOOT_SECTOR 0x100
33 static int spl_sata_load_image_raw(struct spl_image_info *spl_image,
34 struct spl_boot_device *bootdev,
35 struct blk_desc *stor_dev, unsigned long sector)
37 struct image_header *header;
39 u32 image_size_sectors;
40 u32 image_offset_sectors;
44 header = spl_get_load_buffer(-sizeof(*header), stor_dev->blksz);
45 count = blk_dread(stor_dev, sector, 1, header);
49 ret = spl_parse_image_header(spl_image, bootdev, header);
53 image_size_sectors = DIV_ROUND_UP(spl_image->size, stor_dev->blksz);
54 image_offset_sectors = spl_image->offset / stor_dev->blksz;
55 image_offset = spl_image->offset % stor_dev->blksz;
56 count = blk_dread(stor_dev, sector + image_offset_sectors,
58 (void *)spl_image->load_addr);
59 if (count != image_size_sectors)
63 memmove((void *)spl_image->load_addr,
64 (void *)spl_image->load_addr + image_offset,
70 static int spl_sata_load_image(struct spl_image_info *spl_image,
71 struct spl_boot_device *bootdev)
74 struct blk_desc *stor_dev;
76 /* try to recognize storage devices immediately */
78 stor_dev = blk_get_devnum_by_type(IF_TYPE_SCSI, 0);
82 #if CONFIG_IS_ENABLED(OS_BOOT)
83 if (spl_start_uboot() ||
84 spl_load_image_fat_os(spl_image, bootdev, stor_dev,
85 CONFIG_SYS_SATA_FAT_BOOT_PARTITION))
90 if (IS_ENABLED(CONFIG_SPL_FS_FAT)) {
91 err = spl_load_image_fat(spl_image, bootdev, stor_dev,
92 CONFIG_SYS_SATA_FAT_BOOT_PARTITION,
93 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME);
94 } else if (IS_ENABLED(CONFIG_SPL_SATA_RAW_U_BOOT_USE_SECTOR)) {
95 err = spl_sata_load_image_raw(spl_image, bootdev, stor_dev,
96 CONFIG_SPL_SATA_RAW_U_BOOT_SECTOR);
100 puts("Error loading sata device\n");
106 SPL_LOAD_IMAGE_METHOD("SATA", 0, BOOT_DEVICE_SATA, spl_sata_load_image);