Running linux entirely from RAM on SAMA5D4 (Yocto)

This forum is for users of Atmel's SAM Series and who are interested in using Linux OS.

Moderator: nferre

brian_
Posts: 15
Joined: Mon Jan 09, 2017 11:59 am

Running linux entirely from RAM on SAMA5D4 (Yocto)

Mon Jan 09, 2017 5:17 pm

I am trying to get a linux build to run entirely from RAM. I am using the Sama5d4 Xplained platform for this development, using yocto with the meta-atmel bsp.

I am currently able to build an image in yocto that runs from the nand flash. In the demo_script_linux_nandflash.tcl file I can see that both the kernel and dtb files are loaded in to RAM, then the bootz command is used to point to these ram locations. I believe the rootfs location is passed to the kernel via the bootargs "root=" command.

Now I would like to run the rootfs from RAM, loading images from the nand flash in to RAM. After doing some research, I think that the best way to do this currently is using an initramfs approach.

In yocto I have the following:


File: meta-atmel/conf/machine/target.conf

INITRAMFS_IMAGE = "core-image-base"
INITRAMFS_IMAGE_BUNDLE = "1"

IMAGE_FSTYPES = "cpio.gz"


File: meta-atmel/recipes-kernel/linux/linux-at91-4.4/sama5/defconfig
Note: I think I need the following to allow the kernel to read the cpio.gz properly

CONFIG_RD_GZIP=y

Questions:

1. I end up with multiple files in the deploy directory, but I am not sure what they are, e.g.

zImage + zImage-target.bin - Appear to be the same. I think this is the standard kernel without the initramfs, correct?
zImage-at91-sama5d4_explained.dtb - standard dtb

zImage-initramfs-target.bin - Isthis everything in one .bin file? Kernel + dtb + initramfs(rootfs) ?

core-image-minimal-target.cpio.gz - I think this file, or the one below it is the initramfs file system.
core-image-base-target.cpio.gz

modules-target.tgz - not sure of this file

Can someone clarify the files here - I think there are two options:
a. Load the zImage-initramfs-target.bin image which contains everything in to ram and boot?
b. Load in the zImage (Kernel), zImage-at91-sama5d4_explained.dtb and core-image-base-target.cpio.gz files in to ram, then boot?

Is this correct?

2. For option b above, if it is the cpio.gz file that I need to load, do I need to load it in to a specific location in RAM? If not a specific location, is there some way of determining a safe location to load it in to?

I think I need to pass in the location in to the middle argument of the bootz command.

3. How does the kernel know what RAM it is free to use as system ram? E.g. I think I need to tell the kernel to not use the area of RAM where the rootfs is now stored. Is there a configuration file somewhere for this?


Thanks in advance. Apologies for the simple questions - I am new to Yocto, and have never dealt with linux at such a low level before.
blue_z
Location: USA
Posts: 1505
Joined: Thu Apr 19, 2007 10:15 pm

Re: Running linux entirely from RAM on SAMA5D4 (Yocto)

Tue Jan 10, 2017 12:31 am

brian_ wrote:I think I need the following to allow the kernel to read the cpio.gz properly
I don't use Yocto for development, so no critique on validating commands.
brian_ wrote:1. I end up with multiple files in the deploy directory, but I am not sure what they are, e.g.

zImage + zImage-target.bin - Appear to be the same. I think this is the standard kernel without the initramfs, correct?
There are only a few files. Most of the "files" are symbolic links.
brian_ wrote:zImage-initramfs-target.bin - Isthis everything in one .bin file? Kernel + dtb + initramfs(rootfs) ?
No, the dtb is kept separate for booting flexability (unless you're using a FIT image).
brian_ wrote:core-image-minimal-target.cpio.gz - I think this file, or the one below it is the initramfs file system.
core-image-base-target.cpio.gz
Both are compressed cpio achives.
Your Yocto recipes have built more than one version of the rootfs, e.g. minimal and base.
brian_ wrote:modules-target.tgz - not sure of this file
A compressed tar archive of kernel loadable modules.
brian_ wrote:Can someone clarify the files here - I think there are two options:
a. Load the zImage-initramfs-target.bin image which contains everything in to ram and boot?
b. Load in the zImage (Kernel), zImage-at91-sama5d4_explained.dtb and core-image-base-target.cpio.gz files in to ram, then boot?

Is this correct?
No.
Typically the the kernel and cpio archive are combined into one (self-extracting, compressed) zImage file, and the dtb is another file.
So there are two files to load into memory for booting.

BTW Since the kernel and cpio archive are bundled in a compressed zImage file, also compressing the cpio archive is redundant.
Double compression uses more space and requires more time to boot.
IOW do not compress the cpio archive when appending in a zImage.
brian_ wrote:2. For option b above, if it is the cpio.gz file that I need to load, do I need to load it in to a specific location in RAM? If not a specific location, is there some way of determining a safe location to load it in to?
Normally the cpio file is simply appended to the kernel image, and stored/loaded as one file.
There is a method for using an "external" cpio archive file. Refer to the kernel documentation.
brian_ wrote:3. How does the kernel know what RAM it is free to use as system ram?
The kernel manages the memory used by the ramfs. Memory usage can grow or shrink as files are created or removed from the ramfs. That's the advantage of ramfs over the (deprecated) ramdisk.

Regards
brian_
Posts: 15
Joined: Mon Jan 09, 2017 11:59 am

Re: Running linux entirely from RAM on SAMA5D4 (Yocto)

Fri Jan 13, 2017 6:50 pm

Thanks for the response. I was able to take the .dtb file and load it to 0x21000000, then load the .bin file to 0x22000000. After that, I was able to boot with bootz 0x22000000 - 0x21000000

Return to “Linux”

Who is online

Users browsing this forum: No registered users and 1 guest