sandbox: Add options to clean up temporary files

When jumping from one sandbox U-Boot to another in sandbox, the RAM buffer
is preserved in the jump by using a temporary file. Add an option to tell
the receiving U-Boot to remove this file when it is no longer needed.

Similarly the old U-Boot image is left behind in this case. We cannot delete
it immediately since gdb cannot then find its debug symbols. Delete it just
before exiting.

Together these changes ensure that temporary files are removed both for
memory and U-Boot.

Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c
index 36dfc0a..aad3b8b 100644
--- a/arch/sandbox/cpu/start.c
+++ b/arch/sandbox/cpu/start.c
@@ -110,14 +110,8 @@
 static int sandbox_cmdline_cb_jump(struct sandbox_state *state,
 				   const char *arg)
 {
-	state->jumped = 1;
-
-	/*
-	 * TODO(sjg@chromium.org): Note this causes problems for gdb which
-	 * wants to read debug data from the image.
-	 *
-	 * os_unlink(arg);
-	 */
+	/* Remember to delete this U-Boot image later */
+	state->jumped_fname = arg;
 
 	return 0;
 }
@@ -142,6 +136,15 @@
 SANDBOX_CMDLINE_OPT_SHORT(memory, 'm', 1,
 			  "Read/write ram_buf memory contents from file");
 
+static int sandbox_cmdline_cb_rm_memory(struct sandbox_state *state,
+					const char *arg)
+{
+	state->ram_buf_rm = true;
+
+	return 0;
+}
+SANDBOX_CMDLINE_OPT(rm_memory, 0, "Remove memory file after reading");
+
 static int sandbox_cmdline_cb_state(struct sandbox_state *state,
 				    const char *arg)
 {
@@ -229,6 +232,10 @@
 	if (ret)
 		goto err;
 
+	/* Remove old memory file if required */
+	if (state->ram_buf_rm && state->ram_buf_fname)
+		os_unlink(state->ram_buf_fname);
+
 	/* Do pre- and post-relocation init */
 	board_init_f(0);