From b7235da97fd5141ce1f0ea963237a8fb71e71930 Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Fri, 28 Apr 2017 20:18:20 +0200 Subject: [PATCH] dfucore.c: Announce no writable bootloader pages when device is read proteced or bootloader is write protected. Device read protection or write protection on first 4 bootloader pages can only be removed by mass erase. Triggering mass erase with a program running from flash is doomed for failure. User can force bootloader update, at their own risk to brick the device. --- src/platforms/stm32/dfucore.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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';