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 static int spl_sata_load_image_raw(struct spl_image_info
*spl_image
,
21 struct spl_boot_device
*bootdev
,
22 struct blk_desc
*stor_dev
, unsigned long sector
)
24 struct legacy_img_hdr
*header
;
26 u32 image_size_sectors
;
27 u32 image_offset_sectors
;
31 header
= spl_get_load_buffer(-sizeof(*header
), stor_dev
->blksz
);
32 count
= blk_dread(stor_dev
, sector
, 1, header
);
36 ret
= spl_parse_image_header(spl_image
, bootdev
, header
);
40 image_size_sectors
= DIV_ROUND_UP(spl_image
->size
, stor_dev
->blksz
);
41 image_offset_sectors
= spl_image
->offset
/ stor_dev
->blksz
;
42 image_offset
= spl_image
->offset
% stor_dev
->blksz
;
43 count
= blk_dread(stor_dev
, sector
+ image_offset_sectors
,
45 (void *)spl_image
->load_addr
);
46 if (count
!= image_size_sectors
)
50 memmove((void *)spl_image
->load_addr
,
51 (void *)spl_image
->load_addr
+ image_offset
,
57 static int spl_sata_load_image(struct spl_image_info
*spl_image
,
58 struct spl_boot_device
*bootdev
)
61 struct blk_desc
*stor_dev
;
63 /* try to recognize storage devices immediately */
65 stor_dev
= blk_get_devnum_by_uclass_id(UCLASS_SCSI
, 0);
69 #if CONFIG_IS_ENABLED(OS_BOOT)
70 if (spl_start_uboot() ||
71 spl_load_image_fat_os(spl_image
, bootdev
, stor_dev
,
72 CONFIG_SYS_SATA_FAT_BOOT_PARTITION
))
75 #ifdef CONFIG_SPL_FS_FAT
76 err
= spl_load_image_fat(spl_image
, bootdev
, stor_dev
,
77 CONFIG_SYS_SATA_FAT_BOOT_PARTITION
,
78 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME
);
79 #elif defined(CONFIG_SPL_SATA_RAW_U_BOOT_USE_SECTOR)
80 err
= spl_sata_load_image_raw(spl_image
, bootdev
, stor_dev
,
81 CONFIG_SPL_SATA_RAW_U_BOOT_SECTOR
);
85 puts("Error loading sata device\n");
91 SPL_LOAD_IMAGE_METHOD("SATA", 0, BOOT_DEVICE_SATA
, spl_sata_load_image
);