1 // SPDX-License-Identifier: GPL-2.0+
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 /* Try to open existing file */
61 fd = smh_open(filename, MODE_READ | MODE_BINARY | MODE_PLUS);
64 fd = smh_open(filename, MODE_WRITE | MODE_BINARY);
67 ret = smh_seek(fd, pos);
73 ret = smh_write(fd, buffer, towrite, &size);
79 int smh_fs_size(const char *filename, loff_t *result)
83 fd = smh_open(filename, MODE_READ | MODE_BINARY);
97 int smh_fs_read(const char *filename, void *buf, loff_t offset, loff_t len,
102 ret = smh_fs_read_at(filename, offset, buf, len, actread);
104 printf("** Unable to read file %s **\n", filename);
109 int smh_fs_write(const char *filename, void *buf, loff_t offset,
110 loff_t len, loff_t *actwrite)
114 ret = smh_fs_write_at(filename, offset, buf, len, actwrite);
116 printf("** Unable to write file %s **\n", filename);