1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2022, Sean Anderson <sean.anderson@seco.com>
4 * Copyright (c) 2012, Google Inc.
11 #include <semihosting.h>
12 #include <semihostingfs.h>
14 int smh_fs_set_blk_dev(struct blk_desc *rbdd, struct disk_partition *info)
17 * Only accept a NULL struct blk_desc for the semihosting, which is when
18 * hostfs interface is used
23 static int smh_fs_read_at(const char *filename, loff_t pos, void *buffer,
24 loff_t maxsize, loff_t *actread)
28 fd = smh_open(filename, MODE_READ | MODE_BINARY);
31 ret = smh_seek(fd, pos);
46 size = smh_read(fd, buffer, maxsize);
55 static int smh_fs_write_at(const char *filename, loff_t pos, void *buffer,
56 loff_t towrite, loff_t *actwrite)
60 fd = smh_open(filename, MODE_READ | MODE_BINARY | MODE_PLUS);
63 ret = smh_seek(fd, pos);
69 ret = smh_write(fd, buffer, towrite, &size);
75 int smh_fs_size(const char *filename, loff_t *result)
79 fd = smh_open(filename, MODE_READ | MODE_BINARY);
93 int smh_fs_read(const char *filename, void *buf, loff_t offset, loff_t len,
98 ret = smh_fs_read_at(filename, offset, buf, len, actread);
100 printf("** Unable to read file %s **\n", filename);
105 int smh_fs_write(const char *filename, void *buf, loff_t offset,
106 loff_t len, loff_t *actwrite)
110 ret = smh_fs_write_at(filename, offset, buf, len, actwrite);
112 printf("** Unable to write file %s **\n", filename);