Grub and RAMFS (initrd)

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
narke
Member
Member
Posts: 119
Joined: Wed Dec 26, 2007 3:37 am
Location: France

Grub and RAMFS (initrd)

Post by narke »

Hello,

I'm trying to get a RAMFS for my kernel.
I load my ramfs's content as a Grub module.

But the issue is that the RAMFS data get corrupted because it's loaded in between the kernel start and the kernel end addresses.
Maybe it's a problem related with the memory manager which allocates pages.

Kernel start address: 0x201000
Kernel end address: 0x21b000
RAMFS start address: 0x20d000
RAMFS end address: 0x20d081

The code is here: http://versatile.git.sourceforge.net/gi ... -index.cgi

Can someone point out where is the problem?

Thank you.
OS for PowerPC Macs: https://github.com/narke/Einherjar
Operating system: colorForth computing environment for x86.: https://github.com/narke/Roentgenium
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Grub and RAMFS (initrd)

Post by gerryg400 »

Code: Select all

/** Physical pages descriptors array's address */
#define PAGE_DESCRIPTORS_ARRAY_ADDRESS \
  PAGE_ALIGN_UPPER_ADDRESS((uint32) (& __e_kernel))
then later ...

Code: Select all

	*out_kernel_top = PAGE_DESCRIPTORS_ARRAY_ADDRESS
			+ PAGE_ALIGN_UPPER_ADDRESS( (arg_ram_size >> X86_PAGE_SHIFT)
			* sizeof(struct physical_page_descriptor));
You are putting your page descriptor array right after your kernel and overwriting the ramfs.
If a trainstation is where trains stop, what is a workstation ?
User avatar
narke
Member
Member
Posts: 119
Joined: Wed Dec 26, 2007 3:37 am
Location: France

Re: Grub and RAMFS (initrd)

Post by narke »

Thank for your response but the RAMFS isn't placed after the kernel but between the start address and the end address of the kernel.
That's why I am confused.
OS for PowerPC Macs: https://github.com/narke/Einherjar
Operating system: colorForth computing environment for x86.: https://github.com/narke/Roentgenium
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Grub and RAMFS (initrd)

Post by gerryg400 »

narke wrote:Thank for your response but the RAMFS isn't placed after the kernel but between the start address and the end address of the kernel.
That's why I am confused.
Look at how you are calculating the end address of the kernel. Try printing & __e_kernel, PAGE_DESCRIPTORS_ARRAY_ADDRESS and out_kernel_top and you will see the answer.

EDIT: To be more specific, the RAMFS is being placed after the kernel, but then you are putting the PAGE_DESCRIPTORS_ARRAY_ADDRESS at the end of the kernel. This means that the PAGE_DESCRIPTORS_ARRAY_ADDRESS and the RAMFS are at the same place and one overwites the other. The code that returns the out_kernel_top is returning the end of PAGE_DESCRIPTORS_ARRAY_ADDRESS array, NOT the end of kernel.
If a trainstation is where trains stop, what is a workstation ?
User avatar
narke
Member
Member
Posts: 119
Joined: Wed Dec 26, 2007 3:37 am
Location: France

Re: Grub and RAMFS (initrd)

Post by narke »

You got it right, now I am able to read the correct number of files that are present in the RAMFS passed as a module to the kernel.
Now I place the PAGE_DESCRIPTORS_ARRAY_ADDRESS after the RAMSFS end address.

Many thanks
OS for PowerPC Macs: https://github.com/narke/Einherjar
Operating system: colorForth computing environment for x86.: https://github.com/narke/Roentgenium
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Grub and RAMFS (initrd)

Post by gerryg400 »

narke wrote:You got it right, now I am able to read the correct number of files that are present in the RAMFS passed as a module to the kernel.
Now I place the PAGE_DESCRIPTORS_ARRAY_ADDRESS after the RAMSFS end address.

Many thanks
Actually it was easy to spot the bug because your physical memory manager is very similar to mine. It took less than 5 mins of browsing the source tree. It's interesting that we have a similar implementation.
If a trainstation is where trains stop, what is a workstation ?
Post Reply