Skip to content

Commit

Permalink
Fix USB disconnect, new build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
BTChip github committed Mar 28, 2017
1 parent 0270c2e commit 1525802
Show file tree
Hide file tree
Showing 13 changed files with 283 additions and 865 deletions.
52 changes: 52 additions & 0 deletions Makefile.defines
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#*******************************************************************************
# Ledger SDK
# (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.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#*******************************************************************************

#extract TARGET_NAME/TARGET_ID from the SDK to allow for makefile choices
TARGET_ID:=$(shell cat $(BOLOS_SDK)/include/bolos_target.h | grep TARGET_ID | cut -f3 -d' ')
TARGET_NAME:=$(shell cat $(BOLOS_SDK)/include/bolos_target.h | grep TARGET_ | grep -v TARGET_ID | cut -f2 -d' ')
$(info TARGET_NAME=$(TARGET_NAME) TARGET_ID=$(TARGET_ID))

# extra load parameters for loadApp script
ifneq ($(SCP_PRIVKEY),)
PARAM_SCP=--rootPrivateKey $(SCP_PRIVKEY)
endif
COMMON_LOAD_PARAMS=--targetId $(TARGET_ID) --fileName bin/app.hex --appName $(APPNAME) `ICONHEX=\`python $(BOLOS_SDK)/icon.py $(ICONNAME) hexbitmaponly 2>/dev/null\` ; [ ! -z "$$ICONHEX" ] && echo "--icon $$ICONHEX"` $(PARAM_SCP)
COMMON_DELETE_PARAMS=--targetId $(TARGET_ID) --appName $(APPNAME) $(PARAM_SCP)

### platform definitions
DEFINES += ST31 gcc __IO=volatile

# default is not to display make commands
log = $(if $(strip $(VERBOSE)),$1,@$1)

CFLAGS += -gdwarf-2 -gstrict-dwarf
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

AFLAGS += -ggdb2 -O3 -Os -mcpu=cortex-m0 -fno-common -mtune=cortex-m0

LDFLAGS += -gdwarf-2 -gstrict-dwarf
LDFLAGS += -Wall
LDFLAGS += -mcpu=cortex-m0 -mthumb
LDFLAGS += -fno-common -ffunction-sections -fdata-sections -fwhole-program -nostartfiles
LDFLAGS += -mno-unaligned-access
LDFLAGS += -T$(BOLOS_SDK)/script.ld -Wl,--gc-sections -Wl,-Map,debug/app.map,--cref
36 changes: 36 additions & 0 deletions Makefile.glyphs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#*******************************************************************************
# Ledger SDK
# (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.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#*******************************************************************************
#allow for makefile override of the default placement for generated glyph header/c files
ifeq ($(GLYPH_SRC_DIR),)
GLYPH_SRC_DIR = src
endif
ifeq ($(BOLOS_SDK),)
$(error BOLOS_SDK not set)
endif
GLYPH_FILES := $(addprefix glyphs/,$(sort $(notdir $(shell find glyphs/))))
GLYPH_DESTC := $(GLYPH_SRC_DIR)/glyphs.c
GLYPH_DESTH := $(GLYPH_SRC_DIR)/glyphs.h
$(GLYPH_DESTH): $(GLYPH_FILES) $(BOLOS_SDK)/icon.py
$(call log,echo [GLYPH] Compiling...)
$(call log,-mkdir -p $(GLYPH_SRC_DIR))
$(call log,-rm $(GLYPH_DESTC) $(GLYPH_DESTH) 2>/dev/null)
$(call log,touch $(GLYPH_DESTH) $(GLYPH_DESTC))
$(call log,if [ ! -z "$(GLYPH_FILES)" ] ; then for gif in $(GLYPH_FILES) ; do python $(BOLOS_SDK)/icon.py $$gif glyphcheader ; done > $(GLYPH_DESTH) ; fi)
$(call log,if [ ! -z "$(GLYPH_FILES)" ] ; then for gif in $(GLYPH_FILES) ; do python $(BOLOS_SDK)/icon.py $$gif glyphcfile ; done > $(GLYPH_DESTC) ; fi)
#add dependency for generation
$(GLYPH_DESTC): $(GLYPH_DESTH)
85 changes: 85 additions & 0 deletions Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#*******************************************************************************
# Ledger SDK
# (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.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#*******************************************************************************


# 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

#default building rules
.SECONDEXPANSION:

SOURCE_PATH += $(BOLOS_SDK)/src $(foreach libdir, $(SDK_SOURCE_PATH), $(dir $(shell find $(BOLOS_SDK)/$(libdir) | grep "\.c$$"))) $(dir $(foreach libdir, $(APP_SOURCE_PATH), $(dir $(shell find $(libdir) | grep "\.c$$"))))
SOURCE_FILES := $(foreach path, $(SOURCE_PATH),$(shell find $(path) | grep "\.c$$") ) $(GLYPH_DESTC)
INCLUDES_PATH := $(dir $(foreach libdir, $(SDK_SOURCE_PATH), $(dir $(shell find $(BOLOS_SDK)/$(libdir) | grep "\.h$$")))) include $(BOLOS_SDK)/include $(BOLOS_SDK)/include/arm $(dir $(foreach libdir, $(APP_SOURCE_PATH), $(dir $(shell find $(libdir) | grep "\.h$$"))))

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:
$(call log, echo Prepare directories)
@mkdir -p bin obj debug dep

default: bin/app.elf

dep/%.d: %.c $(GLYPH_DESTC) prepare
@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 "[AS] $@"
$(call log,$(call as_cmdline,$(INCLUDES_PATH), $(DEFINES),$<,$@))

bin/app.elf: $(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/app.elf bin/app.hex)
$(call log,cp bin/app.elf obj)
$(call log,$(GCCPATH)arm-none-eabi-objdump -S -d bin/app.elf > debug/app.asm)

### 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
37 changes: 19 additions & 18 deletions icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@
if (len(sys.argv) == 2):
filename = sys.argv[1];
if not os.path.exists(filename):
print sys.argv[0] + ": [<Wmax> <Hmax>] <imagefile> [<forcedBPP>] [hexbitmaponly|glyphcfile|glyphcheader]"
print "Error: " + sys.argv[1] + " does not exists !"
sys.sterr.write(sys.argv[0] + ": [<Wmax> <Hmax>] <imagefile> [<forcedBPP>] [hexbitmaponly|glyphcfile|glyphcheader]\n")
sys.sterr.write("Error: " + sys.argv[1] + " does not exists !\n")
sys.exit(2)
# 3: python imagefile forcedBPP
# 3: python imagefile hexbitmaponly
elif (len(sys.argv) == 3):
filename = sys.argv[1];
if not os.path.exists(filename):
print sys.argv[0] + ": [<Wmax> <Hmax>] <imagefile> [<forcedBPP>] [hexbitmaponly|glyphcfile|glyphcheader]"
print "Error: " + filename + " does not exists !"
sys.sterr.write(sys.argv[0] + ": [<Wmax> <Hmax>] <imagefile> [<forcedBPP>] [hexbitmaponly|glyphcfile|glyphcheader]\n")
sys.sterr.write("Error: " + filename + " does not exists !\n")
sys.exit(2)
if (sys.argv[2] == "hexbitmaponly"):
hexbitmaponly = True
Expand All @@ -64,8 +64,8 @@
if not os.path.exists(filename):
filename = sys.argv[3];
if not os.path.exists(filename):
print sys.argv[0] + ": [<Wmax> <Hmax>] <imagefile> [<forcedBPP>] [hexbitmaponly|glyphcfile|glyphcheader]"
print "Error: " + filename + " does not exists !"
sys.sterr.write(sys.argv[0] + ": [<Wmax> <Hmax>] <imagefile> [<forcedBPP>] [hexbitmaponly|glyphcfile|glyphcheader]\n")
sys.sterr.write("Error: " + filename + " does not exists !\n")
sys.exit(2)
widthmax = int(sys.argv[1])
heightmax = int(sys.argv[2])
Expand All @@ -78,15 +78,15 @@
elif (sys.argv[2] == "glyphcheader"):
glyphcheader = True
else:
print sys.argv[0] + ": [<Wmax> <Hmax>] <imagefile> [<forcedBPP>] [hexbitmaponly|glyphcfile|glyphcheader]"
sys.sterr.write(sys.argv[0] + ": [<Wmax> <Hmax>] <imagefile> [<forcedBPP>] [hexbitmaponly|glyphcfile|glyphcheader]\n")
sys.exit(2)
# 5: python max max imagefile forcedBPP
# 5: python max max imagefile hexbitmaponly
elif (len(sys.argv) == 5):
filename = sys.argv[3];
if not os.path.exists(filename):
print sys.argv[0] + ": [<Wmax> <Hmax>] <imagefile> [<forcedBPP>] [hexbitmaponly|glyphcfile|glyphcheader]"
print "Error: " + filename + " does not exists !"
sys.sterr.write(sys.argv[0] + ": [<Wmax> <Hmax>] <imagefile> [<forcedBPP>] [hexbitmaponly|glyphcfile|glyphcheader]\n")
sys.sterr.write("Error: " + filename + " does not exists !\n")
sys.exit(2)
widthmax = int(sys.argv[1])
heightmax = int(sys.argv[2])
Expand All @@ -104,8 +104,8 @@
elif (len(sys.argv) == 6):
filename = sys.argv[3]
if not os.path.exists(filename):
print sys.argv[0] + ": [<Wmax> <Hmax>] <imagefile> [<forcedBPP>] [hexbitmaponly|glyphcfile|glyphcheader]"
print "Error: " + filename + " does not exists !"
sys.sterr.write(sys.argv[0] + ": [<Wmax> <Hmax>] <imagefile> [<forcedBPP>] [hexbitmaponly|glyphcfile|glyphcheader]\n")
sys.sterr.write("Error: " + filename + " does not exists !\n")
sys.exit(2)
widthmax = int(sys.argv[1])
heightmax = int(sys.argv[2])
Expand All @@ -117,12 +117,12 @@
elif (sys.argv[2] == "glyphcheader"):
glyphcheader = True
else:
print sys.argv[0] + ": [<Wmax> <Hmax>] <imagefile> [<forcedBPP>] [hexbitmaponly|glyphcfile|glyphcheader]"
print "Error: " + filename + " does not exists !"
sys.sterr.write(sys.argv[0] + ": [<Wmax> <Hmax>] <imagefile> [<forcedBPP>] [hexbitmaponly|glyphcfile|glyphcheader]\n")
sys.sterr.write("Error: " + filename + " does not exists !\n")
sys.exit(2)
else:
print sys.argv[0] + ": [<Wmax> <Hmax>] <imagefile> [<forcedBPP>] [hexbitmaponly|glyphcfile|glyphcheader]"
print "Error: " + sys.argv[1] + " does not exists !"
sys.sterr.write(sys.argv[0] + ": [<Wmax> <Hmax>] <imagefile> [<forcedBPP>] [hexbitmaponly|glyphcfile|glyphcheader]\n")
sys.sterr.write("Error: " + sys.argv[1] + " does not exists !\n")
sys.exit(2)


Expand Down Expand Up @@ -152,7 +152,8 @@ def hexbyte(b):
maxcolor = color_index

if (maxcolor+1 > 16):
raise "toomuch colors"
sys.sterr.write("toomuch colors\n")
sys.exit(3)


#not a pow 2 max color count
Expand Down Expand Up @@ -332,5 +333,5 @@ def hexbyte(b):
sys.stdout.write("""#endif // OS_IO_SEPROXYHAL
""")
except:
sys.stdout.write("An error occured\n")
traceback.print_exc()
sys.stderr.write("An error occured\n")
#traceback.print_exc()
4 changes: 1 addition & 3 deletions include/bolos_target.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@

#ifndef TARGET_ID
#define TARGET_ID 0x31100002
#endif
#define TARGET_NANOS
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ uint8_t PC_to_RDR_XfrBlock(void)

error = SC_XferBlock(&Ccid_bulk_data.abData[0],
reqlen,
expectedLength);
&expectedLength);

if (error != SLOT_NO_ERROR)
{
Expand Down
12 changes: 0 additions & 12 deletions lib_stusb/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,6 @@ USBD_StatusTypeDef USBD_CtlReceiveStatus (USBD_HandleTypeDef *pdev)
}


/**
* @brief USBD_GetRxCount
* returns the received data length
* @param pdev: device instance
* @param ep_addr: endpoint address
* @retval Rx Data blengthh
*/
uint16_t USBD_GetRxCount (USBD_HandleTypeDef *pdev , uint8_t ep_addr)
{
return USBD_LL_GetRxDataSize(pdev, ep_addr);
}

/**
* @}
*/
Expand Down
Loading

0 comments on commit 1525802

Please sign in to comment.