Further keyboardio-builder improvements

Now supports everything that the old Makefile did, and a bit more. Some
cases still need to be handled, and documentation needs to be written,
but it is in a much better shape now.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/84/head
Gergely Nagy 8 years ago
parent f655c446a1
commit bd5f7d92ac

@ -0,0 +1,13 @@
# -*- mode: sh -*-
generate_keymaps () {
cd "$(find_sketch)"
. ${ROOT}/tools/settings.sh
rm -f generated/keymaps.h
(cd layouts && ( find . -type f | sort | xargs -n 1 -I % sh -c 'perl ../../../tools/generate_keymaps.pl < % >> ../generated/keymaps.h' ))
}
EXTRA_BUILDER_ARGS="-libraries ${SOURCEDIR}/libraries"
DEFAULT_SKETCH=KeyboardioFirmware
compile_HOOKS="generate_keymaps"

@ -1,91 +1,3 @@
# Shamelessly stolen from git's Makefile
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
DEVICE_PORT := `ls /dev/ttyACM*`
DEVICE_PORT_BOOTLOADER := `ls /dev/ttyACM*`
ARDUINO_PATH?=/usr/local/arduino
ARDUINO_LOCAL_LIB_PATH?=$(HOME)/Arduino
MD5 = md5sum
RESET_BOARD=stty -F $(DEVICE_PORT) 1200 hupcl
ifeq ($(uname_S),Darwin)
# Port locations
DEVICE_PORT := `ls /dev/cu.usbmodemHID?? /dev/cu.usbmodem14*`
DEVICE_PORT_BOOTLOADER := `ls /dev/cu.usbmodem14*`
# Tools
ARDUINO_PATH=/Applications/Arduino.app/Contents/Java/
ARDUINO_LOCAL_LIB_PATH=$(HOME)/Documents/Arduino
MD5 = md5
RESET_BOARD=stty -f $(DEVICE_PORT) 1200
endif
ARDUINO_TOOLS_PATH=$(ARDUINO_PATH)/hardware/tools
ARDUINO_BUILDER_PATH=$(ARDUINO_PATH)/arduino-builder
AVRDUDE_PATH=$(ARDUINO_TOOLS_PATH)/avr/bin/avrdude
AVRDUDE_CONF_PATH=$(ARDUINO_TOOLS_PATH)/avr/etc/avrdude.conf
AVR_SIZE_PATH=$(ARDUINO_TOOLS_PATH)/avr/bin/avr-size
AVR_NM_PATH=$(ARDUINO_TOOLS_PATH)/avr/bin/avr-nm
AVR_OBJDUMP_PATH=$(ARDUINO_TOOLS_PATH)/avr/bin/avr-objdump
#
#
# Device and sketch info
#
#
BOARD = model01
MCU = atmega32u4
FQBN=keyboardio:avr:model01
SKETCH=KeyboardioFirmware.ino
BOOTLOADER_PATH = $(ARDUINO_LOCAL_LIB_PATH)/hardware/keyboardio/avr/bootloaders/caterina/Caterina.hex
VERBOSE= #-verbose
ARDUINO_TOOLS_PARAM = -tools $(ARDUINO_TOOLS_PATH)
ifeq ($(ARDUINO_TOOLS_PATH),)
ARDUINO_TOOLS_PARAM =
endif
ifdef AVR_GCC_PREFIX
ARDUINO_AVR_GCC_PREFIX_PREF = -prefs "runtime.tools.avr-gcc.path=$(AVR_GCC_PREFIX)"
endif
#
#
# Build
#
#
BUILD_PATH := $(shell mktemp -d 2>/dev/null || mktemp -d -t 'build')
OUTPUT_PATH=./output
ARDUINO_IDE_VERSION=100607
#
#
# Output
#
#
GIT_VERSION := $(shell git describe --abbrev=4 --dirty --always)
OUTPUT_FILE_PREFIX=$(SKETCH)-$(GIT_VERSION)
HEX_FILE_PATH=$(OUTPUT_PATH)/$(OUTPUT_FILE_PREFIX).hex
ELF_FILE_PATH=$(OUTPUT_PATH)/$(OUTPUT_FILE_PREFIX).elf
HEX_FILE_WITH_BOOTLOADER_PATH=$(OUTPUT_PATH)/$(OUTPUT_FILE_PREFIX)-with-bootloader.hex
# default action for `make` is `build` # default action for `make` is `build`
build: compile size build: compile size
@ -95,71 +7,28 @@ astyle:
find . -type f -name \*.h |xargs -n 1 astyle --style=google find . -type f -name \*.h |xargs -n 1 astyle --style=google
generate-keymaps: generate-keymaps:
-rm examples/KeyboardioFirmware/generated/keymaps.h tools/keyboardio-builder generate-keymaps
cd examples/KeyboardioFirmware/layouts && ( find . -type f | sort | xargs -n 1 -I % sh -c 'perl ../../../tools/generate_keymaps.pl < % >> ../generated/keymaps.h' )
dirs:
mkdir -p $(OUTPUT_PATH)
compile: dirs compile:
$(ARDUINO_BUILDER_PATH) \ tools/keyboardio-builder compile
-hardware $(ARDUINO_PATH)/hardware \
-hardware $(ARDUINO_LOCAL_LIB_PATH)/hardware \
$(ARDUINO_TOOLS_PARAM) \
-tools $(ARDUINO_PATH)/tools-builder \
-fqbn $(FQBN) \
-libraries $(ARDUINO_LOCAL_LIB_PATH) \
-libraries . \
$(VERBOSE) \
-build-path $(BUILD_PATH) \
-ide-version $(ARDUINO_IDE_VERSION) \
$(ARDUINO_AVR_GCC_PREFIX_PREF) \
examples/KeyboardioFirmware/$(SKETCH)
@cp $(BUILD_PATH)/$(SKETCH).hex $(HEX_FILE_PATH)
@cp $(BUILD_PATH)/$(SKETCH).elf $(ELF_FILE_PATH)
@echo "Firmware is available at $(HEX_FILE_PATH)"
@echo "Have fun!\n"
size: compile size: compile
$(AVR_SIZE_PATH) -C --mcu=$(MCU) $(ELF_FILE_PATH) tools/keyboardio-builder report-size
size-map: compile size-map: compile
$(AVR_NM_PATH) --size-sort -C -r $(ELF_FILE_PATH) tools/keyboardio-builder size-map
decompile: compile decompile: compile
$(AVR_OBJDUMP_PATH) -d $(ELF_FILE_PATH) tools/keyboardio-builder decompile
hex-with-bootloader: compile hex-with-bootloader: compile
@cat $(HEX_FILE_PATH) | awk '/^:00000001FF/ == 0' > $(HEX_FILE_WITH_BOOTLOADER_PATH) tools/keyboardio-builder hex-with-bootloader
@echo "Using $(BOOTLOADER_PATH)"
@$(MD5) $(BOOTLOADER_PATH)
@cat $(BOOTLOADER_PATH) >> $(HEX_FILE_WITH_BOOTLOADER_PATH)
@echo "Combined firmware and bootloader are now at $(HEX_FILE_WITH_BOOTLOADER_PATH)"
@echo "Make sure you have the bootloader version you expect."
@echo "\n\nAnd TEST THIS ON REAL HARDWARE BEFORE YOU GIVE IT TO ANYONE\n\n"
reset-device: reset-device:
$(RESET_BOARD) tools/keyboardio-builder reset-device
flash: compile reset-device flash: compile reset-device
sleep 3 tools/keyboardio-builder flash
$(AVRDUDE_PATH) \
-C$(AVRDUDE_CONF_PATH) \
-v \
-p$(MCU) \
-cavr109 \
-P$(DEVICE_PORT_BOOTLOADER) \
-b57600 \
-D \
-Uflash:w:$(HEX_FILE_PATH):i
program: program:
$(AVRDUDE_PATH) \ tools/keyboardio-builder program
-C$(AVRDUDE_CONF_PATH) \
-v \
-p$(MCU) \
-cusbtiny \
-D \
-B 1 \
-Uflash:w:$(HEX_FILE_PATH):i

@ -40,6 +40,13 @@ submodule_update () {
} }
find_sketch () { find_sketch () {
if [ -e "${SOURCEDIR}/.keyboardio-builder.conf" ]; then
. "${SOURCEDIR}/.keyboardio-builder.conf"
fi
SKETCH="${SKETCH:-${DEFAULT_SKETCH}}"
LIBRARY="${LIBRARY:-${SKETCH}}"
for path in "hardware/keyboardio/avr/libraries/Akela-${LIBRARY}/examples/${SKETCH}" \ for path in "hardware/keyboardio/avr/libraries/Akela-${LIBRARY}/examples/${SKETCH}" \
"examples/${LIBRARY}" \ "examples/${LIBRARY}" \
"src"; do "src"; do
@ -58,9 +65,46 @@ flash () {
echo "Press ENTER when ready..." echo "Press ENTER when ready..."
read a read a
stty -F /dev/ttyACM* 1200 hupcl reset_device
sleep 3s sleep 3s
avrdude -q -q -patmega32u4 -cavr109 -D -P /dev/ttyACM* -b57600 "-Uflash:w:${OUTPUT_PATH}/${SKETCH}-latest.hex:i" avrdude -q -q -p${MCU} -cavr109 -D -P ${DEVICE_PORT_BOOTLOADER} -b57600 "-Uflash:w:${HEX_FILE_PATH}:i"
cd "${SOURCEDIR}"
}
program () {
cd "$(find_sketch)"
. ${ROOT}/tools/settings.sh
echo "Press ENTER when ready..."
read a
avrdude -v \
-p${MCU} \
-cusbtiny \
-D \
-B 1 \
"-Uflash:w:${HEX_FILE_PATH}:i"
cd "${SOURCEDIR}"
}
hex_with_bootloader () {
cd "$(find_sketch)"
. ${ROOT}/tools/settings.sh
cat ${HEX_FILE_PATH} | awk '/^:00000001FF/ == 0' > ${HEX_FILE_WITH_BOOTLOADER_PATH}
echo "Using ${BOOTLOADER_PATH}"
${MD5} ${BOOTLOADER_PATH}
cat ${BOOTLOADER_PATH} >> ${HEX_FILE_WITH_BOOTLOADER_PATH}
cat <<EOF
Combined firmware and bootloader are now at ${HEX_FILE_WITH_BOOTLOADER_PATH}
Make sure you have the bootloader version you expect.
And TEST THIS ON REAL HARDWARE BEFORE YOU GIVE IT TO ANYONE
EOF
cd "${SOURCEDIR}" cd "${SOURCEDIR}"
} }
@ -78,6 +122,8 @@ compile () {
echo "Building ${OUTPUT_DIR}/${SKETCH} (${LIB_VERSION}) ..." echo "Building ${OUTPUT_DIR}/${SKETCH} (${LIB_VERSION}) ..."
${compile_HOOKS}
${ARDUINO_BUILDER} \ ${ARDUINO_BUILDER} \
-compile \ -compile \
-hardware "${ARDUINO_PATH}/hardware" \ -hardware "${ARDUINO_PATH}/hardware" \
@ -85,7 +131,7 @@ compile () {
${ARDUINO_TOOLS_PARAM} \ ${ARDUINO_TOOLS_PARAM} \
-tools "${ARDUINO_PATH}/tools-builder" \ -tools "${ARDUINO_PATH}/tools-builder" \
-fqbn "${FQBN}" \ -fqbn "${FQBN}" \
-libraries "${ROOT}/libraries" \ -libraries "${ARDUINO_LOCAL_LIB_PATH}/libraries" \
-libraries "${BOARD_HARDWARE_PATH}/.." \ -libraries "${BOARD_HARDWARE_PATH}/.." \
-libraries "${ROOT}" \ -libraries "${ROOT}" \
${EXTRA_BUILDER_ARGS} \ ${EXTRA_BUILDER_ARGS} \
@ -149,6 +195,15 @@ size_map () {
cd "${SOURCEDIR}" cd "${SOURCEDIR}"
} }
decompile () {
cd "$(find_sketch)"
. ${ROOT}/tools/settings.sh
"${AVR_OBJDUMP}" -d "${ELF_FILE_PATH}"
cd "${SOURCEDIR}"
}
clean () { clean () {
cd "$(find_sketch)" cd "$(find_sketch)"
. ${ROOT}/tools/settings.sh . ${ROOT}/tools/settings.sh
@ -158,6 +213,15 @@ clean () {
cd "${SOURCEDIR}" cd "${SOURCEDIR}"
} }
reset_device () {
cd "$(find_sketch)"
. ${ROOT}/tools/settings.sh
${RESET_DEVICE}
cd "${SOURCEDIR}"
}
usage () { usage () {
cat <<EOF cat <<EOF
Usage: $0 SKETCH commands... Usage: $0 SKETCH commands...
@ -184,6 +248,12 @@ Available commands:
size-map size-map
Displays the size map for the sketch. Displays the size map for the sketch.
decomple
Decompile the sketch.
reset-device
Reset the device.
flash flash
Flashes the firmware using avrdude. Flashes the firmware using avrdude.
@ -212,10 +282,8 @@ ROOT="$(cd $(dirname $0)/..; pwd)"
export ROOT export ROOT
export SOURCEDIR="$(pwd)" export SOURCEDIR="$(pwd)"
if [ $# -eq 1 ]; then if [ -e "${SOURCEDIR}/.keyboardio-builder.conf" ]; then
cmd="$(echo $1 | tr '-' '_')" . "${SOURCEDIR}/.keyboardio-builder.conf"
${cmd}
exit $?
fi fi
cmds="" cmds=""
@ -237,9 +305,19 @@ done
set -- ${cmds} set -- ${cmds}
if [ $# -eq 1 ]; then
cmd="$(echo $1 | tr '-' '_')"
${cmd}
exit $?
fi
SKETCH="$1" SKETCH="$1"
shift shift
if [ "${SKETCH}" = "default" ]; then
SKETCH="${DEFAULT_SKETCH}"
fi
cmds="" cmds=""
for i in $(seq 1 $#); do for i in $(seq 1 $#); do

@ -1,11 +1,6 @@
## NEEDS: LIBRARY, SKETCH, ROOT, SOURCEDIR ## NEEDS: LIBRARY, SKETCH, ROOT, SOURCEDIR
## Should be included when the current directory is the dir of the Sketch. ## Should be included when the current directory is the dir of the Sketch.
if [ -z "${SKETCH}" ] || [ -z "${LIBRARY}" ] || [ -z "${ROOT}" ] || [ -z "${SOURCEDIR}" ]; then
echo "SKETCH, LIBRARY, SOURCEDIR, and ROOT need to be set before including this file!" >&2
exit 1
fi
case "$0" in case "$0" in
*/settings.sh) */settings.sh)
echo "This file must be included, never run directly!" >&2 echo "This file must be included, never run directly!" >&2
@ -13,23 +8,37 @@ case "$0" in
;; ;;
esac esac
if [ -e "${SOURCEDIR}/settings.sh" ]; then SKETCH="${SKETCH:-${DEFAULT_SKETCH}}"
. "${SOURCEDIR}/settings.sh" LIBRARY="${LIBRARY:-${SKETCH}}"
if [ -z "${SKETCH}" ] || [ -z "${LIBRARY}" ] || [ -z "${ROOT}" ] || [ -z "${SOURCEDIR}" ]; then
echo "SKETCH, LIBRARY, SOURCEDIR, and ROOT need to be set before including this file!" >&2
exit 1
fi fi
BOARD="model01" BOARD="model01"
MCU="atmega32u4" MCU="atmega32u4"
FQBN="keyboardio:avr:model01" FQBN="keyboardio:avr:model01"
ARDUINO_PATH="${ARDUINO_PATH:-${HOME}/install/arduino}" DEVICE_PORT="$(ls /dev/ttyACM* 2>/dev/null || echo '')"
DEVICE_PORT_BOOTLOADER="$(ls /dev/ttyACM* 2>/dev/null || echo '')"
RESET_BOARD="stty -F ${DEVICE_PORT} 1200 hupcl"
ARDUINO_PATH="${ARDUINO_PATH:-/usr/local/arduino}"
ARDUINO_LOCAL_LIB_PATH="${ARDUINO_LOCAL_LIB_PATH:-${HOME}/Arduino}"
ARDUINO_TOOLS_PATH="${ARDUINO_TOOLS_PATH:-${ARDUINO_PATH}/hardware/tools}" ARDUINO_TOOLS_PATH="${ARDUINO_TOOLS_PATH:-${ARDUINO_PATH}/hardware/tools}"
ARDUINO_BUILDER="${ARDUINO_BUILDER:-${ARDUINO_PATH}/arduino-builder}" ARDUINO_BUILDER="${ARDUINO_BUILDER:-${ARDUINO_PATH}/arduino-builder}"
ARDUINO_IDE_VERSION="100607" ARDUINO_IDE_VERSION="100607"
BOARD_HARDWARE_PATH="${BOARD_HARDWARE_PATH:-${ROOT}/hardware}" BOARD_HARDWARE_PATH="${BOARD_HARDWARE_PATH:-${ARDUINO_LOCAL_LIB_PATH}/hardware}"
BOOTLOADER_PATH="${BOARD_HARDWARE_PATH}/keyboardio/avr/bootloaders/caterina/Caterina.hex"
AVR_SIZE="${AVR_SIZE:-${ARDUINO_TOOLS_PATH}/avr/bin/avr-size}" AVR_SIZE="${AVR_SIZE:-${ARDUINO_TOOLS_PATH}/avr/bin/avr-size}"
AVR_NM="${AVR_NM:-${ARDUINO_TOOLS_PATH}/avr/bin/avr-nm}" AVR_NM="${AVR_NM:-${ARDUINO_TOOLS_PATH}/avr/bin/avr-nm}"
AVR_OBJDUMP="${AVR_OBJDUMP:-${ARDUINO_TOOLS_PATH}/avr/bin/avr-objdump}"
MD5="md5sum"
BUILD_PATH="${BUILD_PATH:-$(mktemp -d 2>/dev/null || mktemp -d -t 'build')}" BUILD_PATH="${BUILD_PATH:-$(mktemp -d 2>/dev/null || mktemp -d -t 'build')}"
OUTPUT_DIR="${OUTPUT_DIR:-output/${LIBRARY}}" OUTPUT_DIR="${OUTPUT_DIR:-output/${LIBRARY}}"
@ -41,6 +50,7 @@ LIB_VERSION="$( (grep version= ../../library.properties 2>/dev/null || echo vers
OUTPUT_FILE_PREFIX="${SKETCH}-${LIB_VERSION}" OUTPUT_FILE_PREFIX="${SKETCH}-${LIB_VERSION}"
HEX_FILE_PATH="${OUTPUT_PATH}/${OUTPUT_FILE_PREFIX}.hex" HEX_FILE_PATH="${OUTPUT_PATH}/${OUTPUT_FILE_PREFIX}.hex"
HEX_FILE_WITH_BOOTLOADER_PATH="${OUTPUT_PATH}/${OUTPUT_FILE_PREFIX}-with-bootloader.hex"
ELF_FILE_PATH="${OUTPUT_PATH}/${OUTPUT_FILE_PREFIX}.elf" ELF_FILE_PATH="${OUTPUT_PATH}/${OUTPUT_FILE_PREFIX}.elf"
ARDUINO_TOOLS_PARAM="-tools ${ARDUINO_TOOLS_PATH}" ARDUINO_TOOLS_PARAM="-tools ${ARDUINO_TOOLS_PATH}"
@ -57,3 +67,19 @@ if [ ! -z "${VERBOSE}" ] && [ "${VERBOSE}" -gt 0 ]; then
else else
ARDUINO_VERBOSE="-quiet" ARDUINO_VERBOSE="-quiet"
fi fi
## Platform-specific overrides
# Shamelessly stolen from git's Makefile
uname_S=$(uname -s 2>/dev/null || echo not)
if [ "${uname_S}" = "Darwin" ]; then
DEVICE_PORT="$(ls /dev/cu.usbmodemHID?? /dev/cu.usbmodem14*)"
DEVICE_PORT_BOOTLOADER="$(ls /dev/cu.usbmodem14*)"
ARDUINO_PATH="/Applications/Arduino.app/Contents/Java/"
ARDUINO_LOCAL_LIB_PATH="${HOME}/Documents/Arduino"
MD5="md5"
RESET_BOARD="stty -f ${DEVICE_PORT} 1200"
fi

Loading…
Cancel
Save