Modify build system to place artefacts in separate out/ folder

This commit is contained in:
Keir Fraser
2022-03-15 12:40:35 +00:00
parent 3f81408812
commit 1f6d6c7dcf
18 changed files with 151 additions and 190 deletions

View File

@@ -27,10 +27,10 @@ jobs:
run: |
export P=greaseweazle-firmware
export V=${{ steps.vars.outputs.sha_short }}
make dist
make -j4 dist
mkdir -p _cidist
rm $P-v*.zip
mv $P-v* $P-$V
rm out/$P-v*.zip
mv out/$P-v* $P-$V
rm $P-$V/RELEASE_NOTES
git rev-parse HEAD >$P-$V/COMMIT
zip -r $P-$V.zip $P-$V
@@ -40,9 +40,9 @@ jobs:
run: |
export P=greaseweazle-firmware
export V=${{ steps.vars.outputs.sha_short }}-debug
env debug=y make dist
rm $P-v*.zip
mv $P-v* $P-$V
make -j4 dist level=debug
rm out/$P-v*.zip
mv out/$P-v* $P-$V
rm $P-$V/RELEASE_NOTES
git rev-parse HEAD >$P-$V/COMMIT
echo debug >>$P-$V/COMMIT

View File

@@ -27,7 +27,9 @@ jobs:
run: python3 -m pip install --user crcmod
- name: Build dist
run: make dist
run: |
make -j4 dist
mv out/*.zip .
- name: Upload artifacts
uses: actions/upload-artifact@v2

15
.gitignore vendored
View File

@@ -1,16 +1,5 @@
*.[oa]
.*.d
*~
*.ld
*.elf
*.bin
*.hex
*.orig
*.rej
*.upd
*.adf
*.hfe
*.ipf
*.scp
*.pyc
greaseweazle-firmware-*
/out
/ext

125
Makefile
View File

@@ -2,85 +2,80 @@
export FW_MAJOR := 1
export FW_MINOR := 1
TARGETS := all blinky clean dist mrproper f1_ocd ocd flash start serial
.PHONY: $(TARGETS)
ifneq ($(RULES_MK),y)
export ROOT := $(CURDIR)
$(TARGETS):
$(MAKE) -f $(ROOT)/Rules.mk $@
else
PROJ = greaseweazle-firmware
VER := v$(FW_MAJOR).$(FW_MINOR)
SUBDIRS += src bootloader blinky_test
PYTHON := python3
all:
$(MAKE) -C src -f $(ROOT)/Rules.mk \
greaseweazle.elf greaseweazle.bin greaseweazle.hex
$(MAKE) bootloader=y -C bootloader -f $(ROOT)/Rules.mk \
bootloader.elf bootloader.bin bootloader.hex
srec_cat bootloader/bootloader.hex -Intel src/greaseweazle.hex -Intel \
-o $(PROJ)-$(VER).hex -Intel
$(PYTHON) ./scripts/mk_update.py new $(PROJ)-$(VER).upd \
bootloader/bootloader.bin src/greaseweazle.bin $(mcu)
export ROOT := $(CURDIR)
blinky:
$(MAKE) debug=y mcu=stm32f1 -C blinky_test -f $(ROOT)/Rules.mk \
blinky.elf blinky.bin blinky.hex
.PHONY: FORCE
clean::
rm -f *.hex *.upd
find . -name __pycache__ | xargs rm -rf
.DEFAULT_GOAL := all
dist:
rm -rf $(PROJ)-*
mkdir -p $(PROJ)-$(VER)/hex/alt
$(MAKE) clean
$(MAKE) mcu=stm32f1 all blinky
cp -a $(PROJ)-$(VER).hex $(PROJ)-$(VER)/hex/$(PROJ)-f1-$(VER).hex
cp -a $(PROJ)-$(VER).upd $(PROJ)-$(VER)/$(PROJ)-$(VER).upd
cp -a blinky_test/blinky.hex $(PROJ)-$(VER)/hex/alt/blinky-test-f1-$(VER).hex
cp -a COPYING $(PROJ)-$(VER)/
cp -a README $(PROJ)-$(VER)/
cp -a RELEASE_NOTES $(PROJ)-$(VER)/
$(MAKE) clean
$(MAKE) mcu=stm32f7 all
cp -a $(PROJ)-$(VER).hex $(PROJ)-$(VER)/hex/$(PROJ)-f7-$(VER).hex
$(PYTHON) ./scripts/mk_update.py cat $(PROJ)-$(VER)/$(PROJ)-$(VER).upd \
$(PROJ)-$(VER)/$(PROJ)-$(VER).upd $(PROJ)-$(VER).upd
$(MAKE) clean
$(MAKE) mcu=at32f4 all
cp -a $(PROJ)-$(VER).hex $(PROJ)-$(VER)/hex/$(PROJ)-at32f4-$(VER).hex
$(PYTHON) ./scripts/mk_update.py cat $(PROJ)-$(VER)/$(PROJ)-$(VER).upd \
$(PROJ)-$(VER)/$(PROJ)-$(VER).upd $(PROJ)-$(VER).upd
$(MAKE) clean
$(ZIP) $(PROJ)-$(VER).zip $(PROJ)-$(VER)
prod-%: FORCE
$(MAKE) target mcu=$* target=bootloader level=prod
$(MAKE) target mcu=$* target=greaseweazle level=prod
mrproper: clean
rm -rf $(PROJ)-*
debug-%: FORCE
$(MAKE) target mcu=$* target=bootloader level=debug
$(MAKE) target mcu=$* target=greaseweazle level=debug
all-%: FORCE prod-% debug-% ;
all: FORCE all-stm32f1 all-stm32f7 all-at32f4 ;
$(MAKE) target mcu=stm32f1 target=blinky level=debug
clean: FORCE
rm -rf out
out: FORCE
mkdir -p out/$(mcu)/$(level)/$(target)
rsync -a --include="*/" --exclude="*" src/ out/$(mcu)/$(level)/$(target)
target: FORCE out
$(MAKE) -C out/$(mcu)/$(level)/$(target) -f $(ROOT)/Rules.mk target.bin target.hex target.upd $(mcu)=y $(level)=y $(target)=y
dist: level := prod
dist: FORCE all
rm -rf out/$(PROJ)-*
$(eval t := out/$(PROJ)-$(VER))
mkdir -p out/$(PROJ)-$(VER)/hex/alt
$(eval s := out/stm32f1/$(level)/greaseweazle)
cp -a $(s)/target.hex $(t)/hex/$(PROJ)-f1-$(VER).hex
cp -a $(s)/target.upd $(t)/$(PROJ)-$(VER).upd
$(eval s := out/stm32f1/debug/blinky)
cp -a $(s)/target.hex $(t)/hex/alt/blinky-test-f1-$(VER).hex
$(eval s := out/stm32f7/$(level)/greaseweazle)
cp -a $(s)/target.hex $(t)/hex/$(PROJ)-f7-$(VER).hex
$(PYTHON) ./scripts/mk_update.py cat $(t)/$(PROJ)-$(VER).upd \
$(t)/$(PROJ)-$(VER).upd $(s)/target.upd
$(eval s := out/at32f4/$(level)/greaseweazle)
cp -a $(s)/target.hex $(t)/hex/$(PROJ)-at32f4-$(VER).hex
$(PYTHON) ./scripts/mk_update.py cat $(t)/$(PROJ)-$(VER).upd \
$(t)/$(PROJ)-$(VER).upd $(s)/target.upd
cp -a COPYING $(t)/
cp -a README $(t)/
cp -a RELEASE_NOTES $(t)/
(cd out && zip -r $(PROJ)-$(VER).zip $(PROJ)-$(VER))
BAUD=115200
DEV=/dev/ttyUSB0
SUDO=sudo
STM32FLASH=stm32flash
ocd: all
ocd: FORCE all
$(PYTHON) scripts/telnet.py localhost 4444 \
"reset init ; flash write_image erase `pwd`/$(PROJ)-$(VER).hex ; reset"
"reset init ; flash write_image erase `pwd`/$(target)/$(target).hex ; reset"
f1_ocd: all
python3 scripts/openocd/flash.py `pwd`/$(PROJ)-$(VER).hex
f1_ocd: FORCE all
$(PYTHON) scripts/openocd/flash.py `pwd`/$(target)/$(target).hex
flash: all
sudo stm32flash -b $(BAUD) -w $(PROJ)-$(VER).hex $(DEV)
flash: FORCE all
$(SUDO) $(STM32FLASH) -b $(BAUD) -w $(target)/$(target).hex $(DEV)
start:
sudo stm32flash -b $(BAUD) -g 0 $(DEV)
start: FORCE
$(SUDO) $(STM32FLASH) -b $(BAUD) -g 0 $(DEV)
serial:
sudo miniterm.py $(DEV) 3000000
endif
serial: FORCE
$(SUDO) miniterm.py $(DEV) 3000000

View File

@@ -46,9 +46,8 @@ CFLAGS += $(CFLAGS-y) $(FLAGS) -include decls.h
AFLAGS += $(AFLAGS-y) $(FLAGS) -D__ASSEMBLY__
LDFLAGS += $(LDFLAGS-y) $(FLAGS) -Wl,--gc-sections
RULES_MK := y
include Makefile
SRCDIR := $(shell $(PYTHON) $(ROOT)/scripts/srcdir.py $(CURDIR))
include $(SRCDIR)/Makefile
SUBDIRS += $(SUBDIRS-y)
OBJS += $(OBJS-y) $(patsubst %,%/build.o,$(SUBDIRS))
@@ -67,19 +66,11 @@ build.o: $(OBJS)
%/build.o: FORCE
$(MAKE) -f $(ROOT)/Rules.mk -C $* build.o
%.o: %.c Makefile
@echo CC $@
$(CC) $(CFLAGS) -c $< -o $@
%.o: %.S Makefile
@echo AS $@
$(CC) $(AFLAGS) -c $< -o $@
%.ld: %.ld.S Makefile
%.ld: $(SRCDIR)/%.ld.S $(SRCDIR)/Makefile
@echo CPP $@
$(CC) -P -E $(AFLAGS) $< -o $@
%.elf: $(OBJS) %.ld Makefile
%.elf: $(OBJS) %.ld $(SRCDIR)/Makefile
@echo LD $@
$(CC) $(LDFLAGS) -T$(*F).ld $(OBJS) -o $@
chmod a-x $@
@@ -88,23 +79,25 @@ build.o: $(OBJS)
@echo OBJCOPY $@
$(OBJCOPY) -O ihex $< $@
chmod a-x $@
ifneq ($(bootloader),y)
srec_cat ../bootloader/target.hex -Intel $@ -Intel -o $@ -Intel
endif
%.bin: %.elf
@echo OBJCOPY $@
$(OBJCOPY) -O binary $< $@
chmod a-x $@
%.o: $(RPATH)/%.c Makefile
%.upd: %.bin
$(PYTHON) $(ROOT)/scripts/mk_update.py new $@ \
../bootloader/target.bin $< $(mcu)
%.o: $(SRCDIR)/%.c $(SRCDIR)/Makefile
@echo CC $@
$(CC) $(CFLAGS) -c $< -o $@
%.o: $(RPATH)/%.S Makefile
%.o: $(SRCDIR)/%.S $(SRCDIR)/Makefile
@echo AS $@
$(CC) $(AFLAGS) -c $< -o $@
clean:: $(addprefix _clean_,$(SUBDIRS) $(SUBDIRS-n) $(SUBDIRS-))
rm -f *.orig *.rej *~ *.o *.elf *.hex *.bin *.ld $(DEPS)
_clean_%: FORCE
$(MAKE) -f $(ROOT)/Rules.mk -C $* clean
-include $(DEPS)

View File

@@ -1,19 +0,0 @@
RPATH = $(ROOT)/src
OBJS += board.o
OBJS += build_info.o
OBJS += crc.o
OBJS += vectors.o
OBJS += fw_update.o
OBJS += string.o
OBJS += cortex.o
OBJS += time.o
OBJS += timer.o
OBJS += util.o
OBJS-$(debug) += console.o
SUBDIRS += mcu usb
.PHONY: $(RPATH)/build_info.c
build_info.o: CFLAGS += -DFW_MAJOR=$(FW_MAJOR) -DFW_MINOR=$(FW_MINOR)

View File

@@ -1,14 +0,0 @@
#if MCU == STM32F1
#define FLASH_BASE 0x08000000
#define FLASH_LEN 8K
#elif MCU == STM32F7 || MCU == AT32F4
#define FLASH_BASE 0x08000000
#define FLASH_LEN 16K
#endif
#include "../scripts/stm32.ld.S"

View File

@@ -1,3 +0,0 @@
SUBDIRS-$(stm32f1) += stm32f1
SUBDIRS-$(stm32f7) += stm32f7
SUBDIRS-$(at32f4) += at32f4

View File

@@ -1,4 +0,0 @@
RPATH = $(ROOT)/src/mcu/at32f4
OBJS += stm32.o
OBJS += fpec.o

View File

@@ -1,4 +0,0 @@
RPATH = $(ROOT)/src/mcu/stm32f1
OBJS += stm32.o
OBJS += fpec.o

View File

@@ -1,4 +0,0 @@
RPATH = $(ROOT)/src/mcu/stm32f7
OBJS += stm32.o
OBJS += fpec.o

View File

@@ -1,17 +0,0 @@
RPATH = $(ROOT)/src/usb
OBJS += config.o
OBJS += core.o
OBJS += cdc_acm.o
OBJS-$(stm32f1) += hw_usbd.o
OBJS-$(stm32f1) += hw_f1.o
OBJS-$(stm32f7) += hw_dwc_otg.o
OBJS-$(stm32f7) += hw_f7.o
OBJS-$(at32f4) += hw_dwc_otg.o
OBJS-$(at32f4) += hw_usbd_at32f4.o
OBJS-$(at32f4) += hw_at32f4.o
$(OBJS) $(OBJS-y): CFLAGS += -include $(ROOT)/src/usb/defs.h

View File

@@ -32,8 +32,9 @@ class Version:
def __init__(self, major, minor):
self.major, self.minor = major, minor
with open('Makefile', 'r') as f:
l = f.read()
if sys.argv[1] == 'new':
with open('../../../../Makefile', 'r') as f:
l = f.read()
major = int(re.search('FW_MAJOR := (\d+)', l).group(1))
minor = int(re.search('FW_MINOR := (\d+)', l).group(1))
version = Version(major, minor)

29
scripts/srcdir.py Normal file
View File

@@ -0,0 +1,29 @@
# srcdir.py
#
# Helper script to locate the relative source folder for a given object folder.
# For example:
# objdir = /path/to/out/stm32f105/prod/floppy/usb
# srcdir = ../../../../../src/usb
#
# Written & released by Keir Fraser <keir.xen@gmail.com>
#
# This is free and unencumbered software released into the public domain.
# See the file COPYING for more details, or visit <http://unlicense.org>.
import sys, re
# /out/<mcu>/<level>/<target>
NR_LEVELS = 4
objdir = sys.argv[1]
# stem = /out/<mcu>/<level>/target[/<rest_of_path>]
stem = objdir[objdir.rfind('/out'):]
# stem = [/<rest_of_path>]
m = re.match('/[^/]*'*NR_LEVELS+'(/.*)?', stem)
stem = '' if m.group(1) is None else m.group(1)
# srcdir = path to sources, relative to objdir
srcdir = '../'*(NR_LEVELS+stem.count('/')) + 'src' + stem
print(srcdir)

View File

@@ -2,18 +2,30 @@ OBJS += board.o
OBJS += build_info.o
OBJS += crc.o
OBJS += vectors.o
OBJS += main.o
OBJS += string.o
OBJS += cortex.o
OBJS += time.o
OBJS += timer.o
OBJS += util.o
OBJS-$(debug) += console.o
ifeq ($(blinky),y)
OBJS += blinky.o
else ifeq ($(bootloader),y)
OBJS += fw_update.o
else
OBJS += main.o
OBJS += floppy.o
OBJS += testmode.o
OBJS-$(debug) += console.o
endif
SUBDIRS += mcu usb
.PHONY: build_info.c
.PHONY: $(SRCDIR)/build_info.c
build_info.o: CFLAGS += -DFW_MAJOR=$(FW_MAJOR) -DFW_MINOR=$(FW_MINOR)

View File

@@ -1,14 +0,0 @@
#if MCU == STM32F1
#define FLASH_BASE 0x08002000
#define FLASH_LEN 56K
#elif MCU == STM32F7 || MCU == AT32F4
#define FLASH_BASE 0x08004000
#define FLASH_LEN 48K
#endif
#include "../scripts/stm32.ld.S"

19
src/target.ld.S Normal file
View File

@@ -0,0 +1,19 @@
#if defined(BOOTLOADER) && (MCU == STM32F1)
#define FLASH_BASE 0x08000000
#define FLASH_LEN 8K
#elif defined(BOOTLOADER) && (MCU == STM32F7 || MCU == AT32F4)
#define FLASH_BASE 0x08000000
#define FLASH_LEN 16K
#elif MCU == STM32F1
#define FLASH_BASE 0x08002000
#define FLASH_LEN 56K
#elif MCU == STM32F7 || MCU == AT32F4
#define FLASH_BASE 0x08004000
#define FLASH_LEN 48K
#endif
#include "../scripts/stm32.ld.S"

View File

@@ -12,4 +12,4 @@ OBJS-$(at32f4) += hw_dwc_otg.o
OBJS-$(at32f4) += hw_usbd_at32f4.o
OBJS-$(at32f4) += hw_at32f4.o
$(OBJS) $(OBJS-y): CFLAGS += -include defs.h
$(OBJS) $(OBJS-y): CFLAGS += -include $(SRCDIR)/defs.h