From patchwork Thu Apr 25 19:56:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1091070 X-Patchwork-Delegate: uboot@andestech.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=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="XVTKHYje"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44qnyY5FKRz9s4V for ; Fri, 26 Apr 2019 05:57:07 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id A0211C21E73; Thu, 25 Apr 2019 19:57:00 +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 9673BC21C2C; Thu, 25 Apr 2019 19:56:58 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 6BD2EC21C3F; Thu, 25 Apr 2019 19:56:56 +0000 (UTC) Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) by lists.denx.de (Postfix) with ESMTPS id DB2D1C21BE5 for ; Thu, 25 Apr 2019 19:56:54 +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=1556222216; x=1587758216; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=WHlRSbxA7me5FyQLAZJJgaziql7lXLR9sc/gSPj/oUc=; b=XVTKHYjeA7cGpYRVIdovdTXu3FKYRDXRSt/BuCP2ggEUezEhbmqQW/gu jP9GnwMEq+oA9ZRtZ8MTsL7fFv8FkBYHjq0uwhtsIvYMRApK2IjEDEDC8 vRCK+UzU2IQgVrvIXy9hF27g7aCkc7jsGGXsr8qa9ATGf9Dd2cieHVK/h zgpzqPzMRL1sH9QyELBQ14ulBDk59+J+Oqb5+wMXxazZcm6RmXzMRc6sL 7vuOjaGy19ZkfDv0EEz0EpipPq33mYJOcIPP3OrhhFyaLMvbDsllcS44i iQPu+iHnU/ry0dfJQDgVavWJgqnW4Q0yDGDmb8jwH5ueh6OR/Ucm0w5bX w==; X-IronPort-AV: E=Sophos;i="5.60,394,1549900800"; d="scan'208";a="111798016" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 26 Apr 2019 03:56:52 +0800 IronPort-SDR: Ib/PlNh0U8VZOuK1mXyTZXpGSTedBQhHn8vrSUU7n6F/Ntt2hv7pgXbMoUMPI6WtwnphSYAAod +mOFvSfKcidpe9oVdT74prJ/6vZpThm+2NDxOnq5sNuBAy93yiSfHM+g5+wuWC3Z1RqMujC6Vo P3SgRFbIRSrknz43KWFZa9SlPSPquHK2Ln2Ks43VyjDwrYQaHB8Ez9wIQJzGTDLIInA7saHfCE sEwdgrOTCpj+9VnFpIW16pRCG8otu6cday4qoqFKfEMgV3/2wN7edVsLs5L7YMS9weFS9Ph6+8 7tutubHHKP6Zyb5bHjuHSXJl Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP; 25 Apr 2019 12:35:29 -0700 IronPort-SDR: td4HS1n8gFNHCYyNgVAyB3Bhh5s9JGWtbIhk3Qy1x7EA3nOUxasHAih4kYBtje9w7XLBYYgLZH djxs24KOUFELs+zLKIxgq850rwbJgn2wQNPLQjU04h15Tms8nj894PfLkMLA+fFlwOtZ2GU10A rxPi9jZ6wWJFh3WYDjC4tksCJlwE+c1FJisJB3YGC0IObZv2gAR7W+0ZSEYvfBz7VGbqSkEEw9 h/i4B9ZTktqCl62G6wLi72G7o+Qqms+aPJ2NQe7lt/CKyeNhnvgsAliCAn4Q4IhQIw8/eSKRyz ZfQ= 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; 25 Apr 2019 12:56:51 -0700 From: Atish Patra To: u-boot@lists.denx.de Date: Thu, 25 Apr 2019 12:56:42 -0700 Message-Id: <20190425195643.7104-1-atish.patra@wdc.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Cc: Heinrich Schuchardt , Boris Brezillon , Michal Simek , Joe Hershberger Subject: [U-Boot] [PATCH v2 1/2] RISCV: image: Add booti support. 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" This patch adds booti support for RISC-V Linux kernel. The existing bootm method will also continue to work as it is. It depends on the following kernel patch which adds the header to the flat Image. https://patchwork.kernel.org/patch/10913869/ Tested on HiFive Unleashed and QEMU. Signed-off-by: Atish Patra --- arch/riscv/lib/Makefile | 1 + arch/riscv/lib/image.c | 53 +++++++++++++++++++++++++++++++++++++++++ cmd/Kconfig | 2 +- cmd/booti.c | 8 +++++-- 4 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 arch/riscv/lib/image.c diff --git a/arch/riscv/lib/Makefile b/arch/riscv/lib/Makefile index 1c332db436a9..6ae6ebbeafda 100644 --- a/arch/riscv/lib/Makefile +++ b/arch/riscv/lib/Makefile @@ -7,6 +7,7 @@ # Rick Chen, Andes Technology Corporation obj-$(CONFIG_CMD_BOOTM) += bootm.o +obj-$(CONFIG_CMD_BOOTI) += bootm.o image.o obj-$(CONFIG_CMD_GO) += boot.o obj-y += cache.o obj-$(CONFIG_RISCV_RDTIME) += rdtime.o diff --git a/arch/riscv/lib/image.c b/arch/riscv/lib/image.c new file mode 100644 index 000000000000..e8802007c446 --- /dev/null +++ b/arch/riscv/lib/image.c @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2019 Western Digital Corporation or its affiliates. + * Authors: + * Atish Patra + * Based on arm/lib/image.c + */ + +#include +#include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +/* ASCII version of "RISCV" defined in Linux kernel */ +#define LINUX_RISCV_IMAGE_MAGIC 0x5643534952 + +struct linux_image_h { + uint32_t code0; /* Executable code */ + uint32_t code1; /* Executable code */ + uint64_t text_offset; /* Image load offset */ + uint64_t image_size; /* Effective Image size */ + uint64_t res1; /* reserved */ + uint64_t magic; /* Magic number */ + uint32_t res2; /* reserved */ + uint32_t res3; /* reserved */ +}; + +int booti_setup(ulong image, ulong *relocated_addr, ulong *size, + bool force_reloc) +{ + struct linux_image_h *lhdr; + + lhdr = (struct linux_image_h *)map_sysmem(image, 0); + + if (lhdr->magic != LINUX_RISCV_IMAGE_MAGIC) { + puts("Bad Linux RISCV Image magic!\n"); + return -EINVAL; + } + + if (lhdr->image_size == 0) { + puts("Image lacks image_size field, error!\n"); + return -EINVAL; + } + *size = lhdr->image_size; + *relocated_addr = gd->ram_base + lhdr->text_offset; + + unmap_sysmem(lhdr); + + return 0; +} diff --git a/cmd/Kconfig b/cmd/Kconfig index 2bdbfcb3d091..d427b66d3714 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -212,7 +212,7 @@ config CMD_BOOTZ config CMD_BOOTI bool "booti" - depends on ARM64 + depends on ARM64 || RISCV default y help Boot an AArch64 Linux Kernel image from memory. diff --git a/cmd/booti.c b/cmd/booti.c index 04353b68eccc..c22ba9bae2e4 100644 --- a/cmd/booti.c +++ b/cmd/booti.c @@ -77,7 +77,11 @@ int do_booti(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) bootm_disable_interrupts(); images.os.os = IH_OS_LINUX; + #ifdef CONFIG_RISCV_SMODE + images.os.arch = IH_ARCH_RISCV; + #elif CONFIG_ARM64 images.os.arch = IH_ARCH_ARM64; + #endif ret = do_bootm_states(cmdtp, flag, argc, argv, #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH BOOTM_STATE_RAMDISK | @@ -92,7 +96,7 @@ 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 arm64 Linux Image stored in memory\n" + " - boot arm64/riscv Linux Image stored in memory\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" @@ -107,5 +111,5 @@ static char booti_help_text[] = U_BOOT_CMD( booti, CONFIG_SYS_MAXARGS, 1, do_booti, - "boot arm64 Linux Image image from memory", booti_help_text + "boot arm64/riscv Linux Image image from memory", booti_help_text ); From patchwork Thu Apr 25 19:56:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1091071 X-Patchwork-Delegate: uboot@andestech.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=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="fLtmrFi6"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44qnz54D1Sz9s3q for ; Fri, 26 Apr 2019 05:57:37 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 0D950C21E1E; Thu, 25 Apr 2019 19:57:14 +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 478A3C21DC1; Thu, 25 Apr 2019 19:56:59 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 9D7E7C21BE5; Thu, 25 Apr 2019 19:56:56 +0000 (UTC) Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) by lists.denx.de (Postfix) with ESMTPS id CCF37C21C2C for ; Thu, 25 Apr 2019 19:56:55 +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=1556222217; x=1587758217; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AruyJTIUKexqaaL+3xI2PfSH7lgFwiu1hHjnkL8PxdY=; b=fLtmrFi6vLFcWTPcVPT3zQky4lYDJ5OOgn9rEB/jI2YykQQ0Bj3Hhr09 N3VSpZesRdXA/31FdZ808y7dWmLqF9wXA/kFu1fwxpHorbEUptZyeZRDU N/IbX1yRMo8ashpWZCogeoSz+4Eu9fCN5ERH6B2Dx1cBCj+hpyHGYFc6s R+MPUqWEtormxg3NE/36tqJ9vfUJxvEgVJIqxnN2x2/N/G1sIInWc7An6 mUpt6E31CzmaoaXBeyq6Hj6nE3lXd1/OaH5fJ9AjoUBee9hkDgwfZB+WL nS6aO56xAbACGnklCXiF7WuU3r/RvqmHdrehVWJdSbJtzV+2TEwCB3hdS A==; X-IronPort-AV: E=Sophos;i="5.60,394,1549900800"; d="scan'208";a="111798019" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 26 Apr 2019 03:56:52 +0800 IronPort-SDR: aDeGkJINemnfi7bjBF+Ck0GN3ZvDroRUoTlyWOtvjVi2KO0pHwiqzxpx99ZnKUCMv3hBA70cbh /KbfEQLqfZAavkauLkgXRPbyb6/d9VLhzIMN/YZmdsx7vFE4N0wyYWzSqpZZRLK/Dg3qGHnuLj yeYi/L63L/sfY55RFSpCRTBI0XDGADB5ZsUJxfiqi6OImSWgQBM13kE5pf4KDdLa0f2oUiLqR3 HVhn3iH1zHeRiC20dWHhbMvgcKXVYJxjfTxuTltpciD6nl5Er4xbaOobCbaB1J/FWvAC2ApBx5 ZUvfS1UB6c/EvcxtqJr+KQgk Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP; 25 Apr 2019 12:35:29 -0700 IronPort-SDR: Bunr1wNQ76B6QGRs5zvw854Q+DgI03sh+B8PYCtbqzPTRWJsFtUmkh9N7UblsaZm/AgvbTpg4B NuKU5IMy/nqMGtr1nXYVlwhCqST/N+Xqaz3HM84pd0a5jOXWc/pPxbpj41jduEqmcxe6kiRU54 K7zM5G49cmkZhb2/hBjY9uEufMGcmkyxqlUZNqKybadPHj1BDcCmw2Jv3aGVv6NsPbTsdgU1qz gPc/cOReUHU8/5rmx280ix/Ca5+bF692eZNvdKvF8yvbWbGlG0TdWmuW1jZgqKrgwA1okq3kzE hbY= 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; 25 Apr 2019 12:56:51 -0700 From: Atish Patra To: u-boot@lists.denx.de Date: Thu, 25 Apr 2019 12:56:43 -0700 Message-Id: <20190425195643.7104-2-atish.patra@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190425195643.7104-1-atish.patra@wdc.com> References: <20190425195643.7104-1-atish.patra@wdc.com> MIME-Version: 1.0 Cc: Heinrich Schuchardt , Boris Brezillon , Michal Simek , Joe Hershberger Subject: [U-Boot] [PATCH v2 2/2] RISCV: image: Parse Image.gz 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 gz parsing logic so that booti can parse both Image and Image.gz. Signed-off-by: Atish Patra --- arch/riscv/lib/image.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/arch/riscv/lib/image.c b/arch/riscv/lib/image.c index e8802007c446..73ebd0da3885 100644 --- a/arch/riscv/lib/image.c +++ b/arch/riscv/lib/image.c @@ -9,6 +9,8 @@ #include #include #include +#include +#include #include #include @@ -16,6 +18,8 @@ DECLARE_GLOBAL_DATA_PTR; /* ASCII version of "RISCV" defined in Linux kernel */ #define LINUX_RISCV_IMAGE_MAGIC 0x5643534952 +#define GZ_HEADER_0 0x1f +#define GZ_HEADER_1 0x8b struct linux_image_h { uint32_t code0; /* Executable code */ @@ -32,9 +36,31 @@ int booti_setup(ulong image, ulong *relocated_addr, ulong *size, bool force_reloc) { struct linux_image_h *lhdr; + uint8_t *temp; + void *dest; + ulong dest_end; + int ret; + /* TODO: Is there a way to figure out length of compressed Image.gz ? + * Otherwise, set it to SYS_BOOTM_LEN which should be sufficient. + */ + int len = CONFIG_SYS_BOOTM_LEN; + + temp = (uint8_t *)map_sysmem(image, 0); - lhdr = (struct linux_image_h *)map_sysmem(image, 0); + if (*(temp) == GZ_HEADER_0 && *(temp+1) == GZ_HEADER_1) { + /* Need a temporary location to copy the uncompressed image */ + dest = (void *)map_sysmem(image + 8 * CONFIG_SYS_BOOTM_LEN, 0); + ret = bootm_decomp_image(IH_COMP_GZIP, 0, image, IH_TYPE_KERNEL, + dest, (void *)image, len, + CONFIG_SYS_BOOTM_LEN, &dest_end); + if (ret) + return ret; + /* dest_end contains the uncompressed Image size */ + memmove((void *) image, dest, dest_end); + unmap_sysmem(dest); + } + lhdr = (struct linux_image_h *)temp; if (lhdr->magic != LINUX_RISCV_IMAGE_MAGIC) { puts("Bad Linux RISCV Image magic!\n"); return -EINVAL;