1. 程式人生 > >arm-linux移植手記(三)Linux核心移植

arm-linux移植手記(三)Linux核心移植

    其實已經弄完了,可以把linux核心以及基於busybox1.16.0製作的檔案系統結合。從總的來看是可以用自己的工具鏈編譯生成的u-boot作為Boot Loader,Linux2.6.32.2核心和基於busybox1.16.0的根檔案系統,只是還缺少很多相關的驅動,以後要是想繼續的話再補全啦!這一過程碰到很多問題,包括自己的粗心和記錄不全,當然也包括別人的粗心,讓自己也反反覆覆折騰了好久。令人高興的是終於可以先舒口氣了。
    先說核心的移植,下載了《Mini2440_Linux移植開發實戰指南.pdf》,發現《第三章 Linux-2.6.32.2 核心移植詳細步驟》講得很詳細,以為自己可以很輕鬆的照著做就可以了,沒想到還是有些問題,現在稍微改些,以生成micro2440記錄如下:

    基本的步驟可以是配置為交叉編譯,克隆自己的目標平臺,識別nand分割槽,增加識別yaffs檔案系統

環境介紹:

核心版本:linux2.6.32.2
Linux平臺:虛擬機器下Fedora 11  自己原來編譯的gcc在debian6下,因此在debian6下也順利
交叉編譯工具:fedora 11 :gcc-4.3.2   debian 6 :gcc 4.4.5  
arm開發板:mini2440(CPU:S3C2440 ,SDRAM:64M,Nor Flash:2M,Nand Flash:256M,網絡卡:DM9000EP)

這裡主要還是debian下的過程,發現有問題的時候在Fedora下測試排除編譯器的問題。

    1.下載原始碼
    linux核心官方網站,下載linux核心2.6.32.2  http://www.kernel.org/pub/linux/kernel/v2.6/
    yaffs原始碼:http://www.yaffs.net    但是必須用git下載,命令:git clone git://www.aleph1.co.uk/yaffs2 
    2.克隆自己的目標平臺
    (1)配置為交叉編譯

export KBUILD_BUILDHOST := $(SUBARCH)
ARCH ?= $(SUBARCH)
CROSS_COMPILE ?=
改為
export KBUILD_BUILDHOST := $(SUBARCH)
ARCH ?= arm

CROSS_COMPILE ?= arm-linux-

    (2)增加配置目錄
    在linux-2.6.32.2/arch/arm/configs下增加defconfig配置目錄,自己現在還不打算詳細的去看配置選項,因此直接拷貝的mini2440的,有興趣的可以尋找類似自己的平臺,然後修改。
    (3)在linux-2.6.32.2/arch/arm/mach-s3c2440下複製smdk2440.c建立micro2440.c,參考的文章已說明:linux2.6.32.2核心直接支援mini2440,防止與原有的衝突而刪除。我為了有對照並沒有刪除match-mini2440,而是新建了match-micro2440.c
,因此,對應的修改其目錄下的Makefile:
#obj-$(CONFIG_MACH_MINI2440) += mach-mini2440.o
obj-$(CONFIG_MACH_MINI2440) += mach-micro2440.o
    (4)修改match-micro2440.c
    a.首先對應機器碼
    因為我們的micro2440在linux-2.6.32.2/arch/arm/tools/mach_types 檔案中是沒有機器碼的(比較詳細理解的可以搜尋下或者看參考手冊),而且為了與U-boot中的一致,還是保留了mini2440,
找到MACHINE_START(S3C2440, "SMDK2440") , 
修改為MACHINE_START(MINI2440, "Micro2440 test board")
    b.增加標頭檔案
    參考的手冊上還是少了些東西的,我這裡補上些:
#include <plat/common-smdk.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/nand.h>
#include <linux/mtd/nand_ecc.h>
#include <linux/mtd/partitions.h>
#include <plat/nand.h>
    c.替換“smdk2440”字串
    將match-micro2440.c中的smdk2440替換,就是方便自己檢視,不替換也不影響(去掉#include <plat/common-smdk.h>,替換了可不去)。
    d.修改時鐘
static void __init micro2440_map_io(void)
{
s3c24xx_init_io(micro2440_iodesc, ARRAY_SIZE(micro2440_iodesc));
s3c24xx_init_clocks(12000000);
s3c24xx_init_uarts(micro2440_uartcfgs, ARRAY_SIZE(micro2440_uartcfgs));
}
    e.增加對nand flash的識別
自己對應著修改有區別的地方吧:
static struct platform_device *micro2440_devices[] __initdata = {
&s3c_device_usb,
&s3c_device_lcd,
&s3c_device_wdt,
&s3c_device_i2c0,
&s3c_device_iis,
&s3c_device_nand, //把nand flash 裝置新增到開發板的裝置列表結構  
};
分割槽資訊:
/* NAND Flash on micro2440 board */


static struct mtd_partition micro2440_default_nand_part[]  = {
[0] = {
.name= "u-boot",
.size= 0x00040000,
.offset = 0,
},
[1] = {
.name= "param",
.size= 0x00020000,
.offset = 0x00040000,
},
[2] = {
.name= "kernel",
/* 5 megabytes, for a kernel with no modules
* or a uImage with a ramdisk attached */
.size= 0x00500000,
.offset = 0x00060000,
},
[3] = {
.name= "root",
.offset = 0x00560000,
.size= 1024 * 1024 * 1024, //
},
        [4] = {
.name = "nand", //此區域代表了整片的nand flash,主要是預留使用,比如以後可以通過應用程式訪
//問讀取/dev/mtdblock4 就能實現備份整片nand flash 了。
.offset = 0x00000000,
.size = 1024 * 1024 * 1024, //
},
};


static struct s3c2410_nand_set micro2440_nand_sets[] = {
[0] = {
.name= "nand",
.nr_chips = 1,
.nr_partitions= ARRAY_SIZE(micro2440_default_nand_part),
.partitions = micro2440_default_nand_part,
//.flash_bbt = 1, /* we use u-boot to create a BBT */
},
};


static struct s3c2410_platform_nand micro2440_nand_info  = {
.tacls = 20,
.twrph0 = 60,
.twrph1 = 20,
.nr_sets = ARRAY_SIZE(micro2440_nand_sets),
.sets= micro2440_nand_sets,
.ignore_unset_ecc = 1,
};
修改machineinit函式 
static void __init micro2440_machine_init(void)
{
s3c24xx_fb_set_platdata(&micro2440_fb_info);
s3c_i2c0_set_platdata(NULL);


platform_add_devices(micro2440_devices, ARRAY_SIZE(micro2440_devices));
s3c_device_nand.dev.platform_data = &micro2440_nand_info;


}   
這樣一改:#make micro2440_defconfig     #make zImage一下,以及可以被原來supervivi引導了,但是到最後會因為不支援yaffs而無法引導檔案系統
    3.增加對yaffs的支援
    在下載的yaffs資料夾下執行patch-ker.sh指令碼,其中c 選項表示拷貝,m表示多版本,help中有說明。
./patch-ker.sh c m  ../linux-2.6.32.2
輸出:
Updating ../linux-2.6.32.2/fs/Kconfig
Updating ../linux-2.6.32.2/fs/Makefile
    然後,在核心目錄下執行make menuconfig,新增對yaffs的支援
File systems  ---> 
    [*] Miscellaneous filesystems  ---> 
          <*>   yaffs2 file system support                                               
          -*-     512 byte / page devices                                                
          [ ]       Use older-style on-NAND data format with pageStatus byte (NEW)       
          [ ]         Lets yaffs do its own ECC (NEW)                                     
          -*-     2048 byte (or larger) / page devices                                    
          [*]       Autoselect yaffs2 format (NEW)                                        
          [ ]       Disable yaffs from doing ECC on tags by default (NEW)                 
          [ ]     Force chunk erase check (NEW)                                          
          [ ]     Empty lost and found on boot (NEW)                                      
          [ ]     Disable yaffs2 block refreshing (NEW)                                   
          [ ]     Disable yaffs2 background processing (NEW)                            
          [*]     Enable yaffs2 xattr support (NEW) 
如果執行過make micro2440_defconfig,則直接make zImage;如果沒有,那應該先執行make micro2440_defconfig,再配置yaffs支援,最後make zImage
    如果提示類似fs/yaffs2/Kconfig:131: unknown option "If"的錯誤,可以把fs/yaffs2/Kconfig檔案中的help選項後的說明文字的空行刪除。
    如果有類似於:
  CC      fs/yaffs2/yaffs_vfs.o
fs/yaffs2/yaffs_vfs.c: In function 'yaffs_setattr':
fs/yaffs2/yaffs_vfs.c:522: error: implicit declaration of function 'setattr_copy'
fs/yaffs2/yaffs_vfs.c:525: error: implicit declaration of function 'truncate_setsize'
這樣的錯誤,可能是由於在執行patch-ker.sh的指令碼時,使用選項s的原因。
如果一切OK,那麼將在arch/arm/boot目錄下的zImage用k命令下載看看(Boot Loader和檔案系統為原廠),我的這樣了:
MACH_TYPE = 1999
NOW, Booting Linux......
Uncompressing Linux.............................................................
...................................................................... done, boo
ting the kernel.
Linux version 2.6.32.2 ([email protected]) (gcc version 4.4.5 (GCC) ) #17 Mon Oct 24
11:31:33 CST 2011
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
CPU: VIVT data cache, VIVT instruction cache
Machine: micro2440 board test
ATAG_INITRD is deprecated; please update your bootloader.
Memory policy: ECC disabled, Data cache writeback
CPU S3C2440A (id 0x32440001)
S3C24XX Clocks, (c) 2004 Simtec Electronics
S3C244X: core 405.000 MHz, memory 101.250 MHz, peripheral 50.625 MHz
CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 16256
Kernel command line: noinitrd root=/dev/mtdblock3 init=/linuxrc console=ttySAC0
PID hash table entries: 256 (order: -2, 1024 bytes)
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory: 64MB = 64MB total
Memory: 60524KB available (3688K code, 418K data, 132K init, 0K highmem)
SLUB: Genslabs=11, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
Hierarchical RCU implementation.
NR_IRQS:85
irq: clearing subpending status 00000003
irq: clearing subpending status 00000002
Console: colour dummy device 80x30
console [ttySAC0] enabled
Calibrating delay loop... 201.93 BogoMIPS (lpj=504832)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
NET: Registered protocol family 16
S3C2440: Initialising architecture
S3C2440: IRQ Support
S3C24XX DMA Driver, (c) 2003-2004,2006 Simtec Electronics
DMA channel 0 at c4808000, irq 33
DMA channel 1 at c4808040, irq 34
DMA channel 2 at c4808080, irq 35
DMA channel 3 at c48080c0, irq 36
S3C244X: Clock Support, DVS off
bio: create slab <bio-0> at 0
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
s3c-i2c s3c2440-i2c: slave address 0x10
s3c-i2c s3c2440-i2c: bus frequency set to 98 KHz
s3c-i2c s3c2440-i2c: i2c-0: S3C I2C adapter
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 2048 (order: 2, 16384 bytes)
TCP bind hash table entries: 2048 (order: 1, 8192 bytes)
TCP: Hash tables configured (established 2048 bind 2048)
TCP reno registered
NET: Registered protocol family 1
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
JFFS2 version 2.2. (NAND) 漏 2001-2006 Red Hat, Inc.
ROMFS MTD (C) 2007 Red Hat, Inc.
msgmni has been set to 118
alg: No test for stdrng (krng)
io scheduler noop registered
io scheduler anticipatory registered (default)
io scheduler deadline registered
io scheduler cfq registered
Console: switching to colour frame buffer device 60x53
fb0: s3c2410fb frame buffer device
s3c2440-uart.0: s3c2410_serial0 at MMIO 0x50000000 (irq = 70) is a S3C2440
s3c2440-uart.1: s3c2410_serial1 at MMIO 0x50004000 (irq = 73) is a S3C2440
s3c2440-uart.2: s3c2410_serial2 at MMIO 0x50008000 (irq = 76) is a S3C2440
brd: module loaded
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c24xx-nand s3c2440-nand: Tacls=3, 29ns Twrph0=7 69ns, Twrph1=3 29ns
s3c24xx-nand s3c2440-nand: NAND soft ECC
NAND device: Manufacturer ID: 0xec, Chip ID: 0xda (Samsung NAND 256MiB 3,3V 8-bi
t)
Scanning device for bad blocks
Bad eraseblock 384 at 0x000003000000
Bad eraseblock 385 at 0x000003020000
Bad eraseblock 431 at 0x0000035e0000
Bad eraseblock 447 at 0x0000037e0000
Bad eraseblock 950 at 0x0000076c0000
Bad eraseblock 1098 at 0x000008940000
Creating 5 MTD partitions on "NAND 256MiB 3,3V 8-bit":
0x000000000000-0x000000040000 : "u-boot"
0x000000040000-0x000000060000 : "param"
ftl_cs: FTL header not found.
0x000000060000-0x000000560000 : "kernel"
uncorrectable error :
0x000000560000-0x000040560000 : "root"

mtd: partition "root" extends beyond the end of device "NAND 256MiB 3,3V 8-bit"
-- size truncated to 0xfaa0000
ftl_cs: FTL header not found.
0x000000000000-0x000040000000 : "nand"
mtd: partition "nand" extends beyond the end of device "NAND 256MiB 3,3V 8-bit"
-- size truncated to 0x10000000
dm9000 Ethernet Driver, V1.31
ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
s3c2410-ohci s3c2410-ohci: S3C24XX OHCI
s3c2410-ohci s3c2410-ohci: new USB bus registered, assigned bus number 1
s3c2410-ohci s3c2410-ohci: irq 42, io mem 0x49000000
usb usb1: configuration #1 chosen from 1 choice
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
usbcore: registered new interface driver libusual
mice: PS/2 mouse device common for all mice
S3C24XX RTC, (c) 2004,2006 Simtec Electronics
i2c /dev entries driver
S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled
cpuidle: using governor ladder
sdhci: Secure Digital Host Controller Interface driver
sdhci: Copyright(c) Pierre Ossman
usbcore: registered new interface driver hiddev
usbcore: registered new interface driver usbhid
usbhid: v2.6:USB HID core driver
Advanced Linux Sound Architecture Driver Version 1.0.21.
No device for DAI UDA134X
No device for DAI s3c24xx-i2s
ALSA device list:
  No soundcards found.
TCP cubic registered
NET: Registered protocol family 17
drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
yaffs: dev is 32505859 name is "mtdblock3" rw
yaffs: passed flags ""
usb 1-1: new full speed USB device using s3c2410-ohci and address 2
usb 1-1: configuration #1 chosen from 1 choice
hub 1-1:1.0: USB hub found
hub 1-1:1.0: 4 ports detected
VFS: Mounted root (yaffs filesystem) on device 31:3.
Freeing init memory: 132K
hwclock: can't open '/dev/misc/rtc': No such file or directory
[01/Jan/1970:00:00:12 +0000] boa: server version Boa/0.94.13
[01/Jan/1970:00:00:12 +0000] boa: server built Mar 26 2009 at 15:28:42.
[01/Jan/1970:00:00:12 +0000] boa: starting server pid=751, port 80


open device leds: No such file or directory
Try to bring eth0 interface up......ifconfig: SIOCGIFFLAGS: No such device
ifconfig: SIOCSIFHWADDR: No such device
ifconfig: SIOCSIFADDR: No such device
route: SIOCADDRT: No such process
Done

相關推薦

arm-linux移植手記Linux核心移植

    其實已經弄完了,可以把linux核心以及基於busybox1.16.0製作的檔案系統結合。從總的來看是可以用自己的工具鏈編譯生成的u-boot作為Boot Loader,Linux2.6.32.2核心和基於busybox1.16.0的根檔案系統,只是還缺少很多相關的

java程式設計師菜鳥進階十五linux基礎入門linux使用者和組管理

我們大家都知道,要登入linux作業系統,我們必須要有一個使用者名稱和密碼。每一個使用者都由一個惟一的身份來標識,這個標識叫做使用者ID.系統中的每一個使用者也至少需要屬於一個"使用者分組".同樣,使用者分組也是由一個惟一的身份來標識的,該標識叫做使用者分組ID(GID).每位使用者的許可

arm-linux移植手記基於busybox1.16.0的根檔案系統製作

    參考《Mini2440_Linux移植開發實戰指南.pdf》中的“使用 Busybox 構建檔案系統”,還是有些問題,我自己的為主要原因。詳細的檔案系統的介紹與理解,自己搜尋檢視相關資料吧,我這裡僅是記錄操作步驟與遇到的問題。指南手冊可以在我的資源中下載。環境介紹:

Linux網絡

linux 優先級 treceroute 一、Linux作業和優先級二、ICMP和ftp相關命令三、traceroute四、tcpdump一、Linux作業和優先級nice job fg bg nohup renice job: 前臺作業(foreground):通過終端啟動,且啟動後會一直

linux壓縮命令之xz命令總結

xz linux壓縮 unxz xzcat xz同樣不支持壓縮目錄?xz 1.txt?壓縮文件,壓縮後源文件消失du -sh 1.txt.xz?查看壓縮文件後大小xz -d 1.txt.xz?解壓縮,解壓縮後壓縮包消失unxz 1.txt.xz?解壓縮文件同xz -dxz -c 1.txt &

Linux學習筆記 putty、xshell運用

mage puttygen init for 下載 mkdir shell org c11 上一節學習了centos7的靜態ip配置,今天學習使用putty和xshell遠程連接centos7一.首先來學習使用putty1.下載putty包 https://www.chi

Linux系統管理初步 Linux網絡管理編輯中

中斷 網絡 lin 命令 連接 nag shell sha 系統管理 Linux網絡管理(一) 一、ifconfig命令ifconfig命令可以顯示網卡及ip參數,在centos6中是比較重要的命令。 使用示例:1、網卡停止與網卡啟動 ifdown (網卡名)ifup

03-Linux基礎入門-系統的基礎優化[對於使用虛擬機學習的學習者]

技術分享 ifcfg-eth 特殊 ... selinux 排查 運行 版本 get 1、關閉SELinux功能①SELinux配置文件路徑 /etc/selinux/config ②查看SELinux狀態 getenforce ③關閉SELinux 方法一:常規方法→修

linux常用命令

關閉 現象 磁盤空間 x文件 post div 掛載iso 硬盤 inux 磁盤空間相關的命令 1.mount : 掛載文件系統(包括硬盤,光盤,軟盤等) mount -t 設備類型 存放目錄 eg:在目錄/mnt下,掛載iso9660文件系統:mount -t iso96

linux 基礎命令

linux 基礎命令 上一篇的有個地方補充下(ugo權限對root是不好用的,但是對於其他用戶是好用的) 今天主要跟大家分享下權限 1.UGO權限U:user(擁有者)ownerG:group(所屬組)O:others(其他人) 2. [root@localhost .ssh]# ll -rw-

Linux入侵分析清理木馬和問題用戶

入侵分析 雲安全 清除木馬 安全加固 Linux 1.查看哪些用戶擁有/bin/bash權限 cat /etc/passwd 2.檢查常用命令是否被篡改 (1)找到命令文件的路徑(whereis和which) whereis netstat which netstat which net

linux 常用命令ssh

AD HA key direct password IT 常用 是否可用 erp linux 常用命令(三)ssh (1) 安裝並配置 SSH 無密碼登陸 CentOS 默認已安裝了 SSH client、SSH server,打開終端執行如下命令進行檢驗 rpm -qa

linux內核文件系統

nbsp 編程 目錄 cnblogs 掛載 article 功能 屬於 制作 1、為什麽需要根文件系統 (1)init進程的應用程序在根文件系統上(2)根文件系統提供了根目錄/(3)內核啟動後的應用層配置(etc目錄)在根文件系統上。幾乎可以認為:發行版=內核+rootfs

Linux 筆記 - 第十三章 Linux 系統日常管理之Linux 系統日誌和服務

pac ica link tor 包含 3.1 request closed comm 博客地址:http://www.moonxy.com 一、前言 日誌文件記錄了系統每天發生的各種各樣的事情,比如監測系統狀況、排查問題等。作為系統運維人員可以通過日誌來檢查錯誤發生的原因

Linux shell示例

\n str ons echo return NPU inux pre ech example No. 1作為shell編寫人員,要避免使用者輸入數據的格式不正確,也就是要在shell腳本發布前攔截可能的錯誤;本示例是對使用者輸入的數據(或位置變量)進行判斷是否可用,然後在

linux驅動開發 字符設備驅動框架(自動創建設備節點)

The module __line__ mage fail goto div on() sys 代碼如下 #include <linux/init.h> #include <linux/module.h> #include <linux/ke

Linux應急響應:挖礦病毒

命令 cront 展現 red dir resp ade 2-2 -h 0x00 前言 ? 隨著虛擬貨幣的瘋狂炒作,利用挖礦腳本來實現流量變現,使得挖礦病毒成為不法分子利用最為頻繁的攻擊方式。新的挖礦攻擊展現出了類似蠕蟲的行為,並結合了高級攻擊技術,以增加對目標服務器感染

Linux 基礎命令

ini sss bcd use 個數字 定向 列排序 nbsp 結果 1.file檢查並顯示文件類型(determine file type) 一般用法就是file 後面接要查看的文件 可以一個或多個 [root@test test]# ll total 140 -rw-

Linux基本命令

1、關機命令   Init 0 2、重啟命令 Init 6 3、管道符號  |    ---把前一個命令的輸出結果傳遞給後一個命令處理       以下命令支援放在管道符號後面:more 

linux基礎篇:程序管理

程序 程序的定義:程序就是cpu未完成的工作 ps命令 ps a ##關於當前環境的所有程序 x| -A ##所有程序 f ##顯示程序從屬關係 e ##顯示程序呼叫環境工具的詳細資訊 l ##長列表顯示程序的