]> Git Repo - u-boot.git/blame - common/spl/spl_sata.c
Restore patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet"
[u-boot.git] / common / spl / spl_sata.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
fff40a7e
DM
2/*
3 * (C) Copyright 2013
4 * Texas Instruments, <www.ti.com>
5 *
6 * Dan Murphy <[email protected]>
7 *
fff40a7e
DM
8 * Derived work from spl_usb.c
9 */
10
fff40a7e 11#include <spl.h>
fff40a7e 12#include <sata.h>
fc89b2e4 13#include <scsi.h>
36afd451 14#include <errno.h>
fff40a7e 15#include <fat.h>
fff40a7e
DM
16#include <image.h>
17
60ca969a 18static int spl_sata_load_image_raw(struct spl_image_info *spl_image,
2e0429bc 19 struct spl_boot_device *bootdev,
60ca969a
BS
20 struct blk_desc *stor_dev, unsigned long sector)
21{
f3543e69 22 struct legacy_img_hdr *header;
60ca969a
BS
23 unsigned long count;
24 u32 image_size_sectors;
5fce2875
T
25 u32 image_offset_sectors;
26 u32 image_offset;
60ca969a
BS
27 int ret;
28
29 header = spl_get_load_buffer(-sizeof(*header), stor_dev->blksz);
30 count = blk_dread(stor_dev, sector, 1, header);
31 if (count == 0)
32 return -EIO;
33
2e0429bc 34 ret = spl_parse_image_header(spl_image, bootdev, header);
60ca969a
BS
35 if (ret)
36 return ret;
37
38 image_size_sectors = DIV_ROUND_UP(spl_image->size, stor_dev->blksz);
5fce2875
T
39 image_offset_sectors = spl_image->offset / stor_dev->blksz;
40 image_offset = spl_image->offset % stor_dev->blksz;
41 count = blk_dread(stor_dev, sector + image_offset_sectors,
42 image_size_sectors,
60ca969a
BS
43 (void *)spl_image->load_addr);
44 if (count != image_size_sectors)
45 return -EIO;
46
5fce2875
T
47 if (image_offset)
48 memmove((void *)spl_image->load_addr,
49 (void *)spl_image->load_addr + image_offset,
50 spl_image->size);
51
60ca969a
BS
52 return 0;
53}
54
2a2ee2ac
SG
55static int spl_sata_load_image(struct spl_image_info *spl_image,
56 struct spl_boot_device *bootdev)
fff40a7e 57{
6e73ab32 58 int err = -ENOSYS;
4101f687 59 struct blk_desc *stor_dev;
fff40a7e 60
d498c670
TR
61 /* try to recognize storage devices immediately */
62 scsi_scan(false);
8149b150 63 stor_dev = blk_get_devnum_by_uclass_id(UCLASS_SCSI, 0);
d498c670
TR
64 if (!stor_dev)
65 return -ENODEV;
fff40a7e 66
7115007c 67#if CONFIG_IS_ENABLED(OS_BOOT)
710e9ca5 68 if (spl_start_uboot() ||
2e0429bc 69 spl_load_image_fat_os(spl_image, bootdev, stor_dev,
710e9ca5 70 CONFIG_SYS_SATA_FAT_BOOT_PARTITION))
fff40a7e 71#endif
710e9ca5 72 {
6e73ab32
TR
73#ifdef CONFIG_SPL_FS_FAT
74 err = spl_load_image_fat(spl_image, bootdev, stor_dev,
75 CONFIG_SYS_SATA_FAT_BOOT_PARTITION,
76 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME);
77#elif defined(CONFIG_SPL_SATA_RAW_U_BOOT_USE_SECTOR)
78 err = spl_sata_load_image_raw(spl_image, bootdev, stor_dev,
79 CONFIG_SPL_SATA_RAW_U_BOOT_SECTOR);
80#endif
710e9ca5 81 }
fff40a7e
DM
82 if (err) {
83 puts("Error loading sata device\n");
36afd451 84 return err;
fff40a7e 85 }
36afd451
NK
86
87 return 0;
fff40a7e 88}
ebc4ef61 89SPL_LOAD_IMAGE_METHOD("SATA", 0, BOOT_DEVICE_SATA, spl_sata_load_image);
This page took 0.267273 seconds and 4 git commands to generate.