1 // SPDX-License-Identifier: GPL-2.0+
9 #include <semihosting.h>
12 static int smh_read_full(long fd, void *memp, size_t len)
16 read = smh_read(fd, memp, len);
24 static ulong smh_fit_read(struct spl_load_info *load, ulong file_offset,
25 ulong size, void *buf)
30 fd = smh_open(load->filename, MODE_READ | MODE_BINARY);
32 log_debug("could not open %s: %ld\n", load->filename, fd);
35 ret = smh_read(fd, buf, size);
41 static int spl_smh_load_image(struct spl_image_info *spl_image,
42 struct spl_boot_device *bootdev)
44 const char *filename = CONFIG_SPL_FS_LOAD_PAYLOAD_NAME;
47 struct legacy_img_hdr *header =
48 spl_get_load_buffer(-sizeof(*header), sizeof(*header));
50 fd = smh_open(filename, MODE_READ | MODE_BINARY);
52 log_debug("could not open %s: %ld\n", filename, fd);
58 log_debug("could not get length of image: %d\n", ret);
63 ret = smh_read_full(fd, header, sizeof(struct legacy_img_hdr));
65 log_debug("could not read image header: %d\n", ret);
69 if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
70 image_get_magic(header) == FDT_MAGIC) {
71 struct spl_load_info load;
74 load.read = smh_fit_read;
76 load.filename = filename;
80 return spl_load_simple_fit(spl_image, &load, 0, header);
83 ret = spl_parse_image_header(spl_image, bootdev, header);
85 log_debug("failed to parse image header: %d\n", ret);
89 ret = smh_seek(fd, 0);
91 log_debug("could not seek to start of image: %d\n", ret);
95 ret = smh_read_full(fd, (void *)spl_image->load_addr, len);
97 log_debug("could not read %s: %d\n", filename, ret);
102 SPL_LOAD_IMAGE_METHOD("SEMIHOSTING", 0, BOOT_DEVICE_SMH, spl_smh_load_image);