Update SMEM with the storage medium from which the system booted.

Signed-off-by: Varadarajan Narayanan <[email protected]>
---
v4: Handle Boot medium not specified case properly
    Minor cosmetic changes

v3: Move SMEM init from previous patch to this new patch
---
 arch/arm/mach-snapdragon/spl.c | 73 +++++++++++++++++++++++++++++++++-
 include/smem.h                 |  3 ++
 2 files changed, 75 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-snapdragon/spl.c b/arch/arm/mach-snapdragon/spl.c
index 73e8ca5d459..c1a7d4cb00f 100644
--- a/arch/arm/mach-snapdragon/spl.c
+++ b/arch/arm/mach-snapdragon/spl.c
@@ -11,6 +11,7 @@
 #include <asm/io.h>
 #include <asm/system.h>
 #include <asm/sections.h>
+#include <smem.h>
 #include <atf_common.h>
 #include <linux/err.h>
 #include <dm/device-internal.h>
@@ -166,6 +167,52 @@ static int qcom_spl_get_fit_img_entry_point(void *fit, int 
node,
        return ret;
 }
 
+#if IS_ENABLED(CONFIG_SPL_SMEM)
+/**
+ * qcom_spl_populate_smem() - Populate shared memory (SMEM) information.
+ * @ctx:       Pointer to the global SPL context.
+ *
+ * This function initializes and populates various SMEM items with boot-related
+ * information, such as flash type, try-mode status, and ATF enable status.
+ * Return: 0 on success, or a negative error code on failure.
+ */
+static int qcom_spl_populate_smem(void *ctx)
+{
+       int ret;
+       size_t size;
+       struct udevice *smem;
+       u32 *fltype;
+
+       ret = uclass_get_device(UCLASS_SMEM, 0, &smem);
+       if (ret) {
+               pr_err("Failed to find SMEM node (%d)\n", ret);
+               return ret;
+       }
+
+       size = sizeof(u32);
+       ret = smem_alloc(smem, -1, SMEM_BOOT_FLASH_TYPE, size);
+       if (ret) {
+               pr_err("Failed to alloc item: SMEM_BOOT_FLASH_TYPE (%d)\n", 
ret);
+               return ret;
+       }
+
+       fltype = (u32 *)smem_get(smem, -1, SMEM_BOOT_FLASH_TYPE, &size);
+       if (!fltype) {
+               pr_err("Failed to get item: SMEM_BOOT_FLASH_TYPE\n");
+               return -ENOENT;
+       }
+
+       if (IS_ENABLED(CONFIG_SPL_MMC)) {
+               *fltype = SMEM_BOOT_MMC_FLASH;
+               return 0;
+       }
+
+       pr_err("Boot medium not specified\n");
+
+       return -ENOENT;
+}
+#endif /* IS_ENABLED(CONFIG_SPL_SMEM) */
+
 /**
  * qcom_spl_get_iftbl_entry_by_name() - Get an interface table entry by name.
  * @if_tbl:    Pointer to the QCLIB interface table.
@@ -327,6 +374,30 @@ int qclib_post_process_from_spl(void)
        return 0;
 }
 
+#if IS_ENABLED(CONFIG_SPL_SMEM)
+/**
+ * spl_board_prepare_for_boot() - Prepare board for boot
+ *
+ * This function is called by SPL before jumping to the next stage.
+ * It populates SMEM during coldboot.
+ */
+void spl_board_prepare_for_boot(void)
+{
+       int ret;
+
+       /*
+        * Populate SMEM in coldboot (Dload bit not set)
+        */
+       if (!QCOM_SPL_IS_DLOAD_BIT_SET) {
+               ret = qcom_spl_populate_smem(NULL);
+               if (ret) {
+                       pr_err("Failed to populate SMEM (%d)\n", ret);
+                       qcom_spl_error_handler(NULL);
+               }
+       }
+}
+#endif /* IS_ENABLED(CONFIG_SPL_SMEM) */
+
 /**
  * spl_get_load_buffer() - Allocate a cache-aligned buffer for image loading.
  * @offset:    Offset (unused, typically 0 for SPL).
@@ -395,7 +466,7 @@ struct bl_params *bl2_plat_get_bl31_params_v2(uintptr_t 
bl32_entry,
 
 /**
  * qcom_spl_loader_pre_ddr() - SPL loader for pre-DDR stage.
- * @boot_device:Type of boot device.
+ * @boot_device: Type of boot device.
  *
  * Return: 0 on success, or a negative error code on failure.
  */
diff --git a/include/smem.h b/include/smem.h
index b19c534ebc4..f16ba7d63dc 100644
--- a/include/smem.h
+++ b/include/smem.h
@@ -87,4 +87,7 @@ void *smem_get(struct udevice *dev, unsigned int host, 
unsigned int item, size_t
  */
 int smem_get_free_space(struct udevice *dev, unsigned int host);
 
+#define SMEM_BOOT_FLASH_TYPE                   498
+#define SMEM_BOOT_MMC_FLASH                    5
+
 #endif /* _smem_h_ */
-- 
2.34.1

Reply via email to