歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> 移植Linux-4.7.4到JZ2440開發板

移植Linux-4.7.4到JZ2440開發板

日期:2017/2/28 13:48:44   编辑:Linux教程

一.編譯環境搭建:

1.Linux源碼下載:https://www.kernel.org/
2.安裝交叉編譯工具鏈:
 ①手動下載配置工具鏈

  (1):解壓 arm-linux-gcc-3.4.1.tar.bz2
    #tar -jxvf arm-linux-gcc-3.4.1.tar.bz2
    解壓過程需要一段時間,解壓後的文件形成了 ../temp/usr/local/ 文件夾,進入該文件夾,將arm文件夾拷貝到/usr/local/下
    # cd usr/local/
    #cp -rv arm /usr/local/
    現在交叉編譯程序集都在/usr/local/arm/3.4.1/bin下面了

  (2):修改/etc/profile文件:

    # vim /etc/profile

    增加路徑設置,在末尾添加如下,保存/etc/profile文件:
    export PATH=$PATH:/usr/local/arm/3.4.1/bin

  (3):立即使新的環境變量生效,不用重啟電腦:

   對應方法二:# source /etc/profile

  (4): 檢查是否將路徑加入到PATH:

     # echo $PATH
    顯示的內容中有/usr/local/arm/bin,說明已經將交叉編譯器的路徑加入PATH。
  (5).測試是否安裝成功
  # arm-linux-gcc -v

 ②使用crosstoll-ng構建交叉編譯工具鏈:
 
  (1)官網下載:http://crosstool-ng.org/
   (2)編譯(確認/opt/cross/bin已經安裝):./configure --prefix=/opt/cross : 報錯的話缺what裝what
                      make
                       make install

   (3)使用crosstool-ng構建交叉編譯工具鏈:

    1. 在合適的地方新建一個crosstool-ng工作目錄。這個目錄將會存儲工具鏈的配置文件,自動下載的文件,構建過程中產生的一些中間文件,最後建立在普通可讀寫目錄:
    mkdir -p /home/sheldon/workspace/linux/crosstool

    2. 進入前面一步建立的目錄:
    cd /home/sheldon/workspace/linux/crosstool

    3. 執行 ct-ng menuconfig進入配置界面:(找不到執行檔就鏈接一下:sudo ln -s /opt/cross/bin/ct-ng /usr/bin/ct-ng)
    ct-ng menuconfig

    

4. 選擇‘Paths and misc options’菜單,激活’ Try features marked as EXPERIMENTAL’選項,這一步很重要

    5. 在‘Paths and misc options’ 菜單下,修改‘Directory containing customsource components’值,設置為你想要最終存放工具鏈的目錄。
       (${HOME}/src) Local tarballs directory # 指定制作編譯器所需要的源碼包的下載存放,可以修改成任意位置,請注意權限。現在指定到~/src下。
       (/opt/${CT_TARGET}) Prefix directory # 制作好的編譯器所放置的目錄

    6. 返回主菜單,選擇‘Target options’ , [*] Use EABI # 是否實用EABI方式,對某些指令采用異常的方式來處理(如除法指令),建議選中

    7. ‘Target architecture ’選項選擇‘ arm’;‘Endianness ’選項選擇‘ Little endian’;‘Bitness’選項選擇‘32-bit’。Floating point: (software) ---> # 對於很多ARM架構CPU來說是不支持硬浮點運算的,所以選擇軟件方式有更好的兼容性

    8. 返主菜單,選擇‘Operating system’(跳過‘Toolchain options’,這裡使用缺省選項就夠了)

    9. ‘Target OS’選擇‘linux’, ‘Linuxkernel version’選項中選擇你所使用的內核版本

    10. 返回主菜單,選擇‘Binary utilities

    11. 選擇你需要的版本,筆者直接選擇最高版本(如果需要編譯Linaro版本,請先激活‘Show Linaro versions’選項)。

    12. 返回主菜單,選擇‘C compiler

    13. 選擇你所使用的GCC版本(筆者選擇5.1.0,如果需要編譯Linaro版本,請先激活‘Show Linaro versions’選項),因為筆者需要使用GCC的一個新特性,所以激活‘Compile libsanitizer’選項,一般情況下,保持缺省值就夠了。

    14. Toolchain options --->(tonghuix) Tuple's vendor string # 這裡可以修改成你自己的個性化名稱,最後會生成形如arm-yourname-linux-gnueabi這樣的編譯器前綴

    15. 其它選項用缺省值,退出並保存配置工具

    16. 執行ct-ng build編譯工具鏈
      ct-ng build  

    17. 使用交叉編譯器的時候一般是采用arm-tonghuix-linux-gnueabi這樣的命令的,但是很多標准Makefile需要實用標准的交叉編譯器的名稱,一般這個名稱是arm-linux-gcc這樣的。

      那麼我們在生成交叉編譯器的目錄下寫一個link.sh腳本,新建一些軟鏈接。

      >link.sh

#!/bin/sh
PREFIX=arm-tonghuix-linux-gnueabi-
AFTFIX=arm-linux-
ln -s ${PREFIX}gcc ${AFTFIX}gcc
ln -s ${PREFIX}addr2line ${AFTFIX}addr2line
ln -s  ${PREFIX}gdbtui ${AFTFIX}gdbtui
ln -s  ${PREFIX}ar ${AFTFIX}ar
ln -s  ${PREFIX}as ${AFTFIX}as
ln -s  ${PREFIX}c++ ${AFTFIX}c++
ln -s  ${PREFIX}c++filt ${AFTFIX}c++filt
ln -s  ${PREFIX}cpp ${AFTFIX}cpp
ln -s  ${PREFIX}g++ ${AFTFIX}g++
ln -s  ${PREFIX}gccbug ${AFTFIX}gccbug
ln -s  ${PREFIX}gcj ${AFTFIX}gcj
ln -s  ${PREFIX}gcov ${AFTFIX}gcov
ln -s  ${PREFIX}gdb ${AFTFIX}gdb
ln -s  ${PREFIX}gfortran ${AFTFIX}gfortran
ln -s  ${PREFIX}gprof ${AFTFIX}gprof
ln -s  ${PREFIX}jcf-dump ${AFTFIX}jcf-dump
ln -s  ${PREFIX}ld ${AFTFIX}ld
ln -s  ${PREFIX}ldd ${AFTFIX}ldd
ln -s  ${PREFIX}nm ${AFTFIX}nm
ln -s  ${PREFIX}objcopy ${AFTFIX}objcopy
ln -s  ${PREFIX}objdump ${AFTFIX}objdump
ln -s  ${PREFIX}populate ${AFTFIX}populate
ln -s  ${PREFIX}ranlib ${AFTFIX}ranlib
ln -s  ${PREFIX}readelf ${AFTFIX}readelf
ln -s  ${PREFIX}run ${AFTFIX}run
ln -s  ${PREFIX}size ${AFTFIX}size
ln -s  ${PREFIX}strings ${AFTFIX}strings
ln -s  ${PREFIX}strip ${AFTFIX}strip

      寫完這個link.sh文件以後執行一下:

      sh link.sh

      得到標准名稱的交叉編譯工具鏈,可以在makefile中使用類似arm-linux-gcc這樣的名稱了。

    18. 把你的工具鏈目錄設置到$PATH 環境變量:

      sudo vi /etc/environment 修改PATH的值

      PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/sheldon/x-tools/arm-unknown-linux-gnueabi/bin/"

      . /etc/environment 使生效環境變量

二.編譯linux內核:
  
①清除一下之前的配置:make mrproper
   ②使用默認配置: make s3c2410_defconfig
   ③再配置自己的需求:make menuconfig

      進入【Device Drivers】--->
              Memory Technology Device (MTD) support --->
                  <*>Enable UBI
      進入 【File System】--->
              Miscellaneous filesustems --->
                  <*>UBIFS file system
      進入  【Kernel Features】--->
           [*] Use the ARM EABI to compile the kernel
           [*]   Allow old ABI binaries to run with this kernel (EXPERIMENTAL)

      修改./arch/arm/mach-s3c24xx/common-smdk.c中的smdk_default_nand_part[]結構體數組

      static struct mtd_partition smdk_default_nand_part[] = {
          [0] = {
              .name   = "bootloader",
              .size   = SZ_256K,
              .offset = 0,
          },
          [1] = {
              .name   = "params",
              .offset = MTDPART_OFS_APPEND,
              .size   = SZ_128K,
          },
          [2] = {
              .name   = "kernel",
              .offset = MTDPART_OFS_APPEND,
              .size   = SZ_8M,
          },
          [3] = {
              .name   = "rootfs",
              .offset = MTDPART_OFS_APPEND,
              .size   = MTDPART_SIZ_FULL,
          }
      };

      修改./arch/arm/mach-s3c24xx/mach-smdk2440.c中的smdk2440_init_time(void)函數

      static void __init smdk2440_init_time(void)
���     {
          s3c2440_init_clocks(12000000);//板子的晶振是12M
          samsung_timer_init();
      }

      修改makeflie的第255和256行

      ARCH        ?= arm
      CROSS_COMPILE   ?= arm-linux-

      最後make uImage,在/arch/arm/boot下生成uImage


三.修改U-boot支持新內核:

啟動jz2440,進入uboot
set bootargs console=ttySAC0,115200 root=/dev/mtdblock3
set bootcmd 'nboot 0x32000000 kernel; bootm 0x32000000'
set ipaddr 192.168.199.148      #根據自己修改
set serverip 192.168.199.146    #根據自己修改
save
tftp 0x30000000 uImage
nand erase
nand write.jffs2 0x30000000 kernel $(filesize)
reset

如果系統啟動成功則會最後顯示類似end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-bl,則證明系統啟動成功,下面就是制作根文件系統了。


四.制作新根文件系統采用ubifs文件系統:

首先下載busybox,我這裡用的版本是1.20.0

cd busybox1.20.0
make menconfig
Busybox Settings -->
    Build options -->
        Cross Compiler prefix
        填arm-linux-
Build Options --->
    [*]Build BusyBox as a static binary (no shared libs)

make
make CONFIG_PREFIX=~/2440/ubifs install
cd '/home/zzm/arm/opt/FriendlyARM/toolschain/4.4.3/lib'
cp *.so.* ~/2440/ubifs/lib -d
cd ~/2440/ubifs
cp -r ~/2440/busybox-1.20.0/examples/bootfloppy/etc ./ 
vim inittab

內容如下:

::sysinit:/etc/init.d/rcS
console::askfirst:-/bin/sh
::ctrlaltdel:/bin/umount -a -r
::shutdown:/bin/umount -a -r
vim fstab

內容如下:

proc        /proc   proc    defaults    0   0
tmpfs       /tmp    tmpfs   defaults    0   0
sysfs       /sys    sysfs   defaults    0   0
tmpfs       /dev    tmpfs   defaults    0   0
vim init.d/rcS

內容如下:

#! /bin/sh
mount -a
mkdir /dev/pts
mount -t devpts devpts /dev/pts
echo /sbin/mdev > /proc/sys/kernel/hotplug
mdev -s
cd ~/2440/ubifs
mkdir dev
cd dev
sudo mknod null c 1 3
sudo mknod console c 5 1
cd ..
mkdir proc mnt tmp sys root home
cd ..
mkfs.ubifs -r ubifs -m 2048 -e 129024 -c 105 -o fs_jz2440.img#129024*105=13MB
vim ubinize.cfg
[ubifs]
mode=ubi
image=fs_jz2440.img
vol_id=0
vol_size=13MiB 
vol_type=dynamic
vol_name=root
vol_flags=autoresize

ubinize -o ubi.img -m 2048 -p 128KiB -s 512 ubinize.cfg
生成ubi.img

最後燒寫

tftp 0x30000000 ubi.img
nand erase root
nand write.i 0x30000000 root $(filesize)
bootargs=console=ttySAC0,115200 ubi.mtd=3 root=ubi0:root rootfstype=ubifs
set bootcmd 'nboot 0x32000000 kernel; bootm 0x32000000'
save
reset
Copyright © Linux教程網 All Rights Reserved