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 blk_desc *stor_dev, unsigned long sector)
36 struct image_header *header;
38 u32 image_size_sectors;
41 header = spl_get_load_buffer(-sizeof(*header), stor_dev->blksz);
42 count = blk_dread(stor_dev, sector, 1, header);
46 ret = spl_parse_image_header(spl_image, header);
50 image_size_sectors = DIV_ROUND_UP(spl_image->size, stor_dev->blksz);
51 count = blk_dread(stor_dev, sector, image_size_sectors,
52 (void *)spl_image->load_addr);
53 if (count != image_size_sectors)
59 static int spl_sata_load_image(struct spl_image_info *spl_image,
60 struct spl_boot_device *bootdev)
63 struct blk_desc *stor_dev;
65 #if !defined(CONFIG_DM_SCSI) && !defined(CONFIG_AHCI)
66 err = init_sata(CONFIG_SPL_SATA_BOOT_DEVICE);
69 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
70 printf("spl: sata init failed: err - %d\n", err);
74 /* try to recognize storage devices immediately */
76 stor_dev = blk_get_devnum_by_type(IF_TYPE_SCSI, 0);
81 #ifdef CONFIG_SPL_OS_BOOT
82 if (spl_start_uboot() ||
83 spl_load_image_fat_os(spl_image, stor_dev,
84 CONFIG_SYS_SATA_FAT_BOOT_PARTITION))
89 if (IS_ENABLED(CONFIG_SPL_FS_FAT)) {
90 err = spl_load_image_fat(spl_image, stor_dev,
91 CONFIG_SYS_SATA_FAT_BOOT_PARTITION,
92 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME);
93 } else if (IS_ENABLED(CONFIG_SPL_SATA_RAW_U_BOOT_USE_SECTOR)) {
94 err = spl_sata_load_image_raw(spl_image, stor_dev,
95 CONFIG_SPL_SATA_RAW_U_BOOT_SECTOR);
99 puts("Error loading sata device\n");
105 SPL_LOAD_IMAGE_METHOD("SATA", 0, BOOT_DEVICE_SATA, spl_sata_load_image);