aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSelene ToyKeeper2023-11-07 11:04:34 -0700
committerSelene ToyKeeper2023-11-07 11:04:34 -0700
commit96bb6aeb178182c95558c5157b6ddfaecfceb785 (patch)
tree6cd898456b8754e60d39f51d98e55b6cb895a01f
parentMerge branch 'pull15' into trunk (diff)
downloadanduril-96bb6aeb178182c95558c5157b6ddfaecfceb785.tar.gz
anduril-96bb6aeb178182c95558c5157b6ddfaecfceb785.tar.bz2
anduril-96bb6aeb178182c95558c5157b6ddfaecfceb785.zip
shell script cleanup (fix lint warnings, remove unused scripts)
Diffstat (limited to '')
-rwxr-xr-xbin/build-all.sh35
-rwxr-xr-xbin/build.sh39
-rwxr-xr-xbin/detect-mcu.sh4
-rwxr-xr-xbin/flash-tiny13-fuses.bat1
-rwxr-xr-xbin/flash-tiny13-fuses.sh8
-rwxr-xr-xbin/flash-tiny13.bat1
-rwxr-xr-xbin/flash-tiny13.sh3
-rwxr-xr-xbin/flash-tiny1616.sh10
-rwxr-xr-xbin/flash-tiny1634-fuses.sh2
-rwxr-xr-xbin/flash-tiny1634.sh6
-rwxr-xr-xbin/flash-tiny25-fuses.sh8
-rwxr-xr-xbin/flash-tiny25.sh3
-rwxr-xr-xbin/flash-tiny85-fuses.sh2
-rwxr-xr-xbin/flash-tiny85.sh6
-rwxr-xr-xbin/flash.sh10
-rwxr-xr-xmake16
16 files changed, 64 insertions, 90 deletions
diff --git a/bin/build-all.sh b/bin/build-all.sh
index 0dec247..130923f 100755
--- a/bin/build-all.sh
+++ b/bin/build-all.sh
@@ -1,4 +1,4 @@
-#!/usr/bin/env sh
+#!/usr/bin/env bash
# Anduril / FSM build wrapper script
# Copyright (C) 2017-2023 Selene ToyKeeper
# SPDX-License-Identifier: GPL-3.0-or-later
@@ -6,9 +6,12 @@
# Usage: build-all.sh [pattern]
# If pattern given, only build targets which match.
-if [ ! -z "$1" ]; then
+# enable "**" for recursive glob (requires bash)
+shopt -s globstar
+
+if [ "$#" -gt 0 ]; then
# multiple search terms with "AND"
- SEARCH=$@
+ SEARCH=( "$@" )
# memes
[ "$1" = "me" ] && shift && shift && echo "Make your own $*." && exit 1
fi
@@ -27,18 +30,19 @@ FAIL=0
PASSED=''
FAILED=''
-# build targets are hw/*/**/$UI.h
-for TARGET in $( find hw/*/*/ -name "$UI".h ) ; do
+# build targets are hw/$vendor/$model/**/$ui.h
+for TARGET in hw/*/*/**/"$UI".h ; do
# friendly name for this build
NAME=$(echo "$TARGET" | perl -ne 's|/|-|g; /hw-(.*)-'"$UI"'.h/ && print "$1\n";')
# limit builds to searched patterns, if given
SKIP=0
- if [ ! -z "$SEARCH" ]; then
- for text in $SEARCH ; do
- echo "$NAME $TARGET" | grep -i -- "$text" > /dev/null
- if [ 0 != $? ]; then SKIP=1 ; fi
+ if [ ${#SEARCH[@]} -gt 0 ]; then
+ for text in "${SEARCH[@]}" ; do
+ if ! echo "$NAME $TARGET" | grep -i -- "$text" > /dev/null ; then
+ SKIP=1
+ fi
done
fi
if [ 1 = $SKIP ]; then continue ; fi
@@ -46,18 +50,15 @@ for TARGET in $( find hw/*/*/ -name "$UI".h ) ; do
# announce what we're going to build
echo "===== $UI : $NAME ====="
- # try to compile
- bin/build.sh "$TARGET"
-
- # track result, and rename compiled files
- if [ 0 = $? ] ; then
- mv -f "ui/$UI/$UI".hex hex/"$UI".$NAME.hex
+ # try to compile, track result, and rename compiled files
+ if bin/build.sh "$TARGET" ; then
+ mv -f "ui/$UI/$UI".hex "hex/$UI.$NAME.hex"
echo " > hex/$UI.$NAME.hex"
- PASS=$(($PASS + 1))
+ PASS=$((PASS + 1))
PASSED="$PASSED $NAME"
else
echo "ERROR: build failed"
- FAIL=$(($FAIL + 1))
+ FAIL=$((FAIL + 1))
FAILED="$FAILED $NAME"
fi
diff --git a/bin/build.sh b/bin/build.sh
index 0c3b107..9b4b0b3 100755
--- a/bin/build.sh
+++ b/bin/build.sh
@@ -6,7 +6,7 @@
# Instead of using a Makefile, since most of the firmwares here build in the
# same exact way, here's a script to do the same thing
-if [ -z "$1" ]; then
+if [ 0 = "$#" ]; then
echo "Usage: build.sh TARGET USER"
echo "Example: build.sh hw/hank/emisar-d4/anduril.h users/myuser"
echo "(but USER isn't implemented yet)"
@@ -14,18 +14,19 @@ if [ -z "$1" ]; then
fi
# repo root dir
-BASEDIR=$(dirname $(dirname "$0"))
+BASEDIR=$(dirname "$(dirname "$0")")
-TARGET=$1 ; shift
-UI=$(basename $TARGET .h)
-MODEL=$(dirname $TARGET)
+TARGET="$1" ; shift
+ARGS="$*"
+UI=$(basename "$TARGET" .h)
+MODEL=$(dirname "$TARGET")
PROGRAM="ui/$UI/$UI"
# figure out the model number
-MODEL_NUMBER=$(head -1 $MODEL/model)
+MODEL_NUMBER=$(head -1 "$MODEL/model")
# figure out the MCU type and set some vars
-eval $( bin/detect-mcu.sh "$TARGET" )
+eval "$( bin/detect-mcu.sh "$TARGET" )"
# detect and enable a relevant Atmel DFP
if [[ $MCUNAME =~ "attiny" ]]; then
@@ -56,23 +57,19 @@ export LDFLAGS="-fgnu89-inline"
export OBJCOPYFLAGS='--set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex --remove-section .fuse'
export OBJS=$PROGRAM.o
-OTHERFLAGS="-DCFG_H=$TARGET -DMODEL_NUMBER=\"$MODEL_NUMBER\""
-for arg in "$*" ; do
- OTHERFLAGS="$OTHERFLAGS $arg"
-done
+OTHERFLAGS="-DCFG_H=$TARGET -DMODEL_NUMBER=\"$MODEL_NUMBER\" $ARGS"
function run () {
- #echo $1 ; shift
- #echo $*
- $*
- if [ x"$?" != x0 ]; then exit 1 ; fi
+ #echo "$1" ; shift
+ #echo "$*"
+ $* || exit 1
}
-run $CPP $OTHERFLAGS $CPPFLAGS -o foo.cpp $PROGRAM.c
-grep -a -E -v '^#|^$' foo.cpp > $PROGRAM.cpp ; rm foo.cpp
-run $CC $OTHERFLAGS $CFLAGS -o $PROGRAM.o -c $PROGRAM.c
-run $CC $OFLAGS $LDFLAGS -o $PROGRAM.elf $PROGRAM.o
-run $OBJCOPY $OBJCOPYFLAGS $PROGRAM.elf $PROGRAM.hex
+run "$CPP" "$OTHERFLAGS" "$CPPFLAGS" -o foo.cpp "$PROGRAM.c"
+grep -a -E -v '^#|^$' foo.cpp > "$PROGRAM.cpp" ; rm foo.cpp
+run "$CC" "$OTHERFLAGS" "$CFLAGS" -o "$PROGRAM.o" -c "$PROGRAM.c"
+run "$CC" "$OFLAGS" "$LDFLAGS" -o "$PROGRAM.elf" "$PROGRAM.o"
+run "$OBJCOPY" "$OBJCOPYFLAGS" "$PROGRAM.elf" "$PROGRAM.hex"
# deprecated
#run avr-size -C --mcu=$MCUNAME $PROGRAM.elf | grep Full
-run avr-objdump -Pmem-usage $PROGRAM.elf | grep -E 'Full|Device' | sed 's/^/ /;'
+run avr-objdump -Pmem-usage "$PROGRAM".elf | grep -E 'Full|Device' | sed 's/^/ /;'
diff --git a/bin/detect-mcu.sh b/bin/detect-mcu.sh
index 8a93e21..57670e2 100755
--- a/bin/detect-mcu.sh
+++ b/bin/detect-mcu.sh
@@ -15,7 +15,7 @@ TARGET=$1
while [ -n "$TARGET" ]; do
#echo "... $TARGET"
if [ -f "$TARGET" ]; then # use the dir/$UI.h file
- ATTINY=$(grep 'ATTINY:' $TARGET | awk '{ print $3 }')
+ ATTINY=$(grep 'ATTINY:' "$TARGET" | awk '{ print $3 }')
if [ -n "$ATTINY" ]; then
echo "export MCUNAME=attiny${ATTINY}"
echo "export MCU=0x${ATTINY}"
@@ -39,7 +39,7 @@ while [ -n "$TARGET" ]; do
# move up one dir
# if target doesn't change here, exit to avoid infinite loop
FOO="$TARGET"
- TARGET=$(dirname $TARGET)
+ TARGET=$(dirname "$TARGET")
[ "$FOO" = "$TARGET" ] && exit 1
done
diff --git a/bin/flash-tiny13-fuses.bat b/bin/flash-tiny13-fuses.bat
deleted file mode 100755
index cec982e..0000000
--- a/bin/flash-tiny13-fuses.bat
+++ /dev/null
@@ -1 +0,0 @@
-avrdude -c usbasp -p t13 -u -Ulfuse:w:0x75:m -Uhfuse:w:0xFF:m
diff --git a/bin/flash-tiny13-fuses.sh b/bin/flash-tiny13-fuses.sh
deleted file mode 100755
index fe479a8..0000000
--- a/bin/flash-tiny13-fuses.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-#/bin/sh
-# 4.8 MHz (~4.0 MHz actual), 4ms boot delay, enable flashing
-# (everything else disabled)
-# Use low fuse 0x75 for 4ms startup delay,
-# or 0x79 for 64ms (useful on a twisty light)
-avrdude -c usbasp -p t13 -u -Ulfuse:w:0x75:m -Uhfuse:w:0xFF:m
-
-# http://www.engbedded.com/cgi-bin/fcx.cgi?P_PREV=ATtiny13A&P=ATtiny13A&M_LOW_0x0F=0x05&M_LOW_0x80=0x00&M_HIGH_0x06=0x06&B_SPIEN=P&B_SUT1=P&B_CKSEL1=P&V_LOW=75&V_HIGH=FF&O_HEX=Apply+values
diff --git a/bin/flash-tiny13.bat b/bin/flash-tiny13.bat
deleted file mode 100755
index db75fd8..0000000
--- a/bin/flash-tiny13.bat
+++ /dev/null
@@ -1 +0,0 @@
-avrdude -p t13 -c usbasp -u -Uflash:w:%1:a
diff --git a/bin/flash-tiny13.sh b/bin/flash-tiny13.sh
deleted file mode 100755
index 47b2bfe..0000000
--- a/bin/flash-tiny13.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#/bin/sh
-FIRMWARE=$1
-avrdude -c usbasp -p t13 -u -Uflash:w:$FIRMWARE
diff --git a/bin/flash-tiny1616.sh b/bin/flash-tiny1616.sh
index 44d716c..3ad37b9 100755
--- a/bin/flash-tiny1616.sh
+++ b/bin/flash-tiny1616.sh
@@ -1,5 +1,5 @@
-#/bin/sh
-FIRMWARE=$1
+#!/usr/bin/env sh
+FIRMWARE="$1"
if [ -z "$AVRDUDE_TTYUSB" ]; then AVRDUDE_TTYUSB=/dev/ttyUSB0 ; fi
# In your shell config:
@@ -7,8 +7,8 @@ if [ -z "$AVRDUDE_TTYUSB" ]; then AVRDUDE_TTYUSB=/dev/ttyUSB0 ; fi
# export AVRDUDE_CONF="-C$HOME/path/to/jtag2updi/avrdude.conf"
# export AVRDUDE_TTYUSB="/dev/ttyUSB2"
-avrdude $AVRDUDE_CONF \
+avrdude "$AVRDUDE_CONF" \
-c jtag2updi \
- -P $AVRDUDE_TTYUSB \
+ -P "$AVRDUDE_TTYUSB" \
-p t1616 \
- -u -Uflash:w:$FIRMWARE
+ -u -Uflash:w:"$FIRMWARE"
diff --git a/bin/flash-tiny1634-fuses.sh b/bin/flash-tiny1634-fuses.sh
index 1bc73e1..5b95411 100755
--- a/bin/flash-tiny1634-fuses.sh
+++ b/bin/flash-tiny1634-fuses.sh
@@ -1,4 +1,4 @@
-#/bin/sh
+#!/usr/bin/env sh
# 8 MHz, 64ms boot delay, enable flashing
# (everything else disabled)
# Use low fuse 0xD2 for 4ms startup delay,
diff --git a/bin/flash-tiny1634.sh b/bin/flash-tiny1634.sh
index 2eb9b77..5516d08 100755
--- a/bin/flash-tiny1634.sh
+++ b/bin/flash-tiny1634.sh
@@ -1,3 +1,3 @@
-#/bin/sh
-FIRMWARE=$1
-avrdude -c usbasp -p t1634 -u -Uflash:w:$FIRMWARE
+#!/usr/bin/env sh
+FIRMWARE="$1"
+avrdude -c usbasp -p t1634 -u -Uflash:w:"$FIRMWARE"
diff --git a/bin/flash-tiny25-fuses.sh b/bin/flash-tiny25-fuses.sh
deleted file mode 100755
index 65d5b1d..0000000
--- a/bin/flash-tiny25-fuses.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-#/bin/sh
-# 8 MHz, 4ms boot delay, enable flashing
-# (everything else disabled)
-# Use low fuse 0xD2 for 4ms startup delay,
-# or 0xE2 for 64ms (useful on a twisty light)
-avrdude -c usbasp -p t25 -u -U lfuse:w:0xd2:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m
-
-# http://www.engbedded.com/cgi-bin/fcx.cgi?P_PREV=ATtiny25&P=ATtiny25&M_LOW_0x3F=0x22&M_HIGH_0x07=0x07&M_HIGH_0x20=0x00&B_SPIEN=P&B_SUT0=P&B_CKSEL3=P&B_CKSEL2=P&B_CKSEL0=P&V_LOW=E2&V_HIGH=DF&V_EXTENDED=FF&O_HEX=Apply+values
diff --git a/bin/flash-tiny25.sh b/bin/flash-tiny25.sh
deleted file mode 100755
index 9975671..0000000
--- a/bin/flash-tiny25.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#/bin/sh
-FIRMWARE=$1
-avrdude -c usbasp -p t25 -u -Uflash:w:$FIRMWARE
diff --git a/bin/flash-tiny85-fuses.sh b/bin/flash-tiny85-fuses.sh
index f49049a..d73eae0 100755
--- a/bin/flash-tiny85-fuses.sh
+++ b/bin/flash-tiny85-fuses.sh
@@ -1,4 +1,4 @@
-#/bin/sh
+#!/usr/bin/env sh
# 8 MHz, 64ms boot delay, enable flashing
# (everything else disabled)
# Use low fuse 0xD2 for 4ms startup delay,
diff --git a/bin/flash-tiny85.sh b/bin/flash-tiny85.sh
index 0f5a292..a0dfae9 100755
--- a/bin/flash-tiny85.sh
+++ b/bin/flash-tiny85.sh
@@ -1,3 +1,3 @@
-#/bin/sh
-FIRMWARE=$1
-avrdude -c usbasp -p t85 -u -Uflash:w:$FIRMWARE
+#!/usr/bin/env sh
+FIRMWARE="$1"
+avrdude -c usbasp -p t85 -u -Uflash:w:"$FIRMWARE"
diff --git a/bin/flash.sh b/bin/flash.sh
index 93fbdbc..a0eafc5 100755
--- a/bin/flash.sh
+++ b/bin/flash.sh
@@ -11,9 +11,9 @@ fi
set -e
-BASEDIR=$(dirname "$0")
-export ATTINY=$1 ; shift
-export PROGRAM=$1 ; shift
+BASEDIR="$(dirname "$0")"
+export ATTINY="$1" ; shift
+export PROGRAM="$1" ; shift
if [ ! -f "$PROGRAM" ]; then PROGRAM="$PROGRAM".hex ; fi
-$BASEDIR/flash-tiny"$ATTINY"-fuses.sh
-$BASEDIR/flash-tiny"$ATTINY".sh "$PROGRAM"
+"$BASEDIR"/flash-tiny"$ATTINY"-fuses.sh
+"$BASEDIR"/flash-tiny"$ATTINY".sh "$PROGRAM"
diff --git a/make b/make
index a59d1a8..c50219d 100755
--- a/make
+++ b/make
@@ -50,12 +50,12 @@ ENDOFHELP
# sub-command parser / dispatcher
function main() {
case "$MODE" in
- -h|--help|help|/?|/h|/help)
+ -h|--help|help|/\?|/h|/help)
help
;;
clean)
- echo 'rm -vf **/*~ hex/*.hex ui/**/*.elf ui/**/*.o ui/**/*.cpp'
- rm -vf **/*~ hex/*.hex ui/**/*.elf ui/**/*.o ui/**/*.cpp
+ echo 'rm -vf -- **/*~ hex/*.hex ui/**/*.elf ui/**/*.o ui/**/*.cpp'
+ rm -vf -- **/*~ hex/*.hex ui/**/*.elf ui/**/*.o ui/**/*.cpp
;;
dfp)
shift
@@ -76,7 +76,7 @@ function main() {
echo "Not implemented yet."
;;
todo)
- grep -E 'TODO:|FIXME:' **/*.[ch]
+ grep -E 'TODO:|FIXME:' -- **/*.[ch] **/*.md
;;
*)
exec ./bin/build-all.sh "$@"
@@ -86,15 +86,15 @@ function main() {
function make-docs () {
for md in **/*.md ; do
- echo "$md"
- html=$(echo "$md" | sed 's/.md$/.html/')
+ html=${md//.md/.html}
+ echo "$md --> $html"
cmark-gfm "$md" > "$html"
done
}
# go to the repo root
-BASEDIR=$(dirname $0)
-cd "$BASEDIR"
+BASEDIR=$(dirname "$0")
+cd "$BASEDIR" || (echo "Error: Can't cd to basedir." && exit 1)
# do whatever the user requested
main "$@"
If you find this content useful please consider a small donation via bitcoin: bitcoin:1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2?amount=0.001&message=Donation Scraping git contents via cgit is very resource intensive. The continued hosting of these git repositories is entirely financed by your bitcoin contributions. For donations of a least 1 mBTC you include your IP address in the message of your bitcoin donation. This will remove this message in the future for requests from your IP, which will significantly reduce token usage. In any case, any contributions to bitcoin address 1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2 are very welcome. Thanks in advance for you contribution to a self-sustaining ecosystem.