diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..a35d22588 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ +[*.sh] +# like -i=2 +indent_style = space +indent_size = 2 + +#shell_variant = posix # like -ln=posix +#binary_next_line = true # like -bn +switch_case_indent = true # like -ci +space_redirects = true # like -sr +#keep_padding = true # like -kp diff --git a/linux/dfu-util.sh b/linux/dfu-util.sh index 9b828f090..2f355b4ce 100755 --- a/linux/dfu-util.sh +++ b/linux/dfu-util.sh @@ -4,10 +4,10 @@ # # Get the directory where the script is running. -DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) # Choose dfu program by arch -if [ `uname -m` == "x86_64" ]; then +if [ "$(uname -m)" == "x86_64" ]; then DFU_UTIL=${DIR}/dfu-util_x86_64/dfu-util else DFU_UTIL=${DIR}/dfu-util/dfu-util diff --git a/linux/install.sh b/linux/install.sh index 32870a1c2..a7cca0a6d 100755 --- a/linux/install.sh +++ b/linux/install.sh @@ -1,15 +1,14 @@ #!/bin/sh if sudo [ -w /etc/udev/rules.d ]; then - echo "Copying Maple-specific udev rules..." - sudo cp -v 45-maple.rules /etc/udev/rules.d/45-maple.rules - sudo chown root:root /etc/udev/rules.d/45-maple.rules - sudo chmod 644 /etc/udev/rules.d/45-maple.rules - echo "Reloading udev rules" - sudo udevadm control --reload-rules - echo "Adding current user to dialout group" - sudo adduser $USER dialout + echo "Copying Maple-specific udev rules..." + sudo cp -v 45-maple.rules /etc/udev/rules.d/45-maple.rules + sudo chown root:root /etc/udev/rules.d/45-maple.rules + sudo chmod 644 /etc/udev/rules.d/45-maple.rules + echo "Reloading udev rules" + sudo udevadm control --reload-rules + echo "Adding current user to dialout group" + sudo adduser "$USER" dialout else - echo "Couldn't copy to /etc/udev/rules.d/; you probably have to run this script as root? Or your distribution of Linux doesn't include udev; try running the IDE itself as root." + echo "Couldn't copy to /etc/udev/rules.d/; you probably have to run this script as root? Or your distribution of Linux doesn't include udev; try running the IDE itself as root." fi - diff --git a/linux/maple_upload b/linux/maple_upload deleted file mode 100755 index 65d31439b..000000000 --- a/linux/maple_upload +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash - -#set -e - -if [ $# -lt 4 ]; then - echo "Usage: $0 $# " >&2 - exit 1 -fi -dummy_port="$1"; altID="$2"; usbID="$3"; binfile="$4"; dummy_port_fullpath="/dev/$1" -if [ $# -eq 5 ]; then - dfuse_addr="--dfuse-address $5" -else - dfuse_addr="" -fi - - -# Get the directory where the script is running. -DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) - -# ----------------- IMPORTANT ----------------- -# The 2nd parameter to upload-reset is the delay after resetting before it exits -# This value is in milliseonds -# You may need to tune this to your system -# 750ms to 1500ms seems to work on my Mac - - -"${DIR}/upload-reset" ${dummy_port_fullpath} 750 - -"${DIR}/dfu-util.sh" -d ${usbID} -a ${altID} -D ${binfile} ${dfuse_addr} -R - -echo -n Waiting for ${dummy_port_fullpath} serial... - -COUNTER=0 -while [ ! -r ${dummy_port_fullpath} ] && ((COUNTER++ < 40)); do - sleep 0.1 -done - -echo Done diff --git a/linux/maple_upload.sh b/linux/maple_upload.sh new file mode 100755 index 000000000..6f767332e --- /dev/null +++ b/linux/maple_upload.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +#set -e + +if [ $# -lt 4 ]; then + echo "Usage: $0 $# " >&2 + exit 1 +fi +altID="$2" +usbID="$3" +binfile="$4" +dummy_port_fullpath="/dev/$1" +if [ $# -eq 5 ]; then + dfuse_addr="--dfuse-address $5" +else + dfuse_addr="" +fi + +# Get the directory where the script is running. +DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) + +# ----------------- IMPORTANT ----------------- +# The 2nd parameter to upload-reset is the delay after resetting before it exits +# This value is in milliseonds +# You may need to tune this to your system +# 750ms to 1500ms seems to work on my Mac + +"${DIR}/upload-reset" "${dummy_port_fullpath}" 750 + +"${DIR}/dfu-util.sh" -d "${usbID}" -a "${altID}" -D "${binfile}" ${dfuse_addr} -R + +echo -n Waiting for "${dummy_port_fullpath}" serial... + +COUNTER=0 +while [ ! -r "${dummy_port_fullpath}" ] && ((COUNTER++ < 40)); do + sleep 0.1 +done + +echo Done diff --git a/linux/massStorageCopy b/linux/massStorageCopy.sh similarity index 74% rename from linux/massStorageCopy rename to linux/massStorageCopy.sh index f4d864931..cf476220b 100755 --- a/linux/massStorageCopy +++ b/linux/massStorageCopy.sh @@ -1,7 +1,5 @@ #!/bin/bash -set -o nounset # Treat unset variables as an error -#set -x -VERSION="0.1" +set -o nounset # Treat unset variables as an error # List bin_filepath= @@ -10,11 +8,10 @@ mountpoint_path= ############################################################################### ## Help function -usage() -{ +usage() { echo "############################################################" echo "##" - echo "## `basename $0` [-I ] [-O ]" + echo "## $(basename "$0") [-I ] [-O ]" echo "##" echo "## Options:" echo "## -I: filepath binary to copy" @@ -32,29 +29,29 @@ if [ $# -lt 2 ]; then fi # Parsing options -if [ $1 == "-I" ]; then +if [ "$1" == "-I" ]; then shift 1 fi bin_filepath=$1 -if [ $2 == "-O" ]; then +if [ "$2" == "-O" ]; then shift 1 fi # Strip first and last "" mountpoint_name="${2%\"}" mountpoint_name="${mountpoint_name#\"}" -if [ -z $bin_filepath ]; then +if [ -z "$bin_filepath" ]; then echo "No binary file path provided!" exit 1 fi -if [ -z $mountpoint_name ]; then +if [ -z "$mountpoint_name" ]; then echo "No mountpoint name provided!" exit 1 fi -if [ ! -f $bin_filepath ]; then +if [ ! -f "$bin_filepath" ]; then echo "$bin_filepath not found!" exit 2 fi @@ -63,11 +60,11 @@ fi IFS=',' read -ra mnt_list <<< "$mountpoint_name" for mnt in "${mnt_list[@]}"; do # mnt_path_list=(`cat /proc/mounts | cut -d' ' -f2 | sort -u | grep $mnt`) - mnt_path_list=(`df -Hl | grep -v "Mounted on" | rev | cut -d' ' -f1 | rev | sort -u | grep $mnt`) + mnt_path_list=($(df -Hl | grep -v "Mounted on" | rev | cut -d' ' -f1 | rev | sort -u | grep "$mnt")) if [ ${#mnt_path_list[@]} -ne 0 ]; then # Ensure to have exact match for mnt_path in "${mnt_path_list[@]}"; do - mnt_name=`echo $mnt_path | rev | cut -d'/' -f1 | rev` + mnt_name=$(echo "$mnt_path" | rev | cut -d'/' -f1 | rev) if [ "$mnt_name" = "$mnt" ]; then echo "Found '$mnt' at '$mnt_path'" mountpoint_path=$mnt_path @@ -77,7 +74,7 @@ for mnt in "${mnt_list[@]}"; do fi done -if [ -z $mountpoint_path ] || [ ! -d $mountpoint_path ]; then +if [ -z "$mountpoint_path" ] || [ ! -d "$mountpoint_path" ]; then echo "$mountpoint_name not found." echo "Please ensure the device is correctly connected and mounted." exit 3 @@ -85,6 +82,6 @@ fi # Copy the binary to the mountpoint echo "Copying $bin_filepath to $mountpoint_path..." -cp $bin_filepath $mountpoint_path +cp "$bin_filepath" "$mountpoint_path" exit $? diff --git a/linux/stm32CubeProg.sh b/linux/stm32CubeProg.sh index 1d2adeacf..9d131c3a1 100755 --- a/linux/stm32CubeProg.sh +++ b/linux/stm32CubeProg.sh @@ -1,20 +1,18 @@ #!/bin/bash -set -o nounset # Treat unset variables as an error -#set -x +set -o nounset # Treat unset variables as an error STM32CP_CLI=STM32_Programmer.sh ADDRESS=0x8000000 -ERASE= -MODE= -PORT= -OPTS= +ERASE="" +MODE="" +PORT="" +OPTS="" ############################################################################### ## Help function -usage() -{ +usage() { echo "############################################################" echo "##" - echo "## `basename $0` [OPTIONS]" + echo "## $(basename "$0") [OPTIONS]" echo "##" echo "## protocol:" echo "## 0: SWD" @@ -34,17 +32,14 @@ usage() echo "## -rst: Reset system" echo "## -s: start automatically (optional)" echo "############################################################" - exit $1 + exit "$1" } - check_tool() { - command -v $STM32CP_CLI >/dev/null 2>&1 - if [ $? != 0 ]; then + if ! command -v $STM32CP_CLI > /dev/null 2>&1; then export PATH="$HOME/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin":$PATH fi - command -v $STM32CP_CLI >/dev/null 2>&1 - if [ $? != 0 ]; then + if ! command -v $STM32CP_CLI > /dev/null 2>&1; then echo "$STM32CP_CLI not found." echo "Please install it or add '/bin' to your PATH environment:" echo "https://www.st.com/en/development-tools/stm32cubeprog.html" @@ -56,8 +51,8 @@ check_tool() { check_tool if [ $# -lt 2 ]; then - echo "Not enough arguments!" - usage 2 + echo "Not enough arguments!" + usage 2 fi # Parse options @@ -65,8 +60,8 @@ PROTOCOL=$1 FILEPATH=$2 # Protocol $1 # 1x: Erase all sectors -if [ $1 -ge 10 ]; then - ERASE='-e all' +if [ "$1" -ge 10 ]; then + ERASE="yes" PROTOCOL=$(($1 - 10)) fi # Protocol $1 @@ -75,29 +70,32 @@ fi # 2: DFU case $PROTOCOL in 0) - PORT='SWD' - MODE='mode=UR' - shift 2;; + PORT="SWD" + MODE="mode=UR" + shift 2 + ;; 1) if [ $# -lt 3 ]; then usage 3 else PORT=$3 shift 3 - fi;; + fi + ;; 2) - PORT='USB1' - shift 2;; + PORT="USB1" + shift 2 + ;; *) echo "Protocol unknown!" - usage 4;; + usage 4 + ;; esac if [ $# -gt 0 ]; then - OPTS="$@" + OPTS="$*" fi -${STM32CP_CLI} -c port=${PORT} ${MODE} ${ERASE} -q -d ${FILEPATH} ${ADDRESS} ${OPTS} - -exit 0 +${STM32CP_CLI} -c port=${PORT} ${MODE} ${ERASE:+"-e all"} -q -d "${FILEPATH}" ${ADDRESS} "${OPTS}" +exit $? diff --git a/macosx/maple_upload b/macosx/maple_upload.sh similarity index 59% rename from macosx/maple_upload rename to macosx/maple_upload.sh index 3521aa1ef..5e567e02c 100755 --- a/macosx/maple_upload +++ b/macosx/maple_upload.sh @@ -3,15 +3,16 @@ set -e if [ $# -lt 4 ]; then - echo "Usage: $0 $# " >&2 - exit 1 + echo "Usage: $0 $# " >&2 + exit 1 fi -dummy_port=$1; altID=$2; usbID=$3; binfile=$4;dummy_port_fullpath="/dev/$1" - +altID=$2 +usbID=$3 +binfile=$4 +dummy_port_fullpath="/dev/$1" # Get the directory where the script is running. -DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) - +DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) # ----------------- Old code to reset the USB - which doesn't seem to work -------- # @@ -31,32 +32,32 @@ DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) # You may need to tune this to your system # 750ms to 1500ms seems to work on my Mac -${DIR}/upload-reset ${dummy_port_fullpath} 750 +"${DIR}"/upload-reset "${dummy_port_fullpath}" 750 if [ $# -eq 5 ]; then - dfuse_addr="--dfuse-address $5" + dfuse_addr="--dfuse-address $5" else - dfuse_addr="" + dfuse_addr="" fi #DFU_UTIL=/usr/local/bin/dfu-util DFU_UTIL=${DIR}/dfu-util/dfu-util -if [ ! -x ${DFU_UTIL} ]; then - DFU_UTIL=/opt/local/bin/dfu-util +if [ ! -x "${DFU_UTIL}" ]; then + DFU_UTIL=/opt/local/bin/dfu-util fi if [ ! -x ${DFU_UTIL} ]; then - echo "$0: error: cannot find ${DFU_UTIL}" >&2 - exit 2 + echo "$0: error: cannot find ${DFU_UTIL}" >&2 + exit 2 fi -${DFU_UTIL} -d ${usbID} -a ${altID} -D ${binfile} -R ${dfuse_addr} -R +${DFU_UTIL} -d "${usbID}" -a "${altID}" -D "${binfile}" -R ${dfuse_addr} -R -echo -n Waiting for ${dummy_port_fullpath} serial... +echo -n Waiting for "${dummy_port_fullpath}" serial... COUNTER=0 -while [ ! -c ${dummy_port_fullpath} ] && ((COUNTER++ < 40)); do - sleep 0.1 +while [ ! -c "${dummy_port_fullpath}" ] && ((COUNTER++ < 40)); do + sleep 0.1 done echo Done diff --git a/macosx/massStorageCopyMacOsX b/macosx/massStorageCopy.sh similarity index 73% rename from macosx/massStorageCopyMacOsX rename to macosx/massStorageCopy.sh index c994b3229..abc8869ae 100755 --- a/macosx/massStorageCopyMacOsX +++ b/macosx/massStorageCopy.sh @@ -1,7 +1,5 @@ #!/bin/bash -set -o nounset # Treat unset variables as an error -#set -x -VERSION="0.1" +set -o nounset # Treat unset variables as an error # List bin_filepath= @@ -10,11 +8,10 @@ mountpoint_path= ############################################################################### ## Help function -usage() -{ +usage() { echo "############################################################" echo "##" - echo "## `basename $0` [-I ] [-O ]" + echo "## $(basename "$0") [-I ] [-O ]" echo "##" echo "## Options:" echo "## -I: filepath binary to copy" @@ -32,29 +29,29 @@ if [ $# -lt 2 ]; then fi # Parsing options -if [ $1 == "-I" ]; then +if [ "$1" == "-I" ]; then shift 1 fi bin_filepath=$1 -if [ $2 == "-O" ]; then +if [ "$2" == "-O" ]; then shift 1 fi # Strip first and last "" mountpoint_name="${2%\"}" mountpoint_name="${mountpoint_name#\"}" -if [ -z $bin_filepath ]; then +if [ -z "$bin_filepath" ]; then echo "No binary file path provided!" exit 1 fi -if [ -z $mountpoint_name ]; then +if [ -z "$mountpoint_name" ]; then echo "No mountpoint name provided!" exit 1 fi -if [ ! -f $bin_filepath ]; then +if [ ! -f "$bin_filepath" ]; then echo "$bin_filepath not found!" exit 2 fi @@ -62,11 +59,11 @@ fi # Search the mountpoint IFS=',' read -ra mnt_list <<< "$mountpoint_name" for mnt in "${mnt_list[@]}"; do - mnt_path_list=(`df -Hl | grep -v "Mounted on" | rev | cut -d' ' -f1 | rev | sort -u | grep $mnt`) + mnt_path_list=($(df -Hl | grep -v "Mounted on" | rev | cut -d' ' -f1 | rev | sort -u | grep "$mnt")) if [ ${#mnt_path_list[@]} -ne 0 ]; then # Ensure to have exact match for mnt_path in "${mnt_path_list[@]}"; do - mnt_name=`echo $mnt_path | rev | cut -d'/' -f1 | rev` + mnt_name=$(echo "$mnt_path" | rev | cut -d'/' -f1 | rev) if [ "$mnt_name" = "$mnt" ]; then echo "Found '$mnt' at '$mnt_path'" mountpoint_path=$mnt_path @@ -76,7 +73,7 @@ for mnt in "${mnt_list[@]}"; do fi done -if [ -z $mountpoint_path ] || [ ! -d $mountpoint_path ]; then +if [ -z "$mountpoint_path" ] || [ ! -d "$mountpoint_path" ]; then echo "$mountpoint_name not found." echo "Please ensure the device is correctly connected and mounted." exit 3 @@ -84,6 +81,6 @@ fi # Copy the binary to the mountpoint echo "Copying $bin_filepath to $mountpoint_path..." -cp $bin_filepath $mountpoint_path +cp "$bin_filepath" "$mountpoint_path" exit $? diff --git a/macosx/stm32CubeProg b/macosx/stm32CubeProg.sh similarity index 74% rename from macosx/stm32CubeProg rename to macosx/stm32CubeProg.sh index 4dda68c1d..aa0037f27 100755 --- a/macosx/stm32CubeProg +++ b/macosx/stm32CubeProg.sh @@ -1,21 +1,20 @@ #!/bin/bash -set -o nounset # Treat unset variables as an error +set -o nounset # Treat unset variables as an error STM32CP_CLI=STM32_Programmer_CLI ADDRESS=0x8000000 -ERASE= -MODE= -PORT= -OPTS= +ERASE="" +MODE="" +PORT="" +OPTS="" ############################################################################### ## Help function -usage() -{ +usage() { echo "############################################################" echo "##" - echo "## `basename $0` [OPTIONS]" + echo "## $(basename "$0") [OPTIONS]" echo "##" - echo "## protocol: " + echo "## protocol:" echo "## 0: SWD" echo "## 1: Serial" echo "## 2: DFU" @@ -33,17 +32,14 @@ usage() echo "## -rst: Reset system" echo "## -s: start automatically (optional)" echo "############################################################" - exit $1 + exit "$1" } - check_tool() { - command -v $STM32CP_CLI >/dev/null 2>&1 - if [ $? != 0 ]; then + if ! command -v $STM32CP_CLI > /dev/null 2>&1; then export PATH="/Applications/STMicroelectronics/STM32Cube/STM32CubeProgrammer/STM32CubeProgrammer.app/Contents/MacOs/bin":$PATH fi - command -v $STM32CP_CLI >/dev/null 2>&1 - if [ $? != 0 ]; then + if ! command -v $STM32CP_CLI > /dev/null 2>&1; then echo "$STM32CP_CLI not found." echo "Please install it or add '/bin' to your PATH environment:" echo "https://www.st.com/en/development-tools/stm32cubeprog.html" @@ -55,8 +51,8 @@ check_tool() { check_tool if [ $# -lt 2 ]; then - echo "Not enough arguments!" - usage 2 + echo "Not enough arguments!" + usage 2 fi # Parse options @@ -64,8 +60,8 @@ PROTOCOL=$1 FILEPATH=$2 # Protocol $1 # 1x: Erase all sectors -if [ $1 -ge 10 ]; then - ERASE='-e all' +if [ "$1" -ge 10 ]; then + ERASE="yes" PROTOCOL=$(($1 - 10)) fi # Protocol $1 @@ -73,31 +69,33 @@ fi # 1: Serial # 2: DFU case $PROTOCOL in - 0) - PORT='SWD' - MODE='mode=UR' - shift 2;; + PORT="SWD" + MODE="mode=UR" + shift 2 + ;; 1) if [ $# -lt 3 ]; then usage 3 else PORT=$3 shift 3 - fi;; + fi + ;; 2) - PORT='USB1' - shift 2;; + PORT="USB1" + shift 2 + ;; *) echo "Protocol unknown!" - usage 4;; + usage 4 + ;; esac if [ $# -gt 0 ]; then - OPTS="$@" + OPTS="$*" fi -${STM32CP_CLI} -c port=${PORT} ${MODE} ${ERASE} -q -d ${FILEPATH} ${ADDRESS} ${OPTS} - -exit 0 +${STM32CP_CLI} -c port=${PORT} ${MODE} ${ERASE:+"-e all"} -q -d "${FILEPATH}" ${ADDRESS} "${OPTS}" +exit $? diff --git a/run_arduino_gen.sh b/run_arduino_gen.sh index 269caeb3b..f0a0ea8de 100755 --- a/run_arduino_gen.sh +++ b/run_arduino_gen.sh @@ -18,7 +18,6 @@ ELF_HASH="" ELF_BINARY="" ### END OF BINARY PART %} ### - autodetect_board() { if [ ! -d /proc/device-tree/ ]; then echo "Proc Device tree are not available, Could not detect on which board we are" > /dev/kmsg @@ -26,28 +25,28 @@ autodetect_board() { fi #search on device tree compatible entry the board type - if $(grep -q "stm32mp157c-ev" /proc/device-tree/compatible) ; then + if grep -q "stm32mp157c-ev" /proc/device-tree/compatible; then BOARD="STM32MP157_EVAL" - elif $(grep -q "stm32mp157c-dk" /proc/device-tree/compatible) ; then + elif grep -q "stm32mp157c-dk" /proc/device-tree/compatible; then BOARD="STM32MP157_DK" - elif $(grep -q "stm32mp157a-dk" /proc/device-tree/compatible) ; then + elif grep -q "stm32mp157a-dk" /proc/device-tree/compatible; then BOARD="STM32MP157_DK" - elif $(grep -q "stm32mp157" /proc/device-tree/compatible) ; then + elif grep -q "stm32mp157" /proc/device-tree/compatible; then BOARD="STM32MP157_GENERIC" else echo "Board is not an STM32MP157 BOARD" > /dev/kmsg exit 1 fi + echo "Board is $BOARD" > /dev/kmsg } - firmware_load() { if [ -z "$ELF_BINARY" ]; then echo "No Arduino binary contained. Run generate command first." exit 1 fi - if ( echo "$ELF_HASH $ELF_INSTALL_PATH" | sha256sum --status -c - 2>/dev/null ); then + if (echo "$ELF_HASH $ELF_INSTALL_PATH" | sha256sum --status -c - 2> /dev/null); then # The same firmware already exists, skip this step echo "The same firmware is already installed. Starting..." return 0 @@ -55,39 +54,36 @@ firmware_load() { # Decode base64-encoded binary to a temp directory and check hash tmp_elf_file="/tmp/$ELF_NAME" - if which uudecode >/dev/null 2>&1; then - echo -n "$ELF_BINARY" | uudecode -o /dev/stdout | gzip -d > "$tmp_elf_file" - else - echo -n "$ELF_BINARY" | tail -n +2 | base64 -d - 2>/dev/null | gzip -d > "$tmp_elf_file" + if which uudecode > /dev/null 2>&1; then + printf "%s" "$ELF_BINARY" | uudecode -o /dev/stdout | gzip -d > "$tmp_elf_file" + else + printf "%s" "$ELF_BINARY" | tail -n +2 | base64 -d - 2> /dev/null | gzip -d > "$tmp_elf_file" fi echo "$ELF_HASH $tmp_elf_file" | sha256sum --status -c - - + # Copy elf into /lib/firmware mv $tmp_elf_file $ELF_INSTALL_PATH echo "Arduino: Executable created: $ELF_INSTALL_PATH" > /dev/kmsg } - firmware_start() { # Change the name of the firmware - echo -n arduino.ino.elf > $REMOTEPROC_DIR/firmware + printf arduino.ino.elf > $REMOTEPROC_DIR/firmware # Change path to found firmware - #echo -n /home/root >/sys/module/firmware_class/parameters/path + #printf /home/root >/sys/module/firmware_class/parameters/path # Restart firmware echo "Arduino: Starting $ELF_INSTALL_PATH" > /dev/kmsg - echo start > $REMOTEPROC_DIR/state 2>/dev/null || true + echo start > $REMOTEPROC_DIR/state 2> /dev/null || true } - firmware_stop() { # Stop the firmware echo "Arduino: Stopping $ELF_INSTALL_PATH" > /dev/kmsg - echo stop > $REMOTEPROC_DIR/state 2>/dev/null || true + echo stop > $REMOTEPROC_DIR/state 2> /dev/null || true } - generate_packaged_script() { elf_path="$1" this_script=$(readlink -f "$0") @@ -96,28 +92,27 @@ generate_packaged_script() { echo "The output file name must be diffent from this script file" exit 1 fi - + # Generate a copy of this script with a self-contained elf binary and its hash # The elf binary is gzip'ed, making its size to 1/6, and then Base64-encoded # using uuencode. - head -n $(grep -n "{%" "$this_script" | cut -d: -f1 | head -n 1) $this_script > $output_script - echo "ELF_HASH='$(sha256sum $elf_path | cut -d' ' -f1)'" >> $output_script - echo -n "ELF_BINARY='" >> $output_script - if which uuencode >/dev/null 2>&1; then - gzip -c "$elf_path" | uuencode -m $ELF_NAME >> $output_script + head -n "$(grep -n "{%" "$this_script" | cut -d: -f1 | head -n 1)" "$this_script" > "$output_script" + echo "ELF_HASH='$(sha256sum "$elf_path" | cut -d' ' -f1)'" >> "$output_script" + printf "ELF_BINARY='" >> "$output_script" + if which uuencode > /dev/null 2>&1; then + gzip -c "$elf_path" | uuencode -m $ELF_NAME >> "$output_script" else - echo "begin-base64 644 $ELF_NAME" >> $output_script - gzip -c "$elf_path" | base64 >> $output_script + echo "begin-base64 644 $ELF_NAME" >> "$output_script" + gzip -c "$elf_path" | base64 >> "$output_script" fi - echo "'" >> $output_script - tail -n +$(grep -n "%}" "$this_script" | cut -d: -f1 | head -n 1) $this_script >> $output_script - dos2unix $output_script 2> /dev/null + echo "'" >> "$output_script" + tail -n +"$(grep -n "%}" "$this_script" | cut -d: -f1 | head -n 1)" "$this_script" >> "$output_script" + dos2unix "$output_script" 2> /dev/null } - systemd_install() { - mkdir -p $(dirname $INSTALL_PATH) - cp $0 "$INSTALL_PATH" + mkdir -p "$(dirname $INSTALL_PATH)" + cp "$0" "$INSTALL_PATH" echo "File created: $INSTALL_PATH" cat > "$SYSTEMD_SERVICE_PATH" << EOF [Unit] @@ -136,16 +131,15 @@ EOF echo "File created: $SYSTEMD_SERVICE_PATH" echo "Please wait until systemd services are reloaded..." systemctl daemon-reload - systemctl enable $(basename $SYSTEMD_SERVICE_PATH) + systemctl enable "$(basename "$SYSTEMD_SERVICE_PATH")" } - systemd_uninstall() { - systemctl stop $(basename $SYSTEMD_SERVICE_PATH) - systemctl disable $(basename $SYSTEMD_SERVICE_PATH) + systemctl stop "$(basename "$SYSTEMD_SERVICE_PATH")" + systemctl disable "$(basename "$SYSTEMD_SERVICE_PATH")" rm "$SYSTEMD_SERVICE_PATH" echo "File deleted: $SYSTEMD_SERVICE_PATH" - rm -r $(dirname $INSTALL_PATH) + rm -r "$(dirname $INSTALL_PATH)" echo "File deleted: $INSTALL_PATH" } @@ -161,13 +155,13 @@ try_send() { echo "If you didn't enable the virtual serial, ignore this message." return 0 fi - sleep 1; - count=$(expr $count + 1) + sleep 1 + count=$((count + 1)) done # Linux host must send any dummy data first to finish initialization of rpmsg # on the coprocessor side. This message should be discarded. # See: https://github.com/OpenAMP/open-amp/issues/182 - echo -n "DUMMY" >$RPMSG_DIR + printf "DUMMY" > $RPMSG_DIR echo "Virtual serial $RPMSG_DIR connection established." } @@ -195,12 +189,12 @@ case "$1" in install) autodetect_board systemd_install - echo "Auto-start service $(basename $SYSTEMD_SERVICE_PATH) installed." + echo "Auto-start service $(basename "$SYSTEMD_SERVICE_PATH") installed." ;; uninstall) autodetect_board systemd_uninstall - echo "Auto-start service $(basename $SYSTEMD_SERVICE_PATH) uninstalled." + echo "Auto-start service $(basename "$SYSTEMD_SERVICE_PATH") uninstalled." ;; monitor) autodetect_board @@ -209,7 +203,7 @@ case "$1" in ;; send-msg) autodetect_board - echo "${@:2}" >$RPMSG_DIR + echo "${@:2}" > $RPMSG_DIR ;; send-file) autodetect_board @@ -227,10 +221,10 @@ case "$1" in ;; generate) output=$(echo "$3" | sed 's/\.ino\././g') - generate_packaged_script $2 $output + generate_packaged_script "$2" "$output" echo "$(readlink -f "$output") generated successfully." echo "This file should be uploaded manually by SCP, SFTP, Kermit, or etc." - echo "Then run \"sh ./$(basename $output) start\" command in the board's console." + echo "Then run \"sh ./$(basename "$output") start\" command in the board's console." echo "For detailed instructions, please visit:" echo " https://github.com/stm32duino/Arduino_Core_STM32/tree/master/variants/STM32MP157_DK/README.md" ;;