Chinaunix首页 | 论坛 | 博客
  • 博客访问: 829110
  • 博文数量: 281
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2770
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-02 19:45
个人简介

邮箱:zhuimengcanyang@163.com 痴爱嵌入式技术的蜗牛

文章分类
文章存档

2020年(1)

2018年(1)

2017年(56)

2016年(72)

2015年(151)

分类: LINUX

2016-06-18 11:17:27

移植新内核第二课: 修改分区, 制作新的文件系统

上一节课,可以打印了,但是无法挂接根文件系统。
启动打印信息:

Creating 8 MTD partitions on "NAND":
0x000000000000-0x000000004000 : "Boot Agent"
mtd: partition "Boot Agent" doesn't end on an erase block -- force read-only
0x000000000000-0x000000200000 : "S3C2410 flash partition 1"
0x000000400000-0x000000800000 : "S3C2410 flash partition 2"
0x000000800000-0x000000a00000 : "S3C2410 flash partition 3"
0x000000a00000-0x000000e00000 : "S3C2410 flash partition 4"
0x000000e00000-0x000001800000 : "S3C2410 flash partition 5"
0x000001800000-0x000003000000 : "S3C2410 flash partition 6"
0x000003000000-0x000010000000 : "S3C2410 flash partition 7"
dm9000 Ethernet Driver, V1.31
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
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
usbcore: registered new interface driver libusual
usbcore: registered new interface driver usbserial
usbcore: registered new interface driver usbserial_generic
USB Serial support registered for generic
usbserial: USB Serial Driver core
usbcore: registered new interface driver ftdi_sio
USB Serial support registered for FTDI USB Serial Device
ftdi_sio: v1.6.0:USB FTDI Serial Converters Driver
usbcore: registered new interface driver pl2303
USB Serial support registered for pl2303
mousedev: PS/2 mouse device common for all mice
s3c2410_wdt: S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq disabled
TCP: cubic registered
NET: Registered protocol family 17
drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
ALSA device list:
  No soundcards found.
List of all partitions:
1f00              16 mtdblock0  (driver?)
1f01            2048 mtdblock1  (driver?)
1f02            4096 mtdblock2  (driver?)
1f03            2048 mtdblock3  (driver?)
1f04            4096 mtdblock4  (driver?)
1f05           10240 mtdblock5  (driver?)
1f06           24576 mtdblock6  (driver?)
1f07          212992 mtdblock7  (driver?)
No filesystem could mount root, tried:  ext3 ext2 cramfs vfat msdos iso9660 romfs
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(31,3)
Backtrace:
[] (dump_backtrace+0x0/0x10c) from [] (dump_stack+0x18/0x1c)
 r6:c38a9000 r5:ffffffea r4:c381df2c
[] (dump_stack+0x0/0x1c) from [] (panic+0x7c/0x1d0)
[] (panic+0x0/0x1d0) from [] (mount_block_root+0x1e0/0x23c)
 r3:00000003 r2:c381df2c r1:c381df2c r0:c04e4c20
[] (mount_block_root+0x0/0x23c) from [] (mount_root+0x88/0x108)
[] (mount_root+0x0/0x108) from [] (prepare_namespace+0x110/0x1d0)
 r7:c05ac540 r6:c056e764 r5:c056e764 r4:c05ac5a0
[] (prepare_namespace+0x0/0x1d0) from [] (kernel_init+0x164/0x1b8)
 r6:00000008 r5:c056df38 r4:c0574b34
[] (kernel_init+0x0/0x1b8) from [] (do_exit+0x0/0x76c)

1. 找出分区代码

找到源码中打印该句话的代码 "Boot Agent"
book@book-desktop:/work/system/linux-3.4.2$ grep "\"Boot\ Agent\"" * -nR
\ 转义符,表示使用它原来的意思,\" 表示找到"原来的意思。
打印信息:
arch/arm/mach-s3c24xx/mach-at2440evb.c:85:              .name   = "Boot Agent",
arch/arm/mach-s3c24xx/mach-bast.c:224:          .name   = "Boot Agent",
arch/arm/mach-s3c24xx/mach-osiris.c:140:                .name   = "Boot Agent",
arch/arm/mach-s3c24xx/mach-osiris.c:163:                .name   = "Boot Agent",
arch/arm/mach-s3c24xx/mach-vstms.c:81:          .name   = "Boot Agent",
arch/arm/mach-s3c24xx/mach-anubis.c:129:                .name   = "Boot Agent",
arch/arm/mach-s3c24xx/mach-anubis.c:152:                .name   = "Boot Agent",

arch/arm/mach-s3c24xx/common-smdk.c:113:                .name   = "Boot Agent",


进入代码:arch/arm/mach-s3c24xx/common-smdk.c,找到默认分区表:
static struct mtd_partition smdk_default_nand_part[] = {
    [0] = {
        .name    = "Boot Agent",
        .size    = SZ_16K,
        .offset    = 0,
    },
    [1] = {
        .name    = "S3C2410 flash partition 1",
        .offset = 0,
        .size    = SZ_2M,
    },
    [2] = {
        .name    = "S3C2410 flash partition 2",
        .offset = SZ_4M,
        .size    = SZ_4M,
    },
    [3] = {
        .name    = "S3C2410 flash partition 3",
        .offset    = SZ_8M,
        .size    = SZ_2M,
    },
    [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    = MTDPART_SIZ_FULL,
    }
};

修改为四个分区:
     #: name                size            offset          mask_flags
     0: u-boot              0x00040000      0x00000000      0
     1: params              0x00020000      0x00040000      0
     2: kernel              0x00200000      0x00060000      0
     3: rootfs              0x0fda0000      0x00260000      0
 ----------------------------------------------------------------------------------
 static struct mtd_partition smdk_default_nand_part[] = {
    [0] = {
        .name    = "u-boot",
        .size    = SZ_256K,
        .offset    = 0,
    },
    [1] = {
        .name    = "params",
        .offset = MTDPART_OFS_APPEND,
        .size    = SZ_128K,
    },
    [2] = {
        .name    = "kernel",
        .offset = MTDPART_OFS_APPEND,
        .size    = SZ_2M,
    },
    [3] = {
        .name    = "rootfs",
        .offset    = MTDPART_OFS_APPEND,
        .size    = MTDPART_SIZ_FULL,
    }
};
重新编译内核为uImage_kernel,烧写进开发板,启动打印:
Creating 4 MTD partitions on "NAND":
0x000000000000-0x000000040000 : "u-boot"
0x000000040000-0x000000060000 : "params"
0x000000060000-0x000000260000 : "kernel"
0x000000260000-0x000010000000 : "rootfs"
dm9000 Ethernet Driver, V1.31
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
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
usbcore: registered new interface driver libusual
usbcore: registered new interface driver usbserial
usbcore: registered new interface driver usbserial_generic
USB Serial support registered for generic
usbserial: USB Serial Driver core
usbcore: registered new interface driver ftdi_sio
USB Serial support registered for FTDI USB Serial Device
ftdi_sio: v1.6.0:USB FTDI Serial Converters Driver
usbcore: registered new interface driver pl2303
USB Serial support registered for pl2303
mousedev: PS/2 mouse device common for all mice
s3c2410_wdt: S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq disabled
TCP: cubic registered
NET: Registered protocol family 17
drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
ALSA device list:
  No soundcards found.
List of all partitions:
1f00             256 mtdblock0  (driver?)
1f01             128 mtdblock1  (driver?)
1f02            2048 mtdblock2  (driver?)
1f03          259712 mtdblock3  (driver?)
No filesystem could mount root, tried:  ext3 ext2 cramfs vfat msdos iso9660 romfs
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(31,3)
Backtrace:
[] (dump_backtrace+0x0/0x10c) from [] (dump_stack+0x18/0x1c)
 r6:c38aa000 r5:ffffffea r4:c381df2c
[] (dump_stack+0x0/0x1c) from [] (panic+0x7c/0x1d0)
[] (panic+0x0/0x1d0) from [] (mount_block_root+0x1e0/0x23c)
 r3:00000003 r2:c381df2c r1:c381df2c r0:c04e4c20
[] (mount_block_root+0x0/0x23c) from [] (mount_root+0x88/0x108)
[] (mount_root+0x0/0x108) from [] (prepare_namespace+0x110/0x1d0)
 r7:c05ac4c0 r6:c056e764 r5:c056e764 r4:c05ac520
[] (prepare_namespace+0x0/0x1d0) from [] (kernel_init+0x164/0x1b8)
 r6:00000008 r5:c056df38 r4:c0574b34
[] (kernel_init+0x0/0x1b8) from [] (do_exit+0x0/0x76c)
可以看到创建了4个分区,但是还是说没有文件系统。

2. 烧写YAFFS文件系统实验

tftp 30000000 fs_mini_mdev.yaffs2
nand erase.part rootfs
nand write.yaffs 30000000 260000 $filesize

tftp 30000000 uImage_kernel
bootm 30000000
打印同样的信息,从信息:
No filesystem could mount root, tried:  ext3 ext2 cramfs vfat msdos iso9660 romfs
可知,kernel并不支持yaffs文件格式。
尝试JFFS文件格式。

3. 烧写JFFS文件系统实验

tftp 30000000 fs_mini_mdev.jffs2
nand erase.part rootfs
nand write.jffs2 30000000 260000 $filesize
设置启动参数:
set bootargs console=ttySAC0,115200 root=/dev/mtdblock3 rootfstype=jffs2

启动内核
tftp 30000000 uImage_kernel
bootm 30000000

打印信息:
VFS: Mounted root (jffs2 filesystem) on device 31:3.
Freeing init memory: 172K
init started: BusyBox v1.7.0 (2008-01-22 10:04:09 EST)
starting pid 935, tty '': '/etc/init.d/rcS'
ifconfig: SIOCSIFADDR: No such device

可以挂接jffs文件了,但是启动不了init。

4. 制作根文件系统

4.1 下载busybox:busybox-1.20.0.tar.bz2

4.2 解压busybox,安装交叉编译器

    tar xjf busybox-1.20.0.tar.bz2
    安装交叉编译器,修改主目录下的Makefile文件:
    164 CROSS_COMPILE ?=
    改为
    164 CROSS_COMPILE ?= arm-linux-
    
    make menuconfig:
    CROSS_COMPILER_PREFIX 设置为:arm-linux-
      | Symbol: CROSS_COMPILER_PREFIX [=arm-linux-]                                                                          |
      | Prompt: Cross Compiler prefix                                                                                        |
      |   Defined at Config.in:590                                                                                           |
      |   Location:                                                                                                          |
      |     -> Busybox Settings                                                                                              |
      |       -> Build Options     

4.3 编译

    make

4.4 创建根文件系统的文件夹:/work/nfs_root/my_fs

    mkdir my_fs

4.5 安装busybox到刚建立的根文件目录中

    book@book-desktop:/work/system/busybox-1.20.0$ make install CONFIG_PREFIX=/work/nfs_root/my_fs
    编译安装完成,可以查看目录:/work/nfs_root/my_fs 已经有以下目录,表示安装成功。
    bin  linuxrc  sbin  usr

4.6 安装库文件lib

    book@book-desktop:/work/nfs_root/my_fs$ mkdir lib
    book@book-desktop:/work/nfs_root/my_fs$ mkdir usr/lib -p     // -p 表示递归创建文件夹
    
    从交叉编译器中拷贝需要用到的库文件:
    cp /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib/*so* /work/nfs_root/my_fs/lib -d
    cp /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/usr/lib/*so* /work/nfs_root/my_fs/usr/lib -d
    // -d 表示原来是链接文件,拷贝过来也是链接文件,否则会拷贝整个源文件,使得整个文件变得很大。

4.7 构建根文件系统

4.7.1 构建etc目录
    可以自己写,也可以拷贝以前的。
    book@book-desktop:/work/nfs_root$ cp first_fs/etc/ my_fs/ -rf
    可以分析/etc/inittab,以及/etc/init.d/rcS文件。
    启动linux内核,初始化应用程序在inittab脚本文件中,而在该脚本文件中,调用/etc/init.d/rcS的配置文件运行。

    
4.7.2 构建dev目录,创建设备节点
    book@book-desktop:/work/nfs_root/my_fs$ mkdir dev
    book@book-desktop:/work/nfs_root/my_fs/dev$ sudo mknod console c 5 1
    book@book-desktop:/work/nfs_root/my_fs/dev$ sudo mknod null c 1 3
    
    book@book-desktop:/work/nfs_root/my_fs/dev$ ls -l
        total 0
        crw-r--r-- 1 root root 5, 1 2016-05-23 14:28 console
        crw-r--r-- 1 root root 1, 3 2016-05-23 14:28 null
    
4.7.3 构建其他目录:proc tmp mnt sys root
    book@book-desktop:/work/nfs_root/my_fs$ mkdir proc tmp mnt sys root
    book@book-desktop:/work/nfs_root/my_fs$ ls
        bin  dev  etc  lib  linuxrc  mnt  proc  root  sbin  sys  tmp  usr

5. 制作jiffs2文件

    制作my_fs为my_fs.jffs2
    mkfs.jffs2 -n -s 2048 -e 128KiB -d my_fs -o my_fs.jffs2
 

6. 测试

6.1 下载jffs2文件系统到板子中

    tftp 30000000 my_fs.jffs2
    nand erase.part rootfs
    nand write.jffs2 30000000 260000 $filesize

6.2 设置启动参数

    set bootargs console=ttySAC0,115200 root=/dev/mtdblock3 rootfstype=jffs2

6.3 下载内核,启动

    tftp 30000000 uImage_newnewnewkernel
    bootm 30000000
    
    打印启动信息:
    ......
    ......
    drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
    ALSA device list:
      No soundcards found.
    VFS: Mounted root (jffs2 filesystem) on device 31:3.
    Freeing init memory: 172K
    Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000004

    Backtrace:
    [] (dump_backtrace+0x0/0x10c) from [] (dump_stack+0x18/0x1c)
     r6:c3819d60 r5:c058eb14 r4:c058eb14
    [] (dump_stack+0x0/0x1c) from [] (panic+0x7c/0x1d0)
    [] (panic+0x0/0x1d0) from [] (do_exit+0x644/0x76c)
     r3:c381fc40 r2:c3819e80 r1:00000004 r0:c04ea064
    [] (do_exit+0x0/0x76c) from [] (do_group_exit+0x50/0xb8)
    [] (do_group_exit+0x0/0xb8) from [] (get_signal_to_deliver+0x1e0/0x4f4)
     r4:00000000
    [] (get_signal_to_deliver+0x0/0x4f4) from [] (do_notify_resume+0xd0/0x520)
    [] (do_notify_resume+0x0/0x520) from [] (work_pending+0x24/0x28)

    发现这个错误:
    Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000004

6.4 增加EABI接口:

    发现需要增加EABI接口
    arm-linux-gcc是使用EABI接口,所以内核也需要支持这种接口。
    重新配置,把EABI接口加入到内核配置选项中。
    | Symbol: AEABI [=y]                                                           |
    | Type  : boolean                                                              |
    | Prompt: Use the ARM EABI to compile the kernel                               |
    |   Defined at arch/arm/Kconfig:1678                                           |
    |   Location:                                                                  |
    |     -> Kernel Features                                                       |
    |   Selected by: ARCH_OMAP2PLUS_TYPICAL [=n] && ARCH_OMAP2PLUS [=n] || THUMB2_

    重新编译内核:
    make uImage

6.5 重新设置启动参数,下载新的内核,并启动

设置启动参数
    set bootargs console=ttySAC0,115200 root=/dev/mtdblock3 rootfstype=jffs2

重新编译,下载内核,启动
    tftp 30000000 uImage_eabi
    bootm 30000000
打印如下错误:
    ALSA device list:
      No soundcards found.
    VFS: Mounted root (jffs2 filesystem) on device 31:3.
    Freeing init memory: 148K
    Kernel panic - not syncing: No init found.  Try passing init= option to kernel. See Linux Documentation/init.txt for guidance.
    [] (unwind_backtrace+0x0/0xf8) from [] (panic+0x74/0x1d0)
    [] (panic+0x74/0x1d0) from [] (init_post+0xc0/0x138)
    [] (init_post+0xc0/0x138) from [] (kernel_init+0x16c/0x1bc)
    
这个错误,发现是内核的问题,重新修改和编译了一遍新的内核,就OK了。
tftp 30000000 uImage_eabi; bootm 30000000
启动打印:
    ......
    ALSA device list:
      No soundcards found.
    VFS: Mounted root (jffs2 filesystem) on device 31:3.
    Freeing init memory: 164K
    ifconfig: SIOCSIFADDR: No such device
    can't open /dev/s3c2410_serial0: No such file or directory
    can't open /dev/s3c2410_serial0: No such file or directory
    can't open /dev/s3c2410_serial0: No such file or directory
    can't open /dev/s3c2410_serial0: No such file or directory
    can't open /dev/s3c2410_serial0: No such file or directory
    can't open /dev/s3c2410_serial0: No such file or directory
    ....

问题1:    
    打印语句:ifconfig: SIOCSIFADDR: No such device
回答1:
    是因为文件系统的配置文件:etc/init.d/rcS
    #!/bin/sh
    ifconfig eth0 192.168.1.17   // 目前还没有配置DM9000网卡,所以当运行这句脚本命令将打印找不到设置的警告

    mount -a
    mkdir /dev/pts
    mount -t devpts devpts /dev/pts
    echo /sbin/mdev > /proc/sys/kernel/hotplug
    mdev -s
    
问题2:
    打印语句:can't open /dev/s3c2410_serial0: No such file or directory
回答2:
    在配置文件:etc/inittab 定义了这句命令:s3c2410_serial0::askfirst:-/bin/sh
    # /etc/inittab
    ::sysinit:/etc/init.d/rcS
    s3c2410_serial0::askfirst:-/bin/sh
    ::ctrlaltdel:/sbin/reboot
    ::shutdown:/bin/umount -a -r

    但是在设备文件中根本没定义这个设备:/dev/s3c2410_serial0
    可以查看设备文件,根本没建立这个设备:
    $ ls dev/ -l
    total 0
    crw-r--r-- 1 root root 5, 1 2016-12-10 09:14 console
    crw-r--r-- 1 root root 1, 3 2016-12-10 09:14 null
    
    所以解决方法有两条:
    方法1:改变这个脚本命令:
        s3c2410_serial0::askfirst:-/bin/sh
        修改为:
        ttySAC0::askfirst:-/bin/sh
    方法2:
        在设备文件/dev目录下,增加一个设备文件s3c2410_serial0:
        sudo mknod s3c2410_serial0 c 204 64
      这里采用方法一。
    重新修改文件系统,并制作。
    烧写新的文件系统,新内核镜像,启动后,看打印信息:
 .....
ALSA device list:
  No soundcards found.
jffs2: Empty flash at 0x003b8fd8 ends at 0x003b9000
VFS: Mounted root (jffs2 filesystem) on device 31:3.
Freeing init memory: 164K

Please press Enter to activate this console.
/ #
/ #
/ #
已经启动shell脚本。

总结:

1. 为新的内核在FLASH上添加新的分区信息;
2. 烧写jffs2,yaffs文件系统,看看内核能不能启动;
3. 利用busybox来制作自己的根文件系统,并制作为jffs2文件系统,在新的内核上挂接根文件系统。


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