From owner-svn-src-head@freebsd.org Tue Feb 4 00:06:17 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 37F0F2340C9; Tue, 4 Feb 2020 00:06:17 +0000 (UTC) (envelope-from arichardson@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48BQ2x0n62z4Lj4; Tue, 4 Feb 2020 00:06:17 +0000 (UTC) (envelope-from arichardson@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id EDEC48E7E; Tue, 4 Feb 2020 00:06:16 +0000 (UTC) (envelope-from arichardson@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 01406GR0041223; Tue, 4 Feb 2020 00:06:16 GMT (envelope-from arichardson@FreeBSD.org) Received: (from arichardson@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 01406Ghl041221; Tue, 4 Feb 2020 00:06:16 GMT (envelope-from arichardson@FreeBSD.org) Message-Id: <202002040006.01406Ghl041221@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: arichardson set sender to arichardson@FreeBSD.org using -f From: Alex Richardson Date: Tue, 4 Feb 2020 00:06:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r357480 - head/sys/conf X-SVN-Group: head X-SVN-Commit-Author: arichardson X-SVN-Commit-Paths: head/sys/conf X-SVN-Commit-Revision: 357480 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Feb 2020 00:06:17 -0000 Author: arichardson Date: Tue Feb 4 00:06:16 2020 New Revision: 357480 URL: https://svnweb.freebsd.org/changeset/base/357480 Log: Set the LMA of the riscv kernel to the OpenSBI jump target by default This allows us to boot FreeBSD RISCV on QEMU using the -kernel command line options. When using that option, QEMU maps the kernel ELF file to the addresses specified in the LMAs in the program headers. Since version 4.2 QEMU ships with OpenSBI fw_jump by default so this allows booting FreeBSD using the following command line: qemu-system-riscv64 -bios default -kernel /.../boot/kernel/kernel -nographic -M virt Without this change the -kernel option cannot be used since the LMAs start at address zero and QEMU already maps a ROM to these low physical addresses. For targets that require a different kernel LMA the make variable KERNEL_LMA can be overwritten in the config file. For example, adding `makeoptions KERNEL_LMA=0xc0200000` will create an ELF file that will be loaded at 0xc0200000. Before: There are 4 program headers, starting at offset 64 Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align LOAD 0x001000 0xffffffc000000000 0x0000000000000000 0x75e598 0x8be318 RWE 0x1000 DYNAMIC 0x71fb20 0xffffffc00071eb20 0x000000000071eb20 0x000100 0x000100 RW 0x8 GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0x0 NOTE 0x693400 0xffffffc000692400 0x0000000000692400 0x000024 0x000024 R 0x4 After: There are 4 program headers, starting at offset 64 Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align LOAD 0x001000 0xffffffc000000000 0x0000000080200000 0x734198 0x893e18 RWE 0x1000 DYNAMIC 0x6f7810 0xffffffc0006f6810 0x00000000808f6810 0x000100 0x000100 RW 0x8 GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0x0 NOTE 0x66ca70 0xffffffc00066ba70 0x000000008086ba70 0x000024 0x000024 R 0x4 Reviewed By: br, mhorne (earlier version) Differential Revision: https://reviews.freebsd.org/D23436 Modified: head/sys/conf/Makefile.riscv head/sys/conf/ldscript.riscv Modified: head/sys/conf/Makefile.riscv ============================================================================== --- head/sys/conf/Makefile.riscv Mon Feb 3 23:50:29 2020 (r357479) +++ head/sys/conf/Makefile.riscv Tue Feb 4 00:06:16 2020 (r357480) @@ -28,8 +28,17 @@ S= ../../.. INCLUDES+= -I$S/contrib/libfdt +# Set the ELF LMA to the address that OpenSBI's fw_jump jumps to. This allows +# us to load the kernel with the -kernel flag in QEMU without having to embed +# it inside BBL or OpenSBI's fw_payload first. +# Note: For rv32 the start address is different (0x80400000). +# We set this value using --defsym rather than hardcoding it in ldscript.riscv +# so that different kernel configs can override the load address. +KERNEL_LMA?= 0x80200000 + SYSTEM_LD= @${LD} -N -m ${LD_EMULATION} -Bdynamic -T ${LDSCRIPT} ${_LDFLAGS} \ --no-warn-mismatch --warn-common --export-dynamic \ + --defsym='kernel_lma=${KERNEL_LMA}' \ --dynamic-linker /red/herring \ -o ${.TARGET} -X ${SYSTEM_OBJS} vers.o Modified: head/sys/conf/ldscript.riscv ============================================================================== --- head/sys/conf/ldscript.riscv Mon Feb 3 23:50:29 2020 (r357479) +++ head/sys/conf/ldscript.riscv Tue Feb 4 00:06:16 2020 (r357480) @@ -7,7 +7,8 @@ SECTIONS { /* Read-only sections, merged into text segment: */ . = kernbase; - .text : AT(ADDR(.text) - kernbase) + /* The load address kernel_lma is set using --defsym= on the command line. */ + .text : AT(kernel_lma) { *(.text) *(.stub)