Change MSC boot mode to use persistence layer and unify with bootloader
Replaced the existing `PERSISTENT_OBJECT_BOOTLOADER_REQUEST` that was bootloader specific, with `PERSISTENT_OBJECT_BOOTMODE_REQUEST` that can be shared by any required boot mode based on it's contents. Currently supports bootloader and MSC, but is extensible for additional future needs. The previous hardcoded memory address usage for MSC boot was removed.
This commit is contained in:
parent
5c5520ecf4
commit
065ce24d4d
|
@ -29,7 +29,7 @@ typedef enum {
|
||||||
PERSISTENT_OBJECT_MAGIC = 0,
|
PERSISTENT_OBJECT_MAGIC = 0,
|
||||||
PERSISTENT_OBJECT_HSE_VALUE,
|
PERSISTENT_OBJECT_HSE_VALUE,
|
||||||
PERSISTENT_OBJECT_OVERCLOCK_LEVEL,
|
PERSISTENT_OBJECT_OVERCLOCK_LEVEL,
|
||||||
PERSISTENT_OBJECT_BOOTLOADER_REQUEST,
|
PERSISTENT_OBJECT_BOOTMODE_REQUEST,
|
||||||
PERSISTENT_OBJECT_RTC_HIGH, // high 32 bits of rtcTime_t
|
PERSISTENT_OBJECT_RTC_HIGH, // high 32 bits of rtcTime_t
|
||||||
PERSISTENT_OBJECT_RTC_LOW, // low 32 bits of rtcTime_t
|
PERSISTENT_OBJECT_RTC_LOW, // low 32 bits of rtcTime_t
|
||||||
PERSISTENT_OBJECT_COUNT,
|
PERSISTENT_OBJECT_COUNT,
|
||||||
|
|
|
@ -53,6 +53,7 @@ bool isMPUSoftReset(void);
|
||||||
void cycleCounterInit(void);
|
void cycleCounterInit(void);
|
||||||
|
|
||||||
#define BOOTLOADER_REQUEST_COOKIE 0xDEADBEEF
|
#define BOOTLOADER_REQUEST_COOKIE 0xDEADBEEF
|
||||||
|
#define MSC_REQUEST_COOKIE 0xDDDD1010
|
||||||
|
|
||||||
void enableGPIOPowerUsageAndNoiseReductions(void);
|
void enableGPIOPowerUsageAndNoiseReductions(void);
|
||||||
// current crystal frequency - 8 or 12MHz
|
// current crystal frequency - 8 or 12MHz
|
||||||
|
|
|
@ -41,7 +41,7 @@ void systemReset(void)
|
||||||
|
|
||||||
void systemResetToBootloader(void)
|
void systemResetToBootloader(void)
|
||||||
{
|
{
|
||||||
persistentObjectWrite(PERSISTENT_OBJECT_BOOTLOADER_REQUEST, BOOTLOADER_REQUEST_COOKIE);
|
persistentObjectWrite(PERSISTENT_OBJECT_BOOTMODE_REQUEST, BOOTLOADER_REQUEST_COOKIE);
|
||||||
|
|
||||||
__disable_irq();
|
__disable_irq();
|
||||||
NVIC_SystemReset();
|
NVIC_SystemReset();
|
||||||
|
@ -56,13 +56,12 @@ typedef struct isrVector_s {
|
||||||
|
|
||||||
void checkForBootLoaderRequest(void)
|
void checkForBootLoaderRequest(void)
|
||||||
{
|
{
|
||||||
uint32_t bootloaderRequest = persistentObjectRead(PERSISTENT_OBJECT_BOOTLOADER_REQUEST);
|
uint32_t bootloaderRequest = persistentObjectRead(PERSISTENT_OBJECT_BOOTMODE_REQUEST);
|
||||||
|
|
||||||
persistentObjectWrite(PERSISTENT_OBJECT_BOOTLOADER_REQUEST, 0);
|
|
||||||
|
|
||||||
if (bootloaderRequest != BOOTLOADER_REQUEST_COOKIE) {
|
if (bootloaderRequest != BOOTLOADER_REQUEST_COOKIE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
persistentObjectWrite(PERSISTENT_OBJECT_BOOTMODE_REQUEST, 0);
|
||||||
|
|
||||||
extern isrVector_t system_isr_vector_table_base;
|
extern isrVector_t system_isr_vector_table_base;
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ void systemReset(void)
|
||||||
|
|
||||||
void systemResetToBootloader(void)
|
void systemResetToBootloader(void)
|
||||||
{
|
{
|
||||||
persistentObjectWrite(PERSISTENT_OBJECT_BOOTLOADER_REQUEST, BOOTLOADER_REQUEST_COOKIE);
|
persistentObjectWrite(PERSISTENT_OBJECT_BOOTMODE_REQUEST, BOOTLOADER_REQUEST_COOKIE);
|
||||||
__disable_irq();
|
__disable_irq();
|
||||||
NVIC_SystemReset();
|
NVIC_SystemReset();
|
||||||
}
|
}
|
||||||
|
@ -191,13 +191,12 @@ void(*bootJump)(void);
|
||||||
|
|
||||||
void checkForBootLoaderRequest(void)
|
void checkForBootLoaderRequest(void)
|
||||||
{
|
{
|
||||||
uint32_t bootloaderRequest = persistentObjectRead(PERSISTENT_OBJECT_BOOTLOADER_REQUEST);
|
uint32_t bootloaderRequest = persistentObjectRead(PERSISTENT_OBJECT_BOOTMODE_REQUEST);
|
||||||
|
|
||||||
persistentObjectWrite(PERSISTENT_OBJECT_BOOTLOADER_REQUEST, 0);
|
|
||||||
|
|
||||||
if (bootloaderRequest != BOOTLOADER_REQUEST_COOKIE) {
|
if (bootloaderRequest != BOOTLOADER_REQUEST_COOKIE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
persistentObjectWrite(PERSISTENT_OBJECT_BOOTMODE_REQUEST, 0);
|
||||||
|
|
||||||
void (*SysMemBootJump)(void);
|
void (*SysMemBootJump)(void);
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,6 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define MSC_MAGIC 0xDDDD1010
|
|
||||||
|
|
||||||
void mscInit(void);
|
void mscInit(void);
|
||||||
bool mscCheckBoot(void);
|
bool mscCheckBoot(void);
|
||||||
uint8_t mscStart(void);
|
uint8_t mscStart(void);
|
||||||
|
|
|
@ -40,7 +40,9 @@
|
||||||
#include "drivers/io.h"
|
#include "drivers/io.h"
|
||||||
#include "drivers/light_led.h"
|
#include "drivers/light_led.h"
|
||||||
#include "drivers/nvic.h"
|
#include "drivers/nvic.h"
|
||||||
|
#include "drivers/persistent.h"
|
||||||
#include "drivers/sdmmc_sdio.h"
|
#include "drivers/sdmmc_sdio.h"
|
||||||
|
#include "drivers/system.h"
|
||||||
#include "drivers/time.h"
|
#include "drivers/time.h"
|
||||||
#include "drivers/usb_msc.h"
|
#include "drivers/usb_msc.h"
|
||||||
|
|
||||||
|
@ -123,10 +125,11 @@ uint8_t mscStart(void)
|
||||||
|
|
||||||
bool mscCheckBoot(void)
|
bool mscCheckBoot(void)
|
||||||
{
|
{
|
||||||
if (*((uint32_t *)0x2001FFF0) == MSC_MAGIC) {
|
const uint32_t bootModeRequest = persistentObjectRead(PERSISTENT_OBJECT_BOOTMODE_REQUEST);
|
||||||
return true;
|
return bootModeRequest == MSC_REQUEST_COOKIE;
|
||||||
}
|
// Note that we can't clear the persisent object after checking here. This is because
|
||||||
return false;
|
// this function is called multiple times during initialization. So we clear on a reset
|
||||||
|
// out of MSC mode.
|
||||||
}
|
}
|
||||||
|
|
||||||
bool mscCheckButton(void)
|
bool mscCheckButton(void)
|
||||||
|
@ -159,7 +162,7 @@ void mscWaitForButton(void)
|
||||||
|
|
||||||
void systemResetToMsc(int timezoneOffsetMinutes)
|
void systemResetToMsc(int timezoneOffsetMinutes)
|
||||||
{
|
{
|
||||||
*((uint32_t *)0x2001FFF0) = MSC_MAGIC;
|
persistentObjectWrite(PERSISTENT_OBJECT_BOOTMODE_REQUEST, MSC_REQUEST_COOKIE);
|
||||||
|
|
||||||
__disable_irq();
|
__disable_irq();
|
||||||
|
|
||||||
|
@ -174,8 +177,7 @@ void systemResetToMsc(int timezoneOffsetMinutes)
|
||||||
|
|
||||||
void systemResetFromMsc(void)
|
void systemResetFromMsc(void)
|
||||||
{
|
{
|
||||||
*((uint32_t *)0x2001FFF0) = 0xFFFFFFFF;
|
persistentObjectWrite(PERSISTENT_OBJECT_BOOTMODE_REQUEST, 0);
|
||||||
delay(1);
|
|
||||||
__disable_irq();
|
__disable_irq();
|
||||||
NVIC_SystemReset();
|
NVIC_SystemReset();
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,9 @@
|
||||||
#include "drivers/io.h"
|
#include "drivers/io.h"
|
||||||
#include "drivers/light_led.h"
|
#include "drivers/light_led.h"
|
||||||
#include "drivers/nvic.h"
|
#include "drivers/nvic.h"
|
||||||
|
#include "drivers/persistent.h"
|
||||||
#include "drivers/serial_usb_vcp.h"
|
#include "drivers/serial_usb_vcp.h"
|
||||||
|
#include "drivers/system.h"
|
||||||
#include "drivers/time.h"
|
#include "drivers/time.h"
|
||||||
#include "drivers/usb_msc.h"
|
#include "drivers/usb_msc.h"
|
||||||
|
|
||||||
|
@ -128,10 +130,11 @@ uint8_t mscStart(void)
|
||||||
|
|
||||||
bool mscCheckBoot(void)
|
bool mscCheckBoot(void)
|
||||||
{
|
{
|
||||||
if (*((__IO uint32_t *)BKPSRAM_BASE + 16) == MSC_MAGIC) {
|
const uint32_t bootModeRequest = persistentObjectRead(PERSISTENT_OBJECT_BOOTMODE_REQUEST);
|
||||||
return true;
|
return bootModeRequest == MSC_REQUEST_COOKIE;
|
||||||
}
|
// Note that we can't clear the persisent object after checking here. This is because
|
||||||
return false;
|
// this function is called multiple times during initialization. So we clear on a reset
|
||||||
|
// out of MSC mode.
|
||||||
}
|
}
|
||||||
|
|
||||||
bool mscCheckButton(void)
|
bool mscCheckButton(void)
|
||||||
|
@ -164,7 +167,7 @@ void mscWaitForButton(void)
|
||||||
|
|
||||||
void systemResetToMsc(int timezoneOffsetMinutes)
|
void systemResetToMsc(int timezoneOffsetMinutes)
|
||||||
{
|
{
|
||||||
*((__IO uint32_t*) BKPSRAM_BASE + 16) = MSC_MAGIC;
|
persistentObjectWrite(PERSISTENT_OBJECT_BOOTMODE_REQUEST, MSC_REQUEST_COOKIE);
|
||||||
|
|
||||||
__disable_irq();
|
__disable_irq();
|
||||||
|
|
||||||
|
@ -179,8 +182,7 @@ void systemResetToMsc(int timezoneOffsetMinutes)
|
||||||
|
|
||||||
void systemResetFromMsc(void)
|
void systemResetFromMsc(void)
|
||||||
{
|
{
|
||||||
*((__IO uint32_t*) BKPSRAM_BASE + 16) = 0xFFFFFFFF;
|
persistentObjectWrite(PERSISTENT_OBJECT_BOOTMODE_REQUEST, 0);
|
||||||
delay(1);
|
|
||||||
__disable_irq();
|
__disable_irq();
|
||||||
NVIC_SystemReset();
|
NVIC_SystemReset();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue