qiuri2008

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

Android系统开发时,经常会遇到添加或者调整系统分区大小的问题,下面以mstar的一款产品为例进行分析:

      (1)mount指令可以查看到板子中挂在的分区,主要关注ext4类型分区,例如tvservice,tvconfig,tvconfig,tvcustomer   

130|shell@arbutus:/ # mount
rootfs / rootfs ro,relatime 0 0
tmpfs /dev tmpfs rw,nosuid,relatime,mode=755 0 0
devpts /dev/pts devpts rw,relatime,mode=600 0 0
proc /proc proc rw,relatime 0 0
sysfs /sys sysfs rw,relatime 0 0
debugfs /sys/kernel/debug debugfs rw,relatime 0 0
none /acct cgroup rw,relatime,cpuacct 0 0
none /sys/fs/cgroup tmpfs rw,relatime,mode=750,gid=1000 0 0
tmpfs /mnt/asec tmpfs rw,relatime,mode=755,gid=1000 0 0
tmpfs /mnt/obb tmpfs rw,relatime,mode=755,gid=1000 0 0
none /dev/cpuctl cgroup rw,relatime,cpu 0 0
tmpfs /mnt/usb tmpfs rw,relatime,mode=755,gid=1000 0 0
tmpfs /mnt/iso tmpfs rw,relatime,mode=755,gid=1000 0 0
tmpfs /mnt/samba tmpfs rw,relatime,mode=755,gid=1000 0 0
tmpfs /var tmpfs rw,relatime,mode=775,gid=1000 0 0
/dev/block/platform/mstar_mci.0/by-name/system /system ext4 ro,relatime,data=ordered 0 0
/dev/block/platform/mstar_mci.0/by-name/cache /cache ext4 rw,nosuid,nodev,noatime,data=ordered 0 0
/dev/block/platform/mstar_mci.0/by-name/userdata /data ext4 rw,nosuid,nodev,noatime,data=ordered 0 0
/dev/block/platform/mstar_mci.0/by-name/tvservice /tvservice ext4 ro,relatime,data=ordered 0 0
/dev/block/platform/mstar_mci.0/by-name/tvconfig /tvconfig ext4 ro,relatime,data=ordered 0 0
/dev/block/platform/mstar_mci.0/by-name/tvdatabase /tvdatabase ext4 rw,nosuid,nodev,noatime,data=ordered 0 0
/dev/block/platform/mstar_mci.0/by-name/tvcustomer /tvcustomer ext4 rw,nosuid,nodev,noatime,data=ordered 0 0
/dev/fuse /mnt/sdcard fuse rw,nosuid,nodev,noexec,relatime,user_id=1023,group_id=1023,default_permissions,allow_other 0 0

  (2)查看分区文件fstab.monet (device/mstar/arbutus/目录下),截取部分信息如下:   

/dev/block/platform/mstar_mci.0/by-name/system          /system             ext4      ro                                                    wait
/dev/block/platform/mstar_mci.0/by-name/cache           /cache              ext4      noatime,nosuid,nodev                                  wait,block_validity,nodiscard,data=ordered,journal_checksum
/dev/block/platform/mstar_mci.0/by-name/userdata        /data               ext4      noatime,nosuid,nodev                                  wait,block_validity,nodiscard,data=ordered,journal_checksum
/dev/block/platform/mstar_mci.0/by-name/tvservice       /tvservice          ext4      ro                                                    wait
/dev/block/platform/mstar_mci.0/by-name/tvconfig        /tvconfig           ext4      ro                                                    wait
/dev/block/platform/mstar_mci.0/by-name/tvdatabase      /tvdatabase         ext4      noatime,nosuid,nodev                                  wait,block_validity,nodiscard,data=ordered,journal_checksum
/dev/block/platform/mstar_mci.0/by-name/tvcustomer      /tvcustomer         ext4      noatime,nosuid,nodev   

android平台不同厂商可能名称不一样,但是都是fstab.xxx的形式

      (3)指定各个分区的大小,BoardConfig.mk (device/mstar/arbutus)文件指定各自大小可以根据需要进行修改

# mmc part
# :  type name      (size)
#1.  misc           (512K)
#2.  recovery       (19M)
#3.  boot           (15M)
#4.  tee            (6M)
#5.  rtpm           (256K)
#6.  dtb            (1M)
#7.  system         (800M)
#8.  userdata       (900M)
#9.  cache          (1G)
#10. tvservice      (160M)
#11. tvconfig       (10M)
#12. tvdatabase     (8M)
#13. tvcustomer     (16M)
BOARD_RECOVERYIMAGE_PARTITION_SIZE   := 0x01300000
BOARD_BOOTIMAGE_PARTITION_SIZE       := 0x00F00000
BOARD_TEEIMAGE_PARTITION_SIZE        := 0x00600000
BOARD_RTPMIMAGE_PARTITION_SIZE       := 0x00040000
BOARD_DTBIMAGE_PARTITION_SIZE        := 0x00100000
BOARD_SYSTEMIMAGE_PARTITION_SIZE     := 0x33C00000
BOARD_USERDATAIMAGE_PARTITION_SIZE   := 0x38000000
BOARD_CACHEIMAGE_PARTITION_SIZE      := 0x40000000
BOARD_TVSERVICEIMAGE_PARTITION_SIZE  := 0x0A000000
BOARD_TVCONFIGIMAGE_PARTITION_SIZE   := 0x00A00000
BOARD_TVDATABASEIMAGE_PARTITION_SIZE := 0x00800000
BOARD_TVCUSTOMERIMAGE_PARTITION_SIZE := 0x01000000

BOARD_FLASH_BLOCK_SIZE := 512

  (4)启动脚本加载,init.monet.rc脚本中on fs 模块中启动 

on fs
    mkdir /tvservice
    mkdir /tvconfig
    mkdir /tvdatabase
    mkdir /tvcustomer
    mount_all /fstab.monet

  

(5)init进程解析fstab.monet文件

         keywords.h文件中注册mount_all操作方法        

enum {
    K_UNKNOWN,
#endif
    KEYWORD(capability,  OPTION,  0, 0)
    KEYWORD(chdir,       COMMAND, 1, do_chdir)
    KEYWORD(chroot,      COMMAND, 1, do_chroot)
    KEYWORD(class,       OPTION,  0, 0)
    KEYWORD(class_start, COMMAND, 1, do_class_start)
    KEYWORD(class_stop,  COMMAND, 1, do_class_stop)
    KEYWORD(class_reset, COMMAND, 1, do_class_reset)
    KEYWORD(console,     OPTION,  0, 0)
    KEYWORD(critical,    OPTION,  0, 0)
    KEYWORD(disabled,    OPTION,  0, 0)
    KEYWORD(domainname,  COMMAND, 1, do_domainname)
    KEYWORD(enable,      COMMAND, 1, do_enable)
    KEYWORD(exec,        COMMAND, 1, do_exec)
    KEYWORD(export,      COMMAND, 2, do_export)
    KEYWORD(group,       OPTION,  0, 0)
    KEYWORD(hostname,    COMMAND, 1, do_hostname)
    KEYWORD(ifup,        COMMAND, 1, do_ifup)
    KEYWORD(insmod,      COMMAND, 1, do_insmod)
    KEYWORD(import,      SECTION, 1, 0)
    KEYWORD(keycodes,    OPTION,  0, 0)
    KEYWORD(mkdir,       COMMAND, 1, do_mkdir)
    KEYWORD(mount_all,   COMMAND, 1, do_mount_all)
    KEYWORD(mount,       COMMAND, 3, do_mount)
    KEYWORD(on,          SECTION, 0, 0)
    KEYWORD(oneshot,     OPTION,  0, 0)
    KEYWORD(onrestart,   OPTION,  0, 0)
    KEYWORD(powerctl,    COMMAND, 1, do_powerctl)
    KEYWORD(restart,     COMMAND, 1, do_restart)
    KEYWORD(restorecon,  COMMAND, 1, do_restorecon)
    KEYWORD(restorecon_recursive,  COMMAND, 1, do_restorecon_recursive)
    KEYWORD(rm,          COMMAND, 1, do_rm)
    KEYWORD(rmdir,       COMMAND, 1, do_rmdir)
    KEYWORD(seclabel,    OPTION,  0, 0)
    KEYWORD(service,     SECTION, 0, 0)
    KEYWORD(setcon,      COMMAND, 1, do_setcon)
    KEYWORD(setenforce,  COMMAND, 1, do_setenforce)
    KEYWORD(setenv,      OPTION,  2, 0)
    KEYWORD(setkey,      COMMAND, 0, do_setkey)
    KEYWORD(setprop,     COMMAND, 2, do_setprop)
    KEYWORD(setrlimit,   COMMAND, 3, do_setrlimit)
    KEYWORD(setsebool,   COMMAND, 2, do_setsebool)
    KEYWORD(socket,      OPTION,  0, 0)
    KEYWORD(start,       COMMAND, 1, do_start)
    KEYWORD(stop,        COMMAND, 1, do_stop)
    KEYWORD(swapon_all,  COMMAND, 1, do_swapon_all)
    KEYWORD(trigger,     COMMAND, 1, do_trigger)
    KEYWORD(symlink,     COMMAND, 1, do_symlink)
    KEYWORD(sysclktz,    COMMAND, 1, do_sysclktz)
    KEYWORD(user,        OPTION,  0, 0)
    KEYWORD(wait,        COMMAND, 1, do_wait)
    KEYWORD(write,       COMMAND, 2, do_write)
    KEYWORD(copy,        COMMAND, 2, do_copy)
    KEYWORD(chown,       COMMAND, 2, do_chown)
    KEYWORD(chmod,       COMMAND, 2, do_chmod)
    KEYWORD(loglevel,    COMMAND, 1, do_loglevel)
    KEYWORD(load_persist_props,    COMMAND, 0, do_load_persist_props)
    KEYWORD(load_all_props,        COMMAND, 0, do_load_all_props)
    KEYWORD(ioprio,      OPTION,  0, 0)
#ifdef __MAKE_KEYWORD_ENUM__
    KEYWORD_COUNT,
}

builtins.c文件中do_mount_all,启动一个进程调用fs_mgr_read_fstab,fs_mgr_mount_all启动解析,其中system\core\fs_mgr有被vold,adb等模块用来解析

         fstab.xxx等分区文件。

       (6)根据第三步中指定的分区大小,进行打包对应分区的img文件

          releaseimage.sh, mkimage.sh, build_image.sh, make_usb_upgrade.sh等脚本中,会根据第三步设置的大小来制作img文件

          如mkimage.sh           

function make-images()
{
    mkdir -p $RELEASE_OUT
    mkdir -p $RELEASE_OUT/scripts

    gernerate-script-start

    # Raw partition must be first.
    make-raw-partition
    make-split-fs-partition system $BOARD_SYSTEMIMAGE_PARTITION_SIZE true
    make-fs-partition userdata $BOARD_USERDATAIMAGE_PARTITION_SIZE true
    make-fs-partition cache $BOARD_CACHEIMAGE_PARTITION_SIZE true
    make-fs-partition tvservice $BOARD_TVSERVICEIMAGE_PARTITION_SIZE false
    make-fs-partition tvconfig $BOARD_TVCONFIGIMAGE_PARTITION_SIZE false
    make-fs-partition tvdatabase $BOARD_TVDATABASEIMAGE_PARTITION_SIZE false
    make-fs-partition tvcustomer $BOARD_TVCUSTOMERIMAGE_PARTITION_SIZE false
    ......
    ......

}

buiild_image.sh文件  

#make-fs-partition $PARTITION_NAME $PARTITION_SIZE $PARTITION_LZO
function make-fs-partition()
{
    echo -e "\033[31mMake fs $1 partition...\033[0m"
    local PARTITION_NAME=$1
    local PARTITION_SIZE=$2
    local PARTITION_LZO=$3

    # Generate image
    gernerate-fs-image $PARTITION_NAME $PARTITION_SIZE $PARTITION_LZO

    release-fs-partition $PARTITION_NAME $PARTITION_SIZE $PARTITION_LZO
}
 

 

 

function gernerate-fs-image()
{
    local PARTITION_NAME=$1
    local PARTITION_SIZE=$2
    local PARTITION_LZO=$3

    if [ "$PARTITION_NAME" == "userdata" ]; then
        local MOUNT_POINT=data
    else
        local MOUNT_POINT=$PARTITION_NAME
    fi

    local TARGET_OUT=$PRODUCT_OUT/$MOUNT_POINT
    if [ ! -d "$TARGET_OUT" ]; then
        echo "No $TARGET_OUT directory to gernerate image."
        return
    fi

    if [ "$PARTITION_NAME" == "system" -o "$PARTITION_NAME" == "userdata" -o "$PARTITION_NAME" == "cache" -o "$PARTITION_NAME" == "systembackup" ]; then
        if [  $PARTITION_NAME == "system" ]; then
            local IMAGE_INFO=$PRODUCT_OUT/obj/PACKAGING/systemimage_intermediates/system_image_info.txt
        else
            local IMAGE_INFO=$PRODUCT_OUT/obj/PACKAGING/"$PARTITION_NAME"_intermediates/"$PARTITION_NAME"_image_info.txt
        fi

        generate-userimage-prop-dictionary $IMAGE_INFO
        ./build/tools/releasetools/build_image.py $TARGET_OUT $IMAGE_INFO $PRODUCT_OUT/$PARTITION_NAME.img
    else
        <span style="background-color: rgb(0, 102, 0);">make_ext4fs -S $PRODUCT_OUT/root/file_contexts -l $PARTITION_SIZE -a $MOUNT_POINT $PRODUCT_OUT/$PARTITION_NAME.img $TARGET_OUT</span>
    fi
}

 

posted on 2019-07-08 19:32  江召伟  阅读(879)  评论(0编辑  收藏  举报