diff options
author | Christian Pointner <equinox@helsinki.at> | 2024-05-10 18:56:00 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2024-05-10 18:56:00 (GMT) |
commit | af6bfbbd2496b1f5aa02b94caff4e6f988fa32c9 (patch) | |
tree | 45bebb68a0bf3bfc2fff1646f6fa0f4b976fba57 /snd-alpx-dkms/snd-alpx/tools/audio_card_update_firmware.sh | |
parent | 7035064ca063fdf15669ceb790ecef1e5ed054b0 (diff) |
rename package to snd-alpx-dkms
Diffstat (limited to 'snd-alpx-dkms/snd-alpx/tools/audio_card_update_firmware.sh')
-rwxr-xr-x | snd-alpx-dkms/snd-alpx/tools/audio_card_update_firmware.sh | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/snd-alpx-dkms/snd-alpx/tools/audio_card_update_firmware.sh b/snd-alpx-dkms/snd-alpx/tools/audio_card_update_firmware.sh new file mode 100755 index 0000000..9dfa0c7 --- /dev/null +++ b/snd-alpx-dkms/snd-alpx/tools/audio_card_update_firmware.sh @@ -0,0 +1,99 @@ +#!/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 |