~gabe/flashlight-firmware/anduril2

« back to all changes in this revision

Viewing changes to bin/build.sh

  • Committer: Selene Scriven
  • Date: 2018-11-03 22:54:18 UTC
  • mfrom: (188.1.36 flash-safer)
  • Revision ID: bzr@toykeeper.net-20181103225418-1vsjrc40xh838ggw
merged trunk and flash-safer branch (clean up flash/build scripts and make flashing less likely to produce bricks)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
 
 
3
# Instead of using a Makefile, since most of the firmwares here build in the
 
4
# same exact way, here's a script to do the same thing
 
5
 
 
6
if [ -z "$1" ]; then
 
7
  echo "Usage: build.sh MCU myprogram"
 
8
  echo "MCU is a number, like '13' for attiny13 or '841' for attiny841"
 
9
  exit
 
10
fi
 
11
 
 
12
export ATTINY=$1 ; shift
 
13
export PROGRAM=$1 ; shift
 
14
export MCU=attiny$ATTINY
 
15
export CC=avr-gcc
 
16
export OBJCOPY=avr-objcopy
 
17
export CFLAGS="-Wall -g -Os -mmcu=$MCU -c -std=gnu99 -DATTINY=$ATTINY -I.. -I../.. -I../../.. -fshort-enums"
 
18
export OFLAGS="-Wall -g -Os -mmcu=$MCU"
 
19
export LDFLAGS=
 
20
export OBJCOPYFLAGS='--set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex'
 
21
export OBJS=$PROGRAM.o
 
22
 
 
23
for arg in "$*" ; do
 
24
  OTHERFLAGS="$OTHERFLAGS $arg"
 
25
done
 
26
 
 
27
function run () {
 
28
  echo $*
 
29
  $*
 
30
  if [ x"$?" != x0 ]; then exit 1 ; fi
 
31
}
 
32
 
 
33
run $CC $OTHERFLAGS $CFLAGS -o $PROGRAM.o -c $PROGRAM.c
 
34
run $CC $OFLAGS $LDFLAGS -o $PROGRAM.elf $PROGRAM.o
 
35
run $OBJCOPY $OBJCOPYFLAGS $PROGRAM.elf $PROGRAM.hex
 
36
run avr-size -C --mcu=$MCU $PROGRAM.elf | grep Full