Merge tag 'dm-9oct18' of git://git.denx.de/u-boot-dm
[platform/kernel/u-boot.git] / arch / sandbox / cpu / state.c
index ba73b7e..d3b9c05 100644 (file)
@@ -1,6 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (c) 2011-2012 The Chromium OS Authors.
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
 static struct sandbox_state main_state;
 static struct sandbox_state *state;    /* Pointer to current state record */
 
-void state_record_exit(enum exit_type_id exit_type)
-{
-       state->exit_type = exit_type;
-}
-
 static int state_ensure_space(int extra_size)
 {
        void *blob = state->state_fdt;
@@ -56,7 +51,7 @@ static int state_read_file(struct sandbox_state *state, const char *fname)
        ret = os_get_filesize(fname, &size);
        if (ret < 0) {
                printf("Cannot find sandbox state file '%s'\n", fname);
-               return ret;
+               return -ENOENT;
        }
        state->state_fdt = os_malloc(size);
        if (!state->state_fdt) {
@@ -158,7 +153,7 @@ int sandbox_read_state(struct sandbox_state *state, const char *fname)
                        return ret;
        }
 
-       /* Call all the state read funtcions */
+       /* Call all the state read functions */
        got_err = false;
        blob = state->state_fdt;
        io = ll_entry_start(struct sandbox_state_io, state_io);
@@ -342,6 +337,38 @@ struct sandbox_state *state_get_current(void)
        return state;
 }
 
+void state_set_skip_delays(bool skip_delays)
+{
+       struct sandbox_state *state = state_get_current();
+
+       state->skip_delays = skip_delays;
+}
+
+bool state_get_skip_delays(void)
+{
+       struct sandbox_state *state = state_get_current();
+
+       return state->skip_delays;
+}
+
+void state_reset_for_test(struct sandbox_state *state)
+{
+       /* No reset yet, so mark it as such. Always allow power reset */
+       state->last_sysreset = SYSRESET_COUNT;
+       state->sysreset_allowed[SYSRESET_POWER] = true;
+
+       memset(&state->wdt, '\0', sizeof(state->wdt));
+       memset(state->spi, '\0', sizeof(state->spi));
+
+       /*
+        * Set up the memory tag list. Use the top of emulated SDRAM for the
+        * first tag number, since that address offset is outside the legal
+        * range, and can be assumed to be a tag.
+        */
+       INIT_LIST_HEAD(&state->mapmem_head);
+       state->next_tag = state->ram_size;
+}
+
 int state_init(void)
 {
        state = &main_state;
@@ -350,6 +377,7 @@ int state_init(void)
        state->ram_buf = os_malloc(state->ram_size);
        assert(state->ram_buf);
 
+       state_reset_for_test(state);
        /*
         * Example of how to use GPIOs:
         *
@@ -365,7 +393,7 @@ int state_uninit(void)
 
        state = &main_state;
 
-       if (state->write_ram_buf && !state->ram_buf_rm) {
+       if (state->write_ram_buf) {
                err = os_write_ram_buf(state->ram_buf_fname);
                if (err) {
                        printf("Failed to write RAM buffer\n");
@@ -380,6 +408,10 @@ int state_uninit(void)
                }
        }
 
+       /* Remove old memory file if required */
+       if (state->ram_buf_rm && state->ram_buf_fname)
+               os_unlink(state->ram_buf_fname);
+
        /* Delete this at the last moment so as not to upset gdb too much */
        if (state->jumped_fname)
                os_unlink(state->jumped_fname);