diff mbox series

[U-Boot,05/15] sandbox: Support booting from TPL to SPL

Message ID 20181001175520.239554-6-sjg@chromium.org
State Accepted
Commit 69bc15d5ffaa99b9d20e23a37d3b442f65e7f5ea
Delegated to: Simon Glass
Headers show
Series sandbox: Add support for TPL and other improvements | expand

Commit Message

Simon Glass Oct. 1, 2018, 5:55 p.m. UTC
At present we support booting from SPL to U-Boot proper. Add support for
the previous stage too, so sandbox can be started with TPL.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/sandbox/cpu/os.c | 29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

Comments

Simon Glass Oct. 9, 2018, 11:51 p.m. UTC | #1
At present we support booting from SPL to U-Boot proper. Add support for
the previous stage too, so sandbox can be started with TPL.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/sandbox/cpu/os.c | 29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

Applied to u-boot-dm
diff mbox series

Patch

diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index 3a46038c5fc..a7f17034862 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -642,15 +642,40 @@  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);
+	const char *suffix;
 	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")) {
+	suffix = fname + len - 4;
+
+	/* If we are TPL, boot to SPL */
+	if (!strcmp(suffix, "-tpl")) {
+		fname[len - 3] = 's';
+		fd = os_open(fname, O_RDONLY);
+		if (fd >= 0) {
+			close(fd);
+			return 0;
+		}
+
+		/* Look for 'u-boot-tpl' in the tpl/ directory */
+		p = strstr(fname, "/tpl/");
+		if (p) {
+			p[1] = 's';
+			fd = os_open(fname, O_RDONLY);
+			if (fd >= 0) {
+				close(fd);
+				return 0;
+			}
+		}
+		return -ENOENT;
+	}
+
+	/* Look for 'u-boot' in the same directory as 'u-boot-spl' */
+	if (!strcmp(suffix, "-spl")) {
 		fname[len - 4] = '\0';
 		fd = os_open(fname, O_RDONLY);
 		if (fd >= 0) {