mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-13 08:07:32 -04:00
soc: qcom: mdt_loader: Allow hash at any phdr
The assumption that the elf program header will always have the hash segment program header at index 1 may not hold true in all cases. This change updates the read metadata function to find the hash program header dynamically. Change-Id: Ic5aa0d290b24ec3273003d980fec070b9e058c4f Signed-off-by: Siddharth Gupta <sidgup@codeaurora.org>
This commit is contained in:
parent
616d4d19a3
commit
94ab28d633
1 changed files with 10 additions and 4 deletions
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* Copyright (C) 2016 Linaro Ltd
|
||||
* Copyright (C) 2015 Sony Mobile Communications Inc
|
||||
* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
|
||||
* Copyright (c) 2012-2013, 2020 The Linux Foundation. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <linux/device.h>
|
||||
|
|
@ -88,6 +88,7 @@ void *qcom_mdt_read_metadata(const struct firmware *fw, size_t *data_len)
|
|||
const struct elf32_phdr *phdrs;
|
||||
const struct elf32_hdr *ehdr;
|
||||
size_t hash_offset;
|
||||
size_t hash_index;
|
||||
size_t hash_size;
|
||||
size_t ehdr_size;
|
||||
void *data;
|
||||
|
|
@ -107,11 +108,16 @@ void *qcom_mdt_read_metadata(const struct firmware *fw, size_t *data_len)
|
|||
if (phdrs[0].p_type == PT_LOAD)
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
if ((phdrs[1].p_flags & QCOM_MDT_TYPE_MASK) != QCOM_MDT_TYPE_HASH)
|
||||
for (hash_index = 1; hash_index < ehdr->e_phnum; hash_index++) {
|
||||
if (phdrs[hash_index].p_type != PT_LOAD &&
|
||||
(phdrs[hash_index].p_flags & QCOM_MDT_TYPE_MASK) == QCOM_MDT_TYPE_HASH)
|
||||
break;
|
||||
}
|
||||
if (hash_index >= ehdr->e_phnum)
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
ehdr_size = phdrs[0].p_filesz;
|
||||
hash_size = phdrs[1].p_filesz;
|
||||
hash_size = phdrs[hash_index].p_filesz;
|
||||
|
||||
/* Overflow check */
|
||||
if (ehdr_size > SIZE_MAX - hash_size)
|
||||
|
|
@ -125,7 +131,7 @@ void *qcom_mdt_read_metadata(const struct firmware *fw, size_t *data_len)
|
|||
if (ehdr_size + hash_size == fw->size)
|
||||
hash_offset = phdrs[0].p_filesz;
|
||||
else
|
||||
hash_offset = phdrs[1].p_offset;
|
||||
hash_offset = phdrs[hash_index].p_offset;
|
||||
|
||||
memcpy(data, fw->data, ehdr_size);
|
||||
memcpy(data + ehdr_size, fw->data + hash_offset, hash_size);
|
||||
|
|
|
|||
Loading…
Reference in a new issue