From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 03/15] sandbox: Add a way to write data to the host filesystem
Date: Mon, 1 Oct 2018 11:55:08 -0600 [thread overview]
Message-ID: <20181001175520.239554-4-sjg@chromium.org> (raw)
In-Reply-To: <20181001175520.239554-1-sjg@chromium.org>
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>
---
arch/sandbox/cpu/os.c | 20 ++++++++++++++++++++
include/os.h | 13 +++++++++++++
2 files changed, 33 insertions(+)
diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index 2d20cfe1fa6..3a46038c5fc 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;
diff --git a/include/os.h b/include/os.h
index 9e3a561b65e..efa9e52d124 100644
--- a/include/os.h
+++ b/include/os.h
@@ -347,4 +347,17 @@ void os_abort(void);
*/
int os_mprotect_allow(void *start, size_t len);
+/**
+ * os_write_file() - Write a file to the host filesystem
+ *
+ * This can be useful when debugging for writing data out of sandbox for
+ * inspection by external tools.
+ *
+ * @name: File path to write to
+ * @buf: Data to write
+ * @size: Size of data to write
+ * @return 0 if OK, -ve on error
+ */
+int os_write_file(const char *name, const void *buf, int size);
+
#endif
--
2.19.0.605.g01d371f741-goog
next prev parent reply other threads:[~2018-10-01 17:55 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-01 17:55 [U-Boot] [PATCH 00/15] sandbox: Add support for TPL and other improvements Simon Glass
2018-10-01 17:55 ` [U-Boot] [PATCH 01/15] log: Add helpers for common log levels Simon Glass
2018-10-09 23:51 ` sjg at google.com
2018-10-01 17:55 ` [U-Boot] [PATCH 02/15] sandbox: Support file truncation with os_open() Simon Glass
2018-10-09 23:51 ` sjg at google.com
2018-10-01 17:55 ` Simon Glass [this message]
2018-10-09 23:51 ` [U-Boot] [PATCH 03/15] sandbox: Add a way to write data to the host filesystem sjg at google.com
2018-10-01 17:55 ` [U-Boot] [PATCH 04/15] sandbox: spi: Drop command-line SPI option Simon Glass
2018-10-09 23:51 ` sjg at google.com
2018-10-01 17:55 ` [U-Boot] [PATCH 05/15] sandbox: Support booting from TPL to SPL Simon Glass
2018-10-09 23:51 ` sjg at google.com
2018-10-01 17:55 ` [U-Boot] [PATCH 06/15] sandbox: Add a flag to set the default log level Simon Glass
2018-10-09 23:51 ` sjg at google.com
2018-10-01 17:55 ` [U-Boot] [PATCH 07/15] sandbox: Remove the old memory file later Simon Glass
2018-10-09 23:51 ` sjg at google.com
2018-10-01 17:55 ` [U-Boot] [PATCH 08/15] sandbox: spi: Add more logging Simon Glass
2018-10-09 23:51 ` sjg at google.com
2018-10-01 17:55 ` [U-Boot] [PATCH 09/15] sandbox: video: Speed up video output Simon Glass
2018-10-01 19:20 ` Anatolij Gustschin
2018-10-09 23:51 ` sjg at google.com
2018-10-01 17:55 ` [U-Boot] [PATCH 10/15] sandbox: Add a debug UART Simon Glass
2018-10-09 23:51 ` sjg at google.com
2018-10-01 17:55 ` [U-Boot] [PATCH 11/15] serial: sandbox: Allow serial output without device tree Simon Glass
2018-10-09 23:51 ` sjg at google.com
2018-10-01 17:55 ` [U-Boot] [PATCH 12/15] sandbox: tpm: Tidy up enums and return values Simon Glass
2018-10-09 23:51 ` sjg at google.com
2018-10-01 17:55 ` [U-Boot] [PATCH 13/15] sandbox: tpm: Enhance to support the latest Chromium OS Simon Glass
2018-10-09 23:51 ` sjg at google.com
2018-10-01 17:55 ` [U-Boot] [PATCH 14/15] dm: spi: Clean up detection of sandbox SPI emulator Simon Glass
2018-10-09 23:51 ` sjg at google.com
2018-10-01 17:55 ` [U-Boot] [PATCH 15/15] sandbox: Restore blocking I/O on exit Simon Glass
2018-10-09 23:51 ` sjg at google.com
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181001175520.239554-4-sjg@chromium.org \
--to=sjg@chromium.org \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox