• Android移植busybox


    Android 的toolbox没有自动补齐,命令少,对于开发人员还是需要busybox,直接移植官方的busybox会有很多问题,主要是因为基于Android的交叉编译工具并没有采用glibc作为C库,而是采用了Google自己开发的Bionic Libc,它的官方Toolchain也是基于Bionic Libc而并非glibc的。
    与glibc相比,Bionic Libc有如下一些特点:
    1> 采用BSD License,而不是glibc的GPL License;
    2> 大小只有大约200k,比glibc差不多小一半,且比glibc更快;
    3> 实现了一个更小、更快的pthread;
    4> 提供了一些Android所需要的重要函数,如”getprop”, “LOGI”等;
    5> 不完全支持POSIX标准,比如C++ exceptions,wide chars等;
    6> 不提供libthread_db 和 libm的实现
    下面简单阐述cyanogenmod提供的针对android bionic 库的android源码的移植及添加方法,方便大家开发使用。

    1. 下载cyanogenmod修改过的busybox源码,并解压到源码external/busybox目录
    位置:https://github.com/CyanogenMod/android_external_busybox
    目录内容如下:

    2.编译、配置busybox并修正编译错误:
    先在android源码根目录执行:source build/envsetup.sh
    进入目录:external/CyanogenMod-android_external_busybox-995d0d3/
    1>.执行meke menuconfig
    Busybox Settings  --->
                  General Configuration  --->
                        [*]   Don't use /usr-->  //要选择此项,不然又部分命令会被安装到_install/usr/bin和_install/usr/sbin, busybox-1.18.0中,这项没有用,不管选择与否都会有部分命令安装到_install/usr/bin和_install/usr/sbin。使用busybox-1.17.0就正常,且此项在Build Options中。
                  Build Options  --->
                        [*] Build BusyBox as a static binary (no shared libs) //使用静态库编译
                            (arm-eabi-) Cross Compiler prefix   //填入交叉编译工具链名,如果不在路径PATH中,可使用绝对路径。
                  Busybox Library Tuning  --->
                        [*]   Tab completion  ->  //检测此项是否选择,如没有选,就不能使用tab键补全,默认是选择的。
    2>.执行source ../../build/envsetup.sh      
    3>.执行:mm(单独编译模块)
    4>.编译错误
    问题1:
    build/core/base_rules.mk:74: *** Module name: libclearsilverregex
    build/core/base_rules.mk:75: *** Makefile location: external/android_external_busybox-gingerbread
    build/core/base_rules.mk:76: *
    build/core/base_rules.mk:77: * Each module must use a LOCAL_MODULE_TAGS in its
    build/core/base_rules.mk:78: * Android.mk. Possible tags declared by a module:
    build/core/base_rules.mk:79: *
    build/core/base_rules.mk:80: *     optional, debug, eng, tests, samples
    build/core/base_rules.mk:81: *
    build/core/base_rules.mk:82: * If the module is expected to be in all builds
    build/core/base_rules.mk:83: * of a product, then it should use the
    build/core/base_rules.mk:84: * "optional" tag:
    build/core/base_rules.mk:85: *
    build/core/base_rules.mk:86: *    Add "LOCAL_MODULE_TAGS := optional" in the
    build/core/base_rules.mk:87: *    Android.mk for the affected module, and add
    build/core/base_rules.mk:88: *    the LOCAL_MODULE value for that component
    build/core/base_rules.mk:89: *    into the PRODUCT_PACKAGES section of product
    build/core/base_rules.mk:90: *    makefile(s) where it's necessary, if
    build/core/base_rules.mk:91: *    appropriate.
    build/core/base_rules.mk:92: *
    build/core/base_rules.mk:93: * If the component should be in EVERY build of ALL
    build/core/base_rules.mk:94: * products, then add its LOCAL_MODULE value to the
    build/core/base_rules.mk:95: * PRODUCT_PACKAGES section of
    build/core/base_rules.mk:96: * build/target/product/core.mk
    build/core/base_rules.mk:97: *
    build/core/base_rules.mk:98: *** user tag detected on new module - user tags are only supported on legacy modules.  Stop.
    解决:在Android.mk中的LOCAL_MODULE := libclearsilverregex和LOCAL_MODULE := libuclibcrpc后添加LOCAL_MODULE_TAGS := optional
    问题2:
    我用git add file添加文件时出现这样错误:
    fatal: Not a git repository (or any of the parent directories): .git
    提示说没有.git这样一个目录,解决办法如下:
    git init就可以了!
    问题3:
    make: *** No rule to make target `out/target/product/generic/obj/lib/***.so', needed by `out/target/product/generic/obj/STATIC_LIBRARIES/***/busybox'.  Stop.
    解决办法:
    在/home/ryan/Android2.2/alps/out/target/product 找到我们的工程名,工程名就是我们编译时出现的project=ti816xevm
    在终端输入命令:export TARGET_PRODUCT=ti816xevm
    问题就解决了

    3.安装、创建busybox shell 链接打包:
    编译通过,依据Android.mk中的变量 LOCAL_MODULE_PATH := $(PRODUCT_OUT)/utilities 可知,编译出来目标文件busybox在out/target/product/$(platform_name)/utilities/目录下;
    进入out/target/product/$(platform_name)/utilities/目录下,创建链接便于进入busybox  shell环境,执行:ln -s busybox ash,将busybox 和 ash 一起复制到system/bin/目录下,一起打包进文件系统system.img(链接文件和链接目标文件必须一起打包)

    4.烧录到产品板使用:
    usb 或网络链接adb 之后,adb shell ,之后执行ash 即可进入busybox shell,操作就和pc的linux环境差不多了,可以使用tab键自动补齐,和其他一些busybox的命令;
    也可以通过nfs挂载Android文件系统,直接copy到主机的挂载目录下system/bin/,然后执行ln -s busybox ash, 然后在终端输入ash进入busybox shell, 执行su退出busybox shell环境。

    5.其它编译问题:
    另外,有网友在编译过程中出现其它问题,这里也一并列具出来,供参考;
    问题1描述:In file included from external/busybox/coreutils/df.c:25: bionic/libc/include/mntent.h:48: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'struct'
    解决方法:在出错的文件中,包含头文件stdio.h。
    例如在df.c中增加#include <stdio.h>
    类似的编译出错的文件可能会有:coreutile/df.c util-linux/mount.c util-linux/umount.c
    问题2描述: external/busybox/shell/ash.c:12714: error: 'rlim_t' undeclared (first use in this function)
    原因分析:使用的是早期的Android版本,其中rlim_t没有定义。
    解决方法:在bionic/libc/include/sys/resource.h中增加
    typedef unsigned long rlim_t; 
    typedef unsigned long rlim_t;
    可以参考Froyo bionic/libc/include/sys/resource.h文件。
    问题3描述:busybox/networking/ntpd.c:1458: undefined reference to `adjtimex' 
    出错原因:bionic中没有定义adjtimex,stime,swapon,swapoff,sysinfo,getsid等函数。
    解决方法:修改Android.mk,增加 CYANOGEN_BIONIC:=true

    参考:http://blog.csdn.net/sustzombie/article/details/6763791

  • 相关阅读:
    「luogu2350」[HAOI2012] 外星人
    「csp校内训练 20191030」解题报告
    「csp校内训练 20191025」解题报告
    「2019纪中集训Day23」解题报告
    「luogu3974」[TJOI2015] 组合数问题
    「csp校内训练 20191106」解题报告
    「csp校内训练 20191024」解题报告
    「NOI2019d2t1」弹跳
    「2019纪中集训Day21」解题报告
    「csp校内训练 20191104」解题报告
  • 原文地址:https://www.cnblogs.com/cslunatic/p/3196014.html
Copyright © 2020-2023  润新知