看到飞凌嵌入式论坛上的linux移植比较详细 记下啦!

开贴详述linux-2.6.33内核的移植

宿主机:ubuntu9.10
目标机:s3c2440
交叉编译器:arm-linux-gcc-3.4.1
交叉编译器路径:/usr/local/arm/3.4.1
移植内核版本:linux-2.6.33
文件系统类型: yaffs2 (目前使用光盘中linux-2.6.28.7的文件系统

其实这个移植好的内核可以用arm-linux-gcc-4.3.2来编译,编译好以后仍可使用2.6.28.7的文件系统来启动。更换编译器方法见修改Makefile。
不过要在配置内核的时候添加一个选项,如下:

Kernel Features  --->  
    [*] Use the ARM EABI to compile the kernel
   [*]   Allow old ABI binaries to run with this kernel (EXPERIMENTAL) 

首先,从官网上下载linux-2.6.33的内核。
 ftp://ftp.kernel.org/pub/linux/kernel/v2.6/可以找到。
        新建目录mkdir /file/fl。将内核源码包拷贝到/file/fl的目录下。
 解压源码包

tar zxvf linux-2.6.33.tar.gz

移植yaffs2驱动
下载最新的驱动http://www.aleph1.co.uk/cgi-bin/ ... fs2.tar.gz?view=tar 
解压在/file/fl下
tar zxvf yaffs2.tar.gz
进入yaffs2
cd yaffs2

给内核打补丁
./patch-ker.sh  c  /file/fl/linux-2.6.33

成功后打印信息
Updating /file/fl/linux-2.6.33/fs/Kconfig
Updating /file/fl/linux-2.6.33/fs/Makefile

修改机器码
飞凌开发板的bootloader默认的机器码是193,所以我们在使用smdk2440机器的时候,需要修改机器码。修改arch/arm/tools/mach-types。将
s3c2410      ARCH_S3C2410    S3C2410    193

删掉。然后将
s3c2440      ARCH_S3C2440    S3C2440    362

修改为
s3c2440      ARCH_S3C2440    S3C2440    193

指定目标板machine、编译器和编译器路径
修改linux-2.6.33/Makefile,将
ARCH                ?= $(SUBARCH)
CROSS_COMPILE        ?=  

修改成
#ARCH                ?= $(SUBARCH)
#CROSS_COMPILE        ?=
ARCH                ?= arm
CROSS_COMPILE        ?= /usr/local/arm/3.4.1/bin/arm-linux-  

增加devfs文件管理器的支持
我们所用的文件系统使用的是devfs文件管理器。修改fs/Kconfig,
找到
menu "Pseudo filesystems"

添加如下语句:
config DEVFS_FS
         bool "/dev file system support (OBSOLETE)"
         default y    
config DEVFS_MOUNT
bool "Automatically mount at boot"
default y
depends on DEVFS_FS

修改晶振频率( 可解决打印信息乱码问题 )
文件:arch/arm/mach-s3c2440/mach-smdk2440.c
/*s3c24xx_init_clocks(16934400);*/  s3c24xx_init_clocks(12000000);  

修改MTD分区
文件: arch/arm/plat-s3c24xx/common-smdk.c 
需要和bootloader中的分区信息相同(128M),否则,启动时出错。
static struct mtd_partition smdk_default_nand_part[] = {

        [0] = {
                .name        = "Boot",
                .size        = 0x00100000,
                .offset = 0
        },
        [1] = {
                .name        = "MyApp",
                .size        = 0x003c0000,
                .offset = 0x00140000,
        },
        [2] = {
                .name        = "Kernel",
                .size        = 0x00300000,
                .offset = 0x00500000,
        },
        [3] = {
                .name        = "fs_yaffs",
                .size        = 0x03c00000,         //30M
                .offset = 0x00800000,
        },        
        [4] = {
                .name        = "WINCE",
                .size        = 0x03c00000,
                .offset = 0x04400000,
        }
};

关闭ECC校验
文件:drivers/mtd/nand/s3c2410.c
函数:s3c2410_nand_init_chip
 /*chip->ecc.mode = NAND_ECC_SOFT; */  chip->ecc.mode = NAND_ECC_NONE;

修改nandflash驱动,支持K9F1G08的nandflash
修改drivers/mtd/nand下面的nand_bbt.c文件:
static struct nand_bbt_descr largepage_memorybased = {
        .options = 0,
        .offs = 0,
        .len = 1,           // 原数值为2,支持2K每页的flash修改为1。K9F1G08,K9F2G08是2k每页的flash
        .pattern = scan_ff_pattern
};
static struct nand_bbt_descr largepage_flashbased = {
        .options = NAND_BBT_SCAN2NDPAGE,
        .offs = 0,
        .len = 1,           //原数值为2,支持2K每页的flash修改为1。K9F1G08,K9F2G08是2k每页的flash
        .pattern = scan_ff_pattern
};

下面,开始配置内核。
进入linux-2.6.33目录,把s3c2410的默认配置写入config文件。
make s3c2410_defconfig

配置文件系统选项
配置yaffs2文件系统 
修改配置如下:
 File systems  ---> 
    [*] 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相关选项
修改配置如下:
System Type  ---> 
    S3C2440 Machines  ---> 
        [*] SMDK2440
        [*] SMDK2440 with S3C2440 CPU module

去掉S3C2400 Machines、S3C2410 Machines、S3C2412 Machines、S3C2442 Machines的所有选项,否则会报错。如果现在编译内核,下载到开发板中,内核就可以正常启动了。呵呵,有了雏形,咱们继续移植设备驱动。
移植USB host驱动
在这个版本的linux内核,已经对USB驱动进行来很好的支持,仅仅需要修改配置。
Device Drivers  ---> 
    [*] 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

    SCSI device support  --->
        <*> SCSI device support
        [*] legacy /proc/scsi/ support
        <*> SCSI disk support 
        <*> SCSI tape support
目前2.6.28.7版本的根文件系统的设备管理器是静态生成节点的,所以需要添加节点。
开发板启动以后,在/dev目录下输入一下命令:
mknod sda1 b 8 1
这个命令中的sda1是设备节点名
移植RTC驱动
在这个版本的linux内核,已经对RTC驱动进行来很好的支持,不需要修改配置。相应配置如下
Device Drivers  --->
    <*> 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

添加设备,代码如下:
static struct platform_device *smdk2440_devices[] __initdata = {
        &s3c_device_usb,
        &s3c_device_lcd,
        &s3c_device_wdt,
        &s3c_device_i2c0,
        &s3c_device_iis,
        &s3c_device_rtc,
};

移植UDA1341驱动
在平台上添加和配置UDA1341:
修改
arch/arm/mach-s3c2440/mach-smdk2440.c

在开始添加头文件
#include <sound/s3c24xx_uda134x.h>
#include <mach/gpio-fns.h>

添加设备配置
static struct s3c24xx_uda134x_platform_data s3c24xx_uda134x_data = {
        .l3_clk = S3C2410_GPB(4),
        .l3_data = S3C2410_GPB(3),
        .l3_mode = S3C2410_GPB(2),
        .model = UDA134X_UDA1341,
};

static struct platform_device s3c24xx_uda134x = {
        .name = "s3c24xx_uda134x",
        .dev = {
                .platform_data    = &s3c24xx_uda134x_data,
        }
};

把设备添加到平台当中
static struct platform_device *smdk2440_devices[] __initdata = {
        &s3c_device_usb,
        &s3c_device_lcd,
        &s3c_device_wdt,
        &s3c_device_i2c0,
        &s3c_device_iis,
        &s3c_device_rtc,
        &s3c24xx_uda134x,
};

配置如下
Device Drivers  --->
    <*> 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

移植DM9000驱动
1.修改 drivers/net/dm9000.c 文件:
   头文件增加:
#include <mach/regs-gpio.h> 
#include <mach/irqs.h>
#include <mach/hardware.h>
在dm9000_probe 函数开始增加:
unsigned char ne_def_eth_mac_addr[]={0x00,0x12,0x34,0x56,0x80,0x49};
    static void *bwscon;
    static void *gpfcon;
    static void *extint0;
    static void *intmsk;
    #define BWSCON           (0x48000000)
    #define GPFCON           (0x56000050)
    #define EXTINT0           (0x56000088)
    #define INTMSK           (0x4A000008)
        
        bwscon=ioremap_nocache(BWSCON,0x0000004);
        gpfcon=ioremap_nocache(GPFCON,0x0000004);
        extint0=ioremap_nocache(EXTINT0,0x0000004);
        intmsk=ioremap_nocache(INTMSK,0x0000004);
                       
        writel(readl(bwscon)|0xc0000,bwscon);
        writel( (readl(gpfcon) & ~(0x3 << 14)) | (0x2 << 14), gpfcon); 
        writel( readl(gpfcon) | (0x1 << 7), gpfcon); // Disable pull-up
        writel( (readl(extint0) & ~(0xf << 28)) | (0x4 << 28), extint0); //rising edge
        writel( (readl(intmsk))  & ~0x80, intmsk);    

在这个函数的最后需要修改:
if (!is_valid_ether_addr(ndev->dev_addr)) {
                /* try reading from mac */
                
                mac_src = "chip";
                for (i = 0; i < 6; i++)
                        //ndev->dev_addr[i] = ior(db, i+DM9000_PAR); 
                        ndev->dev_addr[i] = ne_def_eth_mac_addr[i];
        }

2. 修改arch/arm/mach-s3c2440/mach-smdk2440.c,添加设备
static struct platform_device *smdk2440_devices[] __initdata = {
        &s3c_device_usb,
        &s3c_device_lcd,
        &s3c_device_wdt,
        &s3c_device_i2c0,
        &s3c_device_iis,
        &s3c_device_rtc,
        &s3c24xx_uda134x,
        &s3c_device_dm9000,
};
3. 修改 arch/arm/plat-s3c24xx/devs.c 
添加头文件
#include <linux/dm9000.h>

static struct resource s3c_dm9000_resource[] = { 
        [0] = { 
        .start = S3C24XX_PA_DM9000, 
        .end   = S3C24XX_PA_DM9000+ 0x3, 
        .flags = IORESOURCE_MEM 
        }, 
        [1]={ 
        .start = S3C24XX_PA_DM9000 + 0x4, //CMD pin is A2 
        .end = S3C24XX_PA_DM9000 + 0x4 + 0x7c, 
        .flags = IORESOURCE_MEM 
        }, 
        [2] = { 
        .start = IRQ_EINT7, 
        .end   = IRQ_EINT7, 
        .flags = IORESOURCE_IRQ 
        }, 
        }; 

        static struct dm9000_plat_data s3c_device_dm9000_platdata = { 
        .flags= DM9000_PLATF_16BITONLY, 
        }; 

        struct platform_device s3c_device_dm9000 = { 
        .name= "dm9000", 
        .id= 0, 
        .num_resources= ARRAY_SIZE(s3c_dm9000_resource), 
        .resource= s3c_dm9000_resource, 
          .dev= { 
        .platform_data = &s3c_device_dm9000_platdata, 
          } 
}; 
EXPORT_SYMBOL(s3c_device_dm9000);


4. 修改 arch/arm/plat-s3c/include/plat/devs.h   45行附近,添加
extern struct platform_device s3c_device_dm9000;

5.修改arch/arm/mach-s3c2410/include/mach/map.h 文件
/* DM9000 */ 
#define   S3C24XX_PA_DM9000 0x20000300 
#define   S3C24XX_VA_DM9000 0xE0000000

3.5寸LCD显示的移植
更改arch/arm/mach-s3c2440/mach-smdk2440.c
/* LCD driver info */

static struct s3c2410fb_display smdk2440_lcd_cfg __initdata = {

        .lcdcon5        = S3C2410_LCDCON5_FRM565 |
                          S3C2410_LCDCON5_INVVLINE |
                          S3C2410_LCDCON5_INVVFRAME |
                          S3C2410_LCDCON5_PWREN |
                          S3C2410_LCDCON5_HWSWP,

        .type                = S3C2410_LCDCON1_TFT,

        .width                = 240,
        .height                = 320,

        .pixclock        = 166667, /* HCLK 60 MHz, divisor 10 */
        .xres                = 240,
        .yres                = 320,
        .bpp                = 16,
        .left_margin        = 20,
        .right_margin        = 8,
        .hsync_len        = 4,
        .upper_margin        = 8,
        .lower_margin        = 7,
        .vsync_len        = 4,
};

static struct s3c2410fb_mach_info smdk2440_fb_info __initdata = {
        .displays        = &smdk2440_lcd_cfg,
        .num_displays        = 1,
        .default_display = 0,

#if 0
        /* currently setup by downloader */
        .gpccon                = 0xaa940659,
        .gpccon_mask        = 0xffffffff,
        .gpcup                = 0x0000ffff,
        .gpcup_mask        = 0xffffffff,
        .gpdcon                = 0xaa84aaa0,
        .gpdcon_mask        = 0xffffffff,
        .gpdup                = 0x0000faff,
        .gpdup_mask        = 0xffffffff,
#endif

        .lpcsel                = ((0xCE6) & ~7) | 1<<4,
};

修改uart2为普通串口以及测试程序
修改arch/arm/mach-s3c2440/mach-smdk2440.c中的uart2的配置,修改后如下:
static struct s3c2410_uartcfg smdk2440_uartcfgs[] __initdata = {
        [0] = {
                .hwport             = 0,
                .flags             = 0,
                .ucon             = 0x3c5,
                .ulcon             = 0x03,
                .ufcon             = 0x51,
        },
        [1] = {
                .hwport             = 1,
                .flags             = 0,
                .ucon             = 0x3c5,
                .ulcon             = 0x03,
                .ufcon             = 0x51,
        },
        /* IR port */
        [2] = {
                .hwport             = 2,
                .flags             = 0,
                .ucon             = 0x3c5,
                .ulcon             = 0x03,/*fatfish 0x43*/
                .ufcon             = 0x51,
        }
};

在drivers/serial/samsung.c中添加对uart2控制器的配置,配置为普通串口。添加头文件:
#include <linux/gpio.h> 
#include <mach/regs-gpio.h> 

在static int s3c24xx_serial_startup(struct uart_port *port)函数中,添加
        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); 
        } 

测试方法:
在linux内核源码中drivers/serial/samsung.c中
.dev_name        = "ttySAC",

写明在开发板/dev目录下生成的ttySACx为串口设备结点。
使用命令:
getty 115200 /dev/ttySAC2

将终端交给com2,这样可以在com2中收到波特率为115200的终端信息。
这三个针的顺序:最靠近底板丝印层“com2”字样的针脚是com2的发送脚(需要接pc串口的接收脚),中间的是com2的接收脚(接pc串口的发送脚),剩下的那个是地(接pc串口的地)。
移植看门狗

修改配置
Device Drivers --->
    [*] Watchdog Timer Support --->
         <*> S3C2410 Watchdog
即可。但是要是打开看门狗还需要修改源码。稍后奉上看门狗使用方法和测试程序

还没有完 原帖地址 http://bbs.witech.com.cn/thread-468-1-1.html  留下记号




你可能感兴趣的:(看到飞凌嵌入式论坛上的linux移植比较详细 记下啦!)