Skip to content

Commit

Permalink
RP2040: reduce boot delay by enabling cache during bootloader.
Browse files Browse the repository at this point in the history
  • Loading branch information
PetteriAimonen committed Sep 19, 2022
1 parent d44fba3 commit 1033cb0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 11 additions & 0 deletions lib/ZuluSCSI_platform_RP2040/ZuluSCSI_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <hardware/gpio.h>
#include <hardware/uart.h>
#include <hardware/spi.h>
#include <hardware/structs/xip_ctrl.h>
#include <platform/mbed_error.h>

extern "C" {
Expand Down Expand Up @@ -297,7 +298,17 @@ bool azplatform_rewrite_flash_page(uint32_t offset, uint8_t buffer[AZPLATFORM_FL
assert(offset % AZPLATFORM_FLASH_PAGE_SIZE == 0);
assert(offset >= AZPLATFORM_BOOTLOADER_SIZE);

// Avoid any mbed timer interrupts triggering during the flashing.
__disable_irq();

// For some reason any code executed after flashing crashes
// unless we disable the XIP cache.
// Not sure why this happens, as flash_range_program() is flushing
// the cache correctly.
// The cache is now enabled from bootloader start until it starts
// flashing, and again after reset to main firmware.
xip_ctrl_hw->ctrl = 0;

flash_range_erase(offset, AZPLATFORM_FLASH_PAGE_SIZE);
flash_range_program(offset, buffer, AZPLATFORM_FLASH_PAGE_SIZE);
__enable_irq();
Expand Down
4 changes: 1 addition & 3 deletions lib/ZuluSCSI_platform_RP2040/rp2040_btldr.ld
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
/* The bootloader is linked to begin at 0x12000100.
* First 256 bytes are reserved for RP2040 second stage bootloader,
* which comes as part of the main firmware.elf and is never overwritten.
* The bootloader also runs without XIP cache because that seemed to cause
* problems when writing flash.
*/
FLASH(rx) : ORIGIN = 0x12000100, LENGTH = 128k-256
FLASH(rx) : ORIGIN = 0x10000100, LENGTH = 128k-256
RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 240k /* Leave space for pico-debug */
SCRATCH_X(rwx) : ORIGIN = 0x20040000, LENGTH = 4k
SCRATCH_Y(rwx) : ORIGIN = 0x20041000, LENGTH = 4k
Expand Down

0 comments on commit 1033cb0

Please sign in to comment.