This commit is contained in:
Mysteo91
2023-07-04 12:42:37 +03:00
parent 5e6d9a3165
commit 5c26bb8dff
29 changed files with 171 additions and 9647 deletions

View File

@@ -31,7 +31,7 @@
****************************************************************************************/
#include "boot.h" /* bootloader generic header */
#include "stm32g0xx.h" /* STM32 CPU and HAL header */
#include "flash.h"
/****************************************************************************************
* Macro definitions
@@ -40,8 +40,7 @@
#define FLASH_INVALID_SECTOR (0xff)
/** \brief Value for an invalid flash address. */
#define FLASH_INVALID_ADDRESS (0xffffffff)
/** \brief Standard size of a flash block for writing. */
#define FLASH_WRITE_BLOCK_SIZE (512)
/** \brief Total numbers of sectors in array flashLayout[]. */
#define FLASH_TOTAL_SECTORS (sizeof(flashLayout)/sizeof(flashLayout[0]))
/** \brief End address of the bootloader programmable flash. */
@@ -92,11 +91,6 @@ typedef struct
* the flash block and the data that should be programmed into the flash
* block. The .base_addr must be a multiple of FLASH_WRITE_BLOCK_SIZE.
*/
typedef struct
{
blt_addr base_addr;
blt_int8u data[FLASH_WRITE_BLOCK_SIZE];
} tFlashBlockInfo;
/****************************************************************************************
@@ -153,21 +147,66 @@ static blt_int32u FlashGetPage(blt_addr address);
static const tFlashSector flashLayout[] =
{
/* { 0x08000000, 0x00800, 0},
{ 0x08000800, 0x00800, 1},
{ 0x08001000, 0x00800, 2},
{ 0x08001800, 0x00800, 3},*/
{ 0x08002000, 0x00800, 4}, /* flash sector 4 - reserved for bootloader */
{ 0x08002800, 0x00800, 5}, /* flash sector 5 - 2kb */
{ 0x08003000, 0x00800, 6}, /* flash sector 6 - 2kb */
{ 0x08003800, 0x00800, 7}, /* flash sector 7 - 2kb */
{ 0x08004000, 0x00800, 8}, /* flash sector 8 - 2kb */
{ 0x08004800, 0x00800, 9}, /* flash sector 9 - 2kb */
{ 0x08005000, 0x00800, 10}, /* flash sector 10 - 2kb */
{ 0x08005800, 0x00800, 11}, /* flash sector 11 - 2kb */
/* flash sector 7 - 2kb */
{ 0x08002000, 0x00800, 4}, /* flash sector 4 - reserved for bootloader */
{ 0x08002800, 0x00800, 5}, /* flash sector 5 - 2kb */
{ 0x08003000, 0x00800, 6}, /* flash sector 6 - 2kb */
{ 0x08003800, 0x00800, 7}, /* flash sector 7 - 2kb */
{ 0x08004000, 0x00800, 8}, /* flash sector 8 - 2kb */
{ 0x08004800, 0x00800, 9}, /* flash sector 9 - 2kb */
{ 0x08005000, 0x00800, 10}, /* flash sector 10 - 2kb */
{ 0x08005800, 0x00800, 11}, /* flash sector 11 - 2kb */
{ 0x08006000, 0x00800, 12}, /* flash sector 12 - 2kb */
{ 0x08006800, 0x00800, 13}, /* flash sector 13 - 2kb */
{ 0x08007000, 0x00800, 14}, /* flash sector 14 - 2kb */
{ 0x08007800, 0x00800, 15}, /* flash sector 15 - 2kb */
{ 0x08008000, 0x00800, 16}, /* flash sector 9 - 2kb */
{ 0x08008800, 0x00800, 17}, /* flash sector 10 - 2kb */
{ 0x08009000, 0x00800, 18}, /* flash sector 11 - 2kb */
{ 0x08009800, 0x00800, 19}, /* flash sector 12 - 2kb */
{ 0x0800A000, 0x00800, 20}, /* flash sector 13 - 2kb */
{ 0x0800A800, 0x00800, 21}, /* flash sector 14 - 2kb */
{ 0x0800B000, 0x00800, 22}, /* flash sector 15 - 2kb */
{ 0x0800B800, 0x00800, 23}, /* flash sector 8 - 2kb */
{ 0x0800C000, 0x00800, 24}, /* flash sector 9 - 2kb */
{ 0x0800C800, 0x00800, 25}, /* flash sector 10 - 2kb */
{ 0x0800D000, 0x00800, 26}, /* flash sector 11 - 2kb */
{ 0x0800D800, 0x00800, 27}, /* flash sector 12 - 2kb */
{ 0x0800E000, 0x00800, 28}, /* flash sector 13 - 2kb */
{ 0x0800E800, 0x00800, 29}, /* flash sector 14 - 2kb */
{ 0x0800F000, 0x00800, 30}, /* flash sector 15 - 2kb */
{ 0x0800F800, 0x00800, 31}, /* flash sector 8 - 2kb */
{ 0x08010000, 0x00800, 32}, /* flash sector 9 - 2kb */
{ 0x08010800, 0x00800, 33}, /* flash sector 10 - 2kb */
{ 0x08011000, 0x00800, 34}, /* flash sector 11 - 2kb */
{ 0x08011800, 0x00800, 35}, /* flash sector 12 - 2kb */
{ 0x08012000, 0x00800, 36}, /* flash sector 13 - 2kb */
{ 0x08012800, 0x00800, 37}, /* flash sector 14 - 2kb */
{ 0x08013000, 0x00800, 38}, /* flash sector 15 - 2kb */
{ 0x08013800, 0x08000, 39}, /* flash sector 17 - 32kb */
{ 0x08014000, 0x08000, 40}, /* flash sector 18 - 32kb */
{ 0x08014800, 0x08000, 41}, /* flash sector 17 - 32kb */
{ 0x08015000, 0x08000, 42}, /* flash sector 18 - 32kb */
{ 0x08015800, 0x08000, 43}, /* flash sector 17 - 32kb */
{ 0x08016000, 0x08000, 44}, /* flash sector 18 - 32kb */
{ 0x08016800, 0x08000, 45}, /* flash sector 17 - 32kb */
{ 0x08017000, 0x08000, 46}, /* flash sector 18 - 32kb */
{ 0x08017800, 0x00800, 47}, /* flash sector 4 - reserved for bootloader */
{ 0x08018000, 0x00800, 48}, /* flash sector 5 - 2kb */
{ 0x08018800, 0x00800, 49}, /* flash sector 6 - 2kb */
{ 0x08019000, 0x00800, 50}, /* flash sector 7 - 2kb */
{ 0x08019800, 0x00800, 51}, /* flash sector 8 - 2kb */
{ 0x0801A000, 0x00800, 52}, /* flash sector 9 - 2kb */
{ 0x0801A800, 0x00800, 53}, /* flash sector 10 - 2kb */
{ 0x0801B000, 0x00800, 54}, /* flash sector 11 - 2kb */
{ 0x0801B800, 0x00800, 55}, /* flash sector 12 - 2kb */
{ 0x0801C000, 0x00800, 56}, /* flash sector 13 - 2kb */
{ 0x0801C800, 0x00800, 57}, /* flash sector 14 - 2kb */
{ 0x0801D000, 0x00800, 58}, /* flash sector 15 - 2kb */
{ 0x0801D800, 0x00800, 59}, /* flash sector 4 - reserved for bootloader */
{ 0x0801E000, 0x00800, 60}, /* flash sector 5 - 2kb */
{ 0x0801E800, 0x00800, 61}, /* flash sector 6 - 2kb */
{ 0x0801F000, 0x00800, 62}, /* flash sector 7 - 2kb */
{ 0x0801F800, 0x00800, 63} /* flash sector 7 - 2kb */
};
#else
@@ -222,6 +261,16 @@ void FlashInit(void)
bootBlockInfo.base_addr = FLASH_INVALID_ADDRESS;
} /*** end of FlashInit ***/
/*** end of FlashInit ***/
void FlashGetBlockInfoData(blt_int8u *data, blt_int32u *len)
{
*len = *(uint32_t*)&bootBlockInfo.data[BOOT_FLASH_VECTOR_TABLE_CS_OFFSET];
for (uint16_t i = 0; i < FLASH_WRITE_BLOCK_SIZE; i++)
{
*data++ = bootBlockInfo.data[i];
}
}
/************************************************************************************//**
** \brief Reinitializes the flash driver.

View File

@@ -39,7 +39,15 @@ blt_bool FlashWriteChecksum(void);
blt_bool FlashVerifyChecksum(void);
blt_bool FlashDone(void);
blt_addr FlashGetUserProgBaseAddress(void);
void FlashGetBlockInfoData(blt_int8u *data, blt_int32u *len);
/** \brief Standard size of a flash block for writing. */
#define FLASH_WRITE_BLOCK_SIZE (512)
#define FLASH_USER_PROG_SIZE (FLASH_SIZE - (FLASH_USER_PROG_ADDRESS - 0x08000000))
typedef struct
{
blt_addr base_addr;
blt_int8u data[FLASH_WRITE_BLOCK_SIZE];
} tFlashBlockInfo;
#endif /* FLASH_H */
/*********************************** end of flash.h ************************************/

View File

@@ -214,6 +214,10 @@ blt_addr NvmGetUserProgBaseAddress(void)
****************************************************************************************/
blt_bool NvmDone(void)
{
if (FlashDone() != BLT_TRUE)
{
return BLT_FALSE;
}
#if (BOOT_NVM_HOOKS_ENABLE > 0)
/* give the application's NVM driver a chance to finish up */
if (NvmDoneHook() == BLT_FALSE)
@@ -238,7 +242,7 @@ blt_bool NvmDone(void)
#endif
/* finish up internal driver operations */
return FlashDone();
return BLT_TRUE;
} /*** end of NvmDone ***/