Chinaunix首页 | 论坛 | 博客
  • 博客访问: 33170
  • 博文数量: 4
  • 博客积分: 598
  • 博客等级: 中士
  • 技术积分: 90
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-21 15:57
文章存档

2010年(4)

分类: LINUX

2010-02-06 23:30:27

  希望能通过本文能够了解到个模块的初始化顺序的完成及各自的初始化工作是如何被启动的。

  前几次对do_initcalls函数的修改均未取得明确的效果,分析其原因,单纯的对循环赋值会产生NULL空指针,使内核产生Oops,而达不到效果,此次修改对迭代器不做限制(无限循环)的输出为:

输出信息#1

NOW, Booting Linux......
Uncompressing Linux......................................................... done, booting the kernel.
Linux version 2.6.29.4-FriendlyARM (liunx@liunx-desktop) (gcc version 4.3.2 (Sourcery G++ Lite 2008q3-72) ) #7 Sat Feb 6 20:16:31 CST 2010
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
CPU: VIVT data cache, VIVT instruction cache
Machine: FriendlyARM Mini2440 development board
ATAG_INITRD is deprecated; please update your bootloader.
Memory policy: ECC disabled, Data cache writeback
CPU S3C2440A (id 0x32440001)
S3C24XX Clocks, (c) 2004 Simtec Electronics
S3C244X: core 405.000 MHz, memory 101.250 MHz, peripheral 50.625 MHz
CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 16256
Kernel command line: noinitrd root=/dev/mtdblock2 init=/linuxrc console=ttySAC0
irq: clearing subpending status 00000002
PID hash table entries: 256 (order: 8, 1024 bytes)
Console: colour dummy device 80x30
console [ttySAC0] enabled
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory: 64MB = 64MB total
Memory: 63004KB available (1564K code, 230K data, 64K init)
SLUB: Genslabs=12, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
Calibrating delay loop... 201.93 BogoMIPS (lpj=504832)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
S3C2440: Initialising architecture
S3C2440: IRQ Support
S3C24XX DMA Driver, (c) 2003-2004,2006 Simtec Electronics
DMA channel 0 at c4808000, irq 33
DMA channel 1 at c4808040, irq 34
DMA channel 2 at c4808080, irq 35
DMA channel 3 at c48080c0, irq 36
S3C244X: Clock Support, DVS off
bio: create slab at 0
yaffs Feb  2 2010 19:57:45 Installing.
msgmni has been set to 123
io scheduler noop registered (default)
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
loop: module loaded
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c2440-nand s3c2440-nand: Tacls=3, 29ns Twrph0=7 69ns, Twrph1=3 29ns
NAND device: Manufacturer ID: 0xec, Chip ID: 0x76 (Samsung NAND 64MiB 3,3V 8-bit)
Scanning device for bad blocks
Creating 3 MTD partitions on "NAND 64MiB 3,3V 8-bit":
0x000000000000-0x000000030000 : "supervivi"
0x000000050000-0x000000250000 : "Kernel"
0x000000250000-0x000003ffc000 : "root"
mice: PS/2 mouse device common for all mice
Console: colour dummy device 80x30
console [ttySAC0] enabled
Linux version 2.6.29.4-FriendlyARM (liunx@liunx-desktop) (gcc version 4.3.2 (Sourcery G++ Lite 2008q3-72) ) #7 Sat Feb 6 20:16:31 CST 2010
Linux version 2.6.29.4-FriendlyARM (liunx@liunx-desktop) (gcc version 4.3.2 (Sourcery G++ Lite 2008q3-72) ) #7 Sat Feb 6 20:16:31 CST 2010
Linux version 2.6.29.4-FriendlyARM (liunx@liunx-desktop) (gcc version 4.3.2 (Sourcery G++ Lite 2008q3-72) ) #7 Sat Feb 6 20:16:31 CST 2010
Linux version 2.6.29.4-FriendlyARM (liunx@liunx-desktop) (gcc version 4.3.2 (Sourcery G++ Lite 2008q3-72) ) #7 Sat Feb 6 20:16:31 CST 2010
...

星期六, 二月 6, 8:28 下午

再对do_initcalls函数进行修改,结果是:
    for (call = __initcall_start; call < __initcall_end; call++)

那么内核产生Oops的原因有在哪呢?
就让我们看看/arch/arm/kernel/vmlinux.lds.S中的奥秘:
...
        __setup_start = .;
            *(.init.setup)
        __setup_end = .;
        __early_begin = .;
            *(.early_param.init)
        __early_end = .;
        __initcall_start = .;
            INITCALLS
        __initcall_end = .;
        __con_initcall_start = .;
            *(.con_initcall.init)
        __con_initcall_end = .;
        __security_initcall_start = .;
            *(.security_initcall.init)
        __security_initcall_end = .;
#ifdef CONFIG_BLK_DEV_INITRD
...
那么__early_initcall_end全局变量又在哪里呢?

#define INITCALLS                            \
    *(.initcallearly.init)                        \
    VMLINUX_SYMBOL(__early_initcall_end) = .;            \
      *(.initcall0.init)                        \
      *(.initcall0s.init)                        \
      *(.initcall1.init)                        \
      *(.initcall1s.init)                        \
      *(.initcall2.init)                        \
      *(.initcall2s.init)                        \
      *(.initcall3.init)                        \
      *(.initcall3s.init)                        \
      *(.initcall4.init)                        \
      *(.initcall4s.init)                        \
      *(.initcall5.init)                        \
      *(.initcall5s.init)                        \
    *(.initcallrootfs.init)                        \
      *(.initcall6.init)                        \
      *(.initcall6s.init)                        \
      *(.initcall7.init)                        \
      *(.initcall7s.init)

从宏定义可以看出,do_initcalls函数完成对*initcall0-7*的函数的调用工作,当然各个函数的初始化工作有他们自身的函数完成了。

下面再让我们为do_initcalls函数加一个计数器,看看调用了多少函数:
NOW, Booting Linux......
Uncompressing Linux......................................................... done, booting the kernel.
Linux version 2.6.29.4-FriendlyARM (liunx@liunx-desktop) (gcc version 4.3.2 (Sourcery G++ Lite 2008q3-72) ) #9 Sat Feb 6 21:36:50 CST 2010
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
CPU: VIVT data cache, VIVT instruction cache
Machine: FriendlyARM Mini2440 development board
ATAG_INITRD is deprecated; please update your bootloader.
Memory policy: ECC disabled, Data cache writeback
CPU S3C2440A (id 0x32440001)
S3C24XX Clocks, (c) 2004 Simtec Electronics
S3C244X: core 405.000 MHz, memory 101.250 MHz, peripheral 50.625 MHz
CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 16256
Kernel command line: noinitrd root=/dev/mtdblock2 init=/linuxrc console=ttySAC0
irq: clearing subpending status 00000007
irq: clearing subpending status 00000002
PID hash table entries: 256 (order: 8, 1024 bytes)
Console: colour dummy device 80x30
console [ttySAC0] enabled
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory: 64MB = 64MB total
Memory: 63004KB available (1564K code, 230K data, 64K init)
SLUB: Genslabs=12, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
Calibrating delay loop... 201.93 BogoMIPS (lpj=504832)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
Now i am in the 0th function
Now i am in the 1th function
Now i am in the 2th function
Now i am in the 3th function
Now i am in the 4th function
Now i am in the 5th function
Now i am in the 6th function
Now i am in the 7th function
Now i am in the 8th function
Now i am in the 9th function
Now i am in the 10th function
Now i am in the 11th function
Now i am in the 12th function
Now i am in the 13th function
Now i am in the 14th function
Now i am in the 15th function
Now i am in the 16th function
Now i am in the 17th function
Now i am in the 18th function
Now i am in the 19th function
Now i am in the 20th function
Now i am in the 21th function
Now i am in the 22th function
Now i am in the 23th function
Now i am in the 24th function
S3C2440: Initialising architecture
S3C2440: IRQ Support
S3C24XX DMA Driver, (c) 2003-2004,2006 Simtec Electronics
DMA channel 0 at c4808000, irq 33
DMA channel 1 at c4808040, irq 34
DMA channel 2 at c4808080, irq 35
DMA channel 3 at c48080c0, irq 36
S3C244X: Clock Support, DVS off
Now i am in the 25th function
Now i am in the 26th function
Now i am in the 27th function
Now i am in the 28th function
bio: create slab at 0
Now i am in the 29th function
Now i am in the 30th function
Now i am in the 31th function
Now i am in the 32th function
Now i am in the 33th function
Now i am in the 34th function
Now i am in the 35th function
Now i am in the 36th function
Now i am in the 37th function
Now i am in the 38th function
Now i am in the 39th function
Now i am in the 40th function
Now i am in the 41th function
Now i am in the 42th function
Now i am in the 43th function
Now i am in the 44th function
Now i am in the 45th function
Now i am in the 46th function
Now i am in the 47th function
Now i am in the 48th function
Now i am in the 49th function
Now i am in the 50th function
Now i am in the 51th function
Now i am in the 52th function
Now i am in the 53th function
Now i am in the 54th function
Now i am in the 55th function
Now i am in the 56th function
Now i am in the 57th function
Now i am in the 58th function
Now i am in the 59th function
Now i am in the 60th function
Now i am in the 61th function
Now i am in the 62th function
Now i am in the 63th function
Now i am in the 64th function
Now i am in the 65th function
Now i am in the 66th function
Now i am in the 67th function
Now i am in the 68th function
Now i am in the 69th function
Now i am in the 70th function
Now i am in the 71th function
Now i am in the 72th function
Now i am in the 73th function
Now i am in the 74th function
Now i am in the 75th function
Now i am in the 76th function
Now i am in the 77th function
Now i am in the 78th function
Now i am in the 79th function
Now i am in the 80th function
Now i am in the 81th function
Now i am in the 82th function
Now i am in the 83th function
Now i am in the 84th function
Now i am in the 85th function
Now i am in the 86th function
Now i am in the 87th function
Now i am in the 88th function
Now i am in the 89th function
Now i am in the 90th function
Now i am in the 91th function
Now i am in the 92th function
yaffs Feb  2 2010 19:57:45 Installing.
Now i am in the 93th function
msgmni has been set to 123
Now i am in the 94th function
Now i am in the 95th function
Now i am in the 96th function
io scheduler noop registered (default)
Now i am in the 97th function
Now i am in the 98th function
Now i am in the 99th function
Now i am in the 100th function
Now i am in the 101th function
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
Now i am in the 102th function
loop: module loaded
Now i am in the 103th function
Now i am in the 104th function
Now i am in the 105th function
Now i am in the 106th function
Now i am in the 107th function
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c2440-nand s3c2440-nand: Tacls=3, 29ns Twrph0=7 69ns, Twrph1=3 29ns
NAND device: Manufacturer ID: 0xec, Chip ID: 0x76 (Samsung NAND 64MiB 3,3V 8-bit)
Scanning device for bad blocks
Creating 3 MTD partitions on "NAND 64MiB 3,3V 8-bit":
0x000000000000-0x000000030000 : "supervivi"
0x000000050000-0x000000250000 : "Kernel"
0x000000250000-0x000003ffc000 : "root"
Now i am in the 108th function
mice: PS/2 mouse device common for all mice
Now i am in the 109th function
Now i am in the 110th function
Now i am in the 111th function
Now i am in the 112th function
Now i am in the 113th function
Now i am in the 114th function
Now i am in the 115th function
Now i am in the 116th function
FAT: utf8 is not a recommended IO charset for FAT filesystems, filesystem will be case sensitive!
yaffs: dev is 32505858 name is "mtdblock2"
yaffs: passed flags ""
yaffs: Attempting MTD mount on 31.2, "mtdblock2"
yaffs_read_super: isCheckpointed 0
VFS: Mounted root (yaffs filesystem) on device 31:2.
Freeing init memory: 64K
 mount: mounting none on /proc/bus/usb failed: No such file or directory
/etc/init.d/rcS: line 20: can't create /proc/sys/kernel/hotplug: nonexistent directory
hwclock: can't open '/dev/misc/rtc': No such file or directory
[01/Jan/1970:00:00:07 +0000] boa.c:173 - unable to create socket: Function not implemented
open device leds: No such file or directory
                       
ifconfig: socket: Function not implemented
Try to bring eth0 interface up......ifconfig: socket: Function not implemented
ifconfig: socket: Function not implemented
ifconfig: socket: Function not implemented
route: socket: Function not implemented
Done

Please press Enter to activate this console.
[root@FriendlyARM /]#
哇,确实不少,别忘了我还把许多驱动给省掉了,do_initcalls函数虽然不大,可做用可不小啊!
通过这个实验来对比计数器所关联的函数位置和vmlinux.dis(由arm-linux-objdump -D得来),完全符合!看来,每个模块函数都要
遵守纪律排队的!那么,它们之间的先后循序有着怎样的联系呢?
那么,就让我们在INITCALLS这个宏定义上做点文章吧,让我们修改一下他的顺序:

#define INITCALLS                            \
    *(.initcallearly.init)                        \
    VMLINUX_SYMBOL(__early_initcall_end) = .;            \
      *(.initcall0.init)                        \
      *(.initcall0s.init)                        \
      *(.initcall1.init)                        \
      *(.initcall1s.init)                        \
      *(.initcall2.init)                        \
      *(.initcall2s.init)                        \
      *(.initcall3.init)                        \
      *(.initcall3s.init)                        \
      *(.initcall4.init)                        \
      *(.initcall4s.init)                        \
      *(.initcall5.init)                        \
      *(.initcall5s.init)                        \
    *(.initcallrootfs.init)                        \
      *(.initcall7.init)                        \
      *(.initcall7s.init)                        \
      *(.initcall6.init)                        \
      *(.initcall6s.init)
我们将最后两个的位置倒置一下,看看内核运行是否正常吧:
请看输出结果。。。
哈,没有问题,但是还是不能让人信服,如果没有先后顺序,那么为什么还要给initcall增加编号呢?所以,这其中肯定是由主次的。
再修改一下:
...
CPU: Testing write buffer coherency: ok
Now i am in the 0th function
Now i am in the 1th function
Now i am in the 2th function
Now i am in the 3th function
Now i am in the 4th function
Now i am in the 5th function
Now i am in the 6th function
Now i am in the 7th function
Now i am in the 8th function
Now i am in the 9th function
Now i am in the 10th function
Now i am in the 11th function
Now i am in the 12th function
Now i am in the 13th function
Now i am in the 14th function
Now i am in the 15th function
Now i am in the 16th function
Now i am in the 17th function
Now i am in the 18th function
Now i am in the 19th function
Now i am in the 20th function
Now i am in the 21th function
Now i am in the 22th function
Now i am in the 23th function
Now i am in the 24th function
Now i am in the 25th function
Now i am in the 26th function
Now i am in the 27th function
Now i am in the 28th function
Now i am in the 29th function
S3C2440: Initialising architecture
S3C2440: IRQ Support
S3C24XX DMA Driver, (c) 2003-2004,2006 Simtec Electronics
DMA channel 0 at c4808000, irq 33
DMA channel 1 at c4808040, irq 34
DMA channel 2 at c4808080, irq 35
DMA channel 3 at c48080c0, irq 36
S3C244X: Clock Support, DVS off
Now i am in the 30th function
Now i am in the 31th function
Now i am in the 32th function
Now i am in the 33th function
bio: create slab at 0
Now i am in the 34th function
Now i am in the 35th function
Now i am in the 36th function
Now i am in the 37th function
Now i am in the 38th function
Now i am in the 39th function
Now i am in the 40th function
Now i am in the 41th function
Now i am in the 42th function
Now i am in the 43th function
Now i am in the 44th function
Now i am in the 45th function
Now i am in the 46th function
Now i am in the 47th function
Now i am in the 48th function
Now i am in the 49th function
Now i am in the 50th function
Now i am in the 51th function
Now i am in the 52th function
Now i am in the 53th function
Now i am in the 54th function
Now i am in the 55th function
Now i am in the 56th function
Now i am in the 57th function
Now i am in the 58th function
Now i am in the 59th function
Now i am in the 60th function
Now i am in the 61th function
Now i am in the 62th function
Now i am in the 63th function
Now i am in the 64th function
Now i am in the 65th function
Now i am in the 66th function
Now i am in the 67th function
Now i am in the 68th function
Now i am in the 69th function
Now i am in the 70th function
Now i am in the 71th function
Now i am in the 72th function
Now i am in the 73th function
Now i am in the 74th function
Now i am in the 75th function
Now i am in the 76th function
Now i am in the 77th function
Now i am in the 78th function
Now i am in the 79th function
Now i am in the 80th function
Now i am in the 81th function
Now i am in the 82th function
Now i am in the 83th function
Now i am in the 84th function
Now i am in the 85th function
Now i am in the 86th function
Now i am in the 87th function
Now i am in the 88th function
Now i am in the 89th function
Now i am in the 90th function
Now i am in the 91th function
Now i am in the 92th function
Now i am in the 93th function
Now i am in the 94th function
Now i am in the 95th function
Now i am in the 96th function
Now i am in the 97th function
Now i am in the 98th function
Now i am in the 99th function
yaffs Feb  2 2010 19:57:45 Installing.
Now i am in the 100th function
msgmni has been set to 123
Now i am in the 101th function
Now i am in the 102th function
Now i am in the 103th function
io scheduler noop registered (default)
Now i am in the 104th function
Now i am in the 105th function
Now i am in the 106th function
Now i am in the 107th function
Now i am in the 108th function
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
Now i am in the 109th function
loop: module loaded
Now i am in the 110th function
Now i am in the 111th function
Now i am in the 112th function
Now i am in the 113th function
Now i am in the 114th function
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c2440-nand s3c2440-nand: Tacls=3, 29ns Twrph0=7 69ns, Twrph1=3 29ns
NAND device: Manufacturer ID: 0xec, Chip ID: 0x76 (Samsung NAND 64MiB 3,3V 8-bit)
Scanning device for bad blocks
Creating 3 MTD partitions on "NAND 64MiB 3,3V 8-bit":
0x000000000000-0x000000030000 : "supervivi"
0x000000050000-0x000000250000 : "Kernel"
0x000000250000-0x000003ffc000 : "root"
Now i am in the 115th function
mice: PS/2 mouse device common for all mice
Now i am in the 116th function
...
嘿,没问题?搞不明白。。。难道真的没什么秘密吗?






阅读(3592) | 评论(0) | 转发(1) |
0

上一篇:没有了

下一篇:搭建linux music studio

给主人留下些什么吧!~~