由於項目一直使用老舊的Android 2.3.4,然後硬件加入了EMMC所以system和userdata的image格式也相應的由yaffs2變成了EXT4。
在調試過程中由此產生了兩個問題:
一,image的生成問題:更改build/core下的Makefile。
以生成system.img.ext4為例,將原有的build-systemimage-target增加一行。相應的需要在device的BoardConfig.mk中根據EMMC分區定義BOARD_SYSTEMIMAGE_PARTITION_SIZE,定義tag TARGET_SYSTEMIMAGES_USE_EXT4作為開關。
- ifeq ($(INTERNAL_USERIMAGES_USE_EXT),true)
- ifeq ($(TARGET_SYSTEMIMAGES_USE_EXT4),true)
- define build-systemimage-target
- @echo "Target system fs image: $(1)"
- $(call build-userimage-ext-target,$(TARGET_OUT),$(1),system,$(INTERNAL_USERIMAGES_EXT_VARIANT),$(BOARD_SYSTEMIMAGE_PARTITION_SIZE))
- @echo "Using my script"
- $(MAKE_EXT4FS) -l $(BOARD_SYSTEMIMAGE_PARTITION_SIZE) -a system $(PRODUCT_OUT)/system.img.ext4 $(TARGET_OUT)
- endef
- else
- ## generate an ext2 image
- # $(1): output file
- define build-systemimage-target
- @echo "Target system fs image: $(1)"
- $(call build-userimage-ext-target,$(TARGET_OUT),$(1),system,$(INTERNAL_USERIMAGES_EXT_VARIANT),$(BOARD_SYSTEMIMAGE_PARTITION_SIZE))
- endef
- endif # TARGET_SYSTEMIMAGES_USE_EXT4
-
- else # INTERNAL_USERIMAGES_USE_EXT != true
二,init.rc腳本加載文件系統過程:
剛開始調試的時候進adb shell曾經報“exec - /system/bin/sh not found”錯誤,系統加載不成功。但是$(TARGET_OUT)目錄下是完整的,因此應該是文件系統沒有mount成功。init.rc中關於文件系統的片段如下:
- on fs
- # mount mtd partitions
- # Mount /system rw first to give the filesystem a chance to save a checkpoint
- mount yaffs2 mtd@system /system
- #mount yaffs2 mtd@system /system ro remount
- mount yaffs2 mtd@userdata /data nosuid nodev
- mount yaffs2 mtd@persist /persist nosuid nodev
- mount yaffs2 mtd@cache /cache nosuid nodev
- mount yaffs2 mtd@persist /persist nosuid nodev
-
- on emmc-fs
- wait /dev/block/mmcblk0p10
- mount ext4 /dev/block/mmcblk0p19 /system rw barrier=1
- chmod 0777 /system/bin/ext4check.sh
- #
- wait /dev/block/mmcblk0p11
- exec /system/bin/sh -c "/system/bin/fixebr.sh mmcblk0"
- exec /system/bin/sh -c "/system/bin/ext4check.sh USERDATA /dev/block/mmcblk0p22"
- mount ext4 /dev/block/mmcblk0p22 /data nosuid nodev barrier=1
- #
- wait /dev/block/mmcblk0p12
- exec /system/bin/sh -c "/system/bin/ext4check.sh PERSIST /dev/block/mmcblk0p10"
- mount ext4 /dev/block/mmcblk0p10 /persist nosuid nodev barrier=1
- #
- wait /dev/block/mmcblk0p13
- exec /system/bin/sh -c "/system/bin/ext4check.sh CACHE /dev/block/mmcblk0p21"
- mount ext4 /dev/block/mmcblk0p21 /cache nosuid nodev barrier=1
可見fs和emmc-fs兩段代表了兩種不同的文件系統的加載,對比一下system/core/init/init.c在main函數中對fs的解析:
- action_for_each_trigger("init", action_add_queue_tail);
- action_for_each_trigger("early-fs", action_add_queue_tail);
- action_for_each_trigger("fs", action_add_queue_tail);
- action_for_each_trigger("post-fs", action_add_queue_tail);
可以看出這裡並沒有對emmc-fs端做任何處理,老舊的2.3.4呀。。。將其改成
- action_for_each_trigger("init", action_add_queue_tail);
- action_for_each_trigger("early-fs", action_add_queue_tail);
- action_for_each_trigger("emmc-fs", action_add_queue_tail);
- action_for_each_trigger("post-fs", action_add_queue_tail);
後解決,這種hardcore方式還是不方便,可以采用宏定義或者運行時從Kernel讀取配置來選擇fs或emmc-fs的方式靈活配置。
另外還有一個小問題,/data/目錄有時候會寫不進去東西導致dalvik虛擬機不能把cache放進去一直啟動不成功,在init.rc中把
mount rootfs rootfs / ro remount
這句從on post-fs的開始移動到init.rc的最後,這樣就能保證先把/data分區裡面必須的目錄都建立好了再鎖住。