《[信息与通信]Android和linux基础知识笔记分享 有米分享.doc》由会员分享,可在线阅读,更多相关《[信息与通信]Android和linux基础知识笔记分享 有米分享.doc(78页珍藏版)》请在三一办公上搜索。
1、有米手机应用广告(优蜜信息科技) Android和linux基础知识笔记分享试 阅:。内核启动时缺省执行 init 程序,内核将会到/sbin/, /bin/ 等目录下查找默认的init,如果没有找到那么就报告出错。而最后它会去试 /bin/sh (可能在 /etc/rc )。如果说,例如,如果你的 init 程序坏掉了,只要使用 init=/bin/sh这个启动参数就能让你在启动时直接跳到解译环境(shell),使你能够换掉坏掉的程序。ip= 参数nfsaddrs=:ip=192.168.1.101:192.168.1.100:192.168.1.100:255.255.255.0:usb0
2、:onip=192.168.2.175:192.168.2.56:192.168.2.201:255.255.255.0:eth0:on - 板子的ip 使用何种协议端视配置核心时打开的选项以及 参数而定。如果设定此参数,就不会使用反向地址解析协议或启动协议。 - 网络文件系统服务端之互联网地址。 - 网关(gateway), - 本地网络界面的网络掩码。如果为空白,则网络掩码由客户端的互联网地址导出,除非由启动协议接收到值。 - 客户端的域名。如果空白,则使用客户端互联网地址之 ASCII-标记法,或由启动协议接收的值。 - 要使用的网络设备域名。 - 用以作为自动配置的方法。参考文档。正
3、文:Android、linux基础知识总结1. Android编译系统分析2. 文件系统分析3. 制作交叉工具链4. 软件编译常识5. 设置模块流程分析6. linux系统启动流程分析7. linux下svn使用指南8. LFS 相关9. linux 内核的初步理解android系统开发指南(常用环境的搭建和使用)说明:有的步骤会用到脚本简化操作,脚本通过svn服务器获取:svn co svn:/192.168.2.148/smartphone/td0901/release/images/scripts用户名为各位的姓名拼音,密码与用户名相同一 编译android源码,制作文件系统二 ubun
4、tu下烧录内核和文件系统一 编译android源码,制作文件系统1. 开发主线源码位置:svn:/192.168.2.148/smartphone/td0901/trunk/cupcake-jianping /cupcake 源代码svn:/192.168.2.148/smartphone/td0901/trunk/linux-2.6.28-a1 /内核源代码2. 打标的源代码位置svn list svn:/192.168.2.148/smartphone/td0901/tag我们可以通过 svn list svn:/192.168.2.148/smartphone 查看svn版本库内核更多信
5、息请参卡以下文档:http:/192.168.2.148/svn/smartphone/http:/192.168.2.148/svn/smartphone/智能平台开发部资料管理手册V1.0.dochttp:/192.168.2.148/svn/smartphone/linux下svn操作指南及规范.doc用户名为各位的姓名拼音,密码与用户名相同3. 编译源码进入 cupcake 工作拷贝的顶层目录,执行:. ./make_image15.sh部分执行结果:out/target/product/littleton/root/ 内核需要使用的 initramfs out/target/prod
6、uct/littleton/system 文件系统的系统分区out/target/product/littleton/data/ 文件系统数据分区4. 编译内核此处内核编译主要针对驱动组之外的同事1 设置工具链内核的 linux-2.6.28-a1/Makefile 中设定了:CROSS_COMPILE ?= arm-linux-所以设置PATH环境变量,保证能找到正确的工具链假设工具链位于: /usr/local/marvell-arm-linux-4.1.1/ 设置为:export PATH:=/usr/local/marvell-arm-linux-4.1.1/bin/:$PATH2 更
7、改编译选项(网络启动或者本机启动)内核顶层目录执行:make menuconfigGeneral setup - * Initial RAM filesystem and RAM disk (initramfs/initrd) support () Initramfs source file(s) (NEW) 如果需要支持网络启动反选 Initial RAM filesystem and RAM disk (initramfs/initrd) support如果需要支持本地启动选中 * Initial RAM filesystem and RAM disk (initramfs/initrd)
8、 support设置 () Initramfs source file(s) (NEW) 为 root拷贝 cupcake 编译结果 out/target/product/littleton/root/ 到内核顶层目录3 编译内核顶层目录执行 make zImage编译好的内核:arch/arm/boot/zImage5. 搭建网络开发环境1 安装nfs服务器sudo apt-get install nfs-kernel-server nfs-common2 修改nfs服务器配置文件/etc/exports ,确保有以下配置项/nfsroot/rootfs *(rw,no_root_squas
9、h,sync)我们在内核中已经固定,手机通过网络方式启动,默认从 /nfsroot/rootfs 读取文件系统,修改配置项后需要重启nfs服务器:sudo /etc/init.d/nfs-kernel-server restart3 配置网络根文件系统拷贝 out/target/product/littleton/root/ 内容到 /nfsroot/rootfs 目录拷贝 out/target/product/littleton/system 内容到 /nfsroot/rootfs/system修改 /nfsroot/rootfs/init.rc 去掉几个mount命令 为了使大家的过程,结
10、果统一,可以使用脚本 mkfs.cupcake 完成 在执行 mkfs.cupcake.nfs 脚本前先到 cupcake-jianping 目录下执行: . ./make_env15.sh设置环境变量,获取通过手动输入android源码的位置,让脚本来设置环境变量。二 ubuntu下烧录内核和文件系统1. 硬件: 手机一台usb转串口线一根usb转网卡线一根2. 软件环境1 tftp 服务器执行脚本: setup_tftpd.sh 安装和配置tftp服务器,我们默认以 /tftpboot 为 tftp服务器的根目录,需要下载的文件都放在该目录下。2 获取待烧录的镜像文件svn list sv
11、n:/192.168.2.148/smartphone/td0901/release/images 查看服务器上的版本情况,通常我们下载最新的,例如,下载9月18号发布的版本:svn co svn:/192.168.2.148/smartphone/td0901/release/images/images200909183 烧录镜像文件用以下文件为例,示范通过tftp烧写内核和文件系统内核 zImage0917 系统分区: system0918.img 数据分区 data0918.img 待烧写的以上文件必须存在于tftp服务器根目录/tftpboot下。具体步骤:首先连接好硬件设备进入blo
12、b下载模式1 blob 起来后按任意键Processing obm parameters.Cant detect micco. Set PMIC as normal I2C mode.NAND flash(Manu=0x98 Device=0xba) detected!Slot 0 Foundget relocation tableFound Main Bad block table at address 0x0f000000, version 0x01Found Mirror Bad block table at address 0x0efc0000, version 0x01Conside
13、r yourself BLOBed!blob version 2.0.5-pre3 for Marvell LittletonCopyright (C) 1999 2000 2001 2002 2003 Jan-Derk Bakker and Erik Mouwblob comes with ABSOLUTELY NO WARRANTY; read the GNU GPL for details.This is free software, and you are welcome to redistribute itunder certain conditions; read the GNU
14、GPL for details.length not align with page size, change to 0x0Read flash from 0x60000, length 0x0DoneAutoboot (2 seconds) in progress, press any key to stop .Autoboot abortedType help to get a list of commandsblob 2 通过 tftp 下载内核到pc内存 0x80800000 地址处 blob tftp zImage0917Begin init ether usbnet!* Plug-
15、in USB cable & config usbdnet now * exit check_usb_connection:1TFTPing zImage0917* OK.received 6144 blocks (3145156 bytes)tftp_cmd: file zImage0917 loaded via tftp to address 0x80800000.3 擦除原来的内核分区,0x100000 为分区起始地址,0x300000为分区长度blob nanderase -z 0x100000 0x400000the current NAND chip does not suppor
16、t Block Unlocking.Erase 0x300000 length data from flash: 0x100000Erase flash from 0x100000, length 0x300000.Done4 烧写内存 0x80800000 开始 实际长度为 3145156 的内核数据到起始地址为 0x100000 的内核分区blob nandwrite -z 0x80800000 0x100000 3145156the current NAND chip does not support Block Unlocking.Write 0x2ffdc4 length data
17、from RAM: 0x80800000 to flash: 0x100000Write flash from 0x100000, length 0x2ffdc4Erase flash from 0x100000, length 0x300000.Done.Done5 下载系统分区镜像文件到pc内存 0x80800000 地址处 blob tftp system0918.imgTFTPing system0918.img* OK.received 113138 blocks (57925824 bytes)tftp_cmd: file system0918.img loaded via tft
18、p to address 0x80800000.6 擦除原来的flash系统分区blob nanderase -z 0x500000 0x4000000the current NAND chip does not support Block Unlocking.Erase 0x3e0f800 length data from flash: 0x400000Erase flash from 0x400000, length 0x3e0f800.Done7 烧写数据到flash系统分区blob nandwrite -y 0x80800000 0x500000 57925824the current
19、 NAND chip does not support Block Unlocking.Write 0x373e0c0 length data from RAM: 0x80800000 to flash: 0x400000Write flash from 0x400000, length 0x3591800Erase flash from 0x400000, length 0x3591800.Done.Done8 下载数据分区镜像文件到pc内存 0x80800000 地址处 blob tftp data0918.imgTFTPing data0918.img* OK.received 3399
20、2 blocks (17402880 bytes)tftp_cmd: file data0918.img loaded via tftp to address 0x80800000.blob 9 擦除原来的flash数据分区blob nanderase -z 0x4500000 0xBB00000the current NAND chip does not support Block Unlocking.Erase 0xa81f000 length data from flash: 0x4400000Erase flash from 0x4400000, length 0xa81f000.Do
21、ne10 烧写数据镜像到flash数据分区blob nandwrite -y 0x80800000 0x4500000 17402880the current NAND chip does not support Block Unlocking.Write 0x1098c00 length data from RAM: 0x80800000 to flash: 0x4400000Write flash from 0x4400000, length 0x1018000Erase flash from 0x4400000, length 0x1018000.Done.Doneblob flash分
22、区图:* * * * * blob * kernel * system * data * * * * *nanderase -z 0x100000 0x400000tftp zImagenandwrite -z 0x80800000 0x100000 烧写system.img:nanderase -z 0x500000 0x4000000tftp system.imgnandwrite -y 0x80800000 0x500000 烧写 userdata.img :nanderase -z 0x4500000 0xBB00000tftp userdata.imgnandwrite -y 0x8
23、0800000 0x4500000 涉及的内容:svn服务器的使用android的编译系统,原理,工具链,辅助工具,参数等,环境变量,怎样单独添加编译一个单独的模块等。android 的编译结果:文件系统分析文件系统的使用,启动流程设置模块流程分析1. Android编译系统分析编译脚本及系统变量build/envsetup.sh脚本分析在编译源代码之前通常需要在android源代码顶层目录执行 . ./build/envsetup.sh 目的是为了使用脚本 envsetup.sh 里面定义了一些函数:function help()function get_abs_build_var()fun
24、ction get_build_var()function check_product()function check_variant()function setpaths()function printconfig()function set_stuff_for_environment()function set_sequence_number()function settitle()function choosetype()function chooseproduct()function choosevariant()function tapas()function choosecombo
25、()function print_lunch_menu()function lunch()function gettopfunction m()function findmakefile()function mm()function mmm()function croot()function pid()function gdbclient()function jgrep()function cgrep()function resgrep()function getprebuiltfunction tracedmdump()function runhat()function getbugrepo
26、rts()function startviewserver()function stopviewserver()function isviewserverstarted()function smoketest()function runtest()function runtest_py()function godir ()choosecombo 命令分析:function choosecombo() choosesim $1 echo echo choosetype $2 echo echo chooseproduct $3 echo echo choosevariant $4 echo se
27、t_stuff_for_environment printconfig会依次进行如下选择:Build for the simulator or the device? 1. Device 2. SimulatorWhich would you like? 1 Build type choices are: 1. release 2. debugWhich would you like? 1 Product choices are: 1. emulator 2. generic 3. sim 4. littletonYou can also type the name of a product
28、if you know it.Which would you like? littleton Variant choices are: 1. user 2. userdebug 3. engWhich would you like? eng user默认选择以后会出现:TARGET_PRODUCT=littletonTARGET_BUILD_VARIANT=userTARGET_SIMULATOR=falseTARGET_BUILD_TYPE=releaseTARGET_ARCH=armHOST_ARCH=x86HOST_OS=linuxHOST_BUILD_TYPE=releaseBUILD
29、_ID=function chooseproduct()函数分析:choices=(/bin/ls build/target/board/*/BoardConfig.mk vendor/*/*/BoardConfig.mk 2 /dev/null)读取 build/target/board/* 目录下的板配置文件:BoardConfig.mk读取 vendor/*/*/目录下的板配置文件:BoardConfig.mkchoices 的值为:build/target/board/emulator/BoardConfig.mkbuild/target/board/generic/BoardConf
30、ig.mkbuild/target/board/sim/BoardConfig.mkvendor/marvell/littleton/BoardConfig.mk经过: for choice in $choices do # The product name is the name of the directory containing # the makefile we found, above. prodlist=($prodlist dirname $choice | xargs basename) done的处理,prodlist的值为:emulator generic sim lit
31、tleton所以选择菜单为:Product choices are: 1. emulator 2. generic 3. sim 4. littleton如果选择 4,那么 TARGET_PRODUCT 被赋值为: littleton。board_config_mk := $(strip $(wildcard $(SRC_TARGET_DIR)/board/$(TARGET_DEVICE)/BoardConfig.mk vendor/*/$(TARGET_DEVICE)/BoardConfig.mk )怎样添加一个模块LOCAL_PATH:= $(call my-dir)#编译静态库inclu
32、de $(CLEAR_VARS)LOCAL_MODULE = libhellosLOCAL_CFLAGS = $(L_CFLAGS)LOCAL_SRC_FILES = hellos.cLOCAL_C_INCLUDES = $(INCLUDES)LOCAL_SHARED_LIBRARIES := libcutilsLOCAL_COPY_HEADERS_TO := libhellosLOCAL_COPY_HEADERS := hellos.hinclude $(BUILD_STATIC_LIBRARY)#编译动态库include $(CLEAR_VARS)LOCAL_MODULE = libhel
33、lodLOCAL_CFLAGS = $(L_CFLAGS)LOCAL_SRC_FILES = hellod.cLOCAL_C_INCLUDES = $(INCLUDES)LOCAL_SHARED_LIBRARIES := libcutilsLOCAL_COPY_HEADERS_TO := libhellodLOCAL_COPY_HEADERS := hellod.hinclude $(BUILD_SHARED_LIBRARY)BUILD_TEST=trueifeq ($(BUILD_TEST),true)#使用静态库include $(CLEAR_VARS)LOCAL_MODULE := he
34、llosLOCAL_STATIC_LIBRARIES := libhellosLOCAL_SHARED_LIBRARIES :=LOCAL_LDLIBS += -ldlLOCAL_CFLAGS := $(L_CFLAGS)LOCAL_SRC_FILES := mains.cLOCAL_C_INCLUDES := $(INCLUDES)include $(BUILD_EXECUTABLE)#使用动态库include $(CLEAR_VARS)LOCAL_MODULE := hellodLOCAL_MODULE_TAGS := debugLOCAL_SHARED_LIBRARIES := libc
35、 libcutils libhellodLOCAL_LDLIBS += -ldlLOCAL_CFLAGS := $(L_CFLAGS)LOCAL_SRC_FILES := maind.cLOCAL_C_INCLUDES := $(INCLUDES)include $(BUILD_EXECUTABLE)endif # ifeq ($(WPA_BUILD_SUPPLICANT),true)#local_target_dir := $(TARGET_OUT)/etc/wifi#include $(CLEAR_VARS)#LOCAL_MODULE := wpa_supplicant.conf#LOCA
36、L_MODULE_TAGS := user#LOCAL_MODULE_CLASS := ETC#LOCAL_MODULE_PATH := $(local_target_dir)#LOCAL_SRC_FILES := $(LOCAL_MODULE)#include $(BUILD_PREBUILT)#系统变量解析LOCAL_MODULE 编译的目标对象LOCAL_SRC_FILES 编译的源文件LOCAL_C_INCLUDES 需要包含的头文件目录LOCAL_SHARED_LIBRARIES 链接时需要的外部库LOCAL_PRELINK_MODULE 是否需要prelink处理BUILD_SHARED_LIBRARY 指明要编译成动态库LOCAL_PATH - 编译时的目录$(call 目录,目录.) 目录引入操作符如该目录下有个文件夹名称 src,则可以这样写 $(call src),那么就会得到 src 目