WARNING: I don't believe there's a way to undo this.
The BBBW has a 4 GB eMMC. For better reliability, I'm trying to put it into pSLC mode. Since the 4 GB eMMC is an MLC Flash with 2-bits per cell, converting it to pseudo-SLC mode (1-bit per cell) halves the total size.
Here's the original eMMC information:
iex> dmesg
[ 1.701256] mmc1: new high speed MMC card at address 0001
[ 1.702070] mmcblk1: mmc1:0001 S10004 3.56 GiB
[ 1.702389] mmcblk1boot0: mmc1:0001 S10004 partition 1 4.00 MiB
[ 1.702663] mmcblk1boot1: mmc1:0001 S10004 partition 2 4.00 MiB
[ 1.702895] mmcblk1rpmb: mmc1:0001 S10004 partition 3 4.00 MiB, chardev (250:0)
iex> cat "/sys/class/block/mmcblk1/size"
7471104
To convert to pSLC mode, you need the final size in 1K blocks. The size from /sys/class/block/mmcblk1/size
is
in 512 byte blocks.
iex> floor(7471104 * 512 / 1024 / 2)
1867776
The next step is to run the command to put the eMMC into pSLC mode:
iex> cmd("mmc enh_area set -y 0 1867776 /dev/mmcblk1")
setting OTP PARTITION_SETTING_COMPLETED!
Setting OTP PARTITION_SETTING_COMPLETED on /dev/mmcblk1 SUCCESS
Device power cycle needed for settings to take effect.
Confirm that PARTITION_SETTING_COMPLETED bit is set using 'extcsd read' after power cycle
Enhanced User Data Area Size [ENH_SIZE_MULT]: 0x0001c8
i.e. 1867776 KiB
Max Enhanced Area Size [MAX_ENH_SIZE_MULT]: 0x0001c8
i.e. 1867776 KiB
Done setting ENH_USR area on /dev/mmcblk1
0
Disconnect and reconnect power.
Once you boot, dmesg
will show the eMMC as having half the original size.
iex> dmesg
[ 1.700854] mmc1: new high speed MMC card at address 0001
[ 1.701675] mmcblk1: mmc1:0001 S10004 1.78 GiB
[ 1.701997] mmcblk1boot0: mmc1:0001 S10004 partition 1 4.00 MiB
[ 1.702268] mmcblk1boot1: mmc1:0001 S10004 partition 2 4.00 MiB
[ 1.702499] mmcblk1rpmb: mmc1:0001 S10004 partition 3 4.00 MiB, chardev (250:0)
From then on, it should work like any other eMMC would:
iex> cmd("mkfs.f2fs /dev/mmcblk1")
F2FS-tools: mkfs.f2fs Ver: 1.15.0 (2022-05-13)
Info: Disable heap-based policy
Info: Debug level = 0
Info: Trim is enabled
Info: Segments per section = 1
Info: Sections per zone = 1
Info: sector size = 512
Info: total sectors = 3735552 (1824 MB)
Info: zone aligned segment0 blkaddr: 512
Info: format version with
"Linux version 5.10.120 (buildroot@buildroot) (armv7-nerves-linux-gnueabihf-gcc (crosstool-NG 1.25.0.105_0389288) 12.2.0, GNU ld (crosstool-NG 1.25.0.105_0389288) 2.39) #1 PREEMPT Thu Feb 2 14:52:14 UTC 2023"
Info: [/dev/mmcblk1] Discarding device
Info: Secure Discarded 0 MB
Info: Overprovision ratio = 4.730%
Info: Overprovision segments = 90 (GC reserved = 50)
Info: format successful
0
iex> File.mkdir("/tmp/emmc")
:ok
iex> cmd("mount /dev/mmcblk1 /tmp/emmc")
0
iex> ls "/tmp/emmc"
iex> cmd("df")
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mmcblk1 1865728 204808 1660920 11% /tmp/emmc
0