分享

android linux基础知识总结[上]

 shaobin0604@163.com 2011-09-06
===================================================
linux ,Android基础知识总结
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/r ... es/scripts
用户名为各位的姓名拼音,密码与用户名相同
一 编译android源码,制作文件系统
二 ubuntu下烧录内核和文件系统
一 编译android源码,制作文件系统
1. 开发主线源码位置:
svn://192.168.2.148/smartphone/td0901/t ... e-jianping //cupcake 源代码
svn://192.168.2.148/smartphone/td0901/t ... -2.6.28-a1 //内核源代码
2. 打标的源代码位置
svn list svn://192.168.2.148/smartphone/td0901/tag
我们可以通过 svn list svn://192.168.2.148/smartphone 查看svn版本库内核
更多信息请参卡以下文档:
http://192.168.2.148/svn/smartphone/
http://192.168.2.148/svn/smartphone/智能平台开发部资料管理手册V1.0.doc
http://192.168.2.148/svn/smartphone/linux下svn操作指南及规范.doc
用户名为各位的姓名拼音,密码与用户名相同
3. 编译源码
进入 cupcake 工作拷贝的顶层目录,执行:
. ./make_image15.sh
部分执行结果:
out/target/product/littleton/root/ 内核需要使用的 initramfs 
out/target/product/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/:$PATH
2> 更改编译选项(网络启动或者本机启动)
内核顶层目录执行:
make menuconfig
General 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) support
设置 () Initramfs source file(s) (NEW) 为 root
拷贝 cupcake 编译结果 out/target/product/littleton/root/ 到内核顶层目录
3> 编译
内核顶层目录执行 make zImage
编译好的内核:
arch/arm/boot/zImage
5. 搭建网络开发环境
1> 安装nfs服务器
sudo apt-get install nfs-kernel-server nfs-common
2> 修改nfs服务器配置文件/etc/exports ,确保有以下配置项
/nfsroot/rootfs *(rw,no_root_squash,sync)
我们在内核中已经固定,手机通过网络方式启动,默认从 /nfsroot/rootfs 
读取文件系统,修改配置项后需要重启nfs服务器:
sudo /etc/init.d/nfs-kernel-server restart
3> 配置网络根文件系统
拷贝 out/target/product/littleton/root/ 内容到 /nfsroot/rootfs 目录
拷贝 out/target/product/littleton/system 内容到 /nfsroot/rootfs/system
修改 /nfsroot/rootfs/init.rc 去掉几个mount命令 
为了使大家的过程,结果统一,可以使用脚本 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 svn://192.168.2.148/smartphone/td0901/release/images 查看服务器上的
版本情况,通常我们下载最新的,例如,下载9月18号发布的版本:
svn co svn://192.168.2.148/smartphone/td0901/r ... es20090918
3> 烧录镜像文件
用以下文件为例,示范通过tftp烧写内核和文件系统
内核 zImage0917 
系统分区: system0918.img 
数据分区 data0918.img 
待烧写的以上文件必须存在于tftp服务器根目录/tftpboot下。
具体步骤:
首先连接好硬件设备进入blob下载模式
1> blob 起来后按任意键
Processing obm parameters...
Can't detect micco. Set PMIC as normal I2C mode.
NAND flash(Manu=0x98 Device=0xba) detected!
Slot 0 Found
get relocation table
Found Main Bad block table at address 0x0f000000, version 0x01
Found Mirror Bad block table at address 0x0efc0000, version 0x01
Consider yourself BLOBed!
blob version 2.0.5-pre3 for Marvell Littleton
Copyright (C) 1999 2000 2001 2002 2003 Jan-Derk Bakker and Erik Mouw
blob comes with ABSOLUTELY NO WARRANTY; read the GNU GPL for details.
This is free software, and you are welcome to redistribute it
under certain conditions; read the GNU GPL for details.
length not align with page size, change to 0x0
Read flash from 0x60000, length 0x0
Done
Autoboot (2 seconds) in progress, press any key to stop ..
Autoboot aborted
Type "help" to get a list of commands
blob> 
2> 通过 tftp 下载内核到pc内存 0x80800000 地址处 
blob> tftp zImage0917
Begin init ether usbnet!!!
***** Plug-in USB cable & config usbdnet now ****** 
exit check_usb_connection:1
TFTPing zImage0917*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ OK.
received 6144 blocks (3145156 bytes)
tftp_cmd: file 'zImage0917' loaded via tftp to address 0x80800000.
3> 擦除原来的内核分区,0x100000 为分区起始地址,0x300000为分区长度
blob> nanderase -z 0x100000 0x400000
the current NAND chip does not support Block Unlocking.
Erase 0x300000 length data from flash: 0x100000
Erase flash from 0x100000, length 0x300000
........................Done
4> 烧写内存 0x80800000 开始 实际长度为 3145156 的内核数据到起始地址为 0x100000 的内核分区
blob> nandwrite -z 0x80800000 0x100000 3145156
the current NAND chip does not support Block Unlocking.
Write 0x2ffdc4 length data from RAM: 0x80800000 to flash: 0x100000
Write flash from 0x100000, length 0x2ffdc4
Erase flash from 0x100000, length 0x300000
........................Done
........................Done
5> 下载系统分区镜像文件到pc内存 0x80800000 地址处 
blob> tftp system0918.img
TFTPing system0918.img*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ OK.
received 113138 blocks (57925824 bytes)
tftp_cmd: file 'system0918.img' loaded via tftp to address 0x80800000.
6> 擦除原来的flash系统分区
blob> nanderase -z 0x500000 0x4000000
the current NAND chip does not support Block Unlocking.
Erase 0x3e0f800 length data from flash: 0x400000
Erase flash from 0x400000, length 0x3e0f800
...................................................................................
...................................................................................
...................................................................................
..........................Done
7> 烧写数据到flash系统分区
blob> nandwrite -y 0x80800000 0x500000 57925824
the current NAND chip does not support Block Unlocking.
Write 0x373e0c0 length data from RAM: 0x80800000 to flash: 0x400000
Write flash from 0x400000, length 0x3591800
Erase flash from 0x400000, length 0x3591800
....................................................................................
.....................................................................................
................................................................................Done
....................................................................................
....................................................................................
................................................................Done
8> 下载数据分区镜像文件到pc内存 0x80800000 地址处 
blob> tftp data0918.img
TFTPing data0918.img*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ OK.
received 33992 blocks (17402880 bytes)
tftp_cmd: file 'data0918.img' loaded via tftp to address 0x80800000.
blob> 
9> 擦除原来的flash数据分区
blob> nanderase -z 0x4500000 0xBB00000
the current NAND chip does not support Block Unlocking.
Erase 0xa81f000 length data from flash: 0x4400000
Erase flash from 0x4400000, length 0xa81f000
.....................................................................................
.....................................................................................
.....................................................................................
.....................................................................................
...................................................Done
10> 烧写数据镜像到flash数据分区
blob> nandwrite -y 0x80800000 0x4500000 17402880
the current NAND chip does not support Block Unlocking.
Write 0x1098c00 length data from RAM: 0x80800000 to flash: 0x4400000
Write flash from 0x4400000, length 0x1018000
Erase flash from 0x4400000, length 0x1018000
..................................................................................Done
..................................................................................Done
blob> 
flash分区图:
*******************************************
* * * * *
* blob * kernel * system * data *
* * * * *
*******************************************
nanderase -z 0x100000 0x400000
tftp zImage
nandwrite -z 0x80800000 0x100000 
烧写system.img:
nanderase -z 0x500000 0x4000000
tftp system.img
nandwrite -y 0x80800000 0x500000 
烧写 userdata.img :
nanderase -z 0x4500000 0xBB00000
tftp userdata.img
nandwrite -y 0x80800000 0x4500000 
============================
涉及的内容:
svn服务器的使用
android的编译系统,原理,工具链,辅助工具,参数等,环境变量,怎样单独添加编译一个单独的模块等。
android 的编译结果:文件系统分析
文件系统的使用,启动流程
设置模块流程分析
============================
====================================================
1. Android编译系统分析
编译脚本及系统变量
build/envsetup.sh脚本分析
在编译源代码之前通常需要在android源代码顶层目录执行 . ./build/envsetup.sh 目的是为了使用
脚本 envsetup.sh 里面定义了一些函数:
function help()
function get_abs_build_var()
function 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()
function print_lunch_menu()
function lunch()
function gettop
function m()
function findmakefile()
function mm()
function mmm()
function croot()
function pid()
function gdbclient()
function jgrep()
function cgrep()
function resgrep()
function getprebuilt
function tracedmdump()
function runhat()
function getbugreports()
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
set_stuff_for_environment
printconfig
}
会依次进行如下选择:
Build for the simulator or the device?
1. Device
2. Simulator
Which would you like? [1] 
Build type c

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多