build/scripts/sunxi-musb

39 lines
1 KiB
Bash

#!/bin/bash
#
#
# sunxi_musb
#
# Patches Device Tree Blob to modify dr_mode - function of the OTG port
#
# Usage: filename.dtb otg | host
#
# It searches for dtb files in /boot/dtb
#
# It's a part of Armbian project.
if [[ -z $1 ]]; then
echo -e "OTG / HOST changer for DTB v1.0"
echo -e "\n`basename "$0"` filename.dtb otg | host"
echo -e ""
echo -e "\e[0;32mUsage example:\x1B[0m `basename "$0"` sun4i-a10-mini-xplus.dtb otg"
echo -e
exit
fi
[[ ! -f "/boot/dtb/$1" ]] && echo -e "[\e[0;31m Device tree blob /boot/dtb/$1 not found \x1B[0m]"
if [[ $2 != "otg" && $2 != "host" ]]; then
echo -e "[\e[0;31m error \x1B[0m] Unkown parameter $2"
exit 2
fi
( dtc -I dtb -O dts /boot/dtb/$1 | grep dr_mode ) > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "[\e[0;31m error \x1B[0m] dr_mode undefined in /boot/dtb/$1"
exit 1
fi
dtc -I dtb -O dts /boot/dtb/$1 | sed -e "s/dr_mode =.*/dr_mode = \"$2\";/" | dtc -I dts -O dtb -o /boot/dtb/$1
echo -e "[\e[0;32m o.k. \x1B[0m] $2 mode enabled in /boot/dtb/$1"