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 | |
Baruch Siach | a4c61ff | 2019-05-16 13:03:53 +0300 | [diff] [blame^] | 20 | #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 Glass | 2a2ee2a | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 28 | static int spl_sata_load_image(struct spl_image_info *spl_image, |
| 29 | struct spl_boot_device *bootdev) |
Dan Murphy | fff40a7 | 2014-02-03 06:59:01 -0600 | [diff] [blame] | 30 | { |
| 31 | int err; |
Simon Glass | 4101f68 | 2016-02-29 15:25:34 -0700 | [diff] [blame] | 32 | struct blk_desc *stor_dev; |
Dan Murphy | fff40a7 | 2014-02-03 06:59:01 -0600 | [diff] [blame] | 33 | |
| 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 Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 39 | return err; |
Dan Murphy | fff40a7 | 2014-02-03 06:59:01 -0600 | [diff] [blame] | 40 | } else { |
| 41 | /* try to recognize storage devices immediately */ |
Simon Glass | 8eab1a5 | 2017-06-14 21:28:41 -0600 | [diff] [blame] | 42 | scsi_scan(false); |
Simon Glass | edd82ab | 2016-05-01 11:36:16 -0600 | [diff] [blame] | 43 | stor_dev = blk_get_devnum_by_type(IF_TYPE_SCSI, 0); |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 44 | if (!stor_dev) |
| 45 | return -ENODEV; |
Dan Murphy | fff40a7 | 2014-02-03 06:59:01 -0600 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | #ifdef CONFIG_SPL_OS_BOOT |
Simon Glass | 710e9ca | 2016-09-24 18:20:15 -0600 | [diff] [blame] | 49 | if (spl_start_uboot() || |
| 50 | spl_load_image_fat_os(spl_image, stor_dev, |
| 51 | CONFIG_SYS_SATA_FAT_BOOT_PARTITION)) |
Dan Murphy | fff40a7 | 2014-02-03 06:59:01 -0600 | [diff] [blame] | 52 | #endif |
Simon Glass | 710e9ca | 2016-09-24 18:20:15 -0600 | [diff] [blame] | 53 | { |
| 54 | err = spl_load_image_fat(spl_image, stor_dev, |
| 55 | CONFIG_SYS_SATA_FAT_BOOT_PARTITION, |
Guillaume GARDET | 205b4f3 | 2014-10-15 17:53:11 +0200 | [diff] [blame] | 56 | CONFIG_SPL_FS_LOAD_PAYLOAD_NAME); |
Simon Glass | 710e9ca | 2016-09-24 18:20:15 -0600 | [diff] [blame] | 57 | } |
Dan Murphy | fff40a7 | 2014-02-03 06:59:01 -0600 | [diff] [blame] | 58 | if (err) { |
| 59 | puts("Error loading sata device\n"); |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 60 | return err; |
Dan Murphy | fff40a7 | 2014-02-03 06:59:01 -0600 | [diff] [blame] | 61 | } |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 62 | |
| 63 | return 0; |
Dan Murphy | fff40a7 | 2014-02-03 06:59:01 -0600 | [diff] [blame] | 64 | } |
Simon Glass | ebc4ef6 | 2016-11-30 15:30:50 -0700 | [diff] [blame] | 65 | SPL_LOAD_IMAGE_METHOD("SATA", 0, BOOT_DEVICE_SATA, spl_sata_load_image); |