X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=arch%2Fsandbox%2Fcpu%2Fos.c;h=2d63dd88f121e0cbcb4effa498c56530aa6223fb;hb=edf0093732225c2fd0791c3864e9a3eef1f92f19;hp=e6dd17e9efc7c62777bc6e4210c367abb2471435;hpb=0e6b7a28243175ae0874d53b6e6e4eff8548d71f;p=oweals%2Fu-boot.git diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index e6dd17e9ef..2d63dd88f1 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -107,10 +107,12 @@ void os_exit(int exit_code) static struct termios orig_term; static bool term_setup; -static void os_fd_restore(void) +void os_fd_restore(void) { - if (term_setup) + if (term_setup) { tcsetattr(0, TCSANOW, &orig_term); + term_setup = false; + } } /* Put tty into raw mode so and work */ @@ -120,7 +122,6 @@ void os_tty_raw(int fd, bool allow_sigs) if (term_setup) return; - term_setup = true; /* If not a tty, don't complain */ if (tcgetattr(fd, &orig_term)) @@ -134,6 +135,7 @@ void os_tty_raw(int fd, bool allow_sigs) if (tcsetattr(fd, TCSANOW, &term)) return; + term_setup = true; atexit(os_fd_restore); } @@ -539,6 +541,57 @@ int os_jump_to_image(const void *dest, int size) return unlink(fname); } +int os_find_u_boot(char *fname, int maxlen) +{ + struct sandbox_state *state = state_get_current(); + const char *progname = state->argv[0]; + int len = strlen(progname); + char *p; + int fd; + + if (len >= maxlen || len < 4) + return -ENOSPC; + + /* Look for 'u-boot' in the same directory as 'u-boot-spl' */ + strcpy(fname, progname); + if (!strcmp(fname + len - 4, "-spl")) { + fname[len - 4] = '\0'; + fd = os_open(fname, O_RDONLY); + if (fd >= 0) { + close(fd); + return 0; + } + } + + /* Look for 'u-boot' in the parent directory of spl/ */ + p = strstr(fname, "/spl/"); + if (p) { + strcpy(p, p + 4); + fd = os_open(fname, O_RDONLY); + if (fd >= 0) { + close(fd); + return 0; + } + } + + return -ENOENT; +} + +int os_spl_to_uboot(const char *fname) +{ + struct sandbox_state *state = state_get_current(); + char *argv[state->argc + 1]; + int ret; + + memcpy(argv, state->argv, sizeof(char *) * (state->argc + 1)); + argv[0] = (char *)fname; + ret = execv(fname, argv); + if (ret) + return ret; + + return unlink(fname); +} + void os_localtime(struct rtc_time *rt) { time_t t = time(NULL);