]> git.ipfire.org Git - people/ms/u-boot.git/blame - common/spl/spl_sata.c
Prepare for multiple bootcount drivers
[people/ms/u-boot.git] / common / spl / spl_sata.c
CommitLineData
fff40a7e
DM
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>
fc89b2e4 16#include <scsi.h>
36afd451 17#include <errno.h>
fff40a7e 18#include <fat.h>
fff40a7e
DM
19#include <image.h>
20
21DECLARE_GLOBAL_DATA_PTR;
22
2a2ee2ac
SG
23static int spl_sata_load_image(struct spl_image_info *spl_image,
24 struct spl_boot_device *bootdev)
fff40a7e
DM
25{
26 int err;
4101f687 27 struct blk_desc *stor_dev;
fff40a7e
DM
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
36afd451 34 return err;
fff40a7e
DM
35 } else {
36 /* try to recognize storage devices immediately */
8eab1a58 37 scsi_scan(false);
edd82ab3 38 stor_dev = blk_get_devnum_by_type(IF_TYPE_SCSI, 0);
36afd451
NK
39 if (!stor_dev)
40 return -ENODEV;
fff40a7e
DM
41 }
42
43#ifdef CONFIG_SPL_OS_BOOT
710e9ca5
SG
44 if (spl_start_uboot() ||
45 spl_load_image_fat_os(spl_image, stor_dev,
46 CONFIG_SYS_SATA_FAT_BOOT_PARTITION))
fff40a7e 47#endif
710e9ca5
SG
48 {
49 err = spl_load_image_fat(spl_image, stor_dev,
50 CONFIG_SYS_SATA_FAT_BOOT_PARTITION,
205b4f33 51 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME);
710e9ca5 52 }
fff40a7e
DM
53 if (err) {
54 puts("Error loading sata device\n");
36afd451 55 return err;
fff40a7e 56 }
36afd451
NK
57
58 return 0;
fff40a7e 59}
ebc4ef61 60SPL_LOAD_IMAGE_METHOD("SATA", 0, BOOT_DEVICE_SATA, spl_sata_load_image);