blob: bac11f64f13c21e037470503c88798c2b3b3abc0 [file] [log] [blame]
Dan Murphyfff40a72014-02-03 06:59:01 -06001/*
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>
Tom Rinifc89b2e2015-01-05 21:14:04 -050016#include <scsi.h>
Nikita Kiryanov36afd452015-11-08 17:11:49 +020017#include <errno.h>
Dan Murphyfff40a72014-02-03 06:59:01 -060018#include <fat.h>
Dan Murphyfff40a72014-02-03 06:59:01 -060019#include <image.h>
20
21DECLARE_GLOBAL_DATA_PTR;
22
Simon Glass2a2ee2a2016-09-24 18:20:13 -060023static int spl_sata_load_image(struct spl_image_info *spl_image,
24 struct spl_boot_device *bootdev)
Dan Murphyfff40a72014-02-03 06:59:01 -060025{
26 int err;
Simon Glass4101f682016-02-29 15:25:34 -070027 struct blk_desc *stor_dev;
Dan Murphyfff40a72014-02-03 06:59:01 -060028
29 err = init_sata(CONFIG_SPL_SATA_BOOT_DEVICE);
30 if (err) {
31#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
32 printf("spl: sata init failed: err - %d\n", err);
33#endif
Nikita Kiryanov36afd452015-11-08 17:11:49 +020034 return err;
Dan Murphyfff40a72014-02-03 06:59:01 -060035 } else {
36 /* try to recognize storage devices immediately */
Simon Glass8eab1a52017-06-14 21:28:41 -060037 scsi_scan(false);
Simon Glassedd82ab2016-05-01 11:36:16 -060038 stor_dev = blk_get_devnum_by_type(IF_TYPE_SCSI, 0);
Nikita Kiryanov36afd452015-11-08 17:11:49 +020039 if (!stor_dev)
40 return -ENODEV;
Dan Murphyfff40a72014-02-03 06:59:01 -060041 }
42
43#ifdef CONFIG_SPL_OS_BOOT
Simon Glass710e9ca2016-09-24 18:20:15 -060044 if (spl_start_uboot() ||
45 spl_load_image_fat_os(spl_image, stor_dev,
46 CONFIG_SYS_SATA_FAT_BOOT_PARTITION))
Dan Murphyfff40a72014-02-03 06:59:01 -060047#endif
Simon Glass710e9ca2016-09-24 18:20:15 -060048 {
49 err = spl_load_image_fat(spl_image, stor_dev,
50 CONFIG_SYS_SATA_FAT_BOOT_PARTITION,
Guillaume GARDET205b4f32014-10-15 17:53:11 +020051 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME);
Simon Glass710e9ca2016-09-24 18:20:15 -060052 }
Dan Murphyfff40a72014-02-03 06:59:01 -060053 if (err) {
54 puts("Error loading sata device\n");
Nikita Kiryanov36afd452015-11-08 17:11:49 +020055 return err;
Dan Murphyfff40a72014-02-03 06:59:01 -060056 }
Nikita Kiryanov36afd452015-11-08 17:11:49 +020057
58 return 0;
Dan Murphyfff40a72014-02-03 06:59:01 -060059}
Simon Glassebc4ef62016-11-30 15:30:50 -070060SPL_LOAD_IMAGE_METHOD("SATA", 0, BOOT_DEVICE_SATA, spl_sata_load_image);