summaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2018-10-01 20:55:08 +0300
committerSimon Glass <sjg@chromium.org>2018-10-09 13:40:26 +0300
commit056a5cea3139cd41836051114a0f3344ac3d9f58 (patch)
treee470ad79ba80909ee6c0ea40f104795914bb2d5d /arch
parent50b288aca324649fb5b357ce75972a5261cf94fc (diff)
downloadu-boot-056a5cea3139cd41836051114a0f3344ac3d9f58.tar.xz
sandbox: Add a way to write data to the host filesystem
For debugging it is sometimes useful to write out data for inspection using an external tool. Add a function which can write this data to a given file. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'arch')
-rw-r--r--arch/sandbox/cpu/os.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index 1d87a53843..e7d6691b84 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -106,6 +106,26 @@ void os_exit(int exit_code)
exit(exit_code);
}
+int os_write_file(const char *name, const void *buf, int size)
+{
+ char fname[256];
+ int fd;
+
+ fd = os_open(fname, OS_O_WRONLY | OS_O_CREAT | OS_O_TRUNC);
+ if (fd < 0) {
+ printf("Cannot open file '%s'\n", fname);
+ return -EIO;
+ }
+ if (os_write(fd, buf, size) != size) {
+ printf("Cannot write to file '%s'\n", fname);
+ return -EIO;
+ }
+ os_close(fd);
+ printf("Write '%s', size %#x (%d)\n", name, size, size);
+
+ return 0;
+}
+
/* Restore tty state when we exit */
static struct termios orig_term;
static bool term_setup;