Академический Документы
Профессиональный Документы
Культура Документы
Warning: You must be work on one terminal in ubuntu if you switch your terminal
you will not be able to compile below commands.
Note: I had done all the given procedure at your Ubuntu PC so for learning purpose
you can delte your sources and tools to test the whole
process from scratch.
Now Open terminal in Ubuntu PC and please be stick with this terminal don't close
it at any stage other wise you will face issues.
1. cd
2. mkdir raspberryPi
3. cd raspberryPi
4. sudo apt-get install libncurses5-dev
5. git clone --depth=1 https://github.com/raspberrypi/linux
6. git clone https://github.com/raspberrypi/tools
Put the following line#8 in your .bashrc file located at ~/.bashrc location but I
already done it on your Ubuntu PC so you have to replace your old line with given
line#7
7. gedit ~/.bashrc
8. export PATH=$PATH:~/raspberryPi/tools/arm-bcm2708/gcc-linaro-arm-linux-
gnueabihf-raspbian-x64/bin
9. source ~/.bashrc
10. cd ~/raspberryPi/linux/
11. KERNEL=kernel7 // For Raspberry Pi1 you must use this "KERNEL=kernel"
12. export CCPREFIX=~/raspberryPi/tools/arm-bcm2708/gcc-linaro-arm-linux-
gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-
13. ${CCPREFIX}gcc -v // To check your GCC compiler version
Now we need .config file from running raspberry Pi to get all well for new kernel
build, so we will login on Pi open terminal
and then give this command on raspberry pi terminal.
After this command our config.gz will be created at /proc/config.gz loactaion, now
we will again come on Ubuntu terminal where we left.
If prompted for password then please put your login password for raspberry most
probably "raspberry"
If above command ask you some questions about new kernel modules then please enter
without any answer until you get a command prompt.
19. make ARCH=arm CROSS_COMPILE=${CCPREFIX} zImage modules dtbs -j4
After successfully kernel build process you will get new kernel image in
arch/arm/boot/zImage
Now we will load this new kernel image into raspberry pi, so please shutdown your
raspberry pi and safely remove its SD card and
put it in your Ubuntu system. After this given below command on Ubuntu terminal
where you left.
20. lsblk
sdb
sdb1
sdb2
sdb5
sdb6
sdb7
sdb1, sdb2, sdb3 etc will be your SD card partitions With sdb6 being the FAT (boot)
partition, and sdb7 being the ext4 filesystem (root) partition but please make sure
your's may be of different names for FAT (boot) and filesystem (root).
so please use names accordingly.
Finally, copy the kernel and Device Tree blobs onto the SD card, making sure to
back up your old kernel:
After successfully execution of above commands you can safely remove your SD card
and put it in your Pi board and boot it and you will surely
get a new compiled kernel. If you successfully boot your Pi with newly build kernel
then you will surely be able to write your own kernel modules and able to load them
directly in your Pi board without any kernel version issues. So now I tell you the
format of Makefile of kernel modules for cross compiling your kernel moudules here
is the format of kernel module Makefile:
obj-m += piencoder.o
all:
make -C ~/raspberryPi/linux ARCH=arm CROSS_COMPILE=~/raspberryPi/tools/arm-
bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-
SUBDIRS=$(PWD) modules
clean:
make -C ~/raspberryPi/linux ARCH=arm CROSS_COMPILE=~/raspberryPi/tools/arm-
bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-
SUBDIRS=$(PWD) clean
So the above format is for writing Makefile for kernel module say any, copy the
above Makefile format in Makefile file where your kernel module
is placed.
33. make
After make command you will get a piencoder.ko file in your kernel module folder so
to insert this module file you must trasfer it in your Pi board,
to transfer this piencoder.ko file use this command on your Ubuntu PC terminal.
Now you can see this piencoder.ko file in your Raspberry Pi home location, to load
this kernel module you can give following commands.
35. cd
36. sudo insmod piencoder.ko
After above command your kernel module will be loaded and you can confirm it by
giving this command.
37. dmesg
Above command will show you the printk message of your Kernel module which makes
sense that your kernel module loaded successfully.
References:
https://www.raspberrypi.org/documentation/linux/kernel/building.md
http://sysprogs.com/VisualKernel/tutorials/raspberry/buildkernel/
http://elinux.org/Raspberry_Pi_Kernel_Compilation#2._Cross_compiling_from_Linux
http://www.tldp.org/LDP/lkmpg/2.6/html/lkmpg.html
https://pihw.wordpress.com/guides/direct-network-connection/