Skip to content

Commit

Permalink
Merge branch 'binary-image-constraints-CI'
Browse files Browse the repository at this point in the history
Make the extended firmware in the CI
  • Loading branch information
szszszsz committed Jul 30, 2021
2 parents aff3dc6 + b3719fb commit 6e6319a
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 11 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
FROM ubuntu:latest
RUN apt-get update && apt-get install unzip make wget binutils-avr git -qy
RUN apt-get update -q \
&& apt-get install -qy unzip make wget git python3 pipenv
# COPY avr32studio-ide-2.6.0
ARG TOOLCHAIN_LINK=
RUN cd / && wget ${TOOLCHAIN_LINK} -O toolchain.zip -q && \
Expand Down
28 changes: 23 additions & 5 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ include build.mk
GIT=$(shell git describe)
FIRMWARE=nitrokey-storage-$(GIT).hex

all: firmware.hex $(FIRMWARE) firmware_info firmware.lss
all: firmware.hex $(FIRMWARE) firmware_info firmware.lss firmware-extended.hex
ls -lh $<

$(FIRMWARE): firmware.hex
$(FIRMWARE): firmware-extended.hex
cp $< $@

.PHONY: clean
clean:
-rm $(OBJS) $(OBJSASM)
-rm $(OBJS) $(OBJSASM) $(STATEFILES)

.PHONY: build-docker-toolchain
build-docker-toolchain:
Expand All @@ -34,12 +34,22 @@ USB_MASS.elf: $(OBJS) $(OBJSASM)
@$(RUNASM) -o $@ $<

.PHONY: firmware_info
firmware_info: firmware.hex
-cd ../tools && pipenv run ./randomize_empty_space.py status --firmware-file ../src/$<
firmware_info: | pipenv firmware.hex
-cd ../tools && pipenv run ./randomize_empty_space.py status --firmware-file ../src/firmware.hex
-cd ../tools && pipenv run ./randomize_empty_space.py status --firmware-file ../src/firmware-extended.hex

firmware.lss: USB_MASS.elf
$(OBJDUMP) -h -S $< > $@

STATEFILES += pipenv
pipenv:
-cd ../tools && pipenv --rm
cd ../tools && pipenv install --python `which python3`
touch $@

firmware-extended.hex: | pipenv firmware.hex
cd ../tools && pipenv run ./randomize_empty_space.py fill-empty --random-data random.bin --firmware-file ../src/firmware.hex --output-file-name ../src/firmware-extended

firmware.hex: USB_MASS.elf
ls -l $<
$(OBJCOPY) -R .eeprom -O ihex $< $@
Expand Down Expand Up @@ -68,6 +78,7 @@ enable_bootloader:
.PHONY: run_tests
run_tests:
cd $(LIBNK)/unittest && pipenv run pytest $(TP) test_storage.py --template=html1/index.html --report=report.html && notify-send --urgency=low "finished" || notify-send --urgency=low "failed" && xdg-open report.html && false
cp $(LIBNK)/unittest/report.html .

.PHONY: run_tests_quick
TESTS=status
Expand All @@ -84,5 +95,12 @@ help:
devloop: | all enable_bootloader flash run_tests_quick
@echo done

RELEASEDIR=release
.PHONY: release
release: all
mkdir -p $(RELEASEDIR)
rm ./$(RELEASEDIR)/*
mv -v *.hex $(RELEASEDIR)
ls $(RELEASEDIR)

-include local.mk
13 changes: 13 additions & 0 deletions tools/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
intelhex = "*"
click = "*"

[requires]
python_version = "3.8"
37 changes: 37 additions & 0 deletions tools/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions tools/randomize_empty_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def status(firmware_file):
type=click.File('r'))
@click.option("--random-data", prompt="Random data path", help="Random data path", default="random.bin",
type=click.File('rb'))
@click.option("--output-file-prefix", prompt="Output file name prefix", help="Output file name prefix", default="firmware-extended")
def fill_empty(firmware_file, random_data, output_file_prefix):
@click.option("--output-file-name", prompt="Output file name", help="Output file name (without extension)", default="firmware-extended")
def fill_empty(firmware_file, random_data, output_file_name):
"""Fill empty firmware space with the provided random file data content."""
firmware = intelhex.IntelHex()
firmware.loadfile(firmware_file, format='hex')
Expand Down Expand Up @@ -91,10 +91,10 @@ def fill_empty(firmware_file, random_data, output_file_prefix):
calculate_occupation(firmware)

ext = "{.bin,.hex}"
print(f'*** Saving to {output_file_prefix}{ext}')
with open('%s.hex' % output_file_prefix, 'w+') as f:
print(f'*** Saving to {output_file_name}{ext}')
with open('%s.hex' % output_file_name, 'w+') as f:
firmware.write_hex_file(f)
with open('%s.bin' % output_file_prefix, 'bw+') as f:
with open('%s.bin' % output_file_name, 'bw+') as f:
firmware.tobinfile(f)


Expand All @@ -104,3 +104,4 @@ def fill_empty(firmware_file, random_data, output_file_prefix):
if __name__ == '__main__':
print(f'Assuming user page starts at: {hex(USER_PAGE_START)} ({(USER_PAGE_START - FLASH_START) / 1024} kB)')
cli()
print('Done')

0 comments on commit 6e6319a

Please sign in to comment.