init第一阶段的会被编译到ramdisk.img中,init第二阶段会被编译进system.img中。
ramdisk会挂载成rootfs,system.img会被挂载成system分区。
kernel会首先加载/init。
把init编译进去
diff --git a/uml.mk b/uml.mk
index 03db5e9..9b7558e 100644
--- a/uml.mk
+++ b/uml.mk
@@ -49,6 +49,8 @@ PRODUCT_PACKAGES += \
healthd \
hwservicemanager \
init \
+ init_system \
+ init_vendor \
init.environ.rc \
init.rc \
libEGL \
报错找不到/system/bin/init,也就是system分区没有挂载成功.
diff --git a/uml.mk b/uml.mk
index 03db5e9..9b7558e 100644
--- a/uml.mk
+++ b/uml.mk
@@ -49,6 +49,8 @@ PRODUCT_PACKAGES += \
healthd \
hwservicemanager \
init \
+ init_system \
+ init_vendor \
init.environ.rc \
init.rc \
libEGL \
@@ -123,6 +125,7 @@ PRODUCT_SYSTEM_DEFAULT_PROPERTIES += \
debug.atrace.tags.enableflags=0
PRODUCT_COPY_FILES += \
+ device/generic/uml/fstab.uml.initrd:$(TARGET_COPY_OUT_RAMDISK)/fstab.uml \
system/core/rootdir/init.usb.rc:root/init.usb.rc \
system/core/rootdir/init.usb.configfs.rc:root/init.usb.configfs.rc \
system/core/rootdir/ueventd.rc:root/ueventd.rc \
新添加的文件fstab.uml.initrd内容如下:
tom@tom-linuxer:~/work/aosp/device/generic/uml$ cat fstab.uml.initrd
# Android fstab file for ramdisk tom -3
#
#vendor /vendor ext4 ro,barrier=1 wait,logical,first_stage_mount
/dev/block/ubda /system ext4 ro,barrier=1 wait,logical,avb=vbmeta,first_stage_mount
Initializing XFRM netlink socket
NET: Registered protocol family 10
Segment Routing with IPv6
mip6: Mobile IPv6
ip6_tables: (C) 2000-2006 Netfilter Core Team
sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
NET: Registered protocol family 17
NET: Registered protocol family 15
Initialized stdio console driver
Console initialized on /dev/tty0
console [tty0] enabled
Initializing software serial port version 1
console [mc-1] enabled
registered taskstats version 1
This architecture does not have kernel memory protection.
init: init first stage started!
init: [libfs_mgr]ReadFstabFromDt(): failed to read fstab from dt
init: Using Android DT directory /proc/device-tree/firmware/android/
init: bool android::init::FirstStageMount::InitRequiredDevices(): partition(s) not found in /sys, waiting for their uevent(s): super, vbmeta
感觉要从kernel中找到ueventd消息,现在逻辑不清楚。
在文件core/init/uevent_listener.cpp中。
98 bool UeventListener::ReadUevent(Uevent* uevent) const {
99 char msg[UEVENT_MSG_LEN + 2];
100 int n = uevent_kernel_multicast_recv(device_fd_, msg, UEVENT_MSG_LEN);
101 if (n <= 0) {
102 if (errno != EAGAIN && errno != EWOULDBLOCK) {
103 LOG(ERROR) << "Error reading from Uevent Fd";
104 }
105 return false;
106 }
107 if (n >= UEVENT_MSG_LEN) {
108 LOG(ERROR) << "Uevent overflowed buffer, discarding";
109 // Return true here even if we discard as we may have more uevents pending and we
110 // want to keep processing them.
111 return true;
112 }
113
114 msg[n] = '\0';
115 msg[n + 1] = '\0';
116
117 ParseEvent(msg, uevent);
118
119 return true;
120 }
121
函数
调试log
[ 1.399694] init: Using Android DT directory /proc/device-tree/firmware/android/
[ 1.406997] init: tom action=add path=/devices/pci0000:00/0000:00:03.0/virtio0/block/vda/vda2 subsystem=block
[ 1.407819] init: tom firmware= p_name=super
[ 1.408182] init: tom device_name=vda2 modifies=
[ 1.408567] init: tom partition_num=2 major=253 minor=2
[ 1.409392] init: tom action=add path=/devices/pci0000:00/0000:00:03.0/virtio0/block/vda/vda1 subsystem=block
[ 1.410304] init: tom firmware= p_name=vbmeta
[ 1.410827] init: tom device_name=vda1 modifies=
[ 1.411399] init: tom partition_num=1 major=253 minor=1