Google在内核里做了什么改动呢?
有家公司专门比较了标准内核和android内核,发现google修改了75个文件,增加了88个文件。该公司还对这些被修改的和新增的文件做了注解。
Goldfish -- 44 Files
kernel/arch/arm/mach-goldfish
kernel/include/asm-arm/arch-goldfish
Android模拟器运行了一个被google 叫做“金鱼"的虚拟CPU.金鱼运行arm926t指令集(arm926t是属于armv5架构);并且仿真了输入输出:比如键盘输入和LCD 输出。这个模拟器其实是在qemu之上开发的,输入输出基于libSDL.
内核里这个Goldfish接口实现了这个虚拟“金鱼”CPU的一些接口,如果想在真实设备上运行android,这些接口肯定要去掉的。
arm926ej的介绍见http://www.arm.com/products/CPUs/ARM926EJ-S.html
YAFFS2 -- 35 Files
kernel/fs/yaffs2
不同于PC机,文件是存储在硬盘上的;手机使用FLASH作为存储介质。HTC的G1使用NANDFLASH——这中存储目前已经相当普及了,而且种类也颇多,(SLC,MLC等等),存储密度也越来越高(已经出现几十G大小的NANDFLASH),价格也越来越低。
YAFFS2是专门用在FLASH上的文件系统,“YAFFS2”是"Yet Another Flash File System, 2nd edition"的缩写。YAFFS2为Linux内核提供了一个高效访问NANDFLASH的接口。但是NANDFLASH的支持并不包含在标准的2.6.25内核中,所以Google在其中添加了对NANDFLASH的支持。
蓝牙 -- 10 files
在蓝牙通讯协议栈里Google修改了10个文件。这些改动解决了一些跟蓝牙耳机相关的明显的bug,以及一些蓝牙调试和访问控制相关的函数。
调度器 -- 5 files
Android内核还修改了进程调度和时钟相关策略,这个改动就比较深入了。其目的和效果估计在一段时间后才能找到。
为android新增的功能 -- 28 files
除了修正一些bug以及其他的改动,android还增加了一些新的“子系统”,这些系统都比较重要。
IPC Binder
IPC Binder是一种IPC(进程间通信)机制。它使得进程能够为其他进程提供服务——还是通过标准的linux系统调用api。IPC Binder的概念起源于一家叫做“Be.Inc"的公司,在Google之前就已经被用到Palm软件里去了。
Low Memory Killer
其实内核里已经有一个类似的功能, 叫做"oom killer",就是out of memory killer,当内存不够的时候,改策略会试图结束一个进程。不知道为什么Google重新实现了这个策略。
Ashmem
Ashmem,全程Anonymous SHared MEMory,翻译成中文就是匿名共享内存。这个功能使得进程间能够共享大块的内存。比如说,系统可以使用Ashmem保存一些图标,多个应用程序可以访问这个共享内存来获取图标。Ashmem为内核提供了一种回收这些使用完的共享内存块的办法,如果一个进程试图访问这些已经被回收的内存块,它将会得到错误的返回值,以便它重新进行内存块分配和数据初始化。
RAM Console and Log Device
为了调试方便,Android添加了一个功能,使得调试信息可以输入到一个内存块中。此外,Android添加了一个独立的日志模块,这样用户空间的进程能够读写日志消息,调试打印信息等。
Android Debug Bridge
嵌入式设备的调试的确比较麻烦。为了便于调试,google设计了这个调试工具,可以叫做"ADB",使用USB作为连接方式,ADB可以看作是链接android的设备和PC机的一套协议。
Android 还添加了其他的东西,比如 real-time clock, switch,timed GPIO。
增加了Android的相关Driver,相应目录为:
kernel/drivers/android
主要分为:
Android IPC系统: Binder (binder.c)
Android 日志系统: Logger (logger.c)
Android 电源管理: Power (power.c)
Android 闹钟管理: Alarm (alarm.c)
Android 内存控制台: Ram_console (ram_console.c)
Android 时钟控制的gpio: Timed_gpio (timed_gpio.c)
增加了switch处理, 相应的目录为:
kernel/drivers/switch/
增加了一种新的共享内存处理方式, 相应增加的文件为:
kernel/mm/ashmem.c
其他为Linux-2.6.25内核所做的补丁等等,例如BlueTooth, 在此不做详细分析
另外GoldFish平台相关的驱动文件如下:
1. 字符输出设备:
kernel/drivers/char/goldfish_tty.c
2. 图象显示设备: (Frame Buffer)
kernel/drivers/video/goldfishfb.c
3. 键盘输入设备:
kernel/drivers/input/keyboard/goldfish_events.c
4. RTC设备: (Real Time Clock)
kernel/drivers/rtc/rtc-goldfish.c
5. USB Device设备:
kernel/drivers/usb/gadget/android_adb.c
6. SD卡设备:
kernel/drivers/mmc/host/goldfish.c
7. FLASH设备:
kernel/drivers/mtd/devices/goldfish_nand.c
kernel/drivers/mtd/devices/goldfish_nand_reg.h
8. LED设备:
kernel/drivers/leds/ledtrig-sleep.c
9. 电源设备:
kernel/drivers/power/goldfish_battery.c
10. 音频设备:
kernel/arch/arm/mach-goldfish/audio.c
11. 电源管理:
kernel/arch/arm/mach-goldfish/pm.c
12. 时钟管理:
kernel/arch/arm/mach-goldfish/timer.c
Power Management -- 5 files
电源管理对于移动设备来说相当重要,也是最复杂,开发难度最高的一个功能。Google添加了一个新的电源管理系统,并没有原先apm,dpm等。
其他修改 -- 36 files
除了上述改动之外,还有一些小改动,比如新增的额外的调试功能, 键盘背光控制,TCP 网络管理等等,共涉及36个文件。
根据上述,google对标准的内核做了很大的改动。相比其他的项目,比如Nokia N810,Openmoko等项目中,内核的改动仅仅是增加了某个平台的支持。所以移植最快也是最可能的办法是在google使用的kernel上增加平台支持。
也有一些开发人员将google对2.6.25内核的改动做成补丁,直接打在自己开发的内核上——当然,自己的内核也应该是2.6.25,否则会出问题。
模拟器上的Kernel信息
模拟器上kernel的信息
运行emulator –show-kernel –avd <your avd name>
Uncompressing Linux.................................................................................... done, booting the kernel.
emulator: emulator window was out of view and was recentred
Linux version 2.6.25-00350-g40fff9a ([email protected]) (gcc version 4.2.1) #1 Wed Jul 23 18:10:44 PDT 2008
CPU: ARM926EJ-S [41069265] revision 5 (ARMv5TEJ), cr=00003137
Machine: Goldfish
Memory policy: ECC disabled, Data cache writeback
CPU0: D VIVT write-through cache
CPU0: I cache: 4096 bytes, associativity 4, 32 byte lines, 32 sets
CPU0: D cache: 65536 bytes, associativity 4, 32 byte lines, 512 sets
Built 1 zonelists in Zone order, mobility grouping on. Total pages: 24384
Kernel command line: qemu=1 console=ttyS0 android.checkjni=1 android.qemud=ttyS1 android.ndns=2
Unknown boot option `android.checkjni=1': ignoring
Unknown boot option `android.qemud=ttyS1': ignoring
Unknown boot option `android.ndns=2': ignoring
PID hash table entries: 512 (order: 9, 2048 bytes)
Console: colour dummy device 80x30
Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)
Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)
Memory: 96MB = 96MB total
Memory: 94268KB available (2380K code, 445K data, 100K init)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
net_namespace: 152 bytes
android_power_init
android_power_init done
NET: Registered protocol family 16
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 4096 (order: 3, 32768 bytes)
TCP bind hash table entries: 4096 (order: 2, 16384 bytes)
TCP: Hash tables configured (established 4096 bind 4096)
TCP reno registered
checking if image is initramfs... it is
Freeing initrd memory: 136K
goldfish_new_pdev goldfish_interrupt_controller at ff000000 irq -1
goldfish_new_pdev goldfish_device_bus at ff001000 irq 1
goldfish_new_pdev goldfish_timer at ff003000 irq 3
goldfish_new_pdev goldfish_rtc at ff010000 irq 10
goldfish_new_pdev goldfish_tty at ff002000 irq 4
goldfish_new_pdev goldfish_tty at ff011000 irq 11
goldfish_new_pdev smc91x at ff012000 irq 12
goldfish_new_pdev goldfish_fb at ff013000 irq 13
goldfish_new_pdev goldfish_audio at ff004000 irq 14
goldfish_new_pdev goldfish_memlog at ff006000 irq -1
goldfish_new_pdev goldfish-battery at ff014000 irq 15
goldfish_new_pdev goldfish_events at ff015000 irq 16
goldfish_new_pdev goldfish_nand at ff016000 irq -1
goldfish_new_pdev goldfish-switch at ff017000 irq 17
goldfish_new_pdev goldfish-switch at ff018000 irq 18
goldfish_pdev_worker registered goldfish-switch
goldfish_pdev_worker registered goldfish-switch
goldfish_pdev_worker registered goldfish_nand
goldfish_pdev_worker registered goldfish_events
goldfish_pdev_worker registered goldfish-battery
goldfish_pdev_worker registered goldfish_memlog
goldfish_audio_probe
goldfish_pdev_worker registered goldfish_audio
goldfish_pdev_worker registered goldfish_fb
goldfish_pdev_worker registered smc91x
goldfish_pdev_worker registered goldfish_tty
goldfish_pdev_worker registered goldfish_tty
goldfish_pdev_worker registered goldfish_rtc
goldfish_pdev_worker registered goldfish_timer
goldfish_pdev_worker registered goldfish_device_bus
goldfish_pdev_worker registered goldfish_interrupt_controller
ashmem: initialized
Installing knfsd (copyright (C) 1996 [email protected]).
yaffs Jul 23 2008 18:10:35 Installing.
io scheduler noop registered
io scheduler anticipatory registered (default)
io scheduler deadline registered
io scheduler cfq registered
allocating frame buffer 320 * 480, got ffc10000
Console: switching to colour frame buffer device 40x30
console [ttyS0] enabled
brd: module loaded
loop: module loaded
nbd: registered device at major 43
smc91x.c: v1.1, sep 22 2004 by Nicolas Pitre <[email protected]>
No IRQF_TRIGGER set_type function for IRQ 12 (goldfish)
eth0: SMC91C11xFD (rev 1) at c6800000 IRQ 12 [nowait]
eth0: Ethernet addr: 52:54:00:12:34:56
goldfish nand dev0: size 4000000, page 2048, extra 64, erase 131072
goldfish nand dev1: size 4000000, page 2048, extra 64, erase 131072
goldfish nand dev2: size 4000000, page 2048, extra 64, erase 131072
mice: PS/2 mouse device common for all mice
*** events probe ***
events_probe() addr=0xc6804000 irq=16
events_probe() keymap=qwerty2
input: qwerty2 as /class/input/input0
goldfish_rtc goldfish_rtc: rtc core: registered goldfish_rtc as rtc0
logger: created 64K log 'log_main'
logger: created 64K log 'log_events'
logger: created 64K log 'log_radio'
IPv4 over IPv4 tunneling driver
GRE over IPv4 tunneling driver
TCP cubic registered
NET: Registered protocol family 1
NET: Registered protocol family 17
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
802.1Q VLAN Support v1.8 Ben Greear <[email protected]>
All bugs added by David S. Miller <[email protected]>
VFP support v0.3: implementor 41 architecture 1 part 10 variant 9 rev 0
goldfish_rtc goldfish_rtc: setting system clock to 2009-01-02 07:43:01 UTC (1230882181)
Freeing init memory: 100K
init: cannot open '/initlogo.rle'
yaffs: dev is 32505856 name is "mtdblock0"
yaffs: passed flags ""
yaffs: Attempting MTD mount on 31.0, "mtdblock0"
yaffs: dev is 32505857 name is "mtdblock1"
yaffs: passed flags ""
yaffs: Attempting MTD mount on 31.1, "mtdblock1"
yaffs: dev is 32505858 name is "mtdblock2"
yaffs: passed flags ""
yaffs: Attempting MTD mount on 31.2, "mtdblock2"
sh: can't access tty; job control turned off
# init: cannot find '/system/bin/playmp3', disabling 'bootsound'
eth0: link up
warning: `rild' uses 32-bit capabilities (legacy support in use)
init: sys_prop: mis-match msg size recieved: -1 expected: 128
从启动信息可以看出,其主CPU为ARM926EJ-S,并非ARM11 CPU, 说明下载的Emulator内核并非是针对G1手机的,估计只是实现了对ARM926EJ-S CPU的模拟。
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/magicyu2/archive/2009/10/26/4729223.aspx