Commit 26c1f170 authored by Bjorn Andersson's avatar Bjorn Andersson

soc: qcom: mdt_loader: Split out split-file-loader

Spotted in a SM8450 device, the hash metadata segment is split out in a
separate .bNN file which means that the logic for loading split out
segmenents needs to be duplicated in qcom_mdt_read_metadata().

Split out the existing logic to a helper function that can be used in
both code paths.
Signed-off-by: default avatarBjorn Andersson <bjorn.andersson@linaro.org>
Reviewed-by: default avatarDmitry Baryshkov <dmitry.baryshkov@linaro.org>
Link: https://lore.kernel.org/r/20220128025513.97188-3-bjorn.andersson@linaro.org
parent 3a99f121
...@@ -31,6 +31,44 @@ static bool mdt_phdr_valid(const struct elf32_phdr *phdr) ...@@ -31,6 +31,44 @@ static bool mdt_phdr_valid(const struct elf32_phdr *phdr)
return true; return true;
} }
static ssize_t mdt_load_split_segment(void *ptr, const struct elf32_phdr *phdrs,
unsigned int segment, const char *fw_name,
struct device *dev)
{
const struct elf32_phdr *phdr = &phdrs[segment];
const struct firmware *seg_fw;
char *seg_name;
ssize_t ret;
if (strlen(fw_name) < 4)
return -EINVAL;
seg_name = kstrdup(fw_name, GFP_KERNEL);
if (!seg_name)
return -ENOMEM;
sprintf(seg_name + strlen(fw_name) - 3, "b%02d", segment);
ret = request_firmware_into_buf(&seg_fw, seg_name, dev,
ptr, phdr->p_filesz);
if (ret) {
dev_err(dev, "error %zd loading %s\n", ret, seg_name);
kfree(seg_name);
return ret;
}
if (seg_fw->size != phdr->p_filesz) {
dev_err(dev,
"failed to load segment %d from truncated file %s\n",
segment, seg_name);
ret = -EINVAL;
}
release_firmware(seg_fw);
kfree(seg_name);
return ret;
}
/** /**
* qcom_mdt_get_size() - acquire size of the memory region needed to load mdt * qcom_mdt_get_size() - acquire size of the memory region needed to load mdt
* @fw: firmware object for the mdt file * @fw: firmware object for the mdt file
...@@ -127,22 +165,19 @@ void *qcom_mdt_read_metadata(const struct firmware *fw, size_t *data_len) ...@@ -127,22 +165,19 @@ void *qcom_mdt_read_metadata(const struct firmware *fw, size_t *data_len)
EXPORT_SYMBOL_GPL(qcom_mdt_read_metadata); EXPORT_SYMBOL_GPL(qcom_mdt_read_metadata);
static int __qcom_mdt_load(struct device *dev, const struct firmware *fw, static int __qcom_mdt_load(struct device *dev, const struct firmware *fw,
const char *firmware, int pas_id, void *mem_region, const char *fw_name, int pas_id, void *mem_region,
phys_addr_t mem_phys, size_t mem_size, phys_addr_t mem_phys, size_t mem_size,
phys_addr_t *reloc_base, bool pas_init) phys_addr_t *reloc_base, bool pas_init)
{ {
const struct elf32_phdr *phdrs; const struct elf32_phdr *phdrs;
const struct elf32_phdr *phdr; const struct elf32_phdr *phdr;
const struct elf32_hdr *ehdr; const struct elf32_hdr *ehdr;
const struct firmware *seg_fw;
phys_addr_t mem_reloc; phys_addr_t mem_reloc;
phys_addr_t min_addr = PHYS_ADDR_MAX; phys_addr_t min_addr = PHYS_ADDR_MAX;
phys_addr_t max_addr = 0; phys_addr_t max_addr = 0;
size_t metadata_len; size_t metadata_len;
size_t fw_name_len;
ssize_t offset; ssize_t offset;
void *metadata; void *metadata;
char *fw_name;
bool relocate = false; bool relocate = false;
void *ptr; void *ptr;
int ret = 0; int ret = 0;
...@@ -154,14 +189,6 @@ static int __qcom_mdt_load(struct device *dev, const struct firmware *fw, ...@@ -154,14 +189,6 @@ static int __qcom_mdt_load(struct device *dev, const struct firmware *fw,
ehdr = (struct elf32_hdr *)fw->data; ehdr = (struct elf32_hdr *)fw->data;
phdrs = (struct elf32_phdr *)(ehdr + 1); phdrs = (struct elf32_phdr *)(ehdr + 1);
fw_name_len = strlen(firmware);
if (fw_name_len <= 4)
return -EINVAL;
fw_name = kstrdup(firmware, GFP_KERNEL);
if (!fw_name)
return -ENOMEM;
if (pas_init) { if (pas_init) {
metadata = qcom_mdt_read_metadata(fw, &metadata_len); metadata = qcom_mdt_read_metadata(fw, &metadata_len);
if (IS_ERR(metadata)) { if (IS_ERR(metadata)) {
...@@ -258,25 +285,9 @@ static int __qcom_mdt_load(struct device *dev, const struct firmware *fw, ...@@ -258,25 +285,9 @@ static int __qcom_mdt_load(struct device *dev, const struct firmware *fw,
memcpy(ptr, fw->data + phdr->p_offset, phdr->p_filesz); memcpy(ptr, fw->data + phdr->p_offset, phdr->p_filesz);
} else if (phdr->p_filesz) { } else if (phdr->p_filesz) {
/* Firmware not large enough, load split-out segments */ /* Firmware not large enough, load split-out segments */
sprintf(fw_name + fw_name_len - 3, "b%02d", i); ret = mdt_load_split_segment(ptr, phdrs, i, fw_name, dev);
ret = request_firmware_into_buf(&seg_fw, fw_name, dev, if (ret)
ptr, phdr->p_filesz);
if (ret) {
dev_err(dev, "error %d loading %s\n",
ret, fw_name);
break; break;
}
if (seg_fw->size != phdr->p_filesz) {
dev_err(dev,
"failed to load segment %d from truncated file %s\n",
i, fw_name);
release_firmware(seg_fw);
ret = -EINVAL;
break;
}
release_firmware(seg_fw);
} }
if (phdr->p_memsz > phdr->p_filesz) if (phdr->p_memsz > phdr->p_filesz)
...@@ -287,7 +298,6 @@ static int __qcom_mdt_load(struct device *dev, const struct firmware *fw, ...@@ -287,7 +298,6 @@ static int __qcom_mdt_load(struct device *dev, const struct firmware *fw,
*reloc_base = mem_reloc; *reloc_base = mem_reloc;
out: out:
kfree(fw_name);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment