From owner-freebsd-hackers@FreeBSD.ORG Tue May 8 09:41:25 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 0D7D71065679; Tue, 8 May 2012 09:41:25 +0000 (UTC) (envelope-from andrew@fubar.geek.nz) Received: from mailfilter12.ihug.co.nz (mailfilter12.ihug.co.nz [203.109.136.12]) by mx1.freebsd.org (Postfix) with ESMTP id 444478FC1C; Tue, 8 May 2012 09:41:24 +0000 (UTC) X-Cloudmark-SP-Filtered: true X-Cloudmark-SP-Result: v=1.0 c=1 a=2LU9hpEdpD8A:10 a=kj9zAlcOel0A:10 a=6ftCXtrV6KU8V8Uh/wkvUw==:17 a=6I5d2MoRAAAA:8 a=RAuyRO8aAAAA:8 a=Z99owlsjL6tQOCPQm5YA:9 a=QGwn88ynb5q_FL5o2zQA:7 a=CjuIK1q_8ugA:10 a=SV7veod9ZcQA:10 a=vyoC9CF5tf3hooPs:21 a=_nHp_P4zyDSC04mO:21 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av0EAF7pqE/LrZVI/2dsb2JhbABEsySBCIIMAQEEATocIxAIAxguOR4GE4gJBAy7KYsDhgkElX0BgRGNVIFdgn4 X-IronPort-AV: E=Sophos;i="4.75,549,1330858800"; d="scan'208";a="104511305" Received: from 203-173-149-72.dsl.dyn.ihug.co.nz (HELO localhost) ([203.173.149.72]) by cust.filter2.content.vf.net.nz with SMTP; 08 May 2012 21:40:14 +1200 Date: Tue, 8 May 2012 21:39:54 +1200 From: Andrew Turner To: Tim Kientzle Message-ID: <20120508213954.3c4a0c0e@fubar.geek.nz> In-Reply-To: <8B01DF29-747A-449C-A762-E852F57C6380@freebsd.org> References: <3B2A320B-3ADE-4F48-B94E-4F0886178251@freebsd.org> <201205070957.03842.jhb@freebsd.org> <8B01DF29-747A-449C-A762-E852F57C6380@freebsd.org> X-Mailer: Claws Mail 3.8.0 (GTK+ 2.24.6; i386-portbld-freebsd8.0) X-Pirate: Arrrr Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: arm@freebsd.org, freebsd-hackers@freebsd.org, John Baldwin Subject: Re: How does loader(8) decide where to load the kernel? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 May 2012 09:41:25 -0000 On Mon, 7 May 2012 22:32:10 -0700 Tim Kientzle wrote: > > On May 7, 2012, at 6:57 AM, John Baldwin wrote: > > > On Saturday, May 05, 2012 1:06:13 am Tim Kientzle wrote: > >> I have ubldr loading the ELF kernel on BeagleBone and am now > >> trying to untangle some of the hacks I used to get this working. > >> > >> Unfortunately, there's one area of the common loader(8) code > >> that I really don't understand: How does > >> sys/boot/common/load_elf.c determine the physical address at which > >> to load the kernel? > >> > >> __elfN(loadfile) has the following comment: > >> > >> [The file] will be stored at (dest). > >> > >> But that's not really true. For starters, loadfile maps dest > >> through archsw.arch_loadaddr. (This mechanism seems > >> to only be used on ia64 and pc98, though the result is > >> later discarded on those platforms.) > >> > >> Loadfile then passes the value to loadimage which does > >> very strange things: > >> > >> On i386, amd64, powerpc, and arm, loadimage subtracts > >> the dest value from the address declared in the actual ELF > >> headers so that the kernel always gets loaded into low memory. > >> (there's some intermediate bit-twiddling I'm glossing over, but > >> this is the general idea). > > > > The bit twiddling is supposed to be the equivalent of subtracting > > KERNBASE from the load address. On both i386 and amd64, there is > > a direct mapping of the kernel text such that KERNBASE maps address > > 0, etc. By default on i386 KERNBASE is 0xc0000000. > > Exactly my problem. This all assumes that you're loading > the kernel into low memory. > > On the AM3358, the DRAM starts at 0x8000 0000 > on boot, so I'm trying to find a clean way to convince > the loader's ELF code to put the kernel there. I have a script at [1] that builds an image to load the kernel directly from U-Boot. It figures out where to tell U-Boot to load a kernel by using readelf to find the value of physaddr and kernbase to use to calculate what physical addresses to use to load the kernel to and where the first instruction to execute is. Andrew [1] http://fubar.geek.nz/files/freebsd/omap/build_beagle.sh