Page 1 of 1

File System inside of memory

Posted: Mon Aug 31, 2015 7:26 pm
by gardinirafael
I'm working on a simple kernel that runs at ARM CM3 and x86.

I'm looking for a simple way to implement my Virtual File System without need implement disk driver before.

One of those ways is create a simple File System inside of memory.

I've seen a lot of methods to do this with grub using modules (initrd) but with arm architecture will not work in the same way.

I found one method for standardize this function, but I don't know if this is a good practice or if this way can get me in trouble in the future.

Below has steps:

** Convert file to object file using LD **

Code: Select all

i686-elf-ld -r -b binary -o fs.o fs.img
** Linking result object file with kernel **

Map file result is:

Code: Select all

                0x1000000c                _binary_initrd_main_start
                0x10002207                _binary_initrd_main_end
And can access content of file using link file constants

Code: Select all

extern char _binary_initrd_main_start;
extern char _binary_initrd_main_end;

main()
{
    char*  p = &_binary_initrd_main_start;

    while ( p != &_binary_initrd_main_end ) putchar(*p++);
}

Re: File System inside of memory

Posted: Tue Sep 01, 2015 4:13 am
by Kevin
The obvious disadvantage is that your initrd is linked with your kernel and you can't change it without buliding (at least linking) a new kernel. But if you don't have a bootloader that can pass you an initrd, this is probably the way to go,

Re: File System inside of memory

Posted: Tue Sep 01, 2015 5:01 am
by bluemoon
Which board you targeting? uboot support most ARM architectures and board including Cortex M3, and it support initrd/initramfs in similar way.

Re: File System inside of memory

Posted: Tue Sep 01, 2015 5:24 am
by gardinirafael
bluemoon wrote:Which board you targeting? uboot support most ARM architectures and board including Cortex M3, and it support initrd/initramfs in similar way.
My development board for Cortex M3 is mbed LPC1768 and in this case is not needed to care with boot loader because only need to drag and drop binary in card.

Re: File System inside of memory

Posted: Tue Sep 01, 2015 5:50 am
by bluemoon
gardinirafael wrote:not needed to care with boot loader because only need to drag and drop binary in card.
Quite the contrast, you may consider have a boot loader to chain-load your kernel so that you have a consistent mechanism, ie. initrd, on both x86(grub) and ARM(uboot).
The problem of packing the ram disk into the kernel binary is, it put a limitation to your system - if you have a lot of stuff on initrd, your kernel image may soon grow over the maximum load size supported by the firmware.