Skip to content

Commit

Permalink
Add version info to all generated files.
Browse files Browse the repository at this point in the history
Add .ino generation to scripts/gendata.py.
Clean up Makefile to handle new version number generation.

Note that Adafruit release tags will be v<a>.<b>.<c>-adafruit.<n>.
The first part of the tag is the upstream version. The <n> is the
Adafruit increment from that.
  • Loading branch information
dhalbert authored and tannewt committed Nov 16, 2017
1 parent 6d24f14 commit 1705e7a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 28 deletions.
34 changes: 12 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ CFLAGS = $(COMMON_FLAGS) \
-D__$(CHIP_VARIANT)__ \
$(WFLAGS)

UF2_VERSION_BASE = $(shell git describe --dirty --always --tags)

ifeq ($(CHIP_FAMILY), samd21)
LINKER_SCRIPT=./lib/samd21/samd21a/gcc/gcc/samd21j18a_flash.ld
BOOTLOADER_SIZE=8192
Expand Down Expand Up @@ -79,9 +81,10 @@ SELF_SOURCES = $(COMMON_SRC) \
OBJECTS = $(patsubst src/%.c,$(BUILD_PATH)/%.o,$(SOURCES))
SELF_OBJECTS = $(patsubst src/%.c,$(BUILD_PATH)/%.o,$(SELF_SOURCES)) $(BUILD_PATH)/selfdata.o

NAME=bootloader
NAME=bootloader-$(BOARD)-$(UF2_VERSION_BASE)
EXECUTABLE=$(BUILD_PATH)/$(NAME).bin
SELF_EXECUTABLE=$(BUILD_PATH)/update-$(NAME).uf2
SELF_EXECUTABLE_INO=$(BUILD_PATH)/update-$(NAME).ino

all: dirs $(EXECUTABLE) $(SELF_EXECUTABLE)

Expand Down Expand Up @@ -118,7 +121,7 @@ $(EXECUTABLE): $(OBJECTS)
@echo

$(BUILD_PATH)/uf2_version.h: Makefile
echo "#define UF2_VERSION_BASE \"$(shell git describe --tags)\""> $@
echo "#define UF2_VERSION_BASE \"$(UF2_VERSION_BASE)\""> $@

$(SELF_EXECUTABLE): $(SELF_OBJECTS)
$(CC) -L$(BUILD_PATH) $(LDFLAGS) \
Expand All @@ -134,7 +137,7 @@ $(BUILD_PATH)/%.o: src/%.c $(wildcard inc/*.h boards/*/*.h) $(BUILD_PATH)/uf2_ve
$(BUILD_PATH)/%.o: $(BUILD_PATH)/%.c
$(CC) $(CFLAGS) $(BLD_EXTA_FLAGS) $(INCLUDES) $< -o $@

$(BUILD_PATH)/selfdata.c: $(EXECUTABLE) scripts/gendata.js src/sketch.cpp
$(BUILD_PATH)/selfdata.c: $(EXECUTABLE) scripts/gendata.py src/sketch.cpp
python scripts/gendata.py $(BOOTLOADER_SIZE) $(EXECUTABLE)

clean:
Expand Down Expand Up @@ -162,29 +165,16 @@ drop-board: all
mkdir -p build/drop/$(BOARD)
cp $(SELF_EXECUTABLE) build/drop/$(BOARD)/
cp $(EXECUTABLE) build/drop/$(BOARD)/
cp $(BUILD_PATH)/update-bootloader.ino build/drop/$(BOARD)/
cp $(SELF_EXECUTABLE_INO) build/drop/$(BOARD)/
cp boards/$(BOARD)/board_config.h build/drop/$(BOARD)/

drop-pkg:
mv build/drop build/uf2-samd21-$(VERSION)
cp bin-README.md build/uf2-samd21-$(VERSION)/README.md
cd build; 7z a uf2-samd21-$(VERSION).zip uf2-samd21-$(VERSION)
rm -rf build/uf2-samd21-$(VERSION)

tag:
$(MAKE) VERSION=`awk '/define UF2_VERSION_BASE/ { gsub(/"v?/, ""); print $$3 }' inc/uf2.h` do-tag

do-tag:
git add inc/uf2.h
git diff --exit-code
git commit -m "v$(VERSION)"
git tag "v$(VERSION)"
git push
git push --tag
$(MAKE) drop
mv build/drop build/uf2-samd21-$(UF2_VERSION_BASE)
cp bin-README.md build/uf2-samd21-$(UF2_VERSION_BASE)/README.md
cd build; 7z a uf2-samd21-$(UF2_VERSION_BASE).zip uf2-samd21-$(UF2_VERSION_BASE)
rm -rf build/uf2-samd21-$(UF2_VERSION_BASE)

all-boards:
for f in `cd boards; ls` ; do $(MAKE) BOARD=$$f drop-board ; done

drop: all-boards
$(MAKE) VERSION=`awk '/define UF2_VERSION_BASE/ { gsub(/"v?/, ""); print $$3 }' inc/uf2.h` drop-pkg
drop: all-boards drop-pkg
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ a UF2 file is written and immediately write it to flash.

## Board identification

Configuration files for board `foo` is in `boards/foo/board_config.h`. You can
Configuration files for board `foo` are in `boards/foo/board_config.h` and `board.mk`. You can
build it with `make BOARD=foo`. You can also create `Makefile.user` file with `BOARD=foo`
to change the default.

Expand Down Expand Up @@ -75,11 +75,11 @@ Thus, to update the bootloader, one can ship a user-space program,
that contains the new version of the bootloader and copies it to the
appropriate place in flash.

Such a program is generated during build in files `update-bootloader.uf2`.
Such a program is generated during build in files `update-bootloader*.uf2`.
If you're already running UF2 bootloader, the easiest way to update
it, is to just copy this file to the exposed MSD drive.

The build also generates `update-bootloader.ino` with an equivalent Arduino
The build also generates `update-bootloader*.ino` with an equivalent Arduino
sketch. You can copy&paste it into Arduino IDE and upload it to the device.

## Fuses
Expand Down Expand Up @@ -116,7 +116,7 @@ to temporarily turn off the protection. In gdb the command is:
### Requirements

* `make` and an Unix environment
* `node`.js in path
* `node`.js in path (optional)
* `arm-none-eabi-gcc` in the path (the one coming with Yotta will do just fine)
* `openocd` - you can use the one coming with Arduino (after your install the M0 board support)

Expand All @@ -142,7 +142,7 @@ at `0xffffffff`.
The default board is `zero`. You can build a different one using:

```
make BOARD=metro
make BOARD=metro_m0
```

If you're working on different board, it's best to create `Makefile.local`
Expand Down
16 changes: 15 additions & 1 deletion scripts/gendata.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def update_crc(new_byte, current_crc):
bootloader.extend([0xff] * (bootloader_size - len(bootloader)))

# Output the bootloader binary data into C code to use in the self updater.
with open(os.path.dirname(bin_name) + "/selfdata.c", "w") as output:
selfdata_c_path = os.path.join(os.path.dirname(bin_name), "selfdata.c")
with open(selfdata_c_path, "w") as output:
output.write("#include <stdint.h>\n")
output.write("const uint8_t bootloader[{}] ".format(bootloader_size) +
"__attribute__ ((aligned (4))) = {")
Expand All @@ -49,3 +50,16 @@ def update_crc(new_byte, current_crc):
crcs = ["0x{:04x}".format(x) for x in crcs]
output.write("const uint16_t bootloader_crcs[] = {" +
" ,".join(crcs) + "};\n")

bin_dirname = os.path.dirname(bin_name)
bin_basename_no_ext = os.path.basename(os.path.splitext(bin_name)[0])
with open(os.path.join(bin_dirname, "update-" + bin_basename_no_ext + ".ino"), "w") as output:
output.write("""\
// Bootloader update sketch. Paste into Arduino IDE and upload to the device
// to update bootloader. It will blink a few times and then start pulsing.
// Your OS will then detect a USB mass storage device.
""")
with open(selfdata_c_path) as input:
output.write(input.read())
with open("src/sketch.cpp") as input:
output.write(input.read())

0 comments on commit 1705e7a

Please sign in to comment.