From patchwork Sat Nov 9 00:13:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1192338 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 (no SPF record) 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=none dis=none) header.from=wdc.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.b="ONSPfw/I"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 478yM90hP3z9sNT for ; Sat, 9 Nov 2019 11:15:01 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id C09ACC21F8C; Sat, 9 Nov 2019 00:14:09 +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 5E050C21EB4; Sat, 9 Nov 2019 00:13:47 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 47522C21F24; Sat, 9 Nov 2019 00:13:26 +0000 (UTC) Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) by lists.denx.de (Postfix) with ESMTPS id 58CA4C21C3F for ; Sat, 9 Nov 2019 00:13:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1573258405; x=1604794405; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vG/kTKUBLMM7Qn1+tsZP+OJgg57fyQZ/r94RwBK6kPk=; b=ONSPfw/IuBCv6wtAU25vGLz69WF1ZXnOjADe05FomMypEMtMj623vIEP UFmLMaKPUeXl3ePRtOQq4HpK700H44gw9oN6V00DgeZuQg4tSIpOLaUb2 HiYdTz3nYvZyslar80kZawhTPbwVVd0FTJAIwtnL+NcqB9sF8sbjMLbsN opzU/o+s9r9hOkhnOJpCSRnpf6Ochx6ULsy3cojqcetG6aFOMXgKgl81l hH9rN+ENncEjugQw1heLHd/WfPzJFV3h56YnnuyKS/GJ6DDQIReoGl5F0 ehPFZsNEFrX9njaDGS695T1yugC3hv7guCiJBjA4uVgS6U8dZzcg8H3A6 w==; IronPort-SDR: CCPDG8ZOPiq0Sg/UWwZ0IKl25qgT0X2w2/4wfVMTWxbNhShU22mxtPSu4ieSS0y+Lb9KRlpU0x 41bIb/d5KchbjMZdxOiAMjhgQKRGWOKeEgiJ2hDxy7iqHAl/B+pPZJJ909q7wkjj9CXteSnHJ/ 2tt96e27ruVdvmAVzrJwzi7l9hK+1zFOKa8IB5T/CiNsjUu35NC9IL8V+elLgJmdgcPD2dusqg F+j5obUxEnraviA2Td/dkIiX7w6bkyvwfnshYaueGjqOEkuUZ15JQWnoHZe/deijWzESMIxXPK FuQ= X-IronPort-AV: E=Sophos;i="5.68,283,1569254400"; d="scan'208";a="123296258" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 09 Nov 2019 08:13:22 +0800 IronPort-SDR: 4Xa3m4E5mCZ6nTw7+D4DMj94osxjtjn9ST/AyffPUg/6FIK9zpAgxdCwlK6/38DrvEapd0xIg4 s6iINcDt6FWrpFTpDYGd1MsrDUzFcHqChAqTkKjWtwu68aDBy/T4lmnKkZehBZ+sHHLX+i08fs 3gwrvh+l7PLEWTuMmToH3tVSXTb8jG2dJgY8AUiCBgNcXouawwdjTqJn7N7rw/NABPz1nGys5W aigreYTzbE5mX5w/KrcFFDsJON67DBM9wSXi66i6N8uD9r7VGFTJ5ezObAAPO2ERMLd9zCsLYf G3n/uoIoKDyPU05HVsK8y8Qx Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2019 16:08:29 -0800 IronPort-SDR: OHvjcDfwhoh34PRGLZ1MzqfyobG7Nr+6PO/3DGdtLHgu3OOLsDuppouVV8356WC/iVduym7Xbr xLCphhZsiKjz3YCiJVQiyGHSIIQuj/4icBKj+5W/Twcgr85s+nvDlKSY2MhonBpxD2aF/pihk+ lBaPTX1kvxscKRrn4td1P+FsrqOY1fjfS1mBNRp9d6MrUsdfrfgOH6HkwkppjZjFuvW/6pDVC/ F3p2EcqXOygX9pYy6EIf2AeJAkuMGpJsEGgYB0GuEfgQ51OiAqfFG7doKGj6y6FmnhZCirIsAh CvA= WDCIronportException: Internal Received: from jedi-01.sdcorp.global.sandisk.com (HELO jedi-01.int.fusionio.com) ([10.11.143.218]) by uls-op-cesaip01.wdc.com with ESMTP; 08 Nov 2019 16:13:21 -0800 From: Atish Patra To: u-boot@lists.denx.de Date: Fri, 8 Nov 2019 16:13:13 -0800 Message-Id: <20191109001315.29077-2-atish.patra@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191109001315.29077-1-atish.patra@wdc.com> References: <20191109001315.29077-1-atish.patra@wdc.com> MIME-Version: 1.0 Cc: Tom Rini , Joe Hershberger , Thierry Reding , Alexander Graf , Julius Werner Subject: [U-Boot] [RFC/RFT PATCH v4 1/3] lib: kconfig: Add option to set BZIP2 compression method 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" There is no way to select BZIP2 compression method. Add it under library/compression config where all other compression related configs are present. Signed-off-by: Atish Patra Reviewed-by: Tom Rini --- lib/Kconfig | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/Kconfig b/lib/Kconfig index 3da45a5ec322..b5dcdba23014 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -385,6 +385,11 @@ config GZIP help This enables support for GZIP compression algorithm. +config BZIP2 + bool "Enable bzip2 decompression support" + help + This enables support for BZIP2 compression algorithm. + config ZLIB bool default y From patchwork Sat Nov 9 00:13:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1192339 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 (no SPF record) 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=none dis=none) header.from=wdc.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.b="qtDZv2JJ"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 478yMD1WqJz9sNT for ; Sat, 9 Nov 2019 11:15:04 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id D6E50C21E12; Sat, 9 Nov 2019 00:13:58 +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 B88B2C21F3E; Sat, 9 Nov 2019 00:13:42 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 03234C21E4F; Sat, 9 Nov 2019 00:13:27 +0000 (UTC) Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) by lists.denx.de (Postfix) with ESMTPS id 4D12AC21E63 for ; Sat, 9 Nov 2019 00:13:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1573258406; x=1604794406; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yZbmTbHdIw2C3b6n6L3k+Sj188HXtxHrk0c2Aqsj094=; b=qtDZv2JJAWj8jxQyBjqrmdRzxIPBA9WtwINRi5S6/nJ0b1opHW9wPag8 NO3ONcw9KwqKCzi41/MIJdZNHLX8TDfckZ964JZ9jCnkNx2WdeXte4mav 0a4gGJi4PoS02xY2h+bqGNJgQq1vTFpsf3UdaMMWHNu0/b9ZD40uIlSYi XL4OtdIzi0vAwJBFDA7ygzf112GclaFJesOFRVEF4iizoF5vlOq0W5fWf OFy2Too/CjBmZZMElVijL1ebsx7fMFsfKsapGWspa2yDbCH2cnDS0cw/3 3hPk0BoZhD/543JwdGVZwY3jJNSoqWrT/18q1n3wz4R72g99SVYCvJM+5 g==; IronPort-SDR: b7P9phVVNWaRLh7xSNHMjDnpy10LpfF2kchDpijBq9EjH5oXOQHrp46Za5jNe9DS9iRxWWKyxF GHSzWkMjdS0hvJior+er6GXBhpewr3Cna4OaxeLAMBfcHsNJYHwRTr5Oi14bZ8KRZhyElUvvdl xDb8R/aE3trkE/iBP+6/xTKZx2wE/R8mejJOhBSITC3Hxt+AvFAdjeQa0F+A2yr4PZkmTa4arS A6CISjRTNIxVEs681FPIbs2FDlhQn7XMREcRzfUpX3KA51mmBRuTA4EASpDHdzvudpRlebB25H oPk= X-IronPort-AV: E=Sophos;i="5.68,283,1569254400"; d="scan'208";a="123296260" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 09 Nov 2019 08:13:22 +0800 IronPort-SDR: mDuqxyyyjpqoLWMn8aaB5O8F94roA9i2QgN+JThS9+qaqD7ftWEHdHT+3pJwS13pSewdL2Hom/ 3aNyKvtdIDRozsOwObMb6+YPS/zOvx+eo+O990vI1kfZNfZFePieUpAaOWSDNRzArk1vJJYn5M 4exih5mKrVH7noDNuk1m8r3YVg4vc81eTBjxYjdzKGkiUJY4pPQdVVgpHlXofXhRjlkWYaTNXg DGHWpElnewmn9MeYSkBsyi12RHx9M1oY9vEzRc7I8AY98lX7hfnrCBN7i4RHd4St+IpaaYyD1h NtzIYorMkYwxjbWqTg9LvdNF Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2019 16:08:29 -0800 IronPort-SDR: 6RMcWiKxa1suKvs5nrQbtt6RDFszqSsmHRO73+O1t0ijz6RPdnpXxCRy/X0GuAkUWjUBaXlrkV 1NkAXM/BV0D4bWMFrRpll212IB7gE9NAU2/+7tICM9TT9uRgNNEohL1ylsiT9N+YvoHLRmziFI 9yVDUes9K/srSYHCfOp8EexQFEgGp8AnnnlMpM+8fUC1PQrp9079ZKTDMNrMG2nc45M0zP/Z+b Lyz1LuCByQCxgfyvx9LIZno94Z12KjAHgqI5x4M3IZqO5S4ZDVqWU+MzjrmAggFC28k1hk/Ivk osM= WDCIronportException: Internal Received: from jedi-01.sdcorp.global.sandisk.com (HELO jedi-01.int.fusionio.com) ([10.11.143.218]) by uls-op-cesaip01.wdc.com with ESMTP; 08 Nov 2019 16:13:22 -0800 From: Atish Patra To: u-boot@lists.denx.de Date: Fri, 8 Nov 2019 16:13:14 -0800 Message-Id: <20191109001315.29077-3-atish.patra@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191109001315.29077-1-atish.patra@wdc.com> References: <20191109001315.29077-1-atish.patra@wdc.com> MIME-Version: 1.0 Cc: Tom Rini , Joe Hershberger , Thierry Reding , Alexander Graf , Julius Werner Subject: [U-Boot] [RFC/RFT PATCH v4 2/3] image: Add a common compression type detection function. 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" Currently, there is no method that can detect compression types given a file. This is very useful where a compressed kernel image is loaded directly to the memory. Inspect initial few bytes to figure out compression type of the image. It will be used in booti method for now but can be reused any other function in future as well. Signed-off-by: Atish Patra Reviewed-by: Tom Rini --- common/image.c | 23 +++++++++++++++++++++++ include/image.h | 21 +++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/common/image.c b/common/image.c index 179eef0bd2dc..3043f0a1c2fc 100644 --- a/common/image.c +++ b/common/image.c @@ -196,6 +196,14 @@ struct table_info { const table_entry_t *table; }; +static const struct comp_magic_map image_comp[] = { + { IH_COMP_BZIP2, "bzip2", {0x42, 0x5a},}, + { IH_COMP_GZIP, "gzip", {0x1f, 0x8b},}, + { IH_COMP_LZMA, "lzma", {0x5d, 0x00},}, + { IH_COMP_LZO, "lzo", {0x89, 0x4c},}, + { IH_COMP_NONE, "none", {}, }, +}; + static const struct table_info table_info[IH_COUNT] = { { "architecture", IH_ARCH_COUNT, uimage_arch }, { "compression", IH_COMP_COUNT, uimage_comp }, @@ -401,6 +409,21 @@ static void print_decomp_msg(int comp_type, int type, bool is_xip) printf(" Uncompressing %s\n", name); } +int image_decomp_type(const unsigned char *buf, ulong len) +{ + const struct comp_magic_map *cmagic = image_comp; + + if (len < 2) + return -EINVAL; + + for (; cmagic->comp_id > 0; cmagic++) { + if (!memcmp(buf, cmagic->magic, 2)) + break; + } + + return cmagic->comp_id; +} + int image_decomp(int comp, ulong load, ulong image_start, int type, void *load_buf, void *image_buf, ulong image_len, uint unc_len, ulong *load_end) diff --git a/include/image.h b/include/image.h index c1065c06f9bd..733a6a107da8 100644 --- a/include/image.h +++ b/include/image.h @@ -447,6 +447,15 @@ typedef struct table_entry { char *lname; /* long (output) name to print for messages */ } table_entry_t; +/* + * Compression type and magic number mapping table. + */ +struct comp_magic_map { + int comp_id; + const char *name; + unsigned char magic[2]; +}; + /* * get_table_entry_id() scans the translation table trying to find an * entry that matches the given short name. If a matching entry is @@ -851,6 +860,18 @@ static inline int image_check_target_arch(const image_header_t *hdr) } #endif /* USE_HOSTCC */ +/** + * image_decomp_type() - Find out compression type of an image + * + * @buf: Address in U-Boot memory where image is loaded. + * @len: Length of the compressed image. + * @return compression type or IH_COMP_NONE if not compressed. + * + * Note: Only following compression types are supported now. + * lzo, lzma, gzip, bzip2 + */ +int image_decomp_type(const unsigned char *buf, ulong len); + /** * image_decomp() - decompress an image * From patchwork Sat Nov 9 00:13:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1192337 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 (no SPF record) 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=none dis=none) header.from=wdc.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.b="pXfhHr3y"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 478yL53W7Vz9sNT for ; Sat, 9 Nov 2019 11:14:05 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 34D6AC21F24; Sat, 9 Nov 2019 00:13: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 46697C21EE4; Sat, 9 Nov 2019 00:13:35 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id EE82DC21C3F; Sat, 9 Nov 2019 00:13:28 +0000 (UTC) Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) by lists.denx.de (Postfix) with ESMTPS id 7D14EC21E8A for ; Sat, 9 Nov 2019 00:13:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1573258406; x=1604794406; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BKyVGQZdLqIQA1+oARJlnI/rJYPS7meq9xopOvXHTXc=; b=pXfhHr3y5QihGgMUHWLEA2qzllaOQMqB5hw1x5HDsVk74MLABq+l/GUj WuL1jXj3mu9X4bKFVB8mSJmvvumGgoMAN8+/j9hjt5i9LXfhGj5wGCZCL Xh1x5j3FKJDd9bAYAaGtty3fvE6yO1r5X7mFXpzPTzO7pXhskNB/Y93jl f3gKvZbCZa6GSkvPbOFwS4Qg+mepd2L4w3H99+pzp9C356sLSFXa90MYD 7ESxrunrCB6VzfXapeCuChq49XZxeBMLIRuVKaKgytMJhf0z+UPBB6ki7 gHwaIOQ7aOaqMuGBBScutNmgTLkaW4FbtT3IEoJhvPaQnQ4m0oelclJlO A==; IronPort-SDR: e82BP7FaTkdvfK/Y0UvnnYgPGzwsOv2zX1nPaZ+rGuT+hdPeXl7d6vKCbVgTumDAjk0o/WYQrO N136HjgPFTIx9p+qc9r3Wjolp9hU0SVYSB04JnYBuh5YusxAkY6sxA1uolhMCuqto0pTtaAyPK 1dKz4fB3e5gLY3VJcdgbF7QgJF/eULO/HFRTX+Nan/fn3epaEA1sNg4//z/YlL19Krbj/zDGIb hVENFpvE0Cy+yub+4Q5Ld39eO8daobD4LAWJSChsGVAJNdaU3e/G5vcebiUGV5WAVBwlb/+sUD ixI= X-IronPort-AV: E=Sophos;i="5.68,283,1569254400"; d="scan'208";a="123296262" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 09 Nov 2019 08:13:22 +0800 IronPort-SDR: Z08leWoMV75q/436d1pdxijdkRseye7U+siNKP1JQfdFFxVjNf930Ouz43aOUXw7VkZz94L8TJ 8UW6CLvHVs6lAFu1Yk8QGY13F4PX1l8DjTT96lsVCFluMmjsvoDrWJ6SAC4thH8VZSqxQbLPwp 71xHNNKQjdrS3DGJPs9GPlTGYSqTVZnV9Wip8EnmROmzDGaiyOjT2D0Vw+e3TZdcYMcXdhc5/o ylud7QgnrRMOFaNkEEMbBXENwrn+GAtJm45VolZ73M074+xCOC59y84V4PTBeYjq/A9tXAOKwP 1bMA0JXmR5/GRtV5SieKfsuV Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2019 16:08:30 -0800 IronPort-SDR: E/gjvQjDVK/jttktOz0b0hyNuiLCfzFvOWQNPg0GMeDW6Yw52JiHeFmLDw5C+ia5NFW3Rvh+3i EDQD8PYnZdbdgJ33YYUZ1conlzUgV3QkmUpXQtfhGTJMtyGBrmjSo3VgUqUOpPjUHMapwemQNn Fsp57Ft1PWV8t+qhvrOF4GHCZt+t7fn2jiycNueQAmpa8yc5krgWgV/7vUtLprwU/CayWxQDBj 6EhTbh5luzjRi+qAMNfhe94y3Xi40xUOyYMRul2z4P3Fz5oYI0mHhiCjBYzRmdcHn6DYYuUrkx cDM= WDCIronportException: Internal Received: from jedi-01.sdcorp.global.sandisk.com (HELO jedi-01.int.fusionio.com) ([10.11.143.218]) by uls-op-cesaip01.wdc.com with ESMTP; 08 Nov 2019 16:13:22 -0800 From: Atish Patra To: u-boot@lists.denx.de Date: Fri, 8 Nov 2019 16:13:15 -0800 Message-Id: <20191109001315.29077-4-atish.patra@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191109001315.29077-1-atish.patra@wdc.com> References: <20191109001315.29077-1-atish.patra@wdc.com> MIME-Version: 1.0 Cc: Thierry Reding , Tom Rini , Joe Hershberger , Alexander Graf , Julius Werner Subject: [U-Boot] [RFC/RFT PATCH v4 3/3] image: Add compressed Image parsing support in booti. 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" Add compressed Image parsing support so that booti can parse both flat and compressed Image to boot Linux. Currently, it is difficult to calculate a safe address for every board where the compressed image can be decompressed. It is also not possible to figure out the size of the compressed file as well. Thus, user need to set two additional environment variables kernel_comp_addr_r and filesize to make this work. Following compression methods are supported for now. lzma, lzo, bzip2, gzip. lz4 support is not added as ARM64 kernel generates a lz4 compressed image with legacy header which U-Boot doesn't know how to parse and decompress. Tested on HiFive Unleashed and Qemu for RISC-V. Tested on Qemu for ARM64. Signed-off-by: Atish Patra --- I could not test this patch on any ARM64 boards due to lack of access to any ARM64 board. If anybody can test it on ARM64, that would be great. --- cmd/booti.c | 40 ++++++++++++++++++++++++++- doc/README.distro | 12 +++++++++ doc/board/sifive/fu540.rst | 55 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+), 1 deletion(-) diff --git a/cmd/booti.c b/cmd/booti.c index c36b0235df8c..cd8670a9a8db 100644 --- a/cmd/booti.c +++ b/cmd/booti.c @@ -13,6 +13,7 @@ #include #include +DECLARE_GLOBAL_DATA_PTR; /* * Image booting support */ @@ -23,6 +24,12 @@ static int booti_start(cmd_tbl_t *cmdtp, int flag, int argc, ulong ld; ulong relocated_addr; ulong image_size; + uint8_t *temp; + ulong dest; + ulong dest_end; + unsigned long comp_len; + unsigned long decomp_len; + int ctype; ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START, images, 1); @@ -37,6 +44,33 @@ static int booti_start(cmd_tbl_t *cmdtp, int flag, int argc, debug("* kernel: cmdline image address = 0x%08lx\n", ld); } + temp = map_sysmem(ld, 0); + ctype = image_decomp_type(temp, 2); + if (ctype > 0) { + dest = env_get_ulong("kernel_comp_addr_r", 16, 0); + comp_len = env_get_ulong("filesize", 16, 0); + if (!dest || !comp_len) { + puts("kernel_comp_addr_r or filesize is not provided!\n"); + return -EINVAL; + } + if (dest < gd->ram_base || dest > gd->ram_top) { + puts("kernel_comp_addr_r is outside of DRAM range!\n"); + return -EINVAL; + } + + debug("kernel image compression type %d size = 0x%08lx address = 0x%08lx\n", + ctype, comp_len, (ulong)dest); + decomp_len = comp_len * 10; + ret = image_decomp(ctype, 0, ld, IH_TYPE_KERNEL, + (void *)dest, (void *)ld, comp_len, + decomp_len, &dest_end); + if (ret) + return ret; + /* dest_end contains the uncompressed Image size */ + memmove((void *) ld, (void *)dest, dest_end); + } + unmap_sysmem((void *)ld); + ret = booti_setup(ld, &relocated_addr, &image_size, false); if (ret != 0) return 1; @@ -96,10 +130,14 @@ int do_booti(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) #ifdef CONFIG_SYS_LONGHELP static char booti_help_text[] = "[addr [initrd[:size]] [fdt]]\n" - " - boot Linux 'Image' stored at 'addr'\n" + " - boot Linux flat or compressed 'Image' stored at 'addr'\n" "\tThe argument 'initrd' is optional and specifies the address\n" "\tof an initrd in memory. The optional parameter ':size' allows\n" "\tspecifying the size of a RAW initrd.\n" + "\tCurrently only booting from gz, bz2, lzma and lz4 compression\n" + "\ttypes are supported. In order to boot from any of these compressed\n" + "\timages, user have to set kernel_comp_addr_r and filesize enviornment\n" + "\tvariables beforehand.\n" #if defined(CONFIG_OF_LIBFDT) "\tSince booting a Linux kernel requires a flat device-tree, a\n" "\tthird argument providing the address of the device-tree blob\n" diff --git a/doc/README.distro b/doc/README.distro index ab6e6f4e74be..67b49e1e4b6a 100644 --- a/doc/README.distro +++ b/doc/README.distro @@ -246,6 +246,18 @@ kernel_addr_r: A size of 16MB for the kernel is likely adequate. +kernel_comp_addr_r: + Optional. This is only required if user wants to boot Linux from a compressed + Image(.gz, .bz2, .lzma, .lzo) using booti command. It represents the location + in RAM where the compressed Image will be decompressed temporarily. Once the + decompression is complete, decompressed data will be moved kernel_addr_r for + booting. + +filesize: + Optional. This is only required if user wants to boot Linux from a compressed + Image using booti command. It represents the size of the compressed file. The + size has to at least the size of loaded image for decompression to succeed. + pxefile_addr_r: Mandatory. The location in RAM where extlinux.conf will be loaded to prior diff --git a/doc/board/sifive/fu540.rst b/doc/board/sifive/fu540.rst index 7807f5b2c128..df2c5ad8d3e3 100644 --- a/doc/board/sifive/fu540.rst +++ b/doc/board/sifive/fu540.rst @@ -138,6 +138,10 @@ load uImage. => setenv netmask 255.255.252.0 => setenv serverip 10.206.4.143 => setenv gateway 10.206.4.1 + +If you want to use a flat kernel image such as Image file + +.. code-block:: none => tftpboot ${kernel_addr_r} /sifive/fu540/Image ethernet@10090000: PHY present at 0 ethernet@10090000: Starting autonegotiation... @@ -177,6 +181,57 @@ load uImage. 1.2 MiB/s done Bytes transferred = 8867100 (874d1c hex) + +Or if you want to use a compressed kernel image file such as Image.gz + +.. code-block:: none + => tftpboot ${kernel_addr_r} /sifive/fu540/Image.gz + ethernet@10090000: PHY present at 0 + ethernet@10090000: Starting autonegotiation... + ethernet@10090000: Autonegotiation complete + ethernet@10090000: link up, 1000Mbps full-duplex (lpa: 0x3c00) + Using ethernet@10090000 device + TFTP from server 10.206.4.143; our IP address is 10.206.7.133 + Filename '/sifive/fu540/Image.gz'. + Load address: 0x84000000 + Loading: ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ########################################## + 1.2 MiB/s + done + Bytes transferred = 4809458 (4962f2 hex) + =>setenv kernel_comp_addr_r 0x90000000 + =>setenv filesize 0x500000 + +By this time, correct kernel image is loaded and required enviornment variables +are set. You can proceed to load the ramdisk and device tree from the tftp server +as well. + +.. code-block:: none => tftpboot ${ramdisk_addr_r} /sifive/fu540/uRamdisk ethernet@10090000: PHY present at 0 ethernet@10090000: Starting autonegotiation...