From patchwork Mon May 6 18:11:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1095979 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="pWGAEv9b"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44yW6T4K0Gz9s9G for ; Tue, 7 May 2019 04:12:17 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 3BEC1C21D56; Mon, 6 May 2019 18:12: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 20DA5C21C27; Mon, 6 May 2019 18:12:12 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 41E5CC21C27; Mon, 6 May 2019 18:12:10 +0000 (UTC) Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lists.denx.de (Postfix) with ESMTPS id AEB3BC21BE5 for ; Mon, 6 May 2019 18:12:08 +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=1557166352; x=1588702352; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=kSNx+lxYuo3ZB4wLZaFfiu/cEsS0WNJBcu8Rvh04o+g=; b=pWGAEv9bjPiJnUGMdLCzM9pLjkpAShMydkdNyyF8uQ65FmWOt6FHg+p9 6SVDrl7ytIm10mUTTMV2wunMI4bHKtfxqor986FO3069yFMVIghyZ/6TA AN3qM2CAsuG7pdcwwvTh8O+9EQDvhvPGXL6CmF4OEEzbEszLOX9fDSztR c+T0UNGVFVLjx4ST/vBbDshrOF07PIRszZ1XWsl7ftj0KHBLbyvfd7s9w WLCQl+tYhv8a+hS8wtS4qnFstz/DGFKir5NYJ83zWktSrWyZkKy7Oj5Nz SfmAFrp7j80pb1hBEwPUt6JIz81yskXVSRbiB72iwgPP8GoYuT6S2Wst4 A==; X-IronPort-AV: E=Sophos;i="5.60,438,1549900800"; d="scan'208";a="206907345" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 07 May 2019 02:12:29 +0800 IronPort-SDR: z0XunZtmJkSljfrd5tP8ueWICskVCtNGKbCfB5+DZ0bBYPhEBuqainiPAQeqIAUURyCweziVKd FVtCibDN0FEytYF6Nq6e1JltbNCy2hAVUFr4LeI/J+ULaC1CGdRxOfDn001BVl219TZd/IUKzI HpacjvAksAA4qwsZZJ+0haQctLpkng5Zu5sduu/Hhujb3Wh1wtqLfYLhKiEmHlL0bNB6P4Vzh3 eB1viAwAqb8WCo3HTOT4N2e5sbVcCraIEcLpYOlcyndxXeaSMDyTnnpXt1cm2J4mo1adzVHXgG 1t00uIPbzrCU48zeL36E9J/8 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 06 May 2019 10:48:14 -0700 IronPort-SDR: N4vHFeb9yilB1u5h0DfwTf9Q8su5GyfQuHxi0t6LXwH6cd7GrO+Xw5I4Q+WLargOZI/0nbJc51 +pFVB+xUHbPY0h6d2A70OerA+RcrN01QHI+tkORHVYYUPSi4GY2XI+5XoWlEb8D+JZbj0LCvOG TMs0rn7jcy87efy60PpWKc32uT1UXsg01Ve3PwIGs5EFKtHuhs323IN2HO1sNmxy7WQ4MIjvu8 TSEHm9pd7Juov5SzdvM2EMtH46LAfbarnt4zXWoocw3id+eoFiXg2yDaKVxH3nOl+Pqc37Ku6s YtI= 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; 06 May 2019 11:12:07 -0700 From: Atish Patra To: linux-kernel@vger.kernel.org Date: Mon, 6 May 2019 11:11:34 -0700 Message-Id: <20190506181134.9575-1-atish.patra@wdc.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Cc: Tom Rini , Boris Brezillon , Joe Hershberger , Alexander Graf , Michal Simek , Heinrich Schuchardt , u-boot@lists.denx.de Subject: [U-Boot] [v4 PATCH] 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. Gzip compressed Image (Image.gz) support is not enabled with this patch. https://patchwork.kernel.org/patch/10925543/ Tested on HiFive Unleashed and QEMU. Signed-off-by: Atish Patra Reviewed-by: Tom Rini Tested-by: Karsten Merker --- Changes from v3->v4 1. Rebased on top of master to avoid git am errors. Changes from v2->v3 1. Updated the image header structure as per kernel patch. 2. Removed Image.gz support as it will be added as separate RFC patch. --- arch/riscv/lib/Makefile | 1 + arch/riscv/lib/image.c | 55 +++++++++++++++++++++++++++++++++++++++++ cmd/Kconfig | 2 +- cmd/booti.c | 8 ++++-- 4 files changed, 63 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..d063beb7dfbe --- /dev/null +++ b/arch/riscv/lib/image.c @@ -0,0 +1,55 @@ +// 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 res2; /* reserved */ + uint64_t res3; /* reserved */ + uint64_t magic; /* Magic number */ + uint32_t res4; /* reserved */ + uint32_t res5; /* 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 069e0ea7300b..4e11e0f404c8 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -223,7 +223,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..5e902993865b 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 );