Browse Source

PASS1-137: Add Justfile support to Gen 1 repo (#36)

* PASS1-137: Add Justfile support to Gen 1 repo

First pass - not all expected commands are added yet

* Update Justfile with fmt command

Add py and c/h formatting
Need to finalize .clang-format file before doing a full reformatting PR

* Refactor Justfiles to separate them out

Also add graphics build commands

* Update Justfiles a bit

Fix formatting of graphics header files in preparation for automatic code formatting
PASS1-132
Ken Carpenter 4 years ago
committed by GitHub
parent
commit
dfd372d082
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 129
      ports/stm32/Justfile
  2. 112
      ports/stm32/boards/Passport/.clang-format
  3. 4
      ports/stm32/boards/Passport/.reuse/dep5
  4. 39
      ports/stm32/boards/Passport/bootloader/Justfile
  5. 2
      ports/stm32/boards/Passport/bootloader/Makefile
  6. 6
      ports/stm32/boards/Passport/bootloader/bootloader_graphics.h
  7. BIN
      ports/stm32/boards/Passport/bootloader/secrets
  8. 6
      ports/stm32/boards/Passport/firmware_graphics.h
  9. 9
      ports/stm32/boards/Passport/graphics/c/Justfile
  10. 6
      ports/stm32/boards/Passport/graphics/c/cbuild.py
  11. 8
      ports/stm32/boards/Passport/graphics/py/Justfile
  12. 7
      ports/stm32/boards/Passport/tools/version_info/version_info
  13. 5
      ports/stm32/boards/Passport/tools/word_list_gen/word_list_gen.c

129
ports/stm32/Justfile

@ -0,0 +1,129 @@
# SPDX-FileCopyrightText: 2021 Foundation Devices, Inc. <hello@foundationdevices.com>
#
# 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 code of the project
lint-code:
@echo "TBD"
# Lint all of the project
lint: lint-code
reuse lint
#
# 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"
# 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

112
ports/stm32/boards/Passport/.clang-format

@ -1,7 +1,107 @@
---
# We'll use defaults from the LLVM style, but with 4 columns indentation.
BasedOnStyle: Mozilla
IndentWidth: 4
---
Language: Cpp
ColumnLimit: 120
Language: Cpp
# BasedOnStyle: Chromium
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: false
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: false
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeCategories:
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
ReflowComments: false
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
TabWidth: 8
UseTab: Never
...

4
ports/stm32/boards/Passport/.reuse/dep5

@ -18,3 +18,7 @@ License: GPL-3.0-or-later
Files: .vscode/settings.json TODO.txt bootloader/se-config.h clang-format.txt include/se-config.h modules/graphics.py pins.csv utils/README.md
Copyright: 2020 Foundation Devices, Inc. <hello@foundationdevices.com>
License: GPL-3.0-or-later
Files: tools/version_info/version_info
Copyright: 2021 Foundation Devices, Inc. <hello@foundationdevices.com>
License: GPL-3.0-or-later

39
ports/stm32/boards/Passport/bootloader/Justfile

@ -0,0 +1,39 @@
# SPDX-FileCopyrightText: 2021 Foundation Devices, Inc. <hello@foundationdevices.com>
#
# SPDX-License-Identifier: GPL-3.0-or-later
# Launch OCD, run a command and then exit
run-ocd-command command:
cd ../../../; 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"
# Build the bootloader (debug, release, locked or production)
# TODO: Need to handle {{rel}} for locked and production, which should look in release folder for binary
build rel="release":
@echo "\nBuilding Bootloader..."
make {{rel}}
@echo "\nAppending secrets to the end..."
add-secrets -b arm/{{rel}}/bootloader.bin -s secrets
@echo "\nBootloader Build Complete"
# Clean the bootloader build
clean:
@echo "Cleaning Bootloader..."
make clean
@echo "Bootloader Clean Complete"
# Build and flash the bootloader with the secrets appended to the end
flash rel="release": (build rel)
just run-ocd-command "flash write_image erase boards/Passport/bootloader/arm/{{rel}}/bootloader-secrets.bin 0x8000000"
just reset
# Build and flash the bootloader with no secrets (use to setup a new Secure Element)
flash-raw rel="release": (build rel)
just run-ocd-command "flash write_image erase boards/Passport/bootloader/arm/{{rel}}/bootloader.bin 0x8000000"
just reset
# Reset the Passport
reset:
just run-ocd-command "reset"

2
ports/stm32/boards/Passport/bootloader/Makefile

@ -207,7 +207,7 @@ ifneq ($(MAKECMDGOALS),clean)
endif
# make a 'release' build
release: code-committed check-fontawesome clean all capture
release: clean all
release: CFLAGS += -DRELEASE=1 -Werror
clean:

6
ports/stm32/boards/Passport/bootloader/bootloader_graphics.h

@ -8,9 +8,9 @@
#include <stdint.h>
typedef struct _Image {
int16_t width;
int16_t height;
int16_t byte_width;
int16_t width;
int16_t height;
int16_t byte_width;
uint8_t* data;
} Image;

BIN
ports/stm32/boards/Passport/bootloader/secrets

Binary file not shown.

6
ports/stm32/boards/Passport/firmware_graphics.h

@ -8,9 +8,9 @@
#include <stdint.h>
typedef struct _Image {
int16_t width;
int16_t height;
int16_t byte_width;
int16_t width;
int16_t height;
int16_t byte_width;
uint8_t* data;
} Image;

9
ports/stm32/boards/Passport/graphics/c/Justfile

@ -0,0 +1,9 @@
# SPDX-FileCopyrightText: 2021 Foundation Devices, Inc. <hello@foundationdevices.com>
#
# SPDX-License-Identifier: GPL-3.0-or-later
# Build all C graphics and copy files to main source folders
build:
make
cp firmware_graphics.* ../../
cp bootloader_graphics.* ../../bootloader/

6
ports/stm32/boards/Passport/graphics/c/cbuild.py

@ -78,9 +78,9 @@ def gen_header(outfile, fnames):
#include <stdint.h>
typedef struct _Image {
int16_t width;
int16_t height;
int16_t byte_width;
int16_t width;
int16_t height;
int16_t byte_width;
uint8_t* data;
} Image;

8
ports/stm32/boards/Passport/graphics/py/Justfile

@ -0,0 +1,8 @@
# SPDX-FileCopyrightText: 2021 Foundation Devices, Inc. <hello@foundationdevices.com>
#
# SPDX-License-Identifier: GPL-3.0-or-later
# Build all Python graphics and copy files to main source folder
build:
make
cp graphics.py ../../modules/

7
ports/stm32/boards/Passport/tools/version_info/version_info

@ -1,3 +1,6 @@
# SPDX-FileCopyrightText: 2021 Foundation Devices, Inc. <hello@foundationdevices.com>
# SPDX-License-Identifier: GPL-3.0-or-later
usage()
{
echo "Usage: `basename $0` <version information file name> <release string> [-h]"
@ -11,8 +14,8 @@ release=$2
[ -z "$file" ] && usage
[ -z "$release" ] && usage
echo "// SPDX-FileCopyrightText: $(date +"%Y") Foundation Devices, Inc. <hello@foundationdevices.com>" > $file
echo "// SPDX-License-Identifier: GPL-3.0-or-later" >> $file
echo "// SPDX\x2dFileCopyrightText: $(date +"%Y") Foundation Devices, Inc. <hello@foundationdevices.com>\n" > $file
echo "// SPDX\x2dLicense-Identifier: GPL-3.0-or-later\n" >> $file
echo "//" >> $file
echo "" >> $file
echo "char *build_date = \"$(date +"%b. %d, %Y")\";" >> $file

5
ports/stm32/boards/Passport/tools/word_list_gen/word_list_gen.c

@ -87,8 +87,9 @@ int compare_word_info(const void * a, const void * b) {
}
void make_num_pairs_array(const char** words, char* prefix) {
printf("// SPDX-FileCopyrightText: 2021 Foundation Devices, Inc. <hello@foundationdevices.com>\n");
printf("// SPDX-License-Identifier: GPL-3.0-or-later\n");
// Insert the hyphen all weird like this so that `reuse lint` doesn't complain about parsing this
printf("// SPDX%cFileCopyrightText: 2021 Foundation Devices, Inc. <hello@foundationdevices.com>\n", '-');
printf("// SPDX%cLicense-Identifier: GPL-3.0-or-later\n", '-');
printf("//\n\n");
printf("#include <stdint.h>\n\n");

Loading…
Cancel
Save