diff options
author | Eric Woudstra | 2023-03-21 16:14:03 +0100 |
---|---|---|
committer | Eric Woudstra | 2023-03-21 16:21:01 +0100 |
commit | 49ab34c0167e5b3781c3e361aa3f7b6954a62e75 (patch) | |
tree | 101b74aee96830e30c6455f0ff91520b572df281 /bpir-flash2emmc | |
parent | 4d519e08a630e8b6a85f35325cb82ec12987d381 (diff) | |
download | aur-49ab34c0167e5b3781c3e361aa3f7b6954a62e75.tar.gz |
Add R64 to flash script
Diffstat (limited to 'bpir-flash2emmc')
-rwxr-xr-x | bpir-flash2emmc | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/bpir-flash2emmc b/bpir-flash2emmc new file mode 100755 index 000000000000..3dfee43ae523 --- /dev/null +++ b/bpir-flash2emmc @@ -0,0 +1,104 @@ +#!/usr/bin/ash + +# Tool for %PKGBASE% package, needs to run from initrd! +# Connect UART and when kernel starts, keep 'x' key pressed. + +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 +} + +driver="mtk-msdc" +addr="11230000" +compatible="$(tr -d '\0' 2>/dev/null </proc/device-tree/compatible)" + +if [[ "$compatible" == *"bananapi"*"mediatek,mt7622"* ]]; then # BPI-R64 + mmcblk=$(get_mmcblk) + echo "EMMC Device = /dev/${mmcblk}" + mkdir -p /tmp/mnt + mount --source /dev/disk/by-partlabel/*-sdmmc-root --target /tmp/mnt + [ $? -ne 0 ] && exit + echo "Flashing file $1 now..." + dd if="/tmp/mnt$1" of=/dev/${mmcblk} bs=1M conv=fsync,notrunc + umount /tmp/mnt +elif [[ "$compatible" == *"bananapi"*"mediatek,mt7986"* ]]; then # BPI-R3 + addr="11230000" + mount -t configfs none /sys/kernel/config + mmcblk=$(get_mmcblk) + mmcdtbo="/sys/kernel/config/device-tree/overlays/mmc0" + echo "EMMC 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 +fi + +#echo "Testing on mmcblk0boot1..." +#echo 0 > /sys/block/mmcblk0boot1/force_ro +#dd if=/dev/zero of=/dev/mmcblk0boot1 + |