Raspberry kernel Compilation and module development

Source: Internet
Author: User
Tags ssh git clone

Because I intend to learn Linux driver programming, I bought a raspberry to be the development environment. Directly by mirroring the kernel is not directly used to do module development, because the distribution itself is not with the kernel source tree, but the module is necessary to develop this. The first step in all of the kernel module development is to compile the kernel. Specific to the different versions of the raspberry, the compilation method is slightly different, this raspberry official has a document dedicated to this. The process of compiling my kernel is mainly to refer to this article KERNEL building. There are two ways to build a kernel, one is to compile locally on the raspberry, the other is to compile on another machine and then test the Raspberry memory card. Compiling and compiling directly on the raspberry is simpler but it takes time, and I compile it for about one hours, and I personally think that speed can also be:. The other is a cross compilation on the PC, thanks to the official Cross compilation tool, raspberry kernel on the PC is also relatively simple to compile the process. I'm here to write down the process of compiling my raspberry. Kernel compilation

1, download the Linux kernel source code, I directly placed in the user's home directory, this in the compilation of modules will be used.

git clone--depth=1 Https://github.com/raspberrypi/linux

2, the installation of the lack of dependence.

sudo apt-get install BC

3, the kernel configuration, pi1 and pi2,3 are not the same. I am here is pi3, so I only explain Pi3, pi1 refer to the official document.

CD Linux
kernel=kernel7 make
bcm2709_defconfig

4, compile and install the kernel and module.

Make-j4 zimage modules Dtbs sudo make modules_install sudo cp arch/arm/boot/dts/*.dtb/boot/
sudo cp arch/ar m/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

5, reboot or power-on restart, using uname to see if the kernel version has changed. Module Development

I'm using the example in the "Linux device Driver" book here. The following is a record of a procedure.
1, the use of editing software to edit the module source code, my is hello.c

#include <linux/init.h>
#include <linux/module.h>

module_license ("Dual BSD/GPL");

static int hello_init (void)
{
    printk (kern_alert "Hello, world\n");
    return 0;
}

static void Hello_exit (void)
{
    printk (kern_alert "Goodbye, cruel world\n");

Module_init (hello_init);
Module_exit (Hello_exit);

2, edit makefile file, I this relatively simple is used for testing.

Obj-m: = hello.o

3, compile the module in the command line. -C parameter specifies the kernel source tree location, M is the module source directory. Modules didn't figure out what it was for.

Make-c ~/linux m=/home/pi/workspace Modules

4. The module's safety loading and unloading and its output view.

Insmod./hello.ko
rmmod Hello
tail-2/var/log/syslog

The first simple module has been compiled so that we can prepare for the module development behind us. Other configuration methods of the module development environment can refer to this article
The Wire. The IP address is then set to a static password, which is automatically assigned to the raspberry pie each time the router is started.

1. Connect the raspberry pie to the route
Wired to connect, because the advantage of wired connection is that you do not need a password, the line can be used to connect. Connect the network card, switch on the power supply, and then link the raspberry pie now. The first step was to get to the raspberry Pie IP, the first time the Raspberry faction IP address is randomly assigned by the router. Enter the router management page to see.

2, access to IP, Raspberry faction of the default user is pi, the password is raspberry. You can log in with the information above. The specific login tool is logged in via SSH. In the SSH login tool, enter the IP, username and password is OK. If it is a Linux system, you can use the following command to log in. 192.168.0.101 is my raspberry pie assigned to the IP, different in everyone's case.

$ ssh pi@192.168.0.101

3, after the login to modify the network card information. Before modifying, you can look at the network card information and use $ iftop to view it. Can see a wlan0 is my wireless network card. Later, you configure the network card information through VIM. My raspberry pie was fitted with a raspbian. Based on Debian, so his network card path is the same as Debian. Modify the/etc/network/interfaces file.

Auto lo
iface lo inet loopback
iface eth0 inet dhcp
allow-hotplug wlan0 iface wlan0 inet
static
wpa-s Sid  Netgear          #你要连接的wifi SSID
wpa-psk  1234567890     #你的wpa连接密码 address 
192.168.1.110     # Set static IP address
netmask 255.255.255.0     # Network Mask Gateway
192.168.1.1      # gateway
network 192.168.1.1      # Network address
#wpa-roam/etc/wpa_supplicant/wpa_supplicant.conf       #注释掉这一行
iface default inet DHCP

And then reboot it and you can get into the system.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.