[Android Software/Hacking General [Developers Only]] osm0sis:
I was originally waiting for Busybox 1.31.x to go stable, but that seems to be taking forever (1.31.0 unstable has been out since early June), so let's get this update out before I have to focus on my wedding and honeymoon for the next few weeks! ;)

mtd-utils has been up on the Magisk Module Repo for a bit, but this is its Odds thread debut! I'll be updating the OP with blurb/links to it and build instructions shortly.

Also, just so people are properly aware, BasketBuild is down again, so for now Nexus Media is only available as a Magisk module from the Magisk Module Repo (it's too large to attach on xda). I had uploaded the latest version to it before it went down, so whenever it's up again, it's up.

I work on these projects in my limited time off, so if you like the progress I'm making, or enjoy anything else I've done on xda, please do hit the donate link from my profile. Thanks for your support!

UPDATE-adb.Installer.v1.0.39-signed.zip;

UPDATE-Busybox.Installer.v1.30.1-ALL-signed.zip;

UPDATE-ZipSigner.Installer.v3.0-signed.zip:

- update installer for SAR Magisk

UPDATE-Fla****.Installer.v3.6-signed.zip:

- fix false positive Magisk detection with non-Magisk Manager booted installs

- fix slot selection when used with partition detection

- support MTD /dev/bootimg and /dev/recovery char device partitions

- optimize write operations (thanks @arter97)

- fix partition detection taking only last match on older devices

- update installer for SAR Magisk

- update flash_erase, nanddump and nandwrite binaries (mtd-utils 2.1.1)

UPDATE-mtd-utils.Installer.v2.1.1-signed.zip:

- installs ARM compiles of flash_erase, nanddump and nandwrite

- use latest mtd-utils official source

- update installer for SAR Magisk

UPDATE-nano.Terminal.Editor.v4.4-signed.zip:

- update installer for SAR Magisk

- update to latest nano official source

UPDATE-Nexus.Media.Installer-signed.zip:

- fix forcing system install advanced option via .nexusmedia config file

- add noreplace advanced option to allow ROM stock sounds to remain available

- update installer for SAR Magisk

This post can double as the build instruction post for mtd-utils. :p

As with my nano-build.sh, I've made a one-stop shop script to handle it all:

~/mtd-build.sh:

#!/bin/bash
# yayo!

# mtd-build.sh
#
# osm0sis @ xda-developers
#
# requires (in addition to the default basic Ubuntu WSL packages):
# make, automake, libtool, pkg-config, libncurses5, zip, default-jre

RC=0;
MAGISK=$HOME/magisk-modules;

bold() { echo -e "\033[1m"$@"\033[0m"; }

reset() {
bold "--- Removing mtd-ndk build environment ...";
rm -rfv $MAGISK/UPDATE-mtd-utils.Installer* $(dirname $HOME/mtd-utils*/.git)/ zipsigner-*.jar mtd-utils-*.zip UPDATE-mtd-utils.Installer.*-signed.zip;
rmdir $MAGISK 2>/dev/null;
}

init() {
local zipsigner;
reset;
bold "--- Initializing mtd-ndk build environment ...";
bold "- Cloning official mtd-utils git repository at HEAD ...";
git clone git://git.infradead.org/mtd-utils;

bold "- Cloning mtd-ndk installer git repository ...";
mkdir -p $MAGISK;
git clone https://github.com/Magisk-Modules-Repo/mtd-ndk $MAGISK/UPDATE-mtd-utils.Installer;

bold "- Downloading zipsigner ...";
zipsigner="opengapps/opengapps/raw/master/scripts/zipsigner-resources/zipsigner-2.2.jar";
wget -O $HOME/$(basename $zipsigner) https://github.com/$zipsigner;
}

update() {
local curtag;
bold "--- Updating mtd-ndk ...";
git fetch --tags;
if [ "$BRANCH" ]; then
curtag=$BRANCH;
else
curtag=$(git describe --tags `git rev-list --tags --max-count=1`);
fi;
bold "- Downloading latest official mtd-utils sources at $curtag ... ";
git reset -- . > /dev/null;
git clean -df > /dev/null;
git checkout -- .;
git checkout -f $curtag 2>&1 | tail -n 1;

bold "- Setting up repository and patching for Android ...";
./autogen.sh;
autoupdate;
./autogen.sh;
echo -e 'static char* strchrnul(const char *s, int c)\n{\n\twhile (*s != 0 && *s != c)\n\t\ts++;\n\treturn (char*)s;\n}\n' > misc-utils/strchrnul.c;
sed -i "s;0;'\\\0';" misc-utils/strchrnul.c;
sed -i 's;#include "lsmtd.h";#include "lsmtd.h"\n\n#include "strchrnul.c";' misc-utils/lsmtd.c;
if [ "mtd-utils-${curtag//v/}" != "$(basename $PWD)" ]; then
cd $HOME;
mv -f $MTD mtd-utils-${curtag//v/};
fi;
}

config() {
local host sysroot opts ldflags cflags;
opts="--disable-ubihealthd --without-jffs --without-lzo --without-ubifs --without-tests --without-xattr";
ldflags="-static -Wl,--gc-sections";
cflags="-D__ANDROID_API__=21 -O3 -ffunction-sections -s";
for host in arm-linux-androideabi aarch64-linux-android; do
bold "--- Configuring $host ...";
export PATH="$(echo $HOME/x-tools/$host* | rev | cut -d\ -f1 | rev)/bin:$PATH";
./configure --host=$host $opts LD=$host-ld LDFLAGS="$ldflags" CFLAGS="$cflags";
export RC=$?;
cp -f config.status config.$host;
done;
sed -i "s;^sys_lib_search_path_spec=.*;sys_lib_search_path_spec=\'$chain/lib/gcc $chain/lib $chain/sysroot/usr/lib \';" config.status;
}

clean() {
bold "--- Cleaning ...";
make clean;
export RC=$?;
}

build() {
local host suffix;
for host in arm-linux-androideabi aarch64-linux-android; do
bold "--- Building $host ...";
export PATH="$(echo $HOME/x-tools/$host* | rev | cut -d\ -f1 | rev)/bin:$PATH";
cp -f config.$host config.status;
./config.status;
make;
export RC=$?;
case $host in
arm*) suffix=arm;;
aarch64*) suffix=arm64;;
esac;
mkdir -p out/$suffix;
cp -fpv flash_erase flash_lock flash_unlock nanddump nandwrite out/$suffix;
done;
}

bundle() {
local ver curdir modver modcode newmodver newmodcode iteration skipmodprop;
bold "--- Bundling ...";
rm -f mtd-utils-*.zip UPDATE-mtd-utils.Installer.*-signed.zip 2>/dev/null;
ver=$(echo "$MTD" | cut -d- -f3);
if [ -f "$MTD/nandwrite" ]; then
bold "- Copying new mtd-utils $ver builds ...";
curdir=$(basename $MAGISK/UPDATE-mtd-utils.Installer*);
cp -fpr $MTD/out/arm $MAGISK/$curdir/bin;
cp -fpr $MTD/out/arm64 $MAGISK/$curdir/bin;
if [ "$curdir" != "UPDATE-mtd-utils.Installer.v$ver" ]; then
mv $MAGISK/$curdir $MAGISK/UPDATE-mtd-utils.Installer.v$ver;
fi;
fi;
modver=$(grep -o "^version=.*$" $MAGISK/UPDATE-mtd-utils.Installer.*/module.prop | cut -d= -f2);
modcode=$(grep -o "^versionCode=.*$" $MAGISK/UPDATE-mtd-utils.Installer.*/module.prop | cut -d= -f2);
if [ "$ver" == "$modver" ]; then
newmodver="$modver";
newmodcode="$((modcode + 1))";
iteration=1;
else
newmodver="$ver";
newmodcode="${ver//.}0";
test ${#newmodcode} == 3 && newmodcode="$newmodcode"0;
fi;
if [ "$iteration" ]; then
echo -ne "\033[1m\n*** Update Magisk module version code ($modcode -> $newmodcode) (y/n)? \033[0m";
read n; echo;
case $n in
Y|y) ;;
*) skipmodprop=1;;
esac;
fi;
if [ ! "$skipmodprop" ]; then
sed -i -e "s/version=.*/version=$newmodver/" -e "s/versionCode=.*/versionCode=$newmodcode/" $MAGISK/UPDATE-mtd-utils.Installer.*/module.prop;
sed -i -e "s/version\".*/version\": \"$newmodver\",/" -e "s/versionCode\".*/versionCode\": \"$newmodcode\",/" $MAGISK/UPDATE-mtd-utils.Installer.*/update.json;
fi;

bold "- Packing \"mtd-utils-$ver.zip\" ...";cd
cd $MAGISK/UPDATE-mtd-utils.Installer.*;
zip -9 -x .git -x .github -x update.json -r -q $HOME/mtd-utils-$ver.zip *;
cd $HOME;
bold "- Signing as \"UPDATE-mtd-utils.Installer.v$ver-signed.zip\" ...";
java -jar zipsigner-*.jar mtd-utils-$ver.zip mtd-utils-$ver-signed.zip;
mv -f mtd-utils-$ver-signed.zip UPDATE-mtd-utils.Installer.v$ver-signed.zip 2>/dev/null;
rm -f mtd-utils-*.zip /tmp/signAPK*.tmp 2>/dev/null;
}

test ! "$1" && set -- help;
until [ ! $1 ]; do
MTD=$(readlink -f `find $HOME -maxdepth 1 -type d -name 'mtd-utils*'` 2>/dev/null);
if [ ! "$MTD" ]; then
case $1 in
help|init|reset) ;;
*) echo "mtd-build: mtd-utils repo not found, run 'init' option"; exit 1;;
esac;
elif [ "$MTD" == "$HOME/mtd-utils" -o ! -f "$MTD/configure" ]; then
case $1 in
help|init|reset|update|all) ;;
*) echo "mtd-build: mtd-utils repo not patched, run 'update' or 'all' option"; exit 1;;
esac;
fi;
case $1 in
config|build) SAVEDPATH="$PATH";;
esac;
case $1 in
init|reset|bundle) cd $HOME; $1;;
update|config|clean|build) cd $MTD; $1;;
all) set -- "$0" update config clean build bundle;;
help) echo "mtd-build.sh init update config build bundle all clean reset"; exit 1;;
*) echo "mtd-build: invalid option -- '$*'"; exit 1;;
esac;
case $1 in
config|build) export PATH="$SAVEDPATH";;
esac;
shift;
done;

exit $RC;

Only pre-req is an NDK stand-alone ARM+ARM64 cross-compiler in ~/home/x-tools/ matching arm-linux-androideabi-* and aarch64-linux-android-* (y)

Edit

: New special zip features

You may add keywords to zip filename or in a file at /data/.mtd-ndk:

1) system or System or SYSTEM to force a system installation.

2) uninstall or Uninstall or UNINSTALL to uninstall mtd from the zip's detected target location (/su/xbin > /magisk/mtd-ndk/system/xbin > /data/adb/su/xbin > /data/adb/modules/mtd-ndk/system/xbin > /system/xbin, unless system forced per above).