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>
This commit is contained in:
parent
ffb87905cb
commit
ab839dc3e6
|
@ -488,7 +488,7 @@ int os_jump_to_image(const void *dest, int size)
|
||||||
struct sandbox_state *state = state_get_current();
|
struct sandbox_state *state = state_get_current();
|
||||||
char fname[30], mem_fname[30];
|
char fname[30], mem_fname[30];
|
||||||
int fd, err;
|
int fd, err;
|
||||||
const char *extra_args[4];
|
const char *extra_args[5];
|
||||||
char **argv = state->argv;
|
char **argv = state->argv;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
int argc, i;
|
int argc, i;
|
||||||
|
@ -513,6 +513,7 @@ int os_jump_to_image(const void *dest, int size)
|
||||||
extra_args[1] = fname;
|
extra_args[1] = fname;
|
||||||
extra_args[2] = "-m";
|
extra_args[2] = "-m";
|
||||||
extra_args[3] = mem_fname;
|
extra_args[3] = mem_fname;
|
||||||
|
extra_args[4] = "--rm_memory";
|
||||||
err = add_args(&argv, extra_args,
|
err = add_args(&argv, extra_args,
|
||||||
sizeof(extra_args) / sizeof(extra_args[0]));
|
sizeof(extra_args) / sizeof(extra_args[0]));
|
||||||
if (err)
|
if (err)
|
||||||
|
|
|
@ -110,14 +110,8 @@ SANDBOX_CMDLINE_OPT_SHORT(interactive, 'i', 0, "Enter interactive mode");
|
||||||
static int sandbox_cmdline_cb_jump(struct sandbox_state *state,
|
static int sandbox_cmdline_cb_jump(struct sandbox_state *state,
|
||||||
const char *arg)
|
const char *arg)
|
||||||
{
|
{
|
||||||
state->jumped = 1;
|
/* Remember to delete this U-Boot image later */
|
||||||
|
state->jumped_fname = arg;
|
||||||
/*
|
|
||||||
* TODO(sjg@chromium.org): Note this causes problems for gdb which
|
|
||||||
* wants to read debug data from the image.
|
|
||||||
*
|
|
||||||
* os_unlink(arg);
|
|
||||||
*/
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -142,6 +136,15 @@ static int sandbox_cmdline_cb_memory(struct sandbox_state *state,
|
||||||
SANDBOX_CMDLINE_OPT_SHORT(memory, 'm', 1,
|
SANDBOX_CMDLINE_OPT_SHORT(memory, 'm', 1,
|
||||||
"Read/write ram_buf memory contents from file");
|
"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,
|
static int sandbox_cmdline_cb_state(struct sandbox_state *state,
|
||||||
const char *arg)
|
const char *arg)
|
||||||
{
|
{
|
||||||
|
@ -229,6 +232,10 @@ int main(int argc, char *argv[])
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err;
|
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 */
|
/* Do pre- and post-relocation init */
|
||||||
board_init_f(0);
|
board_init_f(0);
|
||||||
|
|
||||||
|
|
|
@ -365,7 +365,7 @@ int state_uninit(void)
|
||||||
|
|
||||||
state = &main_state;
|
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);
|
err = os_write_ram_buf(state->ram_buf_fname);
|
||||||
if (err) {
|
if (err) {
|
||||||
printf("Failed to write RAM buffer\n");
|
printf("Failed to write RAM buffer\n");
|
||||||
|
@ -380,6 +380,10 @@ int state_uninit(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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)
|
if (state->state_fdt)
|
||||||
os_free(state->state_fdt);
|
os_free(state->state_fdt);
|
||||||
memset(state, '\0', sizeof(*state));
|
memset(state, '\0', sizeof(*state));
|
||||||
|
|
|
@ -54,10 +54,11 @@ struct sandbox_state {
|
||||||
const char *parse_err; /* Error to report from parsing */
|
const char *parse_err; /* Error to report from parsing */
|
||||||
int argc; /* Program arguments */
|
int argc; /* Program arguments */
|
||||||
char **argv; /* Command line arguments */
|
char **argv; /* Command line arguments */
|
||||||
bool jumped; /* Jumped from previous U_Boot */
|
const char *jumped_fname; /* Jumped from previous U_Boot */
|
||||||
uint8_t *ram_buf; /* Emulated RAM buffer */
|
uint8_t *ram_buf; /* Emulated RAM buffer */
|
||||||
unsigned int ram_size; /* Size of RAM buffer */
|
unsigned int ram_size; /* Size of RAM buffer */
|
||||||
const char *ram_buf_fname; /* Filename to use for RAM buffer */
|
const char *ram_buf_fname; /* Filename to use for RAM buffer */
|
||||||
|
bool ram_buf_rm; /* Remove RAM buffer file after read */
|
||||||
bool write_ram_buf; /* Write RAM buffer on exit */
|
bool write_ram_buf; /* Write RAM buffer on exit */
|
||||||
const char *state_fname; /* File containing sandbox state */
|
const char *state_fname; /* File containing sandbox state */
|
||||||
void *state_fdt; /* Holds saved state for sandbox */
|
void *state_fdt; /* Holds saved state for sandbox */
|
||||||
|
|
Loading…
Reference in New Issue