]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
sandbox: Allow chaining from SPL to U-Boot proper
authorSimon Glass <sjg@chromium.org>
Mon, 4 Jul 2016 17:57:45 +0000 (11:57 -0600)
committerSimon Glass <sjg@chromium.org>
Fri, 15 Jul 2016 02:40:24 +0000 (20:40 -0600)
SPL is expected to load and run U-Boot. This needs to work with sandbox also.
Provide a function to locate the U-Boot image, and another to start it. This
allows SPL to function on sandbox as it does on other archs.

Signed-off-by: Simon Glass <sjg@chromium.org>
arch/sandbox/cpu/os.c
include/os.h

index 8a4d719835ccb88c00b5aa6fd1e37cfdc049e8e8..2d63dd88f121e0cbcb4effa498c56530aa6223fb 100644 (file)
@@ -541,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);
index 954a48c9919e78a9259b615d6be12aa01c1ef4b3..1782e50e77511769b19b7a83679d5521107e5f8e 100644 (file)
@@ -286,6 +286,31 @@ int os_read_ram_buf(const char *fname);
  */
 int os_jump_to_image(const void *dest, int size);
 
+/**
+ * os_find_u_boot() - Determine the path to U-Boot proper
+ *
+ * This function is intended to be called from within sandbox SPL. It uses
+ * a few heuristics to find U-Boot proper. Normally it is either in the same
+ * directory, or the directory above (since u-boot-spl is normally in an
+ * spl/ subdirectory when built).
+ *
+ * @fname:     Place to put full path to U-Boot
+ * @maxlen:    Maximum size of @fname
+ * @return 0 if OK, -NOSPC if the filename is too large, -ENOENT if not found
+ */
+int os_find_u_boot(char *fname, int maxlen);
+
+/**
+ * os_spl_to_uboot() - Run U-Boot proper
+ *
+ * When called from SPL, this runs U-Boot proper. The filename is obtained by
+ * calling os_find_u_boot().
+ *
+ * @fname:     Full pathname to U-Boot executable
+ * @return 0 if OK, -ve on error
+ */
+int os_spl_to_uboot(const char *fname);
+
 /**
  * Read the current system time
  *