]>
Commit | Line | Data |
---|---|---|
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 <dmurphy@ti.com> | |
7 | * | |
fff40a7e DM |
8 | * Derived work from spl_usb.c |
9 | */ | |
10 | ||
d678a59d | 11 | #include <common.h> |
fff40a7e | 12 | #include <spl.h> |
d678a59d | 13 | #include <asm/u-boot.h> |
fff40a7e | 14 | #include <sata.h> |
fc89b2e4 | 15 | #include <scsi.h> |
36afd451 | 16 | #include <errno.h> |
fff40a7e | 17 | #include <fat.h> |
fff40a7e DM |
18 | #include <image.h> |
19 | ||
60ca969a | 20 | static int spl_sata_load_image_raw(struct spl_image_info *spl_image, |
2e0429bc | 21 | struct spl_boot_device *bootdev, |
60ca969a BS |
22 | struct blk_desc *stor_dev, unsigned long sector) |
23 | { | |
f3543e69 | 24 | struct legacy_img_hdr *header; |
60ca969a BS |
25 | unsigned long count; |
26 | u32 image_size_sectors; | |
5fce2875 T |
27 | u32 image_offset_sectors; |
28 | u32 image_offset; | |
60ca969a BS |
29 | int ret; |
30 | ||
31 | header = spl_get_load_buffer(-sizeof(*header), stor_dev->blksz); | |
32 | count = blk_dread(stor_dev, sector, 1, header); | |
33 | if (count == 0) | |
34 | return -EIO; | |
35 | ||
2e0429bc | 36 | ret = spl_parse_image_header(spl_image, bootdev, header); |
60ca969a BS |
37 | if (ret) |
38 | return ret; | |
39 | ||
40 | image_size_sectors = DIV_ROUND_UP(spl_image->size, stor_dev->blksz); | |
5fce2875 T |
41 | image_offset_sectors = spl_image->offset / stor_dev->blksz; |
42 | image_offset = spl_image->offset % stor_dev->blksz; | |
43 | count = blk_dread(stor_dev, sector + image_offset_sectors, | |
44 | image_size_sectors, | |
60ca969a BS |
45 | (void *)spl_image->load_addr); |
46 | if (count != image_size_sectors) | |
47 | return -EIO; | |
48 | ||
5fce2875 T |
49 | if (image_offset) |
50 | memmove((void *)spl_image->load_addr, | |
51 | (void *)spl_image->load_addr + image_offset, | |
52 | spl_image->size); | |
53 | ||
60ca969a BS |
54 | return 0; |
55 | } | |
56 | ||
2a2ee2ac SG |
57 | static int spl_sata_load_image(struct spl_image_info *spl_image, |
58 | struct spl_boot_device *bootdev) | |
fff40a7e | 59 | { |
6e73ab32 | 60 | int err = -ENOSYS; |
4101f687 | 61 | struct blk_desc *stor_dev; |
fff40a7e | 62 | |
d498c670 TR |
63 | /* try to recognize storage devices immediately */ |
64 | scsi_scan(false); | |
8149b150 | 65 | stor_dev = blk_get_devnum_by_uclass_id(UCLASS_SCSI, 0); |
d498c670 TR |
66 | if (!stor_dev) |
67 | return -ENODEV; | |
fff40a7e | 68 | |
7115007c | 69 | #if CONFIG_IS_ENABLED(OS_BOOT) |
710e9ca5 | 70 | if (spl_start_uboot() || |
2e0429bc | 71 | spl_load_image_fat_os(spl_image, bootdev, stor_dev, |
710e9ca5 | 72 | CONFIG_SYS_SATA_FAT_BOOT_PARTITION)) |
fff40a7e | 73 | #endif |
710e9ca5 | 74 | { |
6e73ab32 TR |
75 | #ifdef CONFIG_SPL_FS_FAT |
76 | err = spl_load_image_fat(spl_image, bootdev, stor_dev, | |
77 | CONFIG_SYS_SATA_FAT_BOOT_PARTITION, | |
78 | CONFIG_SPL_FS_LOAD_PAYLOAD_NAME); | |
79 | #elif defined(CONFIG_SPL_SATA_RAW_U_BOOT_USE_SECTOR) | |
80 | err = spl_sata_load_image_raw(spl_image, bootdev, stor_dev, | |
81 | CONFIG_SPL_SATA_RAW_U_BOOT_SECTOR); | |
82 | #endif | |
710e9ca5 | 83 | } |
fff40a7e DM |
84 | if (err) { |
85 | puts("Error loading sata device\n"); | |
36afd451 | 86 | return err; |
fff40a7e | 87 | } |
36afd451 NK |
88 | |
89 | return 0; | |
fff40a7e | 90 | } |
ebc4ef61 | 91 | SPL_LOAD_IMAGE_METHOD("SATA", 0, BOOT_DEVICE_SATA, spl_sata_load_image); |