xref: /openbmc/u-boot/common/spl/spl_sata.c (revision cd71b1d5)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2013
4  * Texas Instruments, <www.ti.com>
5  *
6  * Dan Murphy <dmurphy@ti.com>
7  *
8  * Derived work from spl_usb.c
9  */
10 
11 #include <common.h>
12 #include <spl.h>
13 #include <asm/u-boot.h>
14 #include <sata.h>
15 #include <scsi.h>
16 #include <errno.h>
17 #include <fat.h>
18 #include <image.h>
19 
20 static int spl_sata_load_image(struct spl_image_info *spl_image,
21 			       struct spl_boot_device *bootdev)
22 {
23 	int err;
24 	struct blk_desc *stor_dev;
25 
26 	err = init_sata(CONFIG_SPL_SATA_BOOT_DEVICE);
27 	if (err) {
28 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
29 		printf("spl: sata init failed: err - %d\n", err);
30 #endif
31 		return err;
32 	} else {
33 		/* try to recognize storage devices immediately */
34 		scsi_scan(false);
35 		stor_dev = blk_get_devnum_by_type(IF_TYPE_SCSI, 0);
36 		if (!stor_dev)
37 			return -ENODEV;
38 	}
39 
40 #ifdef CONFIG_SPL_OS_BOOT
41 	if (spl_start_uboot() ||
42 	    spl_load_image_fat_os(spl_image, stor_dev,
43 				  CONFIG_SYS_SATA_FAT_BOOT_PARTITION))
44 #endif
45 	{
46 		err = spl_load_image_fat(spl_image, stor_dev,
47 					CONFIG_SYS_SATA_FAT_BOOT_PARTITION,
48 				CONFIG_SPL_FS_LOAD_PAYLOAD_NAME);
49 	}
50 	if (err) {
51 		puts("Error loading sata device\n");
52 		return err;
53 	}
54 
55 	return 0;
56 }
57 SPL_LOAD_IMAGE_METHOD("SATA", 0, BOOT_DEVICE_SATA, spl_sata_load_image);
58