[Concept,17/27] sandbox: expo: Add expo_dump_file()

Message ID 20260119204130.3972647-18-sjg@u-boot.org
State New
Headers
Series Expo debugging and textedit improvements (part E) |

Commit Message

Simon Glass Jan. 19, 2026, 8:41 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Add a function to dump expo structures to a file, which is useful for
debugging. This uses the configurable output function added in the
previous patch.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 boot/expo_dump.c | 36 ++++++++++++++++++++++++++++++++++++
 include/expo.h   |  9 +++++++++
 2 files changed, 45 insertions(+)
  

Patch

diff --git a/boot/expo_dump.c b/boot/expo_dump.c
index cb0a1e443e3..940a505b313 100644
--- a/boot/expo_dump.c
+++ b/boot/expo_dump.c
@@ -12,6 +12,7 @@ 
 #include <expo.h>
 #include <mapmem.h>
 #include <membuf.h>
+#include <os.h>
 #include <video.h>
 #include <video_console.h>
 #include "scene_internal.h"
@@ -306,3 +307,38 @@  void expo_dump(struct expo *exp, struct membuf *mb)
 
 	expo_dump_(&ctx, exp);
 }
+
+/**
+ * dump_out_file() - Output function that writes to a file
+ *
+ * @priv: Pointer to file descriptor (int *)
+ * @buf: Buffer containing data to output
+ * @len: Length of data in buffer
+ */
+static void dump_out_file(void *priv, const char *buf, int len)
+{
+	int *fdp = priv;
+
+	os_write(*fdp, buf, len);
+}
+
+int expo_dump_file(struct expo *exp, const char *fname)
+{
+	struct dump_ctx ctx;
+	int fd;
+
+	fd = os_open(fname, OS_O_WRONLY | OS_O_CREAT | OS_O_TRUNC);
+	if (fd < 0)
+		return fd;
+
+	ctx.out = dump_out_file;
+	ctx.priv = &fd;
+	ctx.scn = NULL;
+	ctx.indent = 0;
+
+	expo_dump_(&ctx, exp);
+
+	os_close(fd);
+
+	return 0;
+}
diff --git a/include/expo.h b/include/expo.h
index e3451d8dd23..c854d78255b 100644
--- a/include/expo.h
+++ b/include/expo.h
@@ -1279,6 +1279,15 @@  void expo_damage_add(struct expo *exp, const struct vid_bbox *bbox);
  */
 void expo_dump(struct expo *exp, struct membuf *mb);
 
+/**
+ * expo_dump_file() - Dump expo structure to a file (sandbox only)
+ *
+ * @exp: Expo to dump
+ * @fname: Filename to write to
+ * Return: 0 if OK, -ve on error
+ */
+int expo_dump_file(struct expo *exp, const char *fname);
+
 /**
  * scene_dump() - Dump scene structure to a membuf
  *