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