From patchwork Fri Mar 6 00:24:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1249935 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=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.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.a=rsa-sha256 header.s=dkim.wdc.com header.b=PG2TlNTK; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48YT1f5m0tz9sPJ for ; Fri, 6 Mar 2020 11:26:14 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D7409812D3; Fri, 6 Mar 2020 01:25:44 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.b="PG2TlNTK"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B1A638129E; Fri, 6 Mar 2020 01:25:41 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) (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 AC229804CD for ; Fri, 6 Mar 2020 01:25:35 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=wdc.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=prvs=3272f33ed=atish.patra@wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1583454336; x=1614990336; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pVJFg8syYc4LYcUsrh0CfG2U6bx2JkQH6pURoqqMl3M=; b=PG2TlNTKRtGJ/qp2RfFdHL3URB+QmNS9PGPpHqdpiRQXea3ENYm4Mq1T UvjMIF42CDwZ54Qg2kA1abHfhOCQG18lH+Fz8H2ke5C7ZVChARkycu5a+ odNNcnryScPOxfI6ke0ffVWnRQg7kpdK9H7XEb+GS6W0us+VtiY4RoSfB o5f+wZKTijW7cusQpPyo/f/8USGi8SMB+bH/D6qZnuhZQt7ppwJQB7ehl orMQ7q2qEPYwdUBogYs+6ipOn82R/YrjL4BMz7d25y1Uz4vIvKvAtbo+/ o9j//P06ubPRrnLoERi5kcA/xalwLy+BQZcCVqmm3Ru0mZJA+4VTkXBJU A==; IronPort-SDR: H0DPMjvYRdq8+gYyjHZ4gFUMMM4vw7wn/CEJUIocjpN6hWXMgnIuj6BvSY49YzBsLgl6bA/IcB uBQfa5tLiY+0pGCriEsUrr+ar67kh8LY9eFGnKn6qPRGaRhDWb7iqu5GoLqk1U3+SxMe57Pu5j syVWqUVVDs9l8tf5z5hHqV0Dx3rNGqHptEeQVSFbb2gklWfhQun0UfULxqT1gjUQjSuMOdOvxY H35nFgyhSWACwhcQ2fyHc6MM2jb5fgdrG0vYTDxGLgYhA4othKsPbQ2vY98wVg+FFWS+vhYKlk nLU= X-IronPort-AV: E=Sophos;i="5.70,520,1574092800"; d="scan'208";a="132152830" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 06 Mar 2020 08:25:14 +0800 IronPort-SDR: M67jvolARdSLrhflZc3LjeCHQOzYg8731hTGRdmkq018SZqXCRpQBa3NknNmAVRGKzbJiJANPk CsGWAXEMYKJh8uQSkAfIJyTnxSGFq5Jj+lBTowbyXr6DqXLBKXRKdDt8o2srIjVOBXdalZrlPv n2/D9xyKsRRIIXV09F2ZrMedQZpwSkhEkztB5G4rsr+pRBSWnfIl1kZFHEVd2+Xf2r2da6OR6B Ss9qZ0xVRx/+ZXveOCkC+U38v87CroostnqDrLrJqjMmAI8rKplUclyFLxyAUP1ixSjGYNGffa UcRzkGS5Qv53SJ7kj1Ab71cb Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Mar 2020 16:17:24 -0800 IronPort-SDR: AIgNugWeqgwOAi3VYMl6t5rIbpr0/Wrga1CbhCeVr/PraxIAycvHMd9ScJGB5HECMy/P9jtITx Sgux+XkHHgmF2xnncyVKeQ11Hle6wvBtcyzHGz19DFUk8QVpLdY0BFOa3RgbnwWPSDQuFhbUm6 TUgHe9U7IJ14GcEsA4ESjimNvD1j5fp3rwjkqH+wecc3MsdvM/uuGSEGnRdcwwuzGXsySq8sBE drEhdP+mZYlTtG//dsenwVZX3iDo3CB+gcDXepscqFvnfC8BSd3Fp+ZkAuD5DIspCxU/+62Gqk hJc= WDCIronportException: Internal Received: from jedi-01.sdcorp.global.sandisk.com (HELO jedi-01.int.fusionio.com) ([10.11.143.218]) by uls-op-cesaip02.wdc.com with ESMTP; 05 Mar 2020 16:25:14 -0800 From: Atish Patra To: u-boot@lists.denx.de Cc: Atish Patra , Anup Patel , Bin Meng , Heinrich Schuchardt , Jagan Teki , Marek Vasut , Simon Goldschmidt , David Abdurachmanov , Tom Rini Subject: [RFT PATCH v5 3/3] image: Add compressed Image parsing support in booti. Date: Thu, 5 Mar 2020 16:24:23 -0800 Message-Id: <20200306002423.3954-4-atish.patra@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200306002423.3954-1-atish.patra@wdc.com> References: <20200306002423.3954-1-atish.patra@wdc.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.102.2 at phobos.denx.de X-Virus-Status: Clean 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 Reviewed-by: Tom Rini --- 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 de5058236e0a..4fff8cfcf69f 100644 --- a/cmd/booti.c +++ b/cmd/booti.c @@ -14,6 +14,7 @@ #include #include +DECLARE_GLOBAL_DATA_PTR; /* * Image booting support */ @@ -24,6 +25,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); @@ -38,6 +45,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("kernel_comp_size", 16, 0); + if (!dest || !comp_len) { + puts("kernel_comp_addr_r or kernel_comp_size 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; @@ -100,10 +134,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 kernel_comp_size 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..5076bebd1808 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. + +kernel_comp_size: + 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 3937222c6c6d..6dec4016adef 100644 --- a/doc/board/sifive/fu540.rst +++ b/doc/board/sifive/fu540.rst @@ -135,6 +135,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... @@ -174,6 +178,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 kernel_comp_size 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...