Keep track of whether we were loaded via ABL or if U-Boot is running as
a first-stage bootloader.

For now we set this based on if we have a valid external FDT or not,
since it isn't possible to chainload U-Boot from ABL without there being
an external FDT.

This will be used to inform the capsule update logic which partition
U-Boot is flashed to.

Signed-off-by: Caleb Connolly <caleb.conno...@linaro.org>
---
 arch/arm/mach-snapdragon/board.c     | 26 ++++++++++++++++++++++++++
 arch/arm/mach-snapdragon/qcom-priv.h | 14 ++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/arch/arm/mach-snapdragon/board.c b/arch/arm/mach-snapdragon/board.c
index 
deae4d323789eab75d5fe735159b4cd820c02c45..34e37ab083f20b70660f2ab90a2995a4dfb33f8e
 100644
--- a/arch/arm/mach-snapdragon/board.c
+++ b/arch/arm/mach-snapdragon/board.c
@@ -36,8 +36,10 @@
 #include "qcom-priv.h"
 
 DECLARE_GLOBAL_DATA_PTR;
 
+enum qcom_boot_source qcom_boot_source __section(".data") = 0;
+
 static struct mm_region rbx_mem_map[CONFIG_NR_DRAM_BANKS + 2] = { { 0 } };
 
 struct mm_region *mem_map = rbx_mem_map;
 
@@ -237,8 +239,14 @@ int board_fdt_blob_setup(void **fdtp)
 
        if (ret < 0)
                panic("No valid memory ranges found!\n");
 
+       /* If we have an external FDT, it can only have come from the Android 
bootloader. */
+       if (external_valid)
+               qcom_boot_source = QCOM_BOOT_SOURCE_ANDROID;
+       else
+               qcom_boot_source = QCOM_BOOT_SOURCE_XBL;
+
        debug("ram_base = %#011lx, ram_size = %#011llx\n",
              gd->ram_base, gd->ram_size);
 
        if (internal_valid) {
@@ -472,8 +480,25 @@ static void configure_env(void)
 
        qcom_set_serialno();
 }
 
+void qcom_show_boot_source(void)
+{
+       const char *name = "UNKNOWN";
+
+       switch (qcom_boot_source) {
+       case QCOM_BOOT_SOURCE_ANDROID:
+               name = "ABL";
+               break;
+       case QCOM_BOOT_SOURCE_XBL:
+               name = "XBL";
+               break;
+       }
+
+       log_info("U-Boot loaded from %s\n", name);
+       env_set("boot_source", name);
+}
+
 void __weak qcom_late_init(void)
 {
 }
 
@@ -515,8 +540,9 @@ int board_late_init(void)
 
        configure_env();
        qcom_late_init();
 
+       qcom_show_boot_source();
        /* Configure the dfu_string for capsule updates */
        qcom_configure_capsule_updates();
 
        return 0;
diff --git a/arch/arm/mach-snapdragon/qcom-priv.h 
b/arch/arm/mach-snapdragon/qcom-priv.h
index 
74d39197b89f4e769299b06214c26ee829ecdce0..e5eb4cfbc2b752de799b1407ede69683c81474c1
 100644
--- a/arch/arm/mach-snapdragon/qcom-priv.h
+++ b/arch/arm/mach-snapdragon/qcom-priv.h
@@ -2,8 +2,22 @@
 
 #ifndef __QCOM_PRIV_H__
 #define __QCOM_PRIV_H__
 
+/**
+ * enum qcom_boot_source - Track where we got loaded from.
+ * Used for capsule update logic.
+ *
+ * @QCOM_BOOT_SOURCE_ANDROID: chainloaded (typically from ABL)
+ * @QCOM_BOOT_SOURCE_XBL: flashed to the XBL or UEFI partition
+ */
+enum qcom_boot_source {
+       QCOM_BOOT_SOURCE_ANDROID = 1,
+       QCOM_BOOT_SOURCE_XBL,
+};
+
+extern enum qcom_boot_source qcom_boot_source;
+
 #if IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT)
 void qcom_configure_capsule_updates(void);
 #else
 void qcom_configure_capsule_updates(void) {}

-- 
2.49.0

Reply via email to