From patchwork Fri Jul 12 19:33:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Davis X-Patchwork-Id: 1131515 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=quarantine dis=none) header.from=ti.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ti.com header.i=@ti.com header.b="mY9cgGPh"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45ljlZ0ZpZz9sNT for ; Sat, 13 Jul 2019 05:33:43 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 0EC0BC21E3A; Fri, 12 Jul 2019 19:33:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id EC42EC21CB1; Fri, 12 Jul 2019 19:33:34 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 54FB0C21CB1; Fri, 12 Jul 2019 19:33:33 +0000 (UTC) Received: from lelv0142.ext.ti.com (lelv0142.ext.ti.com [198.47.23.249]) by lists.denx.de (Postfix) with ESMTPS id BD635C21BE5 for ; Fri, 12 Jul 2019 19:33:32 +0000 (UTC) Received: from fllv0035.itg.ti.com ([10.64.41.0]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id x6CJXUbG033702; Fri, 12 Jul 2019 14:33:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1562960010; bh=RPwY1n9DsaBjFM/rpqy1z/CO5o+osb+nM0uuP0Dz1hI=; h=From:To:CC:Subject:Date; b=mY9cgGPhIZ0XnQmvRzwD8a9tMD3Qh2vrCnTmZlMha+0cBMR0CDZBtH3Du5JTB9ktx 405RAYyqmfKSESyCpvfK+z2XCj1eOGLfXsUmATOJ+OWSoqUWLNOmYbAJma07fTaciE BaDXyE1ony2WUP/OopXBSZi0DmmD+nYIL4dCqBio= Received: from DLEE100.ent.ti.com (dlee100.ent.ti.com [157.170.170.30]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x6CJXU2Y116970 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 12 Jul 2019 14:33:30 -0500 Received: from DLEE113.ent.ti.com (157.170.170.24) by DLEE100.ent.ti.com (157.170.170.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Fri, 12 Jul 2019 14:33:30 -0500 Received: from lelv0326.itg.ti.com (10.180.67.84) by DLEE113.ent.ti.com (157.170.170.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5 via Frontend Transport; Fri, 12 Jul 2019 14:33:30 -0500 Received: from legion.dal.design.ti.com (legion.dal.design.ti.com [128.247.22.53]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id x6CJXUek104311; Fri, 12 Jul 2019 14:33:30 -0500 Received: from localhost ([10.250.81.153]) by legion.dal.design.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id x6CJXTa23258; Fri, 12 Jul 2019 14:33:29 -0500 (CDT) From: "Andrew F. Davis" To: Tom Rini , Lokesh Vutla , Andreas Dannenberg Date: Fri, 12 Jul 2019 15:33:25 -0400 Message-ID: <20190712193325.23019-1-afd@ti.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH] arm: mach-keystone: Use appended original image size in image processing X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" 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 --- 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; memcpy(image, image + KS2_HS_SEC_HEADER_LEN, *p_size); /*