Construct embedded Linux (1): Kernel Compilation

Source: Internet
Author: User

Use the cross-compilation environment


Build your own cross-compiling environment to compile the kernel. This part is also a practice of chapter 5 of O 'Reilly's Building Embeded Linux System. We still use moblin as an example. He has provided an example of the config file for the kernel. For menlow, You need to merge config-generic and config-menlow. You can manually modify the data based on the menlow configuration on the basis of generic, or use merge. pl, merg. pl config-generic config-menlow> provided by moblin.
Wei-config, and then cp wei-config. config.
. In alpha3, it seems that merge has some problems with the results. You still need to manually modify the results, but in beta, there is no problem.

$ Make ARCH = x86 CROSS_COMPILE = i586-linux-bzImage
"Because the kernel is large, if zImage is used, an error is reported. bzImage is required 』
$ Make ARCH = x86 CROSS_COMPILE = i586-linux-modules

In the cross-compilation environment, do not use the root identity to overwrite the host system file to avoid misoperations. After compilation, we will sort out the generated key system files and save them as follows:

$ Cp System. map $ PRJROOT/images/myproject/System. map-2.6.29-menlow
$ Cp vmlinux $ PRJROOT/images/myproject/vmlinux-2.6.29-menlow
$ Cp. config $ PRJROOT/images/myproject/2.6.29-menlow. config
$ Cp arch/x86/boot/bzImage $ PRJROOT/images/myproject/bzImage2.6.29-menlow
$ Mkdir modules-2.6.29-menlow
// Used to store our modules

Installation module, stored in the specified location: $ make ARCH = x86 CROSS_COMPILE = i586-linux-INSTALL_MOD_PATH = $ PRJROOT/images/myproject/modules-2.6.29-menlow modules_install

We need to establish the dependency between modules through busybox.

$ Wget http://busybox.net/downloads/busybox-1.13.4.tar.bz2
$ Busybox-1.1.1 cd
$ Make defconfig
// Use the default configuration, which can be configured through make menuconfig. There are many options
$ Make

BusyBox was originally written by Bruce Perens in 1996 for the Debian GNU/Linux installation disk. The goal is to create a bootable GNU/Linux system on a floppy disk, which can be used as an installation disk and an emergency disk. A floppy disk can save about 1.4-1.7 MB of content, so there is not much space left for the Linux kernel and related user applications. BusyBox exposes the fact that many standard Linux tools can share many common elements. For example, many file-based tools (such as grep and find) need to search for file code in the directory. When these tools are merged into an executable program, they can share these same elements to produce smaller executable programs. In fact, BusyBox can pack a tool of about 3.5 MB into a size of about KB. This provides more functionality for boot disks and embedded devices using Linux. We can use BusyBox for Linux kernels 2.4 and 2.6.

Place exampls/depmod. pl in the tool location.

$ Depmod. pl-k. /vmlinux-2.6.29-menlow [or use-F System. map-2.6.29-menlow]-B $ PRJROOT/images/myproject/modules-2.6.29-menlow/lib/modules/2.6.29.1-menlow $ PRJROOT/images/myproject/modules-2.6.29-menlow/lib/modules/2.6.29.1-menlow/modules. dep

Regenerate modules. dep and I also copy it to $ PRJROOT/images/myproject/modules. dep-2.6.29-menlow.

Use the development environment of MIC2


The moblin-chroot tool is available in MIC2 to generate our development environment and provide a simulated target. In the kickstart file of the generated image, we directly change kernel-netbook to kernel-menlow, and the screen appears during installation. If we install netbook img on the mid, we can install it, however, the speed is slow, which may be related to CPU adaptation and cannot be tolerated. Before adding various drivers, we need to adapt the kernel to the menlow Chip Based on the netbook version.

  • [Wei @ Wei project] $ sudo moblin-chroot-s Wei-kernel-chroot -- Unpack-only moblin-netbook-core-developer-alpha3-200905081154.usbimg
    // Enter the simulated environment
  • [Wei @ Wei project] $ sudo moblin-chroot Wei-kernel-chroot/
  • Bash-3.2 # Alias ls = "ls -- color"
    // If you are not used to the absence of colors, modify it.
  • Bash-3.2 # rpm-IVH kernel-2.6.29.1-18.1.moblin2.src.rpm
    // Unpack the RPM package
  • Bash-3.2 # Cd ~
    Bash-3.2 # echo % _ default_patch_fuzz 2>. rpmmacros

    In alpha3, a patch is installed in alpha3 and fuzz 0 is used. The following error occurs:
    Patch #8 (linux-2.6.29-drm-revert.patch ):
    +/Bin/cat/home/wei/rpmbuild/SOURCES/linux-2.6.29-drm-revert.patch
    +/Usr/bin/patch-s-p1 -- fuzz = 0
    -- Saving rejects to file drivers/gpu/drm/i915/i915_dma.c.rej
    1 out of 1 hunk FAILED -- saving rejects to file drivers/gpu/drm/i915/i915_drv.h.rej
    Error: Bad exit status from/var/tmp/rpm-tmp.JUmRvI (% prep) requires fuzz 2, but in beta, this issue is not required. Fuzz: if these locations are not found and the patch command is applying the context difference list, the patch command can perform an inaccurate search. Fuzz factor specifies the number of rows that are not exactly matched. If the Blur factor is set to 1 or greater, the patch command executes the second scan and ignores the first and last rows of the context. If no matching result is found and the maximum blur factor is set to 2 or greater, the patch command executes the third scan, which ignores the first two and last two rows of the context. (The maximum value of the default fuzzy factor is 2 ). If no matching position is found, the patch Command places the block (hunk) in the reject file ). The name of the rejected file is the same as that of the output file, but the file name is suffixed with. rej. The-r flag can overwrite this naming convention.
  • Bash-3.2 # cd rpmbuild/
    Bash-3.2 # ls
    SOURCES SPECS
    Bash-3.2 # cd SPECS/
    Bash-3.2 # rpmbuild-bp kernel. spec
    // Patch
  • The method for generating. config is the same as that in the Cross-compiling environment.
  • Bash-3.2 # make ARCH = x86 bzImage
  • Bash-3.2 # make ARCH = x86 modules
  • Bash-3.2 # make ARCH = x86 modules_install
  • You can use yum to import busybox, But I searched for depmod. pl and provided depmod. But an error was reported during running. I downloaded the busybox package and ran it #~ /Bin/depmod. pl-k./vmlinux-2.6.29-menlow-B/lib/modules/2.6.29.3-menlow // lib/modules/2.6.29.3-menlow/modules. dep

I tried to install it directly using make install,
Make install seems to copy the bzImage file to/boot as vmlinuz. However, when you want to create an img using MIC2, the following error occurs:

This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first. Use tune2fs-c or-I to override.
Tune2fs 1.41.3 (12-Oct-2008)
Setting maximal mount count to-1
Setting interval between checks to 0 seconds
Copying filesystem...
Error creating Live CD: Unable to copy valid kernels or initrds, please check the repo
Your new image can be found here:
Finished.

This problem needs to be further solved. There is no/etc/grub. conf file in moblin, while/boot/grub is different from normal linux.
The reason is that no initrd-file is found in/boot. This file seems to have been deleted in the make modules_install step.

Modify Time Zone



:

1. query the name of the time zone to be replaced in the/usr/share/zoneinfo/directory.
2. Remove the original localtime file;
# Mv/etc/localtime-old
3. Create a New localtime file and link the corresponding time zone file.
# Ln-S/usr/share/zoneinfo/Asia/Shanghai/etc/localtime

 

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.