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-05-16 10:03:53 +00:00
|
|
|
#ifndef CONFIG_SYS_SATA_FAT_BOOT_PARTITION
|
|
|
|
#define CONFIG_SYS_SATA_FAT_BOOT_PARTITION 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME
|
|
|
|
#define CONFIG_SPL_FS_LOAD_PAYLOAD_NAME "u-boot.img"
|
|
|
|
#endif
|
|
|
|
|
2019-07-14 14:54:21 +00:00
|
|
|
#ifndef CONFIG_SPL_SATA_RAW_U_BOOT_SECTOR
|
|
|
|
/* Dummy value to make the compiler happy */
|
|
|
|
#define CONFIG_SPL_SATA_RAW_U_BOOT_SECTOR 0x100
|
|
|
|
#endif
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
struct image_header *header;
|
|
|
|
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
|
|
|
{
|
2019-05-16 10:03:54 +00:00
|
|
|
int err = 0;
|
2016-02-29 22:25:34 +00:00
|
|
|
struct blk_desc *stor_dev;
|
2014-02-03 12:59:01 +00:00
|
|
|
|
2019-05-16 10:03:54 +00:00
|
|
|
#if !defined(CONFIG_DM_SCSI) && !defined(CONFIG_AHCI)
|
2014-02-03 12:59:01 +00:00
|
|
|
err = init_sata(CONFIG_SPL_SATA_BOOT_DEVICE);
|
2019-05-16 10:03:54 +00:00
|
|
|
#endif
|
2014-02-03 12:59:01 +00:00
|
|
|
if (err) {
|
|
|
|
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
|
|
|
|
printf("spl: sata init failed: err - %d\n", err);
|
|
|
|
#endif
|
2015-11-08 15:11:49 +00:00
|
|
|
return err;
|
2014-02-03 12:59:01 +00:00
|
|
|
} else {
|
|
|
|
/* try to recognize storage devices immediately */
|
2017-06-15 03:28:41 +00:00
|
|
|
scsi_scan(false);
|
2016-05-01 17:36:16 +00:00
|
|
|
stor_dev = blk_get_devnum_by_type(IF_TYPE_SCSI, 0);
|
2015-11-08 15:11:49 +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
|
|
|
{
|
2019-05-16 10:03:55 +00:00
|
|
|
err = -ENOSYS;
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_SPL_FS_FAT)) {
|
2022-01-14 13:31:38 +00:00
|
|
|
err = spl_load_image_fat(spl_image, bootdev, stor_dev,
|
2016-09-25 00:20:15 +00:00
|
|
|
CONFIG_SYS_SATA_FAT_BOOT_PARTITION,
|
2019-05-16 10:03:55 +00:00
|
|
|
CONFIG_SPL_FS_LOAD_PAYLOAD_NAME);
|
2019-07-14 14:54:21 +00:00
|
|
|
} else if (IS_ENABLED(CONFIG_SPL_SATA_RAW_U_BOOT_USE_SECTOR)) {
|
2022-01-14 13:31:38 +00:00
|
|
|
err = spl_sata_load_image_raw(spl_image, bootdev, stor_dev,
|
2019-07-14 14:54:21 +00:00
|
|
|
CONFIG_SPL_SATA_RAW_U_BOOT_SECTOR);
|
2019-05-16 10:03:55 +00:00
|
|
|
}
|
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);
|