summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJi Luo <ji.luo@nxp.com>2019-12-06 17:34:46 +0800
committerJi Luo <ji.luo@nxp.com>2020-05-15 17:34:40 +0800
commitcfd8f8229560d4eeecbc964d3dc12d05e4f8eccd (patch)
tree68199d14f850e41104f50d603772874e42b72d36 /lib
parent16b10fcc1a39b35d5ff5601fc73f9ec462baf9d8 (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 imx8mm. Change-Id: Ia5cdaf9962ae1cb8b8e9bee5305205ec6d90b84a Signed-off-by: Ji Luo <ji.luo@nxp.com> (cherry picked from commit 0a299eb1a4c8c929d069cb4a0d58a096c04f09f7)
Diffstat (limited to 'lib')
-rw-r--r--lib/avb/fsl/fsl_avb_ab_flow.c4
-rw-r--r--lib/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 bd56af0fb6..de384eac7b 100644
--- a/lib/avb/fsl/fsl_avb_ab_flow.c
+++ b/lib/avb/fsl/fsl_avb_ab_flow.c
@@ -1001,6 +1001,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/libavb/avb_slot_verify.c b/lib/libavb/avb_slot_verify.c
index 4c3eec9cc6..a1ce05c8d1 100644
--- a/lib/libavb/avb_slot_verify.c
+++ b/lib/libavb/avb_slot_verify.c
@@ -398,12 +398,7 @@ static AvbSlotVerifyResult load_and_verify_hash_partition(
}
uint32_t round_buf_size = ROUND(hash_desc.salt_len + image_size_to_hash,
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,
@@ -420,8 +415,6 @@ static AvbSlotVerifyResult load_and_verify_hash_partition(
}
digest = hash_out;
- free(hash_buf);
- hash_buf = NULL;
#else
avb_sha256_init(&sha256_ctx);
avb_sha256_update(&sha256_ctx, desc_salt, hash_desc.salt_len);
@@ -485,10 +478,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)) &&