blob: 3ba4c249b7dbea18c4a4f417fb65fa53c8e24c53 [file] [log] [blame]
Dan Murphy0c3ab852014-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 Rinieac5b832015-01-05 21:14:04 -050016#include <scsi.h>
Nikita Kiryanov33eefe42015-11-08 17:11:49 +020017#include <errno.h>
Dan Murphy0c3ab852014-02-03 06:59:01 -060018#include <fat.h>
Dan Murphy0c3ab852014-02-03 06:59:01 -060019#include <image.h>
20
21DECLARE_GLOBAL_DATA_PTR;
22
Nikita Kiryanov33eefe42015-11-08 17:11:49 +020023int spl_sata_load_image(void)
Dan Murphy0c3ab852014-02-03 06:59:01 -060024{
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
Nikita Kiryanov33eefe42015-11-08 17:11:49 +020033 return err;
Dan Murphy0c3ab852014-02-03 06:59:01 -060034 } else {
35 /* try to recognize storage devices immediately */
Roger Quadros7a187f52014-09-23 18:07:04 +030036 scsi_scan(0);
Dan Murphy0c3ab852014-02-03 06:59:01 -060037 stor_dev = scsi_get_dev(0);
Nikita Kiryanov33eefe42015-11-08 17:11:49 +020038 if (!stor_dev)
39 return -ENODEV;
Dan Murphy0c3ab852014-02-03 06:59:01 -060040 }
41
42#ifdef CONFIG_SPL_OS_BOOT
43 if (spl_start_uboot() || spl_load_image_fat_os(stor_dev,
44 CONFIG_SYS_SATA_FAT_BOOT_PARTITION))
45#endif
46 err = spl_load_image_fat(stor_dev,
47 CONFIG_SYS_SATA_FAT_BOOT_PARTITION,
Guillaume GARDET602a16c2014-10-15 17:53:11 +020048 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME);
Dan Murphy0c3ab852014-02-03 06:59:01 -060049 if (err) {
50 puts("Error loading sata device\n");
Nikita Kiryanov33eefe42015-11-08 17:11:49 +020051 return err;
Dan Murphy0c3ab852014-02-03 06:59:01 -060052 }
Nikita Kiryanov33eefe42015-11-08 17:11:49 +020053
54 return 0;
Dan Murphy0c3ab852014-02-03 06:59:01 -060055}