6709
Comment:
|
7869
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
## page was renamed from OPWfirstpatchSetup | |
Line 2: | Line 3: |
These instructions assume you're running a variant of Ubuntu (like [[http://www.ubuntu.com/download/desktop/thank-you?distro=desktop&bits=64&release=lts|12.04 LTS]]). | |
Line 3: | Line 5: |
These instructions assume you're running a varient of Ubuntu (like [http://www.ubuntu.com/download/desktop/thank-you?distro=desktop&bits=64&release=lts 12.04 LTS]). == Install some packages == |
= Install some packages = |
Line 9: | Line 8: |
Tip: You may want to pin the terminal app for easy access. Do that by hitting the Windows logo key, moving your mouse over the terminal icon on the left vertical menu, right clicking, and chosing "Lock to Launcher". You can make the menu go away by hitting the escape key. | Tip: You may want to pin the terminal app for easy access. Do that by hitting the Windows logo key, moving your mouse over the terminal icon on the left vertical menu, right clicking, and chosing "Lock to Launcher". You can make the menu go away by hitting the escape key. |
Line 14: | Line 13: |
sudo apt-get install vim libncurses5-dev gcc make git exuberant-ctags}}} | sudo apt-get install vim libncurses5-dev gcc make git exuberant-ctags libssl-dev bison flex libelf-dev bc}}} |
Line 17: | Line 16: |
Line 19: | Line 17: |
{{{ mkdir -p git/kernels cd git/kernels}}} Tip: mkdir creates directories, and cd changes the current working directory to a different directory. You can learn more about any command by reading the manual pages. Simply prefixing the command with the word "man", e.g. {{{man mkdir}}}. Then use the revision control system called [http://git-scm.com/ git] to clone Linus Torvalds' repository: |
|
Line 28: | Line 19: |
git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git}}} | mkdir -p git/kernels; cd git/kernels}}} |
Line 30: | Line 21: |
That's going to take a while. Why don't you read up on [http://lwn.net/Kernel/LDD3/ Linux Device Drivers] in the meantime? The first couple of chapters, especially the ones on kernel modules will be useful. | Tip: mkdir creates directories, and cd changes the current working directory to a different directory. You can learn more about any command by reading the manual pages. Simply prefixing the command with the word "man", e.g. {{{man mkdir}}}. |
Line 32: | Line 23: |
Next, change into the linux directory: | Then use the revision control system called [[http://git-scm.com/|git]] to clone Greg Kroah-Hartman's staging tree repository: |
Line 35: | Line 26: |
cd linux}}} | git clone -b staging-testing git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git}}} That's going to take a while. Why don't you read up on [[http://lwn.net/Kernel/LDD3/|Linux Device Drivers]] in the meantime? The first couple of chapters, especially the ones on kernel modules, will be useful. (Note that LDD3 is a bit outdated; the high-level overviews still make sense, but a few of the code examples are out of date. Still recommended to get a view of the kernel landscape, though.) Next, change into the staging directory: {{{ cd staging}}} |
Line 40: | Line 38: |
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. |
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. |
Line 44: | Line 41: |
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: | |
Line 45: | Line 43: |
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: | |
Line 47: | Line 44: |
cp /boot/config-`uname -r`* .config }}} |
cp /boot/config-`uname -r`* .config }}} |
Line 50: | Line 47: |
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. | If you need to make any changes to your configuration, run this command to silently update any new configuration values to their default: {{{ make olddefconfig}}} If you need to make changes, you can run: |
Line 55: | Line 57: |
This requires the ncurses library to be installed. If you want to compile faster, you can remove from the configuration all the modules you are not using at the moment in your system with: {{{ make localmodconfig}}} Warning: this might not compile some required modules to your system when building the kernel. |
|
Line 56: | Line 67: |
Run | |
Line 57: | Line 69: |
Run | |
Line 62: | Line 73: |
Line 63: | Line 75: |
make -jX }}} |
make -jX }}} |
Line 67: | Line 79: |
Let that compile, and maybe read some more of the [http://lwn.net/Kernel/LDD3/ Linux Device Drivers] book. | Let that compile, and maybe read some more of the [[http://lwn.net/Kernel/LDD3/|Linux Device Drivers]] book. |
Line 69: | Line 81: |
Note: when you run make with a .config file that was copied from a different kernel than the one you were building, you may be prompted to make choices about which new kernel features to enable. When in doubt, just choose the default choice. You can do that by hitting enter. A faster way to simply chose all the defaults is to run {{{make menuconfig}}}. | Note: when you run make with a .config file that was copied from a different kernel than the one you were building, you may be prompted to make choices about which new kernel features to enable. When in doubt, just choose the default choice. You can do that by hitting enter. A faster way to simply chose all the defaults is to run {{{make menuconfig}}}.This will set default values for unset features. Don't forget to save when you exit. |
Line 72: | Line 84: |
Line 76: | Line 87: |
Line 77: | Line 89: |
sudo make modules_install install }}} |
sudo make modules_install install }}} |
Line 80: | Line 92: |
Line 81: | Line 94: |
su -c "make modules_install install" }}} |
su -c "make modules_install install" }}} |
Line 85: | Line 97: |
Line 88: | Line 99: |
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 (like Ubuntu) use a default grub configuration that hides that menu. You can usually get the menu to appear by mashing the ESC key during boot after the BIOS display disappears. | 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 (like Ubuntu) use a default grub configuration that hides that menu. You can usually get the menu to appear by mashing the ESC key during boot after the BIOS display disappears. |
Line 91: | Line 102: |
Line 92: | Line 104: |
sudo vim /etc/default/grub }}} |
sudo vim /etc/default/grub }}} |
Line 96: | Line 107: |
Line 97: | Line 109: |
GRUB_HIDDEN_TIMEOUT=0 GRUB_HIDDEN_TIMEOUT_QUIET=true }}} |
GRUB_HIDDEN_TIMEOUT=0 GRUB_HIDDEN_TIMEOUT_QUIET=true }}} |
Line 102: | Line 112: |
Line 103: | Line 114: |
GRUB_TIMEOUT=10 }}} |
GRUB_TIMEOUT=10 }}} |
Line 109: | Line 119: |
Line 110: | Line 121: |
sudo update-grub2 }}} |
sudo update-grub2 }}} |
Line 117: | Line 126: |
Line 128: | Line 136: |
You may want to send patches with the git send-email command, so you need to install the git-email package: {{{ sudo apt-get install git-email}}} |
|
Line 129: | Line 142: |
{{{ sudo apt-get install gitk }}} |
|
Line 130: | Line 145: |
{{{sudo apt-get install gitk }}} |
gitk is a graphical git repository browser. You can use it to look at the state of your repository and the commits you've made on top of upstream. Just type {{{gitk}}} from within your kernel source directory. |
Line 133: | Line 147: |
In the {{{git/kernels/linux/}}} directory, run {{{make tags }}} |
= Make ctags = In the {{{git/kernels/staging/}}} directory, run |
Line 137: | Line 150: |
That will make ctags for the source code. When you start editing code in vim from the base directory ({{{git/kernels/linux/}}}), you can use the CTRL+[ to look up the definition of a function. See the [http://vim.wikia.com/wiki/Browsing_programs_with_tags ctags entry] in the vim tips wiki for more info. | {{{ make tags }}} That will make ctags for the source code. When you start editing code in vim from the base directory ({{{git/kernels/staging/}}}), you can use the CTRL+] to look up the definition of a function. See the [[http://vim.wikia.com/wiki/Browsing_programs_with_tags|ctags entry]] in the vim tips wiki for more info. |
Line 140: | Line 156: |
Yay, you're done setting up your kernel development environment! Now go start at [wiki:Self:OPWfirstpatch#opw-first-patch-native-start these directions] to get more instructions for how to modify the Linux kernel and send your first patch. |
Yay, you're done setting up your kernel development environment! Now go start at [[OPWfirstpatch#kernel-setup-done|these directions]] to get more instructions for how to modify the Linux kernel and send your first patch. |
Developing on a native Linux platform
These instructions assume you're running a variant of Ubuntu (like 12.04 LTS).
Install some packages
First, open a terminal. Click the ubuntu logo at the top left corner and type "terminal". Click the terminal screen icon.
- Tip: You may want to pin the terminal app for easy access. Do that by hitting the Windows logo key, moving your mouse over the terminal icon on the left vertical menu, right clicking, and chosing "Lock to Launcher". You can make the menu go away by hitting the escape key.
Next, run this command:
sudo apt-get install vim libncurses5-dev gcc make git exuberant-ctags libssl-dev bison flex libelf-dev bc
Setup your Linux kernel code repository
Once that finishes, run these two commands:
mkdir -p git/kernels; cd git/kernels
Tip: mkdir creates directories, and cd changes the current working directory to a different directory. You can learn more about any command by reading the manual pages. Simply prefixing the command with the word "man", e.g. man mkdir.
Then use the revision control system called git to clone Greg Kroah-Hartman's staging tree repository:
git clone -b staging-testing git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git
That's going to take a while. Why don't you read up on Linux Device Drivers in the meantime? The first couple of chapters, especially the ones on kernel modules, will be useful. (Note that LDD3 is a bit outdated; the high-level overviews still make sense, but a few of the code examples are out of date. Still recommended to get a view of the kernel landscape, though.)
Next, change into the staging directory:
cd staging
Now you need to compile the kernel. The first step is setting up your kernel configuration.
Setting up your kernel configuration
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.
Duplicating 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
Changing your config
If you need to make any changes to your configuration, run this command to silently update any new configuration values to their default:
make olddefconfig
If you need to make changes, you can run:
make menuconfig
This requires the ncurses library to be installed.
If you want to compile faster, you can remove from the configuration all the modules you are not using at the moment in your system with:
make localmodconfig
Warning: this might not compile some required modules to your system when building the kernel.
Building the kernel
Run
make
Or, if you have a multi-core processor, run
make -jX
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!
Let that compile, and maybe read some more of the Linux Device Drivers book.
Note: when you run make with a .config file that was copied from a different kernel than the one you were building, you may be prompted to make choices about which new kernel features to enable. When in doubt, just choose the default choice. You can do that by hitting enter. A faster way to simply chose all the defaults is to run make menuconfig.This will set default values for unset features. Don't forget to save when you exit.
Installing the kernel
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"
Running your kernel
Linux stores both old and new kernel versions, so you can boot into your old kernel if you run into issues with your new kernel. The bootloader program called grub lets you chose which kernel you want to boot into.
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 (like Ubuntu) use a default grub configuration that hides that menu. You can usually get the menu to appear by mashing the ESC key during boot after the BIOS display disappears.
To make the grub boot menu always appear under Ubuntu, run
sudo vim /etc/default/grub
Then delete these two lines:
GRUB_HIDDEN_TIMEOUT=0 GRUB_HIDDEN_TIMEOUT_QUIET=true
This next line controls how long grub shows the menu before it choses the kernel at the top of the list (which is usually the most recent kernel):
GRUB_TIMEOUT=10
You may want to increase the GRUB_DEFAULT timeout from 10 seconds to 30 seconds or more. I set it to 60 seconds.
After you've finished editing the grub file, you need to tell grub that you made a change, so that can re-write some automatically generated files. Run this command:
sudo update-grub2
You will (usually) need to reboot into your new kernel.
Email software
To send patches, you will need to be able to have a mail transport client installed:
sudo apt-get install esmtp
Now you will be able to send email through git-send-email. However, we also recommend having a mail client installed that can handle plain text patch format. Our recommendation is a text-based email client called mutt:
sudo apt-get install mutt
You may want to send patches with the git send-email command, so you need to install the git-email package:
sudo apt-get install git-email
Optional tools
sudo apt-get install gitk
gitk is a graphical git repository browser. You can use it to look at the state of your repository and the commits you've made on top of upstream. Just type gitk from within your kernel source directory.
Make ctags
In the git/kernels/staging/ directory, run
make tags
That will make ctags for the source code. When you start editing code in vim from the base directory (git/kernels/staging/), you can use the CTRL+] to look up the definition of a function. See the ctags entry in the vim tips wiki for more info.
Done!
Yay, you're done setting up your kernel development environment! Now go start at these directions to get more instructions for how to modify the Linux kernel and send your first patch.