From 90171e0aa6056b82df6a0211126c8dc4c3469f31 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Wed, 5 Aug 2015 16:57:23 +0200 Subject: [PATCH] update bootloader and demo to new usb api --- .travis.yml | 4 +++- bootloader/Makefile | 16 +++++++--------- bootloader/usb.c | 3 +-- demo/demo.c | 16 ++++++++++++---- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6a12e14ef..8db60b8fc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,4 +14,6 @@ install: script: - cd libopencm3; make; cd .. - TOOLCHAIN_DIR=libopencm3 make - - cd firmware; TOOLCHAIN_DIR=libopencm3 make; cd .. + - cd firmware; TOOLCHAIN_DIR=../libopencm3 make; cd .. + - cd bootloader; TOOLCHAIN_DIR=../libopencm3 make; cd .. + - cd demo; TOOLCHAIN_DIR=../libopencm3 make; cd .. diff --git a/bootloader/Makefile b/bootloader/Makefile index 498bdd16b..1d87042ca 100644 --- a/bootloader/Makefile +++ b/bootloader/Makefile @@ -1,22 +1,20 @@ NAME = bootloader -MCU_DIR=$(subst /bootloader,,$(PWD)) - OBJS += bootloader.o OBJS += signatures.o OBJS += usb.o -OBJS += $(MCU_DIR)/trezor-crypto/bignum.o -OBJS += $(MCU_DIR)/trezor-crypto/ecdsa.small.o -OBJS += $(MCU_DIR)/trezor-crypto/hmac.o -OBJS += $(MCU_DIR)/trezor-crypto/ripemd160.o -OBJS += $(MCU_DIR)/trezor-crypto/secp256k1.small.o -OBJS += $(MCU_DIR)/trezor-crypto/sha2.o +OBJS += ../trezor-crypto/bignum.o +OBJS += ../trezor-crypto/ecdsa.small.o +OBJS += ../trezor-crypto/hmac.o +OBJS += ../trezor-crypto/ripemd160.o +OBJS += ../trezor-crypto/secp256k1.small.o +OBJS += ../trezor-crypto/sha2.o CFLAGS += -DUSE_PRECOMPUTED_IV=0 CFLAGS += -DUSE_PRECOMPUTED_CP=0 -include $(MCU_DIR)/Makefile.include +include ../Makefile.include align: ./firmware_align.py $(NAME).bin diff --git a/bootloader/usb.c b/bootloader/usb.c index 4de353c03..94c93fcc2 100644 --- a/bootloader/usb.c +++ b/bootloader/usb.c @@ -187,8 +187,7 @@ static const char *usb_strings[] = { "", // empty serial }; -static int hid_control_request(usbd_device *dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len, - void (**complete)(usbd_device *, struct usb_setup_data *)) +static int hid_control_request(usbd_device *dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len, usbd_control_complete_callback *complete) { (void)complete; (void)dev; diff --git a/demo/demo.c b/demo/demo.c index 0682e7ca7..51242d650 100644 --- a/demo/demo.c +++ b/demo/demo.c @@ -25,9 +25,9 @@ #include "layout.h" #include "oled.h" #include "setup.h" -//#include "util.h" #include "hmac.h" #include "pbkdf2.h" +#include "rng.h" const int states = 2; int state = 0; @@ -192,8 +192,7 @@ static const char *usb_strings[] = { "01234567", }; -static int hid_control_request(usbd_device *dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len, - void (**complete)(usbd_device *, struct usb_setup_data *)) +static int hid_control_request(usbd_device *dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len, usbd_control_complete_callback *complete) { (void)complete; (void)dev; @@ -239,8 +238,17 @@ void usbInit(void) usbd_register_set_config_callback(usbd_dev, hid_set_config); } +uint32_t __stack_chk_guard; + +void __attribute__((noreturn)) __stack_chk_fail(void) +{ + layoutDialog(DIALOG_ICON_ERROR, NULL, NULL, NULL, "Stack smashing", "detected.", NULL, "Please unplug", "the device.", NULL); + for (;;) {} // loop forever +} + int main(void) { + __stack_chk_guard = random32(); #ifndef APPVER setup(); oledInit(); @@ -264,7 +272,7 @@ int main(void) usbd_poll(usbd_dev); switch (state) { case 1: - layoutProgress("WORKING", frame % 41 * 25, frame % 4); + layoutProgress("WORKING", frame % 41 * 25); pbkdf2_hmac_sha512(pass, passlen, salt, saltlen, 100, seed, 64, NULL); usbd_ep_write_packet(usbd_dev, 0x81, seed, 64); break;