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/state.c b/arch/sandbox/cpu/state.c
index a145808..59adad6 100644
--- a/arch/sandbox/cpu/state.c
+++ b/arch/sandbox/cpu/state.c
@@ -365,7 +365,7 @@
 
 	state = &main_state;
 
-	if (state->write_ram_buf) {
+	if (state->write_ram_buf && !state->ram_buf_rm) {
 		err = os_write_ram_buf(state->ram_buf_fname);
 		if (err) {
 			printf("Failed to write RAM buffer\n");
@@ -380,6 +380,10 @@
 		}
 	}
 
+	/* Delete this at the last moment so as not to upset gdb too much */
+	if (state->jumped_fname)
+		os_unlink(state->jumped_fname);
+
 	if (state->state_fdt)
 		os_free(state->state_fdt);
 	memset(state, '\0', sizeof(*state));