app: aboot: add padding bytes to image size
Image size added with padding bytes to make
its size as multiples of pages.
Change-Id: I87899b9774e9eff6c64d4582de01ee8bf7e40958
diff --git a/app/aboot/aboot.c b/app/aboot/aboot.c
index be347ce..87f2bac 100755
--- a/app/aboot/aboot.c
+++ b/app/aboot/aboot.c
@@ -3340,6 +3340,8 @@
struct ptable *ptable;
unsigned extra = 0;
uint64_t partition_size = 0;
+ unsigned bytes_to_round_page = 0;
+ unsigned rounded_size = 0;
if((uintptr_t)data > (UINT_MAX - sz)) {
fastboot_fail("Cannot flash: image header corrupt");
@@ -3376,9 +3378,22 @@
|| !strcmp(ptn->name, "modem"))
extra = 1;
else {
- if (sz % page_size) {
- fastboot_fail("Buffer size is not aligned to page_size");
- return;
+ rounded_size = ROUNDUP(sz, page_size);
+ bytes_to_round_page = rounded_size - sz;
+ if (bytes_to_round_page) {
+ if (((uintptr_t)data + sz ) > (UINT_MAX - bytes_to_round_page)) {
+ fastboot_fail("Integer overflow detected");
+ return;
+ }
+ if (((uintptr_t)data + sz + bytes_to_round_page) >
+ ((uintptr_t)target_get_scratch_address() + target_get_max_flash_size())) {
+ fastboot_fail("Buffer size is not aligned to page_size");
+ return;
+ }
+ else {
+ memset(data + sz, 0, bytes_to_round_page);
+ sz = rounded_size;
+ }
}
}