kernel 及 ramdisk 移植

 

合成boot.img:
INTERNAL_BOOTIMAGE_ARGS: --kernel out/target/product/xxx/kernel --ramdisk out/target/product/xxx/ramdisk.img --base 0x80000000 --pagesize 2048 --cmdline console=ttyHSL0,115200,n8 androidboot.console=ttyHSL0 androidboot.hardware=qcom msm_rtb.filter=0x237 ehci-hcd.park=3 androidboot.bootdevice=7824900.sdhci lpm_levels.sleep_disabled=1 earlyprintk buildvariant=userdebug

 

http://blog.csdn.net/liuqingsongmsdn2014/article/details/53694794

 

 

 

内核的逻辑地址:0x90100000

modem\common\build\partition_xxx.xml

kernel\Makefile

all: vmlinux
vmlinux: scripts/link-vmlinux.sh $(vmlinux-deps) FORCE
vmlinux-deps := $(KBUILD_LDS) $(KBUILD_VMLINUX_INIT) $(KBUILD_VMLINUX_MAIN)

export KBUILD_VMLINUX_INIT := $(head-y) $(init-y)
export KBUILD_VMLINUX_MAIN := $(core-y) $(libs-y) $(drivers-y) $(net-y)
export KBUILD_LDS          := arch/$(SRCARCH)/kernel/vmlinux.lds

合成boot.img:
INTERNAL_BOOTIMAGE_ARGS: --kernel out/target/product/xxx/kernel --ramdisk out/target/product/xxx/ramdisk.img --base 0x80000000 --pagesize 2048 --cmdline console=ttyHSL0,115200,n8 androidboot.console=ttyHSL0 androidboot.hardware=qcom msm_rtb.filter=0x237 ehci-hcd.park=3 androidboot.bootdevice=7824900.sdhci lpm_levels.sleep_disabled=1 earlyprintk buildvariant=userdebug

kernel\arch\arm\Makefile
head-y		:= arch/arm/kernel/head$(MMUEXT).o



out\target\product\xxx\obj\KERNEL_OBJ\arch\arm\kernel\vmlinux.lds
.head.text
kernel\arch\arm\kernel\head.S

kernel\include\linux\init.h
#define __HEAD		.section	".head.text","ax"

bootloader传过来的值:(0,0,(PA)tags_phys)
entry(0, machtype, (unsigned*)tags_phys);


head.S
/* r0 = 0,r1 = machine nr, r2 = atags or dtb pointer */
    __HEAD
ENTRY(stext)
#include "head-common.S"

kernel\arch\arm\kernel\head-common.S
b    start_kernel  //启动内核kernel


xxx:/ # mount
rootfs on / type rootfs (ro,seclabel,relatime)
tmpfs on /dev type tmpfs (rw,seclabel,nosuid,relatime,size=957928k,nr_inodes=149237,mode=755)
devpts on /dev/pts type devpts (rw,seclabel,relatime,mode=600)
proc on /proc type proc (rw,relatime,gid=3009,hidepid=2)
sysfs on /sys type sysfs (rw,seclabel,relatime)
selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,seclabel,relatime)

kernel\init\main.c
start_kernel
    setup_arch(&command_line);
    setup_command_line(command_line);
    
    mm_init //向内核注册rootfs  //根文件系统初始化
    
    rest_init
        kernel_init
            kernel_init_freeable
              do_basic_setup  //释放Initramfs到rootfs;如果Initramfs中有init,这种情况比较特殊、rootfs就是最后系统使用的根文件系统。
                sys_open((const char __user *) "/dev/console"  //开启控制台
                ramdisk_execute_command = "/init";  //加载ramdisk的init
                load_default_modules  /* rootfs is available now, try loading default modules */
            run_init_process(ramdisk_execute_command) //execute_command  启动init进程
                do_execve
            

ramdisk.img
根文件系统  out\target\product\xxx\root目录
解压 

system\core\init\Android.mk
LOCAL_SRC_FILES:= \
    bootchart.cpp \
    builtins.cpp \
    devices.cpp \
    init.cpp \
    keychords.cpp \
    property_service.cpp \
    signal_handler.cpp \
    ueventd.cpp \
    ueventd_parser.cpp \
    watchdogd.cpp \

LOCAL_MODULE:= init


.rc file
/system/etc/init/
/vendor/etc/init/
/odm/etc/init/


Actions take the form of://执行时机
on  [&& ]*
   
   
   

Services take the form of://执行程序
service   [  ]*
    [  ]* []
powerctl
restart 
restorecon  [  ]*
restorecon_recursive  [  ]*
rm 
rmdir 
setprop  
setrlimit   
start 
stop 
swapon_all 
symlink  
sysclktz 
trigger 
umount 
verity_load_state
verity_update_state 
wait  [  ]
write   

system\core\init\init.cpp
main
    is_first_stage 
        //mount("tmpfs", "/dev", "tmpfs", MS_NOSUID, "mode=0755");
        //mount("devpts", "/dev/pts", "devpts", 0, NULL);
        //mount("proc", "/proc", "proc", 0, "hidepid=2,gid=" MAKE_STR(AID_READPROC));
        //mount("sysfs", "/sys", "sysfs", 0, NULL);
    //device kmsg and null
    
    parser.AddSectionParser("service",std::make_unique());
        section_parsers_service = ServiceParser
  parser.AddSectionParser("on", std::make_unique());
      section_parsers_on = ActionParser
  parser.AddSectionParser("import", std::make_unique());
      section_parsers_import = ImportParser
    
    parser.ParseConfig("/init.rc");//解析配置文件
        read_file
        ParseData
            section_parser->ParseSection
                ServiceManager::GetInstance().AddService
                ActionManager::GetInstance().AddAction
            section_parser->ParseLineSection
            
    am.QueueEventTrigger
    am.ExecuteOneCommand()
    ....

1.根文件系统初始化

对rootfs有了基本的了解后,需要进一步知道rootfs运行起来的流程。从内核init进程出发开始探索:

asmlinkage void __init start_kernel(void)
    vfs_caches_init_early();
        dcache_init_early();
        inode_init_early();
    --> vfs_caches_init(num_physpages);
        dcache_init();
        inode_init();
        files_init(mempages);
        --> mnt_init();
            --> init_rootfs();
            --> init_mount_tree();
            
            
2.虚拟根文件系统与真实根文件系统

简单的说,一个文件系统对应着一块存储区域,虚拟根文件系统对应的存储区域为内存ram,而直根文件系统对应的存储区域为 硬盘或flash,
根据前面介绍,在系统初始化期间,先挂载的是虚拟根文件系统。那么这里有两个疑问,为什么不直接挂载真实根文件系统?真实根文件系统又是什么时机挂载上去的?

http://blog.csdn.net/liuqingsongmsdn2014/article/details/53694794

 

 

 

 

 

 

 

 


 

 

 

 

 

 

你可能感兴趣的:(Android,编译,Android,驱动)