kernel.img file
When using Linux kernel, kernel.img
file is just a renamed linux/arch/arm/boot/Image
. It should also be possible (or at least it was possible last time I checked) to use compressed version of this file - zImage
.
It can contain integrated initramfs
(ramdisk) but it is not required. For example, stock kernel.img
file does not contain initramfs
while kernel_emergency.img
does.
Note: Official kernel compilation guide on eLinux wiki suggest that you should use imagetool-uncompressed.py
tool to prepare kernel.img
file. It was necessary in early days of RaspberyPi but nowadays bootloader can handle regular Image
and zImage
files.
Kernel sources issue
What is very important is that when building kernel for RaspberryPi, you can't just use any version of it. Only special version that is ported to RaspberryPi will work. Unfortunately, current upstream version (found on kernel.org
site) is not compatible with RaspberryPi. Also, versatil_config
is not good for RaspberryPi, you should use bcmrpi_defconfig
instead (found on RaspberryPi compatible kernel sources) or bcmrpi_emergency_defconfig
if your plan on using buildin initramfs
.
Kernel building instructions
The best place to grab kernel sources for RaspberryPi is on foundation github. You can also find some useful explaination on how to get it and how to compile it on official RasbperryPi wiki. Here's my little simplified version of the steps involved (NOTE: I assume you want to crosscompile the kernel. It is much faster and should create the same results but building kernel natively on RaspberryPi is also possible):
Download official toolchain on create your own. Eigher way, I asssume it's installed in /usr/bin/arm-linux-gnueabi-*
. If you have it in other place, you should change CROSS_COMPILE
option in all your make
commands.
Go to https://github.com/raspberrypi/linux site where you can find official RapsberryPi kernel sources. You can download the code in two ways:
- As a compressed file (to use this option you don't have to install
git
utility and you can do this even on RapsberryPi itself): Click on ZIP
icon, a little below Code
tab at the top of site. This should let you download lates source files as zip
file. You could use git to do this instead but that (as described on the wiki) will need a lot more space and time. Then decompress the file to get source tree.
Using git
utility (this didn't work for me on RaspberryPi as there is small amount of RAM probably but should work OK on desktop systems (note --depth 1
argument which prevents git from downloading whole history of the development (which is huge):
git clone --depth 1 git://github.com/raspberrypi/linux.git
Use default config supplied by foundation:
cp arch/arm/configs/bcmrpi_defconfig .config
Run make oldconfig
and answer some questions (it should be ok to hit enter in each question leaving default answer):
make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- oldconfig
Compile the kernel:
make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi-
Copy kernel modules to /tmp/modules
:
make ARCH=arm modules_install INSTALL_MOD_PATH=/tmp/modules
Use Image
file as kernel.img
Upload all the modules to from /tmp/modules/lib/modules/
in your computer to /lib/modules/
directory on your RaspberryPi rootfs.
Adding initramfs
This does not provide instructions on how to create initramfs
, however. Since this is very broad topic (basically, you have to create working Linux userspace environment ant there is really no limit on how complicated it can be), I won't cover this here now. I will only note that initramfs
can be used in two different forms - standalone one, where it's separate file and buildin where it is integrated with kernel image file (like it's in kernel_emergency.img
). The second option should be supported by RaspberryPi bootloader but there some rumors that it's broken on current firmware version so you should probably use buildin version.
The best way to start is to use working initramfs content (that is being used for kernel_emergency.img) by downloading it from another foundation github repository and only after you are able to boot the kernel using this iniramfs
image, try building your own. All that should be needed for this is to point to the downloaded directory uing CONFIG_INITRAMFS_SOURCE
kernel configuration option.
Final notes
So you should do this in 3 steps:
- Try building and booting kernel without
initramfs
file.
- Try adding ready
initramfs
content to your kernel.
- Change this
initramfs
content to suit your needs.
kernel.org
site?