Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp147563imu; Fri, 16 Nov 2018 19:33:12 -0800 (PST) X-Google-Smtp-Source: AJdET5fgsta/aLn3b+zsN/3Hu/RjxkzeYAbG+aTs7NkjjQZbv9ocyvbkrrDG6F4Qg49Daytc/2Yx X-Received: by 2002:a63:a401:: with SMTP id c1mr12382048pgf.403.1542425592196; Fri, 16 Nov 2018 19:33:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542425592; cv=none; d=google.com; s=arc-20160816; b=Es+gp91F31Z/aoW3Kn4icZI4P68wR8z0pK9TfkMf21A9v8oy5PTd+ISTBCkIhmg3EV H9eVptFrshUl7I5cRi2fAaV1bmHbjyz6yeTJiuzlnGrRdJgSq8ihgBSYUqBePcRlfUYZ w/w/zZDcWK9Wh1Fhds9XwGXIXqwwRkhTrssMdRHhg6Pf+jF6RbkardCFZypTydpQMZJx TeDbXGNE5+KMB0CBJYYGm4SlMFqEjK5c2RZgjpm26X4imGcbMXc5fkWVavY+KrTRsXtR n/g76mK3fUvLI6NehAwKF3711rhOPytjT+PxddZw8ua/TALCMyJ4zb58OWOv6f7fnv3G MBKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=K01oj53zY//Z0BA80/gE8gjl/cTB0oPYwPs29CSClPw=; b=gdPSz17+E1GZ04/4IFg294IJapyBIQN9QHhKCQIqSXG6hfiV819t/dLlp704Ico6Yb 0vFi70CHb2EM/+qUS4GZAIZOG1k7KoKLEFRDsIx1+ZI86xeEzH275z4T/uV5IktNk/XC WC++wUcEXf4JsuMsRDXP3ikhWKQXaM1viFc5HyV0H0Tfo5vcbBC8hl72KyeYKvbSy3nV m6xgdByGG00fBpFL/BuMNB0pbnh1bG7xI/EgTSek85YbMKuIBlpNOxv5+4k5WorV771F +dqLQ4muIvwVlvws3ofC0UUC2MBQjfhI/3KT5+HvrUGB0R5N25Zka1h516OnsSjLssgg GQjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=CUoK7gUe; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x14-v6si14340526plr.379.2018.11.16.19.32.56; Fri, 16 Nov 2018 19:33:12 -0800 (PST) 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=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=CUoK7gUe; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729920AbeKQNr1 (ORCPT + 99 others); Sat, 17 Nov 2018 08:47:27 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:44585 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727116AbeKQNr1 (ORCPT ); Sat, 17 Nov 2018 08:47:27 -0500 Received: by mail-wr1-f67.google.com with SMTP id j17-v6so26722484wrq.11 for ; Fri, 16 Nov 2018 19:32:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=K01oj53zY//Z0BA80/gE8gjl/cTB0oPYwPs29CSClPw=; b=CUoK7gUenFo/tJNt/12HhRjGpDK6/uHBZX5B6Z6AyXrIQ6MW95+P/N3DWrd8bAkmsd xWavXJ26GyLdJiuGv8MlHvyJHRujV1e4OzKpqDe6+zvmTdviOlQfsXfdDaWd8C0bzzEF vz/b/Tui7UTqhui5avmj9WNBKnLdLBRfBupEr5edZcwzomep8cdX4GXYOCcmqYoLAGoc 8+5h71EIWOAnFJzZdww0guIFi5G6x+8TlL1VegvmD7W+NSl7y6SpRj3MmZbpIsgHePBg tla0XrdJ24ZgoMTHnlAc/GeCNdpzcsIqQ28RKfHt+9tAH0ECjV/nzU/F8k2+gxrW65r3 dHAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=K01oj53zY//Z0BA80/gE8gjl/cTB0oPYwPs29CSClPw=; b=PkR1kS6ANYpxFeN1HvV2cTtOEk1rvVB9/FPras09Dl/8mObGasDR0wlVKNSgRseyNi ekvIwXTOwT8Q5sjqNAYegd7GvGxoe/hINTrlXkLs5MgfzJj74QOiDfhU+betmmEYp8za Y0pNm35bmcw6spwueyIMwyI+qsWudQVM1L7up0tKxr8FVoBav93cOpSVX2PytVa37HsJ bHC3KqYon6T8DBugwMEi6CReSu7Gh4pElbuo2p0Ec4wdPcSQr/3gHj5xjsMQEK/bpDBN NOHTTw4nCApnUmfjcRoXcFHgl6gObKPVLs3brOkJ5+9FrRB8lZnOoeRY61LOQv6KyL/U qHqQ== X-Gm-Message-State: AA+aEWZ0zGTSp5tmJ1TDFFYuaZqoL2q+R23p1af9EBMBMi3l+9YQj4Ck MXA4vDs/wXCD9SjiB8pEnnPQnVq2hXS8UC/+FIzJNKolnL4= X-Received: by 2002:a5d:4ec4:: with SMTP id s4mr6794233wrv.187.1542425535592; Fri, 16 Nov 2018 19:32:15 -0800 (PST) MIME-Version: 1.0 References: <20181112055515.20341-1-anup@brainfault.org> In-Reply-To: From: Anup Patel Date: Sat, 17 Nov 2018 09:02:04 +0530 Message-ID: Subject: Re: [PATCH] RISC-V: Build flat and compressed kernel images To: Palmer Dabbelt Cc: Albert Ou , Atish Patra , Christoph Hellwig , linux-riscv@lists.infradead.org, "linux-kernel@vger.kernel.org List" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Nov 17, 2018 at 2:43 AM Palmer Dabbelt wrote: > > On Sun, 11 Nov 2018 21:55:15 PST (-0800), anup@brainfault.org wrote: > > This patch extends Linux RISC-V build system to build and install: > > Image - Flat uncompressed kernel image > > Image.gz - Flat and GZip compressed kernel image > > > > Quiet a few bootloaders (such as Uboot, UEFI, etc) are capable of > > booting flat and compressed kernel images. In case of Uboot, booting > > Image or Image.gz is achieved using bootm command. > > > > The flat and uncompressed kernel image (i.e. Image) is very useful > > in pre-silicon developent and testing because we can create back-door > > HEX files for RAM on FPGAs from Image. > > > > Signed-off-by: Anup Patel > > --- > > arch/riscv/Makefile | 15 ++++++++- > > arch/riscv/boot/.gitignore | 2 ++ > > arch/riscv/boot/Makefile | 33 ++++++++++++++++++ > > arch/riscv/boot/install.sh | 60 +++++++++++++++++++++++++++++++++ > > arch/riscv/kernel/head.S | 10 ++++++ > > arch/riscv/kernel/vmlinux.lds.S | 2 +- > > 6 files changed, 120 insertions(+), 2 deletions(-) > > create mode 100644 arch/riscv/boot/.gitignore > > create mode 100644 arch/riscv/boot/Makefile > > create mode 100644 arch/riscv/boot/install.sh > > > > diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile > > index d10146197533..d117a60362eb 100644 > > --- a/arch/riscv/Makefile > > +++ b/arch/riscv/Makefile > > @@ -71,10 +71,23 @@ KBUILD_CFLAGS += $(call cc-option,-mstrict-align) > > # arch specific predefines for sparse > > CHECKFLAGS += -D__riscv -D__riscv_xlen=$(BITS) > > > > +# Default target when executing plain make > > +boot := arch/riscv/boot > > +KBUILD_IMAGE := $(boot)/Image.gz > > + > > head-y := arch/riscv/kernel/head.o > > > > core-y += arch/riscv/kernel/ arch/riscv/mm/ > > > > libs-y += arch/riscv/lib/ > > > > -all: vmlinux > > +all: Image.gz > > + > > +Image: vmlinux > > + $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@ > > + > > +Image.%: Image > > + $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@ > > + > > +zinstall install: > > + $(Q)$(MAKE) $(build)=$(boot) $@ > > diff --git a/arch/riscv/boot/.gitignore b/arch/riscv/boot/.gitignore > > new file mode 100644 > > index 000000000000..8dab0bb6ae66 > > --- /dev/null > > +++ b/arch/riscv/boot/.gitignore > > @@ -0,0 +1,2 @@ > > +Image > > +Image.gz > > diff --git a/arch/riscv/boot/Makefile b/arch/riscv/boot/Makefile > > new file mode 100644 > > index 000000000000..0990a9fdbe5d > > --- /dev/null > > +++ b/arch/riscv/boot/Makefile > > @@ -0,0 +1,33 @@ > > +# > > +# arch/riscv/boot/Makefile > > +# > > +# This file is included by the global makefile so that you can add your own > > +# architecture-specific flags and dependencies. > > +# > > +# This file is subject to the terms and conditions of the GNU General Public > > +# License. See the file "COPYING" in the main directory of this archive > > +# for more details. > > +# > > +# Copyright (C) 2018, Anup Patel. > > +# Author: Anup Patel > > +# > > +# Based on the ia64 and arm64 boot/Makefile. > > +# > > + > > +OBJCOPYFLAGS_Image :=-O binary -R .note -R .note.gnu.build-id -R .comment -S > > + > > +targets := Image > > + > > +$(obj)/Image: vmlinux FORCE > > + $(call if_changed,objcopy) > > + > > +$(obj)/Image.gz: $(obj)/Image FORCE > > + $(call if_changed,gzip) > > + > > +install: > > + $(CONFIG_SHELL) $(srctree)/$(src)/install.sh $(KERNELRELEASE) \ > > + $(obj)/Image System.map "$(INSTALL_PATH)" > > + > > +zinstall: > > + $(CONFIG_SHELL) $(srctree)/$(src)/install.sh $(KERNELRELEASE) \ > > + $(obj)/Image.gz System.map "$(INSTALL_PATH)" > > diff --git a/arch/riscv/boot/install.sh b/arch/riscv/boot/install.sh > > new file mode 100644 > > index 000000000000..18c39159c0ff > > --- /dev/null > > +++ b/arch/riscv/boot/install.sh > > @@ -0,0 +1,60 @@ > > +#!/bin/sh > > +# > > +# arch/riscv/boot/install.sh > > +# > > +# This file is subject to the terms and conditions of the GNU General Public > > +# License. See the file "COPYING" in the main directory of this archive > > +# for more details. > > +# > > +# Copyright (C) 1995 by Linus Torvalds > > +# > > +# Adapted from code in arch/i386/boot/Makefile by H. Peter Anvin > > +# Adapted from code in arch/i386/boot/install.sh by Russell King > > +# > > +# "make install" script for the RISC-V Linux port > > +# > > +# Arguments: > > +# $1 - kernel version > > +# $2 - kernel image file > > +# $3 - kernel map file > > +# $4 - default install path (blank if root directory) > > +# > > + > > +verify () { > > + if [ ! -f "$1" ]; then > > + echo "" 1>&2 > > + echo " *** Missing file: $1" 1>&2 > > + echo ' *** You need to run "make" before "make install".' 1>&2 > > + echo "" 1>&2 > > + exit 1 > > + fi > > +} > > + > > +# Make sure the files actually exist > > +verify "$2" > > +verify "$3" > > + > > +# User may have a custom install script > > +if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi > > +if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi > > + > > +if [ "$(basename $2)" = "Image.gz" ]; then > > +# Compressed install > > + echo "Installing compressed kernel" > > + base=vmlinuz > > +else > > +# Normal install > > + echo "Installing normal kernel" > > + base=vmlinux > > +fi > > + > > +if [ -f $4/$base-$1 ]; then > > + mv $4/$base-$1 $4/$base-$1.old > > +fi > > +cat $2 > $4/$base-$1 > > + > > +# Install system map file > > +if [ -f $4/System.map-$1 ]; then > > + mv $4/System.map-$1 $4/System.map-$1.old > > +fi > > +cp $3 $4/System.map-$1 > > diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S > > index 711190d473d4..fe884cd69abd 100644 > > --- a/arch/riscv/kernel/head.S > > +++ b/arch/riscv/kernel/head.S > > @@ -44,6 +44,16 @@ ENTRY(_start) > > amoadd.w a3, a2, (a3) > > bnez a3, .Lsecondary_start > > > > + /* Clear BSS for flat non-ELF images */ > > + la a3, __bss_start > > + la a4, __bss_stop > > + ble a4, a3, clear_bss_done > > +clear_bss: > > + REG_S zero, (a3) > > + add a3, a3, RISCV_SZPTR > > + blt a3, a4, clear_bss > > +clear_bss_done: > > + > > /* Save hart ID and DTB physical address */ > > mv s0, a0 > > mv s1, a1 > > diff --git a/arch/riscv/kernel/vmlinux.lds.S b/arch/riscv/kernel/vmlinux.lds.S > > index ece84991609c..65df1dfdc303 100644 > > --- a/arch/riscv/kernel/vmlinux.lds.S > > +++ b/arch/riscv/kernel/vmlinux.lds.S > > @@ -74,7 +74,7 @@ SECTIONS > > *(.sbss*) > > } > > > > - BSS_SECTION(0, 0, 0) > > + BSS_SECTION(PAGE_SIZE, PAGE_SIZE, 0) > > What does this do? If bootloader is loading vmlinux ELF then it will take care of zeroing BSS and SBSS section. If we have FLAT image then the head.S has to zero-out BSS and SBSS on boot HART. The secondary/non-boot HART don't need to clear BSS and SBSS. Now with BSS_SECTION(0, 0, 0), there is no alignment constraint on start of BSS and SBSS section so the BSS zeroing code in head.S has handle unaligned BSS and SBSS (i.e. not aligned to XLEN / 8 bytes). To simplify, I have made BSS and SBSS start as page aligned and put a simple assembly code in head.S to zero-out BSS and SBSS. Of course, we can also use BSS_SECTION(16, 16, 0) but I thought of avoiding magic values and made it page aligned (like few other architectures). > > > > > EXCEPTION_TABLE(0x10) > > NOTES > > Thanks! I'm going to target this for the RCs as well: it's technically a new > feature, but it seems pretty safe -- assuming the BSS_SECTION change can be > explained to me :) Thanks, Anup