A33_Vstar的Android的编译过程(一)

根据A33_Vstar_Android_SDK开发手册进行编译后,结果在A33-Vstar/lichee/out目录下

out
└── sun8iw5p1
    └── android
        └── common
            ├── arisc
            ├── bImage
            ├── boot.img
            ├── buildroot
            ├── lib
            ├── rootfs.cpio.gz
            ├── uImage
            ├── vmlinux.tar.bz2
            └── zImage

bImage 是压缩的内核映像,zImage与bImage两种方式引导的系统运行时是相同的。当内核比较小,采用zImage或bImage之一。当内核比较大,采用bImage,不能采用zImage。
ubildroot 中的external-toolchain是交叉编译工具链
lib 下面的modules是摄像头驱动模块
uImage U-boot专用的映像文件,它是在zImage之前加上一个长度为0x40的tag
rootfs.cpio.gz 是一个Linux内核空实例的磁带备份文件。
zImage 是vmlinux经过gzip压缩后的文件。
arisc 是一个APK的二进制资源文件,
vmlinux.tar.bz2 是未压缩的内核(vmlinuz是vmlinux的压缩文件)
boot.img 包括boot.img header、kernel以及ramdisk文件系统。

编译好了uboot以及内核文件镜像,唯一缺少的就是根文件系统rootfs了接下来我们分析一波android源码的编译

首先我们看下官方给的编译步骤
. build/enbsetup.sh注意.后面有个空格,这个.命令就是source命令
$ . build/envsetup.sh #导入环境变量
$ lunch #选择工程
$ extract-bsp #拷贝内核和模块到 android 中
$ make -j8 #多线程编译

/A33-Vstar/android# . build/envsetup.sh 
including device/softwinner/vstar/vendorsetup.sh
including device/softwinner/astar-y3/vendorsetup.sh
including device/softwinner/polaris-common/vendorsetup.sh
including device/softwinner/vstar-4/vendorsetup.sh
including device/lge/mako/vendorsetup.sh
including device/lge/hammerhead/vendorsetup.sh
including device/asus/tilapia/vendorsetup.sh
including device/asus/deb/vendorsetup.sh
including device/asus/flo/vendorsetup.sh
including device/asus/grouper/vendorsetup.sh
including device/samsung/manta/vendorsetup.sh
including device/generic/x86/vendorsetup.sh
including device/generic/armv7-a-neon/vendorsetup.sh
including device/generic/mips/vendorsetup.sh
including sdk/bash_completion/adb.bash

按照编译顺序我可以看下build下的envsetup.sh的脚本文件

分析envsetup.sh的脚本

打开后我们大概看一遍有很多函数,
从第一个函数,可以看出这个脚本主要做的事情,
第一行 cat <<EOF 可避免使用多行echo命令的方式,并实现多行输出的结果

第十九行 调用另外一个函数gettop获得Android源码的根目录T(/bin/pwd) 环境变量,值为当前目录

第二十二行 通过cat命令显示一个Here Document,说明 /build/envsetup.sh文件加载到当前终端后并提供主要命令
通过sed命令解析 /build/envsetup.sh文件,并且获得当前目录在里面定义的所有函数的名称,这些函数名称就是$T/build/envsetup.sh文件加载到当前终端后并提供所有命令。
它表示对所有以“function ”开头的行,如果紧接在“function ”后面的字符串仅由字母a-z和下划线_组成,那么就将这个字符串提取出来。
这正好就对应于shell脚本里面函数的定义获取当前envsetup.sh脚本通过cat显示出“function ”开头的行,后面的字符串仅由字母a-z和下划线_ 组成的字符串,显示到当前终端
sort命令是管排序的

function hmm() {
cat <<EOF
Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
- lunch:   lunch <product_name>-<build_variant>
- tapas:   tapas [<App1> <App2> ...] [arm|x86|mips|armv5] [eng|userdebug|user]
- croot:   Changes directory to the top of the tree.
- m:       Makes from the top of the tree.
- mm:      Builds all of the modules in the current directory, but not their dependencies.
- mmm:     Builds all of the modules in the supplied directories, but not their dependencies.
- mma:     Builds all of the modules in the current directory, and their dependencies.
- mmma:    Builds all of the modules in the supplied directories, and their dependencies.
- cgrep:   Greps on all local C/C++ files.
- jgrep:   Greps on all local Java files.
- resgrep: Greps on all local res/*.xml files.
- godir:   Go to the directory containing a file.

Look at the source to view more functions. The complete list is:
EOF
    T=$(gettop)
    local A
    A=""
    for i in `cat $T/build/envsetup.sh | sed -n "/^function /s/function \([a-z_]*\).*/\1/p" | sort`; do
      A="$A $i"
    done
    echo $A
}

抛开定义的函数到文件结尾处有一段代码

# Execute the contents of any vendorsetup.sh files we can find.
for f in `test -d device && find device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null` \
         `test -d vendor && find vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null`
do
    echo "including $f"
    . $f
done
unset f

#调用addcompletions函数设置基于sdk/bash_completion的补全功能
addcompletions

这个for循环依次查找{device, vendor, product}目录下的vendorsetup.sh文件,对查找到的vendorsetup.sh文件执行"."操作,将其内容加载到当前终端。
vendor和device相应子目录下的vendorsetup.sh文件的实现很简单。
vendorsetup.sh里面调用add_lunch_combo添加编译选项 比如再device下面查看

device
├── astar-y3
├── polaris-common
├── vstar
└── vstar-4

首先我们可以打开其中的一个vstar可以看到有一个vendorsetup.sh脚本文件,这个脚本文件只有两句话

#  vstar是我义的产品的名字,eng是产品的编译类型 eng: 工程机,user:最终用户机
add_lunch_combo vstar-eng
add_lunch_combo vstar-user

它调用函数add_lunch_combo添加名称为“ vstar-eng”和vstar-user的菜单项到Lunch菜单去。

分析一下如何被编译到Lunch中去
function add_lunch_combo()            # 添加lunch项目

# Clear this variable.  It will be built up again when the vendorsetup.sh
# files are included at the end of this file.
unset LUNCH_MENU_CHOICES
function add_lunch_combo()
{
    local new_combo=$1
    local c
    #LUNCH_MENU_CHOICES[@]表示LUNCH_MENU_CHOICES的所有元素
    for c in ${LUNCH_MENU_CHOICES[@]} ; do
        if [ "$new_combo" = "$c" ] ; then
            return
        fi
    done
    
    LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
}

# add the default one here
add_lunch_combo aosp_arm-eng
add_lunch_combo aosp_x86-eng
add_lunch_combo aosp_mips-eng
add_lunch_combo vbox_x86-eng

在 vendorsetup.sh 中 add_lunch_combo 的参数保存在 $1 中,经过 local new_combo=$1 又把参数保存在new_combo中,用来表示提供的编译选项参数添加到 lunch 菜单选项中,然后在列表LUNCH_MENU_CHOICES 中检查要添加 new_combo的参数菜单是否存在,如果不存在就会添加到列表LUNCH_MENU_CHOICES 中去

unset LUNCH_MENU_CHOICES

列表LUNCH_MENU_CHOICES是定义在文件build/envsetup.sh的一个全局变量
当文件build/envsetup.sh被加载的时候,这个列表会被初始化为化aosp_arm-eng、aosp_x86-eng、aosp_mips-eng和vbox_x86-eng,如下所示:

# add the default one here
add_lunch_combo aosp_arm-eng
add_lunch_combo aosp_x86-eng
add_lunch_combo aosp_mips-eng
add_lunch_combo vbox_x86-eng
root@ubuntu:/home/jia/A33-Vstar/android# lunch

You're building on Linux

Lunch menu... pick a combo:
     1. aosp_arm-eng
     2. aosp_x86-eng
     3. aosp_mips-eng
     4. vbox_x86-eng
     5. vstar-eng
     6. vstar-user
     7. astar_y3-eng
     8. astar_y3-user
     9. vstar-4-eng
     10. vstar-4-user
     11. aosp_mako-userdebug
     12. aosp_hammerhead-userdebug
     13. aosp_tilapia-userdebug
     14. aosp_deb-userdebug
     15. aosp_flo-userdebug
     16. aosp_grouper-userdebug
     17. aosp_manta-userdebug
     18. mini_x86-userdebug
     19. mini_armv7a_neon-userdebug
     20. mini_mips-userdebug

当文件build/envsetup.sh加载完毕之后,列表LUNCH_MENU_CHOICES就包含了当前源码所支持的所有设备型号。

  • 分析lunch命令过程和
  • lichee的编译过程
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值