From: Martin Brückner on
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ückner
From: glen herrmannsfeldt on
Martin Br?ckner <bj2spam(a)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
From: Martin Brückner on
Am Mon, 26 Apr 2010 22:08:02 +0000 (UTC)
schrieb glen herrmannsfeldt <gah(a)ugcs.caltech.edu>:

> Martin Br?ckner <bj2spam(a)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ückner
From: Brian Drummond on
On Tue, 27 Apr 2010 10:03:34 +0200, Martin Br�ckner
<bj2spam(a)alice-dsl.net> wrote:

>Am Mon, 26 Apr 2010 22:08:02 +0000 (UTC)
>schrieb glen herrmannsfeldt <gah(a)ugcs.caltech.edu>:
>
>> Martin Br?ckner <bj2spam(a)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
From: Marc Jet on
Martin Brückner wrote:
> void (*linux)();
> ...
> (*linux)();

Wouldn't the last line have to be just this?

linux();