#!/bin/bash # This script is used to update the firmware of the card FOR Audio card only (Alpxxy) with x and y are numbers. # Param 1 : mtd partition number of the "fw-user-updatable", see /proc/mtd file and select # the one of the to be updated card. #Param 2 : firmware complete filepath #NOTE : use BASH read, SH read : follow https://stackoverflow.com/questions/226703/how-do-i-prompt-for-yes-no-cancel-input-in-a-linux-shell-script user_manual(){ echo "Param 1 : mtd partition number of the \"fw-user-updatable\", see /proc/mtd file and select" echo "Param 2 : firmware complete filepath" echo "Check user can write to the mtd partition's file" return 0 } ## MAIN ## # warn about supported card #Warn about the card supported model : Alp Audio card. read -r -n 1 -p "WARNING: This is only for AUDIO based Alp cards (ie Alp222, Alp882 and Alp442) update ? [y/N]:" user_resp echo # (optional) move to a new line if [[ ! "$user_resp" =~ ^[Yy]$ ]] then # handle exits from shell or function but don't exit interactive shell [[ "$0" = "$BASH_SOURCE" ]] && echo "CANCELED by User" && exit 1 || return 1 fi #Check parameters [ "$#" -ne "2" ] && user_manual && exit 1 fw_partition_path="$1" source_fw_file="$2" # /dev/mtd is a character device [ ! -c "$fw_partition_path" ] && echo "$fw_partition_path Not a C Device" && exit 2 #Write access ? [ ! -w "$fw_partition_path" ] && echo "Not writeable" && exit 2 # firmware file condition [ ! -e "$source_fw_file" ] && user_manual && exit 2 [ ! -f "$source_fw_file" ] && user_manual && exit 2 [ ! -s "$source_fw_file" ] && user_manual && exit 2 [ ! -r "$source_fw_file" ] && user_manual && exit 2 #Check available space !! TODO # It Requires firmware size + 4kB for the extracted HEADER. #read : BASH extensions used ! read -r -n 1 -p Writing\ "$source_fw_file"\ to\ "$fw_partition_path ? [y/N]: " user_resp echo # (optional) move to a new line if [[ ! "$user_resp" =~ ^[Yy]$ ]] then # handle exits from shell or function but don't exit interactive shell [[ "$0" = "$BASH_SOURCE" ]] && echo "CANCELED by User" && exit 1 || return 1 fi dd if="$source_fw_file" of=fw_header.bin bs=4096 count=1 status=none if [ "$?" -ne "0" ] ; then echo "Error when preparing the firmware, check disk size please." exit 4; fi dd if="$source_fw_file" of=fw_body.bin bs=4096 skip=1 seek=1 status=none if [ "$?" -ne "0" ] ; then echo "Error when preparing the firmware, check disk size please." exit 4; fi echo "Updating first phase ..." cat fw_body.bin > "$fw_partition_path" if [ "$?" -ne "0" ] ; then echo "!! Update failed DON'T poweroff, correct to retry." rm -f fw_body.bin fw_header.bin exit 3; fi echo "Updating second phase ..." cat fw_header.bin > "$fw_partition_path" if [ "$?" -ne "0" ] ; then echo "!! Update failed DON'T poweroff, correct to retry." rm -f fw_body.bin fw_header.bin exit 3; fi echo "Update SUCCEEDED" rm -f fw_body.bin fw_header.bin exit 0