mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-17 02:52:12 +01:00
bu: check compatibility btw BL and HW before installing
CC and CC3D boards share the same FW image. This is accomplished by checking the BOARD_REVISION field in the board_info_blob that is stored in the BL partition in flash as we init the FW. Make sure that the BU image only writes a BL image that has the same BOARD_TYPE and BOARD_REVISION fields in the embedded image as the ones currently in flash on the board. This ensures that we never write a CC3D BL image onto a CC board and vice versa. This check should prevent "bricking" a board.
This commit is contained in:
parent
e063bb0490
commit
3b0508e753
@ -28,6 +28,7 @@
|
||||
/* Bootloader Includes */
|
||||
#include <pios.h>
|
||||
#include <stdbool.h>
|
||||
#include "pios_board_info.h"
|
||||
|
||||
#define MAX_WRI_RETRYS 3
|
||||
/* Prototype of PIOS_Board_Init() function */
|
||||
@ -56,6 +57,31 @@ int main() {
|
||||
if ((0x08000000 + embedded_image_size) > base_address)
|
||||
error();
|
||||
///
|
||||
|
||||
/*
|
||||
* Make sure the bootloader we're carrying is for the same
|
||||
* board type and board revision as the one we're running on.
|
||||
*
|
||||
* Assume the bootloader in flash and the bootloader contained in
|
||||
* the updater both carry a board_info_blob at the end of the image.
|
||||
*/
|
||||
|
||||
/* Calculate how far the board_info_blob is from the beginning of the bootloader */
|
||||
uint32_t board_info_blob_offset = (uint32_t)&pios_board_info_blob - (uint32_t)0x08000000;
|
||||
|
||||
/* Use the same offset into our embedded bootloader image */
|
||||
struct pios_board_info * new_board_info_blob = (struct pios_board_info *)
|
||||
((uint32_t)embedded_image_start + board_info_blob_offset);
|
||||
|
||||
/* Compare the two board info blobs to make sure they're for the same HW revision */
|
||||
if ((pios_board_info_blob.magic != new_board_info_blob->magic) ||
|
||||
(pios_board_info_blob.board_type != new_board_info_blob->board_type) ||
|
||||
(pios_board_info_blob.board_rev != new_board_info_blob->board_rev)) {
|
||||
error();
|
||||
}
|
||||
|
||||
/* Embedded bootloader looks like it's the right one for this HW, proceed... */
|
||||
|
||||
FLASH_Unlock();
|
||||
|
||||
/// Bootloader memory space erase
|
||||
|
Loading…
x
Reference in New Issue
Block a user