android驱动学习(2)

1,uboot编译:
    tar -xvf uboot-fs210_V5.tar.bz2
    
    
    a,设置交叉工具链
        ifeq ($(ARCH),arm)
            CROSS_COMPILE =/opt/toolchain/toolchain-4.3.2-farsight/bin/arm-none-linux-gnueabi-
        endif
        
    b,选择一个开发板(选择特定源码进行编译)
        make fs210_nand_config
            Configuring for fs210_nand board...
                
                实际是执行了:
                    fs210_nand_config :     unconfig
                        @$(MKCONFIG) $(@:_config=) arm s5pc11x fs210 samsung s5pc110
                        @echo "TEXT_BASE = 0x23e00000" > $(obj)board/samsung/fs210/config.mk

    c,make -j2
    
    最终会生成u-boot.bin
    
    
2, 编译内核:
        tar -xvf linux-3.0.8-FS210.tar.bz2
        
    a,设置交叉工具链    
         195 ARCH            ?= arm
        196 CROSS_COMPILE   ?= /opt/toolchain/toolchain-4.5.1-farsight/bin/arm-none-linux-gnueabi-
    
    b,选择一个soc  
        cp -raf config_for_FS210_Android_v1.0  .config
    
    c,make menuconfig (必须做)
        
        
            //修改mac地址
            vim arch/arm/mach-s5pv210/mach-fs210.c
                static struct dm9000_plat_data fs210_dm9000_platdata = {
                        .flags          = DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM,
                        .dev_addr       = { 0x00, 0x09, 0xc2, 0xff, 0xec, 0x2b },//保持唯一
                };

                
    
    
    d,make zImage  (如果需要make uImage <---sudo cp -raf uboot-fs210_V5/tools/mkimage /usr/bin)
    
    
    最终得到zImage或者uImage
    
    
3, 编译android源码(已经解压过,并编译过)

    编译方法:
        a,初始化编译环境(执行脚本,每进入一个终端都得执行)--提供了编译所需要的命令:croot, lunch, mm, mmm ...一系列的命令
            george@George-JI:~/src_210/android4.0-fs210_v2$
            source  build/envsetup.sh
            
            
            including device/farsight/fs210/vendorsetup.sh
            including device/moto/stingray/vendorsetup.sh
            including device/moto/wingray/vendorsetup.sh
            including sdk/bash_completion/adb.bash
            
        
        b,选择一个产品
            george@George-JI:~/src_210/android4.0-fs210_v2$ lunch //

            You're building on Linux

            Lunch menu... pick a combo:
                 1. full-eng
                 2. full_x86-eng
                 3. vbox_x86-eng
                 4. full_fs210-userdebug
                 5. full_fs210-eng
                 6. full_stingray-userdebug
                 7. full_wingray-userdebug

            Which would you like? [full-eng] 5

            ============================================
            PLATFORM_VERSION_CODENAME=REL
            PLATFORM_VERSION=4.0.4
            TARGET_PRODUCT=full_fs210
            TARGET_BUILD_VARIANT=eng
            TARGET_BUILD_TYPE=release
            TARGET_BUILD_APPS=
            TARGET_ARCH=arm
            TARGET_ARCH_VARIANT=armv7-a-neon
            HOST_ARCH=x86
            HOST_OS=linux
            HOST_BUILD_TYPE=release
            BUILD_ID=IMM76I
            ============================================
            
            
            注意:前两个步骤记得在每次打开一个新的终端都要执行一遍

        c,make
        
    
    android源码编译完成的目的是什么:得到根文件系统
    
    如果制作根文件系统:关注 out/target/product/fs210/
        out/target/product/fs210/root  system data合并在一起就可以
        
        
    用脚本去制作根文件系统:fs210_build.sh先修改如下:
        33 #       make -j$CPU_JOB_NUM
        80         chmod -R 777 rootfs_dir/system/vendor

    执行:
         ./fs210_build.sh
         最终结果:
            out/target/product/fs210/rootfs_dir
            
            
    根文件系统目录结构:
        data
        
        sbin        
        dev  
        proc  
        sys  
        
        init   //android祖先进程,类似于linuxrc, 所以set bootargs init=/init
        init.rc     //启动脚本,类似于/etc/init.d/rcS
        init.fs210.rc  
        init.fs210.usb.rc          
        init.goldfish.rc  
          
        ueventd.rc //用于自动创建设备节点的--类似于mdev
        ueventd.fs210.rc     
        ueventd.goldfish.rc
        
        default.prop    
        system
            |
            app ://android自带的apk,开机就自动安装
            
            bin
            etc
            lib
            usr
            xbin
            
            build.prop    
            fonts  //字体库
            framework // Framework层java代码编译出的字节码,开机的时候装载到dvm进行运行  
            media //开机动画
            tts   
            vendor  
        

===>启动android系统
tftp + nfs方式:    
1,烧录uboot
     cp -raf u-boot.bin  /tftpboot/
    
    
     FS210 # set serverip 192.168.7.3
     FS210 # set ipaddr 192.168.7.6
        tftp 0x40008000 u-boot.bin
     FS210 # nand erase 0x0  0x100000
     FS210 # nand write 0x40008000 0x0  0x100000
2,启动内核

扫描二维码关注公众号,回复: 3096577 查看本文章

    cp -raf uImage  /tftpboot/
    FS210 # set bootcmd tftp 0x40008000 uImage \; bootm 0x40008000
    FS210 # save

3,挂载根文件系统
    cp -raf out/target/product/fs210/rootfs_dir/ /opt/
    
        sudo vim /etc/exports
            /opt/rootfs_dir            *(subtree_check,rw,no_root_squash,async)
        sudo service nfs-kernel-server restart
        
        
    设置bootargs    
    set bootargs console=ttySAC0,115200 init=/init root=/dev/nfs nfsroot=192.168.7.3:/opt/rootfs_dir  ip=192.168.7.6
            
    
4,E:\android底层系统开发-george\各种问题的解决方式\vnc_ok-解决没有lcd屏
        androidvncserver放到根文件系统:
        
    root@android:/ # ./androidvncserver
        Initializing framebuffer device /dev/graphics/fb0...
        xres=800, yres=480, xresv=800, yresv=960, xoffs=0, yoffs=480, bpp=32
        Initializing keyboard device /dev/input/event0 ...
        Initializing touch device /dev/input/event3 ...
                xmin:  0
                xmax: 0
                ymin:  0
                ymax: 0
        Initializing VNC server:
                width:  800
                height: 480
                bpp:    32
                port:   5901
        Initializing server...
        21/09/2017 06:26:05 Listening for VNC connections on TCP port 5901

    
=====================================================================================
在android系统中进行开发:c程序开发
    1,编写代码---一定要在android源码目录中操作
    
        test/c_test$ touch hello.c
        
        #include <stdio.h>
        #include <stdlib.h>
        #include <string.h>
        #include <sys/types.h>
        #include <sys/stat.h>
        #include <fcntl.h>


        int main(int argc, char *argv[])
        {

                printf("hello android world\n");

                int fd;

                fd = open("/dev/input/event0", O_RDWR);
                if(fd < 0)
                {
                        perror("open");
                        exit(1);
                }else{
                        printf("open ok\n");
                }

                return 0;

        }
    
    2,编译代码--Android.mk  
        目标: 依赖
            编译方法
        
        学习Android.mk的方法---抄
        
        
        #获取当前路径,类似pwd
        LOCAL_PATH := $(call my-dir)
        #清空以LOCAL_XX的变量,LOCAL_PATH除外
        include $(CLEAR_VARS)

        #指定依赖
        LOCAL_SRC_FILES:= hello.c
                                    
        #指定目标
        LOCAL_MODULE:= hello_elf
        
        LOCAL_MODULE_TAGS := optional

        #指定编译方法---编译成可执行程序
        include $(BUILD_EXECUTABLE)

george@George-JI:~/src_210/android4.0-fs210_v2$ mmm test/c_test/
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=4.0.4
TARGET_PRODUCT=full_fs210
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a-neon
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=IMM76I
============================================
make:进入目录'/home/george/src_210/android4.0-fs210_v2'
target thumb C: hello_elf <= test/c_test/hello.c
target Executable: hello_elf (out/target/product/fs210/obj/EXECUTABLES/hello_elf_intermediates/LINKED/hello_elf)
target Symbolic: hello_elf (out/target/product/fs210/symbols/system/bin/hello_elf)
target Strip: hello_elf (out/target/product/fs210/obj/EXECUTABLES/hello_elf_intermediates/hello_elf)
Install: out/target/product/fs210/system/bin/hello_elf

        
    3,运行代码
        cp -raf  out/target/product/fs210/system/bin/hello_elf  /opt/rootfs_dir
        
        
        
        如果无法使用ctrl+c : E:\android底层系统开发-george\各种问题的解决方式\解决无法ctrl+c
                替换init
                
                
        
        root@android:/ # ./hello_elf
            hello android world
            open ok


    
    
    
    
    
    
    
       

猜你喜欢

转载自blog.csdn.net/linken_yue/article/details/82558377