blob: adfce1d527f60aec8546da69f9b204eb1b2290d2 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Dan Murphy0c3ab852014-02-03 06:59:01 -06002/*
3 * (C) Copyright 2013
4 * Texas Instruments, <www.ti.com>
5 *
6 * Dan Murphy <dmurphy@ti.com>
7 *
Dan Murphy0c3ab852014-02-03 06:59:01 -06008 * 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>
Tom Rinieac5b832015-01-05 21:14:04 -050015#include <scsi.h>
Nikita Kiryanov33eefe42015-11-08 17:11:49 +020016#include <errno.h>
Dan Murphy0c3ab852014-02-03 06:59:01 -060017#include <fat.h>
Dan Murphy0c3ab852014-02-03 06:59:01 -060018#include <image.h>
19
Simon Glassee306792016-09-24 18:20:13 -060020static int spl_sata_load_image(struct spl_image_info *spl_image,
21 struct spl_boot_device *bootdev)
Dan Murphy0c3ab852014-02-03 06:59:01 -060022{
23 int err;
Simon Glasse3394752016-02-29 15:25:34 -070024 struct blk_desc *stor_dev;
Dan Murphy0c3ab852014-02-03 06:59:01 -060025
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
Nikita Kiryanov33eefe42015-11-08 17:11:49 +020031 return err;
Dan Murphy0c3ab852014-02-03 06:59:01 -060032 } else {
33 /* try to recognize storage devices immediately */
Simon Glass48228732017-06-14 21:28:41 -060034 scsi_scan(false);
Simon Glass9a684322016-05-01 11:36:16 -060035 stor_dev = blk_get_devnum_by_type(IF_TYPE_SCSI, 0);
Nikita Kiryanov33eefe42015-11-08 17:11:49 +020036 if (!stor_dev)
37 return -ENODEV;
Dan Murphy0c3ab852014-02-03 06:59:01 -060038 }
39
40#ifdef CONFIG_SPL_OS_BOOT
Simon Glass3eb382a2016-09-24 18:20:15 -060041 if (spl_start_uboot() ||
42 spl_load_image_fat_os(spl_image, stor_dev,
43 CONFIG_SYS_SATA_FAT_BOOT_PARTITION))
Dan Murphy0c3ab852014-02-03 06:59:01 -060044#endif
Simon Glass3eb382a2016-09-24 18:20:15 -060045 {
46 err = spl_load_image_fat(spl_image, stor_dev,
47 CONFIG_SYS_SATA_FAT_BOOT_PARTITION,
Guillaume GARDET602a16c2014-10-15 17:53:11 +020048 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME);
Simon Glass3eb382a2016-09-24 18:20:15 -060049 }
Dan Murphy0c3ab852014-02-03 06:59:01 -060050 if (err) {
51 puts("Error loading sata device\n");
Nikita Kiryanov33eefe42015-11-08 17:11:49 +020052 return err;
Dan Murphy0c3ab852014-02-03 06:59:01 -060053 }
Nikita Kiryanov33eefe42015-11-08 17:11:49 +020054
55 return 0;
Dan Murphy0c3ab852014-02-03 06:59:01 -060056}
Simon Glass4fc1f252016-11-30 15:30:50 -070057SPL_LOAD_IMAGE_METHOD("SATA", 0, BOOT_DEVICE_SATA, spl_sata_load_image);