app: aboot: Read boot image header only once from mmc into RAM
Changed the mmc_read flow for reading boot image header only once
into the RAM and the same header is used for all other checks.
Change-Id: I755c42eec4d79a45d52909641c47a8d0c7d8d050
diff --git a/app/aboot/aboot.c b/app/aboot/aboot.c
index 01ca589..50a2e29 100755
--- a/app/aboot/aboot.c
+++ b/app/aboot/aboot.c
@@ -1179,13 +1179,14 @@
page_mask = page_size - 1;
}
- /* ensure commandline is terminated */
- hdr->cmdline[BOOT_ARGS_SIZE-1] = 0;
-
kernel_actual = ROUND_TO_PAGE(hdr->kernel_size, page_mask);
ramdisk_actual = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask);
image_addr = (unsigned char *)target_get_scratch_address();
+ memcpy(image_addr, (void *)buf, page_size);
+
+ /* ensure commandline is terminated */
+ hdr->cmdline[BOOT_ARGS_SIZE-1] = 0;
#if DEVICE_TREE
#ifndef OSVERSION_IN_BOOTIMAGE
@@ -1234,9 +1235,9 @@
dprintf(CRITICAL, "booimage size is greater than DDR can hold\n");
return -1;
}
-
- /* Read image without signature */
- if (mmc_read(ptn + offset, (void *)image_addr, imagesize_actual))
+ offset = page_size;
+ /* Read image without signature and header*/
+ if (mmc_read(ptn + offset, (void *)(image_addr + offset), imagesize_actual - page_size))
{
dprintf(CRITICAL, "ERROR: Cannot read boot image\n");
return -1;
@@ -1576,8 +1577,8 @@
return -1;
}
- /* ensure commandline is terminated */
- hdr->cmdline[BOOT_ARGS_SIZE-1] = 0;
+ image_addr = (unsigned char *)target_get_scratch_address();
+ memcpy(image_addr, (void *)buf, page_size);
/*
* Update the kernel/ramdisk/tags address if the boot image header
@@ -1594,6 +1595,9 @@
kernel_actual = ROUND_TO_PAGE(hdr->kernel_size, page_mask);
ramdisk_actual = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask);
+ /* ensure commandline is terminated */
+ hdr->cmdline[BOOT_ARGS_SIZE-1] = 0;
+
/* Check if the addresses in the header are valid. */
if (check_aboot_addr_range_overlap(hdr->kernel_addr, kernel_actual) ||
check_aboot_addr_range_overlap(hdr->ramdisk_addr, ramdisk_actual))
@@ -1618,8 +1622,6 @@
/* Authenticate Kernel */
if(target_use_signed_kernel() && (!device.is_unlocked))
{
- image_addr = (unsigned char *)target_get_scratch_address();
- offset = 0;
#if DEVICE_TREE
dt_actual = ROUND_TO_PAGE(dt_size, page_mask);
@@ -1659,8 +1661,9 @@
dprintf(CRITICAL, "bootimage size is greater than DDR can hold\n");
return -1;
}
- /* Read image without signature */
- if (flash_read(ptn, offset, (void *)image_addr, imagesize_actual))
+ offset = page_size;
+ /* Read image without signature and header*/
+ if (flash_read(ptn, offset, (void *)(image_addr + offset), imagesize_actual - page_size))
{
dprintf(CRITICAL, "ERROR: Cannot read boot image\n");
return -1;