Chinaunix首页 | 论坛 | 博客
  • 博客访问: 155639
  • 博文数量: 116
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 20
  • 用 户 组: 普通用户
  • 注册时间: 2017-08-21 15:04
文章分类

全部博文(116)

文章存档

2014年(1)

2013年(13)

2012年(27)

2011年(49)

2010年(26)

分类: 嵌入式

2011-01-26 17:26:42

由于Linux2.6.34.2S3C64xx有了一定的支持,所以采用Linux2.6.34.2版本的内核。

一、 移植环境

机:VMWare-- 8

开发板:天嵌TQ6410—256M nandflash,

编译器:EABI-4.3.2_V0.1

u-boot

二、 源码获得


         内核源码到下载;


三、 移植步骤

1.Linux2.6.34.2内核源码放到工作目录文件夹下,并解压。

#tar xzvf linux2.6.34.2.tar.gz –c /
#pwd
/
# cd linux2.6.34.2

       2. 修改内核源码根目录下的Makefile文件(CROSS_COMPILE    =的值因个人情况而定,其他可以照做,蓝色部分为修改部分。)

         #gedit Makefile

......
#SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
#                  -e s/arm.*/arm/ -e s/sa110/arm/ \
#                  -e s/s390x/s390/ -e s/parisc64/parisc/ \
#                  -e s/ppc.*/powerpc/ -e s/mips.*/mips/ )
......

#ARCH        ?= $(SUBARCH)
#CROSS_COMPILE    ?=

ARCH        = arm
CROSS_COMPILE    = /usr/local/arm/usr/local/arm/4.3.2/bin/arm-none-linux-
gnueabi-

       3. 对于平台时钟的修改.

 可以查看内核顶层目录下的arch/arm/mach-s3c64xx/mach-smdk6410.csmdk6410_mapio()函数中有声明为12000000,而开发板上的外部时钟也是12M所以不用修改。

     4. 修改机器码,可以看到在arch/arm/mach-s3c64xx/mach-smdk6410.cMACHINE_START(SMDK6410,”SMDK6410”)是在uboot引导内核时需要对应的机器码。所以在arch/arm/tools/mach-types文件中找到这个SMDK6410对应的机器码并改为888(uboot中是这样设置的)

     4. 配置内核,由于开始对s3c6410的内核支持结构不是很了解,所以可以采用默认配置内核。(arch/arm/configs/目录下是一般内核的默认配置)

  1. #pwd

  2. #/linux2.6.34.2

  3. #cp –f arch/arm/configs/s3c6400_defconfig .config

可以使用make menuconfig对刚刚配置的内核根据具体的情况进行修改,开始我没有进行修改直接make zImage,最后在arch/arm/boot/目录下生成zImage镜像文件。


5. 使用mkimage命令打包zImage并烧写到开发板上

#mkimage –n ‘linux-2.6.34.2’ -A arm -O linux -C none -a 0xc0008000 -e 0xc0008000 -d zImage uImage

可以看到内核停在Starting kernel ...不能解压内核。

打印信息如下:

Booting image at c0008000 ...                                

Image Name:    Linux-2.6.34.2                              
Created:       2010-08-10    0:13:40 UTC                      
Image Type:    ARM Linux Kernel Image (uncompressed)         
Data Size:     1650092 Bytes =   1.6 MB                                      
Load Address: c0008000                         

Entry Point:   c0008000            
Verifying Checksum ... OK                                                     
        
Starting kernel ...

后来经过对比天嵌原来开发板上的内核是没有上面的打印信息的,在网上查找原因得知是内核引导指令的问题。原来:生成zImage的内核镜像文件可以通过UBOOT提供的go命令,通过mkimage命令,在zImage中加入头文件(镜像头长0x40,真正的内核入口向后偏移了0x40大小),生成uImage镜像文件,该文件就是执行bootm所需的内核镜像文件。以前uboot引导内核都是用bootm指令,这次用的go指令,所以才会出错。看来学习还是要深究啊。

直接烧写zImage系统引导内核成功了。可是对于内核的系统分区还没有添加,内核最后打印信息为:       Memory: 126516k/126516k available, 4556k reserved, 0K highmemVirtual kernel memory layout:    vector : 0xffff0000 - 0xffff1000   (   4 kB)    fixmap : 0xfff00000 - 0xfffe0000   ( 896 kB)    DMA     : 0xffc00000 - 0xffe00000   (   2 MB)    vmalloc : 0xc8800000 - 0xe0000000   ( 376 MB)    lowmem : 0xc0000000 - 0xc8000000   ( 128 MB)    modules : 0xbf000000 - 0xc0000000   ( 16 MB)      .init : 0xc0008000 - 0xc0024000   ( 112 kB)      .text : 0xc0024000 - 0xc0300000   (2928 kB)     .data : 0xc0300000 - 0xc0324920   ( 147 kB) Please append a correct "root=" boot option; here are the available partitions:Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(2,0)Backtrace: [] (dump_backtrace+0x0/0x114) from [] (dump_stack+0x18/0x1c) r7:c7c11000 r6:00000000 r5:c0021a08 r4:c0325230[] (dump_stack+0x0/0x1c) from [] (panic+0x4c/0xc0)[] (panic+0x0/0xc0) from [] (mount_block_root+0x1e0/0x220) r3:00000000 r2:00000000 r1:c7c27f60 r0:c02c5f65[] (mount_block_root+0x0/0x220) from [] (mount_root+0xc4/0xfc)[] (mount_root+0x0/0xfc) from [] (prepare_namespace+0x170/0x1c8) r5:c0021a08 r4:c0324b60[] (prepare_namespace+0x0/0x1c8) from [] (kernel_init+0x110/0x14c) r5:00000000 r4:c0324920[] (kernel_init+0x0/0x14c) from [] (do_exit+0x0/0x5a8) r5:00000000 r4:00000000

6.
由于linux2.6.34.2s3c6410上的nand驱动支持

  1. #pwd

  2. #gedit mach-smdk6410.c

  3. //add here
  1. static struct mtd_partition s3c_partition_info[] = {
  2.       [0] = {
  3.           .name = "u-boot",
  4.           .offset = 0,
  5.           .size = 0x40000, 
  6.           .mask_flags = MTD_CAP_NANDFLASH,
  7.       },
  8.       [1] = {
  9.           .name = "Kernel",
  10.           .offset = 0x200000, 
  11.           .size = 0x300000,
  12.           .mask_flags = MTD_CAP_NANDFLASH,
  13.       },
  14.       [2] = { 
  15.           .name = "Yaffs2", 
  16.           .offset = 0x500000, 
  17.           .size = MTDPART_SIZ_FULL,
  18.       }
  19. };
  20. static struct s3c2410_nand_set s3c_nandset[]={
  21.      [0]= { 
  22.           .name ="s3c24xx-nand",
  23.           .nr_chips = 1, 
  24.           .nr_partitions =ARRAY_SIZE(s3c_partition_info),
  25.           .partitions =s3c_partition_info, 
  26.      }
  27. };
  28. static struct s3c2410_platform_nand s3c_platform={ 
  29.      .tacls =0,
  30.      .twrph0 =30,
  31.      .sets = &s3c_nandset,
  32.      .nr_sets =ARRAY_SIZE(s3c_nandset),
  33. };
  1. *smdk6410_devices[] __initdata = {
  2. #ifdef
  3.     CONFIG_SMDK6410_SD_CH0 &s3c_device_hsmmc0,
  4. #endif
  5. #ifdef
  6.     CONFIG_SMDK6410_SD_CH1 &s3c_device_hsmmc1,
  7. #endif
  8. &s3c_device_i2c0,
  9. &s3c_device_i2c1,
  10. &s3c_device_fb,
  11. &s3c_device_ohci,
  12. &s3c_device_usb_hsotg,
  13. &s3c64xx_device_iisv4,

说明:分析Linux内核中的nand flash驱动drivers/mtd/nand/s3c2410.c文件中的相应函数,

其中的static int s3c2410_nand_setrate(struct s3c2410_nand_info *info)函数发现:

     struct s3c2410_platform_nand *plat = info->platform;

         int tacls_max = (info->cpu_type == TYPE_S3C2412) ? 8 : 4;   

         …………

     info->clk_rate = clkrate;

         clkrate /= 1000;         /* turn clock into kHz for ease of use */



        if (plat != NULL) {

                 tacls = s3c_nand_calc_rate(plat->tacls, clkrate, tacls_max);

                 twrph0 = s3c_nand_calc_rate(plat->twrph0, clkrate, 8);

                 twrph1 = s3c_nand_calc_rate(plat->twrph1, clkrate, 8);

        } else {      

           /* default timings */

                tacls = tacls_max;

                 twrph0 = 8;

                 twrph1 = 8;
      

             }



         if (tacls < 0 || twrph0 < 0 || twrph1 < 0) {

                 dev_err(info->device, "cannot get suitable timings\n");

                 return -EINVAL;

         }



         dev_info(info->device, "Tacls=%d, %dns Twrph0=%d %dns, Twrph1=%d %dns\n",

               tacls, to_ns(tacls, clkrate), twrph0, to_ns(twrph0, clkrate), twrph1, to_ns(twrph1, clkrate));



由以上内容可以看出,如果内核并没有使用我们的s3c_platform结构体中的配置,就会采用

} else {      

           /* default timings */

                tacls = tacls_max;

                 twrph0 = 8;

                 twrph1 = 8;
      

             }

中的配置信息。这点和我们改的内核输出s3c24xx-nand s3c2440-nand: Tacls=4, 39ns Twrph0=8 79ns, Twrph1=8 79ns完全符合。



因此可以判断我们需要在mach-mini2440.csmdk6410_machine_init(void)函数中增加s3c_nand_set_platdata(&s3c_platform);

配置内核,支持NandFlash


Device Drivers --->


<*> Memory Technology Device (MTD) support --->


[*] MTD partitioning support


<*> NAND Device Support --->


<*> NAND Flash support for S3C/S3C SoC

再次编译烧写,可以看到以下打印信息NAND device: Manufacturer ID: 0xec, Chip ID: 0xda (Samsung NAND 256MiB 3,3V 8-bit)Scanning device for bad blocksBad eraseblock 517 at 0x0000040a0000Bad eraseblock 1383 at 0x00000ace0000Bad eraseblock 1737 at 0x00000d920000Bad eraseblock 1897 at 0x00000ed20000Bad eraseblock 1968 at 0x00000f600000Creating 3 MTD partitions on "NAND 256MiB 3,3V 8-bit":0x000000000000-0x000000040000 : "u-boot"0x000000200000-0x000000500000 : "Kernel"0x000000500000-0x000010000000 : "Yaffs2"mice: PS/2 mouse device common for all micei2c /dev entries driversdhci: Secure Digital Host Controller Interface driversdhci: Copyright(c) Pierre Ossmans3c-sdhci s3c-sdhci.0: clock source 0: hsmmc (133000000 Hz)s3c-sdhci s3c-sdhci.0: clock source 1: hsmmc (133000000 Hz)s3c-sdhci s3c-sdhci.0: clock source 2: mmc_bus (24000000 Hz)mmc0: SDHCI controller on samsung-hsmmc [s3c-sdhci.0] using PIOTCP cubic registeredVFP support v0.3: implementor 41 architecture 1 part 20 variant b rev 5VFS: Cannot open root device "mtdblock2" or unknown-block(31,2)Please append a correct "root=" boot option; here are the available partitions:1f00             256 mtdblock0 (driver?)1f01            3072 mtdblock1 (driver?)1f02          257024 mtdblock2 (driver?)Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(31,2)Backtrace: [] (dump_backtrace+0x0/0x10c) from [] (dump_stack+0x18/0x1c) r7:c0318350 r6:00008000 r5:c0339cb0 r4:c7c27f40[] (dump_stack+0x0/0x1c) from [] (panic+0x4c/0xd0)[] (panic+0x0/0xd0) from [] (mount_block_root+0x178/0x234) r3:00000000 r2:c7c3af2c r1:c7c27f40 r0:c02d5a38[] (mount_block_root+0x0/0x234) from [] (mount_root+0xb0/0xf4)[] (mount_root+0x0/0xf4) from [] (prepare_namespace+0x108/0x1c8) r7:c001e378 r6:c0339600 r5:c001e378 r4:c001e388[] (prepare_namespace+0x0/0x1c8) from [] (kernel_init+0x118/0x160) r7:00000000 r6:c001d8b8 r5:c001db68 r4:c001db68[] (kernel_init+0x0/0x160) from [] (do_exit+0x0/0x640) r7:00000000 r6:00000000 r5:00000000 r4:00000000以上红色部分是由于kernel还未支持yaffs文件系统才会有的错误。

在这要说明的:

1.  ./driver/mtd/nand目录下是关于nand的驱动,与硬件相关的文件是s3c2410.c。如果使用其他的硬件的话可以替换此文件。

2.  ./driver/mtd/nand/s3c2410.c中的s3c2410_nand_driver.driver中的name字段一定要与./arch/arm/plat-samsung/dev_nand.c(平台设备)中的s3c_device_nand中的name字段保持一致,这样才能进行调用。否则可能会出现nand设备驱动不成功的现象。

我的内核打印错误信息如下:[] (strnlen+0x0/0x58) from [] (string+0x44/0xfc)[] (string+0x4/0xfc) from [] (vsnprintf+0x458/0xa28) r9:c033a5b0 r8:c7c27dd0 r7:c02efb56 r6:c02efb56 r5:c02efb57r4:00000000[] (vsnprintf+0x0/0xa28) from [] (vscnprintf+0x14/0x20)[] (vscnprintf+0x0/0x20) from [] (vprintk+0x80/0x38c) r5:00000000 r4:c033a0f8[] (vprintk+0x0/0x38c) from [] (printk+0x28/0x30)[] (printk+0x0/0x30) from [] (add_mtd_partitions+0x2e0/0x7c0) r3:c031b578 r2:c031c1bc r1:70200000 r0:c02efb3c[] (add_mtd_partitions+0x0/0x7c0) from [] (s3c24xx_nand_probe+0x4b4/0x774)[] (s3c24xx_nand_probe+0x0/0x774) from [] (platform_drv_probe+0x20/0x24)[] (platform_drv_probe+0x0/0x24) from [] (driver_probe_device+0x80/0x18c)[] (driver_probe_device+0x0/0x18c) from [] (__driver_attach+0x94/0x98)[] (__driver_attach+0x0/0x98) from [] (bus_for_each_dev+0x68/0x94) r7:c01705bc r6:c0333834 r5:c7c27ee0 r4:00000000[] (bus_for_each_dev+0x0/0x94) from [] (driver_attach+0x20/0x28) r7:c0333834 r6:c7c26000 r5:c0333834 r4:c02d872c[] (driver_attach+0x0/0x28) from [] (bus_add_driver+0xa4/0x260)[] (bus_add_driver+0x0/0x260) from [] (driver_register+0x74/0x15c)[] (driver_register+0x0/0x15c) from [] (platform_driver_register+0x4c/0x60) r7:c03393c0 r6:c7c26000 r5:c001db58 r4:c001dae0[] (platform_driver_register+0x0/0x60) from [] (s3c2410_nand_init+0x1c/0x28)[] (s3c2410_nand_init+0x0/0x28) from [] (do_one_initcall+0x38/0x1c4)[] (do_one_initcall+0x0/0x1c4) from [] (kernel_init+0xac/0x160)[] (kernel_init+0x0/0x160) from [] (do_exit+0x0/0x640) r7:00000000 r6:00000000 r5:00000000 r4:00000000Code: e24cb004 e3510000 e1a02000 0a00000d (e5d03000) ---[ end trace 48c84fc47f611133 ]---Kernel panic - not syncing: Attempted to kill init!Backtrace: [] (dump_backtrace+0x0/0x10c) from [] (dump_stack+0x18/0x1c) r7:c7c24000 r6:c01469e4 r5:c0339cb0 r4:0000000b[] (dump_stack+0x0/0x1c) from [] (panic+0x4c/0xd0)[] (panic+0x0/0xd0) from [] (do_exit+0x548/0x640) r3:c031d408 r2:c7c279a8 r1:c7c27884 r0:c02d8ea4[] (do_exit+0x0/0x640) from [] (die+0x290/0x2dc)[] (die+0x0/0x2dc) from [] (__do_kernel_fault+0x6c/0x8c)[] (__do_kernel_fault+0x0/0x8c) from [] (do_page_fault+0x148/0x200) r9:00000005 r8:c7c27c20 r7:c7c24000 r6:70200000 r5:00000000r4:c7c27c20[] (do_page_fault+0x0/0x200) from [] (do_translation_fault+0x6c/0xa4)[] (do_translation_fault+0x0/0xa4) from [] (do_DataAbort+0x40/0xa4) r7:c0318590 r6:00000005 r5:c7c27c54 r4:c0318540[] (do_DataAbort+0x0/0xa4) from [] (__dabt_svc+0x4c/0x60)Exception stack(0xc7c27c20 to 0xc7c27c68)7c20: 70200000 ffffffff 70200000 ff0a0004 00000000 c033a1dc c033a5b0 0000ffff7c40: 70200000 c033a5b0 c033a1dc c7c27c74 c7c27c78 c7c27c68 c0148150 c01469e47c60: a0000093 ffffffff[] (strnlen+0x0/0x58) from [] (string+0x44/0xfc)[] (string+0x4/0xfc) from [] (vsnprintf+0x458/0xa28) r9:c033a5b0 r8:c7c27dd0 r7:c02efb56 r6:c02efb56 r5:c02efb57r4:00000000[] (vsnprintf+0x0/0xa28) from [] (vscnprintf+0x14/0x20)[] (vscnprintf+0x0/0x20) from [] (vprintk+0x80/0x38c) r5:00000000 r4:c033a0f8[] (vprintk+0x0/0x38c) from [] (printk+0x28/0x30)[] (printk+0x0/0x30) from [] (add_mtd_partitions+0x2e0/0x7c0) r3:c031b578 r2:c031c1bc r1:70200000 r0:c02efb3c[] (add_mtd_partitions+0x0/0x7c0) from [] (s3c24xx_nand_probe+0x4b4/0x774)[] (s3c24xx_nand_probe+0x0/0x774) from [] (platform_drv_probe+0x20/0x24)[] (platform_drv_probe+0x0/0x24) from [] (driver_probe_device+0x80/0x18c)[] (driver_probe_device+0x0/0x18c) from [] (__driver_attach+0x94/0x98)[] (__driver_attach+0x0/0x98) from [] (bus_for_each_dev+0x68/0x94) r7:c01705bc r6:c0333834 r5:c7c27ee0 r4:00000000[] (bus_for_each_dev+0x0/0x94) from [] (driver_attach+0x20/0x28) r7:c0333834 r6:c7c26000 r5:c0333834 r4:c02d872c[] (driver_attach+0x0/0x28) from [] (bus_add_driver+0xa4/0x260)[] (bus_add_driver+0x0/0x260) from [] (driver_register+0x74/0x15c)[] (driver_register+0x0/0x15c) from [] (platform_driver_register+0x4c/0x60) r7:c03393c0 r6:c7c26000 r5:c001db58 r4:c001dae0[] (platform_driver_register+0x0/0x60) from [] (s3c2410_nand_init+0x1c/0x28)[] (s3c2410_nand_init+0x0/0x28) from [] (do_one_initcall+0x38/0x1c4)[] (do_one_initcall+0x0/0x1c4) from [] (kernel_init+0xac/0x160)[] (kernel_init+0x0/0x160) from [] (do_exit+0x0/0x640) r7:00000000 r6:00000000 r5:00000000 r4:00000000

7.添加yaffs文件系统的支持:


1、下载Yaffs2

      


2、解压Yaffs2并将其加入Linux内核(打补丁的方式)

       #cd yaffs2

      
#./patch-ker.sh c /linux-2.6.34.2/


3、修改配置文件,添加对yaffs文件系统的支持(同时也支持cramfsnfs文件系统)

       File systems --->

Miscellaneous filesystems --->

<*> YAFFS2 file system support

-*- 512 byte / page devices

[ ] Use older-style on-NAND data format with pageStatus byte

[ ] Lets Yaffs do its own ECC

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

[*] Autoselect yaffs2 format

[ ] Disable lazy loading

[ ] Turn off wide tnodes

[ ] Force chunk erase check

[*] Cache short names in RAM

< > Journalling Flash File System v2 (JFFS2) support

<*> Compressed ROM file system support (cramfs)

[*] Network File Systems --->

--- Network File Systems

最后重新编译烧写到开发板,打印信息为:

NAND device: Manufacturer ID: 0xec, Chip ID: 0xda (Samsung NAND 256MiB 3,3V 8-bit)

Scanning device for bad blocks

Bad eraseblock 517 at 0x0000040a0000

Bad eraseblock 1383 at 0x00000ace0000

Bad eraseblock 1737 at 0x00000d920000

Bad eraseblock 1897 at 0x00000ed20000

Bad eraseblock 1968 at 0x00000f600000

Creating 3 MTD partitions on "NAND 256MiB 3,3V 8-bit":

0x000000000000-0x000000040000 : "u-boot"

0x000000200000-0x000000500000 : "Kernel"

0x000000500000-0x000010000000 : "Yaffs2"

mice: PS/2 mouse device common for all mice

i2c /dev entries driver

sdhci: Secure Digital Host Controller Interface driver

sdhci: Copyright(c) Pierre Ossman

s3c-sdhci s3c-sdhci.0: clock source 0: hsmmc (133000000 Hz)

s3c-sdhci s3c-sdhci.0: clock source 1: hsmmc (133000000 Hz)

s3c-sdhci s3c-sdhci.0: clock source 2: mmc_bus (24000000 Hz)

mmc0: SDHCI controller on samsung-hsmmc [s3c-sdhci.0] using PIO

TCP cubic registered

VFP support v0.3: implementor 41 architecture 1 part 20 variant b rev 5

。。。

yaffs: dev is 32505858 name is "mtdblock2"

yaffs: passed flags ""

yaffs: Attempting MTD mount on 31.2, "mtdblock2"

block 478 is bad

block 1344 is bad

block 1698 is bad

block 1858 is bad

block 1929 is bad

yaffs_read_super: isCheckpointed 0

VFS: Mounted root (yaffs2 filesystem).

Freeing init memory: 140K

Warning: unable to open an initial console.

Kernel panic - not syncing: No init found. Try passing init= option to kernel.Kernel panic - not syncing:

Backtrace:

[] (dump_backtrace+0x0/0x10c) from [] (dump_stack+0x18/0x1c)

r7:c0318350 r6:00008000 r5:c0339cb0 r4:c7c27f40

[] (dump_stack+0x0/0x1c) from [] (panic+0x4c/0xd0)

[] (panic+0x0/0xd0) from [] (mount_block_root+0x178/0x234)

r3:00000000 r2:c7c3af2c r1:c7c27f40 r0:c02d5a38

[] (mount_block_root+0x0/0x234) from [] (mount_root+0xb0/0xf4)

[] (mount_root+0x0/0xf4) from [] (prepare_namespace+0x108/0x1c8)

r7:c001e378 r6:c0339600 r5:c001e378 r4:c001e388

[] (prepare_namespace+0x0/0x1c8) from [] (                            kernel_init+0x118/0x160)

r7:00000000 r6:c001d8b8 r5:c001db68 r4:c001db68

[] (kernel_init+0x0/0x160) from [] (do_exit+0x0/0x640)

r7:00000000 r6:00000000 r5:00000000 r4:00000000

文件系统还没有移植好所以只能到这了





阅读(779) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~