diff options
author | Christian Pointner <equinox@helsinki.at> | 2024-05-10 18:26:46 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2024-05-10 18:26:46 (GMT) |
commit | 627f7d488817e308d6f3a92fd9a877723ac7ae1d (patch) | |
tree | 554a3c53c90b20da5bd0da0c8da67a9b169bd10f /snd-alpx/tools |
import snd-alpx V3.4.3
Diffstat (limited to 'snd-alpx/tools')
-rwxr-xr-x | snd-alpx/tools/audio_card_update_firmware.sh | 99 | ||||
-rwxr-xr-x | snd-alpx/tools/build-load-script.sh | 111 | ||||
-rwxr-xr-x | snd-alpx/tools/build_driver_pkg.sh | 28 | ||||
-rwxr-xr-x | snd-alpx/tools/build_virtual_board_alsa_conf.sh | 79 |
4 files changed, 317 insertions, 0 deletions
diff --git a/snd-alpx/tools/audio_card_update_firmware.sh b/snd-alpx/tools/audio_card_update_firmware.sh new file mode 100755 index 0000000..9dfa0c7 --- /dev/null +++ b/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 diff --git a/snd-alpx/tools/build-load-script.sh b/snd-alpx/tools/build-load-script.sh new file mode 100755 index 0000000..76e0174 --- /dev/null +++ b/snd-alpx/tools/build-load-script.sh @@ -0,0 +1,111 @@ +#!/bin/bash +#This script will build the manual launch script for the Alpx cards' driver. + +TEXT_BOLD="\e[1m" +TEXT_BLUE="\e[34m" +TEXT_RED="\e[31m" +TEXT_RESET="\e[0m" + +manual_load_script_name="$1" +ALPX_SOUND_DRIVER_NAME="snd-alpx.ko" +ALPX_DMA_DRIVER_NAME="snd-alpx-xdma.ko" + +OPTIONS_REQUIRED=("CONFIG_MTD" "CONFIG_DMA_VIRTUAL_CHANNELS" "CONFIG_SND_PCM") +OPTIONS_OPTIONAL=("CONFIG_SND_DMAENGINE_PCM") + +module_for_option() +{ + option=$1 + + case $option in + "CONFIG_MTD") + echo "mtd" + ;; + "CONFIG_DMA_VIRTUAL_CHANNELS") + echo "virt-dma" + ;; + "CONFIG_SND_DMAENGINE_PCM") + echo "snd-pcm-dmaengine" + ;; + "CONFIG_SND_PCM") + echo "snd-pcm" + ;; + esac +} + +required_module_entry() +{ + option=$1 + module_name=$( module_for_option "$option" ) + + echo -e $TEXT_BOLD$TEXT_BLUE"Option $option was built as a module and will be loaded" + echo -e "echo 'loading required module : $module_name'" >> $manual_load_script_name + echo -e "modprobe $module_name" >> $manual_load_script_name +} + +build_launch_script() +{ + list=$( cat - ) + + if [ -f "$manual_load_script_name" ] + then + rm "$manual_load_script_name" + echo -e "#!/bin/bash" >> $manual_load_script_name + fi + + for option in ${OPTIONS_REQUIRED[@]} + do + match_y=$( echo "$list" | grep -P "^$option=y" ) + match_m=$( echo "$list" | grep -P "^$option=m" ) + + if [ -z "$match_y" ] && [ -z "$match_m" ] + then + echo -e $TEXT_BOLD$TEXT_RED"Missing required option $option!"$TEXT_RESET + return 1 + fi + + if [ -n "$match_m" ] + then + required_module_entry "$option" + fi + done + + for option in ${OPTIONS_OPTIONAL[@]} + do + match_m=$( echo "$list" | grep -P "^$option=m" ) + + if [ -n "$match_m" ] + then + required_module_entry "$option" + fi + done + + + + if [ -f "$manual_load_script_name" ] + then + chmod u+x "$manual_load_script_name" + fi + + #NO> add the drivers entries themselves + echo -e "echo 'loading the dma driver : $ALPX_DMA_DRIVER_NAME '" >> $manual_load_script_name + echo -e "insmod $ALPX_DMA_DRIVER_NAME" >> $manual_load_script_name + echo -e "echo 'loading the sound driver : $ALPX_SOUND_DRIVER_NAME '" >> $manual_load_script_name + echo -e "insmod $ALPX_SOUND_DRIVER_NAME" >> $manual_load_script_name + + + echo -e $TEXT_RESET +} + +config_path="/boot/config"-$( uname -r ) + +if [ -f "/proc/config.gz" ] +then + cat /proc/config.gz | gunzip | build_launch_script +elif [ -f "$config_path" ] +then + cat "$config_path" | build_launch_script +else + echo "No config path found, unable to check!" >&2 + exit 1 +fi diff --git a/snd-alpx/tools/build_driver_pkg.sh b/snd-alpx/tools/build_driver_pkg.sh new file mode 100755 index 0000000..ef568bd --- /dev/null +++ b/snd-alpx/tools/build_driver_pkg.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +#This script will create the driver source archive with the given tag, name compilant with dkms +# and put it in the destination dir + +print_help() { + echo -e "This script requires 2 parameters : \n\t 1: version tag \n\t 2: destination directory" +} + +## MAIN ## +#Check parameters +echo "starting $0 with $#" + +[ ! "$#" -eq "2" ] && print_help && exit 1 + +version_tag=$1 +dest_dir=$2 + +##Handle HEAD as a Special value +if [ "$version_tag" == "HEAD" ] +then + version=$version_tag +else + version=${version_tag:2} +fi + +echo "get ready for the archive V: $version_tag, from tag: $version_tag to $dest_dir/snd-alpx-$version.zip ..." +git archive --format=zip -9 --prefix="snd-alpx-$version/" "$version_tag" > "$dest_dir/snd-alpx-$version.zip" diff --git a/snd-alpx/tools/build_virtual_board_alsa_conf.sh b/snd-alpx/tools/build_virtual_board_alsa_conf.sh new file mode 100755 index 0000000..3e8a605 --- /dev/null +++ b/snd-alpx/tools/build_virtual_board_alsa_conf.sh @@ -0,0 +1,79 @@ +#!/bin/bash +## This script will print an asoundrc stream which add virtual boards from one physical board. +## Output must be directed into a file to be stored + +### FUNCTIONS ### +user_manual() { + echo "Required Parameters + 1. Phy board id like "hw:CARD=Alp882e,DEV=0" + 2. Phy board channels quantity + 3. Virtual boards base name like : \"Emulated analog Alp222\" + 4. Virtual boards channels quantities (2: stéréo, ...)" >&2 +} + + +build_phy_node() { + node_type=$1 + card_id=$2 + channels_qty=$3 + echo -e "pcm_slave.$node_type { \n pcm \"$card_id\"\n channels $channels_qty\n }\n" +} + +build_virtual_node() { +node_alias=$1 +node_type=$2 +node_id=$3 +ipc_key=$4 +phy_name=$5 +phy_channels_base=$6 +phy_channels_qty=$7 +description=$8 +direction=$9 + +echo -e "pcm.$node_alias$node_id { + type $node_type + ipc_key $ipc_key + ipc_key_add_uid true + slave $phy_name" + + for channel_id in $(seq 0 "$(($phy_channels_qty-1))") + do + echo -e "\tbindings.$channel_id $(($channel_id+$phy_channels_base))" + done + + + echo -e "\thint.description" \"$description \#$node_id $direction\" + echo -e "}\n" +} + +### MAIN ### + +[ "$#" -ne "4" ] && user_manual && exit 1 + +ipc_key=$(date +%N) +card_id=$1 +channels_qty=$2 +virtual_basename=$3 +stream_width=$4 +virt_qty=$(($channels_qty / $stream_width)) + +echo "#Building Alsa sound RC file for $virt_qty virtual boards of $stream_width channels from physical board $card_id with $channels_qty." + +##Build the entries first +build_phy_node "ins" "$card_id" "$channels_qty" + +for entry_idx in $(seq 0 $(($virt_qty-1))) +do + build_virtual_node "mic" "dsnoop" "$entry_idx" "$ipc_key" "ins" "$(($stream_width * $entry_idx))" "$stream_width" "virtual Alp-$stream_width" "in" +done + +##Now the outpus +build_phy_node "outs" "$card_id" "$channels_qty" + +ipc_key=$(date +%N) + +for entry_idx in $(seq 0 $(($virt_qty-1))) +do + build_virtual_node "out" "dshare" "$entry_idx" "$ipc_key" "outs" "$(($stream_width * $entry_idx))" "$stream_width" "virtual Alp-$stream_width" "out" +done + |