@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
19
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
761static 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) {
762 rom_pick_ab_partition_fn func = (rom_pick_ab_partition_fn) rom_func_lookup_inline(ROM_FUNC_PICK_AB_PARTITION);
763 if (!bootrom_try_acquire_lock(BOOTROM_LOCK_SHA_256))
764 return BOOTROM_ERROR_LOCK_REQUIRED;
765 int rc = func(workarea_base, workarea_size, partition_a_num, flash_update_boot_window_base);
766 bootrom_release_lock(BOOTROM_LOCK_SHA_256);
767 return rc;
768}
769
794int rom_pick_ab_partition_during_update(uint32_t *workarea_base, uint32_t workarea_size, uint partition_a_num);
795
805static inline int rom_get_b_partition(uint pi_a) {
806 rom_get_b_partition_fn func = (rom_get_b_partition_fn) rom_func_lookup_inline(ROM_FUNC_GET_B_PARTITION);
807 return func(pi_a);
808}
809
810// todo SECURE only
831static inline int rom_get_uf2_target_partition(uint8_t *workarea_base, uint32_t workarea_size, uint32_t family_id, resident_partition_t *partition_out) {
832 rom_get_uf2_target_partition_fn func = (rom_get_uf2_target_partition_fn) rom_func_lookup_inline(ROM_FUNC_GET_UF2_TARGET_PARTITION);
833 if (!bootrom_try_acquire_lock(BOOTROM_LOCK_SHA_256))
834 return BOOTROM_ERROR_LOCK_REQUIRED;
835 int rc = func(workarea_base, workarea_size, family_id, partition_out);
836 bootrom_release_lock(BOOTROM_LOCK_SHA_256);
837 return rc;
838}
839
852static inline intptr_t rom_flash_runtime_to_storage_addr(uintptr_t flash_runtime_addr) {
853 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);
854 return func(flash_runtime_addr);
855}
856
857// todo SECURE only
885static inline int rom_chain_image(uint8_t *workarea_base, uint32_t workarea_size, uint32_t region_base, uint32_t region_size) {
886 rom_chain_image_fn func = (rom_chain_image_fn) rom_func_lookup_inline(ROM_FUNC_CHAIN_IMAGE);
887 bootrom_release_lock(BOOTROM_LOCK_ENABLE);
888 uint32_t interrupt_flags = save_and_disable_interrupts();
889 int rc = func(workarea_base, workarea_size, region_base, region_size);
890 restore_interrupts_from_disabled(interrupt_flags);
891 bootrom_acquire_lock_blocking(BOOTROM_LOCK_ENABLE);
892 return rc;
893}
894
895typedef struct {
896 uint8_t *buffer;
897 uint32_t buffer_size;
898 int *res;
899} rom_helper_explicit_buy_params_t;
900
901static inline void rom_helper_explicit_buy(void *param) {
902 const rom_helper_explicit_buy_params_t *op = (const rom_helper_explicit_buy_params_t *)param;
903 rom_explicit_buy_fn func = (rom_explicit_buy_fn) rom_func_lookup_inline(ROM_FUNC_EXPLICIT_BUY);
904 *(op->res) = func(op->buffer, op->buffer_size);
905}
906
907// todo SECURE only
933static inline int rom_explicit_buy(uint8_t *buffer, uint32_t buffer_size) {
934 int rc = 0;
935 rom_helper_explicit_buy_params_t params = {
936 .buffer = buffer,
937 .buffer_size = buffer_size,
938 .res = &rc
939 };
940 int flash_rc = flash_safe_execute(rom_helper_explicit_buy, &params, UINT32_MAX);
941 if (flash_rc != PICO_OK) {
942 return flash_rc;
943 } else {
944 return rc;
945 }
946}
947
948#ifndef __riscv
963static inline int rom_set_ns_api_permission(uint ns_api_num, bool allowed) {
964 rom_set_ns_api_permission_fn func = (rom_set_ns_api_permission_fn) rom_func_lookup_inline(ROM_FUNC_SET_NS_API_PERMISSION);
965 return func(ns_api_num, allowed);
966}
967#endif
968
969// todo SECURE only
989static inline void* rom_validate_ns_buffer(const void *addr, uint32_t size, uint32_t write, uint32_t *ok) {
990 rom_validate_ns_buffer_fn func = (rom_validate_ns_buffer_fn) rom_func_lookup_inline(ROM_FUNC_VALIDATE_NS_BUFFER);
991 return func(addr, size, write, ok);
992}
993
1008static inline intptr_t rom_set_rom_callback(uint callback_num, bootrom_api_callback_generic_t funcptr) {
1009 rom_set_rom_callback_fn func = (rom_set_rom_callback_fn) rom_func_lookup_inline(ROM_FUNC_SET_ROM_CALLBACK);
1010 return func(callback_num, funcptr);
1011}
1012
1013#define BOOT_TYPE_NORMAL 0
1014#define BOOT_TYPE_BOOTSEL 2
1015#define BOOT_TYPE_RAM_IMAGE 3
1016#define BOOT_TYPE_FLASH_UPDATE 4
1017
1018// values 8-15 are secure only
1019#define BOOT_TYPE_PC_SP 0xd
1020
1021// ORed in if a bootloader chained into the image
1022#define BOOT_TYPE_CHAINED_FLAG 0x80
1023
1056static inline int rom_get_sys_info(uint32_t *out_buffer, uint32_t out_buffer_word_size, uint32_t flags) {
1057 rom_get_sys_info_fn func = (rom_get_sys_info_fn)rom_func_lookup_inline(ROM_FUNC_GET_SYS_INFO);
1058 return func(out_buffer, out_buffer_word_size, flags);
1059}
1060
1061typedef struct {
1062 union {
1063 struct __packed {
1064 int8_t diagnostic_partition_index; // used BOOT_PARTITION constants
1065 uint8_t boot_type;
1066 int8_t partition;
1067 uint8_t tbyb_and_update_info;
1068 };
1069 uint32_t boot_word;
1070 };
1071 uint32_t boot_diagnostic;
1072 uint32_t reboot_params[2];
1073} boot_info_t;
1074
1075static inline int rom_get_boot_info(boot_info_t *info) {
1076 uint32_t result[5];
1077 int words_returned = rom_get_sys_info(result, 5, SYS_INFO_BOOT_INFO);
1078 if (words_returned == (sizeof(result)/sizeof(result[0])) && result[0] == SYS_INFO_BOOT_INFO) {
1079 memcpy(info, &result[1], sizeof(boot_info_t));
1080 return true;
1081 } else {
1082 return false;
1083 }
1084}
1085
1086static inline int rom_get_last_boot_type_with_chained_flag(void) {
1087 uint32_t result[5];
1088 int words_returned = rom_get_sys_info(result, 5, SYS_INFO_BOOT_INFO);
1089 if (words_returned == count_of(result) && result[0] == SYS_INFO_BOOT_INFO) {
1090 // todo use struct
1091 return (int)((result[1] & 0xff00u) >> 8);
1092 } else {
1094 }
1095}
1096
1097// BOOT_TYPE_NORMAL 0x0
1098// BOOT_TYPE_BOOTSEL 0x2
1099// BOOT_TYPE_RAM_IMAGE 0x3
1100// BOOT_TYPE_FLASH_UPDATE 0x4
1101// BOOT_TYPE_PC_SP 0xd
1102static inline int rom_get_last_boot_type(void) {
1103 int rc = rom_get_last_boot_type_with_chained_flag();
1104 if (rc >= 0) rc &= ~BOOT_TYPE_CHAINED_FLAG;
1105 return rc;
1106}
1107
1122int rom_add_flash_runtime_partition(uint32_t start_offset, uint32_t size, uint32_t permissions);
1123
1124#endif
1125
1126#ifdef __cplusplus
1127}
1128#endif
1129
1130#endif // !__ASSEMBLER__
1131#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:35
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:25
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:16
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:20
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:53
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:128
#define count_of(a)
Macro to determine the number of elements in an array.
Definition compiler.h:135
Definition bootrom_constants.h:269