blob: b08efc8419034188ad8c799e9df15c914dd30246 [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
Baruch Siacha4c61ff2019-05-16 13:03:53 +030020#ifndef CONFIG_SYS_SATA_FAT_BOOT_PARTITION
21#define CONFIG_SYS_SATA_FAT_BOOT_PARTITION 1
22#endif
23
24#ifndef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME
25#define CONFIG_SPL_FS_LOAD_PAYLOAD_NAME "u-boot.img"
26#endif
27
Simon Glass2a2ee2a2016-09-24 18:20:13 -060028static int spl_sata_load_image(struct spl_image_info *spl_image,
29 struct spl_boot_device *bootdev)
Dan Murphyfff40a72014-02-03 06:59:01 -060030{
31 int err;
Simon Glass4101f682016-02-29 15:25:34 -070032 struct blk_desc *stor_dev;
Dan Murphyfff40a72014-02-03 06:59:01 -060033
34 err = init_sata(CONFIG_SPL_SATA_BOOT_DEVICE);
35 if (err) {
36#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
37 printf("spl: sata init failed: err - %d\n", err);
38#endif
Nikita Kiryanov36afd452015-11-08 17:11:49 +020039 return err;
Dan Murphyfff40a72014-02-03 06:59:01 -060040 } else {
41 /* try to recognize storage devices immediately */
Simon Glass8eab1a52017-06-14 21:28:41 -060042 scsi_scan(false);
Simon Glassedd82ab2016-05-01 11:36:16 -060043 stor_dev = blk_get_devnum_by_type(IF_TYPE_SCSI, 0);
Nikita Kiryanov36afd452015-11-08 17:11:49 +020044 if (!stor_dev)
45 return -ENODEV;
Dan Murphyfff40a72014-02-03 06:59:01 -060046 }
47
48#ifdef CONFIG_SPL_OS_BOOT
Simon Glass710e9ca2016-09-24 18:20:15 -060049 if (spl_start_uboot() ||
50 spl_load_image_fat_os(spl_image, stor_dev,
51 CONFIG_SYS_SATA_FAT_BOOT_PARTITION))
Dan Murphyfff40a72014-02-03 06:59:01 -060052#endif
Simon Glass710e9ca2016-09-24 18:20:15 -060053 {
54 err = spl_load_image_fat(spl_image, stor_dev,
55 CONFIG_SYS_SATA_FAT_BOOT_PARTITION,
Guillaume GARDET205b4f32014-10-15 17:53:11 +020056 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME);
Simon Glass710e9ca2016-09-24 18:20:15 -060057 }
Dan Murphyfff40a72014-02-03 06:59:01 -060058 if (err) {
59 puts("Error loading sata device\n");
Nikita Kiryanov36afd452015-11-08 17:11:49 +020060 return err;
Dan Murphyfff40a72014-02-03 06:59:01 -060061 }
Nikita Kiryanov36afd452015-11-08 17:11:49 +020062
63 return 0;
Dan Murphyfff40a72014-02-03 06:59:01 -060064}
Simon Glassebc4ef62016-11-30 15:30:50 -070065SPL_LOAD_IMAGE_METHOD("SATA", 0, BOOT_DEVICE_SATA, spl_sata_load_image);