[ONE Android Development] dlhxr:
Just join the OnePlus One group yesterday from Galaxy Nexus and start porting something in Galaxy Nexus threads into OnePlus One.

Image Rom Boot under Custom Kernel​

CONTENTS：

1.Introduction

2.Image Creation

3.Kernel Modification

4.Zip Modification

5.Switch Roms

6.Wipe Data

7.Acknowledgement

8.Most Frequently Asked Questions​

Introduction​

1.Similar to MultiROM, but without kexec-hardboot patch support and makes no change to your original rom.

2.Boot your rom from image files.

/data/media/rom/system.img as system partition
/data/media/rom/data.img as data partition
/data/media/rom/cache.img as cache partition

3.Use recovery zip file to switch roms.

Image Creation​

Create images and then put them into /data/media/rom/

1.Use dd command to create images. E.g. create a image with size 500M and with name 500.img

dd if=/dev/zero bs=1M count=500 >> 500.img
mkfs.ext4 500.img

I suggest 800M for system partition, 1000M for data partition and 50M for cache partition.

Here are some pre-created images with different sizes.

View attachment 2910512

2. Rename the images to system.img, data.img and cache.img and put them into our phone /data/media/rom/

Kennel Modification​

AutoModification Script (Default image location: /rdata/media/rom/default/)

View attachment 2911936

1.Unzip boot.img from rom zip file.

2.Download mkboot tool by xiaolu to unpack the boot.img and get the ramdisk.

3.Put boot.img and tool files into the same directory.

4.Use following command to unpack.

./mkboot boot.img output

5.Get into output/ramdisk and we need to modify fstab.bacon and init.bacon.rc.

6.Find fstab.bacon and commnent the system, cache mounting line and modify data mounting line.

[COLOR="Red"]#[/COLOR]/dev/block/platform/msm_sdcc.1/by-name/system /system ext4 ro,barrier=1 wait
/dev/block/platform/msm_sdcc.1/by-name/userdata /[COLOR="Red"]r[/COLOR]data ext4 noatime,nosuid,nodev,barrier=1,data=ordered,noauto_da_alloc,journal_async_commit,errors=panic wait,check,encryptable=footer,length=-16384
[COLOR="Red"]#[/COLOR]/dev/block/platform/msm_sdcc.1/by-name/cache /cache ext4 noatime,nosuid,nodev,barrier=1,data=ordered,noauto_da_alloc,journal_async_commit,errors=panic wait,check

7.Find init.bacon.rc.

The on fs part. Add following line before mount_all ./fstab.bacon.

mkdir /rdata 0771 system system

Add following lines after mount_all ./fstab.bacon.

exec /sbin/busybox mount -t ext4 -o ro /rdata/media/rom/system.img /system
exec /sbin/busybox mount -t ext4 -o noatime,nosuid,nodev,nomblk_io_submit,errors=panic,rw /rdata/media/rom/data.img /data
exec /sbin/busybox mount -t ext4 -o noatime,nosuid,nodev,nomblk_io_submit,errors=panic,rw /rdata/media/rom/cache.img /cache

Then modify the sdcard simulation line to share the same sdcard directory.

Find # virtual sdcard daemon running as media_rw (1023) and add replace /data/media by /rdata/media

# virtual sdcard daemon running as media_rw (1023)
service sdcard /system/bin/sdcard -u 1023 -g 1023 -l /[COLOR="Red"]r[/COLOR]data/media /mnt/shell/emulated
class late_start

8.Extract the busybox binary from attachment to output/ramdisk/sbin/

View attachment 2910463

9.Repack the kernel with modified ramdisk.

./mkboot output new_boot.img

10.Pack boot.img into a zip file for recovery or we can just flash boot.img using fastboot.

Zip Modification​

AutoModification Script (Default image location: /rdata/media/rom/default/)

View attachment 2911936

Attention: AutoModification Script may not be compatible to all roms

We need to modify the rom zip file in order to install rom into images. Just modify updater-script.

1.Add following lines below the first line. assert(getprop("ro.product.device") == "bacon" || getprop("ro.build.product") == "bacon");

unmount("system");
unmount("data");
unmount("cache");
run_program("/sbin/mkdir", "/rdata");
run_program("/sbin/mount", "-t", "ext4", "/dev/block/platform/msm_sdcc.1/by-name/userdata", "/rdata");

Replace the following line

mount("ext4", "EMMC", "/dev/block/platform/msm_sdcc.1/by-name/system", "/system");

by

run_program("/sbin/losetup", "/dev/block/loop1", "/rdata/media/rom/system.img");
run_program("/sbin/mount", "-t", "ext4", "/dev/block/loop1", "/system");

Replace the following lines

format("ext4", "EMMC", "/dev/block/platform/msm_sdcc.1/by-name/system", "0", "/system");
mount("ext4", "EMMC", "/dev/block/platform/msm_sdcc.1/by-name/system", "/system");

by

run_program("/sbin/losetup", "/dev/block/loop1", "/rdata/media/rom/system.img");
run_program("/sbin/mke2fs", "-T", "ext4", "/dev/block/loop1");
run_program("/sbin/mount", "-t", "ext4", "/dev/block/loop1", "/system");

Replace the following line

mount("ext4", "EMMC", "/dev/block/platform/msm_sdcc.1/by-name/userdata", "/data");

by

run_program("/sbin/losetup", "/dev/block/loop2", "/realdata/media/rom/data.img");
run_program("/sbin/mount", "-t", "ext4", "/dev/block/loop2", "/data");

Replace the following line (not include the lines you add at first.)

unmount("data");

by

run_program("/sbin/umount", "-d", "/data");

Replace the following line (not include the lines you add at first.)

unmount("system");

by

run_program("/sbin/umount", "-d", "/system");

Delete the following line

package_extract_file("boot.img", "/dev/block/platform/omap/omap_hsmmc.0/by-name/boot");

Add the following line in the end

run_program("/sbin/umount", "/rdata");