s3c2440移植linux(轉載) 以及內核模塊的自定義安裝

移植成功了linux到板子上,單移植沒搞明白內核中編譯爲模塊的東西在哪裏怎麼安裝到板子上,因爲在板子上lsmod發現啥都沒有

搜了半天也沒有相關的帖子,研究了一下makefile終於搞明白了,附在文章最後了.


硬件平臺:FL2440

主機平臺:Ubuntu11.04

交叉編譯器:arm-linux-gcc4.3.2

原創作品,轉載請標明出處http://blog.csdn.net/yming0221/article/details/6604616

本來是想移植最新的內核2.6.39但是總是在編譯快完成的時候報錯,有人說是新的內核對arm平臺的支持不好,所以就降低了一下版本,這裏移植2.6.35.4內核

一、準備工作

1、下載解壓內核

從官網上下載linux-2.6.35的內核,ftp://ftp.kernel.org/pub/linux/kernel/v2.6/,文件不大,約85M

新建一個工作目錄s3c2440,將內核源碼包拷貝至工作目錄下,再解壓。

2、移植yaffs2驅動

下載最新的驅動點擊下載解壓在工作目錄s3c2440

進入yaffs2: cd yaffs2 

給內核打補丁:./patch-ker.sh c ../linux-2.6.35


3、安裝交叉編譯環境

下載arm-linux-gcc4.3.2,然後安裝並配置環境變量

最後執行arm-linux-gcc-v查看

二、移植

 



1、修改機器碼

飛凌開發板的bootloader默認的機器碼是193,所以我們在使用smdk2440機器的時候,需要修

改機器碼。修改內核2.6.35.3中的arch/arm/tools/mach-types



 刪掉

s3c2410     ARCH_S3C2410    S3C2410    182 

然後將

s3c2440     ARCH_S3C2440    S3C2440    362 

修改爲

s3c2440     ARCH_S3C2440    S3C2440    193

2、指定目標板machine、編譯器和編譯器路徑

修改linux-2.6.35.3/Makefile,將

ARCH               ?= $(SUBARCH) 

CROSS_COMPILE       ?= 

修改成ARCH               ?= arm 

CROSS_COMPILE       ?= /opt/arm/4.3.2/bin/arm-linux- 

注意:CROSS_COMPILE是指交叉編譯器的路徑,該路徑一定要完整,否則最後makezImage時提示文件不存在。

3、增加devfs文件管理器的支持

我們所用的文件系統使用的是devfs文件管理器。修改fs/Kconfig

找到

menu"Pseudo filesystems"

添加如下語句:

configDEVFS_FS

        bool"/dev file system support (OBSOLETE)"

        defaulty    

configDEVFS_MOUNT

bool"Automatically mount at boot"

defaulty

dependson DEVFS_FS

 

幫助理解:Kconfig就是對應着內核的配置菜單。假如要想添加新的驅動到內核的源碼中,能夠修改Kconfig,

這樣就能夠選擇這個驅動,假如想使這個驅動被編譯,要修改Makefile

4、修改晶振頻率可解決打印信息亂碼問題 )

文件:arch/arm/mach-s3c2440/mach-smdk2440.c

/*s3c24xx_init_clocks(16934400);*/  s3c24xx_init_clocks(12000000);

5、修改MTD分區

[cpp]viewplaincopy

arch/arm/plat-s3c24xx/common-smdk.c

  1. static struct mtd_partition smdk_default_nand_part[] = {  

  2. [0] = {  

  3.         .name   = "Boot",  

  4.         .size   = 0x00100000,  

  5.         .offset = 0  

  6.     },  

  7.     [1] = {  

  8.         .name   = "MyApp",  

  9.         .size   = 0x003c0000,  

  10.         .offset = 0x00140000,  

  11.     },  

  12.     [2] = {  

  13.         .name   = "Kernel",  

  14.         .size   = 0x00300000,  

  15.         .offset = 0x00500000,  

  16.     },  

  17.     [3] = {  

  18.         .name   = "fs_yaffs",  

  19.         .size   = 0x0f000000,    //240M  

  20.         .offset = 0x00800000,  

  21.     },    

  22.     /*[4] = { 

  23.         .name   = "WINCE", 

  24.         .size   = 0x03c00000, 

  25.         .offset = 0x04400000, 

  26.     

  27.     */  

  28. };        


具體參考http://blog.csdn.net/yming0221/article/details/6566551

6、關閉ECC校驗

文件:drivers/mtd/nand/s3c2410.c 
函數:s3c2410_nand_init_chip

/*chip->ecc.mode= NAND_ECC_SOFT; */  chip->ecc.mode = NAND_ECC_NONE;

 

問題:關於ECCECC是“ErrorCorrecting Code”的簡寫,中文名稱是“錯誤檢查和糾正”。ECC是一種能夠實現

錯誤檢查和糾正”的技術,ECC內存就是應用了這種技術的內存,一般多應用在服務器及圖形工作站上,這將使整個

電腦系統在工作時更趨於安全穩定。此處爲避免容易出錯,將ECC關閉。

7、修改nandflash驅動,支持K9F1G08nandflash

   修改drivers/mtd/nand下面的nand_bbt.c 文件:

[cpp]viewplaincopy

  1. static struct nand_bbt_descr largepage_memorybased = {  

  2.         .options = 0,  

  3.         .offs = 0,  

  4.         .len = 1,           // 原數值爲2,支持2K每頁的flash修改爲1K9F1G08K9F2G082k每頁的flash  

  5.         .pattern = scan_ff_pattern  

  6. };  

  7. static struct nand_bbt_descr largepage_flashbased = {  

  8.         .options = NAND_BBT_SCAN2NDPAGE,  

  9.         .offs = 0,  

  10.         .len = 1,           //原數值爲2,支持2K每頁的flash修改爲1K9F1G08K9F2G082k每頁的flash  

  11.         .pattern = scan_ff_pattern  

  12. };  


8、下面,開始配置內核。

進入linux-2.6.35目錄,把s3c2410的默認配置寫入config文件。

makes3c2410_defconfig

makemenuconfig

配置內核特點使用ARMEABI編譯


配置文件系統選項
配置yaffs2文件系統 
修改配置如下:

 Filesystems  ---> 

   [*]Miscellaneous filesystems  --->

       <*>  YAFFS2 file system support 

           -*-    512 byte / page devices

           -*-    2048 byte (or larger) / page devices 

               [*]      Autoselect yaffs2 format 

               [*]    Cache short names in RAM

配置cpu相關選項
修改配置如下:

SystemType  ---> 

   S3C2440Machines  ---> 

       [*]SMDK2440

       [*]SMDK2440 with S3C2440 CPU module

去掉S3C2400MachinesS3C2410MachinesS3C2412MachinesS3C2442Machines的所有選項 ,

否則會報錯。如果現在編譯內核,下載到開發板中,內核就可以正常啓動了.有了雛形,繼續移植設備驅動。

這裏,內核選項*代表編譯至內核,M代表編譯爲模塊 。

9、移植USBhost驅動

在這個版本的linux內核,已經對USB驅動進行來很好的支持,僅僅需要修改配置。

DeviceDrivers  ---> 

   [*]USB support  --->

       {*}  Support for Host-side USB 

       [*]    USB device filesystem (DEPRECATED) 

       [*]    USB device class-devices (DEPRECATED)

       <*>    OHCI HCD support 

       <*>  USB Mass Storage support 

 

   [*]HID Devices  ---> 

       {*}  Generic HID support

       [*]    /dev/hidraw raw HID device support

 

   SCSIdevice support  --->

       <*>SCSI device support

       [*]legacy /proc/scsi/ support

       <*>SCSI disk support 

       <*>SCSI tape support

10、移植RTC驅動

在這個版本的linux內核,已經對RTC驅動進行來很好的支持,不需要修改配置。相應配置如下

DeviceDrivers  --->

   <*>Real Time Clock  --->

       [*]  Set system time from RTC on startup and resume

       (rtc0) RTC used to set the system time

       []   RTC debug support 

             ***RTC interfaces *** 

       [*]  /sys/class/rtc/rtcN (sysfs)

       [*]  /proc/driver/rtc (procfs for rtc0)

       [*]  /dev/rtcN (character devices)

       <*>  Samsung S3C series SoC RTC 

然後添加對設備的支持
打開arch/arm/mach-s3c2440/mach-smdk2440.c ,添加設備,代碼如下:

[cpp]viewplaincopy

  1. static struct platform_device *smdk2440_devices[] __initdata = {  

  2.         &s3c_device_ohci,  

  3.         &s3c_device_lcd,  

  4.         &s3c_device_wdt,  

  5.         &s3c_device_i2c0,  

  6.         &s3c_device_iis,  

  7.         &s3c_device_rtc,  

  8. };  


11、移植UDA1341驅動

在平臺上添加和配置UDA1341:

修改arch/arm/mach-s3c2440/mach-smdk2440.c ,在開始添加頭文件

#include<sound/s3c24xx_uda134x.h>

#include<mach/gpio-fns.h>

[cpp]viewplaincopy

  1. static struct s3c24xx_uda134x_platform_data s3c24xx_uda134x_data = {  

  2.         .l3_clk = S3C2410_GPB(4),  

  3.         .l3_data = S3C2410_GPB(3),  

  4.         .l3_mode = S3C2410_GPB(2),  

  5.         .model = UDA134X_UDA1341,  

  6. };  

  7.    

  8. static struct platform_device s3c24xx_uda134x = {  

  9.         .name = "s3c24xx_uda134x",  

  10.         .dev = {  

  11.                 .platform_data    = &s3c24xx_uda134x_data,  

  12.         }  

  13. };  


把設備添加到平臺當中

[cpp]viewplaincopy

  1. static struct platform_device *smdk2440_devices[] __initdata = {  

  2.         &s3c_device_ohci,  

  3.         &s3c_device_lcd,  

  4.         &s3c_device_wdt,  

  5.         &s3c_device_i2c0,  

  6.         &s3c_device_iis,  

  7.         &s3c_device_rtc,  

  8.         &s3c24xx_uda134x,  

  9. };  


內核配置如下

DeviceDrivers  --->

   <*>Sound card support  --->

       <*>  Advanced Linux Sound Architecture  --->

           <*>  OSS Mixer API

           <*>  OSS PCM (digital audio) API

               [*]    OSS PCM (digital audio) API - Include plugin system

               [*]  Support old ALSA API

               [*]  Verbose procfs contents

               [*]  Verbose printk

               [*]  Generic sound devices  --->

               <*>  ALSA for SoC audio support  --->

                   <*>  SoC Audio for the Samsung S3C24XX chips

                   <*>  SoC I2S Audio support UDA134X wired to a S3C24XX

12、移植DM9000驅動

a、修改 drivers/net/dm9000.c 文件:
頭文件增加:

#include<mach/regs-gpio.h> 

#include<mach/irqs.h>

#include<mach/hardware.h>

dm9000_probe 函數 開始增加:

[cpp]viewplaincopy

  1. unsigned char ne_def_eth_mac_addr[]={0x00,0x12,0x34,0x56,0x80,0x49};  

  2.     static void *bwscon;  

  3.     static void *gpfcon;  

  4.     static void *extint0;  

  5.     static void *intmsk;  

  6.     #define BWSCON           (0x48000000)  

  7.     #define GPFCON           (0x56000050)  

  8.     #define EXTINT0           (0x56000088)  

  9.     #define INTMSK           (0x4A000008)  

  10.           

  11.         bwscon=ioremap_nocache(BWSCON,0x0000004);  

  12.         gpfcon=ioremap_nocache(GPFCON,0x0000004);  

  13.         extint0=ioremap_nocache(EXTINT0,0x0000004);  

  14.         intmsk=ioremap_nocache(INTMSK,0x0000004);  

  15.                          

  16.         writel(readl(bwscon)|0xc0000,bwscon);  

  17.         writel( (readl(gpfcon) & ~(0x3 << 14)) | (0x2 << 14), gpfcon);   

  18.         writel( readl(gpfcon) | (0x1 << 7), gpfcon); // Disable pull-up  

  19.         writel( (readl(extint0) & ~(0xf << 28)) | (0x4 << 28), extint0); //rising edge  

  20.         writel( (readl(intmsk))  & ~0x80, intmsk);      


在這個函數的最後需要修改:

[cpp]viewplaincopy

  1. if (!is_valid_ether_addr(ndev->dev_addr)) {  

  2.                 /* try reading from mac */  

  3.                   

  4.                 mac_src = "chip";  

  5.                 for (i = 0; i < 6; i++)  

  6.                         //ndev->dev_addr[i] = ior(db, i+DM9000_PAR);   

  7.                         ndev->dev_addr[i] = ne_def_eth_mac_addr[i];  

  8.         }  

b、修改arch/arm/mach-s3c2440/mach-smdk2440.c ,添加設備

[cpp]viewplaincopy

  1. static struct platform_device *smdk2440_devices[] __initdata = {  

  2.         &s3c_device_ohci,  

  3.         &s3c_device_lcd,  

  4.         &s3c_device_wdt,  

  5.         &s3c_device_i2c0,  

  6.         &s3c_device_iis,  

  7.         &s3c_device_rtc,  

  8.         &s3c24xx_uda134x,  

  9.         &s3c_device_dm9000,  

  10. };  


c、修改 arch/arm/plat-s3c24xx/devs.c  
添加頭文件

#include<linux/dm9000.h>

添加以下代碼

[cpp]viewplaincopy

  1. static struct resource s3c_dm9000_resource[] = {   

  2.         [0] = {   

  3.         .start = S3C24XX_PA_DM9000,   

  4.         .end   = S3C24XX_PA_DM9000+ 0x3,   

  5.         .flags = IORESOURCE_MEM   

  6.         },   

  7.         [1]={   

  8.         .start = S3C24XX_PA_DM9000 + 0x4, //CMD pin is A2   

  9.         .end = S3C24XX_PA_DM9000 + 0x4 + 0x7c,   

  10.         .flags = IORESOURCE_MEM   

  11.         },   

  12.         [2] = {   

  13.         .start = IRQ_EINT7,   

  14.         .end   = IRQ_EINT7,   

  15.         .flags = IORESOURCE_IRQ   

  16.         },   

  17.         };   

  18.    

  19.         static struct dm9000_plat_data s3c_device_dm9000_platdata = {   

  20.         .flags= DM9000_PLATF_16BITONLY,   

  21.         };   

  22.    

  23.         struct platform_device s3c_device_dm9000 = {   

  24.         .name= "dm9000",   

  25.         .id= 0,   

  26.         .num_resources= ARRAY_SIZE(s3c_dm9000_resource),   

  27.         .resource= s3c_dm9000_resource,   

  28.           .dev= {   

  29.         .platform_data = &s3c_device_dm9000_platdata,   

  30.           }   

  31. };   

  32. EXPORT_SYMBOL(s3c_device_dm9000);  

d、修改 arch/arm/plat-samsung/include/plat/devs.h   45行附近,添加

[cpp]viewplaincopy

  1. extern struct platform_device s3c_device_dm9000;  

e、修改arch/arm/mach-s3c2410/include/mach/map.h 文件

/*DM9000 */ 

#define  S3C24XX_PA_DM9000 0x20000300 

#define  S3C24XX_VA_DM9000 0xE0000000

13、啓動畫面顯示小企鵝的方法

配置內核 ,下面是必選項

DeviceDrivers--->

   Graphicssupport  ---> 

               <*>Support for frame buffer devices

               <*>S3C2410 LCD framebuffer support ,multi support! 

               Consoledisplay driver support  --->

                      <*>Framebuffer Console support  

               Logoconfiguration  --->  

                      [*]Bootup logo 

                              [*]  Standard 224-color Linux logo


143.5LCD顯示的移植

2.6.34內核中已經支持

15、修改uart2爲普通串口以及測試程序

修改arch/arm/mach-s3c2440/mach-smdk2440.c 中的uart2的配置,修改後如下:

[cpp]viewplaincopy

  1. static struct s3c2410_uartcfg smdk2440_uartcfgs[] __initdata = {  

  2.         [0] = {  

  3.                 .hwport             = 0,  

  4.                 .flags             = 0,  

  5.                 .ucon             = 0x3c5,  

  6.                 .ulcon             = 0x03,  

  7.                 .ufcon             = 0x51,  

  8.         },  

  9.         [1] = {  

  10.                 .hwport             = 1,  

  11.                 .flags             = 0,  

  12.                 .ucon             = 0x3c5,  

  13.                 .ulcon             = 0x03,  

  14.                 .ufcon             = 0x51,  

  15.         },  

  16.         /* IR port */  

  17.         [2] = {  

  18.                 .hwport             = 2,  

  19.                 .flags             = 0,  

  20.                 .ucon             = 0x3c5,  

  21.                 .ulcon             = 0x03,/*fatfish 0x43*/  

  22.                 .ufcon             = 0x51,  

  23.         }  

  24. };  

drivers/serial/samsung.c 中添加對uart2控制器的配置,配置爲普通串口。

添加頭文件:

#include<linux/gpio.h> 

#include<mach/regs-gpio.h> 

staticint s3c24xx_serial_startup(struct uart_port *port)函數中,添加

[cpp]viewplaincopy

  1. if (port->line == 2) {   

  2.                s3c2410_gpio_cfgpin(S3C2410_GPH(6), S3C2410_GPH6_TXD2);   

  3.                s3c2410_gpio_pullup(S3C2410_GPH(6), 1);   

  4.                s3c2410_gpio_cfgpin(S3C2410_GPH(7), S3C2410_GPH7_RXD2);   

  5.                s3c2410_gpio_pullup(S3C2410_GPH(7), 1);   

  6.        }   

16、移植看門狗

修改配置

DeviceDrivers --->

   [*]Watchdog Timer Support --->

        <*>S3C2410 Watchdog

最後:make zImage

最後編譯出來的zImage2.1M左右。

燒寫內核,啓動成功


不過,此時,顯示屏顯示還有點問題,出現上下兩欄。解決方法如下:

修改machsmdk2440.c

[cpp]viewplaincopy

  1. static struct s3c2410fb_display smdk2440_lcd_cfg __initdata = {  

  2.      /* Config for 320x240 LCD */  

  3.     .lcdcon5 = S3C2410_LCDCON5_FRM565 |  

  4.                        S3C2410_LCDCON5_INVVLINE |  

  5.                        S3C2410_LCDCON5_INVVFRAME |  

  6.                        S3C2410_LCDCON5_PWREN |  

  7.                        S3C2410_LCDCON5_HWSWP,  

  8.               

  9.     .type       = S3C2410_LCDCON1_TFT,  

  10.     .width      = 320,  

  11.     .height     = 240,  

  12.     .pixclock   = 270000,  

  13.     .xres       = 320,  

  14.     .yres       = 240,  

  15.     .bpp        = 16,  

  16.     .left_margin    =8,   

  17.     .right_margin   = 5,    

  18.     .hsync_len  =  63,   

  19.     .upper_margin   = 15,  

  20.     .lower_margin   = 3,  

  21.     .vsync_len  =  5,  

  22. };  

並且將.lpcsel= ((0xCE6) & ~7) | 1<<4,註釋掉

[cpp]viewplaincopy

  1. static struct s3c2410fb_mach_info smdk2440_fb_info __initdata = {  

  2.     .displays   = &smdk2440_lcd_cfg,  

  3.     .num_displays   = 1,  

  4.     .default_display = 0,  

  5.   

  6. #if 0  

  7.     /* currently setup by downloader */  

  8.     .gpccon     = 0xaa940659,  

  9.     .gpccon_mask    = 0xffffffff,  

  10.     .gpcup      = 0x0000ffff,  

  11.     .gpcup_mask = 0xffffffff,  

  12.     .gpdcon     = 0xaa84aaa0,  

  13.     .gpdcon_mask    = 0xffffffff,  

  14.     .gpdup      = 0x0000faff,  

  15.     .gpdup_mask = 0xffffffff,  

  16. #endif  

  17.   

  18.     //.lpcsel       = ((0xCE6) & ~7) | 1<<4,  

  19. };  

重新編譯即可。

至此,2.6.35.4內核移植成功。


關於內核模塊:

make 完成後

運行: make modules

編譯生成內核模塊,就是在變以內和過程中選擇"M"的模塊

然後make modules_install,這裏值得說明一下,直接運行這個命令,會在當前主機上建立/lib/modules/2.6.XX/ 的目錄並將模塊安裝過來,如果想自己指定這個安裝路徑怎麼辦呢,通過查看makefile發現,只要指定環境變量INSTALL_MOD_PATH即可

運行:

INSTALL_MOD_PATH=/home/user/modules make modules_install

成功將模塊安裝只/home/user/modules

du -sh 看了一下,所有模塊有32M,太大了,我就不往板子上放了.

需要的話可以單獨拷貝需要的模塊到板子上.



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章