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