Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Dan Murphy | 0c3ab85 | 2014-02-03 06:59:01 -0600 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2013 |
| 4 | * Texas Instruments, <www.ti.com> |
| 5 | * |
| 6 | * Dan Murphy <dmurphy@ti.com> |
| 7 | * |
Dan Murphy | 0c3ab85 | 2014-02-03 06:59:01 -0600 | [diff] [blame] | 8 | * 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 Rini | eac5b83 | 2015-01-05 21:14:04 -0500 | [diff] [blame] | 15 | #include <scsi.h> |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 16 | #include <errno.h> |
Dan Murphy | 0c3ab85 | 2014-02-03 06:59:01 -0600 | [diff] [blame] | 17 | #include <fat.h> |
Dan Murphy | 0c3ab85 | 2014-02-03 06:59:01 -0600 | [diff] [blame] | 18 | #include <image.h> |
| 19 | |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 20 | static int spl_sata_load_image(struct spl_image_info *spl_image, |
| 21 | struct spl_boot_device *bootdev) |
Dan Murphy | 0c3ab85 | 2014-02-03 06:59:01 -0600 | [diff] [blame] | 22 | { |
| 23 | int err; |
Simon Glass | e339475 | 2016-02-29 15:25:34 -0700 | [diff] [blame] | 24 | struct blk_desc *stor_dev; |
Dan Murphy | 0c3ab85 | 2014-02-03 06:59:01 -0600 | [diff] [blame] | 25 | |
| 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 Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 31 | return err; |
Dan Murphy | 0c3ab85 | 2014-02-03 06:59:01 -0600 | [diff] [blame] | 32 | } else { |
| 33 | /* try to recognize storage devices immediately */ |
Simon Glass | 4822873 | 2017-06-14 21:28:41 -0600 | [diff] [blame] | 34 | scsi_scan(false); |
Simon Glass | 9a68432 | 2016-05-01 11:36:16 -0600 | [diff] [blame] | 35 | stor_dev = blk_get_devnum_by_type(IF_TYPE_SCSI, 0); |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 36 | if (!stor_dev) |
| 37 | return -ENODEV; |
Dan Murphy | 0c3ab85 | 2014-02-03 06:59:01 -0600 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | #ifdef CONFIG_SPL_OS_BOOT |
Simon Glass | 3eb382a | 2016-09-24 18:20:15 -0600 | [diff] [blame] | 41 | if (spl_start_uboot() || |
| 42 | spl_load_image_fat_os(spl_image, stor_dev, |
| 43 | CONFIG_SYS_SATA_FAT_BOOT_PARTITION)) |
Dan Murphy | 0c3ab85 | 2014-02-03 06:59:01 -0600 | [diff] [blame] | 44 | #endif |
Simon Glass | 3eb382a | 2016-09-24 18:20:15 -0600 | [diff] [blame] | 45 | { |
| 46 | err = spl_load_image_fat(spl_image, stor_dev, |
| 47 | CONFIG_SYS_SATA_FAT_BOOT_PARTITION, |
Guillaume GARDET | 602a16c | 2014-10-15 17:53:11 +0200 | [diff] [blame] | 48 | CONFIG_SPL_FS_LOAD_PAYLOAD_NAME); |
Simon Glass | 3eb382a | 2016-09-24 18:20:15 -0600 | [diff] [blame] | 49 | } |
Dan Murphy | 0c3ab85 | 2014-02-03 06:59:01 -0600 | [diff] [blame] | 50 | if (err) { |
| 51 | puts("Error loading sata device\n"); |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 52 | return err; |
Dan Murphy | 0c3ab85 | 2014-02-03 06:59:01 -0600 | [diff] [blame] | 53 | } |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 54 | |
| 55 | return 0; |
Dan Murphy | 0c3ab85 | 2014-02-03 06:59:01 -0600 | [diff] [blame] | 56 | } |
Simon Glass | 4fc1f25 | 2016-11-30 15:30:50 -0700 | [diff] [blame] | 57 | SPL_LOAD_IMAGE_METHOD("SATA", 0, BOOT_DEVICE_SATA, spl_sata_load_image); |