Skip to contentSkip to conversation

soc: qcom: mdt_loader: Support firmware without hash segment

PATCH New Bjorn Andersson 1 participant 1 message Dec 13, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 soc: qcom: mdt_loader: Support firmware without hash segment

At least some of the firmware found on 8974 does not follow the typical scheme of having a non-loadable hash segment directly following the ELF header, in the modem mdt.

Rather than failing the read of metadata, fall back to passing back a copy of the full first firmware file and let the metadata validator do its job.

---
 drivers/soc/qcom/mdt_loader.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/soc/qcom/mdt_loader.c +13 -1
index 24cd193dec55..dd8a27f866db 100644
@@ -99,7 +99,7 @@ void *qcom_mdt_read_metadata(const struct firmware *fw, size_t *data_len)
 		return ERR_PTR(-EINVAL);
 
 	if (phdrs[0].p_type == PT_LOAD || phdrs[1].p_type == PT_LOAD)
-		return ERR_PTR(-EINVAL);
+		goto return_fw_copy;
 
 	if ((phdrs[1].p_flags & QCOM_MDT_TYPE_MASK) != QCOM_MDT_TYPE_HASH)
 		return ERR_PTR(-EINVAL);
@@ -123,6 +123,18 @@ void *qcom_mdt_read_metadata(const struct firmware *fw, size_t *data_len)
 	*data_len = ehdr_size + hash_size;
 
 	return data;
+
+return_fw_copy:
+	/*
+	 * Some older firmware (e.g. on 8974) doesn't have a hash segment
+	 * following the ELF header, just return a verbatim copy of the
+	 * fw->data and let the metadata authenticator consume what it needs.
+	 */
+	data = kmemdup(fw->data, fw->size, GFP_KERNEL);
+	if (!data)
+		return ERR_PTR(-ENOMEM);
+	*data_len = fw->size;
+	return data;
 }
 EXPORT_SYMBOL_GPL(qcom_mdt_read_metadata);
 
Signature · 1 line
2.23.0