mirror of
https://github.com/andreili/katapult.git
synced 2025-08-24 03:44:06 +02:00
canboot: add application code check
Enter the bootloader if the first block of the application area contains 0xFF. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
4cd17a6f5e
commit
1d2ce10dbd
@ -214,6 +214,19 @@ canboot_process_rx(uint32_t id, uint32_t len, uint8_t *data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline uint8_t
|
||||||
|
check_application_code(void)
|
||||||
|
{
|
||||||
|
// Read the first block of memory, if it
|
||||||
|
// is all 0xFF then no application has been flashed
|
||||||
|
flash_read_block(0, (uint32_t*)page_buffer);
|
||||||
|
for (uint8_t i = 0; i < CONFIG_BLOCK_SIZE; i++) {
|
||||||
|
if (page_buffer[i] != 0xFF)
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************
|
/****************************************************************
|
||||||
* Startup
|
* Startup
|
||||||
@ -252,9 +265,9 @@ void
|
|||||||
canboot_main(void)
|
canboot_main(void)
|
||||||
{
|
{
|
||||||
uint16_t mkey = read_magic_key();
|
uint16_t mkey = read_magic_key();
|
||||||
// Attempt to enter the bootloader. This function should not
|
// Enter the bootloader if the magic key has been set or if
|
||||||
// return
|
// no application has been flashed
|
||||||
if (mkey == CONFIG_MAGIC_KEY)
|
if (mkey == CONFIG_MAGIC_KEY || !check_application_code())
|
||||||
enter_bootloader();
|
enter_bootloader();
|
||||||
|
|
||||||
// set magic key and delay for one second. This enters the bootloader if
|
// set magic key and delay for one second. This enters the bootloader if
|
||||||
|
Loading…
x
Reference in New Issue
Block a user