xref: /openbmc/u-boot/common/spl/spl_sata.c (revision 949dbc12)
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 <fat.h>
18 #include <version.h>
19 #include <image.h>
20 
21 DECLARE_GLOBAL_DATA_PTR;
22 
23 void spl_sata_load_image(void)
24 {
25 	int err;
26 	block_dev_desc_t *stor_dev;
27 
28 	err = init_sata(CONFIG_SPL_SATA_BOOT_DEVICE);
29 	if (err) {
30 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
31 		printf("spl: sata init failed: err - %d\n", err);
32 #endif
33 		hang();
34 	} else {
35 		/* try to recognize storage devices immediately */
36 		scsi_scan(0);
37 		stor_dev = scsi_get_dev(0);
38 	}
39 
40 #ifdef CONFIG_SPL_OS_BOOT
41 	if (spl_start_uboot() || spl_load_image_fat_os(stor_dev,
42 									CONFIG_SYS_SATA_FAT_BOOT_PARTITION))
43 #endif
44 	err = spl_load_image_fat(stor_dev,
45 				CONFIG_SYS_SATA_FAT_BOOT_PARTITION,
46 				CONFIG_SPL_FS_LOAD_PAYLOAD_NAME);
47 	if (err) {
48 		puts("Error loading sata device\n");
49 		hang();
50 	}
51 }
52