Skip to content

Commit

Permalink
signature: add unknown state for binary without signature
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor-Misic authored and jciberlin committed May 29, 2022
1 parent 35c7311 commit 785e26b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions Bootloader/Inc/signature.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ typedef enum detectedBinary_ENUM {
detectedBinary_FIRMWARE_RAM, //!< Firmware for RAM
detectedBinary_BOOTLOADER_FLASH, //!< New bootloader for FLASH
detectedBinary_BOOTLOADER_RAM, //!< Bootloader for RAM
detectedBinary_UNKNOWN, //!< Not existing or unknown signature
} detectedBinary_E;

detectedBinary_E Signature_verification(const signature_S* signature);
Expand Down
16 changes: 13 additions & 3 deletions Bootloader/Src/binary_update.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,14 @@ BinaryUpdate_handleDetectedBinary(detectedBinary_E detected_binary) {
s_address = RAM_FIRMWARE_ADDRESS;
break;

default:
case detectedBinary_UNKNOWN:
//we support unsigned binary but handle it as firmware for flash
success = false;
s_address = FLASH_FIRMWARE_ADDRESS;
break;

default:
break;
}

return success;
Expand Down Expand Up @@ -130,9 +134,12 @@ BinaryUpdate_erase(uint32_t firmware_size) {
case detectedBinary_BOOTLOADER_RAM:
break;

default:
case detectedBinary_UNKNOWN:
success = FlashAdapter_erase(firmware_size, s_address);
break;

default:
break;
}

return success;
Expand Down Expand Up @@ -195,11 +202,14 @@ BinaryUpdate_finish(void) {
boot_info.skip_bl_loop = true;
break;

default:
case detectedBinary_UNKNOWN:
boot_info.jump_address = FLASH_FIRMWARE_ADDRESS;
boot_info.skip_bl_loop = false;
success = FlashAdapter_finish();
break;

default:
break;
}

boot_info.previus_binary = s_detected_binary;
Expand Down
2 changes: 1 addition & 1 deletion Bootloader/Src/signature.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Signature_verification(const signature_S* signature) {
} else if (0 == memcmp(&(signature->magic_key), &bl_ram_signature_magic_key, sizeof(bl_ram_signature_magic_key))) {
detected_binary = detectedBinary_BOOTLOADER_RAM;
} else {
detected_binary = detectedBinary_FIRMWARE_FLASH;
detected_binary = detectedBinary_UNKNOWN;
}

return detected_binary;
Expand Down

0 comments on commit 785e26b

Please sign in to comment.