Message ID | 20190925141147.191166-12-sjg@chromium.org |
---|---|
State | Accepted |
Commit | 8e83b76df41f2a7c36adae7af7aa40a0b1ab36a1 |
Delegated to: | Bin Meng |
Headers | show |
Series | x86: Various modifications to prepare for FSP2 | expand |
On Wed, Sep 25, 2019 at 10:12 PM Simon Glass <sjg@chromium.org> wrote: > > U-Boot is built in three phases: TPL, SPL and U-Boot proper. Sometimes > it is necessary to use different init code depending on the phase. For > example, TPL might do very basic CPU init, SPL might do a little more > and U-Boot proper might bring the CPU up to full speed and enable all > cores. > > Add a function which allows easy determination of the current phase being > built. > > Signed-off-by: Simon Glass <sjg@chromium.org> > --- > > Changes in v2: None > > include/spl.h | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 60 insertions(+) > Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
On Wed, Oct 2, 2019 at 9:58 PM Bin Meng <bmeng.cn@gmail.com> wrote: > > On Wed, Sep 25, 2019 at 10:12 PM Simon Glass <sjg@chromium.org> wrote: > > > > U-Boot is built in three phases: TPL, SPL and U-Boot proper. Sometimes > > it is necessary to use different init code depending on the phase. For > > example, TPL might do very basic CPU init, SPL might do a little more > > and U-Boot proper might bring the CPU up to full speed and enable all > > cores. > > > > Add a function which allows easy determination of the current phase being > > built. > > > > Signed-off-by: Simon Glass <sjg@chromium.org> > > --- > > > > Changes in v2: None > > > > include/spl.h | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 60 insertions(+) > > > > Reviewed-by: Bin Meng <bmeng.cn@gmail.com> applied to u-boot-x86/next, thanks!
diff --git a/include/spl.h b/include/spl.h index 4bc35cb0e77..2869c9dc702 100644 --- a/include/spl.h +++ b/include/spl.h @@ -49,6 +49,66 @@ static inline bool u_boot_first_phase(void) return false; } +enum u_boot_phase { + PHASE_TPL, + PHASE_SPL, + PHASE_U_BOOT, +}; + +/** + * spl_phase() - Find out the phase of U-Boot + * + * This can be used to avoid #ifdef logic and use if() instead. + * + * For example, to include code only in TPL, you might do: + * + * #ifdef CONFIG_TPL_BUILD + * ... + * #endif + * + * but with this you can use: + * + * if (spl_phase() == PHASE_TPL) { + * ... + * } + * + * To include code only in SPL, you might do: + * + * #if defined(CONFIG_SPL_BUILD) && !defined(CONFIG_TPL_BUILD) + * ... + * #endif + * + * but with this you can use: + * + * if (spl_phase() == PHASE_SPL) { + * ... + * } + * + * To include code only in U-Boot proper, you might do: + * + * #ifndef CONFIG_SPL_BUILD + * ... + * #endif + * + * but with this you can use: + * + * if (spl_phase() == PHASE_U_BOOT) { + * ... + * } + * + * @return U-Boot phase + */ +static inline enum u_boot_phase spl_phase(void) +{ +#ifdef CONFIG_TPL_BUILD + return PHASE_TPL; +#elif CONFIG_SPL_BUILD + return PHASE_SPL; +#else + return PHASE_U_BOOT; +#endif +} + /* A string name for SPL or TPL */ #ifdef CONFIG_SPL_BUILD # ifdef CONFIG_TPL_BUILD
U-Boot is built in three phases: TPL, SPL and U-Boot proper. Sometimes it is necessary to use different init code depending on the phase. For example, TPL might do very basic CPU init, SPL might do a little more and U-Boot proper might bring the CPU up to full speed and enable all cores. Add a function which allows easy determination of the current phase being built. Signed-off-by: Simon Glass <sjg@chromium.org> --- Changes in v2: None include/spl.h | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+)