A little zenity-gui for flashing images to the neo

Dale Maggee antisol at internode.on.net
Sun Sep 7 19:19:53 CEST 2008


Rorschach wrote:
> Hi,
> I was bored and just wrote a little zenity-gui for flashing images to the neo: http://paste.ubuntuusers.de/391300/ .
>
> For the zenity-gui you need of course zenity and a bash-shell. To make the progress-bar work you need to patch dfu-util:
>   
Hi,

I was more bored and wanted to exercise my scripting skillz, so I made 
some changes to this script.

new stuff:

- ability to flash more than one image at once - the 'what do you wanna 
flash' now has checkboxes instead of radio buttons, and all your 
selections are flashed one after the other. (which i find very handy, 
stops the FR powering down while you're typing the next dfu-util 
command, or locating the next image - works great for flashing a new 
distro & kernel). if an error occurs, subsequent files will not be flashed.

- more confirmation / idiot-proofing - it now tells you what you're 
doing much more clearly (i.e: "about to flash Kernel with /foo/bar.bin, 
rootfs with /foo/bar.jffs". allows you to confirm that you chose the 
right images). also the 'choose file' dialogs tell you what you're 
browsing for

- ability for users to press 'cancel' at the various dialogs and exit 
gracefully.

- checks that dfu-util exists and is executable. I moved my dfu-util to 
/usr/local/bin, so it looks there first, but it will also check the 
current directory and prompt if it can't find it

- I wasn't a fan of patching dfu-util, and the pulsating zenity progress 
dialog drags my (prehistoric) PC to a crawl, so I disabled the progress 
bar and use the text output of dfu-util instead.

hope somebody finds it usefull, enjoy!

-Dale

---BEGIN---

#!/bin/bash
# dfu-util Image-Flashing Gui 0.2

function check_dfu {

        if [ ! -x $dfutils_path ]; then
                #look in current folder...
                if [ -x './dfu-util' ]; then
                        dfutils_path='./dfu-util'
                else
                        zenity --info --text "The dfu utility could not 
be found at $dfutils_path, or is not exceutable. Please point me to the 
dfu-util..."
                        dfutils_path=$(zenity --file-selection 
--title="Select the dfu-util executable:" --filename="$dfutils_path")
                        if [ -z "$dfutils_path" ]; then
                                echo "Cancelled!"
                                exit
                        fi
                        #check selection...
                        check_dfu
                fi
        fi
}

function perform_flash {
        # $1 - what we're flashing (for display)
        # $2 - dfu-params
        # $3 - file to flash

        echo
        echo "*** Flashing $1 with $3 ..."
        echo

        $dfutils_path $2 $3 2> $tmp_error_log_path
        # add the following line to the previous line to get back the 
zenity progress dialog:
        # | zenity --progress --pulsate --percentage=0 --title "Flashing 
$1 in progress.." --auto-close
        if [ "${PIPESTATUS[0]}" != "0" ];then
                zenity --error --text "Some error occured while flashing 
$1.\n\nError message:\n`cat $tmp_error_log_path`"
                exit
        else
                #sleep to allow dfu to reset...
                sleep 2
        fi
}

dfutils_path='/usr/local/bin/dfu-util'

check_dfu

tmp_error_log_path='/tmp/flash-error-log'

ans=$(zenity  --list --text "What do you wanna flash?" --title "dfu-util 
gui" --checklist --column "Pick" --column "Option" TRUE Root-Filesystem 
TRUE Kernel FALSE Bootloader)

if [ -z "$ans" ]; then
        #handle cancel / no selection...
        echo "Nothing to do!"
        exit
fi

txt="The flashing will now start.\n\nMake sure your Neo is connected to 
the USB-Device and booted into the Nor (for kernel and rootfs) or Nand 
(for u-boot) screen before proceeding.\nRemember that flashing a large 
image like a rootfs will take some time so don't abort it.\n\n"

if [ -n "`echo $ans | grep Root-Filesystem`" ];then
        du_param_r='-a rootfs -R -D'
        rootfs=True
        img_file_r=$(zenity --file-selection --title="Select an 
image-file for the ROOTFS:")
        if [ "$img_file_r" = "" ]; then
                echo "Cancelled!"
                exit
        fi
        txt="$txt - Flashing rootfs with $img_file_r \n\n"
fi

if [ -n "`echo $ans | grep Kernel`" ];then
        du_param_k='-a kernel -R -D'
        kernel=True
        img_file_k=$(zenity --file-selection --title="Select an 
image-file for the KERNEL:")
        if [ "$img_file_k" = "" ]; then
                echo "Cancelled!"
                exit
        fi
        txt="$txt - Flashing kernel with $img_file_k \n\n"
fi

if [ -n "` echo $ans | grep Bootloader`" ];then
        du_param_u='-a u-boot -R -D'
        uboot=True
        img_file_u=$(zenity --file-selection --title="Select an 
image-file for UBOOT:")
        if [ "$img_file_u" = "" ]; then
                echo "Cancelled!"
                exit
        fi
        txt="$txt - Flashing uboot with $img_file_u \n\n"
fi

touch $tmp_error_log_path

zenity --info --text "$txt"

if [ "$rootfs" = True ]; then
        perform_flash rootfs "$du_param_r" "$img_file_r"
fi

if [ "$kernel" = True ]; then
        perform_flash kernel "$du_param_k" "$img_file_k"
fi

if [ "$uboot" = True ]; then
        perform_flash uboot "$du_param_u" "$img_file_u"
fi

rm $tmp_error_log_path
exit 0

---END




More information about the community mailing list