blob: adfce1d527f60aec8546da69f9b204eb1b2290d2 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Dan Murphyfff40a72014-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 Murphyfff40a72014-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 Rinifc89b2e2015-01-05 21:14:04 -050015#include <scsi.h>
Nikita Kiryanov36afd452015-11-08 17:11:49 +020016#include <errno.h>
Dan Murphyfff40a72014-02-03 06:59:01 -060017#include <fat.h>
Dan Murphyfff40a72014-02-03 06:59:01 -060018#include <image.h>
19
Simon Glass2a2ee2a2016-09-24 18:20:13 -060020static int spl_sata_load_image(struct spl_image_info *spl_image,
21 struct spl_boot_device *bootdev)
Dan Murphyfff40a72014-02-03 06:59:01 -060022{
23 int err;
Simon Glass4101f682016-02-29 15:25:34 -070024 struct blk_desc *stor_dev;
Dan Murphyfff40a72014-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 Kiryanov36afd452015-11-08 17:11:49 +020031 return err;
Dan Murphyfff40a72014-02-03 06:59:01 -060032 } else {
33 /* try to recognize storage devices immediately */
Simon Glass8eab1a52017-06-14 21:28:41 -060034 scsi_scan(false);
Simon Glassedd82ab2016-05-01 11:36:16 -060035 stor_dev = blk_get_devnum_by_type(IF_TYPE_SCSI, 0);
Nikita Kiryanov36afd452015-11-08 17:11:49 +020036 if (!stor_dev)
37 return -ENODEV;
Dan Murphyfff40a72014-02-03 06:59:01 -060038 }
39
40#ifdef CONFIG_SPL_OS_BOOT
Simon Glass710e9ca2016-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 Murphyfff40a72014-02-03 06:59:01 -060044#endif
Simon Glass710e9ca2016-09-24 18:20:15 -060045 {
46 err = spl_load_image_fat(spl_image, stor_dev,
47 CONFIG_SYS_SATA_FAT_BOOT_PARTITION,
Guillaume GARDET205b4f32014-10-15 17:53:11 +020048 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME);
Simon Glass710e9ca2016-09-24 18:20:15 -060049 }
Dan Murphyfff40a72014-02-03 06:59:01 -060050 if (err) {
51 puts("Error loading sata device\n");
Nikita Kiryanov36afd452015-11-08 17:11:49 +020052 return err;
Dan Murphyfff40a72014-02-03 06:59:01 -060053 }
Nikita Kiryanov36afd452015-11-08 17:11:49 +020054
55 return 0;
Dan Murphyfff40a72014-02-03 06:59:01 -060056}
Simon Glassebc4ef62016-11-30 15:30:50 -070057SPL_LOAD_IMAGE_METHOD("SATA", 0, BOOT_DEVICE_SATA, spl_sata_load_image);