Use ext4 for /boot partition on Phicomm N1

Be careful when doing this, I suggest you backup your data before reformatting your /boot as ext4. Any mistake you make would potentially require a reflash of your device (or booting from USB stick to repair, at least).

Theoretically this also applies to boxes running Armbian as well as many other devices that use U-boot to boot the system.

U-boot (used by Phicomm N1 as well as many other ARM boards) itself supports loading files from ext4 filesystem. Therefore it’s possible to use ext4 as /boot‘s filesystem even if Armbian defaults this to vfat.

Note that it was reported that U-boot had issues of being slow when reading files from ext4 partitions in certain scenarios, but that’s not the case on Phicomm N1 (at least not for me). The reason could be that either Phicomm N1 is using a newer version of U-boot (IIRC N1 is using U-boot 2015+) or the files I’m placing on /boot does not span over 4 extents.

To use ext4 for /boot, the following steps need to be performed:

  1. Ensure your device is booting though firmware environment variable start_emmc_autoscript by fw_printenv start_emmc_autoscript. If you got nothing or an error from this command, you might need to reset start_autoscript by:
    fw_setenv start_autoscript 'if usb start; then run start_usb_autoscript; fi; run start_emmc_autoscript;'
  2. Instruct U-boot to load start script from an ext4 partition instead of a vfat partition. This could be done by changing firmware variable start_emmc_autoscript (I would suggest you back up the variable by saving fw_printenv‘s output beforehand.):

    You might want to check out this if fw_printenv / fw_setenv does not work on your device.

    fw_setenv start_emmc_autoscript 'if ext4load mmc 1 1020000 emmc_autoscript; then autoscr 1020000; fi;'
  3. Use ext4load instead of fatload in file /boot/emmc_autoscript, which is used by start_emmc_autoscript variable we changed in step 1.

    Generally you should already have a file named emmc_autoscript.cmd in /boot, and you would want to s/fatload/ext4load/g it. But even if you don’t, the following one should work:

    setenv env_addr "0x10400000"
    setenv kernel_addr "0x11000000"
    setenv initrd_addr "0x13000000"
    setenv dtb_mem_addr "0x1000000"
    setenv boot_start booti ${kernel_addr} ${initrd_addr} ${dtb_mem_addr}
    if ext4load mmc 1 ${env_addr} uEnv.ini; then env import -t ${env_addr} ${filesize}; if ext4load mmc 1 ${kernel_addr} ${kernel_name}; then if ext4load mmc 1 ${initrd_addr} uInitrd; then if ext4load mmc 1 ${dtb_mem_addr} ${dtb_name}; then run boot_start;fi;fi;fi;fi;

    emmc_autoscript could then be built by executing this:

    mkimage -C none -A arm64 -T script -d emmc_autoscript.cmd emmc_autoscript
  4. Backup /boot, reformat /dev/mmcblk1p1 as ext4 and copy files that were in /boot back.

    You might also need to re-label the partition if you’re using its parition label in /etc/fstab to mount it (Armbian defaults to mount /boot with LABEL=BOOT_EMMC in /etc/fstab).

  5. (Optional) Mark partition type of /dev/mmcblk1p1 as Linux:

    sfdisk --id /dev/mmcblk1 1 83

    DO NOT REBOOT THE SYSTEM EVEN IF SFDISK ASKS YOU TO. REBOOT THE SYSTEM ONLY AFTER YOU PERFORMED ALL THE STEPS BELOW, OR YOU WILL BRICK YOUR DEVICE.

    If you’re not sure whether you’d want to perform this step, skip ahead, it won’t hurt.

    This mark is not used by the filesystem driver, it’s only a mark. This step is not necessary if you don’t mind sfdisk -l list /dev/mmcblk1p1 as W95 FAT32 (LBA).

    This is what sfdisk -l would look like if you don’t perform this step:

    Device         Boot  Start      End  Sectors  Size Id Type
    /dev/mmcblk1p1      204800   466943   262144  128M  c W95 FAT32 (LBA)
    /dev/mmcblk1p2      466944 15269887 14802944  7.1G 83 Linux

    This is what it would look like if you do peform this step:

    Device         Boot  Start      End  Sectors  Size Id Type
    /dev/mmcblk1p1      204800   466943   262144  128M 83 Linux
    /dev/mmcblk1p2      466944 15269887 14802944  7.1G 83 Linux
  6. Remember to update filesystem type for /boot specified in /etc/fstab.

Run reboot now, and now the device should be booted from the ext4 /boot partition:

[root@n1-box ~]# df -hT
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/mmcblk1p1 ext4      120M   32M   80M  30% /boot
/dev/mmcblk1p2 ext4      6.9G  800M  6.1G  11% /
...

1 thought on “Use ext4 for /boot partition on Phicomm N1”

Leave a Reply

Your email address will not be published. Required fields are marked *