xistor 910619de4c fix missing semicolon 1 year ago
..
Makefile 426205e2a3 Added makefiles for LLVM Clang 5 years ago
Makefile.clang 9c5c2813a0 Update QEMU command in all README and Makefile 2 years ago
Makefile.gcc 9c5c2813a0 Update QEMU command in all README and Makefile 2 years ago
OLVASSEL.md 12f9635933 Now supports cpio format too 6 years ago
README.md a2ce05070e Fixes in comments 6 years ago
delays.c 910619de4c fix missing semicolon 1 year ago
delays.h ed7cb505f9 Fixed typos and more tutorials 6 years ago
gpio.h ed7cb505f9 Fixed typos and more tutorials 6 years ago
initrd.c 426205e2a3 Added makefiles for LLVM Clang 5 years ago
initrd.h ed7cb505f9 Fixed typos and more tutorials 6 years ago
kernel8.img 4bfdd46ea7 Use returned channel order, fixed issue #64 4 years ago
link.ld ed7cb505f9 Fixed typos and more tutorials 6 years ago
main.c 12f9635933 Now supports cpio format too 6 years ago
mbox.c 214885df63 compute the mailbox cmd only once 6 years ago
mbox.h ed7cb505f9 Fixed typos and more tutorials 6 years ago
start.S ea4691947c Improve comments wrt stack setup 3 years ago
uart.c 8a80ab88b9 Clearified mbox call in uart per issue #49 6 years ago
uart.h ed7cb505f9 Fixed typos and more tutorials 6 years ago

README.md

Tutorial 0E - Initial RamDisk

Many OS uses initial ramdisk to load files into memory during boot. I felt the need for such a tutorial as most hobby OS developer's never learned how to do this properly.

First of all, we're not going to reinvent the wheel and come up with a new format and an awful image creator tool. We're going to use the POSIX standard tar utility and the cpio utility to create our initrd. The former is more straightforward, the latter is used by Linux.

Tar's format is really simple, first comes an 512 bytes long header with file meta information, followed by the file contents padded with zeros to round up to be multiple of 512 bytes. This repeats for every file in the archive.

Cpio is very similar but it has a variable length header and file content is not padded.

If you want a compressed initrd, you can use for example the tinf library to inflate. The uncompressed buffer can be parsed by the method described here.

Second, about loading your ramdisk into memory, we have several options:

Load a file on our own

You can use the fat_readfile() from the previous tutorial. In that case your initrd's address will be returned by the function.

Ask the GPU to do so

You can use config.txt to tell start.elf to load the initrd for you. With this you won't need any SD card reader or FAT parser at all, resulting in a much smaller kernel. As for the config.txt, you have two options:

ramfsfile=(filename) - this will load (filename) after your kernel. You can access it at the label &_end defined by our linker script.

initramfs (filename) (address) - load (filename) into a specified location. You can access it at (address).

Statically link

This is not very practical because you have to build your kernel every time you want to change the initrd. But it is the simplest method, and to keep this tutorial simple we'll use this method. You can access the initrd by the label _binary_ramdisk_start.

Makefile

I've added an rd.o rule to convert the archive into an object file. I've also added

make tar which will create an archive in tar format

make cpio which will create a cpio hpodc archive.

So when you compile, you either have to use make tar all or make cpio all.

Initrd.h, initrd.c

initrd_list(buf) list the contents of an archive in the buffer. Detects the format automatically.

Main

We initialize console and then pass the initrd buffer to lister.