Appearently configfs for dynamic overlays is not a mainline kernel thing…
Anyway, I borrowed from xilinx:
https://github.com/Xilinx/linux-xlnx/blob/master/drivers/of/configfs.c
And made it part of my kernel. I now can run me script from initrd busybox, that looks like this:
#!/usr/bin/ash
# Tool for %PKGBASE% package, needs to run from initrd!
# Connect UART and when kernel starts, keep 'x' key pressed.
driver="mtk-msdc"
addr="11230000"
function get_sysmmc {
str=$(echo /sys/bus/platform/devices/${addr}.mmc/mmc_host/mmc*/mmc* | head -1)
[ -e "$str" ] && echo ${str} || echo ""
}
function get_mmcblk {
str=$(get_sysmmc)
[ ! -z "$str" ] && echo "$(basename $(ls ${str}/block | head -1))" || echo "/dev/null"
}
function get_mmctype {
str=$(get_sysmmc)
[ ! -z "$str" ] && cat ${str}/type || echo "NONE"
}
function set_sdmmc {
rmdir ${mmcdtbo}
}
function set_emmc {
cat <<EOT | tee /tmp/mmc0.dts
/dts-v1/;
/plugin/;
&mmc0 {
bus-width = <8>;
max-frequency = <200000000>;
cap-mmc-highspeed;
mmc-hs200-1_8v;
// mmc-hs400-1_8v;
// hs400-ds-delay = <0x14014>;
no-sd;
no-sdio;
status = "okay";
};
EOT
mkdir -p ${mmcdtbo}
dtc -@ -I dts -O dtb -o ${mmcdtbo}/dtbo /tmp/mmc0.dts
}
function restart_driver {
[[ "$1" == "SD" ]] && pos="UP"
[[ "$1" == "MMC" ]] && pos="DOWN"
until [[ "$(get_mmctype)" == "$1" ]]; do
echo ${addr}.mmc >/sys/bus/platform/drivers/${driver}/unbind
sleep 0.1
echo ${addr}.mmc >/sys/bus/platform/drivers/${driver}/bind
echo "Flip SD/EMMC switch ${pos} (=$1) (most near to power plug), the rest stay up!"
sleep 1.9
done
}
mount -t configfs none /sys/kernel/config
mmcblk=$(get_mmcblk)
mmcdtbo="/sys/kernel/config/device-tree/overlays/mmc0"
echo "Device = /dev/${mmcblk}"
if [[ "$(get_mmctype)" == "SD" ]]; then
mkdir -p /tmp/mnt
mount --source /dev/disk/by-partlabel/*-sdmmc-root --target /tmp/mnt
[ $? -ne 0 ] && exit
echo "Reading file $1 now..."
cp -f "/tmp/mnt$1" "/tmp/tempfile"
umount /tmp/mnt
[ $? -ne 0 ] && exit
echo "Switching to EMMC..."
set_emmc
restart_driver "MMC"
mmcblk=$(get_mmcblk)
if [ -e "/tmp/tempfile" ]; then
echo "Setting up EMMC so that ${mmcblk} is the bootdevice."
mmc bootpart enable 7 1 /dev/${mmcblk}
echo "Writing $1 to EMMC now..."
xz -dcv "/tmp/tempfile" | dd of=/dev/${mmcblk} conv=fsync,notrunc
echo "Reboot and enjoy booting from EMMC."
fi
elif [[ "$(get_mmctype)" == "MMC" ]]; then
echo "Switching back to SDMMC..."
set_sdmmc
restart_driver "SD"
mmcblk=$(get_mmcblk)
fi
Now I can write the image with HS200 speed…
Run the script again and it it possible to change back to SD.
But I cannot get HS400 to work, also without dynamic overlays, only loading 1 dtb with HS400 set, I get errors. Maybe I’m missing something in kernel 6.2.7.
[ 133.416314] mtk-msdc 11230000.mmc: Final PAD_DS_TUNE: 0x15414
[ 133.426428] mtk-msdc 11230000.mmc: Final PAD_DS_TUNE: 0x15414
[ 133.436566] mtk-msdc 11230000.mmc: Final PAD_DS_TUNE: 0x15414
[ 133.540762] mtk-msdc 11230000.mmc: Final PAD_DS_TUNE: 0x15414
[ 133.551996] mtk-msdc 11230000.mmc: Final PAD_DS_TUNE: 0x15414
[ 133.562159] mtk-msdc 11230000.mmc: Final PAD_DS_TUNE: 0x15414
[ 133.567923] I/O error, dev mmcblk0, sector 10038120 op 0x1:(WRITE) flags 0x104000 phys_seg 123 prio class 2
[ 133.568168] I/O error, dev mmcblk0, sector 10039144 op 0x1:(WRITE) flags 0x100000 phys_seg 73 prio class 2
[ 148.533725] mtk-msdc 11230000.mmc: Final PAD_DS_TUNE: 0x15414
/ # [ 148.544168] mtk-msdc 11230000.mmc: Final PAD_DS_TUNE: 0x15414
[ 148.554497] mtk-msdc 11230000.mmc: Final PAD_DS_TUNE: 0x15414
[ 148.564559] mtk-msdc 11230000.mmc: Final PAD_DS_TUNE: 0x15414
[ 148.570331] I/O error, dev mmcblk0, sector 1115648 op 0x1:(WRITE) flags 0x800 phys_seg 87 prio class 2
[ 148.584183] mtk-msdc 11230000.mmc: Final PAD_DS_TUNE: 0x15414
[ 148.594287] mtk-msdc 11230000.mmc: Final PAD_DS_TUNE: 0x15414
[ 148.604389] mtk-msdc 11230000.mmc: Final PAD_DS_TUNE: 0x15414
[ 148.608827] F2FS-fs (mmcblk0p3): do_checkpoint failed err:-5, stop checkpoint
[ 148.614491] mtk-msdc 11230000.mmc: Final PAD_DS_TUNE: 0x15414
[ 148.627342] mtk-msdc 11230000.mmc: Final PAD_DS_TUNE: 0x15414
[ 148.637446] mtk-msdc 11230000.mmc: Final PAD_DS_TUNE: 0x15414
[ 148.647547] mtk-msdc 11230000.mmc: Final PAD_DS_TUNE: 0x15414
[ 148.657648] mtk-msdc 11230000.mmc: Final PAD_DS_TUNE: 0x15414
[ 148.667613] mtk-msdc 11230000.mmc: Final PAD_DS_TUNE: 0x15414
[ 148.677575] mtk-msdc 11230000.mmc: Final PAD_DS_TUNE: 0x15414
[ 148.687536] mtk-msdc 11230000.mmc: Final PAD_DS_TUNE: 0x15414
[ 148.697445] mtk-msdc 11230000.mmc: Final PAD_DS_TUNE: 0x15414
[ 148.707408] mtk-msdc 11230000.mmc: Final PAD_DS_TUNE: 0x15414
[ 148.717369] mtk-msdc 11230000.mmc: Final PAD_DS_TUNE: 0x15414
[ 148.727337] mtk-msdc 11230000.mmc: Final PAD_DS_TUNE: 0x15414
[ 148.737299] mtk-msdc 11230000.mmc: Final PAD_DS_TUNE: 0x15414
[ 148.747260] mtk-msdc 11230000.mmc: Final PAD_DS_TUNE: 0x15414
[ 148.753031] I/O error, dev mmcblk0, sector 248464 op 0x1:(WRITE) flags 0x3800 phys_seg 1 prio class 2
[ 148.766411] mtk-msdc 11230000.mmc: Final PAD_DS_TUNE: 0x15414
[ 148.772179] I/O error, dev mmcblk0, sector 160432 op 0x1:(WRITE) flags 0x3800 phys_seg 1 prio class 2
[ 148.785497] mtk-msdc 11230000.mmc: Final PAD_DS_TUNE: 0x15414
[ 148.791272] I/O error, dev mmcblk0, sector 159904 op 0x1:(WRITE) flags 0x3800 phys_seg 1 prio class 2
[ 148.804649] mtk-msdc 11230000.mmc: Final PAD_DS_TUNE: 0x15414
[ 148.810419] I/O error, dev mmcblk0, sector 155800 op 0x1:(WRITE) flags 0x3800 phys_seg 1 prio class 2
[ 148.823791] mtk-msdc 11230000.mmc: Final PAD_DS_TUNE: 0x15414
[ 148.829561] I/O error, dev mmcblk0, sector 155648 op 0x1:(WRITE) flags 0x3800 phys_seg 1 prio class 2
[ 148.842942] mtk-msdc 11230000.mmc: Final PAD_DS_TUNE: 0x15414
[ 148.848699] I/O error, dev mmcblk0, sector 151552 op 0x1:(WRITE) flags 0x3800 phys_seg 1 prio class 2
[ 148.862073] mtk-msdc 11230000.mmc: Final PAD_DS_TUNE: 0x15414
[ 148.867831] I/O error, dev mmcblk0, sector 147784 op 0x1:(WRITE) flags 0x3800 phys_seg 2 prio class 2
[ 148.877190] I/O error, dev mmcblk0, sector 143360 op 0x1:(WRITE) flags 0x3800 phys_seg 3 prio class 2
Or do I need to change 14014 to 15414?