如何移植iptables1.4.9到Tiny6410_Linux2.6.38内核

    版权声明:对于本博客所有原创文章,允许个人、教育和非商业目的使用,但务必保证文章的完整性且不作任何修改地以超链接形式注明原始作者、出处及本声明。

    博客地址:http://blog.csdn.net/shuxiao9058

    原始作者:季亚


一、 建立交叉编译环境
在Linux平台下,要为开发板(Tiny6410等)开发程序,编译内核等操作时,均需要交叉编译工具链,我们使用的是arm-linux-gcc-4.5.1,它默认采用arm-v6指令集,支持硬浮点运算,下面是安装它的详细步骤:

Step1: 下载arm-linux-gcc-4.5.1,并将其拷贝至Linux下任意目录位置(如/tmp/linux),打开终端切换到该位置,执行解压命令(注意:C后面有个空格,并且C是大写的,它是英文单词“change”的第一个字母,在此是改变目录的意思):

arm-linux-gcc-4.5.1下载地址:http://115.com/file/e6au07fx#

执行如下命令:

[root@localhost ~]# cd /tmp/linux/
[root@localhost linux]# ls
arm-linux-gcc-4.5.1-v6-vfp-20101103.tgz  mktools-20110720.tar.gz
arm-qte-4.7.0-20101105.tar.gz            rootfs_qtopia_qt4-20111018.tgz
arm-qt-extended-4.4.3-20101105.tgz       rootfs_qtopia_qt4-s-20111018.tgz
arm-qtopia-20101105.tar.gz               u-boot-mini6410-20111018.tar.gz
busybox-1.17.2-20101120.tgz              x86-qte-4.6.1-20100201.tar.gz
examples-mini6410-20110104.tgz           x86-qt-extended-4.4.3-20101003.tgz
linux-2.6.28.6-20101007.tar.gz           x86-qtopia-20100420.tar.gz
linux-2.6.38-20110718.tar.gz             说明.txt
logomaker.tgz
[root@localhost linux]# tar xzvf arm-linux-gcc-4.5.1-v6-vfp-20101103.tgz -C /

执行以上命令,将把arm-linux-gcc安装到/opt/FriendlyARM/toolschain/4.5.1目录下。

Step2:把编译器路径加入系统环境变量,可以运行如下命令:

[root@localhost linux]# echo "export PATH=$PATH:/opt/FriendlyARM/toolschain/4.5.1/bin" >> ~/.bashrc
注意:这里我们使用的是root用户修改的,因此只对root用户生效!如果其他用户也要使用arm-linux-gcc,在使用其他用户登录终端后请重新使用本命令。

也可以运行如下命令,修改~/.bashrc这个文件:

[root@localhost /]# vi ~/.bashrc

# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi
export PATH=$PATH:/opt/FriendlyARM/toolschain/4.5.1/bin

修改完毕后记得要保存。


测试:重新登录系统(不必重启机器,开始->logout 或者重新打开终端即可),使以上设置生效,在命令行输入arm-linux-gcc -v,会出现如下信息,这说明交叉编译环境已经成功安装。 

[root@localhost /]# arm-linux-gcc -v
Using built-in specs.
COLLECT_GCC=arm-linux-gcc
COLLECT_LTO_WRAPPER=/opt/FriendlyARM/toolschain/4.5.1/libexec/gcc/arm-none-linux-gnueabi/4.5.1/lto-wrapper
Target: arm-none-linux-gnueabi
Configured with: /work/toolchain/build/src/gcc-4.5.1/configure --build=i686-build_pc-linux-gnu --host=i686-build_pc-linux-gnu --target=arm-none-linux-gnueabi --prefix=/opt/FriendlyARM/toolschain/4.5.1 --with-sysroot=/opt/FriendlyARM/toolschain/4.5.1/arm-none-linux-gnueabi/sys-root --enable-languages=c,c++ --disable-multilib --with-cpu=arm1176jzf-s --with-tune=arm1176jzf-s --with-fpu=vfp --with-float=softfp --with-pkgversion=ctng-1.8.1-FA --with-bugurl=http://www.arm9.net/ --disable-sjlj-exceptions --enable-__cxa_atexit --disable-libmudflap --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --with-gmp=/work/toolchain/build/arm-none-linux-gnueabi/build/static --with-mpfr=/work/toolchain/build/arm-none-linux-gnueabi/build/static --with-ppl=/work/toolchain/build/arm-none-linux-gnueabi/build/static --with-cloog=/work/toolchain/build/arm-none-linux-gnueabi/build/static --with-mpc=/work/toolchain/build/arm-none-linux-gnueabi/build/static --with-libelf=/work/toolchain/build/arm-none-linux-gnueabi/build/static --enable-threads=posix --with-local-prefix=/opt/FriendlyARM/toolschain/4.5.1/arm-none-linux-gnueabi/sys-root --disable-nls --enable-symvers=gnu --enable-c99 --enable-long-long
Thread model: posix
gcc version 4.5.1 (ctng-1.8.1-FA) 
[root@localhost /]# 

二、 重新配置编译内核,使其支持netfilter

Netfilter是内核态提供的包过滤框架,其中包含了各种各样的过滤表,默认的内核配置一般不包含这个框架,所以我们要先配置内核选项让其支持netfilte才行。

首先我们需要把友善官方提供的Linux内核源码解压到Linux下指定目录(/opt/FriendlyARM/mini6410/linux/),然后切换到该目录下,会发现多了一个linux-2.6.38文件夹:

[root@localhost /]# cd /opt/FriendlyARM/mini6410/linux/
[root@localhost linux]# ls
arm-qte-4.7.0          busybox-1.17.2  rootfs_qtopia_qt4  x86-qt-extended-4.4.3
arm-qt-extended-4.4.3  examples        u-boot-mini6410    x86-qtopia
arm-qtopia             linux-2.6.38    x86-qte-4.6.1
[root@localhost linux]# 
切换到linux-2.6.38文件夹下,首先我们使用make distclean命令清除临时文件、中间文件和配置文件!然后查看里面的文件,会发现有很多配置文件,这些都是友善预先为我们做好的配置文件,方便了我们使用,在此我们将板子自带的配置文件改名为.config,执行cp config_mini6410_n43 .config,接下来就需要进入图形选择相应的选项了。
[root@localhost linux]# cd linux-2.6.38/
[root@localhost linux-2.6.38]# make distclean
  CLEAN   .
  CLEAN   arch/arm/kernel
  CLEAN   drivers/tty/vt
  CLEAN   drivers/video/logo
  CLEAN   firmware
  CLEAN   kernel
  CLEAN   lib
  CLEAN   usr
  CLEAN   arch/arm/boot/compressed
  CLEAN   arch/arm/boot
  CLEAN   .tmp_versions
  CLEAN   vmlinux System.map .tmp_kallsyms1.o .tmp_kallsyms1.S .tmp_kallsyms2.o .tmp_kallsyms2.S .tmp_vmlinux1 .tmp_vmlinux2 .tmp_System.map
  CLEAN   scripts/basic
  CLEAN   scripts/kconfig
  CLEAN   scripts/mod
  CLEAN   scripts
  CLEAN   include/config include/generated
  CLEAN   .config .config.old .version include/linux/version.h Module.symvers
[root@localhost linux-2.6.38]# ls
arch                         config_mini6410_x35  lib
block                        COPYING              MAINTAINERS
config_mini6410_a70          CREDITS              Makefile
config_mini6410_ezvga        crypto               mm
config_mini6410_g10          Documentation        net
config_mini6410_l80          drivers              README
config_mini6410_n43          firmware             REPORTING-BUGS
config_mini6410_s70          fs                   samples
config_mini6410_t35          include              scripts
config_mini6410_vga1024x768  init                 security
config_mini6410_vga640x480   ipc                  sound
config_mini6410_vga800x600   Kbuild               tools
config_mini6410_w35          Kconfig              usr
config_mini6410_w50          kernel               virt
[root@localhost linux-2.6.38]# cp config_mini6410_n43 .config
[root@localhost linux-2.6.38]# 
完成以上操作后,在Linux代码树下执行make menuconfig命令,进入基于文本模式的菜单型的Linux内核配置。

[root@localhost linux-2.6.38]# make menuconfig
scripts/kconfig/mconf Kconfig
warning: (PLAT_S3C64XX) selects SAMSUNG_WAKEMASK which has unmet direct dependencies (PLAT_SAMSUNG && PM)

 .config - Linux/arm 2.6.38 Kernel Configuration
 ------------------------------------------------------------------------------
  +----------------- Linux/arm 2.6.38 Kernel Configuration -----------------+
  |  Arrow keys navigate the menu.   selects submenus --->.          |
  |  Highlighted letters are hotkeys.  Pressing  includes,  excludes, |
  |   modularizes features.  Press  to exit,  for Help,  |
  |  for Search.  Legend: [*] built-in  [ ] excluded   module  < >       |
  | +---------------------------------------------------------------------+ |
  | |        General setup  --->                                          | |
  | |    [*] Enable loadable module support  --->                         | |
  | |    -*- Enable the block layer  --->                                 | |
  | |        System Type  --->                                            | |
  | |        Bus support  --->                                            | |
  | |        Kernel Features  --->                                        | |
  | |        Boot options  --->                                           | |
  | |        CPU Power Management  --->                                   | |
  | |        Floating point emulation  --->                               | |
  | |        Userspace binary formats  --->                               | |
  | +----v(+)-------------------------------------------------------------+ |
  +-------------------------------------------------------------------------+
  |                        < Exit >    < Help >                     |
  +-------------------------------------------------------------------------+

Step2:在上面的菜单项中,按向下箭头键向下翻!选择“Networking options  ---> ”项,回车进入子菜单项:

  +-------------------------- Networking options ---------------------------+
  |  Arrow keys navigate the menu.   selects submenus --->.          |
  |  Highlighted letters are hotkeys.  Pressing  includes,  excludes, |
  |   modularizes features.  Press  to exit,  for Help,  |
  |  for Search.  Legend: [*] built-in  [ ] excluded   module  < >       |
  | +---------------------------------------------------------------------+ |
  | |    <*> Packet socket                                                | |
  | |    <*> Unix domain sockets                                          | |
  | |    < > PF_KEY sockets                                               | |
  | |    [*] TCP/IP networking                                            | |
  | |    [ ]   IP: multicasting                                           | |
  | |    [ ]   IP: advanced router                                        | |
  | |    [*]   IP: kernel level autoconfiguration                         | |
  | |    [*]     IP: DHCP support                                         | |
  | |    [*]     IP: BOOTP support                                        | |
  | |    [*]     IP: RARP support                                         | |
  | +----v(+)-------------------------------------------------------------+ |
  +-------------------------------------------------------------------------+
  |                        < Exit >    < Help >                     |
  +-------------------------------------------------------------------------+

Netfilter配置菜单页

  +------------ Network packet filtering framework (Netfilter) -------------+
  |  Arrow keys navigate the menu.   selects submenus --->.          |
  |  Highlighted letters are hotkeys.  Pressing  includes,  excludes, |
  |   modularizes features.  Press  to exit,  for Help,  |
  |  for Search.  Legend: [*] built-in  [ ] excluded   module  < >       |
  | +---------------------------------------------------------------------+ |
  | |    --- Network packet filtering framework (Netfilter)               | |
  | |    [ ]   Network packet filtering debugging (NEW)                   | |
  | |    [*]   Advanced netfilter configuration (NEW)                     | |
  | |          Core Netfilter Configuration  --->                         | |
  | |    < >   IP virtual server support (NEW)  --->                      | |
  | |          IP: Netfilter Configuration  --->                          | |
  | |                                                                     | |
  | |                                                                     | |
  | |                                                                     | |
  | |                                                                     | |
  | +---------------------------------------------------------------------+ |
  +-------------------------------------------------------------------------+
  |