Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- temp_dir="/tmp/screen"
- mmc_dir="/mnt/mmc"
- sunxi_tools_dir="/opt/sunxi-tools"
- bin_file="script.bin"
- fex_file="script.fex"
- ts_file="/usr/share/X11/xorg.conf.d/20-ts.conf"
- tempfile1=/tmp/dialog_1_$$
- tempfile2=/tmp/dialog_2_$$
- tempfile3=/tmp/dialog_3_$$
- tempfile4=/tmp/dialog_4_$$
- # Define some functions
- SET_NONE() {
- #get line number
- line=$(grep -nr "screen0_output_type" $temp_dir/$fex_file | awk '{print$1}' FS=":")
- dialog --title "Confirmation" --yesno "Disable screen ?" 0 0
- case $? in
- 0)
- #replace line
- sed -i $line's/.*/screen0_output_type = 0/' $temp_dir/$fex_file
- dialog --infobox "Changes saved" 3 17
- sleep 2
- ;;
- 1|255)
- dialog --infobox "No changes done" 3 19
- sleep 2
- ;;
- esac
- }
- SET_HDMI() {
- #get line number
- line=$(grep -nr "screen0_output_type" $temp_dir/$fex_file | awk '{print$1}' FS=":")
- mode=$(grep -nr "screen0_output_mode" $temp_dir/$fex_file | awk '{print$1}' FS=":")
- dialog --backtitle "OLimeXino-A20 screen configuration" \
- --radiolist "Select screen mode:" 12 55 8 \
- 0 "480i" on \
- 1 "576i" off \
- 2 "480p" off \
- 3 "576p" off \
- 4 "720p50" off \
- 5 "720p60" off \
- 6 "1080i50" off \
- 7 "1080i60" off \
- 8 "1080p24" off \
- 9 "1080p50" off \
- 10 "1080p60" off \
- 11 "pal" off \
- 27 "1280x1024p60" off \
- 14 "ntsc" off 2> $tempfile3
- retv=$?
- choice=$(cat $tempfile3)
- # Check if ESC of CANCLE are pressed
- if [ $retv -eq 1 -o $retv -eq 255 ];
- then
- clear
- exit
- fi
- case $choice in
- 0)
- dialog --title "Confirmation" --yesno "Set HDMI to 480i ?" 0 0
- case $? in
- 0)
- #replace line
- sed -i $line's/.*/screen0_output_type = 3/' $temp_dir/$fex_file
- sed -i $mode's/.*/screen0_output_mode = 0/' $temp_dir/$fex_file
- dialog --infobox "Changes saved" 3 17
- sleep 2
- ;;
- 1|255)
- dialog --infobox "No changes done" 3 19
- sleep 2
- ;;
- esac
- ;;
- 1)
- dialog --title "Confirmation" --yesno "Set HDMI to 576i ?" 0 0
- case $? in
- 0)
- #replace line
- sed -i $line's/.*/screen0_output_type = 3/' $temp_dir/$fex_file
- sed -i $mode's/.*/screen0_output_mode = 1/' $temp_dir/$fex_file
- dialog --infobox "Changes saved" 3 17
- sleep 2
- ;;
- 1|255)
- dialog --infobox "No changes done" 3 19
- sleep 2
- ;;
- esac
- ;;
- 2)
- dialog --title "Confirmation" --yesno "Set HDMI to 480p ?" 0 0
- case $? in
- 0)
- #replace line
- sed -i $line's/.*/screen0_output_type = 3/' $temp_dir/$fex_file
- sed -i $mode's/.*/screen0_output_mode = 2/' $temp_dir/$fex_file
- dialog --infobox "Changes saved" 3 17
- sleep 2
- ;;
- 1|255)
- dialog --infobox "No changes done" 3 19
- sleep 2
- ;;
- esac
- ;;
- 3)
- dialog --title "Confirmation" --yesno "Set HDMI to 576p ?" 0 0
- case $? in
- 0)
- #replace line
- sed -i $line's/.*/screen0_output_type = 3/' $temp_dir/$fex_file
- sed -i $mode's/.*/screen0_output_mode = 3/' $temp_dir/$fex_file
- dialog --infobox "Changes saved" 3 17
- sleep 2
- ;;
- 1|255)
- dialog --infobox "No changes done" 3 19
- sleep 2
- ;;
- esac
- ;;
- 4)
- dialog --title "Confirmation" --yesno "Set HDMI to 720p50 ?" 0 0
- case $? in
- 0)
- #replace line
- sed -i $line's/.*/screen0_output_type = 3/' $temp_dir/$fex_file
- sed -i $mode's/.*/screen0_output_mode = 4/' $temp_dir/$fex_file
- dialog --infobox "Changes saved" 3 17
- sleep 2
- ;;
- 1|255)
- dialog --infobox "No changes done" 3 19
- sleep 2
- ;;
- esac
- ;;
- 5)
- dialog --title "Confirmation" --yesno "Set HDMI to 720p60 ?" 0 0
- case $? in
- 0)
- #replace line
- sed -i $line's/.*/screen0_output_type = 3/' $temp_dir/$fex_file
- sed -i $mode's/.*/screen0_output_mode = 5/' $temp_dir/$fex_file
- dialog --infobox "Changes saved" 3 17
- sleep 2
- ;;
- 1|255)
- dialog --infobox "No changes done" 3 19
- sleep 2
- ;;
- esac
- ;;
- 6)
- dialog --title "Confirmation" --yesno "Set HDMI to 1080i50 ?" 0 0
- case $? in
- 0)
- #replace line
- sed -i $line's/.*/screen0_output_type = 3/' $temp_dir/$fex_file
- sed -i $mode's/.*/screen0_output_mode = 6/' $temp_dir/$fex_file
- dialog --infobox "Changes saved" 3 17
- sleep 2
- ;;
- 1|255)
- dialog --infobox "No changes done" 3 19
- sleep 2
- ;;
- esac
- ;;
- 7)
- dialog --title "Confirmation" --yesno "Set HDMI to 1080i60 ?" 0 0
- case $? in
- 0)
- #replace line
- sed -i $line's/.*/screen0_output_type = 3/' $temp_dir/$fex_file
- sed -i $mode's/.*/screen0_output_mode = 7/' $temp_dir/$fex_file
- dialog --infobox "Changes saved" 3 17
- sleep 2
- ;;
- 1|255)
- dialog --infobox "No changes done" 3 19
- sleep 2
- ;;
- esac
- ;;
- 8)
- dialog --title "Confirmation" --yesno "Set HDMI to 1080p24 ?" 0 0
- case $? in
- 0)
- #replace line
- sed -i $line's/.*/screen0_output_type = 3/' $temp_dir/$fex_file
- sed -i $mode's/.*/screen0_output_mode = 8/' $temp_dir/$fex_file
- dialog --infobox "Changes saved" 3 17
- sleep 2
- ;;
- 1|255)
- dialog --infobox "No changes done" 3 19
- sleep 2
- ;;
- esac
- ;;
- 9)
- dialog --title "Confirmation" --yesno "Set HDMI to 1080p50 ?" 0 0
- case $? in
- 0)
- #replace line
- sed -i $line's/.*/screen0_output_type = 3/' $temp_dir/$fex_file
- sed -i $mode's/.*/screen0_output_mode = 9/' $temp_dir/$fex_file
- dialog --infobox "Changes saved" 3 17
- sleep 2
- ;;
- 1|255)
- dialog --infobox "No changes done" 3 19
- sleep 2
- ;;
- esac
- ;;
- 10)
- dialog --title "Confirmation" --yesno "Set HDMI to 1080p60 ?" 0 0
- case $? in
- 0)
- #replace line
- sed -i $line's/.*/screen0_output_type = 3/' $temp_dir/$fex_file
- sed -i $mode's/.*/screen0_output_mode = 10/' $temp_dir/$fex_file
- dialog --infobox "Changes saved" 3 17
- sleep 2
- ;;
- 1|255)
- dialog --infobox "No changes done" 3 19
- sleep 2
- ;;
- esac
- ;;
- 11)
- dialog --title "Confirmation" --yesno "Set HDMI to pal ?" 0 0
- case $? in
- 0)
- #replace line
- sed -i $line's/.*/screen0_output_type = 3/' $temp_dir/$fex_file
- sed -i $mode's/.*/screen0_output_mode = 11/' $temp_dir/$fex_file
- dialog --infobox "Changes saved" 3 17
- sleep 2
- ;;
- 1|255)
- dialog --infobox "No changes done" 3 19
- sleep 2
- ;;
- esac
- ;;
- 27)
- dialog --title "Confirmation" --yesno "Set HDMI to 1280x1024p60 ?" 0 0
- case $? in
- 0)
- #replace line
- sed -i $line's/.*/screen0_output_type = 3/' $temp_dir/$fex_file
- sed -i $mode's/.*/screen0_output_mode = 27/' $temp_dir/$fex_file
- dialog --infobox "Changes saved" 3 17
- sleep 2
- ;;
- 1|255)
- dialog --infobox "No changes done" 3 19
- sleep 2
- ;;
- esac
- ;;
- 14)
- dialog --title "Confirmation" --yesno "Set HDMI to ntsc ?" 0 0
- case $? in
- 0)
- #replace line
- sed -i $line's/.*/screen0_output_type = 3/' $temp_dir/$fex_file
- sed -i $mode's/.*/screen0_output_mode = 14/' $temp_dir/$fex_file
- dialog --infobox "Changes saved" 3 17
- sleep 2
- ;;
- 1|255)
- dialog --infobox "No changes done" 3 19
- sleep 2
- ;;
- esac
- ;;
- esac
- }
- SET_VGA() {
- #get line number
- line=$(grep -nr "screen0_output_type" $temp_dir/$fex_file | awk '{print$1}' FS=":")
- mode=$(grep -nr "screen0_output_mode" $temp_dir/$fex_file | awk '{print$1}' FS=":")
- dialog --backtitle "OLimeXino-A20 screen configuration" \
- --radiolist "Select screen mode:" 0 0 0 \
- 0 "1680x1050" off \
- 1 "1440x900" off \
- 2 "1360x768" off \
- 3 "1280x1024" off \
- 4 "1024x768" off \
- 5 "800x600" off \
- 6 "640x480" off \
- 10 "1920x1080" off \
- 11 "1280x720" on 2> $tempfile4
- retv=$?
- choice=$(cat $tempfile4)
- # Check if ESC of CANCLE are pressed
- if [ $retv -eq 1 -o $retv -eq 255 ];
- then
- clear
- exit
- fi
- case $choice in
- 0)
- dialog --title "Confirmation" --yesno "Set VGA to 1680x1050 ?" 0 0
- case $? in
- 0)
- #replace line
- sed -i $line's/.*/screen0_output_type = 4/' $temp_dir/$fex_file
- sed -i $mode's/.*/screen0_output_mode = 0/' $temp_dir/$fex_file
- dialog --infobox "Changes saved" 3 17
- sleep 2
- ;;
- 1|255)
- dialog --infobox "No changes done" 3 19
- sleep 2
- ;;
- esac
- ;;
- 1)
- dialog --title "Confirmation" --yesno "Set VGA to 1440x900 ?" 0 0
- case $? in
- 0)
- #replace line
- sed -i $line's/.*/screen0_output_type = 4/' $temp_dir/$fex_file
- sed -i $mode's/.*/screen0_output_mode = 1/' $temp_dir/$fex_file
- dialog --infobox "Changes saved" 3 17
- sleep 2
- ;;
- 1|255)
- dialog --infobox "No changes done" 3 19
- sleep 2
- ;;
- esac
- ;;
- 2)
- dialog --title "Confirmation" --yesno "Set VGA to 1360x768 ?" 0 0
- case $? in
- 0)
- #replace line
- sed -i $line's/.*/screen0_output_type = 4/' $temp_dir/$fex_file
- sed -i $mode's/.*/screen0_output_mode = 2/' $temp_dir/$fex_file
- dialog --infobox "Changes saved" 3 17
- sleep 2
- ;;
- 1|255)
- dialog --infobox "No changes done" 3 19
- sleep 2
- ;;
- esac
- ;;
- 3)
- dialog --title "Confirmation" --yesno "Set VGA to 1280x1024 ?" 0 0
- case $? in
- 0)
- #replace line
- sed -i $line's/.*/screen0_output_type = 4/' $temp_dir/$fex_file
- sed -i $mode's/.*/screen0_output_mode = 3/' $temp_dir/$fex_file
- dialog --infobox "Changes saved" 3 17
- sleep 2
- ;;
- 1|255)
- dialog --infobox "No changes done" 3 19
- sleep 2
- ;;
- esac
- ;;
- 4)
- dialog --title "Confirmation" --yesno "Set VGA to 1024x768 ?" 0 0
- case $? in
- 0)
- #replace line
- sed -i $line's/.*/screen0_output_type = 4/' $temp_dir/$fex_file
- sed -i $mode's/.*/screen0_output_mode = 4/' $temp_dir/$fex_file
- dialog --infobox "Changes saved" 3 17
- sleep 2
- ;;
- 1|255)
- dialog --infobox "No changes done" 3 19
- sleep 2
- ;;
- esac
- ;;
- 5)
- dialog --title "Confirmation" --yesno "Set VGA to 800x600 ?" 0 0
- case $? in
- 0)
- #replace line
- sed -i $line's/.*/screen0_output_type = 4/' $temp_dir/$fex_file
- sed -i $mode's/.*/screen0_output_mode = 5/' $temp_dir/$fex_file
- dialog --infobox "Changes saved" 3 17
- sleep 2
- ;;
- 1|255)
- dialog --infobox "No changes done" 3 19
- sleep 2
- ;;
- esac
- ;;
- 6)
- dialog --title "Confirmation" --yesno "Set VGA to 640x480 ?" 0 0
- case $? in
- 0)
- #replace line
- sed -i $line's/.*/screen0_output_type = 4/' $temp_dir/$fex_file
- sed -i $mode's/.*/screen0_output_mode = 6/' $temp_dir/$fex_file
- dialog --infobox "Changes saved" 3 17
- sleep 2
- ;;
- 1|255)
- dialog --infobox "No changes done" 3 19
- sleep 2
- ;;
- esac
- ;;
- 10)
- dialog --title "Confirmation" --yesno "Set VGA to 1920x1080 ?" 0 0
- case $? in
- 0)
- #replace line
- sed -i $line's/.*/screen0_output_type = 4/' $temp_dir/$fex_file
- sed -i $mode's/.*/screen0_output_mode = 10/' $temp_dir/$fex_file
- dialog --infobox "Changes saved" 3 17
- sleep 2
- ;;
- 1|255)
- dialog --infobox "No changes done" 3 19
- sleep 2
- ;;
- esac
- ;;
- 11)
- dialog --title "Confirmation" --yesno "Set VGA to 1280x720 ?" 0 0
- case $? in
- 0)
- #replace line
- sed -i $line's/.*/screen0_output_type = 4/' $temp_dir/$fex_file
- sed -i $mode's/.*/screen0_output_mode = 11/' $temp_dir/$fex_file
- dialog --infobox "Changes saved" 3 17
- sleep 2
- ;;
- 1|255)
- dialog --infobox "No changes done" 3 19
- sleep 2
- ;;
- esac
- ;;
- esac
- }
- SET_LCD() {
- dialog --backtitle "OLimeXino-A20 screen configuration" \
- --radiolist "Select screen mode:" 0 0 0 \
- "4.3" "480x272" on \
- "7.0" "800x480" off \
- "10.3" "1024x600" off 2> $tempfile2
- retv=$?
- choice=$(cat $tempfile2)
- # Check if ESC of CANCLE are pressed
- if [ $retv -eq 1 -o $retv -eq 255 ];
- then
- clear
- exit
- fi
- case $choice in
- "4.3")
- x=480
- y=272
- freq=9
- hbp=40
- ht=525
- vbp=8
- vt=576
- vspw=5
- hspw=30
- ;;
- "7.0")
- x=800
- y=480
- freq=33
- hbp=46
- ht=1055
- vbp=23
- vt=1050
- vspw=1
- hspw=30
- ;;
- "10.3")
- x=1024
- y=600
- freq=45
- hbp=160
- ht=1200
- vbp=23
- vt=1250
- vspw=2
- hspw=10
- ;;
- esac
- dialog --title "Confirmation" --yesno "Set LCD to '$x'x'$y' ?" 0 0
- case $? in
- 0)
- #Edit fex file
- line_x=$(grep -nr -m 1 "lcd_x" $temp_dir/$fex_file | awk '{print$1}' FS=":")
- line_y=$(grep -nr -m 1 "lcd_y" $temp_dir/$fex_file | awk '{print$1}' FS=":")
- line_freq=$(grep -nr -m 1 "lcd_dclk_freq" $temp_dir/$fex_file | awk '{print$1}' FS=":")
- line_hbp=$(grep -nr -m 1 "lcd_hbp" $temp_dir/$fex_file | awk '{print$1}' FS=":")
- line_ht=$(grep -nr -m 1 "lcd_ht" $temp_dir/$fex_file | awk '{print$1}' FS=":")
- line_vbp=$(grep -nr -m 1 "lcd_vbp" $temp_dir/$fex_file | awk '{print$1}' FS=":")
- line_vt=$(grep -nr -m 1 "lcd_vt" $temp_dir/$fex_file | awk '{print$1}' FS=":")
- line_vspw=$(grep -nr -m 1 "lcd_vspw" $temp_dir/$fex_file | awk '{print$1}' FS=":")
- line_hspw=$(grep -nr -m 1 "lcd_hspw" $temp_dir/$fex_file | awk '{print$1}' FS=":")
- line=$(grep -nr "screen0_output_type" $temp_dir/$fex_file | awk '{print$1}' FS=":")
- sed -i $line's/.*/screen0_output_type = 1/' $temp_dir/$fex_file
- sed -i $line_x's/.*/lcd_x = '$x'/' $temp_dir/$fex_file
- sed -i $line_y's/.*/lcd_y = '$y'/' $temp_dir/$fex_file
- sed -i $line_freq's/.*/lcd_dclk_freq = '$freq'/' $temp_dir/$fex_file
- sed -i $line_hbp's/.*/lcd_hbp = '$hbp'/' $temp_dir/$fex_file
- sed -i $line_ht's/.*/lcd_ht = '$ht'/' $temp_dir/$fex_file
- sed -i $line_vbp's/.*/lcd_vbp = '$vbp'/' $temp_dir/$fex_file
- sed -i $line_vt's/.*/lcd_vt = '$vt'/' $temp_dir/$fex_file
- sed -i $line_vspw's/.*/lcd_vspw = '$vspw'/' $temp_dir/$fex_file
- sed -i $line_hspw's/.*/lcd_hspw = '$hspw'/' $temp_dir/$fex_file
- #Edit TS
- ts_line_x=$(grep -nr -m 1 "Width" $ts_file | awk '{print$1}' FS=":")
- ts_line_y=$(grep -nr -m 1 "Height" $ts_file | awk '{print$1}' FS=":")
- sed -i $ts_line_x's/.*/\tOption "Width" "'$x'"/' $ts_file
- sed -i $ts_line_y's/.*/\tOption "Height" "'$y'"/' $ts_file
- dialog --infobox "Changes saved" 3 17
- sleep 2
- ;;
- 1|255)
- dialog --infobox "No changes done" 3 19
- sleep 2
- ;;
- esac
- }
- MAIN() {
- # Now to some fancy stuff
- dialog --backtitle "OLimeXino-A20 screen configuration" \
- --radiolist "Select output type:" 12 55 8 \
- "None" "Disable all screens" off \
- "LCD" "Set configuration for LCD" off \
- "HDMI" "Set configuration for HDMI" on \
- "VGA" "Set configuration for VGA" off 2> $tempfile1
- retv=$?
- choice=$(cat $tempfile1)
- # Check if ESC of CANCLE are pressed
- if [ $retv -eq 1 -o $retv -eq 255 ];
- then
- clear
- exit
- fi
- # Check selected option
- case $choice in
- "None") SET_NONE;;
- "LCD") SET_LCD;;
- "HDMI") SET_HDMI;;
- "VGA") SET_VGA
- esac
- }
- trap "rm -f $tempfile1" 0 1 2 5 15
- # Export PATH
- export PATH=$PATH:$sunxi_tools_dir
- # Check for /mnt/mmc
- if [ ! -d $mmc_dir ];
- then
- mkdir -p $mmc_dir
- fi
- # Check for /mnt/mmc
- if [ ! -d $temp_dir ];
- then
- mkdir -p $temp_dir
- fi
- # Mount sdcard
- mount /dev/mmcblk0p1 $mmc_dir
- # Copy current script
- cp $mmc_dir/$bin_file $temp_dir/
- # bin2fex
- bin2fex $temp_dir/$bin_file > $temp_dir/$fex_file
- # Unmount
- umount /dev/mmcblk0p1
- # Remove binfile
- rm $temp_dir/$bin_file
- MAIN
- # make the bin file
- fex2bin $temp_dir/$fex_file > $temp_dir/$bin_file
- # Mount sdcard
- mount /dev/mmcblk0p1 $mmc_dir
- # Copy current script
- cp $temp_dir/$bin_file $mmc_dir/
- # Unmount
- umount /dev/mmcblk0p1
- #rm -rf $temp_dir
- dialog --title "Reboot" --yesno "Reboot the board? " 0 0
- case $? in
- 0) reboot;;
- 1|255) clear;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement