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 );