From patchwork Tue Apr 23 23:36:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1089831 X-Patchwork-Delegate: marek.vasut@gmail.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="AyNzI1oI"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44pfxH5P4Jz9sBp for ; Wed, 24 Apr 2019 09:37:05 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id C8799C21DA2; Tue, 23 Apr 2019 23:36:57 +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 44216C21C2C; Tue, 23 Apr 2019 23:36:55 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id D7539C21C27; Tue, 23 Apr 2019 23:36:53 +0000 (UTC) Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lists.denx.de (Postfix) with ESMTPS id BB8E2C21C2C for ; Tue, 23 Apr 2019 23:36:52 +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=1556062613; x=1587598613; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=HUi3qNPqiPMD4C/1RyZeLvnXNBGI/8eHN+ZKkKBv3UE=; b=AyNzI1oIU4wtFlXFbvBaaX+9KaaPufW7zQYvKoQcLxx8xLzN3ewoAWr7 deWRiModLPrDAU4D5a9+ddRCI2JBAznH3BZCm4sVX1fEh1fQgCxz1T4rO jdzyDidKymqsNuMcdmxzDKteWmpxsdYgtTtTHvz5LzjqymmKzzUaFoDRa EN2j17pDjV2nvZqXRrKUubk6mGGRwQy5oZfKp/AmKh9uVvxwJVFxdTvUy IiulvEsheuWUwtd9BPJcoWa1mA/WHBJu0KI2x8WqEq4bX6dXaWEPIVSSs hbX8yXZ38cEZAHdVN+knUSxKX5TmB+ncw2t/9ZMgu9GrqHz+5cAxT4VLB Q==; X-IronPort-AV: E=Sophos;i="5.60,387,1549900800"; d="scan'208";a="106648274" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 24 Apr 2019 07:36:51 +0800 IronPort-SDR: FIWNhNpr2VvWsuz21+iqgF3TRzs2OINh/MCQAWmYpedgI09fQ3vK2noa08TK8aw3zLGhf93aDB HpGgU3oBStzptU5l2oXD9Dd5jEQMn8YP6Fpu/0syCwT9vinYJK0w12ZCuVa74FbVNCKxvHZmXC HyuQKiv3T94HKbz15PMVyKbPGz7sr//B1ACrgCxagIV46y3B6ZzMO8JQ6nFeag0mln4BOuWPEW DHj1BDLgpBdzYPyvicYDOpfnrB4KmXf7PMojfQosuD1Sk92wLBYhC9dTqmP4U1aBN09NZor5ZM WsT0ecEF+whdR8zNtJqAUDMf Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP; 23 Apr 2019 16:15:31 -0700 IronPort-SDR: QOAdaN5cp8TVnXWI3sxpyRkQtJysDbJwIurgKOtebzzWd/nioTNB0aCeysxlY8OfsUSERzvRP5 zev22Ep/AKHbGsGLX3twmJ13u+woibA2MQxz+aVDKi09uqFnigaAifmdoH0HdwQQYTzIpx+dYn 33Mtl9obzhMqABsSysG4DVYDfIm/AQulVVgFaNG4WLpQKR90LsLZraL3qqBoI4EUN1+45NzyqZ tNIvsOznL3CkJhfgtpO2w0Y6TuDNuSjmy5mhIH1mv7glMBAQWBom42DGEPiNZNr6zN3sukrBZ/ Lkw= 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; 23 Apr 2019 16:36:51 -0700 From: Atish Patra To: u-boot@lists.denx.de Date: Tue, 23 Apr 2019 16:36:49 -0700 Message-Id: <20190423233649.12893-1-atish.patra@wdc.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Cc: Michal Simek , Joe Hershberger , Heinrich Schuchardt , Alexander Graf Subject: [U-Boot] [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. https://patchwork.kernel.org/patch/10913869/ Tested on HiFive Unleashed and QEMU. Currently, compressed images such as Image.gz are not supported. Signed-off-by: Atish Patra --- arch/riscv/lib/Makefile | 1 + arch/riscv/lib/image.c | 60 +++++++++++++++++++++++++++++++++++++++++ cmd/Kconfig | 2 +- cmd/booti.c | 8 ++++-- 4 files changed, 68 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..99c2e31066a3 --- /dev/null +++ b/arch/riscv/lib/image.c @@ -0,0 +1,60 @@ +// 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 + +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; + uint64_t dst; + uint64_t image_size, text_offset; + + *relocated_addr = image; + + lhdr = (struct linux_image_h *)map_sysmem(image, 0); + + if (lhdr->magic != LINUX_RISCV_IMAGE_MAGIC) { + puts("Bad Linux RISCV Image magic!\n"); + return 1; + } + + if (lhdr->image_size != 0) { + image_size = lhdr->image_size; + text_offset = lhdr->text_offset; + } else { + puts("Image lacks image_size field, Error!!\n"); + return 1; + } + *size = image_size; + dst = gd->ram_base; + *relocated_addr = dst + 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 );