[ONE Android Development] zaphodbeeb:
How to produce flashable f2fs roms from ext4 versions

In this post I'll take you through the process required to produce f2fs-all, mixed-f2fs flashable primary roms.This article focusses on the Katinatez rom, but it should work with any f2fs enabled rom.

I use Ubuntu 14.04 for this, so I recommend that. I have ubuntu as my main os on my laptop, but it can be installed as a vm quite easily and there are plenty of articles on how to do this elsewhere, so Im assuming that you have done this for our purposes here.

1. Download your new f2fs friendly rom. Just a quick note here on what f2fs friendly actually means. It means that the kernel in the rom has the f2fs commits built into it. This doesnt make the rom flashable to a f2fs environment but that it is capable of working as such.

2. Modify the kernel to be f2fs-all or f2fs-mixed. To do this, the first step is to extract the current boot.img file. Open the rom zip, select the boot.img and extract it to a folder ready to work on it.

3. Next we need a tool to help modify the kernel. I found this to be an easy and simple tool to use. So after download, extract it somewhere easy to find. You'll see that the folder name is a bit long-winded , so rename it to "boot-tools" once you have extracted it.

Now, you need to extract the kernel from your downloaded rom. On ubuntu this is easy. Open the rom.zip (double click), select the boot.img file and click the extract button. Now instruct it to extract to the boot tools folder you just made. You will be asked if you want to show files. Select yes, and the folder of boot-tools will be shown. Using terminal, navigate to the boot-tools folder where boot.img is located and type

bash unpackimg.sh boot.img

Dont use sudo. Its not necessary, and can make life difficult later. You will note all of the other folders shown. Open the ram-disk folder and open the fstab.bacon file. Just double click. You will see that the rom is configured to use ext4 partitions, we need to replace the content of this file with one of the following.

For f2fs-all setup.

# Android fstab file.
#<src> <mnt_point> <type> <mnt_flags and options> <fs_mgr_flags>
# The filesystem that contains the filesystem checker binary (typically /system) cannot
# specify MF_CHECK, and must come before any filesystems that do specify MF_CHECK

/dev/block/platform/msm_sdcc.1/by-name/system /system f2fs ro,noatime,nosuid,nodev,discard,nodiratime,inline_xattr,errors=recover wait
/dev/block/platform/msm_sdcc.1/by-name/userdata /data f2fs noatime,nosuid,nodev,discard,nodiratime,inline_xattr,errors=recover wait,nonremovable,encryptable=/dev/block/platform/msm_sdcc.1/by-name/reserve4
/dev/block/platform/msm_sdcc.1/by-name/cache /cache f2fs noatime,nosuid,nodev,discard,nodiratime,inline_xattr,errors=recover wait
/dev/block/platform/msm_sdcc.1/by-name/persist /persist ext4 nosuid,nodev,barrier=1,data=ordered,nodelalloc,nomblk_io_submit,errors=panic wait,check
/dev/block/platform/msm_sdcc.1/by-name/boot /boot emmc defaults defaults
/dev/block/platform/msm_sdcc.1/by-name/recovery /recovery emmc defaults defaults
/dev/block/platform/msm_sdcc.1/by-name/misc /misc emmc defaults defaults
/dev/block/platform/msm_sdcc.1/by-name/modem /firmware vfat ro,shortname=lower,uid=1000,gid=1000,dmask=227,fmask=337,context=u:object_r:firmware_file:s0 wait

/devices/platform/xhci-hcd auto vfat defaults voldmanaged=usbdisk:auto

or for f2fs-mixed setup

# Android fstab file.
#<src> <mnt_point> <type> <mnt_flags and options> <fs_mgr_flags>
# The filesystem that contains the filesystem checker binary (typically /system) cannot
# specify MF_CHECK, and must come before any filesystems that do specify MF_CHECK

/dev/block/platform/msm_sdcc.1/by-name/system /system ext4 ro,barrier=1 wait
/dev/block/platform/msm_sdcc.1/by-name/userdata /data f2fs noatime,nosuid,nodev,discard,nodiratime,inline_xattr,errors=recover wait,nonremovable,encryptable=/dev/block/platform/msm_sdcc.1/by-name/reserve4
/dev/block/platform/msm_sdcc.1/by-name/cache /cache f2fs noatime,nosuid,nodev,discard,nodiratime,inline_xattr,errors=recover wait
/dev/block/platform/msm_sdcc.1/by-name/persist /persist ext4 nosuid,nodev,barrier=1,data=ordered,nodelalloc,nomblk_io_submit,errors=panic wait,check
/dev/block/platform/msm_sdcc.1/by-name/boot /boot emmc defaults defaults
/dev/block/platform/msm_sdcc.1/by-name/recovery /recovery emmc defaults defaults
/dev/block/platform/msm_sdcc.1/by-name/misc /misc emmc defaults defaults
/dev/block/platform/msm_sdcc.1/by-name/modem /firmware vfat ro,shortname=lower,uid=1000,gid=1000,dmask=227,fmask=337,context=u:object_r:firmware_file:s0 wait

/devices/platform/xhci-hcd auto vfat defaults voldmanaged=usbdisk:auto

or for any setup. Please note that this should enable to kernel to work with any configuration of partitions (i.e. all-ext4, mixed or all f2fs). So you just need to use this for fstab

# Android fstab file.
#<src> <mnt_point> <type> <mnt_flags and options> <fs_mgr_flags>
# The filesystem that contains the filesystem checker binary (typically /system) cannot
# specify MF_CHECK, and must come before any filesystems that do specify MF_CHECK

/dev/block/platform/msm_sdcc.1/by-name/system /system ext4 ro,barrier=1 wait
/dev/block/platform/msm_sdcc.1/by-name/system /system f2fs ro,noatime,nosuid,nodev,discard,nodiratime,inline_xattr,errors=recover wait
/dev/block/platform/msm_sdcc.1/by-name/userdata /data ext4 noatime,nosuid,nodev,barrier=1,data=ordered,noauto_da_alloc,errors=panic wait,check,encryptable=/dev/block/platform/msm_sdcc.1/by-name/reserve4
/dev/block/platform/msm_sdcc.1/by-name/userdata /data f2fs noatime,nosuid,nodev,discard,nodiratime,inline_xattr,errors=recover wait,nonremovable,encryptable=/dev/block/platform/msm_sdcc.1/by-name/reserve4
/dev/block/platform/msm_sdcc.1/by-name/cache /cache ext4 noatime,nosuid,nodev,barrier=1,data=ordered,noauto_da_alloc,errors=panic wait,check
/dev/block/platform/msm_sdcc.1/by-name/cache /cache f2fs noatime,nosuid,nodev,discard,nodiratime,inline_xattr,errors=recover wait
/dev/block/platform/msm_sdcc.1/by-name/persist /persist ext4 nosuid,nodev,barrier=1,data=ordered,nodelalloc,nomblk_io_submit,errors=panic wait,check
/dev/block/platform/msm_sdcc.1/by-name/boot /boot emmc defaults defaults
/dev/block/platform/msm_sdcc.1/by-name/recovery /recovery emmc defaults defaults
/dev/block/platform/msm_sdcc.1/by-name/misc /misc emmc defaults defaults
/dev/block/platform/msm_sdcc.1/by-name/modem /firmware vfat ro,shortname=lower,uid=1000,gid=1000,dmask=227,fmask=337,context=u:object_r:firmware_file:s0 wait

/devices/platform/xhci-hcd auto vfat defaults voldmanaged=usbdisk:auto

Save the file and display the contents of boot-tools folder again (i.e. exit the ramdisk folder and go up to the boot-tools folder). Now we will generate our new reconfigured kernel, so in terminal type

bash repackimg.sh

You will see a new file appear in the boot-tools folder called image-new.img. Delete the boot.img file you placed in the boot-tools folder and rename image-new.img to boot.img.

One last thing to do here in terminal is to tidy up after ourselves so type

bash unpackimg.sh

Because we didnt specify a file to unpack this will flush out the ramdisk folders etc but then generate a gripe about no file being attached. Dont worry, it zapped the contents of the folders which is all we wanted.

4. Now we need to replace the original boot.img with our new one. So open the rom.zip, and select add file. Navigate to the boot-tools folder and select our new boot.img file. This will replace the existing boot.img file in the zip with our new one.

5. Although we have modified our kernel, the flashable rom is not yet configured to install to f2fs partitions. Most are configured to work with ext4 out of the box. To fix that we need to edit a file called updater-script. This is located in the rom in the following location META-INF – com – google – android. Double click the updater script and it will open.

In step 3 you determined if you were going to make a f2fs-all, or f2fs-mixed type flashable rom. The changes that need to be made in the updater-script file are different dependant on what flavour f2fs rom you want to make.

First, search for ext4 in the document using the search on the toolbar of the text editor. Look at these and locate lines that refer to the data partition. We dont use ext4 with data partition in the f2fs world so these need to be changed.

If you see a line like

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

It needs to be changed to

run_program("/sbin/busybox", "mount", "/data");

If you look a little further on after you will also find a line

unmount("/data");

replace this with

run_program("/sbin/busybox", "unmount", "/data");

If all you want is a mixed f2fs flashable rom then save the changes you made in the text editor. This will prompt you to update the zip file of the rom so click to update this also. Job done.

If you want to create a f2fs-all type rom there are a few more lines to be changed, as follows:

find

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

and replace them with

run_program("/sbin/busybox", "mount", "/system");

find

mount("ext4", "EMMC", "/dev/block/platform/msm_sdcc.1/by-name/system", "/system", "max_batch_time=0,commit=1,data=ordered,barrier=1,errors=panic,nodelalloc");

and replace it with

run_program("/sbin/busybox", "mount", "/system");

find

unmount("/system");

and replace them with

run_program("/sbin/busybox", "unmount", "/system");

find

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

and replace it with

run_program("/sbin/mkfs.f2fs", "/dev/block/platform/msm_sdcc.1/by-name/system");

save the file, and then save changes to the zip.

Congratulations you just produced a f2f2 installable version of an ext4 rom by modifying the kernel, and updater-script.

Happy f2fs flashing.:laugh: