Browse Source

Build with new SDK scripts, fix USB disconnect, add pending icons

zcash_overwinter
BTChip github 8 years ago
parent
commit
ac3c1a19cf
No known key found for this signature in database GPG Key ID: 48BCF826EBFA4D17
  1. 212
      Makefile
  2. BIN
      glyphs/badge_bitcoin_testnet.gif
  3. BIN
      glyphs/badge_komodo.gif
  4. BIN
      glyphs/badge_peercoin.gif
  5. BIN
      glyphs/badge_stratis.gif
  6. BIN
      glyphs/icon_komodo.gif
  7. BIN
      icon_komodo.gif
  8. BIN
      icon_komodo_blue.gif
  9. BIN
      icon_peercoin_blue.gif
  10. BIN
      icon_stratis_blue.gif
  11. 62
      src/main.c
  12. 32
      src/usbd_hid_impl.c
  13. 11
      src/usbd_hid_impl.h

212
Makefile

@ -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.
@ -14,71 +14,19 @@
# See the License for the specific language governing permissions and
# 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))
APP_LOAD_PARAMS=--appFlags 0x50 --path "" --curve secp256k1
ifeq ($(BOLOS_SDK),)
$(error Environment variable BOLOS_SDK is not set)
endif
include $(BOLOS_SDK)/Makefile.defines
APP_LOAD_PARAMS=--appFlags 0x50 --path "" --curve secp256k1 $(COMMON_LOAD_PARAMS)
APPVERSION_M=1
APPVERSION_N=1
APPVERSION_P=5
APPVERSION=$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)
#prepare hsm generation
ifeq ($(TARGET_ID),0x31000002)
LOADFLAGS = --params --appVersion $(APPVERSION)
else
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
CONFIG_PRODUCTIONS := bin/$(PROG)
GLYPH_FILES := $(addprefix glyphs/,$(sort $(notdir $(shell find glyphs/))))
GLYPH_DESTC := src/glyphs.c
GLYPH_DESTH := src/glyphs.h
$(GLYPH_DESTC) $(GLYPH_DESTH): $(GLYPH_FILES) $(BOLOS_SDK)/icon.py
-rm $@
for gif in $(GLYPH_FILES) ; do python $(BOLOS_SDK)/icon.py $$gif glyphcheader ; done > $(GLYPH_DESTH)
for gif in $(GLYPH_FILES) ; do python $(BOLOS_SDK)/icon.py $$gif glyphcfile ; done > $(GLYPH_DESTC)
SOURCE_PATH := src $(BOLOS_SDK)/src $(dir $(shell find $(BOLOS_SDK)/lib_stusb* | grep "\.c$$"))
SOURCE_FILES := $(foreach path, $(SOURCE_PATH),$(shell find $(path) | grep -E "\.c$$|\.s") ) $(GLYPH_DESTC)
INCLUDES_PATH := $(dir $(shell find $(BOLOS_SDK)/lib_stusb* | grep "\.h$$")) include src $(BOLOS_SDK)/include $(BOLOS_SDK)/include/arm
### platform definitions
DEFINES := ST31 gcc __IO=volatile
DEFINES += OS_IO_SEPROXYHAL IO_SEPROXYHAL_BUFFER_SIZE_B=300
DEFINES += HAVE_BAGL HAVE_SPRINTF
#DEFINES += HAVE_PRINTF PRINTF=screen_printf
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) TCS_LOADER_PATCH_VERSION=0 APPVERSION=\"$(APPVERSION)\"
# ifndef COIN
# COIN =bitcoin
# endif
@ -107,6 +55,10 @@ else ifeq ($(COIN),zcash)
# Zcash
DEFINES += BTCHIP_P2PKH_VERSION=7352 BTCHIP_P2SH_VERSION=7357 BTCHIP_COIN_FAMILY=1 BTCHIP_COINID=\"Zcash\" COINID_UPCASE=\"ZCASH\" COLOR_HDR=0x3790CA COLOR_DB=0x9BC8E5 COINID_NAME=\"Zcash\" COINID=$(COIN) BTCHIP_COINID_SHORT=\"ZEC\" COIN_ZCASH
APPNAME ="Zcash"
else ifeq ($(COIN),komodo)
# Komodo
DEFINES += BTCHIP_P2PKH_VERSION=60 BTCHIP_P2SH_VERSION=85 BTCHIP_COIN_FAMILY=1 BTCHIP_COINID=\"Komodo\" COINID_UPCASE=\"KMD\" COLOR_HDR=0x326464 COLOR_DB=0x99b2b2 COINID_NAME=\"Komodo\" COINID=$(COIN) BTCHIP_COINID_SHORT=\"KMD\" COIN_KOMODO
APPNAME ="Komodo"
else ifeq ($(COIN),stratis)
# Stratis
DEFINES += BTCHIP_P2PKH_VERSION=63 BTCHIP_P2SH_VERSION=125 BTCHIP_COIN_FAMILY=2 BTCHIP_COINID=\"Stratis\" COINID_UPCASE=\"STRAT\" COLOR_HDR=0x3790CA COLOR_DB=0x9BC8E5 COINID_NAME=\"Strat\" COINID=$(COIN) BTCHIP_COINID_SHORT=\"STRAT\" COIN_STRATIS HAVE_PEERCOIN_SUPPORT
@ -117,16 +69,34 @@ DEFINES += BTCHIP_P2PKH_VERSION=55 BTCHIP_P2SH_VERSION=117 BTCHIP_COIN_FAMILY=2
APPNAME ="Peercoin"
else
ifeq ($(filter clean,$(MAKECMDGOALS)),)
$(error Unsupported COIN - use bitcoin_testnet, bitcoin, litecoin, dogecoin, dash, zcash, stratis, peercoin)
$(error Unsupported COIN - use bitcoin_testnet, bitcoin, litecoin, dogecoin, dash, zcash, komodo, stratis, peercoin)
endif
endif
ifeq ($(TARGET_ID),0x31000002)
ifeq ($(TARGET_NAME),TARGET_BLUE)
ICONNAME=icon_$(COIN)_blue.gif
else
ICONNAME=icon_$(COIN).gif
endif
################
# Default rule #
################
all: default
############
# Platform #
############
DEFINES += OS_IO_SEPROXYHAL IO_SEPROXYHAL_BUFFER_SIZE_B=300
DEFINES += HAVE_BAGL HAVE_SPRINTF
#DEFINES += HAVE_PRINTF PRINTF=screen_printf
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) TCS_LOADER_PATCH_VERSION=0
# U2F
DEFINES += HAVE_U2F
DEFINES += USB_SEGMENT_SIZE=64
@ -134,117 +104,41 @@ DEFINES += BLE_SEGMENT_SIZE=32 #max MTU, min 20
#DEFINES += U2F_MAX_MESSAGE_SIZE=264 #257+5+2
DEFINES += U2F_MAX_MESSAGE_SIZE=200
DEFINES += UNUSED\(x\)=\(void\)x
DEFINES += APPVERSION=\"$(APPVERSION)\"
##############
# Compiler #
##############
GCCPATH := $(BOLOS_ENV)/gcc-arm-none-eabi-5_3-2016q1/bin/
CLANGPATH := $(BOLOS_ENV)/clang-arm-fropi/bin
CC := $(CLANGPATH)/clang
CFLAGS_SHARED :=
CFLAGS_SHARED += -gdwarf-2 -gstrict-dwarf
CFLAGS_SHARED += -mcpu=cortex-m0 -mthumb
CFLAGS_SHARED += -fno-common -mtune=cortex-m0 -mlittle-endian
CFLAGS_SHARED += -std=gnu99 -Werror=int-to-pointer-cast -Wall -Wextra #-save-temps
CFLAGS_SHARED += -fdata-sections -ffunction-sections -funsigned-char -fshort-enums
CFLAGS_SHARED += -mno-unaligned-access
CFLAGS_SHARED += -Wno-unused-parameter -Wno-duplicate-decl-specifier
#CFLAGS_SHARED += --analyze
CFLAGS_SHARED += -fropi --target=armv6m-none-eabi
#CFLAGS += -finline-limit-0 -funsigned-bitfields
CFLAGS += -O3 -Os $(CFLAGS_SHARED)
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
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
### 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))))))
#GCCPATH := $(BOLOS_ENV)/gcc-arm-none-eabi-5_3-2016q1/bin/
#CLANGPATH := $(BOLOS_ENV)/clang-arm-fropi/bin/
CC := $(CLANGPATH)clang
ifeq ($(filter clean,$(MAKECMDGOALS)),)
-include $(DEPEND_FILES)
endif
#CFLAGS += -O0
CFLAGS += -O3 -Os
clean:
rm -fr obj bin debug dep $(GLYPH_DESTC) $(GLYPH_DESTH)
AS := $(GCCPATH)arm-none-eabi-gcc
prepare: $(GLYPH_DESTC)
@mkdir -p bin obj debug dep
.SECONDEXPANSION:
LD := $(GCCPATH)arm-none-eabi-gcc
LDFLAGS += -O3 -Os
LDLIBS += -lm -lgcc -lc
# default is not to display make commands
log = $(if $(strip $(VERBOSE)),$1,@$1)
# import rules to compile glyphs(/pone)
include $(BOLOS_SDK)/Makefile.glyphs
default: prepare bin/$(PROG)
### computed variables
APP_SOURCE_PATH += src
SDK_SOURCE_PATH += lib_stusb
reload: delete load
load: all
python -m ledgerblue.loadApp --targetId $(TARGET_ID) --fileName bin/$(PROG).hex --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
@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

BIN
glyphs/badge_bitcoin_testnet.gif

Binary file not shown.

After

Width:  |  Height:  |  Size: 362 B

BIN
glyphs/badge_komodo.gif

Binary file not shown.

After

Width:  |  Height:  |  Size: 386 B

BIN
glyphs/badge_peercoin.gif

Binary file not shown.

After

Width:  |  Height:  |  Size: 361 B

BIN
glyphs/badge_stratis.gif

Binary file not shown.

After

Width:  |  Height:  |  Size: 363 B

BIN
glyphs/icon_komodo.gif

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 B

BIN
icon_komodo.gif

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 B

BIN
icon_komodo_blue.gif

Binary file not shown.

After

Width:  |  Height:  |  Size: 466 B

BIN
icon_peercoin_blue.gif

Binary file not shown.

After

Width:  |  Height:  |  Size: 436 B

BIN
icon_stratis_blue.gif

Binary file not shown.

After

Width:  |  Height:  |  Size: 456 B

62
src/main.c

@ -2263,49 +2263,57 @@ __attribute__((section(".boot"))) int main(void) {
// ensure exception will work as planned
os_boot();
UX_INIT();
for (;;) {
UX_INIT();
BEGIN_TRY {
TRY {
io_seproxyhal_init();
BEGIN_TRY {
TRY {
io_seproxyhal_init();
btchip_context_init();
btchip_context_init();
// deactivate usb before activating
USB_power_U2F(0, 0);
#ifdef HAVE_U2F
os_memset((unsigned char *)&u2fService, 0, sizeof(u2fService));
u2fService.inputBuffer = G_io_apdu_buffer;
u2fService.outputBuffer = G_io_apdu_buffer;
u2fService.messageBuffer = (uint8_t *)u2fMessageBuffer;
u2fService.messageBufferSize = U2F_MAX_MESSAGE_SIZE;
u2f_initialize_service((u2f_service_t *)&u2fService);
USB_power_U2F(1, N_btchip.fidoTransport);
os_memset((unsigned char *)&u2fService, 0, sizeof(u2fService));
u2fService.inputBuffer = G_io_apdu_buffer;
u2fService.outputBuffer = G_io_apdu_buffer;
u2fService.messageBuffer = (uint8_t *)u2fMessageBuffer;
u2fService.messageBufferSize = U2F_MAX_MESSAGE_SIZE;
u2f_initialize_service((u2f_service_t *)&u2fService);
USB_power_U2F(1, N_btchip.fidoTransport);
#else
USB_power_U2F(1, 0);
USB_power_U2F(1, 0);
#endif
#ifdef HAVE_BLE
BLE_power(1, "Ledger Wallet");
BLE_power(0, NULL);
BLE_power(1, "Ledger Wallet");
#endif // HAVE_BLE
#if TARGET_ID == 0x31000002
// setup the status bar colors (remembered after wards, even more if
// another app does not resetup after app switch)
UX_SET_STATUS_BAR_COLOR(0xFFFFFF, COLOR_APP);
// setup the status bar colors (remembered after wards, even
// more if another app does not resetup after app switch)
UX_SET_STATUS_BAR_COLOR(0xFFFFFF, COLOR_APP);
#endif // TARGET_ID
ui_idle();
ui_idle();
app_main();
}
CATCH_ALL {
// exit :)
}
FINALLY {
app_main();
}
CATCH(EXCEPTION_IO_RESET) {
// reset IO and UX
continue;
}
CATCH_ALL {
break;
}
FINALLY {
}
}
END_TRY;
}
END_TRY;
app_exit();
return 0;

32
src/usbd_hid_impl.c

@ -96,6 +96,11 @@
* @{
*/
#if 0
/* Private functions ---------------------------------------------------------*/
static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len);
static void Get_SerialNum(void);
#endif
/**
* @}
@ -463,18 +468,21 @@ uint8_t USBD_HID_DataOut_impl(USBD_HandleTypeDef *pdev, uint8_t epnum,
U2F_MEDIA_USB);
#endif
} else {
// add to the hid transport
switch (
io_usb_hid_receive(io_usb_send_apdu_data, buffer,
io_seproxyhal_get_ep_rx_size(HID_EPOUT_ADDR))) {
default:
break;
case IO_USB_APDU_RECEIVED:
G_io_apdu_media = IO_APDU_MEDIA_USB_HID; // for application code
G_io_apdu_state = APDU_USB_HID; // for next call to io_exchange
G_io_apdu_length = G_io_usb_hid_total_length;
break;
// avoid troubles when an apdu has not been replied yet
if (G_io_apdu_media == IO_APDU_MEDIA_NONE) {
// add to the hid transport
switch (io_usb_hid_receive(
io_usb_send_apdu_data, buffer,
io_seproxyhal_get_ep_rx_size(HID_EPOUT_ADDR))) {
default:
break;
case IO_USB_APDU_RECEIVED:
G_io_apdu_media = IO_APDU_MEDIA_USB_HID; // for application code
G_io_apdu_state = APDU_USB_HID; // for next call to io_exchange
G_io_apdu_length = G_io_usb_hid_total_length;
break;
}
}
}

11
src/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
Loading…
Cancel
Save