@web-font-path: "roboto-debian.css";
Loading...
Searching...
No Matches
bootrom.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef _PICO_BOOTROM_H
8#define _PICO_BOOTROM_H
9
10#include "pico.h"
11#include "pico/bootrom_constants.h"
12
20#ifndef __ASSEMBLER__
21#include <string.h>
22#include "pico/bootrom/lock.h"
23#include "pico/flash.h"
24// ROM FUNCTION SIGNATURES
25
26#if PICO_RP2040
27typedef uint32_t (*rom_popcount32_fn)(uint32_t);
28typedef uint32_t (*rom_reverse32_fn)(uint32_t);
29typedef uint32_t (*rom_clz32_fn)(uint32_t);
30typedef uint32_t (*rom_ctz32_fn)(uint32_t);
31typedef uint8_t *(*rom_memset_fn)(uint8_t *, uint8_t, uint32_t);
32typedef uint32_t *(*rom_memset4_fn)(uint32_t *, uint8_t, uint32_t);
33typedef uint32_t *(*rom_memcpy_fn)(uint8_t *, const uint8_t *, uint32_t);
34typedef uint32_t *(*rom_memcpy44_fn)(uint32_t *, const uint32_t *, uint32_t);
35#endif
36typedef void __attribute__((noreturn)) (*rom_reset_usb_boot_fn)(uint32_t, uint32_t);
37typedef int (*rom_reboot_fn)(uint32_t flags, uint32_t delay_ms, uint32_t p0, uint32_t p1);
38typedef rom_reset_usb_boot_fn reset_usb_boot_fn; // kept for backwards compatibility
39typedef void (*rom_connect_internal_flash_fn)(void);
40typedef void (*rom_flash_exit_xip_fn)(void);
41typedef void (*rom_flash_range_erase_fn)(uint32_t, size_t, uint32_t, uint8_t);
42typedef void (*rom_flash_range_program_fn)(uint32_t, const uint8_t*, size_t);
43typedef void (*rom_flash_flush_cache_fn)(void);
44typedef void (*rom_flash_enter_cmd_xip_fn)(void);
45#if !PICO_RP2040
46typedef void (*rom_bootrom_state_reset_fn)(uint32_t flags);
47typedef void (*rom_flash_reset_address_trans_fn)(void);
48typedef void (*rom_flash_select_xip_read_mode_fn)(bootrom_xip_mode_t mode, uint8_t clkdiv);
49typedef int (*rom_get_sys_info_fn)(uint32_t *out_buffer, uint32_t out_buffer_word_size, uint32_t flags);
50typedef int (*rom_get_partition_table_info_fn)(uint32_t *out_buffer, uint32_t out_buffer_word_size, uint32_t partition_and_flags);
51typedef int (*rom_explicit_buy_fn)(uint8_t *buffer, uint32_t buffer_size);
52typedef void* (*rom_validate_ns_buffer_fn)(const void *addr, uint32_t size, uint32_t write, uint32_t *ok);
57typedef intptr_t (*rom_set_rom_callback_fn)(uint callback_num, bootrom_api_callback_generic_t funcptr);
58typedef int (*rom_chain_image_fn)(uint8_t *workarea_base, uint32_t workarea_size, uint32_t window_base, uint32_t window_size);
59typedef int (*rom_load_partition_table_fn)(uint8_t *workarea_base, uint32_t workarea_size, bool force_reload);
60typedef int (*rom_pick_ab_partition_fn)(uint8_t *workarea_base, uint32_t workarea_size, uint partition_a_num, uint32_t flash_update_boot_window_base);
61typedef int (*rom_get_b_partition_fn)(uint pi_a);
62typedef int (*rom_get_uf2_target_partition_fn)(uint8_t *workarea_base, uint32_t workarea_size, uint32_t family_id, resident_partition_t *partition_out);
63typedef int (*rom_func_otp_access_fn)(uint8_t *buf, uint32_t buf_len, otp_cmd_t cmd);
64// Apply the address translation currently specified in QMI_ATRANSx ("rolling window" hardware
65// translation). Need to take care using this on the boot path, as the QMI may not yet have been
66// set up, but this should be suitable for translating system bus addresses into flash storage
67// addresses in user callbacks. Returns all-ones for an invalid address, which is also an invalid
68// flash storage address, so invalidity is propagated.
69typedef intptr_t (*rom_flash_runtime_to_storage_addr_fn)(uintptr_t flash_runtime_addr);
70
71// Perform the specified erase/program/read operation, translating addresses according to
72// QMI_ATRANSx if necessary, and checking flash permissions based on the resident partition table
73// and the specified effective security level. `addr` may be either a flash runtime address or a
74// flash storage address, depending on the ASPACE given in `flags`.
75//
76// NOTE: This function does not validate the buffer for NS access. This must be validated before
77// calling if the caller is reachable from a Secure Gateway.
78typedef int (*rom_flash_op_fn)(cflash_flags_t flags, uintptr_t addr, uint32_t size_bytes, uint8_t *buf);
79
80#ifndef __riscv
81typedef int (*rom_set_ns_api_permission_fn)(uint ns_api_num, bool allowed);
94typedef int (*rom_func_secure_call)(uintptr_t a0, ...);
95#endif
96
97#ifdef __riscv
98typedef struct {
99 uint32_t *base;
100 uint32_t size;
101} bootrom_stack_t;
102// passed in, and out.
103typedef int (*rom_set_bootrom_stack_fn)(bootrom_stack_t *stack);
104#endif
105#endif
106
107#ifdef __cplusplus
108extern "C" {
109#endif
110
120static inline uint32_t rom_table_code(uint8_t c1, uint8_t c2) {
121 return ROM_TABLE_CODE((uint32_t) c1, (uint32_t) c2);
122}
123
130void *rom_func_lookup(uint32_t code);
131
138void *rom_data_lookup(uint32_t code);
139
151bool rom_funcs_lookup(uint32_t *table, unsigned int count);
152
153// Bootrom function: rom_table_lookup
154// Returns the 32 bit pointer into the ROM if found or NULL otherwise.
155#if PICO_RP2040
156typedef void *(*rom_table_lookup_fn)(uint16_t *table, uint32_t code);
157#else
158typedef void *(*rom_table_lookup_fn)(uint32_t code, uint32_t mask);
159#endif
160
161#if PICO_C_COMPILER_IS_GNU && (__GNUC__ >= 12)
162// Convert a 16 bit pointer stored at the given rom address into a 32 bit pointer
163__force_inline static void *rom_hword_as_ptr(uint16_t rom_address) {
164#pragma GCC diagnostic push
165#pragma GCC diagnostic ignored "-Warray-bounds"
166 return (void *)(uintptr_t)*(uint16_t *)(uintptr_t)rom_address;
167#pragma GCC diagnostic pop
168}
169#else
170// Convert a 16 bit pointer stored at the given rom address into a 32 bit pointer
171#define rom_hword_as_ptr(rom_address) (void *)(uintptr_t)(*(uint16_t *)(uintptr_t)(rom_address))
172#endif
173
174#ifdef __riscv
175static __force_inline bool rom_size_is_64k(void) {
176#ifdef RASPBERRYPI_AMETHYST_FPGA
177 return *(uint16_t*)0x14 >= 0x8000;
178#else
179 return false;
180#endif
181}
182#endif
183
190#pragma GCC diagnostic push
191// diagnostic: GCC thinks near-zero value is a null pointer member access, but it's not
192#pragma GCC diagnostic ignored "-Warray-bounds"
193static __force_inline void *rom_func_lookup_inline(uint32_t code) {
194#if PICO_RP2040
195 rom_table_lookup_fn rom_table_lookup = (rom_table_lookup_fn) rom_hword_as_ptr(BOOTROM_TABLE_LOOKUP_OFFSET);
196 uint16_t *func_table = (uint16_t *) rom_hword_as_ptr(BOOTROM_FUNC_TABLE_OFFSET);
197 return rom_table_lookup(func_table, code);
198#else
199#ifdef __riscv
200 uint32_t rom_offset_adjust = rom_size_is_64k() ? 32 * 1024 : 0;
201 // on RISC-V the code (a jmp) is actually embedded in the table
202 rom_table_lookup_fn rom_table_lookup = (rom_table_lookup_fn) (uintptr_t)*(uint16_t*)(BOOTROM_TABLE_LOOKUP_ENTRY_OFFSET + rom_offset_adjust);
203 return rom_table_lookup(code, RT_FLAG_FUNC_RISCV);
204#else
205 // on ARM the function pointer is stored in the table, so we dereference it
206 // via lookup() rather than lookup_entry()
207 rom_table_lookup_fn rom_table_lookup = (rom_table_lookup_fn) (uintptr_t)*(uint16_t*)(BOOTROM_TABLE_LOOKUP_OFFSET);
208 if (pico_processor_state_is_nonsecure()) {
209 return rom_table_lookup(code, RT_FLAG_FUNC_ARM_NONSEC);
210 } else {
211 return rom_table_lookup(code, RT_FLAG_FUNC_ARM_SEC);
212 }
213#endif
214#endif
215}
216#pragma GCC diagnostic pop
217
224#pragma GCC diagnostic push
225// diagnostic: GCC thinks near-zero value is a null pointer member access, but it's not
226#pragma GCC diagnostic ignored "-Warray-bounds"
227static __force_inline void *rom_data_lookup_inline(uint32_t code) {
228#if PICO_RP2040
229 rom_table_lookup_fn rom_table_lookup = (rom_table_lookup_fn) rom_hword_as_ptr(BOOTROM_TABLE_LOOKUP_OFFSET);
230 uint16_t *data_table = (uint16_t *) rom_hword_as_ptr(BOOTROM_DATA_TABLE_OFFSET);
231 return rom_table_lookup(data_table, code);
232#else
233#ifdef __riscv
234 uint32_t rom_offset_adjust = rom_size_is_64k() ? 32 * 1024 : 0;
235 rom_table_lookup_fn rom_table_lookup = (rom_table_lookup_fn) (uintptr_t)*(uint16_t*)(BOOTROM_TABLE_LOOKUP_OFFSET + rom_offset_adjust);
236#else
237 rom_table_lookup_fn rom_table_lookup = (rom_table_lookup_fn) (uintptr_t)*(uint16_t*)(BOOTROM_TABLE_LOOKUP_OFFSET);
238#endif
239 return rom_table_lookup(code, RT_FLAG_DATA);
240#endif
241}
242#pragma GCC diagnostic pop
243
261void __attribute__((noreturn)) rom_reset_usb_boot(uint32_t usb_activity_gpio_pin_mask, uint32_t disable_interface_mask);
262static inline void __attribute__((noreturn)) reset_usb_boot(uint32_t usb_activity_gpio_pin_mask, uint32_t disable_interface_mask) {
263 rom_reset_usb_boot(usb_activity_gpio_pin_mask, disable_interface_mask);
264}
265
283void __attribute__((noreturn)) rom_reset_usb_boot_extra(int usb_activity_gpio_pin, uint32_t disable_interface_mask, bool usb_activity_gpio_pin_active_low);
284
297static inline void rom_connect_internal_flash(void) {
298 rom_connect_internal_flash_fn func = (rom_connect_internal_flash_fn) rom_func_lookup_inline(ROM_FUNC_CONNECT_INTERNAL_FLASH);
299 func();
300}
301
328static inline void rom_flash_exit_xip(void) {
329 rom_flash_exit_xip_fn func = (rom_flash_exit_xip_fn) rom_func_lookup_inline(ROM_FUNC_FLASH_EXIT_XIP);
330 func();
331}
332
364static inline void rom_flash_range_erase(uint32_t addr, size_t count, uint32_t block_size, uint8_t block_cmd) {
365 rom_flash_range_erase_fn func = (rom_flash_range_erase_fn) rom_func_lookup_inline(ROM_FUNC_FLASH_RANGE_ERASE);
366 func(addr, count, block_size, block_cmd);
367}
368
389static inline void rom_flash_range_program(uint32_t addr, const uint8_t *data, size_t count) {
390 rom_flash_range_program_fn func = (rom_flash_range_program_fn) rom_func_lookup_inline(ROM_FUNC_FLASH_RANGE_PROGRAM);
391 func(addr, data, count);
392}
393
411static inline void rom_flash_flush_cache(void) {
412 rom_flash_flush_cache_fn func = (rom_flash_flush_cache_fn) rom_func_lookup_inline(ROM_FUNC_FLASH_FLUSH_CACHE);
413 func();
414}
415
427static inline void rom_flash_enter_cmd_xip(void) {
428 rom_flash_enter_cmd_xip_fn func = (rom_flash_enter_cmd_xip_fn) rom_func_lookup_inline(ROM_FUNC_FLASH_ENTER_CMD_XIP);
429 func();
430}
431
432#if !PICO_RP2040 || PICO_COMBINED_DOCS
433#ifdef __riscv
450static inline int rom_set_bootrom_stack(bootrom_stack_t *stack) {
451 rom_set_bootrom_stack_fn func = (rom_set_bootrom_stack_fn) rom_func_lookup_inline(ROM_FUNC_SET_BOOTROM_STACK);
452 return func(stack);
453}
454#endif
455
502static inline int rom_reboot(uint32_t flags, uint32_t delay_ms, uint32_t p0, uint32_t p1) {
503 rom_reboot_fn func = (rom_reboot_fn) rom_func_lookup_inline(ROM_FUNC_REBOOT);
504 return func(flags, delay_ms, p0, p1);
505}
506
507bool rom_get_boot_random(uint32_t out[4]);
508
533static inline void rom_bootrom_state_reset(uint32_t flags) {
534 rom_bootrom_state_reset_fn func = (rom_bootrom_state_reset_fn) rom_func_lookup_inline(ROM_FUNC_BOOTROM_STATE_RESET);
535 return func(flags);
536}
537
546static inline void rom_flash_reset_address_trans(void) {
547 rom_flash_reset_address_trans_fn func = (rom_flash_reset_address_trans_fn) rom_func_lookup_inline(ROM_FUNC_FLASH_RESET_ADDRESS_TRANS);
548 func();
549}
550
561static inline void rom_flash_select_xip_read_mode(bootrom_xip_mode_t mode, uint8_t clkdiv) {
562 rom_flash_select_xip_read_mode_fn func = (rom_flash_select_xip_read_mode_fn) rom_func_lookup_inline(ROM_FUNC_FLASH_SELECT_XIP_READ_MODE);
563 func(mode, clkdiv);
564}
565
566typedef struct {
567 cflash_flags_t flags;
568 uintptr_t addr;
569 uint32_t size_bytes;
570 uint8_t *buf;
571 int *res;
572} rom_helper_flash_op_params_t;
573
574static inline void rom_helper_flash_op(void *param) {
575 const rom_helper_flash_op_params_t *op = (const rom_helper_flash_op_params_t *)param;
576 rom_flash_op_fn func = (rom_flash_op_fn) rom_func_lookup_inline(ROM_FUNC_FLASH_OP);
577 *(op->res) = func(op->flags, op->addr, op->size_bytes, op->buf);
578}
579
619static inline int rom_flash_op(cflash_flags_t flags, uintptr_t addr, uint32_t size_bytes, uint8_t *buf) {
620 if (!bootrom_try_acquire_lock(BOOTROM_LOCK_FLASH_OP))
621 return BOOTROM_ERROR_LOCK_REQUIRED;
622 int rc = 0;
623 rom_helper_flash_op_params_t params = {
624 .flags = flags,
625 .addr = addr,
626 .size_bytes = size_bytes,
627 .buf = buf,
628 .res = &rc
629 };
630 int flash_rc = flash_safe_execute(rom_helper_flash_op, &params, UINT32_MAX);
631 bootrom_release_lock(BOOTROM_LOCK_FLASH_OP);
632 if (flash_rc != PICO_OK) {
633 return flash_rc;
634 } else {
635 return rc;
636 }
637}
638
663static inline int rom_func_otp_access(uint8_t *buf, uint32_t buf_len, otp_cmd_t cmd) {
664 rom_func_otp_access_fn func = (rom_func_otp_access_fn) rom_func_lookup_inline(ROM_FUNC_OTP_ACCESS);
665 if (!bootrom_try_acquire_lock(BOOTROM_LOCK_OTP))
666 return BOOTROM_ERROR_LOCK_REQUIRED;
667 int rc = func(buf, buf_len, cmd);
668 bootrom_release_lock(BOOTROM_LOCK_OTP);
669 return rc;
670}
671
700static inline int rom_get_partition_table_info(uint32_t *out_buffer, uint32_t out_buffer_word_size, uint32_t partition_and_flags) {
701 rom_get_partition_table_info_fn func = (rom_get_partition_table_info_fn) rom_func_lookup_inline(ROM_FUNC_GET_PARTITION_TABLE_INFO);
702 if (!bootrom_try_acquire_lock(BOOTROM_LOCK_SHA_256))
703 return BOOTROM_ERROR_LOCK_REQUIRED;
704 int rc = func(out_buffer, out_buffer_word_size, partition_and_flags);
705 bootrom_release_lock(BOOTROM_LOCK_SHA_256);
706 return rc;
707}
708
709// todo SECURE only
725static inline int rom_load_partition_table(uint8_t *workarea_base, uint32_t workarea_size, bool force_reload) {
726 rom_load_partition_table_fn func = (rom_load_partition_table_fn) rom_func_lookup_inline(ROM_FUNC_LOAD_PARTITION_TABLE);
727 if (!bootrom_try_acquire_lock(BOOTROM_LOCK_SHA_256))
728 return BOOTROM_ERROR_LOCK_REQUIRED;
729 int rc = func(workarea_base, workarea_size, force_reload);
730 bootrom_release_lock(BOOTROM_LOCK_SHA_256);
731 return rc;
732}
733
734// todo SECURE only
757static inline int rom_pick_ab_partition(uint8_t *workarea_base, uint32_t workarea_size, uint partition_a_num, uint32_t flash_update_boot_window_base) {
758 rom_pick_ab_partition_fn func = (rom_pick_ab_partition_fn) rom_func_lookup_inline(ROM_FUNC_PICK_AB_PARTITION);
759 if (!bootrom_try_acquire_lock(BOOTROM_LOCK_SHA_256))
760 return BOOTROM_ERROR_LOCK_REQUIRED;
761 int rc = func(workarea_base, workarea_size, partition_a_num, flash_update_boot_window_base);
762 bootrom_release_lock(BOOTROM_LOCK_SHA_256);
763 return rc;
764}
765
775static inline int rom_get_b_partition(uint pi_a) {
776 rom_get_b_partition_fn func = (rom_get_b_partition_fn) rom_func_lookup_inline(ROM_FUNC_GET_B_PARTITION);
777 return func(pi_a);
778}
779
780// todo SECURE only
801static inline int rom_get_uf2_target_partition(uint8_t *workarea_base, uint32_t workarea_size, uint32_t family_id, resident_partition_t *partition_out) {
802 rom_get_uf2_target_partition_fn func = (rom_get_uf2_target_partition_fn) rom_func_lookup_inline(ROM_FUNC_GET_UF2_TARGET_PARTITION);
803 if (!bootrom_try_acquire_lock(BOOTROM_LOCK_SHA_256))
804 return BOOTROM_ERROR_LOCK_REQUIRED;
805 int rc = func(workarea_base, workarea_size, family_id, partition_out);
806 bootrom_release_lock(BOOTROM_LOCK_SHA_256);
807 return rc;
808}
809
822static inline intptr_t rom_flash_runtime_to_storage_addr(uintptr_t flash_runtime_addr) {
823 rom_flash_runtime_to_storage_addr_fn func = (rom_flash_runtime_to_storage_addr_fn) rom_func_lookup_inline(ROM_FUNC_FLASH_RUNTIME_TO_STORAGE_ADDR);
824 return func(flash_runtime_addr);
825}
826
827// todo SECURE only
855static inline int rom_chain_image(uint8_t *workarea_base, uint32_t workarea_size, uint32_t region_base, uint32_t region_size) {
856 rom_chain_image_fn func = (rom_chain_image_fn) rom_func_lookup_inline(ROM_FUNC_CHAIN_IMAGE);
857 bootrom_release_lock(BOOTROM_LOCK_ENABLE);
858 uint32_t interrupt_flags = save_and_disable_interrupts();
859 int rc = func(workarea_base, workarea_size, region_base, region_size);
860 restore_interrupts_from_disabled(interrupt_flags);
861 bootrom_acquire_lock_blocking(BOOTROM_LOCK_ENABLE);
862 return rc;
863}
864
865typedef struct {
866 uint8_t *buffer;
867 uint32_t buffer_size;
868 int *res;
869} rom_helper_explicit_buy_params_t;
870
871static inline void rom_helper_explicit_buy(void *param) {
872 const rom_helper_explicit_buy_params_t *op = (const rom_helper_explicit_buy_params_t *)param;
873 rom_explicit_buy_fn func = (rom_explicit_buy_fn) rom_func_lookup_inline(ROM_FUNC_EXPLICIT_BUY);
874 *(op->res) = func(op->buffer, op->buffer_size);
875}
876
877// todo SECURE only
903static inline int rom_explicit_buy(uint8_t *buffer, uint32_t buffer_size) {
904 int rc = 0;
905 rom_helper_explicit_buy_params_t params = {
906 .buffer = buffer,
907 .buffer_size = buffer_size,
908 .res = &rc
909 };
910 int flash_rc = flash_safe_execute(rom_helper_explicit_buy, &params, UINT32_MAX);
911 if (flash_rc != PICO_OK) {
912 return flash_rc;
913 } else {
914 return rc;
915 }
916}
917
918#ifndef __riscv
933static inline int rom_set_ns_api_permission(uint ns_api_num, bool allowed) {
934 rom_set_ns_api_permission_fn func = (rom_set_ns_api_permission_fn) rom_func_lookup_inline(ROM_FUNC_SET_NS_API_PERMISSION);
935 return func(ns_api_num, allowed);
936}
937#endif
938
939// todo SECURE only
959static inline void* rom_validate_ns_buffer(const void *addr, uint32_t size, uint32_t write, uint32_t *ok) {
960 rom_validate_ns_buffer_fn func = (rom_validate_ns_buffer_fn) rom_func_lookup_inline(ROM_FUNC_VALIDATE_NS_BUFFER);
961 return func(addr, size, write, ok);
962}
963
978static inline intptr_t rom_set_rom_callback(uint callback_num, bootrom_api_callback_generic_t funcptr) {
979 rom_set_rom_callback_fn func = (rom_set_rom_callback_fn) rom_func_lookup_inline(ROM_FUNC_SET_ROM_CALLBACK);
980 return func(callback_num, funcptr);
981}
982
983#define BOOT_TYPE_NORMAL 0
984#define BOOT_TYPE_BOOTSEL 2
985#define BOOT_TYPE_RAM_IMAGE 3
986#define BOOT_TYPE_FLASH_UPDATE 4
987
988// values 8-15 are secure only
989#define BOOT_TYPE_PC_SP 0xd
990
991// ORed in if a bootloader chained into the image
992#define BOOT_TYPE_CHAINED_FLAG 0x80
993
1026static inline int rom_get_sys_info(uint32_t *out_buffer, uint32_t out_buffer_word_size, uint32_t flags) {
1027 rom_get_sys_info_fn func = (rom_get_sys_info_fn)rom_func_lookup_inline(ROM_FUNC_GET_SYS_INFO);
1028 return func(out_buffer, out_buffer_word_size, flags);
1029}
1030
1031typedef struct {
1032 union {
1033 struct __packed {
1034 int8_t diagnostic_partition_index; // used BOOT_PARTITION constants
1035 uint8_t boot_type;
1036 int8_t partition;
1037 uint8_t tbyb_and_update_info;
1038 };
1039 uint32_t boot_word;
1040 };
1041 uint32_t boot_diagnostic;
1042 uint32_t reboot_params[2];
1043} boot_info_t;
1044
1045static inline int rom_get_boot_info(boot_info_t *info) {
1046 uint32_t result[5];
1047 int words_returned = rom_get_sys_info(result, 5, SYS_INFO_BOOT_INFO);
1048 if (words_returned == (sizeof(result)/sizeof(result[0])) && result[0] == SYS_INFO_BOOT_INFO) {
1049 memcpy(info, &result[1], sizeof(boot_info_t));
1050 return true;
1051 } else {
1052 return false;
1053 }
1054}
1055
1056static inline int rom_get_last_boot_type_with_chained_flag(void) {
1057 uint32_t result[5];
1058 int words_returned = rom_get_sys_info(result, 5, SYS_INFO_BOOT_INFO);
1059 if (words_returned == count_of(result) && result[0] == SYS_INFO_BOOT_INFO) {
1060 // todo use struct
1061 return (int)((result[1] & 0xff00u) >> 8);
1062 } else {
1064 }
1065}
1066
1067// BOOT_TYPE_NORMAL 0x0
1068// BOOT_TYPE_BOOTSEL 0x2
1069// BOOT_TYPE_RAM_IMAGE 0x3
1070// BOOT_TYPE_FLASH_UPDATE 0x4
1071// BOOT_TYPE_PC_SP 0xd
1072static inline int rom_get_last_boot_type(void) {
1073 int rc = rom_get_last_boot_type_with_chained_flag();
1074 if (rc >= 0) rc &= ~BOOT_TYPE_CHAINED_FLAG;
1075 return rc;
1076}
1077
1092int rom_add_flash_runtime_partition(uint32_t start_offset, uint32_t size, uint32_t permissions);
1093
1094#endif
1095
1096#ifdef __cplusplus
1097}
1098#endif
1099
1100#endif // !__ASSEMBLER__
1101#endif
static __force_inline uint32_t save_and_disable_interrupts(void)
Disable interrupts on the calling core, returning the previous interrupt state.
Definition sync.h:237
static __force_inline void restore_interrupts_from_disabled(uint32_t status)
Restore interrupts to a specified state on the calling core with restricted transitions.
Definition sync.h:280
@ PICO_OK
No error; the operation succeeded.
Definition error.h:23
@ PICO_ERROR_INVALID_DATA
A data structure failed to validate.
Definition error.h:40
static void rom_flash_flush_cache(void)
Flush the XIP cache.
Definition bootrom.h:411
void rom_reset_usb_boot(uint32_t usb_activity_gpio_pin_mask, uint32_t disable_interface_mask)
Reboot the device into BOOTSEL mode.
Definition bootrom.c:32
static uint32_t rom_table_code(uint8_t c1, uint8_t c2)
Return a bootrom lookup code based on two ASCII characters.
Definition bootrom.h:120
bool rom_funcs_lookup(uint32_t *table, unsigned int count)
Helper function to lookup the addresses of multiple bootrom functions.
Definition bootrom.c:22
static void rom_connect_internal_flash(void)
Connect the SSI/QMI to the QSPI pads.
Definition bootrom.h:297
static void rom_flash_exit_xip(void)
Return the QSPI device from its XIP state to a serial command state.
Definition bootrom.h:328
static void rom_flash_enter_cmd_xip(void)
Configure the SSI/QMI with a standard command.
Definition bootrom.h:427
#define ROM_TABLE_CODE(c1, c2)
Return a bootrom lookup code based on two ASCII characters.
Definition bootrom_constants.h:155
static void rom_flash_range_program(uint32_t addr, const uint8_t *data, size_t count)
Program bytes in flash.
Definition bootrom.h:389
static __force_inline void * rom_func_lookup_inline(uint32_t code)
Lookup a bootrom function by code. This method is forcibly inlined into the caller for FLASH/RAM sens...
Definition bootrom.h:193
void * rom_func_lookup(uint32_t code)
Lookup a bootrom function by its code.
Definition bootrom.c:13
static __force_inline void * rom_data_lookup_inline(uint32_t code)
Lookup a bootrom data address by its code. This method is forcibly inlined into the caller for FLASH/...
Definition bootrom.h:227
static void rom_flash_range_erase(uint32_t addr, size_t count, uint32_t block_size, uint8_t block_cmd)
Erase bytes in flash.
Definition bootrom.h:364
void * rom_data_lookup(uint32_t code)
Lookup a bootrom data address by its code.
Definition bootrom.c:17
void rom_reset_usb_boot_extra(int usb_activity_gpio_pin, uint32_t disable_interface_mask, bool usb_activity_gpio_pin_active_low)
Reboot the device into BOOTSEL mode.
Definition bootrom.c:50
int flash_safe_execute(void(*func)(void *), void *param, uint32_t enter_exit_timeout_ms)
Execute a function with IRQs disabled and with the other core also not executing/reading flash.
Definition flash.c:75
#define __force_inline
Attribute to force inlining of a function regardless of optimization level.
Definition compiler.h:125
#define count_of(a)
Macro to determine the number of elements in an array.
Definition compiler.h:132
Definition bootrom_constants.h:307
Definition bootrom_constants.h:275
Definition bootrom_constants.h:269