Remove unused bootloader support
This commit is contained in:
@@ -1,138 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019 Scene Connect Ltd.
|
||||
*
|
||||
* This code is based on the bootloader developed by Okra Solar.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifdef BOOTLOADER_ENABLED
|
||||
|
||||
#include "bl_support.h"
|
||||
#include "stm32l0xx.h"
|
||||
#include "debug.h"
|
||||
|
||||
/**
|
||||
* Unlock the FLASH control register access and the program memory access.
|
||||
*/
|
||||
void flash_unlock(void)
|
||||
{
|
||||
if (HAL_IS_BIT_SET(FLASH->PECR, FLASH_PECR_PRGLOCK)) {
|
||||
/* Unlocking FLASH_PECR register access*/
|
||||
if (HAL_IS_BIT_SET(FLASH->PECR, FLASH_PECR_PELOCK)) {
|
||||
WRITE_REG(FLASH->PEKEYR, FLASH_PEKEY1);
|
||||
WRITE_REG(FLASH->PEKEYR, FLASH_PEKEY2);
|
||||
}
|
||||
/* Unlocking the program memory access */
|
||||
WRITE_REG(FLASH->PRGKEYR, FLASH_PRGKEY1);
|
||||
WRITE_REG(FLASH->PRGKEYR, FLASH_PRGKEY2);
|
||||
}
|
||||
else {
|
||||
// Error handler
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Program a word at a specified address in the flash memory.
|
||||
* (1) Perform the data write (32-bit word) at the desired address
|
||||
* (2) Wait until the BSY bit is reset in the FLASH_SR register
|
||||
* (3) Check the EOP flag in the FLASH_SR register
|
||||
* (4) clear it by software by writing it at 1
|
||||
*/
|
||||
void flash_program(uint32_t address, uint32_t data)
|
||||
{
|
||||
/* Program word (32-bit) at a specified address.*/
|
||||
*(__IO uint32_t *)address = data;
|
||||
|
||||
while ((FLASH->SR & FLASH_SR_BSY) != 0) { /* (2) */
|
||||
/* For robust implementation, add here time-out management */
|
||||
}
|
||||
if ((FLASH->SR & FLASH_SR_EOP) != 0) { /* (3) */
|
||||
FLASH->SR = FLASH_SR_EOP; /* (4) */
|
||||
}
|
||||
else {
|
||||
/* Manage the error cases */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to write the bootloader status to the flash address 'BOOTLOADER_STATUS_STRUCT_ADDR'.
|
||||
* @param status: The struct containing the bootloader status information.
|
||||
*/
|
||||
void write_status_reg(BootloaderStatus& status)
|
||||
{
|
||||
// Make sure the status reg is halfword aligned
|
||||
// Check if this is really required.
|
||||
static_assert(sizeof(status) % 2 == 0);
|
||||
|
||||
// Unlock the FLASH_PECR register access.
|
||||
// Then unlock the program memory access.
|
||||
flash_unlock();
|
||||
|
||||
/*
|
||||
* Erase a page in the Flash at BOOTLOADER_STATUS_STRUCT_ADDR - For STM32L073RZ
|
||||
* (1) Set the ERASE and PROG bits in the FLASH_PECR register to enable page erasing
|
||||
* (2) Write a 32-bit word value in an address of the selected page to start the erase sequence
|
||||
* (3) Wait until the BSY bit is reset in the FLASH_SR register
|
||||
* (4) Check the EOP flag in the FLASH_SR register
|
||||
* (5) Clear EOP flag by software by writing EOP at 1
|
||||
* (6) Reset the ERASE and PROG bits in the FLASH_PECR register to disable the page erase
|
||||
* Program and erase control register (FLASH_PECR) - This register can only be written after a
|
||||
* good write sequence done in FLASH_PEKEYR, resetting the PELOCK bit.
|
||||
*/
|
||||
FLASH->PECR |= FLASH_PECR_ERASE | FLASH_PECR_PROG;
|
||||
|
||||
*(__IO uint32_t *)BOOTLOADER_STATUS_STRUCT_ADDR = (uint32_t)0;
|
||||
|
||||
while ((FLASH->SR & FLASH_SR_BSY) != 0) {
|
||||
/* For robust implementation, add here time-out management */
|
||||
}
|
||||
|
||||
if ((FLASH->SR & FLASH_SR_EOP) != 0) {
|
||||
FLASH->SR = FLASH_SR_EOP;
|
||||
}
|
||||
else {
|
||||
/* Manage the error cases */
|
||||
}
|
||||
FLASH->PECR &= ~(FLASH_PECR_ERASE | FLASH_PECR_PROG);
|
||||
|
||||
/*
|
||||
* Write status struct to the flash
|
||||
* (1) Set the PROG and FPRG bits in the FLASH_PECR register to enable a half page programming
|
||||
* (2) Perform the data write (half-word) at the desired address
|
||||
* (3) Wait until the BSY bit is reset in the FLASH_SR register
|
||||
* (4) Check the EOP flag in the FLASH_SR register
|
||||
* (5) clear it by software by writing it at 1
|
||||
* (6) Reset the PROG and FPRG bits to disable programming
|
||||
*/
|
||||
uint32_t *data = (uint32_t *)&status;
|
||||
uint32_t address = BOOTLOADER_STATUS_STRUCT_ADDR;
|
||||
|
||||
for (unsigned int i = 0; i < sizeof(status) / sizeof(uint32_t); i++) {
|
||||
flash_program(address, *data);
|
||||
data++;
|
||||
address += 4;
|
||||
}
|
||||
|
||||
// Locking FLASH_PECR register again
|
||||
// Set the PRGLOCK Bit to lock the FLASH Registers access
|
||||
SET_BIT(FLASH->PECR, FLASH_PECR_PRGLOCK);
|
||||
}
|
||||
|
||||
// Called from main
|
||||
void check_bootloader(void)
|
||||
{
|
||||
//print_info("App1...\r\n");
|
||||
|
||||
// Read the bootloader status from the flash memory location
|
||||
BootloaderStatus status_reg = *((BootloaderStatus *)BOOTLOADER_STATUS_STRUCT_ADDR);
|
||||
|
||||
// If the Bootloader Status is ATTEMPT_NEW_APP, change it to STABLE_APP
|
||||
if (status_reg.status == BootloaderState::ATTEMPT_NEW_APP) {
|
||||
status_reg.status = BootloaderState::STABLE_APP;
|
||||
write_status_reg(status_reg); // Write the status to flash
|
||||
//print_info("Switched to stable app...\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
#endif /*BOOTLOADER_ENABLED*/
|
||||
@@ -1,84 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019 Scene Connect Ltd.
|
||||
*
|
||||
* This code is based on the bootloader developed by Okra Solar.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef BL_SUPPORT_H
|
||||
#define BL_SUPPORT_H
|
||||
|
||||
#ifdef BOOTLOADER_ENABLED
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
/** Length of the bootloader name string (including \0 termination) */
|
||||
const uint8_t BOOTLADER_NAME_LENGTH = 18;
|
||||
|
||||
/**
|
||||
* Flash address for the bootloader status structure.
|
||||
* This address must be aligned to a flash page. Each time a new application
|
||||
* is detected by the bootloader (BootloaderState::newApp),
|
||||
* the full page is erased, and the updated struct is written to the address
|
||||
*/
|
||||
const uint32_t BOOTLOADER_STATUS_STRUCT_ADDR = 0x0802FF80; // The last flash page
|
||||
|
||||
/**
|
||||
* Bootloader state enumeration. This state needs to be set to "newApp"
|
||||
* by the application after an update, and to "stableApp" after the
|
||||
* first successful boot
|
||||
*/
|
||||
enum BootloaderState {
|
||||
NO_STATE = 0, ///< State not properly initialized
|
||||
NEW_APP, ///< Set By App after download of the binary
|
||||
ATTEMPT_NEW_APP, ///< Set by Bootloader when first booting the new binary
|
||||
STABLE_APP, ///< Set by App after sucessful boot of the new app
|
||||
};
|
||||
|
||||
/**
|
||||
* Bootloader status struct. This struct's status field should be updated
|
||||
* in flash by the app after first boot (stableApp) or after an update of the
|
||||
* other firmware binary (newApp)
|
||||
*/
|
||||
struct BootloaderStatus {
|
||||
char bootloader_name[BOOTLADER_NAME_LENGTH];
|
||||
uint32_t bootloader_version;
|
||||
uint32_t status; ///< Update this field and write to flash in your app!
|
||||
uint32_t live_app_select;
|
||||
uint32_t retry_count;
|
||||
};
|
||||
|
||||
/**
|
||||
* Write the bootloader status to the flash address 'BOOTLOADER_STATUS_STRUCT_ADDR'.
|
||||
*
|
||||
* @param status: The struct containing the bootloader status information.
|
||||
*/
|
||||
void write_status_reg(BootloaderStatus &status);
|
||||
|
||||
/**
|
||||
* Unlock the FLASH control register access and the program memory access.
|
||||
*/
|
||||
void flash_unlock(void);
|
||||
|
||||
/**
|
||||
* Program a word at a specified address in the flash memory.
|
||||
* (1) Perform the data write (32-bit word) at the desired address
|
||||
* (2) Wait until the BSY bit is reset in the FLASH_SR register
|
||||
* (3) Check the EOP flag in the FLASH_SR register
|
||||
* (4) clear it by software by writing it at 1
|
||||
*
|
||||
* @param address The flash address to write to.
|
||||
* @param data The data to write to the flash.
|
||||
*/
|
||||
void flash_program(uint32_t address, uint32_t data);
|
||||
|
||||
|
||||
/**
|
||||
* Called from main. This implements the bootloader status update from the application side.
|
||||
*/
|
||||
void check_bootloader(void);
|
||||
|
||||
#endif /* BOOTLOADER_ENABLED */
|
||||
|
||||
#endif /* BL_SUPPORT_H */
|
||||
Reference in New Issue
Block a user