8000 Customize dfu flash operations according to key presence · arduino/mcuboot-arduino-stm32h7@d257915 · GitHub
[go: up one dir, main page]

Skip to content

Commit d257915

Browse files
committed
Customize dfu flash operations according to key presence
1 parent 5dbff35 commit d257915

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

app/dfu/usbd_dfu_flash.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "FlashSimBlockDevice.h"
2929
#include "flash_map_backend/secondary_bd.h"
3030
#include "bootutil/bootutil.h"
31+
#include "bootutil/bootutil_extra.h"
3132

3233
/* Private typedef ----------------------------------------------------------- */
3334
/* Private define ------------------------------------------------------------ */
@@ -60,7 +61,21 @@ mbed::BlockDevice* dfu_secondary_bd = get_secondary_bd();
6061
const uint32_t QSPIFLASH_BASE_ADDRESS = 0x90000000;
6162
const uint32_t FILEBLOCK_BASE_ADDRESS = 0xA0000000;
6263

63-
USBD_DFU_MediaTypeDef USBD_DFU_Flash_fops = {
64+
USBD_DFU_MediaTypeDef USBD_DFU_Flash_fops_default = {
65+
{
66+
(uint8_t *) FLASH_DESC_STR,
67+
(uint8_t *) QSPI_FLASH_DESC_STR,
68+
(uint8_t *) BOOTLOADER_DESC_STR
69+
},
70+
Flash_If_Init,
71+
Flash_If_DeInit,
72+
Flash_If_Erase,
73+
Flash_If_Write,
74+
Flash_If_Read,
75+
Flash_If_GetStatus,
76+
};
77+
78+
USBD_DFU_MediaTypeDef USBD_DFU_Flash_fops_MCUboot = {
6479
{
6580
(uint8_t *) FLASH_DESC_STR,
6681
(uint8_t *) QSPI_FLASH_DESC_STR,
@@ -83,7 +98,11 @@ void init_Memories() {
8398
if (dfu_secondary_bd != nullptr) {
8499
dfu_secondary_bd->init();
85100
}
86-
snprintf(BOOTLOADER_DESC_STR, sizeof(BOOTLOADER_DESC_STR), "@MCUBoot version %d /0x00000000/0*4Kg", BOOTLOADER_VERSION);
101+
if(boot_empty_keys()) {
102+
snprintf(BOOTLOADER_DESC_STR, sizeof(BOOTLOADER_DESC_STR), "@Arduino boot v.%d /0x00000000/0*4Kg", BOOTLOADER_VERSION);
103+
} else {
104+
snprintf(BOOTLOADER_DESC_STR, sizeof(BOOTLOADER_DESC_STR), "@MCUboot v.%d /0x00000000/0*4Kg", BOOTLOADER_VERSION);
105+
}
87106
}
88107

89108
Thread writeThread(osPriorityHigh);

app/dfu/usbd_dfu_flash.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
#define ADDR_FLASH_SECTOR_7_BANK2 ((uint32_t)0x081E0000) /* Base @ of Sector 7, 128 Kbytes */
4949

5050
/* Exported macro ------------------------------------------------------------*/
51-
extern USBD_DFU_MediaTypeDef USBD_DFU_Flash_fops;
51+
extern USBD_DFU_MediaTypeDef USBD_DFU_Flash_fops_default;
52+
extern USBD_DFU_MediaTypeDef USBD_DFU_Flash_fops_MCUboot;
5253
#define FLASH_BASE_ADDR (uint32_t)(FLASH_BASE)
5354
#define FLASH_END_ADDR (uint32_t)(0x081FFFFF)
5455

app/main.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,11 @@ static int start_dfu(void) {
151151
USBD_RegisterClass(&USBD_Device, USBD_DFU_CLASS);
152152

153153
/* Add DFU Media interface */
154-
USBD_DFU_RegisterMedia(&USBD_Device, &USBD_DFU_Flash_fops);
154+
if(boot_empty_keys()) {
155+
USBD_DFU_RegisterMedia(&USBD_Device, &USBD_DFU_Flash_fops_default);
156+
} else {
157+
USBD_DFU_RegisterMedia(&USBD_Device, &USBD_DFU_Flash_fops_MCUboot);
158+
}
155159

156160
/* Start Device Process */
157161
USBD_Start(&USBD_Device);

0 commit comments

Comments
 (0)
0