[U-Boot] [PATCH] arm: mach-keystone: Use appended original image size in image processing
Lokesh Vutla
lokeshvutla at ti.com
Tue Jul 16 05:06:00 UTC 2019
On 13/07/19 1:03 AM, Andrew F. Davis wrote:
> When an image is signed/encrypted on K2 devices the image may get padded
> to meet alignment requirements for the signature/encryption type. The
> original size is appended as 4 bytes little-endian to the end of the
> final image.
>
> Normally the trailing extra bytes are ignored and so restoring the
> exact original size is not important. In the case of initrd the
> original size is important as the kernel uses it to look for
> additional filesystem data and can do the wrong thing when the
> size is not correct.
>
> Read off the original size and report it back from the image post
> processing stage.
>
> Signed-off-by: Andrew F. Davis <afd at ti.com>
> ---
> arch/arm/mach-keystone/mon.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm/mach-keystone/mon.c b/arch/arm/mach-keystone/mon.c
> index 51af028590..b7ffe277c1 100644
> --- a/arch/arm/mach-keystone/mon.c
> +++ b/arch/arm/mach-keystone/mon.c
> @@ -105,6 +105,7 @@ void board_fit_image_post_process(void **p_image, size_t *p_size)
> {
> int result = 0;
> void *image = *p_image;
> + uint8_t *size_image = image + (*p_size - 4);
>
> if (strncmp(image + KS2_HS_SEC_TAG_OFFSET, "KEYS", 4)) {
> printf("No signature found in image!\n");
> @@ -120,9 +121,12 @@ void board_fit_image_post_process(void **p_image, size_t *p_size)
> /*
> * Overwrite the image headers after authentication
> * and decryption. Update size to reflect removal
> - * of header.
> + * of header and restore original file size.
> */
> - *p_size -= KS2_HS_SEC_HEADER_LEN;
> + *p_size = *(size_image+0) << 0 |
> + *(size_image+1) << 8 |
> + *(size_image+2) << 16 |
> + *(size_image+3) << 24;
Instead use get_unaligned_le32(size)?
Thanks and regards,
Lokesh
> memcpy(image, image + KS2_HS_SEC_HEADER_LEN, *p_size);
>
> /*
>
More information about the U-Boot
mailing list