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:
Bruce Luckcuck 2019-01-12 17:53:24 -05:00
parent 5c5520ecf4
commit 065ce24d4d
7 changed files with 26 additions and 25 deletions

View File

@ -29,7 +29,7 @@ typedef enum {
PERSISTENT_OBJECT_MAGIC = 0,
PERSISTENT_OBJECT_HSE_VALUE,
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_LOW, // low 32 bits of rtcTime_t
PERSISTENT_OBJECT_COUNT,

View File

@ -53,6 +53,7 @@ bool isMPUSoftReset(void);
void cycleCounterInit(void);
#define BOOTLOADER_REQUEST_COOKIE 0xDEADBEEF
#define MSC_REQUEST_COOKIE 0xDDDD1010
void enableGPIOPowerUsageAndNoiseReductions(void);
// current crystal frequency - 8 or 12MHz

View File

@ -41,7 +41,7 @@ void systemReset(void)
void systemResetToBootloader(void)
{
persistentObjectWrite(PERSISTENT_OBJECT_BOOTLOADER_REQUEST, BOOTLOADER_REQUEST_COOKIE);
persistentObjectWrite(PERSISTENT_OBJECT_BOOTMODE_REQUEST, BOOTLOADER_REQUEST_COOKIE);
__disable_irq();
NVIC_SystemReset();
@ -56,13 +56,12 @@ typedef struct isrVector_s {
void checkForBootLoaderRequest(void)
{
uint32_t bootloaderRequest = persistentObjectRead(PERSISTENT_OBJECT_BOOTLOADER_REQUEST);
persistentObjectWrite(PERSISTENT_OBJECT_BOOTLOADER_REQUEST, 0);
uint32_t bootloaderRequest = persistentObjectRead(PERSISTENT_OBJECT_BOOTMODE_REQUEST);
if (bootloaderRequest != BOOTLOADER_REQUEST_COOKIE) {
return;
}
persistentObjectWrite(PERSISTENT_OBJECT_BOOTMODE_REQUEST, 0);
extern isrVector_t system_isr_vector_table_base;

View File

@ -45,7 +45,7 @@ void systemReset(void)
void systemResetToBootloader(void)
{
persistentObjectWrite(PERSISTENT_OBJECT_BOOTLOADER_REQUEST, BOOTLOADER_REQUEST_COOKIE);
persistentObjectWrite(PERSISTENT_OBJECT_BOOTMODE_REQUEST, BOOTLOADER_REQUEST_COOKIE);
__disable_irq();
NVIC_SystemReset();
}
@ -191,13 +191,12 @@ void(*bootJump)(void);
void checkForBootLoaderRequest(void)
{
uint32_t bootloaderRequest = persistentObjectRead(PERSISTENT_OBJECT_BOOTLOADER_REQUEST);
persistentObjectWrite(PERSISTENT_OBJECT_BOOTLOADER_REQUEST, 0);
uint32_t bootloaderRequest = persistentObjectRead(PERSISTENT_OBJECT_BOOTMODE_REQUEST);
if (bootloaderRequest != BOOTLOADER_REQUEST_COOKIE) {
return;
}
persistentObjectWrite(PERSISTENT_OBJECT_BOOTMODE_REQUEST, 0);
void (*SysMemBootJump)(void);

View File

@ -24,8 +24,6 @@
#pragma once
#define MSC_MAGIC 0xDDDD1010
void mscInit(void);
bool mscCheckBoot(void);
uint8_t mscStart(void);

View File

@ -40,7 +40,9 @@
#include "drivers/io.h"
#include "drivers/light_led.h"
#include "drivers/nvic.h"
#include "drivers/persistent.h"
#include "drivers/sdmmc_sdio.h"
#include "drivers/system.h"
#include "drivers/time.h"
#include "drivers/usb_msc.h"
@ -123,10 +125,11 @@ uint8_t mscStart(void)
bool mscCheckBoot(void)
{
if (*((uint32_t *)0x2001FFF0) == MSC_MAGIC) {
return true;
}
return false;
const uint32_t bootModeRequest = persistentObjectRead(PERSISTENT_OBJECT_BOOTMODE_REQUEST);
return bootModeRequest == MSC_REQUEST_COOKIE;
// Note that we can't clear the persisent object after checking here. This is because
// this function is called multiple times during initialization. So we clear on a reset
// out of MSC mode.
}
bool mscCheckButton(void)
@ -159,7 +162,7 @@ void mscWaitForButton(void)
void systemResetToMsc(int timezoneOffsetMinutes)
{
*((uint32_t *)0x2001FFF0) = MSC_MAGIC;
persistentObjectWrite(PERSISTENT_OBJECT_BOOTMODE_REQUEST, MSC_REQUEST_COOKIE);
__disable_irq();
@ -174,8 +177,7 @@ void systemResetToMsc(int timezoneOffsetMinutes)
void systemResetFromMsc(void)
{
*((uint32_t *)0x2001FFF0) = 0xFFFFFFFF;
delay(1);
persistentObjectWrite(PERSISTENT_OBJECT_BOOTMODE_REQUEST, 0);
__disable_irq();
NVIC_SystemReset();
}

View File

@ -39,7 +39,9 @@
#include "drivers/io.h"
#include "drivers/light_led.h"
#include "drivers/nvic.h"
#include "drivers/persistent.h"
#include "drivers/serial_usb_vcp.h"
#include "drivers/system.h"
#include "drivers/time.h"
#include "drivers/usb_msc.h"
@ -128,10 +130,11 @@ uint8_t mscStart(void)
bool mscCheckBoot(void)
{
if (*((__IO uint32_t *)BKPSRAM_BASE + 16) == MSC_MAGIC) {
return true;
}
return false;
const uint32_t bootModeRequest = persistentObjectRead(PERSISTENT_OBJECT_BOOTMODE_REQUEST);
return bootModeRequest == MSC_REQUEST_COOKIE;
// Note that we can't clear the persisent object after checking here. This is because
// this function is called multiple times during initialization. So we clear on a reset
// out of MSC mode.
}
bool mscCheckButton(void)
@ -164,7 +167,7 @@ void mscWaitForButton(void)
void systemResetToMsc(int timezoneOffsetMinutes)
{
*((__IO uint32_t*) BKPSRAM_BASE + 16) = MSC_MAGIC;
persistentObjectWrite(PERSISTENT_OBJECT_BOOTMODE_REQUEST, MSC_REQUEST_COOKIE);
__disable_irq();
@ -179,8 +182,7 @@ void systemResetToMsc(int timezoneOffsetMinutes)
void systemResetFromMsc(void)
{
*((__IO uint32_t*) BKPSRAM_BASE + 16) = 0xFFFFFFFF;
delay(1);
persistentObjectWrite(PERSISTENT_OBJECT_BOOTMODE_REQUEST, 0);
__disable_irq();
NVIC_SystemReset();
}