移植Android时关于Linux中MACHINE_START的一点探讨

来源:互联网 发布:苹果mac怎么下视频 编辑:程序博客网 时间:2024/05/21 04:42

在嵌入式Linux中内核移植产品代码分支时往往会遇到以下一个内核代码结构:

MACHINE_START(OPT, "OMAP4 opmex tablet")/* Maintainer: Vincent - SUNSEA OPMEX */.boot_params= 0x80000100,.reserve= omap_tablet_reserve,.map_io= omap_tablet_map_io,.init_early= omap_tablet_init_early,.init_irq= gic_init_irq,.init_machine= omap_tablet_init,.timer= &omap_timer,MACHINE_END
其实上面就是为产品定义产品ID(OPT),和平台名称(“OMAP4 opmex tablet”),移植Linux系统中重要的io静态映射、中断、定时器等等。

本文主要想探讨一下产品平台名称(”OMAP4 opt“)对移植Android的影响。

首先是简单介绍自己移植Android的一点过程(针对Android 4.0.4,4.0以上的Android几乎是如此的):

参考demo,

1.新建一个产品目录,在Android目录device/"厂商"/”产品名称“,这里我是新建device/ti/opmex_tablet,没错opmex_tablet 就是产品代号。

2.拷贝demo中的文件过来,比如这里我是拷贝TI blaze平板中的文件过来。拷贝device/ti/blaze_tablet 中的文件到device/ti/opmex_tablet中。

3.根据实际需要修改刚才拷贝过来的所有文件,将有文件名或文件内容中有”blaze_tablet“字符的信息替换成”opmex_tablet“,需注意两个文件:

a.文件vendorsetup.sh

修改后内容为:

## Copyright (C) 2011 The Android Open Source Project## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at##      http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.#add_lunch_combo full_opmex_tablet-userdebugadd_lunch_combo full_opmex_tablet-useradd_lunch_combo full_opmex_tablet-eng
在编译Android时要导入lunch选项”opmex_tablet-userdebug"或“”opmex_tablet-user“”或“opmex_tablet-eng”。

b.文件init.omap4opt.rc(由文件init.omap4blazeboard.rc所得)。这里只是注意其件名而已。这个文件是Android文件系统的初始化文件。编译时会最终被拷贝到生产的根文件系统下。

完成以上工作后,编译Android。。。

source build/envsetup.sh
lunch full_opmex_tablet-userdebug
make

漫长等待,编译完成烧录启动测试,出现以下启动信息的错误:

[    7.581970] init: Unable to open persistent property directory /data/property errno: 2
[    7.609710] omap-rproc omap-rproc.1: rproc_loader_cont: failed to load ducati-m3.bin
[    7.619110] init: cannot find '/system/bin/servicemanager', disabling 'servicemanager'
[    7.627777] init: cannot find '/system/bin/vold', disabling 'vold'
[    7.634674] HDCP: failed to load keys
[    7.634735] init: cannot find '/system/bin/netd', disabling 'netd'
[    7.634765] init: cannot find '/system/bin/debuggerd', disabling 'debuggerd'
[    7.634765] init: cannot find '/system/bin/rild', disabling 'ril-daemon'
[    7.634796] init: cannot find '/system/bin/surfaceflinger', disabling 'surfaceflinger'
[    7.634796] init: cannot find '/system/bin/app_process', disabling 'zygote'
[    7.634826] init: cannot find '/system/bin/drmserver', disabling 'drm'
[    7.634826] init: cannot find '/system/bin/mediaserver', disabling 'media'
[    7.634857] init: cannot find '/system/bin/dbus-daemon', disabling 'dbus'
[    7.634857] init: cannot find '/system/bin/installd', disabling 'installd'
[    7.634857] init: cannot find '/system/etc/install-recovery.sh', disabling 'flash_recovery'
[    7.634887] init: cannot find '/system/bin/keystore', disabling 'keystore'
[    7.634948] init: cannot find '/system/bin/sh', disabling 'console'
[    8.571044] (stk) : timed out waiting for ldisc to be un-installed
[    8.687591] (stk) :ldisc_install = 1
[    9.844482] (stk) :ldisc installation timeout
[    9.849761] (stk) :ldisc_install = 0
[   11.008575] (stk) : timed out waiting for ldisc to be un-installed
[   11.125152] (stk) :ldisc_install = 1
[   12.281951] (stk) :ldisc installation timeout
[   12.287078] (stk) :ldisc_install = 0
[   13.446014] (stk) : timed out waiting for ldisc to be un-installed

专业判断是sytstem无法mount上,分析怀疑是不是eMMC驱动有问题。。。但是经过对比,发现这部分没做更改,在demo上都是可以的,而且上面的提示出现的原因也有多种多样,网上有人提到可能是目录权限问题,但是作者根据自身的开发对比,觉得不应该是这个问题。

其中这个问题的最终原因是在

MACHINE_START(OPT, "OMAP4 opmex tablet")/* Maintainer: Vincent - SUNSEA OPMEX */.boot_params= 0x80000100,.reserve= omap_tablet_reserve,.map_io= omap_tablet_map_io,.init_early= omap_tablet_init_early,.init_irq= gic_init_irq,.init_machine= omap_tablet_init,.timer= &omap_timer,MACHINE_END
“OMAP4 opmex tablet"这个字符串上,将“OMAP4 opmex tablet"改为”“OMAP4 opt"则成功启动。

又经过漫长的资料查找,没法理解为什么Android和Linux内核有一个这样严重的耦合。。。于是作了一些尝试。

a.将“OMAP4 opmex tablet"改为”“OMAP4 opt",启动OK。

b.将“OMAP4 opmex tablet"改为”“OMAP4 opmex tablet",启动失败。

c.将“OMAP4 opmex tablet"改为”“opmex tablet",启动失败。

d.将“OMAP4 opmex tablet"改为”“opt",启动失败。

还是无法解释,怀疑是不是和上面的init.omap4opt.rc文件名匹配,但是这样的理解是很牵强。

于是观察了Linux内核源代码和Android源码中基于TI OMAP4的所有产品板级代码,

1.blaze:MACHINE_START(OMAP_BLAZE, "OMAP4 blaze board")与device/ti/blaze_tablet及init.omap4blazeboard.rc对应。

2.panda:MACHINE_START(OMAP_PANDA, "OMAP4 panda board")与device/ti/panda及init.omap4pandaboard.rc对应。

3.xxyyzz:MACHINE_START(NHELLO, "OMAP4 xxyyzz")与device/ti/xxyyzz及init.omap4xxyyzz.rc对应。(xxyyzz是一个代号,是第三方的产品,非TI官方的,不方便透露。)


上面启动错误信息知道,在android执行init.xxx.rc时出现失败的,难道是由于名字不匹配导致出现权限问题?但感觉是和这个init.xxx.rc脚本有关,不过最终还是无法知道在TI omap4平台上的Android和Linux内核耦合的原因所在,TI OMAP在天朝的支持不给力。。。so。。