Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1495928
  • 博文数量: 267
  • 博客积分: 3010
  • 博客等级: 少校
  • 技术积分: 3089
  • 用 户 组: 普通用户
  • 注册时间: 2011-06-05 17:09
个人简介

尊天命,尽人事

文章分类

全部博文(267)

文章存档

2017年(6)

2015年(4)

2014年(27)

2013年(52)

2012年(59)

2011年(120)

分类:

2011-08-29 10:04:01

宿主机:
Kubuntu 8.04 (linux-2.6.24-19)
gcc-4.2.3

目标机:
s3c2440

交叉编译器(由crosstool-0.43制作):
arm-linux-gcc-4.1.0

要移植的内核版本:
linux-2.6.26

文件系统:
cramfs
---------------------------------------------------------------------------------------------------
准备知识:

Linux支持多种平台架构。在其源码的arch目录下,已经将各种支持的平台架构的源码分门别类。为了配置方便,在各种平台架构的目录下,一般都配有一个名为configs的目录。其中,放置着许多已经初步配置好的defconfig文件。通过这些defconfig文件,加快了我们配置内核的速度。
比如我所用的是一个arm架构的s3c2440板,那我就可以从arch/arm/configs/中找到s3c2410_defconfig,这是目前最匹配2440的一个默认配置文件了。使用:
$ make s3c2410_defconfig


$ cp arch/arm/configs/s3c2410_defconfig ./.config

执行上述命令后,将会在源码目录下生成相应的.config配置文件。通过
$ make menuconfig


$ make xconfig

可以进一步配置内核。最后执行
$ make zImage

生成我们所需的烧录文件

内核编译基本命令:

make mrproper --- 清理全部文件,包括.config和一些备份文件
make clean --- 清理生成文件,但会保留.config和一些模块文件。

make defconfig --- 生成包含全部默认选项的.config文件。这里用make s3c2410_defconfig替代
make oldconfig --- 在旧的.config基础上生成新的.config。如果只想在原来内核配置的基础上修改一些小地方,会省去不少麻烦

make config --- 基于文本的最为传统的配置界面,不推荐使用
make menuconfig --- 基于文本选单的配置界面,字符终端下推荐使用
make xconfig --- 基于图形窗口模式的配置界面,Xwindow下推荐使用
   目的都是生成一个.config文件,这三个命令中,make xconfig的界面最为友好,如果你可以使用Xwindow,你就用这个好了,这个比较方便,也好设置。如果你不能使用Xwindow,那么就使用 make menuconfig好了。界面虽然比上面一个差点,总比make config的要好多了。


make --- 默认编译。
make bzImage --- 编译生成压缩的内核二进制文件,也会用make zImage替代

---------------------------------------------------------------------------------------------------
参考资料: 
《  》
《 移植内核2.6.24.4到S3C2440 》
《  对于Kernel panic - ……出错的一点总结! 》

---------------------------------------------------------------------------------------------------
移植linux-2.6.26内核(假设已下载linux-2.6.26.tar.bz2)

1. 解压源代码
$ tar jxvf linux-2.6.26.tar.bz2
$ cd linux-2.6.26


2. 更改Makefile
#ARCH        ?= $(SUBARCH)
#CROSS_COMPILE    ?=
ARCH        ?= arm
CROSS_COMPILE    ?= $HOME/toolchain/crosstool/gcc-4.1.0-glibc-2.3.2/arm-linux-gnu/bin/arm-linux-gnu-


3. 生成默认配置
$ make s3c2410_defconfig


4. 增加devfs文件系统支持
linux2.6.26已经去掉devfs,为了内核支持devfs以及在启动时并在/sbin/init运行之前能自动挂载/dev为devfs文件系统,修改fs的Kconfig文件。
linux-2.6.26/fs/Kconfig

修改的内容:
找到menu "Pseudo filesystems"
添加如下语句:

config DEVFS_FS
    bool "/dev file system support (OBSOLETE)"
    depends on EXPERIMENTAL
    help
      This is support for devfs, a virtual file system (like /proc) which
      provides the file system interface to device drivers, normally found
      in /dev. Devfs does not depend on major and minor number
      allocations. Device drivers register entries in /dev which then
      appear automatically, which means that the system administrator does
      not have to create character and block special device files in the
      /dev directory using the mknod command (or MAKEDEV script) anymore.

      This is work in progress. If you want to use this, you *must* read
      the material in , especially
      the file README there.

      Note that devfs no longer manages /dev/pts! If you are using UNIX98
      ptys, you will also need to mount the /dev/pts filesystem (devpts).

      Note that devfs has been obsoleted by udev,
      <>.
      It has been stripped down to a bare minimum and is only provided for
      legacy installations that use its naming scheme which is
      unfortunately different from the names normal Linux installations
      use.

      If unsure, say N.

config DEVFS_MOUNT
    bool "Automatically mount at boot"
    depends on DEVFS_FS
    help
      This option appears if you have CONFIG_DEVFS_FS enabled. Setting
      this to 'Y' will make the kernel automatically mount devfs onto /dev
      when the system is booted, before the init thread is started.
      You can override this with the "devfs=nomount" boot option.

      If unsure, say N.

config DEVFS_DEBUG
    bool "Debug devfs"
    depends on DEVFS_FS
    help
      If you say Y here, then the /dev file system code will generate
      debugging messages. See the file
      for more details.

      If unsure, say N.


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


6. 修改MTD分区
文件: arch/arm/plat-s3c24xx/common-smdk.c

/* fix mtd partition to be same with bootloader */
/* a flash all in 64M bit size have been devided into 4 partition: */
/*   1. boot : offset is 0 and size is 192k */
/*   2. kernel : offset is 0x30000 and size is 1856k */
/*   3. rootfs : offset is 0x200000 and size is 30M */
/*   4. ext-fs1 : offset is 0x2000000 and size is 32M */
static struct mtd_partition smdk_default_nand_part[] = {
    [0] = {
        .name    = "boot", /* default is "Boot Agent", by qspy */
        .size    = SZ_64K*3,  /* default is SZ_16K, qspy fix it to 192K*/
        .offset    = 0,
    },
    [1] = {
        .name    = "kernel", /* default is "S3C2410 flash partition 1", by qspy */
        .offset = SZ_64K*3,/* default is 0, by qspy */
        .size    = SZ_64K*29,/* default is SZ_2M, qspy fix it to 1856K*/
    },
    [2] = {
        .name    = "rootfs",/* default is "S3C2410 flash partition 2", by qspy */
        .offset = SZ_2M,/* default is SZ_4M, by qspy */
        .size    = SZ_1M*30,/* default is SZ_4M, qspy fix it to 30M*/
    },
    [3] = {
        .name    = "ext-fs1",/* default is "S3C2410 flash partition 2", by qspy */
        .offset    = SZ_32M,/* default is SZ_8M, by qspy */
        .size    = SZ_32M,/* default is SZ_2M, qspy fix it to 30M*/
    } /*,
    [4] = {
        .name    = "S3C2410 flash partition 4",
        .offset = SZ_1M * 10,
        .size    = SZ_4M,
    },
    [5] = {
        .name    = "S3C2410 flash partition 5",
        .offset    = SZ_1M * 14,
        .size    = SZ_1M * 10,
    },
    [6] = {
        .name    = "S3C2410 flash partition 6",
        .offset    = SZ_1M * 24,
        .size    = SZ_1M * 24,
    },
    [7] = {
        .name    = "S3C2410 flash partition 7",
        .offset = SZ_1M * 48,
        .size    = SZ_16M,
    } */
};


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



8. 配置内核
$ make xconfig

其中有几项一定要修改的,分别是:

a. 启动
|---Boot options
|    |---Default kernel command string: [root=/dev/mtdblock2 rootfstype=cramfs init=/linuxrc console=ttySAC1,115200 devfs=mount mem=64]

分析:
/dev/mtdblock2 : 表示MTD分区的第2个分区存储根文件系统
rootfstype=cramfs : 分区是cramfs类型,这项不加应该关系不大
init=/linuxrc : 启动的首个脚本即根目录下的linuxrc
console=ttySAC1,115200 : 使用串口1作为串口调试,波特率设置为115200; 现在已经摒弃了以前使用ttyS0的写法
devfs=mount : 在/sbin/init运行之前能自动挂载/dev为devfs文件系统
mem=64 : 存储器大小为64M

b. 增加devfs文件系统支持
|---File systems
|    |---Pseudo filesystems
|    |      |---/dev file system support 
|    |      |      |---Automatically mount at boot
|    |      |      |---Debug devfs

这几项都是必选的

c. 芯片及系统类型
|---System Type
|    |---S3C2410 Machines
|    |      |---SMDK2410/A9M2410

支持2440时,这一项也是必选的,否则会编译不过

-----------------------------------------------------
遇到的问题:

1. 启动时乱码
信息:
Nand flash status = c0
Set boot params = root=/dev/mtdblock2 init=/linuxrc load_ramdisk=0 console=ttySAC1,115200 mem=65536K devfs=mount display=shp480
Load Kernel...
8???腳c?洤''D?G#溰 ?`納 { 悃\'榌


解决:时钟问题,更改时钟频率为12M即可

2. 文件系统cramfs挂载失败

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
NetWinder Floating Point Emulator V0.97 (double precision)
msgmni has been set to 120
io scheduler noop registered
io scheduler anticipatory registered (default)
io scheduler deadline registered
io scheduler cfq registered
Console: switching to colour frame buffer device 30x40
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
usbcore: registered new interface driver ub
dm9000 Ethernet Driver, V1.30
Linux video capture interface: v2.00
NFTL driver: nftlcore.c $Revision: 1.98 $, nftlmount.c $Revision: 1.41 $
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c2440-nand s3c2440-nand: Tacls=1, 10ns Twrph0=4 40ns, Twrph1=1 10ns
NAND device: Manufacturer ID: 0xec, Chip ID: 0x76 (Samsung NAND 64MiB 3,3V 8-bit)
s3c2410_nand_update_chip: chip c3d7d4bc: 9
Scanning device for bad blocks
Bad eraseblock 357 at 0x00594000
Bad eraseblock 3335 at 0x0341c000
Bad eraseblock 3995 at 0x03e6c000
Creating 4 MTD partitions on "NAND 64MiB 3,3V 8-bit":
0x00000000-0x00030000 : "boot"
0x00030000-0x00200000 : "kernel"
0x00200000-0x02000000 : "rootfs"
0x02000000-0x04000000 : "ext-fs1"
usbmon: debugfs is not available
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
Initializing USB Mass Storage driver...
usbcore: registered new interface driver usb-storage
USB Mass Storage support registered.
mice: PS/2 mouse device common for all mice
i2c /dev entries driver
s3c2440-i2c s3c2440-i2c: slave address 0x10
s3c2440-i2c s3c2440-i2c: bus frequency set to 390 KHz
s3c2440-i2c s3c2440-i2c: i2c-0: S3C I2C adapter
S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled
Registered led device: led4
Registered led device: led5
Registered led device: led6
Registered led device: led7
TCP cubic registered
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
end_request: I/O error, dev mtdblock2, sector 2
EXT2-fs: unable to read superblock
end_request: I/O error, dev mtdblock2, sector 0
Buffer I/O error on device mtdblock2, logical block 0
end_request: I/O error, dev mtdblock2, sector 0
Buffer I/O error on device mtdblock2, logical block 0
end_request: I/O error, dev mtdblock2, sector 8
Buffer I/O error on device mtdblock2, logical block 1
end_request: I/O error, dev mtdblock2, sector 8
Buffer I/O error on device mtdblock2, logical block 1
end_request: I/O error, dev mtdblock2, sector 16
Buffer I/O error on device mtdblock2, logical block 2
end_request: I/O error, dev mtdblock2, sector 16
Buffer I/O error on device mtdblock2, logical block 2
end_request: I/O error, dev mtdblock2, sector 24
Buffer I/O error on device mtdblock2, logical block 3
end_request: I/O error, dev mtdblock2, sector 24
Buffer I/O error on device mtdblock2, logical block 3
end_request: I/O error, dev mtdblock2, sector 0
FAT: unable to read boot sector
VFS: Cannot open root device "mtdblock2" or unknown-block(31,2)
Please append a correct "root=" boot option; here are the available partitions:
1f00        192 mtdblock0 (driver?)
1f01       1856 mtdblock1 (driver?)
1f02      30720 mtdblock2 (driver?)
1f03      32768 mtdblock3 (driver?)
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(31,2)


问题可能:
a。MTD分区与bootloader不匹配
b。没有 devfs文件系统支持
c。ECC校验没有关闭

3. /linuxrc初始化失败
Linux video capture interface: v2.00
NFTL driver: nftlcore.c $Revision: 1.98 $, nftlmount.c $Revision: 1.41 $
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c2440-nand s3c2440-nand: Tacls=1, 10ns Twrph0=4 40ns, Twrph1=1 10ns
NAND device: Manufacturer ID: 0xec, Chip ID: 0x76 (Samsung NAND 64MiB 3,3V 8-bit)
s3c2410_nand_update_chip: chip c3d704bc: 9
NAND_ECC_NONE selected by board driver. This is not recommended !!
Scanning device for bad blocks
Bad eraseblock 357 at 0x00594000
Bad eraseblock 3335 at 0x0341c000
Bad eraseblock 3995 at 0x03e6c000
Creating 4 MTD partitions on "NAND 64MiB 3,3V 8-bit":
0x00000000-0x00030000 : "boot"
0x00030000-0x00200000 : "kernel"
0x00200000-0x02000000 : "rootfs"
0x02000000-0x04000000 : "ext-fs1"
usbmon: debugfs is not available
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
Initializing USB Mass Storage driver...
usbcore: registered new interface driver usb-storage
USB Mass Storage support registered.
mice: PS/2 mouse device common for all mice
i2c /dev entries driver
s3c2440-i2c s3c2440-i2c: slave address 0x10
s3c2440-i2c s3c2440-i2c: bus frequency set to 390 KHz
s3c2440-i2c s3c2440-i2c: i2c-0: S3C I2C adapter
S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled
Registered led device: led4
Registered led device: led5
Registered led device: led6
Registered led device: led7
TCP cubic registered
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
VFS: Mounted root (cramfs filesystem) readonly.
Freeing init memory: 124K
cramfs: bad compressed blocksize 989432407
cramfs: bad compressed blocksize 4274059297
Failed to execute /linuxrc.  Attempting defaults...
Kernel panic - not syncing: No init found.  Try passing init= option to kernel.


问题可能:
a。 "Default kernel command string"设置有误,比如启动分区指定不对
b。 可能是文件系统有问题

最后的这个问题更多的可能是文件系统制作导致的,由于我之前一直是用开发板自带的文件系统做的,一直不行。网上很多介绍busybox的文章,也许可以用这个试一下
阅读(565) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~