Skip to content

Commit 83849c5

Browse files
flash_decoder: Pass address to validate_target_image function.
When blocks are received out of order the data passed to board_detect_incompatible_image() via flash_decoder_validate_target_image() might not be the first block of flash data, as expected by the microbitv2 imcompatibility detection, so pass the address to the function and perform the check.
1 parent 82dc31d commit 83849c5

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

source/board/microbitv2/microbitv2.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -446,13 +446,16 @@ static uint32_t read_file_data_txt(uint32_t sector_offset, uint8_t *data, uint32
446446
return VFS_SECTOR_SIZE;
447447
}
448448

449-
uint8_t board_detect_incompatible_image(const uint8_t *data, uint32_t size)
449+
uint8_t board_detect_incompatible_image(uint32_t addr, const uint8_t *data, uint32_t size)
450450
{
451-
uint8_t result = 0;
451+
// We can only check image compatibility on the first block of flash data
452+
if (addr != 0) {
453+
return 0;
454+
}
452455

453456
// Check difference in vectors (mem fault, bus fault, usage fault)
454457
// If these vectors are 0, we assume it's an M0 image (not compatible)
455-
result = memcmp(data + M0_RESERVED_VECT_OFFSET, (uint8_t[M0_RESERVED_VECT_SIZE]){0}, M0_RESERVED_VECT_SIZE);
458+
uint8_t result = memcmp(data + M0_RESERVED_VECT_OFFSET, (uint8_t[M0_RESERVED_VECT_SIZE]){0}, M0_RESERVED_VECT_SIZE);
456459

457460
return result == 0;
458461
}

source/daplink/drag-n-drop/flash_decoder.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static bool flash_type_target_bin;
6060

6161
static bool flash_decoder_is_at_end(uint32_t addr, const uint8_t *data, uint32_t size);
6262

63-
__WEAK uint8_t board_detect_incompatible_image(const uint8_t *data, uint32_t size)
63+
__WEAK uint8_t board_detect_incompatible_image(uint32_t addr, const uint8_t *data, uint32_t size)
6464
{
6565
return 0; // Return 0 if image is compatible
6666
}
@@ -190,14 +190,14 @@ error_t flash_decoder_get_flash(flash_decoder_type_t type, uint32_t addr, bool a
190190
return status;
191191
}
192192

193-
error_t flash_decoder_validate_target_image(flash_decoder_type_t type, const uint8_t *data, uint32_t size)
193+
error_t flash_decoder_validate_target_image(flash_decoder_type_t type, uint32_t addr, const uint8_t *data, uint32_t size)
194194
{
195195
error_t status = ERROR_SUCCESS;
196196

197197
if (daplink_is_interface()) {
198198
if (FLASH_DECODER_TYPE_TARGET == type) {
199199
if (g_board_info.target_cfg) {
200-
if (board_detect_incompatible_image(data, size)){
200+
if (board_detect_incompatible_image(addr, data, size)){
201201
status = ERROR_FD_INCOMPATIBLE_IMAGE;
202202
} else {
203203
status = ERROR_SUCCESS;
@@ -295,7 +295,7 @@ error_t flash_decoder_write(uint32_t addr, const uint8_t *data, uint32_t size)
295295

296296
// Validate incompatible target image file
297297
if (config_get_detect_incompatible_target()){
298-
status = flash_decoder_validate_target_image(flash_type, flash_buf, flash_buf_pos);
298+
status = flash_decoder_validate_target_image(flash_type, addr, flash_buf, flash_buf_pos);
299299

300300
if (ERROR_SUCCESS != status) {
301301
state = DECODER_STATE_ERROR;

source/daplink/drag-n-drop/flash_decoder.h

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ typedef enum {
4545
flash_decoder_type_t flash_decoder_detect_type(const uint8_t *data, uint32_t size, uint32_t addr, bool addr_valid);
4646
error_t flash_decoder_get_flash(flash_decoder_type_t type, uint32_t addr, bool addr_valid, uint32_t *start_addr, const flash_intf_t **flash_intf);
4747

48-
error_t flash_decoder_validate_target_image(flash_decoder_type_t type, const uint8_t *data, uint32_t size);
4948
error_t flash_decoder_open(void);
5049
error_t flash_decoder_write(uint32_t addr, const uint8_t *data, uint32_t size);
5150
error_t flash_decoder_close(void);

0 commit comments

Comments
 (0)