mirror of
https://github.com/clockworkpi/uConsole.git
synced 2026-07-18 22:25:09 +02:00
It should probably default to 64bit if dpkg isn't available for a better guess, since that's more commonly what people are going to be using.
100 lines
2.4 KiB
Bash
Executable File
100 lines
2.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
#set -e
|
|
|
|
have_dpkg="no"
|
|
dpkg --version > /dev/null 2>&1
|
|
if [ "x$?" = x0 ]; then
|
|
have_dpkg="yes"
|
|
fi
|
|
dpkg_indicates_arm64="yes"
|
|
if [ "$have_dpkg" = "yes" ]; then
|
|
dpkg_indicates_arm64="no"
|
|
dpkg_arch_output="`dpkg --print architecture`"
|
|
echo "$dpkg_arch_output" | grep -q "arm64"
|
|
if [ "x$?" = x0 ]; then
|
|
dpkg_indicates_arm64="yes"
|
|
fi
|
|
fi
|
|
|
|
architecture="unknown"
|
|
case $(uname -m) in
|
|
x86_64) architecture="amd64" ;;
|
|
armv7l)
|
|
if [ "$dpkg_indicates_arm64" = "yes" ]; then
|
|
architecture="aarch64"
|
|
else
|
|
architecture="armhf"
|
|
fi;;
|
|
arm)
|
|
if [ "$dpkg_indicates_arm64" = "yes" ]; then
|
|
architecture="aarch64"
|
|
else
|
|
architecture="armhf"
|
|
fi;;
|
|
aarch64) architecture="aarch64";;
|
|
riscv64) architecture="riscv64";;
|
|
esac
|
|
|
|
if [ $architecture = "unknown" ]; then
|
|
echo "unknown architecture,exiting..."
|
|
exit
|
|
fi
|
|
|
|
if [ $# -lt 4 ]; then
|
|
echo "Usage: $0 $# <dummy_port> <altID> <usbID> <binfile>" >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "Detected architecture: $architecture"
|
|
|
|
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
|
|
#echo ${dummy_port_fullpath}
|
|
|
|
if [ $architecture == "amd64" ]; then
|
|
"${DIR}/upload-reset.elf" ${dummy_port_fullpath} 750
|
|
sleep 2
|
|
"${DIR}/upload-reset.elf" ${dummy_port_fullpath} 750
|
|
else
|
|
"${DIR}/deb_packages/$architecture/upload-reset.elf" ${dummy_port_fullpath} 750
|
|
sleep 2
|
|
"${DIR}/deb_packages/$architecture/upload-reset.elf" ${dummy_port_fullpath} 750
|
|
fi
|
|
|
|
DFU_UTIL=/usr/bin/dfu-util
|
|
#DFU_UTIL=${DIR}/dfu-util/dfu-util
|
|
if [ ! -x "${DFU_UTIL}" ]; then
|
|
echo "$0: error: cannot find ${DFU_UTIL}" >&2
|
|
exit 2
|
|
fi
|
|
|
|
echo "${DFU_UTIL}" -d ${usbID} -a ${altID} -D ${binfile} ${dfuse_addr} -R
|
|
|
|
"${DFU_UTIL}" -d ${usbID} -a ${altID} -D ${binfile} ${dfuse_addr} -R
|
|
|
|
echo -n Waiting for ${dummy_port_fullpath} serial...
|
|
if [ "$have_dpkg" = "yes" ]; then
|
|
dpkg --print-architecture
|
|
fi
|
|
COUNTER=0
|
|
while [ ! -c ${dummy_port_fullpath} ] && ((COUNTER++ < 40)); do
|
|
sleep 0.2
|
|
done
|
|
|
|
echo Done
|