rp2040: Add _ramfunc macro to internal.h and use in bootrom.c and chipid.c

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2021-07-04 11:40:45 -04:00
parent ba958468b7
commit f2b4d353d8
3 changed files with 13 additions and 9 deletions

View File

@ -7,15 +7,15 @@
#include <stdint.h> // uint16_t, uint32_t, uintptr_t #include <stdint.h> // uint16_t, uint32_t, uintptr_t
#include <string.h> // memcpy #include <string.h> // memcpy
#include "compiler.h" // noinline, __section #include "compiler.h" // noinline, __section
#include "internal.h" // _ramfunc
#define ROM_TABLE_CODE(c1, c2) ((c1) | ((c2) << 8)) #define ROM_TABLE_CODE(c1, c2) ((c1) | ((c2) << 8))
// All functions in here need to be RAM-resident, as we may need // All functions in here need to be RAM-resident, as we may need
// to (especially for the flash functions) call while the XIP layer // to (especially for the flash functions) call while the XIP layer
// is unavailable. // is unavailable.
#define noinline_ram noinline __section(".ramfunc.read_chip_id")
static void * noinline_ram static void * _ramfunc
rom_func_lookup(uint32_t code) rom_func_lookup(uint32_t code)
{ {
// Table and lookup function are provided by the BOOTROM // Table and lookup function are provided by the BOOTROM
@ -25,7 +25,7 @@ rom_func_lookup(uint32_t code)
return fn(table, code); return fn(table, code);
} }
void noinline_ram void _ramfunc
reset_to_usb_boot(uint32_t gpio_activity_pin_mask reset_to_usb_boot(uint32_t gpio_activity_pin_mask
, uint32_t disable_interface_mask) , uint32_t disable_interface_mask)
{ {
@ -33,21 +33,21 @@ reset_to_usb_boot(uint32_t gpio_activity_pin_mask
fn(gpio_activity_pin_mask, disable_interface_mask); fn(gpio_activity_pin_mask, disable_interface_mask);
} }
void noinline_ram void _ramfunc
connect_internal_flash(void) connect_internal_flash(void)
{ {
void (*fn)(void) = rom_func_lookup(ROM_TABLE_CODE('I', 'F')); void (*fn)(void) = rom_func_lookup(ROM_TABLE_CODE('I', 'F'));
fn(); fn();
} }
void noinline_ram void _ramfunc
flash_exit_xip(void) flash_exit_xip(void)
{ {
void (*fn)(void) = rom_func_lookup(ROM_TABLE_CODE('E', 'X')); void (*fn)(void) = rom_func_lookup(ROM_TABLE_CODE('E', 'X'));
fn(); fn();
} }
void noinline_ram void _ramfunc
flash_flush_cache(void) flash_flush_cache(void)
{ {
void (*fn)(void) = rom_func_lookup(ROM_TABLE_CODE('F', 'C')); void (*fn)(void) = rom_func_lookup(ROM_TABLE_CODE('F', 'C'));

View File

@ -30,7 +30,7 @@ usbserial_get_serialid(void)
// Functions for reading out the flash chip ID. Adapted from the official // Functions for reading out the flash chip ID. Adapted from the official
// Pi SDK. // Pi SDK.
static void noinline __section(".ramfunc.read_chip_id") static void _ramfunc
flash_cs_force(int high) flash_cs_force(int high)
{ {
uint32_t field_val = high ? uint32_t field_val = high ?
@ -60,7 +60,7 @@ flash_enter_xip_prepare(void)
barrier(); barrier();
} }
static void noinline __section(".ramfunc.read_chip_id") static void _ramfunc
flash_enter_xip_perform(void) flash_enter_xip_perform(void)
{ {
((void (*)(void))boot2_copy+1)(); ((void (*)(void))boot2_copy+1)();
@ -71,7 +71,7 @@ flash_enter_xip_perform(void)
#define FLASH_RUID_DATA_BYTES 8 #define FLASH_RUID_DATA_BYTES 8
#define FLASH_RUID_TOTAL_BYTES (1+FLASH_RUID_DUMMY_BYTES+FLASH_RUID_DATA_BYTES) #define FLASH_RUID_TOTAL_BYTES (1+FLASH_RUID_DUMMY_BYTES+FLASH_RUID_DATA_BYTES)
static void noinline __section(".ramfunc.read_chip_id") static void _ramfunc
read_unique_id(uint8_t *out) read_unique_id(uint8_t *out)
{ {
uint8_t txbuf[FLASH_RUID_TOTAL_BYTES] = {0}; uint8_t txbuf[FLASH_RUID_TOTAL_BYTES] = {0};

View File

@ -14,4 +14,8 @@ void connect_internal_flash(void);
void flash_exit_xip(void); void flash_exit_xip(void);
void flash_flush_cache(void); void flash_flush_cache(void);
// Force a function to run from ram
#define UNIQSEC __FILE__ "." __stringify(__LINE__)
#define _ramfunc noinline __section(".ramfunc." UNIQSEC)
#endif // internal.h #endif // internal.h