# SPDX-FileCopyrightText: 2021 Foundation Devices, Inc. # # SPDX-License-Identifier: GPL-3.0-or-later # Install dependencies. deps: @echo "Not sure we will need this if all deps are setup via Dockerfile" # Initialize development environment init: deps git config core.hooksPath .githooks # Lint only the python code of the project lint-py: pycodestyle --exclude trezor-firmware --statistics . # Lint only the C code of the project lint-c: @echo "TBD" # Lint only the code of the project lint-code: lint-py lint-c # Lint the licensing lint-license: reuse lint # Lint all of the project lint: lint-code lint-license # # Firmware Commands # build: make BOARD=Passport # Sign current firmware build with the user.pem key and set specified version sign version="1.0.0": build @echo "\nAdding user signature...\n" @cosign -f build-Passport/firmware.bin -k ~/bin/keys/user.pem -v {{version}} > /dev/null @cosign -f build-Passport/firmware-key-user.bin -x @echo "\nSigning Complete!" # Build, sign and flash the firmware with the specified version flash version="1.0.0": (sign version) just run-ocd-command "flash write_image erase build-Passport/firmware-key-user.bin 0x8020000" just reset # Install a recent Foundation-signed build flash-foundation version="1.0.0": just run-ocd-command "flash write_image erase ../../releases/passport-fw-{{version}}.bin 0x8020000" just reset # Clean the firmware build clean: make BOARD=Passport clean # # Misc. Commands # # Launch OCD, run a command and then exit run-ocd-command command: sudo /usr/local/bin/openocd -f stlink.cfg -c "adapter speed 1000; transport select hla_swd" -f stm32h7x.cfg -c "init; reset halt; {{command}}" -c "exit" run-ocd-command-no-halt command: sudo /usr/local/bin/openocd -f stlink.cfg -c "adapter speed 1000; transport select hla_swd" -f stm32h7x.cfg -c "init; {{command}}" -c "exit" # Build all Python graphics graphics-py: just -f boards/Passport/graphics/py/Justfile build # Build all C graphics (firmware & bootloader) graphics-c: just -f boards/Passport/graphics/c/Justfile build graphics: graphics-py graphics-c # Reset the Passport reset: just run-ocd-command "reset" # Get the username for use below user := `whoami` # Read the "ROM Secrets" from Passport and save them to a file save-secrets filename="boards/Passport/bootloader/secrets": just run-ocd-command "dump_image {{filename}} 0x0801FF00 256" # Running OCD as sudo makes the output file be owned by root, so switch it back to the user sudo chown {{user}}:{{user}} {{filename}} secrets: #!/usr/bin/env bash # The last bit below redirects stderr to stdout, which the backticks capture into the variable `secrets` secrets=`just run-ocd-command "mdb 0x0801FF00 256" 2>&1` secrets=`echo "$secrets" | tail -n 8` echo -e "Passport ROM Secrets:\n$secrets" # Calculate all hashes and format it all for GitHub release notes hash filepath: #!/usr/bin/env bash filename=`basename {{filepath}}` # SHA256 sha=`shasum -b -a 256 {{filepath}} | sed -rn 's/^(.*) .*$/\1/p'` echo -e "\n\`SHA256: $sha\`" echo -e "\`(shasum -b -a 256 $filename)\`\n" # MD5 md5=`mdsum {{filepath}} | sed -rn 's/^(.*) .*$/\1/p'` echo "\`MD5: $md5\`" echo -e "\`(md5 $filename or mdsum $filename)\`\n" # Build Hash build_hash=`cosign -f {{filepath}} -x | sed -rn 's/^FW Build Hash: (.*)$/\1/p'` echo -e "\`Build Hash: $build_hash\`" echo -e "\`(Developers Only)\`\n" # Run all tests test: @echo "TBD" # Format the project's .py files under boards/Passport/modules fmt-py: #!/usr/bin/env bash pushd boards/Passport/modules files_to_fmt=`find . -path ./trezor-firmware -prune -false -o -name '*.py'` autopep8 --max-line-length=120 --in-place $files_to_fmt popd # Format the project's .c and .h files under boards/Passport/ fmt-c: #!/usr/bin/env bash pushd boards/Passport files_to_fmt=`find . -path ./trezor-firmware -prune -false -o -name '*.[c|h]'` clang-format-5.0 -i --style=file $files_to_fmt popd # Format the project's source code under boards/Passport fmt: fmt-py fmt-c # Convert a raw pixel map to a PNG convert-screenshot from_file to_file: #!/usr/bin/python3 from PIL import Image, ImageOps raw_bits = open('{{from_file}}', 'rb').read() WIDTH = 230 HEIGHT = 303 SCAN_WIDTH = 240 # Convert img = Image.frombuffer('1', (SCAN_WIDTH, HEIGHT), raw_bits) # Crop to actual width (framebuffer is 240 vs 230 for actual display) img = img.crop((0, 0, WIDTH, HEIGHT)) # Invert since raw image is actually white on black - have to convert to grayscale first since invert() doesn't work # for 1-bit per pixel black/white images. img = ImageOps.grayscale(img) img = ImageOps.invert(img) # Apply a color shift to make it look nicer img = ImageOps.colorize(img, (0,0,0,0), '#E0E0E0') img.save('{{to_file}}') # Capture a screenshot from Passport via OCD screenshot filename: #!/usr/bin/env bash ADDR_FILE=screenshot-addr.tmp TMP_FILE=screenshot.tmp just run-ocd-command-no-halt "dump_image $ADDR_FILE 0x38006920 4" N=`head -c 4 $ADDR_FILE | od -An --endian=little -t u4` FRAMEBUFFER_ADDR=`printf '%x\n' $N` echo FRAMEBUFFER_ADDR=$FRAMEBUFFER_ADDR just run-ocd-command-no-halt "dump_image screenshot.tmp 0x$FRAMEBUFFER_ADDR 9090" just convert-screenshot $TMP_FILE {{filename}} rm -f $TMP_FILE $ADDR_FILE