Remove unused bootloader support

This commit is contained in:
Martin Jäger
2020-07-23 12:41:32 +02:00
parent 705abbed6b
commit 8a28d8bc22
5 changed files with 0 additions and 325 deletions
-4
View File
@@ -127,10 +127,6 @@ To add the files to the firmware build, create an own CMakeLists.txt in the fold
If you think the customization could be relevant for others, please consider sending a pull request. Integrating features into the upstream charge controller firmware guarantees that the feature stays up-to-date and that it will not accidentally break after changes in the original firmware.
## Bootloader Support (STM32L072 only)
The custom linker script file STM32L072XZ.ld.link_script.ld needs to be updated before generating the application firmware binary. For each application, the flash start address and the maximum code size need to be updated in this file. Currently, the locations 0x08001000 and 0x08018000 are used for applications 1 & 2 respectively.
## API documentation
The documentation auto-generated by Doxygen can be found [here](https://libre.solar/charge-controller-firmware/).
-92
View File
@@ -1,92 +0,0 @@
MEMORY
{
FLASH (rx) : ORIGIN = 0x08018000, LENGTH = 94k
RAM (rwx) : ORIGIN = 0x200000C0, LENGTH = 20K - 0xC0
}
ENTRY(Reset_Handler)
SECTIONS
{
.text :
{
KEEP(*(.isr_vector))
*(.text*)
KEEP(*(.init))
KEEP(*(.fini))
*crtbegin.o(.ctors)
*crtbegin?.o(.ctors)
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
*(SORT(.ctors.*))
*(.ctors)
*crtbegin.o(.dtors)
*crtbegin?.o(.dtors)
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
*(SORT(.dtors.*))
*(.dtors)
*(.rodata*)
KEEP(*(.eh_frame*))
} > FLASH
.ARM.extab :
{
*(.ARM.extab* .gnu.linkonce.armextab.*)
} > FLASH
__exidx_start = .;
.ARM.exidx :
{
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
} > FLASH
__exidx_end = .;
__etext = .;
_sidata = .;
.data : AT (__etext)
{
__data_start__ = .;
_sdata = .;
*(vtable)
*(.data*)
. = ALIGN(8);
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP(*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
. = ALIGN(8);
PROVIDE_HIDDEN (__init_array_start = .);
KEEP(*(SORT(.init_array.*)))
KEEP(*(.init_array))
PROVIDE_HIDDEN (__init_array_end = .);
. = ALIGN(8);
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP(*(SORT(.fini_array.*)))
KEEP(*(.fini_array))
PROVIDE_HIDDEN (__fini_array_end = .);
KEEP(*(.jcr*))
. = ALIGN(8);
__data_end__ = .;
_edata = .;
} > RAM
.bss :
{
. = ALIGN(8);
__bss_start__ = .;
_sbss = .;
*(.bss*)
*(COMMON)
. = ALIGN(8);
__bss_end__ = .;
_ebss = .;
} > RAM
.heap (COPY):
{
__end__ = .;
end = __end__;
*(.heap*)
__HeapLimit = .;
} > RAM
.stack_dummy (COPY):
{
*(.stack*)
} > RAM
__StackTop = ORIGIN(RAM) + LENGTH(RAM);
_estack = __StackTop;
__StackLimit = __StackTop - SIZEOF(.stack_dummy);
PROVIDE(__stack = __StackTop);
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
}
-7
View File
@@ -76,13 +76,6 @@ board = mppt_2420_hpx
[env:pwm_2420_lus]
board = pwm_2420_lus
# The changed linker setting should also be handled by DTS overlays in the future
[env:pwm_2420_lus_bl]
board = pwm_2420_lus
build_flags = ${env.build_flags}
-D BOOTLOADER_ENABLED
-Wl,-T'"$PROJECT_DIR/boards/STM32L072XZ.ld.link_script.ld"',-v
[env:unit_test]
platform = native
framework =
-138
View File
@@ -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*/
-84
View File
@@ -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 */