In snagboot mode, XBL loads U-Boot directly without populating CMD DB.
The cmd-db driver fails to bind when CMD DB magic is invalid, blocking
boot even when CMD DB is not strictly required.

Use QCOM_SNAGBOOT_MODE config to allow the driver to bind
successfully when CMD DB data is absent. When QCOM_SNAGBOOT_MODE is
enabled and CMD DB data is present, we log a warning.

Signed-off-by: Balaji Selvanathan <[email protected]>
---
Changes in v4:
- Removed QCOM_COMMAND_DB_OPTIONAL as now we use
  CONFIG_QCOM_SNAGBOOT_MODE
- Drop these warnings if snagboot mode is enabled since that's the
  expected case
- Log a warning if snagboot is enabled and we do have a valid cmd-db,
  since that isn't an expected usecase

 Changes in v3:
- Used "if (IS_ENABLED(CONFIG_QCOM_COMMAND_DB_OPTIONAL))" instead
  of #ifdef

Changes in v2:
- No changes
---
 drivers/soc/qcom/Kconfig  | 18 ++++++++++++++++++
 drivers/soc/qcom/cmd-db.c | 15 +++++++++++++--
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/drivers/soc/qcom/Kconfig b/drivers/soc/qcom/Kconfig
index cdd9e30f43e..987719bb925 100644
--- a/drivers/soc/qcom/Kconfig
+++ b/drivers/soc/qcom/Kconfig
@@ -18,6 +18,24 @@ config QCOM_COMMAND_DB
          resource on a RPM-hardened platform must use this database to get
          SoC specific identifier and information for the shared resources.
 
+config QCOM_COMMAND_DB_OPTIONAL
+       bool "Allow operation without Command DB data"
+       depends on QCOM_COMMAND_DB
+       help
+         Allow the Command DB driver to bind successfully even when CMD DB
+         data is not populated or has an invalid magic number.
+
+         This is useful for platforms where CMD DB is not populated by the
+         previous bootloader (e.g., snagboot mode where XBL loads U-Boot
+         directly without initializing CMD DB).
+
+         When enabled, missing CMD DB will generate warnings but allow boot
+         to continue. Consumer drivers must handle cmd_db API failures
+         gracefully by checking return values.
+
+         If unsure, say N. Most production Qualcomm platforms require
+         valid CMD DB data.
+
 config QCOM_RPMH
        bool "Qualcomm RPMh support"
        depends on QCOM_COMMAND_DB
diff --git a/drivers/soc/qcom/cmd-db.c b/drivers/soc/qcom/cmd-db.c
index d0a6047b8a6..c94a90a2903 100644
--- a/drivers/soc/qcom/cmd-db.c
+++ b/drivers/soc/qcom/cmd-db.c
@@ -252,8 +252,19 @@ static int cmd_db_bind(struct udevice *dev)
 
        cmd_db_header = base;
        if (!cmd_db_magic_matches(cmd_db_header)) {
-               log_err("%s: Invalid Command DB Magic\n", __func__);
-               return -EINVAL;
+               if (IS_ENABLED(CONFIG_QCOM_SNAGBOOT_MODE)) {
+                       /* Missing CMD DB is expected in snagboot mode */
+                       cmd_db_header = NULL;
+                       return 0;
+               } else {
+                       log_err("%s: Invalid Command DB Magic\n", __func__);
+                       return -EINVAL;
+               }
+       }
+
+       if (IS_ENABLED(CONFIG_QCOM_SNAGBOOT_MODE)) {
+               log_warning("%s: CMD DB found in snagboot mode - this is 
unexpected\n",
+                           __func__);
        }
 
        return 0;

-- 
2.34.1

Reply via email to