I downloaded a Linux kernel "linux-4.1.13.tar.xz" from kernel.org that I want to compile it for Raspberry Pi.
Is it possible?
I downloaded a Linux kernel "linux-4.1.13.tar.xz" from kernel.org that I want to compile it for Raspberry Pi.
Is it possible?
The following comes from raspberrypi.org ... there is more, but I am just posting the minimum to answer the question.
There are two main methods for building the kernel. You can build locally on a Raspberry Pi which will take a long time; or you can cross-compile, which is much quicker, but requires more setup.
On a Raspberry Pi first install the latest version of Raspbian from the downloads page. Then boot your Pi, plug in Ethernet to give you access to the sources, and log in.
First get the sources, which will take some time:
git clone --depth=1 https://github.com/raspberrypi/linux
Add missing dependencies:
sudo apt-get install bc
Configure the kernel - as well as the default configuration you may wish to configure your kernel in more detail or apply patches from another source to add or remove required functionality:
Run the following commands depending on your Raspberry Pi version.
cd linux
KERNEL=kernel
make bcmrpi_defconfig
cd linux
KERNEL=kernel7
make bcm2709_defconfig
Build and install the kernel, modules and Device Tree blobs; this step takes a long time...
make -j4 zImage modules dtbs
sudo make modules_install
sudo cp arch/arm/boot/dts/*.dtb /boot/
sudo cp arch/arm/boot/dts/overlays/*.dtb* /boot/overlays/
sudo cp arch/arm/boot/dts/overlays/README /boot/overlays/
sudo scripts/mkknlimg arch/arm/boot/zImage /boot/$KERNEL.img
Note: On a Raspberry Pi 2/3, the -j4 flag splits the work between all four cores, speeding up compilation significantly.
This official wiki page tracks differences between mainline and the RPI fork: https://github.com/raspberrypi/linux/wiki/Upstreaming
It shows that the differences are mainly in defconfigs, dtb and drivers.
Since Raspberry Pi has its own Linux fork, using a vanilla kernel will likely not work, or some functionality will be missing (unless you reapply some of the changes which are present in the fork).
Why don't you just make your changes on top of the RPI fork?
Related: Which kernel source is required to compile for Raspberry Pi?