Initial Release
This commit is contained in:
8
src/rp2_common/pico_bootrom/CMakeLists.txt
Normal file
8
src/rp2_common/pico_bootrom/CMakeLists.txt
Normal file
@ -0,0 +1,8 @@
|
||||
add_library(pico_bootrom INTERFACE)
|
||||
|
||||
target_sources(pico_bootrom INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}/bootrom.c
|
||||
)
|
||||
|
||||
target_include_directories(pico_bootrom INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
|
||||
target_link_libraries(pico_bootrom INTERFACE pico_base_headers)
|
38
src/rp2_common/pico_bootrom/bootrom.c
Normal file
38
src/rp2_common/pico_bootrom/bootrom.c
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include "pico/bootrom.h"
|
||||
|
||||
/// \tag::table_lookup[]
|
||||
|
||||
// Bootrom function: rom_table_lookup
|
||||
// Returns the 32 bit pointer into the ROM if found or NULL otherwise.
|
||||
typedef void *(*rom_table_lookup_fn)(uint16_t *table, uint32_t code);
|
||||
|
||||
// Convert a 16 bit pointer stored at the given rom address into a 32 bit pointer
|
||||
#define rom_hword_as_ptr(rom_address) (void *)(uintptr_t)(*(uint16_t *)rom_address)
|
||||
|
||||
void *rom_func_lookup(uint32_t code) {
|
||||
rom_table_lookup_fn rom_table_lookup = (rom_table_lookup_fn) rom_hword_as_ptr(0x18);
|
||||
uint16_t *func_table = (uint16_t *) rom_hword_as_ptr(0x14);
|
||||
return rom_table_lookup(func_table, code);
|
||||
}
|
||||
|
||||
void *rom_data_lookup(uint32_t code) {
|
||||
rom_table_lookup_fn rom_table_lookup = (rom_table_lookup_fn) rom_hword_as_ptr(0x18);
|
||||
uint16_t *data_table = (uint16_t *) rom_hword_as_ptr(0x16);
|
||||
return rom_table_lookup(data_table, code);
|
||||
}
|
||||
/// \end::table_lookup[]
|
||||
|
||||
bool rom_funcs_lookup(uint32_t *table, unsigned int count) {
|
||||
bool ok = true;
|
||||
for (unsigned int i = 0; i < count; i++) {
|
||||
table[i] = (uintptr_t) rom_func_lookup(table[i]);
|
||||
if (!table[i]) ok = false;
|
||||
}
|
||||
return ok;
|
||||
}
|
85
src/rp2_common/pico_bootrom/include/pico/bootrom.h
Normal file
85
src/rp2_common/pico_bootrom/include/pico/bootrom.h
Normal file
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#ifndef _PLATFORM_BOOTROM_H
|
||||
#define _PLATFORM_BOOTROM_H
|
||||
|
||||
#include "pico.h"
|
||||
|
||||
/** \file bootrom.h
|
||||
* \defgroup pico_bootrom pico_bootrom
|
||||
* Access to functions and data in the RP2040 bootrom
|
||||
*/
|
||||
|
||||
|
||||
/*! \brief Return a bootrom lookup code based on two ASCII characters
|
||||
* \ingroup pico_bootrom
|
||||
*
|
||||
* These codes are uses to lookup data or function addresses in the bootrom
|
||||
*
|
||||
* \param c1 the first character
|
||||
* \param c2 the second character
|
||||
* \return the 'code' to use in rom_func_lookup() or rom_data_lookup()
|
||||
*/
|
||||
static inline uint32_t rom_table_code(char c1, char c2) {
|
||||
return (c2 << 8u) | c1;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Lookup a bootrom function by code
|
||||
* \ingroup pico_bootrom
|
||||
* \param code the code
|
||||
* \return a pointer to the function, or NULL if the code does not match any bootrom function
|
||||
*/
|
||||
void *rom_func_lookup(uint32_t code);
|
||||
|
||||
/*!
|
||||
* \brief Lookup a bootrom address by code
|
||||
* \ingroup pico_bootrom
|
||||
* \param code the code
|
||||
* \return a pointer to the data, or NULL if the code does not match any bootrom function
|
||||
*/
|
||||
void *rom_data_lookup(uint32_t code);
|
||||
|
||||
/*!
|
||||
* \brief Helper function to lookup the addresses of multiple bootrom functions
|
||||
* \ingroup pico_bootrom
|
||||
*
|
||||
* This method looks up the 'codes' in the table, and convert each table entry to the looked up
|
||||
* function pointer, if there is a function for that code in the bootrom.
|
||||
*
|
||||
* \param table an IN/OUT array, elements are codes on input, function pointers on success.
|
||||
* \param count the number of elements in the table
|
||||
* \return true if all the codes were found, and converted to function pointers, false otherwise
|
||||
*/
|
||||
bool rom_funcs_lookup(uint32_t *table, unsigned int count);
|
||||
|
||||
typedef void __attribute__((noreturn)) (*reset_usb_boot_fn)(uint32_t, uint32_t);
|
||||
|
||||
/*!
|
||||
* \brief Reboot the device into BOOTSEL mode
|
||||
* \ingroup pico_bootrom
|
||||
*
|
||||
* This function reboots the device into the BOOTSEL mode ('usb boot").
|
||||
*
|
||||
* Facilities are provided to enable an "activity light" via GPIO attached LED for the USB Mass Storage Device,
|
||||
* and to limit the USB interfaces exposed.
|
||||
*
|
||||
* \param usb_activity_gpio_pin_mask 0 No pins are used as per a cold boot. Otherwise a single bit set indicating which
|
||||
* GPIO pin should be set to output and raised whenever there is mass storage activity
|
||||
* from the host.
|
||||
* \param disable_interface_mask value to control exposed interfaces
|
||||
* - 0 To enable both interfaces (as per a cold boot)
|
||||
* - 1 To disable the USB Mass Storage Interface
|
||||
* - 2 To disable the USB PICOBOOT Interface
|
||||
*/
|
||||
static inline void __attribute__((noreturn)) reset_usb_boot(uint32_t usb_activity_gpio_pin_mask,
|
||||
uint32_t disable_interface_mask) {
|
||||
reset_usb_boot_fn func = (reset_usb_boot_fn) rom_func_lookup(rom_table_code('U', 'B'));
|
||||
func(usb_activity_gpio_pin_mask, disable_interface_mask);
|
||||
}
|
||||
|
||||
#endif
|
50
src/rp2_common/pico_bootrom/include/pico/bootrom/sf_table.h
Normal file
50
src/rp2_common/pico_bootrom/include/pico/bootrom/sf_table.h
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#ifndef _PICO_SF_TABLE_H
|
||||
#define _PICO_SF_TABLE_H
|
||||
|
||||
// NOTE THESE FUNCTION IMPLEMENTATIONS MATCH THE BEHAVIOR DESCRIBED IN THE BOOTROM SECTION OF THE RP2040 DATASHEET
|
||||
|
||||
#define SF_TABLE_FADD 0x00
|
||||
#define SF_TABLE_FSUB 0x04
|
||||
#define SF_TABLE_FMUL 0x08
|
||||
#define SF_TABLE_FDIV 0x0c
|
||||
#define SF_TABLE_FCMP_FAST 0x10
|
||||
#define SF_TABLE_FCMP_FAST_FLAGS 0x14
|
||||
#define SF_TABLE_FSQRT 0x18
|
||||
#define SF_TABLE_FLOAT2INT 0x1c
|
||||
#define SF_TABLE_FLOAT2FIX 0x20
|
||||
#define SF_TABLE_FLOAT2UINT 0x24
|
||||
#define SF_TABLE_FLOAT2UFIX 0x28
|
||||
#define SF_TABLE_INT2FLOAT 0x2c
|
||||
#define SF_TABLE_FIX2FLOAT 0x30
|
||||
#define SF_TABLE_UINT2FLOAT 0x34
|
||||
#define SF_TABLE_UFIX2FLOAT 0x38
|
||||
#define SF_TABLE_FCOS 0x3c
|
||||
#define SF_TABLE_FSIN 0x40
|
||||
#define SF_TABLE_FTAN 0x44
|
||||
#define SF_TABLE_V3_FSINCOS 0x48
|
||||
#define SF_TABLE_FEXP 0x4c
|
||||
#define SF_TABLE_FLN 0x50
|
||||
|
||||
#define SF_TABLE_V1_SIZE 0x54
|
||||
|
||||
#define SF_TABLE_FCMP_BASIC 0x54
|
||||
#define SF_TABLE_FATAN2 0x58
|
||||
#define SF_TABLE_INT642FLOAT 0x5c
|
||||
#define SF_TABLE_FIX642FLOAT 0x60
|
||||
#define SF_TABLE_UINT642FLOAT 0x64
|
||||
#define SF_TABLE_UFIX642FLOAT 0x68
|
||||
#define SF_TABLE_FLOAT2INT64 0x6c
|
||||
#define SF_TABLE_FLOAT2FIX64 0x70
|
||||
#define SF_TABLE_FLOAT2UINT64 0x74
|
||||
#define SF_TABLE_FLOAT2UFIX64 0x78
|
||||
#define SF_TABLE_FLOAT2DOUBLE 0x7c
|
||||
|
||||
#define SF_TABLE_V2_SIZE 0x80
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user