In previous post we built full Linux system for our emulated qemu ARM machine. The next step is to tell buildroot that we want to use our custom kernel source tree. This will be the same kernel as in default buildroot configuration just in external directory. This will enable us to change it and test under qemu environment. First step is to fetch kernel, we can grab tarball from https://www.kernel.org/ or clone repository with git.
git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
cd linux-stable
git checkout -b 3.18.4 v3.18.4
To check which kernel version was previously in use you can simply check configuration or look what's in buildroot/output/build directory. After that we simply go to buildroot directory and type:
make menuconfig
Go to
Kernel ->
Kernel version, choose
Local Directory and put (full) path to your local kernel copy. Exit and save configuration. Now you can rebuild your Linux, to be 100% sure that you use your custom kernel, you can remove old copy from output directory
rm -rf output/build/linux-3.18.4/
now just type make. Buildroot will sync sources from local copy and do build. You can now try out to change something in your kernel to feel that you have "power" to make changes. E.g. open init/main.c file from your kernel source tree and put something like:
pr_info("Hello world from custom kernel!\n");
in start_kernel() function, just after
pr_notice("Kernel command line: %s\n", boot_command_line);
Save your changes, go back to buildroot directory and type
make linux-rebuild
Now you're done with your very own custom version of Linux kernel. Start qemu
qemu-system-arm -M vexpress-a9 -kernel output/images/zImage -drive
file=output/images/rootfs.ext2,if=sd -append "console=ttyAMA0,115200
root=/dev/mmcblk0" -serial stdio
Login as root and open /var/log/message for example with vi editor
vi /var/log/messages
You should find your print in log
Apr 6 17:38:26 buildroot kern.notice kernel: Kernel command line: console=ttyAMA0,115200 root=/dev/mmcblk0
Apr 6 17:38:26 buildroot kern.info kernel: Hello world from custom kernel!
Apr 6 17:38:26 buildroot kern.info kernel: PID hash table entries: 512 (order: -1, 2048 bytes)
Have fun!
No comments:
Post a Comment