如何只build linux kernel build某个mdoule

From linux-sunxi.org
This page describes how to get the sunxi specific linux kernel built for your device.
support for the sunxi family (Allwinner , , ...) started with a source drop of 2.6.36 made by , followed by an official release of 2.6.36 sources by . Developement jumped forward after a source release of 3.0.8 made by
Initially living in
repo is located in the .
The main sunxi kernel repository is available at .
You can clone the entire (huge) repository by installing the git package and running:
git clone /linux-sunxi/linux-sunxi.git
but if you just want to build our kernel, then follow .
There are several branches in our kernel tree. Unless you wish to do some specific development, you should probably stick to the sunxi-3.4 branch as this will get the most out of your hardware quickly.
Description
sunxi support initially based on lichee3-3.0.8 and keeping reference-3.0 as it's mainline reference.
sunxi support forward ported from sunxi-3.0 and keeping reference-3.4 as it's mainline reference. [PREFERRED]
experimental/sunxi-3.10
scheduled for removal. DO NOT USE.
sunxi support forward ported from sunxi-3.4, backporting from mainline and keeping reference-3.10 as it's mainline reference.
experimental/sunxi-3.14
highly experimental
sunxi-2.6.36
sunxi support based on the official 2.6.36 release.
reference-3.0
merge of mirror/android-3.0 and the latest v3.0.x mainline stable tag. Used to see what of sunxi-3.0 is sunxi specific.
reference-3.4
merge of mirror/android-3.4 and the latest v3.4.x mainline stable tag. Used to see what of sunxi-3.4 is sunxi specific.
reference-3.10
merge of mirror/android-3.10 and the latest v3.10.x mainline stable tag. Used to see what of sunxi-3.10 is sunxi specific.
mirror/allwinner-2.6.36
mirror of allwinner's official 2.6.36 tree (aka )
mirror/android-2.6.36
mirror of Android's kernel-common for Android 2.3 (Gingerbread)
mirror/android-3.0
Android's kernel-common for Android 4.0 (Ice Cream Sandwich), 4.1 (Jelly Bean)
mirror/android-3.4
mirror of Android's 3.4 kernel branch.
mirror/android-3.10
mirror of Android's 3.10 kernel branch.
mirror/master
mirror of Linus Torvalds' master.
lichee-3.0.8-sun4i
based on 's source release, kept only to let people drop-in new modules into a GPL-violating / based install.
experimental and very likely to 1) be rebased, 2) be seriously broken
If unsure, use the sunxi-3.4 branch.
If you haven't done so before, get a suitable
installed and added to your PATH.
This command will clone the sunxi-3.4 branch:
git clone -b sunxi-3.4 /linux-sunxi/linux-sunxi.git
If you just want a quick build and do not wish to download a big git repository, then run:
git clone -b sunxi-3.4 --depth 1 /linux-sunxi/linux-sunxi.git
This will create a so-called shallow clone (still a 500MB download), which does not allow for much in the way of development or changes.
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- sun4i_defconfig
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- sun5i_defconfig
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- sun5i_defconfig
But to get a booting system, you need to set:
CONFIG_SW_DEBUG_UART=1
CONFIG_SW_DEBUG_UART=0
in .config.
Through menuconfig, you need to dig through:
System Type ---&
Allwinner's sunxi options
And then set this to 0:
(1) UART to use for low-level debug
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- sun7i_defconfig
After you have set a default configuration, you can fine-tune your kernel configuration.
For this you will need ncurses development code installed. So for example, on a system that uses the apt package manager, run the following:
apt-get install libncurses5-dev
Now you can run menuconfig, and edit your configuration:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig
Note that the sunxi kernel is based on an obsolete kernel version with vendor hacks thrown in to support the sunxi hardware. As a result some configurations that are possible to select will not build or work.
In particular some sunxi-specific drivers were not fixed to work both as built-in and as module and IPv6 only works as built-in.
Make sure you have the package u-boot-tools installed, then:
make -j4 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- uImage modules
The -j4 option runs 4 make instances in parallel to speed up compilation. Please adjust this to the number of CPU cores/thread execution units available.
As a final step, create the full module tree:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=output modules_install
The INSTALL_MOD_PATH option specifies the directory where the full module tree will be made available, in this example, it will be the output directory under the kernel build directory itself.
Now you have the following sitting in your kernel tree:
arch/arm/boot/uImage
output/lib/modules/3.4.XXX/
The uImage file (the kernel minus the modules) needs to be started by u-boot, so it is usually copied to a boot partition where u-boot will find it, load it in RAM and then transfer control to it (u-boot can also pass parameters to the kernel). The modules directory needs to be copied to the /lib/modules on the target root file system.
There is some sunxi code available in Linus' tree. But this is not suited for normal use yet, and will likely need a lot more work to get there. For more information, see our .AboutContact usForumsHomeLinux How-to & TutorialsShell ScriptsRSS/FeednixCraftRecently I received a question via email:How do I build Linux kernel module against installed or running Linux kernel? Do I need to install new kernel source tree from kernel.org? To be frank you do not need a new full source tree in order to just compile or build module against the running kernel i.e
an exploded source tree is not required to build kernel driver or module. The instruction outlined below will benefit immensely to a developer and power user.Linux Kernel headersThis is essential because if you just want to compile and install driver for new hardware such as Wireless card or SCSI device etc. With following method, you will save the time, as you are not going to compile entire Linux kernel.Please note that to work with this hack you just need the Linux kernel headers and not the full kernel source tree. Install the linux-kernel-headers package which provides headers from the Linux kernel. These headers are used by the installed headers for GNU glibc and other system libraries as well as compiling modules. Use following command to install kernel headers: # apt-get install kernel-headers-2.6.xx.xx.xxReplace xx.xx with your actual running kernel version (e.g. 2.6.8.-2) and architecture name (e.g. 686/em64t/amd64). Use uname -r command to get actual kernel version name. Please note that above command will only install kernel headers and not the entire kernel source-code tree.A more generic (recommend) and accurate way is as follows: # apt-get install kernel-headers-$(uname -r)All you need to do is change Makefile to use current kernel build directory. You can obtain this directory name by typing following command: $ ls -d /lib/modules/$(uname -r)/build Sample output:/lib/modules/2.6.27-7-generic/buildLet, say you have .c source code file called hello.c. Now create a Makefile as follows in the directory containing hello.c program / file: $ vi Makefile Append following text:obj-m := hello.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modulesSave and close the file. Type the following command to build the hello.ko module: $ makeTo load Linux kernel module type the command: # modprobe hello A complete exampleCreate test directory (you can download following Makefile and .c file here): $ mkdir ~/test $ cd ~/test Create hello.c kernel module file:#include &linux/module.h&
#include &linux/kernel.h&
int init_module(void)
printk(KERN_INFO &init_module() called\n&);
void cleanup_module(void)
printk(KERN_INFO &cleanup_module() called\n&);
&Create a Makefile:obj-m += hello.o
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) cleaTo build kernel module enter: $ make Sample output:make -C /lib/modules/2.6.27-7-generic/build M=/tmp/test2 modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.27-7-generic'
/tmp/test2/hello.o
Building modules, stage 2.
MODPOST 1 modules
/tmp/test2/hello.mod.o
/tmp/test2/hello.ko
make[1]: Leaving directory `/usr/src/linux-headers-2.6.27-7-generic'
Run ls command to see newly build kernel module: $ ls Sample output:hello.c
hello.mod.c hello.mod.o
Makefile Module.markers modules.order
Module.symvershello.ko is kernel module file. To see information about module, enter: $ modinfo hello.ko
Sample output:filename:
srcversion:
4F856ABA1FD961
2.6.27-7-generic SMP mod_unload modversions 586 To load kernel module, enter: $ sudo insmod hello.ko OR $ sudo modprobe hello To list installed Linux kernel module, enter: $ lsmod $ lsmod | grep hello
To remove hello Linux kernel module, enter: $ rmmod hello This module just logs message to a log file called /var/log/messages (/var/log/syslog), enter: $ tail -f /var/log/messages Sample output:Nov
5 00:36:36 vivek-desktop kernel: [] init_module() called
5 00:36:50 vivek-desktop kernel: [] cleanup_module() calledDownload above examples in zip formatDownload fileSee a detailed and completeexample with C source code about Compiling Linux kernel module for more information. TwitterFacebookGoogle+PDF version Featured Articles:30 Cool Open Source Software I Discovered in 2013 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS XTop 30 Nmap Command Examples For Sys/Network Admins25 PHP Security Best Practices For Sys Admins20 Linux System Monitoring Tools Every SysAdmin Should Know20 Linux Server Hardening Security TipsLinux: 20 Iptables Examples For New SysAdminsTop 20 OpenSSH Server Best Security Practices Top 20 Nginx WebServer Best Security Practices20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors15 Greatest Open Source Terminal Applications Of 2012My 10 UNIX Command Line MistakesTop 10 Open Source Web-Based Project Management SoftwareTop 5 Email Client For Linux, Mac OS X, and Windows UsersThe Novice Guide To Buying A Linux Laptop Leave a Comment
Related PostsHow to: Compile Linux kernel modulesHow to: Compile Linux kernel 2.6How to display or show information about a Linux Kernel module or driversHow To Patch Running Linux Kernel Source TreeUninstall files installed from a source code tar-ballHowTo: Linux Check IDE / SATA Hard Disk Transfer SpeedLinux Configure Netconsole To Log Messages Over UDP Network Redhat Enterprise Linux securely mount remote Linux / UNIX directory or file system using SSHFSHow do I forcefully unmount a Linux disk partition?shoes – A cross-platform Windowing Applikit
Latest Linux/Unix Q & AFreeBSD Unix Show Mounted File SystemsBash: Reissue And Repeat A Long Command Without Retyping It on a Linux, OS X & UnixApple OS X: Install X Window System XQuartz For SSH X11 Forwarding On a Mavericks or YosemiteFreeBSD Force DHCP Client (dhclient) to Renew IP Address To Get A New LeaseHow To Stress Test CPU and Memory (VM) On a Linux and Unix With Stress-ngGlibc: GHOST Vulnerability Test To See If a Linux Sever Is
SecureHow To Patch and Protect Linux Server Against the Glibc GHOST Vulnerability # CVE-How To Add Swap on FreeBSD Unix SystemsHow To PFSense Configure Network Interface As A Bridge / Network SwitchHow to Run and Execute Command When I Log Out Of Linux Session?Unix / Linux: Initialize Dot Files Without Restarting The Current Shell SessionHow To Install MariaDB Databases on a FreeBSD v10 Unix ServerHow To Extract a Tar Files To a Different Directory on a Linux/Unix-like SystemsHow To Install Apache, MySQL, PHP stack on FreeBSD Unix ServerCheck The Number Of MySQL Open Database Connections on Linux Or Unix-like ServerHowTo: Use ps, kill, nice, and killall To Manage processes in FreeBSD and OS X Unix Operating SystemInstall LEMP (Linux, Nginx, MySQL and PHP) Stack
on Ubuntu Linux 14.04 LTSHow To Add, Delete, and Grant Sudo Privileges to Users on a FreeBSD ServerSet Up SSH Tunneling on a Linux / Unix / BSD Server To Bypass NATSubscribe to nixCraftLearn something new about Linux/Unix by emailEnter your email address:Immutable Page
More Actions:
Print View
Delete Cache
------------
Check Spelling
Like Pages
Local Site Map
------------
Rename Page
Delete Page
------------
Attach File
Package Pages
Render As Docbook
Subscribe User
KernelBuild
Guide to building the Linux kernel.
The latest source code for the Linux kernel is kept on .
You can either download the full source code as a tar ball (not recommended and will take forever to download), or you can check out the code from the read-only .
To build the Linux kernel from source, you need several tools: git, make, gcc, and (optionally) ctags and/or ncurses-dev.
The tool packages may be called something else in your Linux distribution, so you may need to search for the package. The ncurses-dev tools are used if you "make menuconfig" or "make nconfig".
On Ubuntu, you can get these tools by running:
sudo apt-get install libncurses5-dev gcc make git exuberant-ctags
On Red Hat based systems like Fedora, Scientific Linux, and CentOS you can run:
sudo yum install gcc make git ctags ncurses-devel
If you want to test to see if a bug is fixed then test against the latest stable kernel from kernel.org. If you are brave and your system is backed up the latest release candidate from Linus's tree is a great target.
Sometimes the maintainer may want you to use an experimental branch from their own git tree.
You should use the git URL they gave you instead of the git URLs below.
If you're doing development for a new feature, or trying to test a bug fix, you should use Linus' tree, or the subsystem maintainer's -next tree.
Most subsystem maintainers keep their
on kernel.org.
When in doubt, use Linus' tree.
If you don't understand what a stable or release candidate kernel is, you should read the
First, checkout the stable kernel git repository:
git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
cd linux-stable
Next, find the latest stable kernel tag by running
git tag -l | less
Find the latest stable kernel by looking for the largest vX.Y.Z values.
For example, use the v3.1 tag over the v3.0.46 tag.
If v3.1.1 is available, use that instead of v3.1.
The kernel tags that end with -rcX are release candidate kernels, not stable kernels.
Now checkout the code associated with that kernel with the command
git checkout -b stable tag
Where tag is the latest vX.Y.Z tag you found.
Check out Linus' tree:
git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Many kernel drivers can be turned on or off, or built as modules.
The .config file in the kernel source directory determines which drivers are built.
When you download the source tree, it doesn't come with a .config file. You have several options on generating a .config file. The easiest is to duplicate your current config.
If you're trying to see if a bug is fixed, you probably want to duplicate the configuration on your running kernel.
That config file is stored somewhere in /boot/.
There might be several files that start with config, so you want the one associated with your running kernel.
You can find that by running uname&-a and finding the config file that ends with your kernel version number.
Copy that file into the source directory as .config.
Or just run this command:
cp /boot/config-`uname -r`* .config
Remember, a default config may not have the options you are currently using.
make defconfig
Compiling a kernel from scratch from a distribution configuration can take "forever" because the distros turn on every hardware configuration possible.
For people wanting to do kernel development fast, you want to make a minimal configuration.
Steve Rostedt uses ktest.pl make_min_config to get a truely minimum config, but it will take a day or two to build.
Warning: make sure you have all your USB devices plugged into the system, or you won't get the drivers for them!
If you need to make any changes to your configuration, you can run one of the following commands. These require the curses tools to be installed.
make menuconfig
make nconfig
Or, if you have a multi-core processor, run
Where X is a number like 2 or 4.
If you have a dual core, 2 or 3 might be good.
Quad core, 4 or 6.
Do not run with really big numbers unless you want your machine to be dog-slow!
Walk away, get some coffee, lunch, or go .
To install a kernel, you will need to either manually update your GRUB configuration file, or have an installkernel script.
This script installs the kernel to /boot/, installs modules to /lib/modules/X.Y.Z/ (where X.Y.Z is something like 3.1.5), and updates file /boot/grub/grub.conf.
Fortunately, Ubuntu provides an installkernel script in /sbin/installkernel. The grubby RPM provides it for RPM based systems.
If you have an installkernel script, you can just run
sudo make modules_install install
Or if you don't have sudo installed, run
su -c "make modules_install install"
First, make sure you know how to select a kernel at boot time.
If your new kernel is broken, you want a way to boot into your old kernel. The grub bootloader usually presents users with a choice of kernels and you can reboot into a known good kernel if your new compile doesn't work. Some distros use a default grub config that hides that menu.
You can usually get the menu to appear by mashing the ESC key during boot after the BIOS display disappears.
Ubuntu: To make the grub menu always appear on boot under Ubuntu, remove the GRUB_HIDDEN_TIMEOUT_QUIET line from /etc/default/grub.
You may want to increase the GRUB_DEFAULT timeout from 0 to 15 seconds or more.
After you've finished editing the grub file you may need to update your grub file.
sudo update-grub2
You will (usually) need to reboot into your new kernel.
There are several ways to apply a patch to your kernel.
Usually the maintainer will send you a patch as attachment, or inline in the mail.
You should either save the file, or copy and paste the patch into a new file.
To apply the patch, go to the base kernel directory and run
git am patchfile
Where patchfile is the file you saved.
If patch fails, you can run:
git am --abort
git reset --hard HEAD
git am -3 patchfile
This applies the patch, and attempts to run a three-way merge if the patch application fails.
If all else fails, you can attempt to duplicate the patch changes by hand.
Then you need to re-build your kernel and reboot.
(Note: the older way of manually patching the kernel with patch&-p1&&patchfile does not create any git history, which makes it hard to revert and retry different patches.
You will often have to go through several patches with a maintainer to find the right fix for a bug, so having the git history is useful.)
If a maintainer wants you to revert a patch you have applied, and try a different patch, you can use git to reset the history to the point before the patch was applied.
If git&log shows the patch to be removed is the first log entry, you can run
git reset --hard HEAD^
If you need to revert several patches, you can use git log to find the commit ID of the first commit before those patches.
For instance, say you have applied two patches to the stable tree 3.4.17, and you want to revert those patches.
git&log will look like this:
$ git log --pretty=oneline --abbrev-commit
8901234 Testing patch 2
1234567 Testing patch 1
5390967 Linux 3.4.17
1f94bd4 drm/i915: no lvds quirk for Zotac ZDBOX SD ID12/ID13
, mm: Use memblock memory loop instead of e820_RAM
a0419ca staging: comedi: amplc_pc236: fix invalid register access during detach
To reset your tree to 3.4.17, you can run:
git reset --hard 5390967
If you look at the commits with gitk you will notice that the 3.4.17 commit is also tagged as v3.4.17.
You can reset by tag as well:
git reset --hard v3.4.17
If you have a driver installed as a module, you can recompile just that driver.
This saves time, because the kernel build system doesn't have to look for changes across the entire kernel tree or compile any of the built-in code.
All module files end with .ko.
The kernel make system will compile just one .ko file if you give it the full path to the file:
make drivers/usb/host/xhci-hcd.ko
Note you will need to be in the base kernel source directory for this to work.
You can't make from a different directory.
You can also reload drivers without rebooting your kernel.
For example, I can remove the xHCI driver and reload it with
sudo rmmod xhci-hcd && sudo insmod drivers/usb/host/xhci-hcd.ko
Make sure that you understand the consequences of unloading your driver!
For instance, if you unload the USB core driver in order to try out changes, your USB mouse and keyboard aren't going to work until the USB core driver is reloaded.
You may have to unload other drivers that depend on your driver before you can reload it.
Use lsmod to find which drivers that are loaded depend on your driver.
$ lsmod | grep usb
2 rndis_host,cdc_ether
1 hid_logitech
xhci_hcd,rndis_host,cdc_ether,usbnet,btusb,uvcvideo,usbhid,ehci_hcd
usb_common
In this case, usbcore is used by xhci_hcd, rndis_host, cdc_ether, usbnet, btusb, uvcvideo, usbhid, and ehci_hcd.
I would have to unload all those drivers in order to reload the usbcore module.
Linux Kernel in a Nutshell by Greg Kroah-Hartman, , online:
, Kwan Lowe, 2004
Tell others about this page:

我要回帖

更多关于 linux kernel map 的文章

 

随机推荐