Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorganisation of the repo #424

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,4 @@ main
builds/*
tools/testing/.idea/*
tools/testing/tests/__pycache__/*
.idea/*
8 changes: 4 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[submodule "tinycbor"]
path = tinycbor
path = libs/tinycbor
url = https://github.com/intel/tinycbor
[submodule "crypto/micro-ecc"]
path = crypto/micro-ecc
path = libs/crypto/micro-ecc
url = https://github.com/kmackay/micro-ecc.git
[submodule "crypto/tiny-AES-c"]
path = crypto/tiny-AES-c
path = libs/crypto/tiny-AES-c
url = https://github.com/kokke/tiny-AES-c
[submodule "targets/stm32l442/dfuse-tool"]
path = targets/stm32l442/dfuse-tool
url = https://github.com/solokeys/dfuse-tool
[submodule "crypto/cifra"]
path = crypto/cifra
path = libs/crypto/cifra
url = https://github.com/solokeys/cifra.git
115 changes: 27 additions & 88 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,69 +1,29 @@
include fido2/version.mk
#Load commons variables
include common.mk

#define uECC_arch_other 0
#define uECC_x86 1
#define uECC_x86_64 2
#define uECC_arm 3
#define uECC_arm_thumb 4
#define uECC_arm_thumb2 5
#define uECC_arm64 6
#define uECC_avr 7
ecc_platform=2
.PHONY: all $(LIBCBOR) $(LIBSOLO) black blackcheck cppcheck wink clean full-clean travis test clean version pc stm32l432
all: pc stm32l432

src = pc/device.c pc/main.c
pc:
$(MAKE) -C $(TARGET_PC_PATH) $(ACTION)

obj = $(src:.c=.o)
stm32l432:
$(MAKE) -C $(TARGET_STM32L432_PATH) $(ACTION)

LIBCBOR = tinycbor/lib/libtinycbor.a
LIBSOLO = fido2/libsolo.a

ifeq ($(shell uname -s),Darwin)
export LDFLAGS = -Wl,-dead_strip
else
export LDFLAGS = -Wl,--gc-sections
endif
LDFLAGS += $(LIBSOLO) $(LIBCBOR)


CFLAGS = -O2 -fdata-sections -ffunction-sections -g
ECC_CFLAGS = -O2 -fdata-sections -ffunction-sections -DuECC_PLATFORM=$(ecc_platform)

INCLUDES = -I../ -I./fido2/ -I./pc -I../pc -I./tinycbor/src

CFLAGS += $(INCLUDES)
CFLAGS += -DAES256=1 -DSOLO_EXPERIMENTAL=1 -DDEBUG_LEVEL=1

name = main

.PHONY: all $(LIBCBOR) $(LIBSOLO) black blackcheck cppcheck wink fido2-test clean full-clean travis test clean version
all: main

tinycbor/Makefile crypto/tiny-AES-c/aes.c:
$(LIB_TINYCBOR_PATH)/Makefile $(LIB_TINY_AES_PATH)/aes.c:
git submodule update --init

.PHONY: cbor
cbor: $(LIBCBOR)

$(LIBCBOR):
cd tinycbor/ && $(MAKE) LDFLAGS='' -j8

$(LIBSOLO):
cd fido2/ && $(MAKE) CFLAGS="$(CFLAGS)" ECC_CFLAGS="$(ECC_CFLAGS)" APP_CONFIG=app.h -j8

version:
@git describe

test: venv
$(MAKE) clean
$(MAKE) -C . main
$(MAKE) pc
$(MAKE) clean
$(MAKE) -C ./targets/stm32l432 test PREFIX=$(PREFIX) "VENV=$(VENV)" VERSION_FULL=${SOLO_VERSION_FULL}
$(MAKE) -C $(TARGET_STM32L432_PATH) test PREFIX=$(PREFIX) "VENV=$(VENV)" VERSION_FULL=${SOLO_VERSION_FULL}
$(MAKE) clean
$(MAKE) cppcheck

$(name): $(obj) $(LIBCBOR) $(LIBSOLO)
$(CC) $(LDFLAGS) -o $@ $(obj) $(LDFLAGS)

venv:
python3 -m venv venv
venv/bin/pip -q install --upgrade pip
Expand All @@ -77,63 +37,42 @@ black: venv
wink: venv
venv/bin/solo key wink

fido2-test: venv
venv/bin/python tools/ctap_test.py

update:
git fetch --tags
git checkout master
git rebase origin/master
git submodule update --init --recursive

DOCKER_TOOLCHAIN_IMAGE := "solokeys/solo-firmware-toolchain"
clean:
$(MAKE) -C $(LIB_TINYCBOR_PATH) clean
$(MAKE) pc ACTION=clean
$(MAKE) stm32l432 ACTION=clean-artifacts

full-clean: clean
rm -rf venv


docker-build-toolchain:
docker build -t $(DOCKER_TOOLCHAIN_IMAGE) .
docker build -t $(DOCKER_TOOLCHAIN_IMAGE) ./tools/docker/
docker tag $(DOCKER_TOOLCHAIN_IMAGE):latest $(DOCKER_TOOLCHAIN_IMAGE):${SOLO_VERSION}
docker tag $(DOCKER_TOOLCHAIN_IMAGE):latest $(DOCKER_TOOLCHAIN_IMAGE):${SOLO_VERSION_MAJ}
docker tag $(DOCKER_TOOLCHAIN_IMAGE):latest $(DOCKER_TOOLCHAIN_IMAGE):${SOLO_VERSION_MAJ}.${SOLO_VERSION_MIN}

uncached-docker-build-toolchain:
docker build --no-cache -t $(DOCKER_TOOLCHAIN_IMAGE) .
docker build --no-cache -t $(DOCKER_TOOLCHAIN_IMAGE) ./tools/docker/
docker tag $(DOCKER_TOOLCHAIN_IMAGE):latest $(DOCKER_TOOLCHAIN_IMAGE):${SOLO_VERSION}
docker tag $(DOCKER_TOOLCHAIN_IMAGE):latest $(DOCKER_TOOLCHAIN_IMAGE):${SOLO_VERSION_MAJ}
docker tag $(DOCKER_TOOLCHAIN_IMAGE):latest $(DOCKER_TOOLCHAIN_IMAGE):${SOLO_VERSION_MAJ}.${SOLO_VERSION_MIN}

docker-build-all:
docker run --rm -v "$(CURDIR)/builds:/builds" \
-v "$(CURDIR):/solo" \
-u $(shell id -u ${USER}):$(shell id -g ${USER}) \
$(DOCKER_TOOLCHAIN_IMAGE) "solo/in-docker-build.sh" ${SOLO_VERSION_FULL}

CPPCHECK_FLAGS=--quiet --error-exitcode=2

cppcheck:
cppcheck $(CPPCHECK_FLAGS) crypto/aes-gcm
cppcheck $(CPPCHECK_FLAGS) crypto/sha256
cppcheck $(CPPCHECK_FLAGS) fido2
cppcheck $(CPPCHECK_FLAGS) pc

clean:
rm -f *.o main.exe main $(obj)
for f in crypto/tiny-AES-c/Makefile tinycbor/Makefile ; do \
if [ -f "$$f" ]; then \
(cd `dirname $$f` ; git checkout -- .) ;\
fi ;\
done
cd fido2 && $(MAKE) clean

full-clean: clean
rm -rf venv

test-docker:
rm -rf builds/*
$(MAKE) uncached-docker-build-toolchain
# Check if there are 4 docker images/tas named "solokeys/solo-firmware-toolchain"
NTAGS=$$(docker images | grep -c "solokeys/solo-firmware-toolchain") && [ $$NTAGS -eq 4 ]
$(MAKE) docker-build-all
cppcheck $(CPPCHECK_FLAGS) $(LIB_AES_GCM_PATH)
cppcheck $(CPPCHECK_FLAGS) $(LIB_SHA256_PATH)
cppcheck $(CPPCHECK_FLAGS) $(LIB_SOLO_PATH)
$(MAKE) pc ACTION=cppcheck

travis:
$(MAKE) test VENV=". ../../venv/bin/activate;"
$(MAKE) test-docker
$(MAKE) uncached-docker-build-toolchain
$(MAKE) stm32l432 ACTION=test-docker
$(MAKE) black
23 changes: 23 additions & 0 deletions common.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# common.mk
# This defines variable for easier path manipulation in other Makefiles

PROJECT_ROOT := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))

LIBS_PATH := $(PROJECT_ROOT)libs
LIB_SOLO_PATH := $(LIBS_PATH)/libsolo
LIB_TINYCBOR_PATH := $(LIBS_PATH)/tinycbor

LIBS_CRYPTO_PATH := $(LIBS_PATH)/crypto
LIB_CIFRA_PATH := $(LIBS_CRYPTO_PATH)/cifra
LIB_TINY_AES_PATH := $(LIBS_CRYPTO_PATH)/tiny-AES-c
LIB_SHA256_PATH := $(LIBS_CRYPTO_PATH)/sha256
LIB_MICRO_ECC_PATH := $(LIBS_CRYPTO_PATH)/micro-ecc
LIB_AES_GCM_PATH := $(LIBS_CRYPTO_PATH)/aes-gcm

TARGETS_PATH := $(PROJECT_ROOT)/targets
TARGET_PC_PATH := $(TARGETS_PATH)/pc/
TARGET_STM32L432_PATH := $(TARGETS_PATH)/stm32l432/

DOCKER_TOOLCHAIN_IMAGE := "solokeys/solo-firmware-toolchain"

include $(PROJECT_ROOT)/libs/libsolo/version.mk
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
76 changes: 76 additions & 0 deletions targets/pc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Load paths
include ../../common.mk

#define uECC_arch_other 0
#define uECC_x86 1
#define uECC_x86_64 2
#define uECC_arm 3
#define uECC_arm_thumb 4
#define uECC_arm_thumb2 5
#define uECC_arm64 6
#define uECC_avr 7
ecc_platform=2

src = device.c main.c

obj = $(src:.c=.o)

LIBCBOR = $(LIB_TINYCBOR_PATH)/lib/libtinycbor.a
LIBSOLO = $(LIB_SOLO_PATH)/libsolo.a

ifeq ($(shell uname -s),Darwin)
export LDFLAGS = -Wl,-dead_strip
else
export LDFLAGS = -Wl,--gc-sections
endif
LDFLAGS += $(LIBSOLO) $(LIBCBOR)


CFLAGS = -O2 -fdata-sections -ffunction-sections -g
ECC_CFLAGS = -O2 -fdata-sections -ffunction-sections -DuECC_PLATFORM=$(ecc_platform)

INCLUDES = -I$(LIB_SOLO_PATH) -I$(TARGET_PC_PATH) -I$(LIB_TINYCBOR_PATH)/src

CFLAGS += $(INCLUDES)
CFLAGS += -DAES256=1 -DSOLO_EXPERIMENTAL=1 -DDEBUG_LEVEL=1

name = main

.PHONY: all $(LIBCBOR) $(LIBSOLO) cppcheck clean version
all: main

$(LIB_TINYCBOR_PATH)/Makefile $(LIB_TINY_AES_PATH)/aes.c:
git submodule update --init

.PHONY: cbor
cbor: $(LIBCBOR)

$(LIBCBOR):
cd $(LIB_TINYCBOR_PATH) && $(MAKE) LDFLAGS='' -j8

$(LIBSOLO):
cd $(LIB_SOLO_PATH) && $(MAKE) CFLAGS="$(CFLAGS)" ECC_CFLAGS="$(ECC_CFLAGS)" APP_CONFIG=app.h -j8

version:
@git describe

test:
$(MAKE) clean
$(MAKE) main
$(MAKE) clean
$(MAKE) cppcheck

$(name): $(obj) $(LIBCBOR) $(LIBSOLO)
$(CC) $(LDFLAGS) -o $@ $(obj) $(LDFLAGS)

cppcheck:
cppcheck $(CPPCHECK_FLAGS) $(TARGET_PC_PATH)

clean:
rm -f *.o main.exe main $(obj)
for f in $(LIB_TINY_AES_PATH)/Makefile $(LIB_TINYCBOR_PATH)/Makefile ; do \
if [ -f "$$f" ]; then \
(cd `dirname $$f` ; git checkout -- .) ;\
fi ;\
done
cd $(LIB_SOLO_PATH) && $(MAKE) clean
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion targets/stm32l432/.ycm_extra_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
'-std=c99',
'-Ilib/',
'-Isrc/cmsis',
'-I../../fido2',
'-I../../libs/libsolo',
]

# Clang automatically sets the '-std=' flag to 'c++14' for MSVC 2015 or later,
Expand Down
25 changes: 25 additions & 0 deletions targets/stm32l432/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
include ../../common.mk


ifndef DEBUG
DEBUG=0
endif
Expand All @@ -10,6 +13,12 @@ merge_hex=solo mergehex

.PHONY: all all-hacker all-locked debugboot-app debugboot-boot boot-sig-checking boot-no-sig build-release-locked build-release build-release build-hacker build-debugboot clean clean2 flash flash_dfu flashboot detach cbor test

#Build all flavours of arm targets using docker
full:
docker run --rm -v "$(PROJECT_ROOT)/builds:/builds" \
-v "$(PROJECT_ROOT):/solo" \
-u $(shell id -u ${USER}):$(shell id -g ${USER}) \
$(DOCKER_TOOLCHAIN_IMAGE) "solo/tools/docker/in-docker-build.sh" ${SOLO_VERSION_FULL} $(FLAVOUR)

# The following are the main targets for reproducible builds.
# TODO: better explanation
Expand All @@ -30,8 +39,23 @@ bootloader-verifying:

full-clean: clean2

clean-artifacts: full-clean
rm -f bootloader*.hex firmware*.hex bootloader*.sha2 firmware*.sha2 bundle*.hex bundle*.sha2
cd $(PROJECT_ROOT)/builds/ && rm -f bootloader*.hex firmware*.hex bootloader*.sha2 firmware*.sha2 bundle*.hex bundle*.sha2

test-docker:
$(MAKE) clean-artifacts
# Check if there are 4 docker images/tas named "solokeys/solo-firmware-toolchain"
NTAGS=$$(docker images | grep -c "solokeys/solo-firmware-toolchain") && [ $$NTAGS -eq 4 ]
$(MAKE) full




#
# The older targets, may be re-organised
#

all:
$(MAKE) -f $(APPMAKE) -j8 solo.hex PREFIX=$(PREFIX) DEBUG=$(DEBUG) EXTRA_DEFINES='-DFLASH_ROP=1'

Expand Down Expand Up @@ -75,6 +99,7 @@ clean2:
$(MAKE) -f $(APPMAKE) clean
$(MAKE) -f $(BOOTMAKE) clean


flash: solo.hex bootloader.hex
$(VENV) $(merge_hex) solo.hex bootloader.hex all.hex
STM32_Programmer_CLI -c port=SWD -halt -e all --readunprotect
Expand Down
Loading