RibShark
Posts: 9
Joined: Wed Jul 04, 2012 6:10 pm

Use initramfs?

Sat Jul 07, 2012 4:51 pm

Hello! I am currently trying to use Plymouth on my Pi so I can have a Epic Splash Screen of Epicness! (r) (tm). However Plymouth requires that I use an initramfs. How can I provide the Pi this? I have heard you can patch it into the kernel however this isn't an option for me as I may constantly update my initramfs file and it would take too long to patch (and I'm a new linux user).

Is there any way of getting the Pi to use this file?

kadamski
Posts: 187
Joined: Fri Jun 08, 2012 10:56 pm

Re: Use initramfs?

Sat Jul 07, 2012 11:10 pm

There is a special option in config.txt called "ramfsfile". You can use it to point to your initramfs file, like this:

Code: Select all

ramfsfile=init.gz
There is, however, one problem - bootloader won't pass ATAG_INITRD2 to kernel so you have to tell it where to find this image in memory. First, you need to know where it actually is. By default, bootloader will put it just after kernel image, which should be stored at 0x8000 so you should be able to calculate proper address manually. I don't do that because the size of my kernel build changes all the time so i just force bootloader to put the file in some known location, ensuring it won't overwrite the kernel itself. I use address 0x00a00000 and option called ramfsaddr, like this:

Code: Select all

ramfsfile=init.gz
ramfsaddr=0x00a00000
Now all you have to do is to provide information about location and size of initramfs file to the kernel (as I said, unfortunetly it is not currently done by the bootloader). You will use cmdline.txt file for this whre you should append something like:

Code: Select all

initrd=0xa00000,0x654da9
Where "0x654da9" is the size of initramfs file in bytes.

Note: you should check if your kernel does support initramfs file (from /proc/config.gz) and if it is, what compression types are enabled. I don't remember what is defaults kernel configuration.

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5257
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: Use initramfs?

Sat Jul 07, 2012 11:55 pm

kadamski wrote: There is, however, one problem - bootloader won't pass ATAG_INITRD2 to kernel
I can look into this if you're able to test.

kadamski
Posts: 187
Joined: Fri Jun 08, 2012 10:56 pm

Re: Use initramfs?

Sun Jul 08, 2012 8:04 am

No problem for me. Just let me know how can I help.

RibShark
Posts: 9
Joined: Wed Jul 04, 2012 6:10 pm

Re: Use initramfs?

Sun Jul 08, 2012 9:24 am

kadamski wrote:Note: you should check if your kernel does support initramfs file (from /proc/config.gz) and if it is, what compression types are enabled. I don't remember what is defaults kernel configuration.
My kernel appears not to. What kernel do you use that allows it?

kadamski
Posts: 187
Joined: Fri Jun 08, 2012 10:56 pm

Re: Use initramfs?

Sun Jul 08, 2012 9:52 am

I'm using custom one compiled by myself. You can find sources of official kernel at https://github.com/raspberrypi/linux

User avatar
jojopi
Posts: 3069
Joined: Tue Oct 11, 2011 8:38 pm

Re: Use initramfs?

Sun Jul 08, 2012 11:02 am

kadamski wrote: ramfsfile=init.gz
ramfsaddr=0x00a00000
You can also use "initramfs init.gz 0x00a00000". But this does not appear to pass the ATAG either.
Note: you should check if your kernel does support initramfs file (from /proc/config.gz) and if it is, what compression types are enabled. I don't remember what is defaults kernel configuration.
Indeed. The kernel documentation makes it sound as though initramfs support cannot be disabled. But actually you do need CONFIG_BLK_DEV_INITRD. (Despite the fact that initramfs is not the same as initramdisk, and is not a block device.) And CONFIG_RD_GZIP or such for the compression.

kadamski
Posts: 187
Joined: Fri Jun 08, 2012 10:56 pm

Re: Use initramfs?

Sun Jul 08, 2012 11:13 am

Well, CONFIG_BLK_DEV_INITRD can be confusing name but it has a title "Initial RAM filesystem and RAM disk (initramfs/initrd) support" which does explain that it is for both initrd and initramfs.

nidO
Posts: 22
Joined: Sun Jun 03, 2012 3:58 pm

Re: Use initramfs?

Sun Jul 08, 2012 11:41 am

Just a note on this, you can happily patch an initramfs directly into your kernel without much bother even if you are updating the initramfs regularly - As long as you arent changing the kernel itself, adding a new/changed initramfs to the kernel on-device takes a few minutes at most.

kadamski
Posts: 187
Joined: Fri Jun 08, 2012 10:56 pm

Re: Use initramfs?

Thu Jul 12, 2012 10:39 am

dom wrote:I can look into this if you're able to test.
Did you look into this? Or maybe you still plan doing it but had no time yet? Just wanted to know you didn't forget about this since I know you have a lot of other work.

User avatar
AndrewS
Posts: 3625
Joined: Sun Apr 22, 2012 4:50 pm
Location: Cambridge, UK
Contact: Website

Re: Use initramfs?

Thu Jul 12, 2012 11:16 am

jojopi wrote:
kadamski wrote: ramfsfile=init.gz
ramfsaddr=0x00a00000
You can also use "initramfs init.gz 0x00a00000". But this does not appear to pass the ATAG either.
Hmmm, more settings missing from http://elinux.org/RPi_config.txt :(
(I won't update the page myself, as I wouldn't know how to accurately describe the options)

kadamski
Posts: 187
Joined: Fri Jun 08, 2012 10:56 pm

Re: Use initramfs?

Thu Jul 12, 2012 11:37 am

I've created an account and updated the wiki.

User avatar
AndrewS
Posts: 3625
Joined: Sun Apr 22, 2012 4:50 pm
Location: Cambridge, UK
Contact: Website

Re: Use initramfs?

Thu Jul 12, 2012 12:20 pm

Just done some searching, and also found http://www.raspberrypi.org/phpBB3/viewt ... =24&t=1569 which mentions a "initramfs <filename> followkernel" option too, but says that it isn't currently usable.

kadamski
Posts: 187
Joined: Fri Jun 08, 2012 10:56 pm

Re: Use initramfs?

Thu Jul 12, 2012 12:31 pm

Yes, but as dom said, right now "followkernel" is not that usefull since you are not able to tell your kernel where to find it. Unless it's easy to calculate it.. But i don't know how. We know where the kernel is loaded, we know it's size, but does this mean that using followkernel option, initramfs is loaded at 0x8000+$kernel_size? I think I tried using this address for image and kernel complained that it is reserved region. Also, I'm not sure how this would work for compressed kernel, i have to check where is kernel decompressed at boot... Anyways, having ATAG_INITRD2 working would be great for anybody wanting to use initramfs as a seperate file.

kadamski
Posts: 187
Joined: Fri Jun 08, 2012 10:56 pm

Re: Use initramfs?

Thu Jul 12, 2012 6:16 pm

jojopi wrote:You can also use "initramfs init.gz 0x00a00000".
Just noticed that when trying to use this option (after several power cycles with only colorful-booting-error-screen) - theres no "=" character here. So this option, somehow, uses different syntax than any other options. I'm wondering if we ever get the full list of supported options.

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5257
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: Use initramfs?

Fri Jul 13, 2012 4:14 pm

Anyone who wants to try testing
https://dl.dropbox.com/u/3669512/temp/start_initrd.elf

(rename to start.elf). It should fill in the ATAG_INITRD2.

Note: start.elf knows nothing about compressed kernels.
followkernel will just load the initramfs blob after the kernel blob and report through the ATAG where it is loaded.

kadamski
Posts: 187
Joined: Fri Jun 08, 2012 10:56 pm

Re: Use initramfs?

Fri Jul 13, 2012 4:55 pm

Dom, thanks for your work on this. Here's the report:
1. It does fill ATAG_INITRD2:

Code: Select all

# /root/atagparser.py 
ATAG_CORE: flags: 0x0, pagesize: 0x0, rootdev: 0x0
ATAG_MEM: size: 0x8000000(131072KB), start: 0x0
ATAG_INITRD2: start: 0x4b3000, size: 0x655000(6484KB)
ATAG_CMDLINE: "dma.dmachans=0x3c bcm2708_fb.fbwidth=1024 bcm2708_fb.fbheight=768 bcm2708.boardrev=0x2 bcm2708.serial=0xf86dc374 smsc95xx.macaddr=B8:27:EB:6D:C3:74 dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p3 rootfstype=ext4 elevator=noop rootwait"
2. Unfortunatly, the size that is reported by ATAG_INITRD2 is wrong which gives me this in dmesg:

Code: Select all

Trying to unpack rootfs image as initramfs...
rootfs image is not initramfs (junk in compressed archive); looks like an initrd
RAMDISK: incomplete write (8285 != 17841)
write error
The real size of my image is 0x654da9 so it seems you are rounding it to a page size. Start of the image must be aligned to page size but the size has to be real one with byte accuracy.

3. followkernel option (which is default if you don't give an address to intiramfs option, is not working for linux kernel. As I previously said, it produces this error:

Code: Select all

INITRD: 0x004b3000+0x00655000 overlaps in-use memory region - disabling initrd
This is not a problem for me since I can easly change the address but it might be better to have working default. Typical address for loading initramfs into is 8MB from base address. It has to fit compressed and decompressed kernel however, so I like to use 0x00800000. You don't have to worry about that memory being lost. In case of a initramfs it is always freed.

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5257
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: Use initramfs?

Fri Jul 13, 2012 5:25 pm

@kadamski
Thanks.

I've updated start_initrd.elf to fix the alignment of size. Any better?

For the overlap problem I'm not quite understanding:
ATAG_MEM: size: 0x8000000(131072KB), start: 0x0
ATAG_INITRD2: start: 0x4b3000, size: 0x655000(6484KB)

Is the problem that ATAG_MEM range overlaps the ATAG_INITRD2 range?
If so, what do you want? The ARM has 128M available, so that's what I fill in in the ATAG_MEM, and the initrd has to live inside that. Is that behaviour wrong?

kadamski
Posts: 187
Joined: Fri Jun 08, 2012 10:56 pm

Re: Use initramfs?

Fri Jul 13, 2012 5:50 pm

Ok, now it's working ok (if I specify load address manually). Great work.

As for the overlaping problem - of course you have to put it in the ARM memory and it actually *has* to be in the region defined by ATAG_MEM. I'm putting it in 0xa00000 (or 0x800000) and it is working ok. It just can't be too close to the kernel end since it seems to be allocating this memory for something before loading initramfs (and overrides it probably). I don't know what exactly is this memory region allocated for but I can investigate. Right now you could default to to some higher working address.

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5257
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: Use initramfs?

Fri Jul 13, 2012 5:56 pm

kadamski wrote:Ok, now it's working ok (if I specify load address manually). Great work.

As for the overlaping problem - of course you have to put it in the ARM memory and it actually *has* to be in the region defined by ATAG_MEM. I'm putting it in 0xa00000 (or 0x800000) and it is working ok. It just can't be too close to the kernel end since it seems to be allocating this memory for something before loading initramfs (and overrides it probably). I don't know what exactly is this memory region allocated for but I can investigate. Right now you could default to to some higher working address.
Any suggestion? kernel_size + 8M ?

kadamski
Posts: 187
Joined: Fri Jun 08, 2012 10:56 pm

Re: Use initramfs?

Fri Jul 13, 2012 5:58 pm

Ok, I'm stupid. It was just in front of my eyes. This region is reserved for BSS:

Code: Select all

Virtual kernel memory layout:
    vector  : 0xffff0000 - 0xffff1000   (   4 kB)
    fixmap  : 0xfff00000 - 0xfffe0000   ( 896 kB)
    DMA     : 0xffc00000 - 0xffe00000   (   2 MB)
    vmalloc : 0xc8800000 - 0xd8000000   ( 248 MB)
    lowmem  : 0xc0000000 - 0xc8000000   ( 128 MB)
    modules : 0xbf000000 - 0xc0000000   (  16 MB)
      .text : 0xc0008000 - 0xc0471000   (4516 kB)
      .init : 0xc0471000 - 0xc0493000   ( 136 kB)
      .data : 0xc0494000 - 0xc04b2ec0   ( 124 kB)
       .bss : 0xc04b2ee4 - 0xc0501df8   ( 316 kB)
BSS is from 0x004b2ee4 to 0x00501df8 and if I use 0x00502000 as a base address for initramfs it works (but anything lower is not working, of course).

kadamski
Posts: 187
Joined: Fri Jun 08, 2012 10:56 pm

Re: Use initramfs?

Fri Jul 13, 2012 6:00 pm

Yes I think, end of kernel + 8MB will be good. This will leave the room for uncompressed kernel (I havn't tested initramfs on RPi with compressed kernel yet, i will be able to do this on monday).

Also, since we have ATAG_INITRD2 now, I don't think it actually matters that much where it will go by default as long as it's going to work in most situations. Other situations can be handled by setting this address manually and it can even be changed in future.

kadamski
Posts: 187
Joined: Fri Jun 08, 2012 10:56 pm

Re: Use initramfs?

Sat Jul 14, 2012 7:58 am

Dom, there's one big problem with this start.elf I figured out this morning - it wont boot (stops on colorfull booterror screen) when no inittrams is configured (i.e. default config).

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5257
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: Use initramfs?

Sat Jul 14, 2012 8:45 am

kadamski wrote:Dom, there's one big problem with this start.elf I figured out this morning - it wont boot (stops on colorfull booterror screen) when no inittrams is configured (i.e. default config).
Can you try latest GitHub version? That has the new tag in. It worked for me on default config.

RibShark
Posts: 9
Joined: Wed Jul 04, 2012 6:10 pm

Re: Use initramfs?

Sat Jul 14, 2012 9:47 am

dom wrote:
kadamski wrote:Dom, there's one big problem with this start.elf I figured out this morning - it wont boot (stops on colorfull booterror screen) when no inittrams is configured (i.e. default config).
Can you try latest GitHub version? That has the new tag in. It worked for me on default config.
Where is the GitHub version located?

Return to “General discussion”