diff --git a/src/platforms/stm32/dfucore.c b/src/platforms/stm32/dfucore.c index f020e61..61cfd04 100644 --- a/src/platforms/stm32/dfucore.c +++ b/src/platforms/stm32/dfucore.c @@ -124,12 +124,13 @@ 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_IFACE_STRING, + upd_if_string, }; static uint32_t get_le32(const void *vp) @@ -355,6 +356,12 @@ static char *get_dev_unique_id(char *s) if (fuse_flash_size == 0x40) /* Handle F103x8 as F103xC! */ fuse_flash_size = 0x80; 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';