【Android源码 栏目提醒】:以下是网学会员为您推荐的Android源码 -内核移植和Android文件系统 - 互联网,希望本篇文章对您学习有所帮助。
内核移植和
Android文件系统 最新clone下来的
Android Linux内核是2.6.27版本。
与最开始发布m5-rc14的
Android 2.6.25内核相比2.6.27的内核删除了goldfish目标板的板机支持包。
1.内核移植前几天把NaviEngine一直到了2.6.28内核上所以现在只需要把
Android的内核patch从2.6.27移植到2.6.28上。
首先需要将
Android内核Patch取出来从www.kernel.org下载2.6.27的内核linux-2.6.27.tar.gz并解压缩tar zxf linux-2.6.27.tar.gzAndroid的内核在git repository的kernel目录。
执行一下命令cdandroiddiff-Nuar-x.git./linux-2.6.27 kernel
android-2.6.27.patch然后把
android-2.6.27.patch通过patch命令apply到2.6.28的内核之上。
patch的时候会有冲突这时候需要手动修改一下源代码。
Android的内核包含了很多设备驱动但是如果目标板没有该设备的话这类驱动可以不用patch到自己的内核上比如bluetoothi2c等等。
另外它还包含了yaffs2文件系统如果不想使用该文件系统的话这些
源码也可以不要。
应用到2.6.28上的patchandroid-2.6.28.patch另外我对binder和framebuffer的驱动做了一些修改否则
Android启动会不成功binder Indexlinux-2.6.28/drivers/misc/binder.c-linux-2.6.28.orig/drivers/misc/binder.clinux-2.6.28/drivers/misc/binder.c-156157includeincludeincludeinclude-557568static int binder_read_proc_procendif ifndef __i386__-define FORBIDDEN_MMAP_FLAGSVM_WRITEVM_EXEC/define FORBIDDEN_MMAP_FLAGSVM_WRITEVM_EXEC/define FORBIDDEN_MMAP_FLAGSVM_WRITEelsedefine FORBIDDEN_MMAP_FLAGSVM_WRITEendifframebuffer
Android使用了double buffer/page flipping。
所以framebuffer的驱动必须支持double buffer.NaviEngine原有的驱动并不支持该功能。
我增加了这个patchne1-fb-double-buffer.patch主要是增加了ne1_fb_pan_display函数。
这个函数是切换buffer时候被调用的。
Double buffer设计成上下两个buffer的模式因此xres_virtualxresyres_virtualyres2struct fb_info结构体的ypanstep要设成1。
另外内核分配framebuffer内存的时候也需要分配两倍的内存。
这样切换buffer的时候会调用ne1_fb_pan_display该函数将新的内存地址写到LCD控制器。
/Set new xy offsets in the virtual display for the visible area and switchto the new mode./static int ne1_fb_pan_displaystruct fb_var_screeninfovarstruct fb_infoinfostruct ne1_fb_parparinfo-parunsigned int bytes_pixelvar-bits_per_pixel/8unsigned long offsetinfo-var.xoffsetvar-xoffsetinfo-var.yoffsetvar-yoffsetoffsetvar-xoffsetbytes_pixelvar-yoffsetinfo-fix.line_length//Set buffer start addressne1_fb_write64NE1_HW_LAYER_1 regsMF_SADR_01return 02.
Android文件系统要在目标板上启动
Android需要
Android的文件系统。
这些可以从
Android的模拟器里得到。
参考这边文章url以下是具体的步骤Start emulator in debug mode and with sdcardemulator-sdcard card.img-debug-kernelcard.img is created by mksdcard commandmksdcard-l card 256M card.imgDownload busybox fromurllink/urlor busybox for
android.After emulator starteddo this in hostadb push busybox/system/bin/busyboxadb shellcommands below runs on emulator shellchmod 755/system/bin/busyboxcd/sdcardbusybox tar cf system.tar/systemcd/umount/sdcardFollow the guide aboveit says the/data direcotry is also needed.But from the init.rcthe init scripts create this directory.So it is not necessary to dump data directory.shutdown the emulatorand copy system.tar outmount-o loop card.img/mnt/sdcardls/mnt/sdcard/-l-r-xr-xr-x 1root root 45923328 2009-01-09 1346 system.tarcp/mnt/sdcard/system.img.umount/mnt/sdcardMake
android filesystem Now we have all the files for
android filesystemsystem.tar dumped from emulatorramdisk.img in emula tor directorytools/lib/images/ mkdir
android_rootfscd
android_rootfsunpack system.tartar xf/
android/system.tarunpack ramdisk.img
Android ram disk image is agziped cpio archive.cp ramdisk.img ramdisk.gzgunzip ramdisk.gzcd
android_rootfscpio-iv./ramdiskNow the
android rootfs contained the files we need.另外还有几个文件需要修改一下init.rc init.goldfish.rc和/system/etc/init.goldfish.sh.这几个文件都是针对goldfish目标板的。
init程序会读这些文件并执行相应的命令。
init程序读取配置文件的时候目标板的名字是通过以下接口获得的cat/proc/cpuinfo ProcessorARMv6-compatible processor rev 4v6l…HardwareNE1 Revision0000上面Hardware就是init使用的目标板的名字。
因此cp init.goldfish.rc init.ne1.rccp/system/etc/init.goldfish.sh/system/etc/init.ne1.sh然后再修改init.rc init.ne1.rc和/system/etc/init.ne1.sh 3.启动
Android可以直接从
Android rootfs里启动也可以先从原有的根文件系统启动然后通过chroot命令切换到
Android文件系统并启动
Android.这里选择后者。
NaviEngine使用NFS因此首先从NFS启动系统然后在切换到
Android文件系统。
这里将
Android文件系统放在USB HardDisk上。
NaviEngine启动完之后通过一下脚本start_
android.sh切换到
Android文件系统----/bin/sh-x echoStarting
Android…mount/dev/sda1/mnt/urm-f/mnt/u/tmp/umount/sys umount/dev/pts umount/proc umask 000 chroot/mnt/u/system/bin/sh----运行该脚本之后进入了
Android的shell注意上面chroot命令后面的参数/system/bin/sh表示切换之后运行该命令启动shell。
最后执行该命令./init initcannot open/initlogo.rleshcant access ttyjob control turned offwarningrilduses 32-bit capabilitieslegacy support in useLCD上出现了
Android文字和
Android的LOGO。
Enjoy it.ps USER PID PPIDVSIZE RSS WCHAN PC NAME root 10 1376500 c003f6e4 40064db0 S/bin/busybox root 20 00 c0051208 00000000 Skthreadd root 32 00 c0041e50 00000000 Sksoftirqd/0 root 42 00 c0061790 00000000 Swatchdog/0 root 52 00 c004e124 00000000 Sevents/0 root 62 00 c004e124 00000000 Skhelper root 101 20 0c004e124 00000000 Skblockd/0 root 112 20 0c 026323c 00000000 Skhubd root 115 20 0c02829a4 00000000 Skseriod root 135 20 0c 0070800 00000000 Spdflush root 136 20 0c 0070800 00000000 Spdflush root 137 20 0c 007531c 00000000 Skswapd0 root 139 20 0c004e124 00000000 Saio/0 root 140 20 0c004e124 00000000 Snfsiod root 142 20 0c004e124 00000000 Sxfs_mru_cache root 143 20 0c004e124 00000000 Sxfslogd/0 root 144 20 0c004e124 00000000 Sxfsdatad/0 root 357 20 0c004e124 00000000 Skpsmoused root 359 20 0c004e124 00000000 Skstriped root 362 20 0c004e124 00000000 Shid_compat root 386 20 0c004e124 00000000 Srpciod/0 root 443 12192232 c009dbf0 4012fb34 S/devel/us r/in/telnetd root 452 11364500 c003f6e4 40064db0 S/bin/ash root 456 20 0c 0252278 00000000 Sscsi_eh_1 root 457 20 0c027ba3c 00000000 Su-storage root 472 452 28401292 c003f6e4 40125778 S/bin/sh root 478 472 708 320 c003f6e4 afe0d0dc S/system/bin/sh root 479 478 288 196 c009d69c 0000c58c S./init root 733 479 740 332 c003f6e4 afe0d0dc S/system/bin/sh system 734 479 812 268 c0240428 afe0c33c S/system/bin/servicemanager root 735 479 1848356 ffffffff afe0c09c S/system/bin/mountd root 736 479 668 268 c02b0220 afe0cccc S/system/bin/debuggerd radio 737 479 3276616 ffffffff afe0c9ac S/system/bin/rild root 738 479 70640 18848 c009dbf0 afe0c464 Szygote media 739 479 17828 3476ffffffff afe0c33c S/system/bin/mediaserver bluetooth 740 479 1168572 c009d69c afe0d2ac S/system/bin/dbus-daemon root 741 479 804 312 c0309e6c afe0c09c S/system/bin/installd system 755 738 174828 27052 ffffffff afe0c33c Ssystem_server radio 793 738 101896 17776 ffffffff afe0d434 Scom.
android.phone app_3 797 738 115224 23304 ffff ffff afe0d434 Sandroid.process.acore app_21 808 738 92532 14636 ffffffff afe0d434 Scom.example.
android.softkeyboard app_7 824 738 96228 15628 ffffffff afe0d434 Scom.
android.mms app_0 837 738 92768 14784 ffffffff afe0d434 Scom.
android.alarmclock app_25 846 738 95016 14920 ffffffff afe0d434 Sandroid.process.im app_22 853 738 95016 16244 ffffffff afe0d434 Scom.
android.calendar app_2 867 738 94960 15668 ffffffff afe0d434 Sandroid.process.media root 882 733 888 348 00000000 afe0c09c Rps也可以通过logcat命令查看系统log。