davidbrazdil
Posts: 4
Joined: Sat Jul 27, 2019 6:06 pm

[pi4] initramfs mapped incorrectly?

Wed Sep 11, 2019 5:37 pm

Hi,

I'm writing a bare metal program and want to read data from an initramfs configured in config.txt. I see that the linux,initrd-start and linux-initrd-end values are being added to the FDT and the size matches the size of the initramfs file. However, when I read the data the memory contains a random file from the SD card (an overlay DTBO in my case), not the specified ramdisk file.

Has someone else seen this? Is it possible that there is a problem with the Pi4 firmware?

Thanks,
-David

LdB
Posts: 1207
Joined: Wed Dec 07, 2016 2:29 pm

Re: [pi4] initramfs mapped incorrectly?

Thu Sep 12, 2019 12:40 am

I am scratching my head, initramfs is a linux construct AFAIK it's just an area in memory address range allocated for linux to do it's thing with it's kernel.

In baremetal all that linux stuff is irrelevant, the memory is whatever you decide and there won't be anything other than junk in it. When we setup baremetal cards we don't even have a linux kernel on the card we only have a handful or required files.

So for me the question is what exactly are you expecting to be in the area and how does it get there? It almost appears you expect some file contents to be there? The extension to the question is are you really talking baremetal at all?

davidbrazdil
Posts: 4
Joined: Sat Jul 27, 2019 6:06 pm

Re: [pi4] initramfs mapped incorrectly?

Thu Sep 12, 2019 9:26 am

You're right that the concept of a ramdisk is more traditional in the Linux world but underneath it just means that the boot loader loads some data into memory and puts its address into the r0 register before jumping to the kernel. Linux makes use of it as an early filesystem before it's booted enough to be able to mount the real filesystem. The 'kernel=' config option is very similar to the 'initramfs' option - it just tells the boot loader to load a file from the SD card and jump to the beginning of it. Neither of them is strictly tied to Linux.

You could argue that I could get around this problem by compiling the file into my kernel. While that's true, the reason why I want to do this is to be able to give users one kernel image and several ramdisks which they can switch between using the config file. I could produce one kernel for each ramdisk but that's just not as elegant and starts taking up a lot of space.

davidbrazdil
Posts: 4
Joined: Sat Jul 27, 2019 6:06 pm

Re: [pi4] initramfs mapped incorrectly?

Thu Sep 12, 2019 9:33 am

Just re-read your message. Maybe I misunderstood the point of the Bare metal, Assembly language forum. My project still uses the RPi boot loader and DTBs, only supplements the Linux kernel for my own. Sounds like you're suggesting this question should not be posted here?

LdB
Posts: 1207
Joined: Wed Dec 07, 2016 2:29 pm

Re: [pi4] initramfs mapped incorrectly?

Thu Sep 12, 2019 11:46 am

So you understand how the Pi starts and you semi answered your own question

You have 2 choices
1.) Bind all the kernel images into one big kernel image (the VC6 will then load it for you excatly as you described) . The FAT32
loader in the VC4/VC6 is not exposed you can't get access to it from the ARM side and it will lift only the one file.
2.) Make a kernel image which is a bootstrap loader with a FAT32 reader and load whichever kernel you want from the SD card.
A FAT32 reader is super simple because you don't have the issue of changing the FAT clusters like with write and delete of files.

On the Pi4 there is probably a 3rd option that has not been exposed to us which would be to write the file into spare space on the boot eeprom.
https://www.raspberrypi.org/documentati ... teeprom.md

Option 2 is probably what you are wanting to do as the viable alternative and is reasonably simple.

davidbrazdil
Posts: 4
Joined: Sat Jul 27, 2019 6:06 pm

Re: [pi4] initramfs mapped incorrectly?

Thu Sep 12, 2019 12:04 pm

Well, all of those are of course valid, but my original question was whether it is possible that there is a bug in the Pi boot loader (which is closed source and part of https://github.com/raspberrypi/firmware). From what I can gather, my current approach should work and I should not need any workarounds.

I have been playing with it today and I found that it actually works fine if I specify the memory address the file should be loaded to, instead of the default 'followkernel' option which picks the address automatically (https://www.raspberrypi.org/documentati ... xt/boot.md). This is making me think more and more that it is a boot loader issue.

Return to “Bare metal, Assembly language”