① linux內核移植是什麼意思
內核總是針對某一種硬體(CPU)的,內核移植就是將為某種CPU所寫的linux經過少量修改運行到另外一種CPU上
② 有關linux內核移植時的裁剪涉及哪些內容
嵌入式Linux系統的移植主要有U-Boot、Linux內核、文件系統這三部分。
Uboot是在系統上電時開始執行,初始化硬體設備,准備好軟體環境,然後才調用Linux操作系統內核。文件系統是Linux操作系統中用來管理用戶文件的內核軟體層。文件系統包括根文件系統和建立於Flash內存設備之上文件系統。根文件系統包括系統使用的軟體和庫,以及所有用來為用戶提供支持架構和用戶使用的應用軟體,並作為存儲數據讀寫結果的區域。
可將Linux系統移植過程大致需要分成6個步驟:
1) 准備工作,包括下載源碼、建立交叉編譯環境等。交叉開發是指在開發主機上安裝開發工具,編輯、編譯目標板的引導程序、內核和文件系統,使其能在目標板上運行。
2) 配置和編bootloader(引導裝載程序)。通過這段小程序,可以初始化硬體設備、建立內存空間的映射表,從而建立適當的系統硬體環境,為最終調用操作系統內核做好准備。
3) 配置和編譯Linux內核,對其進行相應的裁剪,修改內核以支持相關的硬體設備。
4) 為大容量NAND Flash移植YAFFS文件系統,並將該文件系統加入Linux內核中;
5) 製作RAMdisk來掛載根文件系統。Linux系統中的文件和設備是通過文件系統來組織的。文件系統的存在使得數據和設備可以被有效而透明地存取訪問。一個linux的最簡根文件系統應該包括支持linux系統正常運行的基本內容,包括系統使用的軟體和庫,以及所有用來為用戶提供基本支持的架構和指令。
6) 燒寫、調試系統;如果調試出錯,則需要重新配置,返回上述步驟(2)。
③ 如何將linux2.6.38內核移植到TQ2440
移植步驟:
1.修改根目錄的Makefile中的ARCH=arm,CROSS-COMPILE=arm-linux-
2.在arch/arm/mach-s3c2440/mach-smdk2440.c中,將163行的s3c24xx_init_clocks(16934400)改為s3c24xx_init_clocks(12000000)。
3.修改arch/arm/tools/mach-types中379行的362改為168,因為uboot中定義的機器碼是168.
4.修改arch/arm/boot/中的Makefile文件,在58行添加@cp -f arch/arm/boot/zImage zImage.bin,實現把生成的zImage文件復制到內核源碼根目錄下。
5.在根目錄的Makefile的1164行添加rm -f zImage.bin,使得在執行make distclean在清除產生的文件的同時,把內核根目錄下的zImage也清除。
6.修改arch/arm/plat-s3c24xx/common-smdk.c中111行的static struct mtd_partition smdk_default_nand_part[]的nandflash分區為:
[0] = {
.name = "Andy_uboot",
.offset = 0x00000000,
.size = 0x00040000,
},
[1] = {
.name = "Andy_kernel",
.offset = 0x00200000,
.size = 0x00200000,
},
[2] = {
.name = "Andy_yaffs2",
.offset = 0x00400000,
.size = 0x0FB80000,
}
7.修改drivers/mtd/nand/s3c2410.c中的839行為chip->ecc.mode=NAND_ECC_NONE;
8.修改arch/arm/mach-s3c2440/mach-smdk2440.c中100行為.ulcon = 0x03。
9.在drivers/serial/samsung.c的51行添加
#include
#include
在433行添加:
if (port->line == 2) {
s3c2410_gpio_cfgpin(S3C2410_GPH(6), S3C2410_GPH6_TXD2);
s3c2410_gpio_pullup(S3C2410_GPH(6), 1);
s3c2410_gpio_cfgpin(S3C2410_GPH(7), S3C2410_GPH7_RXD2);
s3c2410_gpio_pullup(S3C2410_GPH(7), 1);
}
10.用git工具下載最新的yaffs2源代碼。
具體為在終端輸入git clone git://www.aleph1.co.uk/yaffs2下載最新的yaffs2,下
載完成給內核打補丁,進入yaffs目錄,執行
./patch-kernel.sh c m opt/Andy/linux-2.6.38(以自己的內核目錄為准),其中的c代表復制,m代表復合類型。
11.用make menuconfig配置linux內核。
12.執行make zImage,將生成的zImage.bin下載到TQ2440。
13.製作文件系統。
解壓busybox-1.18.4.tar.bz2,修改busybox-1.18.4中的Makefile,在164行和190行分別修改為CROSS-COMPILE=arm-linux-和ARCH=arm。執行make,然後在執行make install。將生成_install復制到根目錄,添加文件系統文件,用天嵌提供的mkyaffs2image生成root.bin的可執行文件,下載到開發板。
14.啟動開發板,列印信息如下:
Start Linux ...
Copy linux kernel from 0x00200000 to 0x30008000, size = 0x00200000 ... Copy Kernel to SDRAM done,NOW, Booting Linux......
Uncompressing Linux... done, booting the kernel.
Linux version 2.6.38-Andy (root@Andy) (gcc version 4.3.3 (Sourcery G++ Lite 2009q1-176) ) #15 Fri Apr 8 20:21:42 CST 2011
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
CPU: VIVT data cache, VIVT instruction cache
Machine: Andy's TQ2440 development board!
ATAG_INITRD is deprecated; please update your bootloader.
Memory policy: ECC disabled, Data cache writeback
CPU S3C2440A (id 0x32440001)
S3C24XX Clocks, Copyright 2004 Simtec Electronics
S3C244X: core 400.000 MHz, memory 100.000 MHz, peripheral 50.000 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/mtdblock2 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: 60896k/60896k available, 4640k reserved, 0K highmem
Virtual kernel memory layout:
vector : 0xffff0000 - 0xffff1000 ( 4 kB)
fixmap : 0xfff00000 - 0xfffe0000 ( 896 kB)
DMA : 0xffc00000 - 0xffe00000 ( 2 MB)
vmalloc : 0xc4800000 - 0xf6000000 ( 792 MB)
lowmem : 0xc0000000 - 0xc4000000 ( 64 MB)
moles : 0xbf000000 - 0xc0000000 ( 16 MB)
.init : 0xc0008000 - 0xc0025000 ( 116 kB)
.text : 0xc0025000 - 0xc0399000 (3536 kB)
.data : 0xc039a000 - 0xc03bac40 ( 132 kB)
SLUB: Genslabs=13, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
NR_IRQS:85
irq: clearing pending ext status 00080000
irq: clearing subpending status 00000003
irq: clearing subpending status 00000002
Console: colour mmy device 80x30
console [ttySAC0] enabled
Calibrating delay loop... 199.47 BogoMIPS (lpj=498688)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
gpiochip_add: gpios 288..303 (GPIOK) failed to register
gpiochip_add: gpios 320..334 (GPIOL) failed to register
gpiochip_add: gpios 352..353 (GPIOM) failed to register
NET: Registered protocol family 16
S3C2440: Initialising architecture
S3C2440: IRQ Support
S3C24XX DMA Driver, Copyright 2003-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 at 0
SCSI subsystem initialized
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 97 KHz
s3c-i2c s3c2440-i2c: i2c-0: S3C I2C adapter
Advanced Linux Sound Architecture Driver Version 1.0.23.
cfg80211: Calling CRDA to update world regulatory domain
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
UDP hash table entries: 256 (order: 0, 4096 bytes)
UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
NET: Registered protocol family 1
RPC: Registered udp transport mole.
RPC: Registered tcp transport mole.
RPC: Registered tcp NFSv4.1 backchannel transport mole.
msgmni has been set to 118
io scheler noop registered (default)
s3c2440-uart.0: ttySAC0 at MMIO 0x50000000 (irq = 70) is a S3C2440
s3c2440-uart.1: ttySAC1 at MMIO 0x50004000 (irq = 73) is a S3C2440
s3c2440-uart.2: ttySAC2 at MMIO 0x50008000 (irq = 76) is a S3C2440
loop: mole loaded
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c24xx-nand s3c2440-nand: Tacls=2, 20ns Twrph0=6 60ns, Twrph1=2 20ns
s3c24xx-nand s3c2440-nand: NAND ECC disabled
NAND device: Manufacturer ID: 0xec, Chip ID: 0xda (Samsung NAND 256MiB 3,3V 8-bit)
NAND_ECC_NONE selected by board driver. This is not recommended !!
Scanning device for bad blocks
Bad eraseblock 62 at 0x0000007c0000
Bad eraseblock 1435 at 0x00000b360000
cmdlinepart partition parsing not available
Creating 3 MTD partitions on "NAND":
0x000000000000-0x000000040000 : "Andy_uboot"
0x000000200000-0x000000400000 : "Andy_kernel"
0x000000400000-0x00000ff80000 : "Andy_yaffs2"
dm9000 Ethernet Driver, V1.31
Now use the default MAC address: 10:23:45:67:89:ab
eth0: dm9000e at c4810000,c4814004 IRQ 51 MAC: 10:23:45:67:89:ab (EmbedSky)
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: New USB device found, idVendor=1d6b, idProct=0001
usb usb1: New USB device strings: Mfr=3, Proct=2, SerialNumber=1
usb usb1: Proct: S3C24XX OHCI
usb usb1: Manufacturer: Linux 2.6.38-Andy ohci_hcd
usb usb1: SerialNumber: s3c24xx
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
Initializing USB Mass Storage driver...
usbcore: registered new interface driver usb-storage
USB Mass Storage support registered.
usbcore: registered new interface driver usbserial
usbserial: USB Serial Driver core
USB Serial support registered for pl2303
usbcore: registered new interface driver pl2303
pl2303: Prolific PL2303 USB to serial adaptor driver
s3c2410_udc: debugfs dir creation failed -19
mousedev: PS/2 mouse device common for all mice
S3C24XX RTC, (c) 2004,2006 Simtec Electronics
s3c-rtc s3c2410-rtc: rtc disabled, re-enabling
s3c-rtc s3c2410-rtc: rtc core: registered s3c as rtc0
i2c /dev entries driver
S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled
usbcore: registered new interface driver usbhid
usbhid: USB HID core driver
ALSA device list:
No soundcards found.
TCP cubic registered
lib80211: common routines for IEEE802.11 drivers
s3c-rtc s3c2410-rtc: setting system clock to 2000-01-02 00:47:19 UTC (946774039)
yaffs: dev is 32505858 name is "mtdblock2" rw
yaffs: passed flags ""
VFS: Mounted root (yaffs filesystem) on device 31:2.
Freeing init memory: 116K
Please press Enter to activate this console.
移植過程中產生的問題及其解決方法將在下一節說明。還有一些驅動沒有移植。繼續努力!
在移植linux2.6.38過程中,遇見了很多的問題,通過在網上查閱相關信息和在圖書館不停的查閱資料,終於成功了。下面將移植過程中產生的問題及其解放方法與大家共享一下。
1、編譯內核時yaffs2出現unknown field 'clear_inode' specified in initializer的
錯誤,原因是所下載的yaffs2不支持linux2.6.38.
解決方法:最新的yaffs2採用git發布,所以採用git工具下載最新的yaffs2源代碼。
具體為在終端輸入git clone git://www.aleph1.co.uk/yaffs2下載最新的yaffs2,下
載完成給內核打補丁,進入yaffs目錄,執行
./patch-ker.sh c m opt/Andy/linux-2.6.38(以自己的內核目錄為准),其中的c代表復制,m代表復合類型。
2、移植linux內核到開發板後,出現data abort的錯誤,錯誤原因為內核大小超過了2M,
天嵌的Uboot只分配給內核2M的空間,所以報錯。
解決方法:精簡內核,使其小於2M。或者修改Uboot,是內核大小大於2M。
所以個人認為天嵌的Uboot值得改進,下一步我將移植Uboot,用自己的Uboot就不存在這個問題了。嘿嘿
3.移植內核時,出現Uncompressing Linux... done, booting the kernel後,系統不能啟動,網上好多人說是因為在menuconfig選項中的Boot options中的Default kernel command string中沒有設置noinitrd root=/dev/mtdblock2 init=/linuxrc console=ttySAC0 rootfs=yaffs2 rw。其實不用設置這個參數也可以,我採用在內核配置文件中將Kernel Feature/Provide old way to pass kernel parameters選上就行了,因為天嵌用的bootloader太老了,從列印的內核信息中就可以看出。(ATAG_INITRD is deprecated; please update your bootloader.)
4.內核啟動時,出現Failed to execute /linuxrc的錯誤,原因是:
(1)文件系統中沒有包含linuxrc的可執行文件。在文件系統中添加linuxrc就可完成linux的啟動。
(2)在/driver/mtd/nand/s3c2410.c中將chip->ecc.mode = NAND_ECC_SOFT;改為chip->ecc.mode = NAND_ECC_NONE;並在配置內核中將Samsung S3C NAND Hardware ECC選項刪掉。
這個問題糾結了我好久,我遇見這個問題後,先嘗試用nfs掛載,能夠掛載上,所以我確定肯定是nandflash出了問題了,以為nandflash壞了(因為被我不停的擦寫,嘿嘿),後來用天嵌自帶的鏡像試了是好的,我就明白了,估計是我的nand驅動有問題了,仔細檢查驅動,發現內核配置中的Samsung S3C NAND Hardware ECC沒有去掉,,一個小小的問題折磨了我這么久。所以一定一定要仔細啊。
5.編譯串口驅動是出現error: implicit declaration of function 's3c2410_gpio_cfgpin'的錯誤,是因為內核版本2.6.38的內核定義s3c2410_gpio_cfgpin是在linux/gpio.h中,所以添加#include 後即可。
6.編譯串口驅動是出現error: 'S3C2410_GPH6' undeclared (first use in this function)是因為在內核版本2.6.38的內核定義s3c2410_gpio_cfgpin的函數變數採用的是S3C2410_GPH(6),而非S3C2410_GPH6,將其改為S3C2410_GPH(6)即可解決問題。
7.linux內核2.6.38的串口程序samsung.c在/driver/tty/serial中。這里與原來的內核版本不一致。這個要注意,內核版本改了,介面也改了,我當時找不到samsung.c,然後通過find命令一看,暈,原來在這裡面。
8.在添加yaffs2內核支持時,找不到Kconfig,復制Yaffs2文件夾中的Kconfig_muti到linux內核的fs/yaffs2中,並將Kconfig_muti修改為Kconfig。
④ LINUX為什麼要進行內核移植 內核移植的作用
做U-boot開發,需要對硬體進行裁剪,U-boot的目的是為了引導內核的啟動,首先保證的是u-boot要和內你的內核配套,然後對硬體進容行裁剪,比如說,你原版的u-boot不支持USB的下載方式,所以需要添加對USB下載方式的支持,下載之前需要做一些初始化的工作,看你的開發板需要初始化哪些硬體,都需要添加到U-boot裡面,內核裡面要裁剪好你這些硬體的驅動程序,u-boot和內核的移植,需要看你的開發板想要支持的硬體,還有自己想實現的功能,比如說U-boot下載界面,都是為了開發方便自己添加上去的。
⑤ linux系統移植和內核移植是什麼_解壓縮然後編譯
沒那麼簡單,除非壓縮包裡面的代碼是板子配套的。linux移植一般包括uboot移植和kernel移植,kernel移植主要是BSP開發,包括設備驅動。希望對你有幫助
⑥ 自己配置的linux內核,移植到mini2440出錯
具體方法參考移植手冊,常見問題如下。
錯誤一:
NOW, Booting Linux......
Uncompressing Linux...................................................................................... done, booting the kernel.
停止的情況
下面的是tools/mach-types中關於體系的參數定義
s3c2440 ARCH_S3C2440 S3C2440 362
mini2440 MACH_MINI2440 MINI2440 1999
解決方法:linux機器碼要與bootloader一致,否則出現這個錯誤!
2.內核的配置
1..[*] Enable loadable mole support --->
[*] Mole unloading
2. System Type ---->
[*] S3C2410 DMA support [*] Support ARM920T processor
S3C2440 Machines --->
[*] SMDK2440
[*] SMDK2440 with S3C2440 CPU moleq
其他的比如2410,2443相關的全部去掉
3.Boot options --->
將 (root=/dev/hda1 ro init=/bin/bash console=ttySAC0) Default kernel command string
改成 (noinitrd root=/dev/mtdblock2 init=/linuxrc console=ttySAC0 )
其中 mtdblock2 表示 MTD 分區的第二個分區存文件系統; Linuxrc 為啟動的首個腳本。
4關掉nand ecc .因為bootload中已經有ecc校驗演算法
Device Drivers --->
<*> Memory Technology Device (MTD) support --->
[*] MTD partitioning support
<*> NAND Device Support --->
<*> NAND Flash support for S3C2410/S3C2440 SoC
[ ] S3C2410 NAND Hardware ECC // 這個要去掉
3.添加nand flash驅動(可參考arm/plat-s3c24xx/common-smdk.c)
在arm/mach-mini2440.c
錯誤二:
//注意結構和函數的順序
中添加static struct mtd_partition mini2440_default_nand_part[] = {
[0] = {
.name = "supervivi",
.size = 0x00040000,//dev/mdkbloack0
.offset = 0,
},
[1] = {
.name = "param",
.offset = 0x00040000,
.size = 0x00020000,
},
[2] = {
.name = "Kernel",
.offset = 0x00560000,
.size =1024 * 1024 * 1024,
},
[3] = {
.name = "nand",
.offset = 0x00000000,
.size = 1024 * 1024 * 1024,
},
};
static struct s3c2410_nand_set mini2440_nand_sets[] = {
[0] = {
.name = "NAND",
.nr_chips = 1,
.nr_partitions = ARRAY_SIZE(mini2440_default_nand_part),
.partitions =mini2440_default_nand_part,
},
};
static struct s3c2410_platform_nand mini2440_nand_info = {
.tacls = 20,
.twrph0 = 60,
.twrph1 = 20,
.nr_sets = ARRAY_SIZE(mini2440_nand_sets),
.sets = mini2440_nand_sets,
.ignore_unset_ecc = 1,
};
錯誤三:
Unable to handle kernel NULL pointer dereference at virtual address 00000018
pgd = c0004000
[00000018] *pgd=00000000
Internal error: Oops: 5 [#1]
make zIamge下載後報錯
解決辦法:
static void __init mini2440_machine_init(void)
{
s3c24xx_fb_set_platdata(&mini2440_fb_info);
s3c_i2c0_set_platdata(NULL);
s3c_device_nand.dev.platform_data = &mini2440_nand_info; //這個函數手冊上沒有,但得加
platform_add_devices(mini2440_devices, ARRAY_SIZE(mini2440_devices));
//smdk_machine_init();
}
static struct platform_device *mini2440_devices[] __initdata = {
&s3c_device_usb,
&s3c_device_lcd,
&s3c_device_wdt,
&s3c_device_i2c0,
&s3c_device_iis,
&s3c_device_nand, // 把 nand flash 設備添加到開發板的設備列表結構
};
更改drivers/mtd/nand/s3c2410.c關閉ecc校驗
chip->ecc.mode = NAND_ECC_SOFT;
改為:chip->ecc.mode = NAND_ECC_NONE;
錯誤四:
arch/arm/mach-s3c2440/mach-mini2440.c:84: error: array type has incomplete element type
arch/arm/mach-s3c2440/mach-mini2440.c:85: error: array index in non-array initializer
arch/arm/mach-s3c2440/mach-mini2440.c:85: error: (near initialization for 'mini2440_nand_sets')
arch/arm/mach-s3c2440/mach-mini2440.c:86: error: field name not in record or union initializer
arch/arm/mach-s3c2440/mach-mini2440.c:86: error: (near initialization for 'mini2440_nand_sets')
arch/arm/mach-s3c2440/mach-mini2440.c:87: error: field name not in record or union initializer
在macn-mini2440中添加頭文件
#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>//這個也不能少的哦
編譯後下載:
affs: dev is 32505858 name is "mtdblock2"
yaffs: passed flags ""
yaffs: Attempting MTD mount on 31.2, "mtdblock2"
yaffs: auto selecting yaffs2
yaffs_read_super: isCheckpointed 0
VFS: Mounted root (yaffs filesystem) on device 31:2.
Freeing init memory: 128K
錯誤五:
Kernel panic - not syncing: Attempted to kill init
解決辦法: 這個時候懵了,哪裡錯呢~ 沒辦法,只能對照著友善的配置一個個大模塊對著來改
當改到Kernel Features的時候錯誤消失了,原來需要選上
Use the ARM EABI to compile the kernel
Allow old ABI binaries to run with thie Kernel
為什麼呢?~ Google了一下,原來友善的根文件系統在編譯的時候也啟用了EABI特性,內核和文件系統需要對上
文件系統用了EABI 內核也要用EABI 內核不用EABI 也只能讀取不用EABI的文件系統
⑦ linux內核移植的一般步驟
#include <reg52.h>
sbit K1=P3^1;
sbit K2=P3^0;
void dealy(int k)
{
int i,j;
for(i=k;i>0;i--)
for(j=110;j>0;j--);
}
void main()
{
int a=0xff;
if(K1==0)
{
dealy(500);
if(K1==0)
{
while(!(K2==0))
{
P2=a;
a=a>>1;
dealy(1000);
if(a==0x00)
{
P2=0x00;
dealy(1000);
a=0xff;
}
}
P2=0xff;
}
}
}