2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2014-02-03 12:59:01 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2013
|
|
|
|
* Texas Instruments, <www.ti.com>
|
|
|
|
*
|
|
|
|
* Dan Murphy <dmurphy@ti.com>
|
|
|
|
*
|
|
|
|
* Derived work from spl_usb.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <spl.h>
|
|
|
|
#include <asm/u-boot.h>
|
|
|
|
#include <sata.h>
|
2015-01-06 02:14:04 +00:00
|
|
|
#include <scsi.h>
|
2015-11-08 15:11:49 +00:00
|
|
|
#include <errno.h>
|
2014-02-03 12:59:01 +00:00
|
|
|
#include <fat.h>
|
|
|
|
#include <image.h>
|
|
|
|
|
2019-07-14 14:54:21 +00:00
|
|
|
static int spl_sata_load_image_raw(struct spl_image_info *spl_image,
|
2022-01-14 13:31:38 +00:00
|
|
|
struct spl_boot_device *bootdev,
|
2019-07-14 14:54:21 +00:00
|
|
|
struct blk_desc *stor_dev, unsigned long sector)
|
|
|
|
{
|
2022-09-07 02:26:52 +00:00
|
|
|
struct legacy_img_hdr *header;
|
2019-07-14 14:54:21 +00:00
|
|
|
unsigned long count;
|
|
|
|
u32 image_size_sectors;
|
2021-07-23 09:14:27 +00:00
|
|
|
u32 image_offset_sectors;
|
|
|
|
u32 image_offset;
|
2019-07-14 14:54:21 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
header = spl_get_load_buffer(-sizeof(*header), stor_dev->blksz);
|
|
|
|
count = blk_dread(stor_dev, sector, 1, header);
|
|
|
|
if (count == 0)
|
|
|
|
return -EIO;
|
|
|
|
|
2022-01-14 13:31:38 +00:00
|
|
|
ret = spl_parse_image_header(spl_image, bootdev, header);
|
2019-07-14 14:54:21 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
image_size_sectors = DIV_ROUND_UP(spl_image->size, stor_dev->blksz);
|
2021-07-23 09:14:27 +00:00
|
|
|
image_offset_sectors = spl_image->offset / stor_dev->blksz;
|
|
|
|
image_offset = spl_image->offset % stor_dev->blksz;
|
|
|
|
count = blk_dread(stor_dev, sector + image_offset_sectors,
|
|
|
|
image_size_sectors,
|
2019-07-14 14:54:21 +00:00
|
|
|
(void *)spl_image->load_addr);
|
|
|
|
if (count != image_size_sectors)
|
|
|
|
return -EIO;
|
|
|
|
|
2021-07-23 09:14:27 +00:00
|
|
|
if (image_offset)
|
|
|
|
memmove((void *)spl_image->load_addr,
|
|
|
|
(void *)spl_image->load_addr + image_offset,
|
|
|
|
spl_image->size);
|
|
|
|
|
2019-07-14 14:54:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-09-25 00:20:13 +00:00
|
|
|
static int spl_sata_load_image(struct spl_image_info *spl_image,
|
|
|
|
struct spl_boot_device *bootdev)
|
2014-02-03 12:59:01 +00:00
|
|
|
{
|
2023-01-10 16:19:35 +00:00
|
|
|
int err = -ENOSYS;
|
2016-02-29 22:25:34 +00:00
|
|
|
struct blk_desc *stor_dev;
|
2014-02-03 12:59:01 +00:00
|
|
|
|
2022-05-13 17:37:30 +00:00
|
|
|
/* try to recognize storage devices immediately */
|
|
|
|
scsi_scan(false);
|
2022-09-17 15:00:09 +00:00
|
|
|
stor_dev = blk_get_devnum_by_uclass_id(UCLASS_SCSI, 0);
|
2022-05-13 17:37:30 +00:00
|
|
|
if (!stor_dev)
|
|
|
|
return -ENODEV;
|
2014-02-03 12:59:01 +00:00
|
|
|
|
2021-10-31 03:03:48 +00:00
|
|
|
#if CONFIG_IS_ENABLED(OS_BOOT)
|
2016-09-25 00:20:15 +00:00
|
|
|
if (spl_start_uboot() ||
|
2022-01-14 13:31:38 +00:00
|
|
|
spl_load_image_fat_os(spl_image, bootdev, stor_dev,
|
2016-09-25 00:20:15 +00:00
|
|
|
CONFIG_SYS_SATA_FAT_BOOT_PARTITION))
|
2014-02-03 12:59:01 +00:00
|
|
|
#endif
|
2016-09-25 00:20:15 +00:00
|
|
|
{
|
2023-01-10 16:19:35 +00:00
|
|
|
#ifdef CONFIG_SPL_FS_FAT
|
|
|
|
err = spl_load_image_fat(spl_image, bootdev, stor_dev,
|
|
|
|
CONFIG_SYS_SATA_FAT_BOOT_PARTITION,
|
|
|
|
CONFIG_SPL_FS_LOAD_PAYLOAD_NAME);
|
|
|
|
#elif defined(CONFIG_SPL_SATA_RAW_U_BOOT_USE_SECTOR)
|
|
|
|
err = spl_sata_load_image_raw(spl_image, bootdev, stor_dev,
|
|
|
|
CONFIG_SPL_SATA_RAW_U_BOOT_SECTOR);
|
|
|
|
#endif
|
2016-09-25 00:20:15 +00:00
|
|
|
}
|
2014-02-03 12:59:01 +00:00
|
|
|
if (err) {
|
|
|
|
puts("Error loading sata device\n");
|
2015-11-08 15:11:49 +00:00
|
|
|
return err;
|
2014-02-03 12:59:01 +00:00
|
|
|
}
|
2015-11-08 15:11:49 +00:00
|
|
|
|
|
|
|
return 0;
|
2014-02-03 12:59:01 +00:00
|
|
|
}
|
2016-11-30 22:30:50 +00:00
|
|
|
SPL_LOAD_IMAGE_METHOD("SATA", 0, BOOT_DEVICE_SATA, spl_sata_load_image);
|