diff options
Diffstat (limited to '')
| -rwxr-xr-x | bin/build-all.sh | 7 | ||||
| -rwxr-xr-x | bin/build-tiny13.sh | 4 | ||||
| -rwxr-xr-x | bin/build-tiny25.sh | 4 | ||||
| -rwxr-xr-x | bin/build-tiny85.sh | 4 | ||||
| -rwxr-xr-x | bin/build.sh | 26 | ||||
| -rwxr-xr-x | bin/detect-mcu.sh | 41 | ||||
| -rwxr-xr-x | bin/models.py | 62 |
7 files changed, 95 insertions, 53 deletions
diff --git a/bin/build-all.sh b/bin/build-all.sh index 582ed87..2d443a5 100755 --- a/bin/build-all.sh +++ b/bin/build-all.sh @@ -1,4 +1,7 @@ #!/bin/sh +# Anduril / FSM build wrapper script +# Copyright (C) 2017-2023 Selene ToyKeeper +# SPDX-License-Identifier: GPL-3.0-or-later # Usage: build-all.sh [pattern] # If pattern given, only build targets which match. @@ -41,10 +44,6 @@ for TARGET in $( find hw/*/*/ -name "$UI".h ) ; do # announce what we're going to build echo "===== $UI : $NAME =====" - # figure out MCU type - #ATTINY=$(grep 'ATTINY:' $TARGET | awk '{ print $3 }') - #if [ -z "$ATTINY" ]; then ATTINY=85 ; fi - # try to compile bin/build.sh "$TARGET" diff --git a/bin/build-tiny13.sh b/bin/build-tiny13.sh deleted file mode 100755 index d4b492f..0000000 --- a/bin/build-tiny13.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -BASEDIR=$(dirname "$0") -$BASEDIR/build.sh 13 $* diff --git a/bin/build-tiny25.sh b/bin/build-tiny25.sh deleted file mode 100755 index 779f1ef..0000000 --- a/bin/build-tiny25.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -BASEDIR=$(dirname "$0") -$BASEDIR/build.sh 25 $* diff --git a/bin/build-tiny85.sh b/bin/build-tiny85.sh deleted file mode 100755 index 6ee8397..0000000 --- a/bin/build-tiny85.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -BASEDIR=$(dirname "$0") -$BASEDIR/build.sh 85 $* diff --git a/bin/build.sh b/bin/build.sh index 41abfc7..8743260 100755 --- a/bin/build.sh +++ b/bin/build.sh @@ -1,4 +1,7 @@ #!/bin/bash +# Anduril / FSM build script +# Copyright (C) 2014-2023 Selene ToyKeeper +# SPDX-License-Identifier: GPL-3.0-or-later # 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 @@ -12,12 +15,16 @@ fi TARGET=$1 ; shift UI=$(basename $TARGET .h) +MODEL=$(dirname $TARGET) +PROGRAM="ui/$UI/$UI" -ATTINY=$(grep 'ATTINY:' $TARGET | awk '{ print $3 }') -if [ -z "$ATTINY" ]; then ATTINY=85 ; fi +# figure out the model number +MODEL_NUMBER=$(head -1 $MODEL/model) -PROGRAM="ui/$UI/$UI" +# figure out the MCU type and set some vars +eval $( bin/detect-mcu.sh "$TARGET" ) +# TODO: add support for AVR DD # give a more useful error message when AVR DFP is needed but not installed # (Atmel ATtiny device family pack, for attiny1616 support) # http://packs.download.atmel.com/ @@ -31,21 +38,20 @@ if [[ $SERIES1 =~ " $ATTINY " ]]; then fi fi -export MCU=attiny$ATTINY export CC=avr-gcc export CPP=avr-cpp export OBJCOPY=avr-objcopy -export DFPFLAGS="-B $ATTINY_DFP/gcc/dev/$MCU/ -I $ATTINY_DFP/include/" +export DFPFLAGS="-B $ATTINY_DFP/gcc/dev/$MCUNAME/ -I $ATTINY_DFP/include/" # TODO: include $user/ first so it can override other stuff INCLUDES="-I ui -I hw -I. -I.. -I../.. -I../../.." -export CFLAGS=" -Wall -g -Os -mmcu=$MCU -c -std=gnu99 -fgnu89-inline -fwhole-program -DATTINY=$ATTINY $INCLUDES -fshort-enums $DFPFLAGS" -export CPPFLAGS="-Wall -g -Os -mmcu=$MCU -C -std=gnu99 -fgnu89-inline -fwhole-program -DATTINY=$ATTINY $INCLUDES -fshort-enums $DFPFLAGS" -export OFLAGS="-Wall -g -Os -mmcu=$MCU -mrelax $DFPFLAGS" +export CFLAGS=" -Wall -g -Os -mmcu=$MCUNAME -c -std=gnu99 -fgnu89-inline -fwhole-program $MCUFLAGS $INCLUDES -fshort-enums $DFPFLAGS" +export CPPFLAGS="-Wall -g -Os -mmcu=$MCUNAME -C -std=gnu99 -fgnu89-inline -fwhole-program $MCUFLAGS $INCLUDES -fshort-enums $DFPFLAGS" +export OFLAGS="-Wall -g -Os -mmcu=$MCUNAME -mrelax $DFPFLAGS" 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" +OTHERFLAGS="-DCFG_H=$TARGET -DMODEL_NUMBER=\"$MODEL_NUMBER\"" for arg in "$*" ; do OTHERFLAGS="$OTHERFLAGS $arg" done @@ -63,5 +69,5 @@ 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=$MCU $PROGRAM.elf | grep Full +#run avr-size -C --mcu=$MCUNAME $PROGRAM.elf | grep Full 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 new file mode 100755 index 0000000..fa3a926 --- /dev/null +++ b/bin/detect-mcu.sh @@ -0,0 +1,41 @@ +#!/bin/sh +# Anduril / FSM MCU type detection script +# Copyright (C) 2014-2023 Selene ToyKeeper +# SPDX-License-Identifier: GPL-3.0-or-later + +if [ -z "$1" ]; then + echo "Usage: detect-mcu.sh FILE" + echo "or: eval $(detect-mcu.sh FILE)" + echo "Example: detect-mcu.sh hw/hank/emisar-d4/anduril.h" + echo "Figures out which MCU a build uses, and sets env vars for it" + exit +fi + +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 }') + if [ -n "$ATTINY" ]; then + echo "export MCUNAME=attiny${ATTINY}" + echo "export MCU=0x${ATTINY}" + echo "export ATTINY=${ATTINY}" + echo "export MCUFLAGS=\"-DMCUNAME=attiny${ATTINY} -DMCU=0x${ATTINY} -DATTINY=${ATTINY}\"" + exit + fi + else # use the dir/arch file + if [ -f "${TARGET}/arch" ]; then + MCU=$(head -1 "${TARGET}/arch") + if [ -n "$MCU" ]; then + NUM=$( echo "$MCU" | sed 's/^avr//; s/^attiny//;' ) + echo "export MCUNAME=${MCU}" + echo "export MCU=0x${NUM}" + echo "export ATTINY=${NUM}" + echo "export MCUFLAGS=\"-DMCUNAME=${MCU} -DMCU=0x${NUM} -DATTINY=${NUM}\"" + exit + fi + fi + fi + TARGET=$(dirname $TARGET) +done + diff --git a/bin/models.py b/bin/models.py index 1985352..8e54d1c 100755 --- a/bin/models.py +++ b/bin/models.py @@ -10,33 +10,37 @@ def main(args): models = [] # load all cfg-*.h files - paths = os.listdir('.') - for p in paths: - if p.startswith('cfg-') and p.endswith('.h'): - m = load_cfg(p) - models.append(m) + for p, dirs, files in os.walk('hw'): + for d in dirs: + if '/' not in p: # skip top-level brand dirs + continue + #print('... %s' % d) + m = load_model(os.path.join(p, d)) + if m.mcu and m.model: + models.append(m) # sort by model number - foo = [(m.num, m.name, m) for m in models] + foo = [(m.model, m.name, m) for m in models] foo.sort() models = [x[-1] for x in foo] + print('Models: %i\n' % len(models)) fmt = '%s\t%-30s\t%s' print(fmt % ('Model', 'Name', 'MCU')) print(fmt % ('-----', '----', '---')) for m in models: - print(fmt % (m.num, m.name, m.attiny)) + print(fmt % (m.model, m.name, m.mcu)) print('\nDuplicates:') for i, m in enumerate(models): for m2 in models[i+1:]: - #if (m.num == m2.num) and (m is not m2): - if m.num == m2.num: - print('%s\t%s, %s' % (m.num, m.name, m2.name)) + #if (m.model == m2.model) and (m is not m2): + if m.model == m2.model: + print('%s\t%s, %s' % (m.model, m.name, m2.name)) print('\nMissing:') for m in models: - if not m.num: + if not m.model: print(m.name) @@ -44,27 +48,31 @@ class Empty: pass -def load_cfg(path): +def load_model(path): + #print('load_model(%s)' % path) m = Empty() - m.name, m.num, m.attiny = '', '', 'attiny85' - - m.name = path.replace('cfg-', '').replace('.h', '') - - num_pat = re.compile(r'#define\s+MODEL_NUMBER\s+"(\d+)"') - mcu_pat = re.compile(r'ATTINY:\s+(\d+)') - # TODO? use C preprocessor to generate more complete file to scan - with open(path) as fp: - for line in fp: - found = num_pat.search(line) - if found: - m.num = found.group(1) - found = mcu_pat.search(line) - if found: - m.attiny = 'attiny' + found.group(1) + m.name, m.model, m.mcu = '', '', '???' + + m.name = path.replace('hw/','').replace('/', '-') + m.mcu = inherit(path, 'arch') + m.model = inherit(path, 'model') return m +def inherit(path, field): + #print('inherit(%s, %s)' % (path, field)) + check = os.path.join(path, field) + if os.path.exists(check): + line = open(check).readline().strip() + return line + else: + parent = os.path.join(*os.path.split(path)[:-1]) + if parent: + return inherit(parent, field) + return None + + if __name__ == "__main__": import sys main(sys.argv[1:]) |
