TRENDnet AC2600 (TEW-827DRU v1.0R)

I created a new "freespace" partition in this DTS file for this latest release (OpenWRT v18.06.01/LEDE v17.01.06).

This device uses a raw 256MB SLC NAND flash chip for storage. Each UBI is 64MB in size, plus another 20MB in uboot partitions and other stuff, and finally 108MB of completely unused space on the end of the chip. This previously unused space is the new freespace partition.

This partition will probably show up as mtd 15.

Feel free to do whatever you want with this partition. The OEM system doesn't use it, and uboot doesn't know about it.

Since this partition is on raw SLC NAND, we need to use a filesystem which specifically supports it. In my case I wanted to do this with UBIFS, which is unfortunately much more complicated and troublesome than it should be. Alternatively, you could use jffs2, but that has it's own issues which I don't address here.

Here's instructions for how I did it:

opkg update
opkg install ubi-utils

cat /proc/mtd
ubiformat /dev/mtd15
ubiattach -p /dev/mtd15 -d 1
ubimkvol /dev/ubi1 -N freespace -m
ubinfo -a -d 1

# NOTE: OpenWRT/LEDE doesn't distribute mkfs.ubifs.
# The mount command will automatically format the new filesystem with a new blank fs.

mkdir /mnt/freespace
mount -t ubifs ubi1:freespace /mnt/freespace

Automatically mounting this new filesystem at boot is unfortunately not so simple. The problem is that we need to run the ubiattach command before filesystems get mounted. This is similar to the way LVM needs to run lvscan.

Thus, we need to create an init script that will start the UBI at boot:

echo "#!/bin/sh /etc/rc.common

start () {
        ubiattach -p /dev/mtd15 -d 1 || return 2

stop () {
        ubidetach -p /dev/mtd15 || return 2
}" > /etc/init.d/ubi_local

# Set file exec perms
chmod ugo+rx /etc/init.d/ubi_local

# Create the /etc/rc.d entries
/etc/init.d/ubi_local enable

START at 10 should be okay. Make sure this runs before fstab and anything related to mounting block devices. Also note that we don't seem to need a STOP, as the kernel seems to automatically run ubidettach on reboots.

If you don't already have the "block-mount" package installed, you will need to do that. See the fstab wiki doc for more info:

Additionally, if you want to mount via UUIDs like I do here, you will need to install the "mount-utils" package. And, though not required, installing the "blkid" package might be a good idea.

Then add your new filesystem to the /etc/config/fstab file with something like this:

# freespace UBI
config mount
	option target		/mnt/freespace
	option uuid			45dc0c61-4dd4-4b8d-92da-246a35be8c8e
	option fstype		ubifs
	# option options	rw,sync
	option enabled		1

One problem I have with this method is that the init script needs to be re-enabled after each sysupgrade because the /etc/rc.d/ links are wiped on sysupgrade. Normally a package will have an entry in "/etc/uci-defaults/" to do this automatically during the sysupgrade run-once, but we don't have that. I guess we could add "/etc/rc.d/S15ubi_local" to our "/etc/sysupgrade.conf" file, but that feels pretty hacky.

This freespace partition should survive all factory reinstall/flash-overwrites and sysupgrades, including OEM factory image restore.

Also don't be like me and freak out when you manage to copy 200MB of log files into your new 86MB partition. UBIFS includes automatic transparent compression, which makes estimating usage difficult/interesting.

1 Like