From c4fbb962278d7631dee8156dcff34780fa755053 Mon Sep 17 00:00:00 2001 From: BTChip github Date: Tue, 4 Apr 2017 17:31:34 +0200 Subject: [PATCH] Move to new build SDK, add 2FA for ERC-20 tokens Matchpool, Lunyr, Round, TaaS --- Makefile.genericwallet | 160 +++++------------------------- src_genericwallet/tokens.c | 20 +++- src_genericwallet/tokens.h | 2 +- src_genericwallet/usbd_hid_impl.h | 11 ++ 4 files changed, 56 insertions(+), 137 deletions(-) create mode 100644 src_genericwallet/usbd_hid_impl.h diff --git a/Makefile.genericwallet b/Makefile.genericwallet index 5db690f..5a1037d 100755 --- a/Makefile.genericwallet +++ b/Makefile.genericwallet @@ -1,6 +1,6 @@ #******************************************************************************* -# Ledger Blue -# (c) 2016 Ledger +# Ledger App +# (c) 2017 Ledger # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,21 +15,22 @@ # limitations under the License. #******************************************************************************* -#extract TARGET_ID from the SDK to allow for makefile choices -TARGET_ID := $(shell cat $(BOLOS_SDK)/include/bolos_target.h | grep 0x | cut -f3 -d' ') -$(info TARGET_ID=$(TARGET_ID)) +ifeq ($(BOLOS_SDK),) +$(error Environment variable BOLOS_SDK is not set) +endif +include $(BOLOS_SDK)/Makefile.defines + APPNAME = Ethereum -APP_LOAD_PARAMS=--appFlags 0x40 --path "44'/60'" --path "44'/61'" --curve secp256k1 +APP_LOAD_PARAMS=--appFlags 0x40 --path "44'/60'" --path "44'/61'" --curve secp256k1 $(COMMON_LOAD_PARAMS) APPVERSION_M=1 APPVERSION_N=0 -APPVERSION_P=9 +APPVERSION_P=10 APPVERSION=$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P) #prepare hsm generation -ifeq ($(TARGET_ID),0x31000002) +ifeq ($(TARGET_NAME),TARGET_BLUE) ICONNAME=app_ethereum.gif -LOADFLAGS = --params --appVersion $(APPVERSION) else ICONNAME=icon.gif endif @@ -38,41 +39,11 @@ endif ################ # Default rule # ################ - all: default -# consider every intermediate target as final to avoid deleting intermediate files -.SECONDARY: - -# disable builtin rules that overload the build process (and the debug log !!) -.SUFFIXES: -MAKEFLAGS += -r - -SHELL = /bin/bash -#.ONESHELL: - - ############ # Platform # ############ -PROG := token-genericwallet - -CONFIG_PRODUCTIONS := bin/$(PROG) - -GLYPH_FILES := $(addprefix glyphs/,$(sort $(notdir $(shell find glyphs/)))) -GLYPH_DESTC := src_common/glyphs.c -GLYPH_DESTH := src_common/glyphs.h -$(GLYPH_DESTC) $(GLYPH_DESTH): $(GLYPH_FILES) $(BOLOS_SDK)/icon.py - -rm $@ - if [ ! -z "$(GLYPH_FILES)" ] ; then for gif in $(GLYPH_FILES) ; do python $(BOLOS_SDK)/icon.py $$gif glyphcheader ; done > $(GLYPH_DESTH) ; fi - if [ ! -z "$(GLYPH_FILES)" ] ; then for gif in $(GLYPH_FILES) ; do python $(BOLOS_SDK)/icon.py $$gif glyphcfile ; done > $(GLYPH_DESTC) ; fi - -SOURCE_PATH := src_genericwallet $(BOLOS_SDK)/src $(dir $(shell find $(BOLOS_SDK)/lib_stusb* | grep "\.c$$")) src_common -SOURCE_FILES := $(foreach path, $(SOURCE_PATH),$(shell find $(path) | grep "\.c$$") ) $(GLYPH_DESTC) -INCLUDES_PATH := $(dir $(shell find $(BOLOS_SDK)/lib_stusb* | grep "\.h$$")) include src_genericwallet $(BOLOS_SDK)/include $(BOLOS_SDK)/include/arm src_common - -### platform definitions -DEFINES := ST31 gcc __IO=volatile DEFINES += OS_IO_SEPROXYHAL IO_SEPROXYHAL_BUFFER_SIZE_B=128 DEFINES += HAVE_BAGL HAVE_SPRINTF @@ -81,7 +52,6 @@ DEFINES += PRINTF\(...\)= DEFINES += HAVE_IO_USB HAVE_L4_USBLIB IO_USB_MAX_ENDPOINTS=6 IO_HID_EP_LENGTH=64 HAVE_USB_APDU DEFINES += LEDGER_MAJOR_VERSION=$(APPVERSION_M) LEDGER_MINOR_VERSION=$(APPVERSION_N) LEDGER_PATCH_VERSION=$(APPVERSION_P) - # U2F DEFINES += HAVE_U2F DEFINES += USB_SEGMENT_SIZE=64 @@ -91,116 +61,38 @@ DEFINES += UNUSED\(x\)=\(void\)x DEFINES += APPVERSION=\"$(APPVERSION)\" ############## -# Compiler # +# Compiler # ############## -GCCPATH := $(BOLOS_ENV)/gcc-arm-none-eabi-5_3-2016q1/bin/ -CLANGPATH := $(BOLOS_ENV)/clang-arm-fropi/bin -CC := $(CLANGPATH)/clang +#GCCPATH := $(BOLOS_ENV)/gcc-arm-none-eabi-5_3-2016q1/bin/ +#CLANGPATH := $(BOLOS_ENV)/clang-arm-fropi/bin/ +CC := $(CLANGPATH)clang -CFLAGS := -CFLAGS += -gdwarf-2 -gstrict-dwarf #CFLAGS += -O0 -#CFLAGS += -O0 -g3 CFLAGS += -O3 -Os -CFLAGS += -mcpu=cortex-m0 -mthumb -CFLAGS += -fno-common -mtune=cortex-m0 -mlittle-endian -CFLAGS += -std=gnu99 -Werror=int-to-pointer-cast -Wall -Wextra #-save-temps -CFLAGS += -fdata-sections -ffunction-sections -funsigned-char -fshort-enums -CFLAGS += -mno-unaligned-access -CFLAGS += -Wno-unused-parameter -Wno-duplicate-decl-specifier -CFLAGS += -fropi --target=armv6m-none-eabi -#CFLAGS += -finline-limit-0 -funsigned-bitfields +AS := $(GCCPATH)arm-none-eabi-gcc -AS := $(GCCPATH)/arm-none-eabi-gcc -AFLAGS += -ggdb2 -O3 -Os -mcpu=cortex-m0 -fno-common -mtune=cortex-m0 - -# NOT SUPPORTED BY STM3L152 CFLAGS += -fpack-struct -#-pg --coverage -LD := $(GCCPATH)/arm-none-eabi-gcc -LDFLAGS := -LDFLAGS += -gdwarf-2 -gstrict-dwarf -#LDFLAGS += -O0 -g3 +LD := $(GCCPATH)arm-none-eabi-gcc LDFLAGS += -O3 -Os -#LDFLAGS += -O0 -LDFLAGS += -Wall -LDFLAGS += -mcpu=cortex-m0 -mthumb -LDFLAGS += -fno-common -ffunction-sections -fdata-sections -fwhole-program -nostartfiles -LDFLAGS += -mno-unaligned-access -#LDFLAGS += -nodefaultlibs -#LDFLAGS += -nostdlib -nostdinc -LDFLAGS += -T$(BOLOS_SDK)/script.ld -Wl,--gc-sections -Wl,-Map,debug/$(PROG).map,--cref -LDLIBS += -Wl,--library-path -Wl,$(GCCPATH)/../lib/armv6-m/ -#LDLIBS += -Wl,--start-group LDLIBS += -lm -lgcc -lc -#LDLIBS += -Wl,--end-group -# -mno-unaligned-access -#-pg --coverage + +# import rules to compile glyphs(/pone) +include $(BOLOS_SDK)/Makefile.glyphs ### computed variables -VPATH := $(dir $(SOURCE_FILES)) -OBJECT_FILES := $(sort $(addprefix obj/, $(addsuffix .o, $(basename $(notdir $(SOURCE_FILES)))))) -DEPEND_FILES := $(sort $(addprefix dep/, $(addsuffix .d, $(basename $(notdir $(SOURCE_FILES)))))) - -ifeq ($(filter clean,$(MAKECMDGOALS)),) --include $(DEPEND_FILES) -endif - -clean: - rm -fr obj bin debug dep $(GLYPH_DESTC) $(GLYPH_DESTH) - -prepare: $(GLYPH_DESTC) - @mkdir -p bin obj debug dep - -.SECONDEXPANSION: - -# default is not to display make commands -log = $(if $(strip $(VERBOSE)),$1,@$1) - -default: prepare bin/$(PROG) - +APP_SOURCE_PATH += src_genericwallet src_common +SDK_SOURCE_PATH += lib_stusb load: all - python -m ledgerblue.loadApp --targetId $(TARGET_ID) --fileName bin/$(PROG).hex --delete --appName $(APPNAME) --icon `python $(BOLOS_SDK)/icon.py $(ICONNAME) hexbitmaponly` $(LOADFLAGS) $(APP_LOAD_PARAMS) + python -m ledgerblue.loadApp $(APP_LOAD_PARAMS) delete: - python -m ledgerblue.deleteApp --targetId $(TARGET_ID) --appName $(APPNAME) + python -m ledgerblue.deleteApp $(COMMON_DELETE_PARAMS) -bin/$(PROG): $(OBJECT_FILES) $(BOLOS_SDK)/script.ld - @echo "[LINK] $@" - $(call log,$(call link_cmdline,$(OBJECT_FILES) $(LDLIBS),$@)) - $(call log,$(GCCPATH)/arm-none-eabi-objcopy -O ihex -S bin/$(PROG) bin/$(PROG).hex) - $(call log,mv bin/$(PROG) bin/$(PROG).elf) - $(call log,cp bin/$(PROG).elf obj) - $(call log,$(GCCPATH)/arm-none-eabi-objdump -S -d bin/$(PROG).elf > debug/$(PROG).asm) +# import generic rules from the sdk +include $(BOLOS_SDK)/Makefile.rules +#add dependency on custom makefile filename dep/%.d: %.c Makefile.genericwallet - @echo "[DEP] $@" - @mkdir -p dep - $(call log,$(call dep_cmdline,$(INCLUDES_PATH), $(DEFINES),$<,$@)) - -obj/%.o: %.c dep/%.d - @echo "[CC] $@" - $(call log,$(call cc_cmdline,$(INCLUDES_PATH), $(DEFINES),$<,$@)) - -obj/%.o: %.s - @echo "[CC] $@" - $(call log,$(call as_cmdline,$(INCLUDES_PATH), $(DEFINES),$<,$@)) - - -### BEGIN GCC COMPILER RULES - -# link_cmdline(objects,dest) Macro that is used to format arguments for the linker -link_cmdline = $(LD) $(LDFLAGS) -o $(2) $(1) - -# dep_cmdline(include,defines,src($<),dest($@)) Macro that is used to format arguments for the dependency creator -dep_cmdline = $(CC) -M $(CFLAGS) $(addprefix -D,$(2)) $(addprefix -I,$(1)) $(3) | sed 's/\($*\)\.o[ :]*/obj\/\1.o: /g' | sed -e 's/[:\t ][^ ]\+\.c//g' > dep/$(basename $(notdir $(4))).d 2>/dev/null - -# cc_cmdline(include,defines,src,dest) Macro that is used to format arguments for the compiler -cc_cmdline = $(CC) -c $(CFLAGS) $(addprefix -D,$(2)) $(addprefix -I,$(1)) -o $(4) $(3) - -as_cmdline = $(AS) -c $(AFLAGS) $(addprefix -D,$(2)) $(addprefix -I,$(1)) -o $(4) $(3) - -### END GCC COMPILER RULES diff --git a/src_genericwallet/tokens.c b/src_genericwallet/tokens.c index f5eefe4..380520a 100644 --- a/src_genericwallet/tokens.c +++ b/src_genericwallet/tokens.c @@ -63,6 +63,10 @@ const tokenDefinition_t const TOKENS[NUM_TOKENS] = { 0x85, 0x90, 0xFe, 0x1f, 0x24, 0x54, 0xd7, 0xD4, 0xaC, 0x0d}, "GNT ", 18}, + {{0xf7, 0xB0, 0x98, 0x29, 0x8f, 0x7C, 0x69, 0xFc, 0x14, 0x61, + 0x0b, 0xf7, 0x1d, 0x5e, 0x02, 0xc6, 0x07, 0x92, 0x89, 0x4C}, + "GUP ", + 3}, {{0x14, 0xF3, 0x7B, 0x57, 0x42, 0x42, 0xD3, 0x66, 0x55, 0x8d, 0xB6, 0x1f, 0x33, 0x35, 0x28, 0x9a, 0x50, 0x35, 0xc5, 0x06}, "HKG ", @@ -71,6 +75,10 @@ const tokenDefinition_t const TOKENS[NUM_TOKENS] = { 0xD7, 0x5b, 0x57, 0x26, 0xCe, 0xe9, 0x9A, 0x87, 0xD6, 0x98}, "ICN ", 18}, + {{0xfa, 0x05, 0xa7, 0x3f, 0xfe, 0x78, 0xef, 0x8f, 0x1a, 0x73, + 0x94, 0x73, 0xe4, 0x62, 0xc5, 0x4b, 0xae, 0x65, 0x67, 0xd9}, + "LUN ", + 18}, {{0xe2, 0x3c, 0xd1, 0x60, 0x76, 0x1f, 0x63, 0xfc, 0x3a, 0x1c, 0xf7, 0x8a, 0xa0, 0x34, 0xb6, 0xcd, 0xf9, 0x7d, 0x3e, 0x0c}, "MIT ", @@ -85,7 +93,7 @@ const tokenDefinition_t const TOKENS[NUM_TOKENS] = { 18}, {{0x45, 0xe4, 0x2D, 0x65, 0x9D, 0x9f, 0x94, 0x66, 0xcD, 0x5D, 0xF6, 0x22, 0x50, 0x60, 0x33, 0x14, 0x5a, 0x9b, 0x89, 0xBc}, - "NXM ", + "NxC ", 3}, {{0xD8, 0x91, 0x2C, 0x10, 0x68, 0x1D, 0x8B, 0x21, 0xFd, 0x37, 0x42, 0x24, 0x4f, 0x44, 0x65, 0x8d, 0xBA, 0x12, 0x26, 0x4E}, @@ -95,6 +103,10 @@ const tokenDefinition_t const TOKENS[NUM_TOKENS] = { 0x54, 0x38, 0xB5, 0x4C, 0xba, 0x84, 0xf2, 0x9F, 0x32, 0xa5}, "REP ", 18}, + {{0x49, 0x93, 0xCB, 0x95, 0xc7, 0x44, 0x3b, 0xdC, 0x06, 0x15, + 0x5c, 0x5f, 0x56, 0x88, 0xBe, 0x9D, 0x8f, 0x69, 0x99, 0xa5}, + "RND ", + 18}, {{0xae, 0xc2, 0xe8, 0x7e, 0x0a, 0x23, 0x52, 0x66, 0xd9, 0xc5, 0xad, 0xc9, 0xde, 0xb4, 0xb2, 0xe2, 0x9b, 0x54, 0xd0, 0x09}, "SNGL ", @@ -103,6 +115,10 @@ const tokenDefinition_t const TOKENS[NUM_TOKENS] = { 0x29, 0xC4, 0x99, 0x71, 0x73, 0xd8, 0x4C, 0xdF, 0x26, 0x07}, "SWT ", 18}, + {{0xe7, 0x77, 0x5a, 0x6e, 0x9b, 0xcf, 0x90, 0x4e, 0xb3, 0x9d, + 0xa2, 0xb6, 0x8c, 0x5e, 0xfb, 0x4f, 0x93, 0x60, 0xe0, 0x8c}, + "TaaS ", + 6}, {{0x65, 0x31, 0xf1, 0x33, 0xe6, 0xDe, 0xeB, 0xe7, 0xF2, 0xdc, 0xE5, 0xA0, 0x44, 0x1a, 0xA7, 0xef, 0x33, 0x0B, 0x4e, 0x53}, "TIME ", @@ -118,6 +134,6 @@ const tokenDefinition_t const TOKENS[NUM_TOKENS] = { {{0x4D, 0xF8, 0x12, 0xF6, 0x06, 0x4d, 0xef, 0x1e, 0x5e, 0x02, 0x9f, 0x1c, 0xa8, 0x58, 0x77, 0x7C, 0xC9, 0x8D, 0x2D, 0x81}, "XAUR ", - 8}, + 8} }; diff --git a/src_genericwallet/tokens.h b/src_genericwallet/tokens.h index f8df01c..fbc290e 100644 --- a/src_genericwallet/tokens.h +++ b/src_genericwallet/tokens.h @@ -23,6 +23,6 @@ typedef struct tokenDefinition_t { uint8_t decimals; } tokenDefinition_t; -#define NUM_TOKENS 20 +#define NUM_TOKENS 29 extern tokenDefinition_t const TOKENS[NUM_TOKENS]; diff --git a/src_genericwallet/usbd_hid_impl.h b/src_genericwallet/usbd_hid_impl.h new file mode 100644 index 0000000..adb7be9 --- /dev/null +++ b/src_genericwallet/usbd_hid_impl.h @@ -0,0 +1,11 @@ +#ifndef USBD_HID_IMPL_H +#define USBD_HID_IMPL_H + +#define HID_EPIN_ADDR 0x82 +#define HID_EPIN_SIZE 0x40 + +#define HID_EPOUT_ADDR 0x02 +#define HID_EPOUT_SIZE 0x40 + +#endif // USBD_HID_IMPL_H +