Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Dan Murphy | fff40a7 | 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 | fff40a7 | 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 | fc89b2e | 2015-01-05 21:14:04 -0500 | [diff] [blame] | 15 | #include <scsi.h> |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 16 | #include <errno.h> |
Dan Murphy | fff40a7 | 2014-02-03 06:59:01 -0600 | [diff] [blame] | 17 | #include <fat.h> |
Dan Murphy | fff40a7 | 2014-02-03 06:59:01 -0600 | [diff] [blame] | 18 | #include <image.h> |
| 19 | |
Simon Glass | 2a2ee2a | 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 | fff40a7 | 2014-02-03 06:59:01 -0600 | [diff] [blame] | 22 | { |
| 23 | int err; |
Simon Glass | 4101f68 | 2016-02-29 15:25:34 -0700 | [diff] [blame] | 24 | struct blk_desc *stor_dev; |
Dan Murphy | fff40a7 | 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 | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 31 | return err; |
Dan Murphy | fff40a7 | 2014-02-03 06:59:01 -0600 | [diff] [blame] | 32 | } else { |
| 33 | /* try to recognize storage devices immediately */ |
Simon Glass | 8eab1a5 | 2017-06-14 21:28:41 -0600 | [diff] [blame] | 34 | scsi_scan(false); |
Simon Glass | edd82ab | 2016-05-01 11:36:16 -0600 | [diff] [blame] | 35 | stor_dev = blk_get_devnum_by_type(IF_TYPE_SCSI, 0); |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 36 | if (!stor_dev) |
| 37 | return -ENODEV; |
Dan Murphy | fff40a7 | 2014-02-03 06:59:01 -0600 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | #ifdef CONFIG_SPL_OS_BOOT |
Simon Glass | 710e9ca | 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 | fff40a7 | 2014-02-03 06:59:01 -0600 | [diff] [blame] | 44 | #endif |
Simon Glass | 710e9ca | 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 | 205b4f3 | 2014-10-15 17:53:11 +0200 | [diff] [blame] | 48 | CONFIG_SPL_FS_LOAD_PAYLOAD_NAME); |
Simon Glass | 710e9ca | 2016-09-24 18:20:15 -0600 | [diff] [blame] | 49 | } |
Dan Murphy | fff40a7 | 2014-02-03 06:59:01 -0600 | [diff] [blame] | 50 | if (err) { |
| 51 | puts("Error loading sata device\n"); |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 52 | return err; |
Dan Murphy | fff40a7 | 2014-02-03 06:59:01 -0600 | [diff] [blame] | 53 | } |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 54 | |
| 55 | return 0; |
Dan Murphy | fff40a7 | 2014-02-03 06:59:01 -0600 | [diff] [blame] | 56 | } |
Simon Glass | ebc4ef6 | 2016-11-30 15:30:50 -0700 | [diff] [blame] | 57 | SPL_LOAD_IMAGE_METHOD("SATA", 0, BOOT_DEVICE_SATA, spl_sata_load_image); |