diff --git a/src/platforms/native/usbdfu.c b/src/platforms/native/usbdfu.c index 020a976..db44002 100644 --- a/src/platforms/native/usbdfu.c +++ b/src/platforms/native/usbdfu.c @@ -42,7 +42,7 @@ int main(void) if(gpio_get(GPIOB, GPIO12)) dfu_jump_app_if_valid(); - dfu_protect(DFU_MODE); + dfu_protect(false); rcc_clock_setup_in_hse_8mhz_out_72mhz(); systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8); @@ -60,7 +60,7 @@ int main(void) gpio_set_mode(LED_PORT, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, LED_0 | LED_1 | LED_2); - dfu_init(&st_usbfs_v1_usb_driver, DFU_MODE); + dfu_init(&st_usbfs_v1_usb_driver); /* Configure the USB pull up pin. */ gpio_set(GPIOA, GPIO8); diff --git a/src/platforms/stlink/Makefile.inc b/src/platforms/stlink/Makefile.inc index 66feef6..a1d74f5 100644 --- a/src/platforms/stlink/Makefile.inc +++ b/src/platforms/stlink/Makefile.inc @@ -39,16 +39,12 @@ SRC += cdcacm.c \ ifeq ($(ST_BOOTLOADER), 1) all: blackmagic.bin else -all: blackmagic.bin blackmagic_dfu.bin blackmagic_dfu.hex dfu_upgrade.bin dfu_upgrade.hex +all: blackmagic.bin blackmagic_dfu.bin blackmagic_dfu.hex endif blackmagic_dfu.elf: usbdfu.o dfucore.o dfu_f1.o stlink_common.o @echo " LD $@" $(Q)$(CC) $^ -o $@ $(LDFLAGS_BOOT) -dfu_upgrade.elf: dfu_upgrade.o dfucore.o dfu_f1.o stlink_common.o - @echo " LD $@" - $(Q)$(CC) $^ -o $@ $(LDFLAGS) - host_clean: -$(Q)$(RM) *.bin *elf *hex diff --git a/src/platforms/stlink/dfu_upgrade.c b/src/platforms/stlink/dfu_upgrade.c deleted file mode 100644 index aeb559d..0000000 --- a/src/platforms/stlink/dfu_upgrade.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - * This file is part of the Black Magic Debug project. - * - * Copyright (C) 2013 Gareth McMullin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include - -#include "usbdfu.h" -#include "general.h" -#include "platform.h" - -uint32_t app_address = 0x08000000; -static uint16_t led_upgrade; -static uint32_t led2_state = 0; -extern uint32_t _stack; -static uint32_t rev; - -void dfu_detach(void) -{ - platform_request_boot(); - scb_reset_core(); -} - -int main(void) -{ - rev = detect_rev(); - rcc_clock_setup_in_hse_8mhz_out_72mhz(); - if (rev == 0) - led_upgrade = GPIO8; - else - led_upgrade = GPIO9; - - systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8); - systick_set_reload(900000); - - dfu_protect(UPD_MODE); - - systick_interrupt_enable(); - systick_counter_enable(); - - if (rev > 1) /* Reconnect USB */ - gpio_set(GPIOA, GPIO15); - dfu_init(&st_usbfs_v1_usb_driver, UPD_MODE); - - dfu_main(); -} - -void dfu_event(void) -{ -} - -void sys_tick_handler(void) -{ - if (rev == 0) { - gpio_toggle(GPIOA, led_upgrade); - } else { - if (led2_state & 1) { - gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, - GPIO_CNF_OUTPUT_PUSHPULL, led_upgrade); - gpio_set(GPIOA, led_upgrade); - } else { - gpio_set_mode(GPIOA, GPIO_MODE_INPUT, - GPIO_CNF_INPUT_ANALOG, led_upgrade); - } - led2_state++; - } -} diff --git a/src/platforms/stlink/platform.h b/src/platforms/stlink/platform.h index 99e3555..ee776f6 100644 --- a/src/platforms/stlink/platform.h +++ b/src/platforms/stlink/platform.h @@ -42,9 +42,7 @@ int usbuart_debug_write(const char *buf, size_t len); #define BOARD_IDENT "Black Magic Probe (STLINK), (Firmware " FIRMWARE_VERSION ")" #define BOARD_IDENT_DFU "Black Magic (Upgrade) for STLink/Discovery, (Firmware " FIRMWARE_VERSION ")" -#define BOARD_IDENT_UPD "Black Magic (DFU Upgrade) for STLink/Discovery, (Firmware " FIRMWARE_VERSION ")" #define DFU_IDENT "Black Magic Firmware Upgrade (STLINK)" -#define UPD_IFACE_STRING "@Internal Flash /0x08000000/8*001Kg" /* Hardware definitions... */ #define TDI_PORT GPIOA diff --git a/src/platforms/stlink/usbdfu.c b/src/platforms/stlink/usbdfu.c index d016075..8b1cf7c 100644 --- a/src/platforms/stlink/usbdfu.c +++ b/src/platforms/stlink/usbdfu.c @@ -63,7 +63,7 @@ int main(void) if(((GPIOA_CRL & 0x40) == 0x40) && stlink_test_nrst()) dfu_jump_app_if_valid(); - dfu_protect(DFU_MODE); + dfu_protect(false); rcc_clock_setup_in_hse_8mhz_out_72mhz(); systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8); @@ -75,7 +75,7 @@ int main(void) if (rev > 1) gpio_set(GPIOA, GPIO15); - dfu_init(&st_usbfs_v1_usb_driver, DFU_MODE); + dfu_init(&st_usbfs_v1_usb_driver); dfu_main(); } diff --git a/src/platforms/stm32/dfu_f1.c b/src/platforms/stm32/dfu_f1.c index b4b9208..fc9f418 100644 --- a/src/platforms/stm32/dfu_f1.c +++ b/src/platforms/stm32/dfu_f1.c @@ -62,9 +62,9 @@ uint32_t dfu_poll_timeout(uint8_t cmd, uint32_t addr, uint16_t blocknum) return 100; } -void dfu_protect(dfu_mode_t mode) +void dfu_protect(bool enable) { - if (mode == DFU_MODE) { + if (enable) { #ifdef DFU_SELF_PROTECT if ((FLASH_WRPR & 0x03) != 0x00) { flash_unlock(); diff --git a/src/platforms/stm32/dfucore.c b/src/platforms/stm32/dfucore.c index 8bdb05d..d90f6ea 100644 --- a/src/platforms/stm32/dfucore.c +++ b/src/platforms/stm32/dfucore.c @@ -132,15 +132,6 @@ static const char *usb_strings[] = { if_string, }; -static char upd_if_string[] = UPD_IFACE_STRING; -static const char *usb_strings_upd[] = { - "Black Sphere Technologies", - BOARD_IDENT_UPD, - serial_no, - /* This string is used by ST Microelectronics' DfuSe utility */ - upd_if_string, -}; - static uint32_t get_le32(const void *vp) { const uint8_t *p = vp; @@ -293,12 +284,12 @@ static enum usbd_request_return_codes usbdfu_control_request(usbd_device *dev, return USBD_REQ_NOTSUPP; } -void dfu_init(const usbd_driver *driver, dfu_mode_t mode) +void dfu_init(const usbd_driver *driver) { get_dev_unique_id(serial_no); usbdev = usbd_init(driver, &dev, &config, - (mode == DFU_MODE)?usb_strings:usb_strings_upd, 4, + usb_strings, 4, usbd_control_buffer, sizeof(usbd_control_buffer)); usbd_register_control_callback(usbdev, @@ -357,12 +348,6 @@ static char *get_dev_unique_id(char *s) fuse_flash_size = 0x80; set_dfu_iface_string(fuse_flash_size - 8); max_address = FLASH_BASE + (fuse_flash_size << 10); - /* If bootloader pages are write protected or device is read - * protected, deny bootloader update. - * User can still force updates, at his own risk! - */ - if (((FLASH_WRPR & 0x03) != 0x03) || (FLASH_OBR & FLASH_OBR_RDPRT_EN)) - upd_if_string[30] = '0'; /* Fetch serial number from chip's unique ID */ for(i = 0; i < 8; i++) { s[7-i] = ((unique_id >> (4*i)) & 0xF) + '0'; diff --git a/src/platforms/stm32/usbdfu.h b/src/platforms/stm32/usbdfu.h index 3f5b3f8..aaa949a 100644 --- a/src/platforms/stm32/usbdfu.h +++ b/src/platforms/stm32/usbdfu.h @@ -27,20 +27,15 @@ #define CMD_ERASE 0x41 extern uint32_t app_address; -typedef enum { - DFU_MODE = 0, - UPD_MODE = 1 -} dfu_mode_t; - /* dfucore.c - DFU core, common to libopencm3 platforms. */ -void dfu_init(const usbd_driver *driver, dfu_mode_t mode); +void dfu_init(const usbd_driver *driver); void dfu_main(void); /* Device specific functions */ void dfu_check_and_do_sector_erase(uint32_t sector); void dfu_flash_program_buffer(uint32_t baseaddr, void *buf, int len); uint32_t dfu_poll_timeout(uint8_t cmd, uint32_t addr, uint16_t blocknum); -void dfu_protect(dfu_mode_t mode); +void dfu_protect(bool enable); void dfu_jump_app_if_valid(void); void dfu_event(void); diff --git a/src/platforms/swlink/Makefile.inc b/src/platforms/swlink/Makefile.inc index 5ac76ec..5cad72e 100644 --- a/src/platforms/swlink/Makefile.inc +++ b/src/platforms/swlink/Makefile.inc @@ -29,16 +29,12 @@ SRC += cdcacm.c \ traceswoasync.c \ platform_common.c \ -all: blackmagic.bin blackmagic_dfu.bin blackmagic_dfu.hex dfu_upgrade.bin dfu_upgrade.hex +all: blackmagic.bin blackmagic_dfu.bin blackmagic_dfu.hex blackmagic_dfu.elf: usbdfu.o dfucore.o dfu_f1.o platform_common.o @echo " LD $@" $(Q)$(CC) $^ -o $@ $(LDFLAGS_BOOT) -dfu_upgrade.elf: dfu_upgrade.o dfucore.o dfu_f1.o platform_common.o - @echo " LD $@" - $(Q)$(CC) $^ -o $@ $(LDFLAGS) - host_clean: -$(Q)$(RM) blackmagic.bin blackmagic_dfu blackmagic_dfu.bin blackmagic_dfu.hex diff --git a/src/platforms/swlink/dfu_upgrade.c b/src/platforms/swlink/dfu_upgrade.c deleted file mode 100644 index c34123a..0000000 --- a/src/platforms/swlink/dfu_upgrade.c +++ /dev/null @@ -1,68 +0,0 @@ -/* - * This file is part of the Black Magic Debug project. - * - * Copyright (C) 2018 Uwe Bonnes (bon@elektron.ikp.physik.tu-darmstadt.de) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include - -#include "usbdfu.h" -#include "general.h" -#include "platform.h" - -uint32_t app_address = 0x08000000; -extern uint32_t _stack; -static uint32_t rev; - -void dfu_detach(void) -{ - platform_request_boot(); - scb_reset_core(); -} - -int main(void) -{ - rev = detect_rev(); - rcc_clock_setup_in_hse_8mhz_out_72mhz(); - systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8); - systick_set_reload(900000); - - dfu_protect(UPD_MODE); - - systick_interrupt_enable(); - systick_counter_enable(); - - dfu_init(&st_usbfs_v1_usb_driver, UPD_MODE); - - dfu_main(); -} - -void dfu_event(void) -{ -} - -void sys_tick_handler(void) -{ - if (rev == 0) { - gpio_toggle(GPIOA, GPIO8); - } else { - gpio_toggle(GPIOC, GPIO13); - } -} diff --git a/src/platforms/swlink/platform.h b/src/platforms/swlink/platform.h index aadf042..c8a9f2e 100644 --- a/src/platforms/swlink/platform.h +++ b/src/platforms/swlink/platform.h @@ -39,9 +39,7 @@ int usbuart_debug_write(const char *buf, size_t len); #define BOARD_IDENT "Black Magic Probe (SWLINK), (Firmware " FIRMWARE_VERSION ")" #define BOARD_IDENT_DFU "Black Magic (Upgrade), SWLINK, (Firmware " FIRMWARE_VERSION ")" -#define BOARD_IDENT_UPD "Black Magic (DFU Upgrade), SWLINK, (Firmware " FIRMWARE_VERSION ")" #define DFU_IDENT "Black Magic Firmware Upgrade (SWLINK)" -#define UPD_IFACE_STRING "@Internal Flash /0x08000000/8*001Kg" /* Hardware definitions... */ #define TMS_PORT GPIOA diff --git a/src/platforms/swlink/usbdfu.c b/src/platforms/swlink/usbdfu.c index 527ad44..c6a2b28 100644 --- a/src/platforms/swlink/usbdfu.c +++ b/src/platforms/swlink/usbdfu.c @@ -75,7 +75,7 @@ int main(void) if(((GPIOA_CRL & 0x40) == 0x40) && normal_boot) dfu_jump_app_if_valid(); - dfu_protect(DFU_MODE); + dfu_protect(false); rcc_clock_setup_in_hse_8mhz_out_72mhz(); systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8); @@ -84,7 +84,7 @@ int main(void) systick_interrupt_enable(); systick_counter_enable(); - dfu_init(&st_usbfs_v1_usb_driver, DFU_MODE); + dfu_init(&st_usbfs_v1_usb_driver); dfu_main(); }