qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Milton Miller <miltonm@bga.com>
To: "J. Mayer" <l_indien@magic.fr>
Cc: Aurelien Jarno <aurelien@aurel32.net>,
	qemu-devel <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] I got a kernel booted under qemu-system-ppc !
Date: Fri, 19 Oct 2007 12:57:34 -0500	[thread overview]
Message-ID: <a63e735c2607a82461390bf079e0a022@bga.com> (raw)
In-Reply-To: <1192751161.14048.21.camel@rapid>

On Oct 18, 2007, at 6:46 PM, J. Mayer wrote:
> On Thu, 2007-10-18 at 19:12 -0500, Rob Landley wrote:
>> The easy way to reproduce this is go to  
>> "http://landley.net/hg/firmware",
>> download tip, and "./build.sh powerpc".  When it finishes building
>> everything, cd build and "./run-powerpc.sh".
>>
> [...]
>
>> The downside is that the result boots fine under qemu-0.9.0, but is  
>> broken
>> with current cvs.  I tracked it down to the specific patch with "git  
>> bisect",
>> and it's this one:
>>
>> http://git.kernel.dk/?p=qemu.git;a=commit; 
>> h=36f447f730f61ac413c5b1c4a512781f5dea0c94
>>
>> author  j_mayer <j_mayer>
>> 	Mon, 9 Apr 2007 22:45:36 +0000 (22:45 +0000)
>> committer  j_mayer <j_mayer>
>> 	Mon, 9 Apr 2007 22:45:36 +0000 (22:45 +0000)
>
> What is strange is that it was reported as unable to boot long before
> this patch. It was broken when the Qemu PCI architecture has been
> redesigned and have never been reported booting since then (2 years  
> ago,
> if I remember well).

My job includes getting the linux kernel to run on various PowerPC  
hardware.  While searching for a small file system, I came across Rob's  
work and it was close to what I needed so I started working with it.   
Rob was having trouble getting the kernel to build and run on qemu with  
Open Hackware.

I took the approach of treating qemu as another embedded board and  
describing the hardware to the kernel.  I quickly got ide and serial  
working, and later got pci config working.  I haven't gotten pci memory  
working yet; I don't know if that is the emulation or the description.   
Since hackware can initialize the video, its probably the later.   
Here's some history.

In the linux kernel, the ppc arch is being replaced by the powerpc  
arch, which has already replaced the ppc64 arch and supports all  
powerpc processors.  The ppc arch is slated to be removed by June 2008,  
having been in process over two years.  Part of the merge process,  
however, is to standardize the entry requirements of the kernel.  The  
ppc port had been accepting data from random firmwares in random  
structures, and it promoted drivers that only worked on one platform.   
The powerpc kernel requires that this information be translated to a  
device tree, similar to that provided by Open Firmware.  By forcing the  
device tree, the drivers are loaded based on the platform supplied data  
instead of knowing the platform and searching for data.  Instead of  
requiring a client interface however, a powerpc kenrel will accept the  
information as a data structure known as the flat device tree.  In  
fact, when booted with a client interface, after interacting with  
firmware (including storing some properties in the tree ond opening  
video cards to initialize them), the kernel builds this data structure  
and restarts itself with it.  The kernel tree also provides a library  
of boot code, called the wrapper or zImage, for translating random  
firmware structures into a flattened device tree.  It also provides  
support for loading compressed kernels and combining an initrd with the  
kernel into a single image.

Rob was complaining he needed arch ppc to boot prep qemu but  
kernel_headers only worked on powerpc.  Rob choose prep because the  
header on the prep kernel was the only one that satisfied Open Hackware  
when supplied to -kernel.  About this time Dave Gibson started code to  
run prep hardware under powerpc.  It had several assumptions on what  
the machine looked like.  As I remember it, I tried Dave's port on the  
qemu 0.6.2 found on the Knoppix 4.0.2 dvd and caused qemu to segv.  I  
was not prepared to debug qemu; I assumed the assumptions were not met.

Taking a look at Open Hackware 0.4, it appears that it treats the  
memory given to -kernel as a block device.  That makes no sense to me.   
I would expect it to treat the memory as the file loaded from the block  
device.  Seeing that no updates to Open Hackware had been made in  
years, and that it only pretended to have a open firmware client  
interface and contained a mostly useless rtas (eg no pci config  
methods), I decided to try bypassing it and just give the kernel what  
it was looking for: a description of the hardware.

I choose to continue with prep because I knew the expected hardware  
much better than pmac (the heathrow emulation).  I started by mining  
Open Hackware 0.4 for information describing the hardware and its  
startup.  I found the entry point was 0xfffffffc and after a bit of  
experimentation I found qemu required the rom to be 512k and was read  
only.  I found that since there were no caches I could do IO to serial  
in real mode, which meant I didn't have to decide what to map via bats.  
  Since the zImage code runs where it starts execution, I wrote some  
code to copy the rom to ram and start it there.  With only 512k the  
zImage couldn't contain the kernel, even compressed, to support  
something like kboot or petiboot (where the first kenrel is used with  
kexec to become a bootloader), but I already had patches to use the  
kernel loaded elsewhere.  I found the code in hackware to read nvram to  
find the memory size, loaded kernel, initrd, and command line and  
taught zImage to fetch the info from nvram and modify a device tree.  I  
used David's device tree and port as a baseline to modify.  When I  
didn't find code to describe an openpic or mpic, I decided to try using  
the 8259 as the interrupt controller.  After cutting down Dave's prep  
kernel code and changing its expectations to match the device tree, I  
quickly had interrupts, serial, and ide working.

http://patchwork.ozlabs.org/linuxppc/patch?person=79&id=13140

After a peek at qemu I got the right address for pci config and had  
that working. Rob complained my instructions were too hard to follow  
and had too much unmerged code, so I split and rebased them.  The  
kernel code patched cleanly against 2.6.23 but but the zImage code  
required patches queued for 2.6.24 and about 4 more not yet accepted.   
After looking at what the wrapper was doing, I decided it was was  
easier to just write the assembly code to copy the device tree to ram,  
copy the nvram to ram, and patch the 5 or so items based on the nvram.   
That resulted in the code for the rom that Rob posted.

> In march 2007, I did test and reported that PreP
> and heathrow target were unable to boot, not receiving any IRQ from PCI
> (in fact, adding traces proves there are even no IRQ generated in the
> PCI code). Someone reported the faulty patch during this summer (but
> I've not been unable to find the mail in the mailing list archive
> tonight).

As I stated, I haven't gotten pci memory working yet; my attempt at  
using -usb on under Q 0.9.0 (the os X compiled qemu) had the linux code  
failing to reset the chip.  However, since Open Hackware can initialize  
the graphics card, its probably an error in my description of the  
memory map in the device tree.  The linux driver for the video card  
also dies, I don't know if its because of no bios, the memory map, or  
other issues.

> I have to admit I never put the focus on trying to solve this issue,  
> has
> I usually use Mac99 or PowerPC 405 targets for tests and that PreP
> machines are long obsolete and the heathrow target does not reflect any
> real machine. But this is to be solved, for sure.

 From the patch description you inserted a openpic between the 8259 and  
the cpu.  If this is true, at a minimum it will require this to be  
described to be in the device tree for linux (or in the prep residual  
data in general for hackware).  My qemu linux code wasn't expecting an  
openpic so it would need to adjust; or perhaps David's kernel code  
would now work.

 From a linux on powerpc standpoint, I don't care if we found the  
hardware with the same platform code as a real machine or if a custom  
platform and boot code to create the device tree was used.  If the  
device tree matches the standard firmware, I can use the standard linux  
platform code.  If not, I can still use all the drivers.  If qemu  
misses a piece of hardware in the platform, I can choose to modify an  
existing one or create a new one.  However, I see being able to test  
the zImage with -kernel as a requirement (be it the standard platform  
zImage or a custom one customized to qemu), and if hackware is getting  
in the way it needs to be fixed or replaced.

I can help you debug from the linux side, but I have no interest in  
debugging qemu.  To complete the port to the 0.9 prep, I need to learn  
a bit more about the actual emulated machine and how its pci is hooked  
up.

The rom I provided was aimed at running linux on the hardware I knew,  
bypassing broken firmware.  I took advantage of the hardware being  
setup (eg ram working) and do the minimum to start the loaded linux.   
This means I support the image being an elf with a single load segment  
and the entry point can run where the file is loaded.  The code could  
be extended to check the platform and jump to another copy of itself  
when it doesn't match, meaning that through chaining it would search  
until it found the device tree for the platform being emulated and then  
start the kernel with that tree.  This would allow a rom to be built  
supporting several platforms, but it requires the kernel to be loaded  
via -kernel (as I don't have any floppy or hard drive code in it).   
This approach doesn't support booting from file systems, but an  
approach using kexec with kernel in rom could.

milton

  reply	other threads:[~2007-10-19 17:58 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-19  0:12 [Qemu-devel] I got a kernel booted under qemu-system-ppc ! Rob Landley
2007-10-18 23:46 ` J. Mayer
2007-10-19 17:57   ` Milton Miller [this message]
2007-10-23  9:17     ` J. Mayer
2007-10-19  6:00 ` [Qemu-devel] " Milton Miller
2007-10-19 15:03 ` [Qemu-devel] " Aurelien Jarno
2007-10-19 15:19 ` Aurelien Jarno
2007-10-19 17:39   ` Jocelyn Mayer
2007-10-19 18:10     ` Milton Miller
2007-10-19 19:39     ` Aurelien Jarno
2007-10-19 20:33       ` Aurelien Jarno
2007-10-20  6:08         ` Rob Landley
2007-10-20  8:50           ` J. Mayer
2007-10-21  9:55             ` Rob Landley
2007-10-21 10:24               ` J. Mayer
2007-10-21 12:28                 ` J. Mayer
2007-10-21 22:37                 ` Rob Landley
2007-10-20 14:23       ` Aurelien Jarno
2007-10-20 14:49         ` Aurelien Jarno
2007-10-20 21:49           ` Aurelien Jarno
2007-10-21  9:01             ` J. Mayer
2007-10-20  7:52   ` Rob Landley
2007-10-20  9:03   ` J. Mayer
2007-10-20  9:42     ` Aurelien Jarno

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a63e735c2607a82461390bf079e0a022@bga.com \
    --to=miltonm@bga.com \
    --cc=aurelien@aurel32.net \
    --cc=l_indien@magic.fr \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).