From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4E336C433EF for ; Tue, 10 May 2022 12:30:07 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E0012842D9; Tue, 10 May 2022 14:28:52 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id D08C3842FA; Tue, 10 May 2022 14:28:36 +0200 (CEST) Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 314BC842EF for ; Tue, 10 May 2022 14:20:49 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=weijie.gao@mediatek.com X-UUID: 6cfe20f720454b92971ff7e2c1b2cb84-20220510 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.4, REQID:5d476464-d1bc-4f92-ad07-e23d03687995, OB:-327 68,LOB:0,IP:0,URL:0,TC:0,Content:0,EDM:0,RT:-32768,SF:-32768,FILE:0,RULE:R elease_Ham,ACTION:release,TS:0 X-CID-META: VersionHash:faefae9, CLOUDID:87cb48b3-56b5-4c9e-8d83-0070b288eb6a, C OID:nil,Recheck:0,SF:nil,TC:nil,Content:0,EDM:-3,File:nil,QS:0,BEC:nil X-UUID: 6cfe20f720454b92971ff7e2c1b2cb84-20220510 Received: from mtkmbs11n1.mediatek.inc [(172.21.101.185)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1249048124; Tue, 10 May 2022 20:20:08 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.15; Tue, 10 May 2022 20:20:07 +0800 Received: from mcddlt001.gcn.mediatek.inc (10.19.240.15) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 10 May 2022 20:20:06 +0800 From: Weijie Gao To: CC: GSS_MTK_Uboot_upstream , =?UTF-8?q?Pali=20Roh=C3=A1r?= , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Stefan Roese , Weijie Gao Subject: [PATCH v4 22/25] spl: spl_legacy: fix the use of SPL_COPY_PAYLOAD_ONLY Date: Tue, 10 May 2022 20:20:05 +0800 Message-ID: X-Mailer: git-send-email 2.17.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain X-MTK: N X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean If the payload is compressed, SPL_COPY_PAYLOAD_ONLY should always be set since the payload will not be directly read to its load address. The payload will first be read to a temporary buffer, and then be decompressed to its load address, without image header. If the payload is not compressed, and SPL_COPY_PAYLOAD_ONLY is set, image header should be skipped on loading. Otherwise image header should also be read to its load address. Signed-off-by: Weijie Gao --- v4 changes: new --- common/spl/spl_legacy.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/common/spl/spl_legacy.c b/common/spl/spl_legacy.c index 2ec7154423..ae8731c782 100644 --- a/common/spl/spl_legacy.c +++ b/common/spl/spl_legacy.c @@ -88,15 +88,29 @@ int spl_load_legacy_img(struct spl_image_info *spl_image, /* Read header into local struct */ load->read(load, header, sizeof(hdr), &hdr); + /* + * If the payload is compressed, the decompressed data should be + * directly write to its load address. + */ + if (spl_image_get_comp(&hdr) != IH_COMP_NONE) + spl_image->flags |= SPL_COPY_PAYLOAD_ONLY; + ret = spl_parse_image_header(spl_image, bootdev, &hdr); if (ret) return ret; - dataptr = header + sizeof(hdr); - /* Read image */ switch (spl_image_get_comp(&hdr)) { case IH_COMP_NONE: + dataptr = header; + + /* + * Image header will be skipped only if SPL_COPY_PAYLOAD_ONLY + * is set + */ + if (spl_image->flags & SPL_COPY_PAYLOAD_ONLY) + dataptr += sizeof(hdr); + load->read(load, dataptr, spl_image->size, (void *)(unsigned long)spl_image->load_addr); break; @@ -104,6 +118,9 @@ int spl_load_legacy_img(struct spl_image_info *spl_image, case IH_COMP_LZMA: lzma_len = LZMA_LEN; + /* dataptr points to compressed payload */ + dataptr = header + sizeof(hdr); + debug("LZMA: Decompressing %08lx to %08lx\n", dataptr, spl_image->load_addr); src = malloc(spl_image->size); -- 2.17.1