summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJi Luo <ji.luo@nxp.com>2019-12-10 17:54:40 +0800
committerJi Luo <ji.luo@nxp.com>2019-12-10 20:26:21 +0800
commit7740677930170f694766ce4c8a4be231b8a7f937 (patch)
tree55beb44e20ca879f35acdfdfc3da659128ad8811 /lib
parentce15b01bac8f6a0cf9265eca913bf4560513c0af (diff)
MA-16048 Fix imx8q u-boot hang
Address 0x8880_0000 is reserved for M4 image on imx8q, which leaves limited memory region for the malloc pool. The avb will consume much heap memory to verify the kernel and dtbo image, memory conflicts may happen as the kernel/dtbo image size is getting larger. As the avb will load kernel/dtbo in every avb_slot_verify(), but will only free the memory after both slots are checked(if needed). And for trusty enabled platforms, extra heap memory will be used to do the hash calculation. This commit will free the slot memory once it's marked as unbootable and will use fixed memory started from CONFIG_FASTBOOT_BUF_ADDR to help store the data to do the hash calculation. With above change, we get a chance to decrease the malloc pool size. Test: boot on imx8qxp and imx8mn. Change-Id: Id95b9becf6fa7fae4f120a4dc9e9a3ba90da578c Signed-off-by: Ji Luo <ji.luo@nxp.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/avb/fsl/fsl_avb_ab_flow.c4
-rw-r--r--lib/avb/libavb/avb_slot_verify.c13
2 files changed, 5 insertions, 12 deletions
diff --git a/lib/avb/fsl/fsl_avb_ab_flow.c b/lib/avb/fsl/fsl_avb_ab_flow.c
index 5637212157..091304b67c 100644
--- a/lib/avb/fsl/fsl_avb_ab_flow.c
+++ b/lib/avb/fsl/fsl_avb_ab_flow.c
@@ -1168,6 +1168,10 @@ AvbABFlowResult avb_ab_flow_fast(AvbABOps* ab_ops,
fsl_slot_set_unbootable(&ab_data.slots[target_slot]);
set_slot_unbootable = false;
}
+ if (slot_data[target_slot] != NULL) {
+ avb_slot_verify_data_free(slot_data[target_slot]);
+ slot_data[target_slot] = NULL;
+ }
}
/* switch to another slot */
target_slot = (target_slot == 1 ? 0 : 1);
diff --git a/lib/avb/libavb/avb_slot_verify.c b/lib/avb/libavb/avb_slot_verify.c
index 2ca4ff9bd3..f682007a5e 100644
--- a/lib/avb/libavb/avb_slot_verify.c
+++ b/lib/avb/libavb/avb_slot_verify.c
@@ -313,12 +313,7 @@ static AvbSlotVerifyResult load_and_verify_hash_partition(
}
uint32_t round_buf_size = ROUND(hash_desc.salt_len + hash_desc.image_size,
ARCH_DMA_MINALIGN);
- hash_buf = memalign(ARCH_DMA_MINALIGN, round_buf_size);
- if (hash_buf == NULL) {
- avb_error("failed to alloc memory!\n");
- ret = AVB_SLOT_VERIFY_RESULT_ERROR_OOM;
- goto out;
- }
+ hash_buf = (void *)CONFIG_FASTBOOT_BUF_ADDR;
avb_memcpy(hash_buf, desc_salt, hash_desc.salt_len);
avb_memcpy(hash_buf + hash_desc.salt_len,
@@ -335,8 +330,6 @@ static AvbSlotVerifyResult load_and_verify_hash_partition(
}
digest = hash_out;
- free(hash_buf);
- hash_buf = NULL;
#else
AvbSHA256Ctx sha256_ctx;
avb_sha256_init(&sha256_ctx);
@@ -399,10 +392,6 @@ out:
free(hash_out);
hash_out = NULL;
}
- if (hash_buf != NULL) {
- free(hash_buf);
- hash_buf = NULL;
- }
#endif
/* If it worked and something was loaded, copy to slot_data. */
if ((ret == AVB_SLOT_VERIFY_RESULT_OK || result_should_continue(ret)) &&