summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2021-01-13 20:29:42 -0700
committerTom Rini <trini@konsulko.com>2021-01-27 17:03:16 -0500
commit09d9ba9097ceb374f2802506c9e755fd8d5dd861 (patch)
treea6d33a1a08089a112d037a4128fac5dc14c438f6
parent040fad3791fe05b985516a68c9437847173da56a (diff)
downloadu-boot-09d9ba9097ceb374f2802506c9e755fd8d5dd861.tar.gz
u-boot-09d9ba9097ceb374f2802506c9e755fd8d5dd861.tar.bz2
u-boot-09d9ba9097ceb374f2802506c9e755fd8d5dd861.zip
spl: Add functions for next and previous phase
It is useful to be able to figure out which phase we are loading next and which phase we came from. Add some functions to handle this as well as returning the name of a phase. This allows messages like "Booting to x" where x is the next phase. At present, TPL says 'Jumping to U-Boot' at the end, when in fact it is jumping to SPL. This is confusing, so use the new functions to correct this. Tests for this will come with an upcoming minor SPL test refactor. Signed-off-by: Simon Glass <sjg@chromium.org>
-rw-r--r--common/spl/spl.c2
-rw-r--r--include/spl.h53
2 files changed, 54 insertions, 1 deletions
diff --git a/common/spl/spl.c b/common/spl/spl.c
index 8b7374487d..8cb6f3d531 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -734,7 +734,7 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
debug("Failed to stash bootstage: err=%d\n", ret);
#endif
- debug("loaded - jumping to U-Boot...\n");
+ debug("loaded - jumping to %s...\n", spl_phase_name(spl_next_phase()));
spl_board_prepare_for_boot();
jump_to_image_no_args(&spl_image);
}
diff --git a/include/spl.h b/include/spl.h
index a7648787b7..faffeb519a 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -58,6 +58,7 @@ static inline bool u_boot_first_phase(void)
}
enum u_boot_phase {
+ PHASE_NONE, /* Invalid phase, signifying before U-Boot */
PHASE_TPL, /* Running in TPL */
PHASE_SPL, /* Running in SPL */
PHASE_BOARD_F, /* Running in U-Boot before relocation */
@@ -123,6 +124,58 @@ static inline enum u_boot_phase spl_phase(void)
#endif
}
+/**
+ * spl_prev_phase() - Figure out the previous U-Boot phase
+ *
+ * @return the previous phase from this one, e.g. if called in SPL this returns
+ * PHASE_TPL, if TPL is enabled
+ */
+static inline enum u_boot_phase spl_prev_phase(void)
+{
+#ifdef CONFIG_TPL_BUILD
+ return PHASE_NONE;
+#elif defined(CONFIG_SPL_BUILD)
+ return IS_ENABLED(CONFIG_TPL) ? PHASE_TPL : PHASE_NONE;
+#else
+ return IS_ENABLED(CONFIG_SPL) ? PHASE_SPL : PHASE_NONE;
+#endif
+}
+
+/**
+ * spl_next_phase() - Figure out the next U-Boot phase
+ *
+ * @return the next phase from this one, e.g. if called in TPL this returns
+ * PHASE_SPL
+ */
+static inline enum u_boot_phase spl_next_phase(void)
+{
+#ifdef CONFIG_TPL_BUILD
+ return PHASE_SPL;
+#else
+ return PHASE_BOARD_F;
+#endif
+}
+
+/**
+ * spl_phase_name() - Get the name of the current phase
+ *
+ * @return phase name
+ */
+static inline const char *spl_phase_name(enum u_boot_phase phase)
+{
+ switch (phase) {
+ case PHASE_TPL:
+ return "TPL";
+ case PHASE_SPL:
+ return "SPL";
+ case PHASE_BOARD_F:
+ case PHASE_BOARD_R:
+ return "U-Boot";
+ default:
+ return "phase?";
+ }
+}
+
/* A string name for SPL or TPL */
#ifdef CONFIG_SPL_BUILD
# ifdef CONFIG_TPL_BUILD