FPGARelated.com
Forums

Booting Linux from my own bootloader

Started by Martin Brückner April 26, 2010
Hello,

I'm writing a boot loader to start Linux on the PowerPC440 (Virtex5FXT).
At first the program copies the kernel into the RAM at address
0x00400000 and afterwards it boots Linux with the following lines:

#define LINUX_START_ADDRESS 0x004002b4

int main()
{
	void (*linux)();
	linux = (void*) LINUX_START_ADDRESS;

	... // here is the code which copies the kernel into ram

	(*linux)();
}

With the following steps, booting works fine:
(1). comment out the line (*linux)();
(2). start the program
(3). start xmd and enter "rst -processor"
(4). set the program counter: "rwr pc 0x004002b4"
(5). enter "con"

What does not work:
Starting Linux directly within the program with the last line.
All I can see is the following and thats all.

zImage starting: loaded at 0x00400000 (sp: 0x00569fb0)
Allocating 0x2efa98 bytes for kernel ...
gunzipping (0x00000000 <- 0x0040d000:0x0056837e)...done 0x2d2270 bytes

Linux/PowerPC load: console=ttyUL0 root=/dev/mmcblk0p1 rootdelay=5
Finalizing device tree... flat tree at 0x576300



So the question is: What do I have to do to boot Linux from within the
program?


Best Regards
Martin Br&uuml;ckner
Martin Br?ckner <bj2spam@alice-dsl.net> wrote:
 
> I'm writing a boot loader to start Linux on the PowerPC440 (Virtex5FXT). > At first the program copies the kernel into the RAM at address > 0x00400000 and afterwards it boots Linux with the following lines:
> #define LINUX_START_ADDRESS 0x004002b4
(snip)
> (*linux)();
With the assumption that data pointers can be properly cast to function pointers, that line should jump to location 0x4002b4 and start executing the code there.
> With the following steps, booting works fine: > (1). comment out the line (*linux)(); > (2). start the program > (3). start xmd and enter "rst -processor" > (4). set the program counter: "rwr pc 0x004002b4" > (5). enter "con"
I presume that mostly starts executing at 0x4002b4?
> What does not work: > Starting Linux directly within the program with the last line. > All I can see is the following and thats all.
> zImage starting: loaded at 0x00400000 (sp: 0x00569fb0) > Allocating 0x2efa98 bytes for kernel ... > gunzipping (0x00000000 <- 0x0040d000:0x0056837e)...done 0x2d2270 bytes
> Linux/PowerPC load: console=ttyUL0 root=/dev/mmcblk0p1 rootdelay=5 > Finalizing device tree... flat tree at 0x576300
So it does start executing, and doing things that it is supposed to do, but doesn't end up working?
> So the question is: What do I have to do to boot Linux from within the > program?
-- glen
Am Mon, 26 Apr 2010 22:08:02 +0000 (UTC)
schrieb glen herrmannsfeldt <gah@ugcs.caltech.edu>:

> Martin Br?ckner <bj2spam@alice-dsl.net> wrote: > > > I'm writing a boot loader to start Linux on the PowerPC440 > > (Virtex5FXT). At first the program copies the kernel into the RAM > > at address 0x00400000 and afterwards it boots Linux with the > > following lines: > > > #define LINUX_START_ADDRESS 0x004002b4 > > (snip) > > > (*linux)(); > > With the assumption that data pointers can be properly > cast to function pointers, that line should jump to > location 0x4002b4 and start executing the code there. > > > With the following steps, booting works fine: > > (1). comment out the line (*linux)(); > > (2). start the program > > (3). start xmd and enter "rst -processor" > > (4). set the program counter: "rwr pc 0x004002b4" > > (5). enter "con" > > I presume that mostly starts executing at 0x4002b4?
Yes.
> > > What does not work: > > Starting Linux directly within the program with the last line. > > All I can see is the following and thats all. > > > zImage starting: loaded at 0x00400000 (sp: 0x00569fb0) > > Allocating 0x2efa98 bytes for kernel ... > > gunzipping (0x00000000 <- 0x0040d000:0x0056837e)...done 0x2d2270 > > bytes > > > Linux/PowerPC load: console=ttyUL0 root=/dev/mmcblk0p1 rootdelay=5 > > Finalizing device tree... flat tree at 0x576300 > > So it does start executing, and doing things that it is > supposed to do, but doesn't end up working?
Yes, exactly. When resetting the CPU before booting, everything is fine. But in this case it ends up here. At the moment I'm learning how to extract the syslog out of Linux to get messages before the console is initialized. I'll post the result here, soon.
> > > So the question is: What do I have to do to boot Linux from within > > the program? > > -- glen
-- Martin Br&uuml;ckner
On Tue, 27 Apr 2010 10:03:34 +0200, Martin Br&#4294967295;ckner
<bj2spam@alice-dsl.net> wrote:

>Am Mon, 26 Apr 2010 22:08:02 +0000 (UTC) >schrieb glen herrmannsfeldt <gah@ugcs.caltech.edu>: > >> Martin Br?ckner <bj2spam@alice-dsl.net> wrote: >> >> > I'm writing a boot loader to start Linux on the PowerPC440 >> > (Virtex5FXT). At first the program copies the kernel into the RAM >> > at address 0x00400000 and afterwards it boots Linux with the >> > following lines: >> >> > #define LINUX_START_ADDRESS 0x004002b4 >> >> (snip) >> >> > (*linux)(); >> >> With the assumption that data pointers can be properly >> cast to function pointers, that line should jump to >> location 0x4002b4 and start executing the code there.
I haven't used the PPC since the V2Pro, but... Xilinx example code typically has boilerplate to do things like invalidate caches and set up interrupt state before handing over to "real" code. It is possible that using XMD to reset the CPU does that for you. Have you covered these bases in your own code? - Brian
Martin Br=FCckner wrote:
> void (*linux)(); > ... > (*linux)();
Wouldn't the last line have to be just this? linux();
On Mon, 26 Apr 2010 22:50:19 +0200, Martin Br&uuml;ckner wrote:

> Hello, > > I'm writing a boot loader to start Linux on the PowerPC440 (Virtex5FXT). > At first the program copies the kernel into the RAM at address > 0x00400000 and afterwards it boots Linux with the following lines: > > #define LINUX_START_ADDRESS 0x004002b4 > > int main() > { > void (*linux)(); > linux = (void*) LINUX_START_ADDRESS; > > ... // here is the code which copies the kernel into ram > > (*linux)(); > } >
Did you setup the stack pointer? The above is going to try and push the return address on the stack. Compile with -S and look at the resulting asm output. [snip]
> Best Regards > Martin Br&uuml;ckner
-- Joe Chisolm Marble Falls, Tx.
Joe Chisolm <jchisolm6@earthlink.net> wrote:
> On Mon, 26 Apr 2010 22:50:19 +0200, Martin Br?ckner wrote:
>> I'm writing a boot loader to start Linux on the PowerPC440 (Virtex5FXT). >> At first the program copies the kernel into the RAM at address >> 0x00400000 and afterwards it boots Linux with the following lines:
>> #define LINUX_START_ADDRESS 0x004002b4
(snip)
>> (*linux)();
> Did you setup the stack pointer? The above is going to try and push > the return address on the stack. Compile with -S and look at the > resulting asm output.
Not knowing at all about the linux boot process, I would have assumed that one of the first thing that the booting kernel does would be to set up its own stack. It might, though, depend on a previous level of boot program to have set up a stack for it. I wouldn't expect the boot ROM to have done it, but often there are multiple levels of boot programs. -- glen
Am Tue, 27 Apr 2010 11:17:03 +0100
schrieb Brian Drummond <brian_drummond@btconnect.com>:

> On Tue, 27 Apr 2010 10:03:34 +0200, Martin Br&uuml;ckner > <bj2spam@alice-dsl.net> wrote: > > >Am Mon, 26 Apr 2010 22:08:02 +0000 (UTC) > >schrieb glen herrmannsfeldt <gah@ugcs.caltech.edu>: > > > >> Martin Br?ckner <bj2spam@alice-dsl.net> wrote: > >> > >> > I'm writing a boot loader to start Linux on the PowerPC440 > >> > (Virtex5FXT). At first the program copies the kernel into the RAM > >> > at address 0x00400000 and afterwards it boots Linux with the > >> > following lines: > >> > >> > #define LINUX_START_ADDRESS 0x004002b4 > >> > >> (snip) > >> > >> > (*linux)(); > >> > >> With the assumption that data pointers can be properly > >> cast to function pointers, that line should jump to > >> location 0x4002b4 and start executing the code there. > > I haven't used the PPC since the V2Pro, but... > > Xilinx example code typically has boilerplate to do things like > invalidate caches and set up interrupt state before handing over to > "real" code. It is possible that using XMD to reset the CPU does that > for you. > > Have you covered these bases in your own code?
When I started with this project I was sure that Linux invalidates caches and sets up the interrupt state and the comments in arch/powerpc/kernel/head_44x.S seems to confirm that (I am not deep enough into PowerPC Assembler to understand all of its code). Probably there might be a bug in this initializing code. Anyway, all I tried out yet was disabling the cache but that did not help. Do you know where to find more Xilinx-Commands to handle Cache and MMU?
> > - Brian
Martin
Am Tue, 27 Apr 2010 18:23:11 +0000 (UTC)
schrieb glen herrmannsfeldt <gah@ugcs.caltech.edu>:

> Joe Chisolm <jchisolm6@earthlink.net> wrote: > > On Mon, 26 Apr 2010 22:50:19 +0200, Martin Br?ckner wrote: > > >> I'm writing a boot loader to start Linux on the PowerPC440 > >> (Virtex5FXT). At first the program copies the kernel into the RAM > >> at address 0x00400000 and afterwards it boots Linux with the > >> following lines: > > >> #define LINUX_START_ADDRESS 0x004002b4 > (snip) > >> (*linux)(); > > > Did you setup the stack pointer? The above is going to try and push > > the return address on the stack. Compile with -S and look at the > > resulting asm output. > > Not knowing at all about the linux boot process, I would have > assumed that one of the first thing that the booting kernel does > would be to set up its own stack. > > It might, though, depend on a previous level of boot program > to have set up a stack for it. I wouldn't expect the boot > ROM to have done it, but often there are multiple levels of > boot programs. > > -- glen
As I wrote before (answering Brian), I also assumed that Linux would manage that. What I found out this day is, that the Linux syslog-buffer is empty. Martin
Am Tue, 27 Apr 2010 04:07:41 -0700 (PDT)
schrieb Marc Jet <jetmarc@hotmail.com>:

> Martin Br=FCckner wrote: > > void (*linux)(); > > ... > > (*linux)(); >=20 > Wouldn't the last line have to be just this? >=20 > linux();
The result of (*linux)() and linux() is the same.