I hope you can publish without me having to register in the forum.
I have an SD card, I don't know eMMC (so I never used it), I use a USB SD adapter, maybe there is something similar for eMMS fstrim:
But what I noticed, since you sometimes have to flash it again, it it may be that it no longer works with the boot. The first bootbits are then not at the desired address in the file system on the SD where the boot process wants to access. The remedy for me with an SD card is always to trim the SD card. I don't know if it works for eMMC.
Note: /!\ !!
================================================== ==================================================
The correct device must be selected, otherwise you will delete your normal computer. As Attention /!\ !!
fstrim can only trim mounted filesystems.
PS: A SWAP partition cannot be edited by fstrim. The SWAP must be maintained via fstab with the discard option.
Example /etc/fstab:
# swap was on /dev/nvme0n1p5 during installation
UUID=1346a3ab-57fc-4484-86c1-*******1e0 none swap sw,discard 0 0
However, the images that write normally to the SD card do not work with SWAP partition, so that doesn't concern us.
================================================== ===================================================
Here's how I do it: In the example I'm talking about my device, i.e. /dev/sdb (note you have to take what your SD card is)
The SD card is plugged into the USB SD adapter on the normal computer
sudo mkdir -p /mnt/tmp (you can leave /mnt/tmp if you need a tmp mount point again)
Only one umount would be necessary, but both as an example, if necessary, check sudo mount to see if it hangs where.
sudo umount /dev/sdb1
sudo umount /dev/sdb
wipefs -a /dev/sdb (very dangerous command, it just wipes out everything from entries in the MBR)
sudo mkfs.ext4 /dev/sdb (that means everything becomes ext4 also the MBR, I want that because of the trim)
sudo mount /dev/sdb /mnt/tmp (now I mount that temporarily)
sudo fstrim -a (this trims everything that is mounted)
sudo umount /dev/sdb
Now you can flash again.....
Example: (I got the image from the community, decompressing the .xz first with unxz file)
chris@z240:~/Downloads/OrangePiZero2/ArmBian$ sudo dd if=Armbian_23.02.0-trunk_Orangepizero2_sid_edge_6.1.0.img of=/dev/sdb bs=1M conv=fsync
2276+0 records 2276+0 records out 2386558976 bytes (2.4 GB, 2.2 GiB) copied, 228,217 s, 10.5 MB/s
Much luck