Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp6467585yba; Wed, 1 May 2019 12:57:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqxo2An7NyL/WM5Y/kk6bSx/AXHp8o6oLi/G+AIkch9Zi/Um8la7+GzgLgzhJOxj4YWw8ens X-Received: by 2002:a65:63c3:: with SMTP id n3mr60837811pgv.170.1556740655686; Wed, 01 May 2019 12:57:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556740655; cv=none; d=google.com; s=arc-20160816; b=qOlyhNiudNUyoEOUbYPhoUaQfZGV9crvRHCq90f7Xtx4yfSJvI+vKeGU1Q1bx7J2+b Jd4KI6aYZz7vCDCFDs+2YZFUwAOfBKNi+kw2yGkb9rM+GI9+ztrHY3f2yKVixZwynhJ+ uIho/XCz6bfWUJzrhvSMIk7bfhOYcdeMlB4FR7XaHSO3Z5vNPscxWOEYNiiMCkTUeEkm E3C5xhea6fIY4yzHaJxYS2cj6pAa1q2TsJjAsUXhGaqMKXKiCU2n+u0dcxJ62aB/oTqL GSySkar6S9rCRl8qmFY4+0jUzNYNUK6yUrU2GS0jhtA2f9b7um8QNfpt7p8AujbI6TjW LZoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:ironport-sdr:ironport-sdr :dkim-signature; bh=wUL+FRPomfwdS5PpMXjIOc3K680ho/v4mBkMbRuHb7w=; b=BXuWno4+yr8tvtV5BqGtFJbVFvcF3w2igBEJzdiAUJ4rqAoLCK4UVpgWhDle50w98S 8mY2Vr2gWPLeOeaO0A7XDleNjiwd9KF5g7MAcD25b+xd+QK164MAEvZis/W7HQXPQGL0 /boOvBwWuADg3jbuR3jaPXxzH+Fg7NawUajCl57fGYo0NWVysqPgZNB2h8uW6GdT0GZl l0NeMGwf63VqgxmMbk0aPTor+jbOpMXjWgCfqwZgLJK12151kni8SDyWtpRqnIWXzKl0 Pv4IGxqrcl9QcZPwWhGO0Zly7+DTddxIf1jG0wonRLa9/HjyA3VmBiJBPs5sx5hH85ZM QyQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=WdX5uj0r; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f6si44818984plf.90.2019.05.01.12.57.19; Wed, 01 May 2019 12:57:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=WdX5uj0r; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726173AbfEAT4Z (ORCPT + 99 others); Wed, 1 May 2019 15:56:25 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:62667 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726004AbfEAT4Y (ORCPT ); Wed, 1 May 2019 15:56:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1556740584; x=1588276584; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=HiC1BhVQDcUK5m3uXFgIx1Wx/ouIkY0QSuBsbL+0D6U=; b=WdX5uj0r5xv7crksoS68bQw0kbOs8j//bOkKEbkR2hQTZdvxBMpELa2S lMdUOO3PHEz9l9c/lT26+K93nRcex7X+sqFMqtU4w5xR0jiI4/b7WqeUg I1+/vcTm2UX0Tu4bZhhKK1u/HncjkvtOKaGKahRgiLZ1IaolM62AmUB6l 93+0psj0DlNr7d7fiSi2Aia5YpgGe/Csu8xyVkM8A0323Tta5ZZagfiG8 2Vkt9WkAImKQLRBDUWOmlIWEhRITBTL4KEhezsKQgFW76Nf0lpaIA+aTw uW0u2fBFAPF/00wFfaB4oDB6vYgJgfklGTXucJ+iZbqNbC/5WE2j52OHA g==; X-IronPort-AV: E=Sophos;i="5.60,418,1549900800"; d="scan'208";a="107289431" 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; 02 May 2019 03:56:23 +0800 IronPort-SDR: QpppXnE1FEY0wGN/NLuqMb9J1bmKcLwMNXPd5dDjC2bjBrp09FASLMjXeS5oCRNHmO7syIDhWG 6s9Xho2x107ArVKNsy5jcenTLkGVHz5yRYJpMTzxieAY5gccWVJHKGoM18okPBNP7fhxH7cmD9 8k8kDWpI+BYcRi1F2SJpf2A4M00DYXcX7PjCQ5bFuQaAvp+T6Z/opKZscVLEJXdddv7v6nDpxd QX493hGezikLIuLX8YCOmQxPrEvJ3JrSHBsxSHNiEWlt1hHYxnQEBZVwBc4MeMhGoJ5fHFUwRx wmG0EcatmFe/6TFvGif4n2Pv Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP; 01 May 2019 12:32:43 -0700 IronPort-SDR: 64bfk7lvm02jAvWULVkiHb/LDqgE0xh3Jfd2ZwMXj3wwvTcqloWgF4crIPBBElJ+uAqK8WOvXg GxUEGfa4SH4uti10/WBT/xLdSi+O3g7k68OGaRp6/gZz16Zw5xg40885TNsmzlC5qXp+ZiV49e lMH/GQPI5qAMQ+xEyuHJOS2M9AeVJJlUKySfll9O+eHlzODL7TigzC3JW08F/O0U3fNi+hp1Qu CqwSo4nIIJBDkyeFwWkfE09yEdXggZGLPEc+bU8yYi5IIqRBdL45HyLwewfTwdJdk03ERuADwU QdY= Received: from jedi-01.sdcorp.global.sandisk.com (HELO jedi-01.int.fusionio.com) ([10.11.143.218]) by uls-op-cesaip01.wdc.com with ESMTP; 01 May 2019 12:56:22 -0700 From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Albert Ou , Anup Patel , linux-riscv@lists.infradead.org, Palmer Dabbelt , Zong Li , mark.rutland@arm.com, merker@debian.org Subject: [v2 PATCH] RISC-V: Add a PE/COFF compliant Image header. Date: Wed, 1 May 2019 12:56:07 -0700 Message-Id: <20190501195607.32553-1-atish.patra@wdc.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, last stage boot loaders such as U-Boot can accept only uImage which is an unnecessary additional step in automating boot flows. Add a PE/COFF compliant image header that boot loaders can parse and directly load kernel flat Image. The existing booting methods will continue to work as it is. Another goal of this header is to support EFI stub for RISC-V in future. EFI specification needs PE/COFF image header in the beginning of the kernel image in order to load it as an EFI application. In order to support EFI stub, code0 should be replaced with "MZ" magic string and res5(at offset 0x3c) should point to the rest of the PE/COFF header (which will be added during EFI support). Tested on both QEMU and HiFive Unleashed using OpenSBI + U-Boot + Linux. Signed-off-by: Atish Patra --- Changes from v1-v2: 1. Added additional reserved elements to make it fully PE compatible. --- arch/riscv/include/asm/image.h | 37 ++++++++++++++++++++++++++++++++++ arch/riscv/kernel/head.S | 30 +++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 arch/riscv/include/asm/image.h diff --git a/arch/riscv/include/asm/image.h b/arch/riscv/include/asm/image.h new file mode 100644 index 000000000000..927333ededee --- /dev/null +++ b/arch/riscv/include/asm/image.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __ASM_IMAGE_H +#define __ASM_IMAGE_H + +#define RISCV_IMAGE_MAGIC "RISCV" + +#ifndef __ASSEMBLY__ +/* + * struct riscv_image_header - riscv kernel image header + * + * @code0: Executable code + * @code1: Executable code + * @text_offset: Image load offset + * @image_size: Effective Image size + * @reserved: reserved + * @reserved: reserved + * @reserved: reserved + * @magic: Magic number + * @reserved: reserved + * @reserved: reserved (will be used for PE COFF offset) + */ + +struct riscv_image_header { + u32 code0; + u32 code1; + u64 text_offset; + u64 image_size; + u64 res1; + u64 res2; + u64 res3; + u64 magic; + u32 res4; + u32 res5; +}; +#endif /* __ASSEMBLY__ */ +#endif /* __ASM_IMAGE_H */ diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S index fe884cd69abd..12d660d929ba 100644 --- a/arch/riscv/kernel/head.S +++ b/arch/riscv/kernel/head.S @@ -19,9 +19,39 @@ #include #include #include +#include __INIT ENTRY(_start) + /* + * Image header expected by Linux boot-loaders. The image header data + * structure is described in asm/image.h. + * Do not modify it without modifying the structure and all bootloaders + * that expects this header format!! + */ + /* jump to start kernel */ + j _start_kernel + /* reserved */ + .word 0 + .balign 8 +#if __riscv_xlen == 64 + /* Image load offset(2MB) from start of RAM */ + .dword 0x200000 +#else + /* Image load offset(4MB) from start of RAM */ + .dword 0x400000 +#endif + /* Effective size of kernel image */ + .dword _end - _start + .dword 0 + .dword 0 + .dword 0 + .asciz RISCV_IMAGE_MAGIC + .word 0 + .word 0 + +.global _start_kernel +_start_kernel: /* Mask all interrupts */ csrw sie, zero -- 2.21.0