return base;
}
+
+void os_relaunch(char *argv[])
+{
+ execv(argv[0], argv);
+ os_exit(1);
+}
#include <common.h>
#include <command.h>
+#include <dm/root.h>
#include <errno.h>
#include <init.h>
#include <os.h>
DECLARE_GLOBAL_DATA_PTR;
+static char **os_argv;
+
/* Compare two options so that they can be sorted into alphabetical order */
static int h_compare_opt(const void *p1, const void *p2)
{
printf("\n");
}
+void sandbox_reset(void)
+{
+ /* Do this here while it still has an effect */
+ os_fd_restore();
+ if (state_uninit())
+ os_exit(2);
+
+ if (dm_uninit())
+ os_exit(2);
+
+ /* Restart U-Boot */
+ os_relaunch(os_argv);
+}
+
int main(int argc, char *argv[])
{
struct sandbox_state *state;
gd_t data;
int ret;
+ /*
+ * Copy argv[] so that we can pass the arguments in the original
+ * sequence when resetting the sandbox.
+ */
+ os_argv = calloc(argc + 1, sizeof(char *));
+ if (!os_argv)
+ os_exit(1);
+ memcpy(os_argv, argv, sizeof(char *) * (argc + 1));
+
memset(&data, '\0', sizeof(data));
gd = &data;
gd->arch.text_base = os_find_text_base();
/* No reset yet, so mark it as such. Always allow power reset */
state->last_sysreset = SYSRESET_COUNT;
state->sysreset_allowed[SYSRESET_POWER_OFF] = true;
+ state->sysreset_allowed[SYSRESET_COLD] = true;
state->allow_memio = false;
memset(&state->wdt, '\0', sizeof(state->wdt));
*/
int sandbox_read_fdt_from_file(void);
+/**
+ * sandbox_reset() - reset sandbox
+ *
+ * This functions implements the cold reboot of the sandbox. It relaunches the
+ * U-Boot binary with the same command line parameters as the original call.
+ * The PID of the process stays the same. All file descriptors that have not
+ * been opened with O_CLOEXEC stay open including stdin, stdout, stderr.
+ */
+void sandbox_reset(void);
+
/* Exit sandbox (quit U-Boot) */
void sandbox_exit(void);
switch (type) {
case SYSRESET_COLD:
state->last_sysreset = type;
+ if (!state->sysreset_allowed[type])
+ return -EACCES;
+ sandbox_reset();
break;
case SYSRESET_POWER_OFF:
state->last_sysreset = type;
*/
void *os_find_text_base(void);
+/**
+ * os_relaunch() - restart the sandbox
+ *
+ * This functions is used to implement the cold reboot of the sand box.
+ * @argv[0] specifies the binary that is started while the calling process
+ * stops immediately. If the new binary cannot be started, the process is
+ * terminated and 1 is set as shell return code.
+ *
+ * The PID of the process stays the same. All file descriptors that have not
+ * been opened with O_CLOEXEC stay open including stdin, stdout, stderr.
+ *
+ * @argv: NULL terminated list of command line parameters
+ */
+void os_relaunch(char *argv[]);
+
#endif