Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

big-flash: changes to app code. #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 27 additions & 18 deletions appcode/rboot-bigflash.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ extern void Cache_Read_Enable(uint32, uint32, uint32);
uint8 rBoot_mmap_1 = 0xff;
uint8 rBoot_mmap_2 = 0xff;

#ifdef BOOT_RTC_ENABLED
typedef union
{
rboot_rtc_data data;
uint32_t overlay[4];
} rboot_rtc_data_overlay_t;
#endif

// this function must remain in iram
void IRAM_ATTR Cache_Read_Enable_New(void) {

Expand All @@ -36,24 +44,25 @@ void IRAM_ATTR Cache_Read_Enable_New(void) {
SPIRead(BOOT_CONFIG_SECTOR * SECTOR_SIZE, &conf, sizeof(rboot_config));

#ifdef BOOT_RTC_ENABLED
// rtc support here isn't written ideally, we don't read the whole structure and
// we don't check the checksum. However this code is only run on first boot, so
// the rtc data should have just been set and the user app won't have had chance
// to corrupt it or suspend or anything else that might upset it. And if
// it were bad what should we do anyway? We can't just ignore bad data here, we
// need it. But the main reason is that this code must be in iram, which is in
// very short supply, doing this "properly" increases the size about 3x

// used only to calculate offset into structure, should get optimized out
rboot_rtc_data rtc;
uint8 off = (uint8*)&rtc.last_rom - (uint8*)&rtc;
// get the four bytes containing the one of interest
volatile uint32 *rtcd = (uint32*)(0x60001100 + (RBOOT_RTC_ADDR*4) + (off & ~3));
val = *rtcd;
// extract the one of interest
val = ((uint8*)&val)[off & 3];
// get address of rom
val = conf.roms[val];
{
const rboot_rtc_data_overlay_t *rtc_in_iospace;
rboot_rtc_data_overlay_t rtc_in_dram;
unsigned int ix;

rtc_in_iospace = (const rboot_rtc_data_overlay_t *)(0x60001100 + (RBOOT_RTC_ADDR * 4));

for(ix = 0; ix < sizeof(rtc_in_dram.overlay) / sizeof(rtc_in_dram.overlay[0]); ix++)
rtc_in_dram.overlay[ix] = rtc_in_iospace->overlay[ix];

// Don't check for next_mode == RBOOT_TEMP_ROM and neither use next_slot
// because they already have been reset by rboot at this point.
// Trust rboot to have selected the correct rom slot instead.

if(rtc_in_dram.data.magic == RBOOT_RTC_MAGIC)
val = conf.roms[rtc_in_dram.data.last_rom];
else
val = conf.roms[conf.current_rom];
}
#else
val = conf.roms[conf.current_rom];
#endif
Expand Down