1# note: requires x86 because we assume grub is the mbr bootloader. 2ifeq ($(TARGET_ARCH),x86) 3ifeq ($(TARGET_USE_DISKINSTALLER),true) 4 5diskinstaller_root := bootable/diskinstaller 6 7android_sysbase_modules := \ 8 libc \ 9 libcutils \ 10 libdl \ 11 liblog \ 12 libm \ 13 libstdc++ \ 14 linker \ 15 ash \ 16 toolbox \ 17 logcat \ 18 gdbserver \ 19 strace \ 20 netcfg 21android_sysbase_files = \ 22 $(call module-installed-files,$(android_sysbase_modules)) 23 24# $(1): source base dir 25# $(2): target base dir 26define sysbase-copy-files 27$(hide) $(foreach _f,$(android_sysbase_files), \ 28 f=$(patsubst $(1)/%,$(2)/%,$(_f)); \ 29 mkdir -p `dirname $$f`; \ 30 echo "Copy: $$f" ; \ 31 cp -fR $(_f) $$f; \ 32) 33endef 34 35installer_base_modules := \ 36 libdiskconfig \ 37 libext2fs \ 38 libext2_com_err \ 39 libext2_e2p \ 40 libext2_blkid \ 41 libext2_uuid \ 42 libext2_profile \ 43 badblocks \ 44 resize2fs \ 45 tune2fs \ 46 mke2fs \ 47 e2fsck 48installer_base_files = \ 49 $(call module-built-files,$(installer_base_modules)) 50 51# $(1): source base dir 52# $(2): target base dir 53define installer-copy-modules 54$(hide) $(foreach m,$(installer_base_modules), \ 55 src=$(firstword $(strip $(call module-built-files,$(m)))); \ 56 dest=$(patsubst $(strip $(1))/%,$(strip $(2))/%,\ 57 $(firstword $(strip $(call module-installed-files,$(m))))); \ 58 echo "Copy: $$src -> $$dest"; \ 59 mkdir -p `dirname $$dest`; \ 60 cp -fdp $$src $$dest; \ 61) 62endef 63 64# Build the installer ramdisk image 65installer_initrc := $(diskinstaller_root)/init.rc 66installer_kernel := $(INSTALLED_KERNEL_TARGET) 67installer_ramdisk := $(TARGET_INSTALLER_OUT)/ramdisk-installer.img 68installer_build_prop := $(INSTALLED_BUILD_PROP_TARGET) 69installer_config := $(diskinstaller_root)/installer.conf 70installer_binary := \ 71 $(call intermediates-dir-for,EXECUTABLES,diskinstaller)/diskinstaller 72 73$(installer_ramdisk): $(diskinstaller_root)/config.mk \ 74 $(MKBOOTFS) \ 75 $(INSTALLED_RAMDISK_TARGET) \ 76 $(INSTALLED_BOOTIMAGE_TARGET) \ 77 $(TARGET_DISK_LAYOUT_CONFIG) \ 78 $(installer_binary) \ 79 $(installer_initrc) \ 80 $(installer_kernel) \ 81 $(installer_config) \ 82 $(android_sysbase_files) \ 83 $(installer_base_files) \ 84 $(installer_build_prop) 85 @echo ----- Making installer image ------ 86 rm -rf $(TARGET_INSTALLER_OUT) 87 mkdir -p $(TARGET_INSTALLER_OUT) 88 mkdir -p $(TARGET_INSTALLER_ROOT_OUT) 89 mkdir -p $(TARGET_INSTALLER_ROOT_OUT)/sbin 90 mkdir -p $(TARGET_INSTALLER_ROOT_OUT)/data 91 mkdir -p $(TARGET_INSTALLER_SYSTEM_OUT) 92 mkdir -p $(TARGET_INSTALLER_SYSTEM_OUT)/etc 93 mkdir -p $(TARGET_INSTALLER_SYSTEM_OUT)/bin 94 @echo Copying baseline ramdisk... 95 cp -fR $(TARGET_ROOT_OUT) $(TARGET_INSTALLER_OUT) 96 @echo Copying sysbase files... 97 $(call sysbase-copy-files,$(TARGET_OUT),$(TARGET_INSTALLER_SYSTEM_OUT)) 98 @echo Copying installer base files... 99 $(call installer-copy-modules,$(TARGET_OUT),\ 100 $(TARGET_INSTALLER_SYSTEM_OUT)) 101 @echo Modifying ramdisk contents... 102 cp -f $(installer_initrc) $(TARGET_INSTALLER_ROOT_OUT)/ 103 cp -f $(TARGET_DISK_LAYOUT_CONFIG) \ 104 $(TARGET_INSTALLER_SYSTEM_OUT)/etc/disk_layout.conf 105 cp -f $(installer_config) \ 106 $(TARGET_INSTALLER_SYSTEM_OUT)/etc/installer.conf 107 cp -f $(installer_binary) $(TARGET_INSTALLER_SYSTEM_OUT)/bin/installer 108 $(hide) chmod ug+rw $(TARGET_INSTALLER_ROOT_OUT)/default.prop 109 cat $(installer_build_prop) >> $(TARGET_INSTALLER_ROOT_OUT)/default.prop 110 $(MKBOOTFS) $(TARGET_INSTALLER_ROOT_OUT) | gzip > $(installer_ramdisk) 111 @echo ----- Made installer ramdisk -[ $@ ]- 112 113###################################################################### 114# Now the installer boot image which includes the kernel and the ramdisk 115internal_installerimage_args := \ 116 --kernel $(installer_kernel) \ 117 --ramdisk $(installer_ramdisk) 118 119internal_installerimage_files := \ 120 $(filter-out --%,$(internal_installerimage_args)) 121 122BOARD_INSTALLER_CMDLINE := $(strip $(BOARD_INSTALLER_CMDLINE)) 123ifdef BOARD_INSTALLER_CMDLINE 124 internal_installerimage_args += --cmdline "$(BOARD_INSTALLER_CMDLINE)" 125endif 126 127installer_tmp_img := $(TARGET_INSTALLER_OUT)/installer_tmp.img 128tmp_dir_for_inst_image := \ 129 $(call intermediates-dir-for,EXECUTABLES,installer_img)/installer_img 130internal_installerimage_args += --tmpdir $(tmp_dir_for_inst_image) 131internal_installerimage_args += --genext2fs $(MKEXT2IMG) 132$(installer_tmp_img): $(MKEXT2IMG) $(internal_installerimage_files) 133 $(call pretty,"Target installer image: $@") 134 $(hide) $(MKEXT2BOOTIMG) $(internal_installerimage_args) --output $@ 135 136###################################################################### 137# Now make a data image that contains all the target image files for the 138# installer. 139 140bootldr_bin := $(PRODUCT_OUT)/grub/grub.bin 141installer_target_data_files := \ 142 $(INSTALLED_BOOTIMAGE_TARGET) \ 143 $(INSTALLED_SYSTEMIMAGE) \ 144 $(INSTALLED_USERDATAIMAGE_TARGET) \ 145 $(bootldr_bin) 146 147# $(1): src directory 148# $(2): output file 149# $(3): mount point 150# $(4): ext variant (ext2, ext3, ext4) 151# $(5): size of the partition 152define build-installerimage-ext-target 153 @mkdir -p $(dir $(2)) 154 $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$(PATH) \ 155 $(MKEXTUSERIMG) $(1) $(2) $(4) $(3) $(5) 156endef 157 158installer_data_img := $(TARGET_INSTALLER_OUT)/installer_data.img 159$(installer_data_img): $(diskinstaller_root)/config.mk \ 160 $(installer_target_data_files) \ 161 $(MKEXT2IMG) \ 162 $(installer_ramdisk) 163 @echo --- Making installer data image ------ 164 mkdir -p $(TARGET_INSTALLER_OUT) 165 mkdir -p $(TARGET_INSTALLER_OUT)/data 166 cp -f $(bootldr_bin) $(TARGET_INSTALLER_OUT)/data/bootldr.bin 167 cp -f $(INSTALLED_BOOTIMAGE_TARGET) $(TARGET_INSTALLER_OUT)/data/boot.img 168 cp -f $(INSTALLED_SYSTEMIMAGE) \ 169 $(TARGET_INSTALLER_OUT)/data/system.img 170 cp -f $(INSTALLED_USERDATAIMAGE_TARGET) \ 171 $(TARGET_INSTALLER_OUT)/data/userdata.img 172 $(call build-installerimage-ext-target,$(TARGET_INSTALLER_OUT)/data,$@, \ 173 inst_data,ext4,$(BOARD_INSTALLERIMAGE_PARTITION_SIZE)) 174 @echo --- Finished installer data image -[ $@ ]- 175 176###################################################################### 177# now combine the installer image with the grub bootloader 178grub_bin := $(PRODUCT_OUT)/grub/grub.bin 179installer_layout := $(diskinstaller_root)/installer_img_layout.conf 180edit_mbr := $(HOST_OUT_EXECUTABLES)/editdisklbl 181 182INSTALLED_DISK_INSTALLER_IMAGE_TARGET := $(PRODUCT_OUT)/installer.img 183$(INSTALLED_DISK_INSTALLER_IMAGE_TARGET): \ 184 $(installer_tmp_img) \ 185 $(installer_data_img) \ 186 $(grub_bin) \ 187 $(edit_mbr) \ 188 $(installer_layout) 189 @echo "Creating bootable installer image: $@" 190 @rm -f $@ 191 $(hide) cat $(grub_bin) > $@ 192 $(hide) $(edit_mbr) -l $(installer_layout) -i $@ \ 193 inst_boot=$(installer_tmp_img) \ 194 inst_data=$(installer_data_img) 195 @echo "Done with bootable installer image -[ $@ ]-" 196 197# 198# Ditto for the android_system_disk and android_data_disk images 199# 200 201INSTALLED_ANDROID_IMAGE_SYSTEM_TARGET := $(PRODUCT_OUT)/android_system_disk.img 202android_system_layout := $(diskinstaller_root)/android_img_system_layout.conf 203 204INSTALLED_ANDROID_IMAGE_DATA_TARGET := $(PRODUCT_OUT)/android_data_disk.img 205android_data_layout := $(diskinstaller_root)/android_img_data_layout.conf 206 207$(INSTALLED_ANDROID_IMAGE_SYSTEM_TARGET): \ 208 $(INSTALLED_SYSTEMIMAGE) \ 209 $(INSTALLED_BOOTIMAGE_TARGET) \ 210 $(grub_bin) \ 211 $(edit_mbr) \ 212 $(android_system_layout) 213 @echo "Creating bootable android system-disk image: $@" 214 @rm -f $@ 215 $(hide) cat $(grub_bin) > $@ 216 $(hide) $(edit_mbr) -l $(android_system_layout) -i $@ \ 217 inst_boot=$(INSTALLED_BOOTIMAGE_TARGET) \ 218 inst_system=$(INSTALLED_SYSTEMIMAGE) 219 @echo "Done with bootable android system-disk image -[ $@ ]-" 220 221$(INSTALLED_ANDROID_IMAGE_DATA_TARGET): \ 222 $(INSTALLED_USERDATAIMAGE_TARGET) \ 223 $(INSTALLED_CACHEIMAGE_TARGET) \ 224 $(grub_bin) \ 225 $(edit_mbr) \ 226 $(android_data_layout) 227 @echo "Creating bootable android data-disk image: $@" 228 @rm -f $@ 229 $(hide) cat $(grub_bin) > $@ 230 $(hide) $(edit_mbr) -l $(android_data_layout) -i $@ \ 231 inst_data=$(INSTALLED_USERDATAIMAGE_TARGET) \ 232 inst_cache=$(INSTALLED_CACHEIMAGE_TARGET) 233 @echo "Done with bootable android data-disk image -[ $@ ]-" 234 235 236 237###################################################################### 238# now convert the installer_img (disk image) to a VirtualBox image 239 240INSTALLED_VBOX_INSTALLER_IMAGE_TARGET := $(PRODUCT_OUT)/installer.vdi 241virtual_box_manager := VBoxManage 242# hrd-code the UUID so we don't have to release the disk manually in the VirtualBox manager. 243virtual_box_manager_options := convertfromraw --format VDI 244virtual_box_manager_system_disk_ptions := --uuid "{aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa}" 245virtual_box_manager_data_disk_ptions := --uuid "{bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb}" 246 247$(INSTALLED_VBOX_INSTALLER_IMAGE_TARGET): $(INSTALLED_DISK_INSTALLER_IMAGE_TARGET) 248 @rm -f $(INSTALLED_VBOX_INSTALLER_IMAGE_TARGET) 249 $(hide) $(virtual_box_manager) $(virtual_box_manager_options) $(INSTALLED_DISK_INSTALLER_IMAGE_TARGET) $(INSTALLED_VBOX_INSTALLER_IMAGE_TARGET) 250 @echo "Done with VirtualBox bootable installer image -[ $@ ]-" 251 252# 253# Ditto for the android_system_disk and android_user_disk images 254# 255 256INSTALLED_VBOX_SYSTEM_DISK_IMAGE_TARGET := $(PRODUCT_OUT)/android_system_disk.vdi 257$(INSTALLED_VBOX_SYSTEM_DISK_IMAGE_TARGET): $(INSTALLED_ANDROID_IMAGE_SYSTEM_TARGET) 258 @rm -f $@ 259 $(hide) $(virtual_box_manager) \ 260 $(virtual_box_manager_options) \ 261 $(virtual_box_manager_system_disk_ptions) \ 262 $^ $@ 263 @echo "Done with VirtualBox bootable system-disk image -[ $@ ]-" 264 265INSTALLED_VBOX_DATA_DISK_IMAGE_TARGET := $(PRODUCT_OUT)/android_data_disk.vdi 266$(INSTALLED_VBOX_DATA_DISK_IMAGE_TARGET): $(INSTALLED_ANDROID_IMAGE_DATA_TARGET) 267 @rm -f $@ 268 $(hide) $(virtual_box_manager) \ 269 $(virtual_box_manager_options) \ 270 $(virtual_box_manager_data_disk_ptions) \ 271 $^ $@ 272 @echo "Done with VirtualBox bootable data-disk image -[ $@ ]-" 273 274.PHONY: installer_img 275installer_img: $(INSTALLED_DISK_INSTALLER_IMAGE_TARGET) 276 277.PHONY: installer_vdi 278installer_vdi: $(INSTALLED_VBOX_INSTALLER_IMAGE_TARGET) 279 280.PHONY: android_disk_vdi android_system_disk_vdi android_data_disk_vdi 281android_system_disk_vdi: $(INSTALLED_VBOX_SYSTEM_DISK_IMAGE_TARGET) 282android_data_disk_vdi: $(INSTALLED_VBOX_DATA_DISK_IMAGE_TARGET) 283android_disk_vdi: android_system_disk_vdi android_data_disk_vdi 284 285 286else # ! TARGET_USE_DISKINSTALLER 287INSTALLED_DISK_INSTALLER_IMAGE_TARGET := 288INSTALLED_VBOX_SYSTEM_DISK_IMAGE_TARGET := 289INSTALLED_VBOX_DATA_DISK_IMAGE_TARGET := 290endif 291endif # TARGET_ARCH == x86 292