/* * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. * * SPDX-License-Identifier: BSD-3-Clause *//* ... */#ifndef_PICO_BOOTROM_CONSTANTS_H#define_PICO_BOOTROM_CONSTANTS_H#ifndefNO_PICO_PLATFORM#include"pico/platform.h"#endif// ROOT ADDRESSES#defineBOOTROM_MAGIC_OFFSET0x10#defineBOOTROM_FUNC_TABLE_OFFSET0x14#ifPICO_RP2040#defineBOOTROM_DATA_TABLE_OFFSET0x16#endif#ifPICO_RP2040#defineBOOTROM_VTABLE_OFFSET0x00#defineBOOTROM_TABLE_LOOKUP_OFFSET0x18/* ... */#else// todo remove this (or #ifdef it for A1/A2)#defineBOOTROM_IS_A2()((*(volatileuint8_t*)0x13)==2)#defineBOOTROM_WELL_KNOWN_PTR_SIZE(BOOTROM_IS_A2()?2:4)#ifdefined(__riscv)#defineBOOTROM_ENTRY_OFFSET0x7dfc#defineBOOTROM_TABLE_LOOKUP_ENTRY_OFFSET(BOOTROM_ENTRY_OFFSET-BOOTROM_WELL_KNOWN_PTR_SIZE)#defineBOOTROM_TABLE_LOOKUP_OFFSET(BOOTROM_ENTRY_OFFSET-BOOTROM_WELL_KNOWN_PTR_SIZE*2)/* ... */#else#defineBOOTROM_VTABLE_OFFSET0x00#defineBOOTROM_TABLE_LOOKUP_OFFSET(BOOTROM_FUNC_TABLE_OFFSET+BOOTROM_WELL_KNOWN_PTR_SIZE)/* ... */#endif/* ... */#endif#if!PICO_RP2040||PICO_COMBINED_DOCS#defineBOOTROM_OK0//#define BOOTROM_ERROR_TIMEOUT (-1)//#define BOOTROM_ERROR_GENERIC (-2)//#define BOOTROM_ERROR_NO_DATA (-3) // E.g. read from an empty buffer/FIFO#defineBOOTROM_ERROR_NOT_PERMITTED(-4)// Permission violation e.g. write to read-only flash partition#defineBOOTROM_ERROR_INVALID_ARG(-5)// Argument is outside of range of supported values`//#define BOOTROM_ERROR_IO (-6)//#define BOOTROM_ERROR_BADAUTH (-7)//#define BOOTROM_ERROR_CONNECT_FAILED (-8)//#define BOOTROM_ERROR_INSUFFICIENT_RESOURCES (-9) // Dynamic allocation of resources failed#defineBOOTROM_ERROR_INVALID_ADDRESS(-10)// Address argument was out-of-bounds or was determined to be an address that the caller may not access#defineBOOTROM_ERROR_BAD_ALIGNMENT(-11)// Address modulo transfer chunk size was nonzero (e.g. word-aligned transfer with address % 4 != 0)#defineBOOTROM_ERROR_INVALID_STATE(-12)// Something happened or failed to happen in the past, and consequently we (currently) can't service the request#defineBOOTROM_ERROR_BUFFER_TOO_SMALL(-13)// A user-allocated buffer was too small to hold the result or working state of this function#defineBOOTROM_ERROR_PRECONDITION_NOT_MET(-14)// This call failed because another ROM function must be called first#defineBOOTROM_ERROR_MODIFIED_DATA(-15)// Cached data was determined to be inconsistent with the full version of the data it was calculated from#defineBOOTROM_ERROR_INVALID_DATA(-16)// A data structure failed to validate#defineBOOTROM_ERROR_NOT_FOUND(-17)// Attempted to access something that does not exist; or, a search failed#defineBOOTROM_ERROR_UNSUPPORTED_MODIFICATION(-18)// Write is impossible based on previous writes; e.g. attempted to clear an OTP bit#defineBOOTROM_ERROR_LOCK_REQUIRED(-19)// A required lock is not owned#defineBOOTROM_ERROR_LAST(-19)#defineRT_FLAG_FUNC_RISCV0x0001#defineRT_FLAG_FUNC_RISCV_FAR0x0003#defineRT_FLAG_FUNC_ARM_SEC0x0004// reserved for 32-bit pointer: 0x0008#defineRT_FLAG_FUNC_ARM_NONSEC0x0010// reserved for 32-bit pointer: 0x0020#defineRT_FLAG_DATA0x0040// reserved for 32-bit pointer: 0x0080#definePARTITION_TABLE_MAX_PARTITIONS16// note this is deliberately > MAX_PARTITIONs is likely to be, and also -1 as a signed byte#definePARTITION_TABLE_NO_PARTITION_INDEX0xff// todo these are duplicated in picoboot_constants.h// values 0-7 are secure/non-secure#defineBOOT_TYPE_NORMAL0#defineBOOT_TYPE_BOOTSEL2#defineBOOT_TYPE_RAM_IMAGE3#defineBOOT_TYPE_FLASH_UPDATE4// values 8-15 are secure only#defineBOOT_TYPE_PC_SP0xd// ORed in if a bootloader chained into the image#defineBOOT_TYPE_CHAINED_FLAG0x8027 defines// call from NS to S#ifndef__riscv#defineBOOTROM_API_CALLBACK_secure_call0#endif#defineBOOTROM_API_CALLBACK_COUNT1#defineBOOTROM_LOCK_SHA_2560#defineBOOTROM_LOCK_FLASH_OP1#defineBOOTROM_LOCK_OTP2#defineBOOTROM_LOCK_MAX2#defineBOOTROM_LOCK_ENABLE7#defineBOOT_PARTITION_NONE(-1)#defineBOOT_PARTITION_SLOT0(-2)#defineBOOT_PARTITION_SLOT1(-3)#defineBOOT_PARTITION_WINDOW(-4)#defineBOOT_DIAGNOSTIC_WINDOW_SEARCHED0x01// note if both BOOT_DIAGNOSTIC_INVALID_BLOCK_LOOP and BOOT_DIAGNOSTIC_VALID_BLOCK_LOOP then the block loop was valid// but it has a PARTITION_TABLE which while it passed the initial verification (and hash/sig) had invalid contents// (discovered when it was later loaded)#defineBOOT_DIAGNOSTIC_INVALID_BLOCK_LOOP0x02#defineBOOT_DIAGNOSTIC_VALID_BLOCK_LOOP0x04#defineBOOT_DIAGNOSTIC_VALID_IMAGE_DEF0x08#defineBOOT_DIAGNOSTIC_HAS_PARTITION_TABLE0x10#defineBOOT_DIAGNOSTIC_CONSIDERED0x20#defineBOOT_DIAGNOSTIC_CHOSEN0x40#defineBOOT_DIAGNOSTIC_PARTITION_TABLE_LSB7#defineBOOT_DIAGNOSTIC_PARTITION_TABLE_MATCHING_KEY_FOR_VERIFY0x80#defineBOOT_DIAGNOSTIC_PARTITION_TABLE_HASH_FOR_VERIFY0x100#defineBOOT_DIAGNOSTIC_PARTITION_TABLE_VERIFIED_OK0x200#defineBOOT_DIAGNOSTIC_IMAGE_DEF_LSB10#defineBOOT_DIAGNOSTIC_IMAGE_DEF_MATCHING_KEY_FOR_VERIFY0x400#defineBOOT_DIAGNOSTIC_IMAGE_DEF_HASH_FOR_VERIFY0x800#defineBOOT_DIAGNOSTIC_IMAGE_DEF_VERIFIED_OK0x1000#defineBOOT_DIAGNOSTIC_LOAD_MAP_ENTRIES_LOADED0x2000#defineBOOT_DIAGNOSTIC_IMAGE_LAUNCHED0x4000#defineBOOT_DIAGNOSTIC_IMAGE_CONDITION_FAILURE0x8000#defineBOOT_PARSED_BLOCK_DIAGNOSTIC_MATCHING_KEY_FOR_VERIFY0x1// if this is present and VERIFIED_OK isn't the sig check failed#defineBOOT_PARSED_BLOCK_DIAGNOSTIC_HASH_FOR_VERIFY0x2// if this is present and VERIFIED_OL isn't then hash check failed#defineBOOT_PARSED_BLOCK_DIAGNOSTIC_VERIFIED_OK0x4#defineBOOT_TBYB_AND_UPDATE_FLAG_BUY_PENDING0x1#defineBOOT_TBYB_AND_UPDATE_FLAG_OTP_VERSION_APPLIED0x2#defineBOOT_TBYB_AND_UPDATE_FLAG_OTHER_ERASED0x434 defines#ifndef__ASSEMBLER__// Limited to 3 arguments in case of varm multiplex hint (trashes Arm r3)typedefint(*bootrom_api_callback_generic_t)(uint32_tr0,uint32_tr1,uint32_tr2);// Return negative for error, else number of bytes transferred://typedef int (*bootrom_api_callback_stdout_put_blocking_t)(const uint8_t *buffer, uint32_t size);//typedef int (*bootrom_api_callback_stdin_get_t)(uint8_t *buffer, uint32_t size);//typedef void (*bootrom_api_callback_core1_security_setup_t)(void);/* ... */#endif/* ... */#endif/*! \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() *//* ... */#defineROM_TABLE_CODE(c1,c2)((c1)|((c2)<<8))// ROM FUNCTIONS// RP2040 & RP2350#defineROM_DATA_SOFTWARE_GIT_REVISIONROM_TABLE_CODE('G','R')#defineROM_FUNC_FLASH_ENTER_CMD_XIPROM_TABLE_CODE('C','X')#defineROM_FUNC_FLASH_EXIT_XIPROM_TABLE_CODE('E','X')#defineROM_FUNC_FLASH_FLUSH_CACHEROM_TABLE_CODE('F','C')#defineROM_FUNC_CONNECT_INTERNAL_FLASHROM_TABLE_CODE('I','F')#defineROM_FUNC_FLASH_RANGE_ERASEROM_TABLE_CODE('R','E')#defineROM_FUNC_FLASH_RANGE_PROGRAMROM_TABLE_CODE('R','P')8 defines#ifPICO_RP2040// RP2040 only#defineROM_FUNC_MEMCPY44ROM_TABLE_CODE('C','4')#defineROM_DATA_COPYRIGHTROM_TABLE_CODE('C','R')#defineROM_FUNC_CLZ32ROM_TABLE_CODE('L','3')#defineROM_FUNC_MEMCPYROM_TABLE_CODE('M','C')#defineROM_FUNC_MEMSETROM_TABLE_CODE('M','S')#defineROM_FUNC_POPCOUNT32ROM_TABLE_CODE('P','3')#defineROM_FUNC_REVERSE32ROM_TABLE_CODE('R','3')#defineROM_FUNC_MEMSET4ROM_TABLE_CODE('S','4')#defineROM_FUNC_CTZ32ROM_TABLE_CODE('T','3')#defineROM_FUNC_RESET_USB_BOOTROM_TABLE_CODE('U','B')10 defines#endif/* ... */#if!PICO_RP2040||PICO_COMBINED_DOCS// RP2350 only#defineROM_FUNC_PICK_AB_PARTITIONROM_TABLE_CODE('A','B')#defineROM_FUNC_CHAIN_IMAGEROM_TABLE_CODE('C','I')#defineROM_FUNC_EXPLICIT_BUYROM_TABLE_CODE('E','B')#defineROM_FUNC_FLASH_RUNTIME_TO_STORAGE_ADDRROM_TABLE_CODE('F','A')#defineROM_DATA_FLASH_DEVINFO16_PTRROM_TABLE_CODE('F','D')#defineROM_FUNC_FLASH_OPROM_TABLE_CODE('F','O')#defineROM_FUNC_GET_B_PARTITIONROM_TABLE_CODE('G','B')#defineROM_FUNC_GET_PARTITION_TABLE_INFOROM_TABLE_CODE('G','P')#defineROM_FUNC_GET_SYS_INFOROM_TABLE_CODE('G','S')#defineROM_FUNC_GET_UF2_TARGET_PARTITIONROM_TABLE_CODE('G','U')#defineROM_FUNC_LOAD_PARTITION_TABLEROM_TABLE_CODE('L','P')#defineROM_FUNC_OTP_ACCESSROM_TABLE_CODE('O','A')#defineROM_DATA_PARTITION_TABLE_PTRROM_TABLE_CODE('P','T')#defineROM_FUNC_FLASH_RESET_ADDRESS_TRANSROM_TABLE_CODE('R','A')#defineROM_FUNC_REBOOTROM_TABLE_CODE('R','B')#defineROM_FUNC_SET_ROM_CALLBACKROM_TABLE_CODE('R','C')#defineROM_FUNC_SECURE_CALLROM_TABLE_CODE('S','C')#defineROM_FUNC_SET_NS_API_PERMISSIONROM_TABLE_CODE('S','P')#defineROM_FUNC_BOOTROM_STATE_RESETROM_TABLE_CODE('S','R')#defineROM_FUNC_SET_BOOTROM_STACKROM_TABLE_CODE('S','S')#defineROM_DATA_SAVED_XIP_SETUP_FUNC_PTRROM_TABLE_CODE('X','F')#defineROM_FUNC_FLASH_SELECT_XIP_READ_MODEROM_TABLE_CODE('X','M')#defineROM_FUNC_VALIDATE_NS_BUFFERROM_TABLE_CODE('V','B')23 defines#endif/* ... */// these form a bit set#defineBOOTROM_STATE_RESET_CURRENT_CORE0x01#defineBOOTROM_STATE_RESET_OTHER_CORE0x02#defineBOOTROM_STATE_RESET_GLOBAL_STATE0x04// reset any global state (e.g. permissions)// partition level stuff is returned first (note PT_INFO flags is only 16 bits)// 3 words: pt_count, unpartitioned_perm_loc, unpartioned_perm_flags#definePT_INFO_PT_INFO0x0001#definePT_INFO_SINGLE_PARTITION0x8000// marker to just include a single partition in the results)// then in order per partition selected// 2 words: unpartitioned_perm_loc, unpartioned_perm_flags#definePT_INFO_PARTITION_LOCATION_AND_FLAGS0x0010// 2 words: id lsb first#definePT_INFO_PARTITION_ID0x0020// n+1 words: n, family_id...#definePT_INFO_PARTITION_FAMILY_IDS0x0040// (n+3)/4 words... bytes are: n (len), c0, c1, ... cn-1 padded to word boundary with zeroes#definePT_INFO_PARTITION_NAME0x0080// items are returned in order// 3 words package_id, device_id, wafer_id#defineSYS_INFO_CHIP_INFO0x0001// 1 word: chip specific critical bits#defineSYS_INFO_CRITICAL0x0002// 1 word: bytes: cpu_type, supported_cpu_type_bitfield#defineSYS_INFO_CPU_INFO0x0004// 1 word: same as FLASH_DEVINFO row in OTP#defineSYS_INFO_FLASH_DEV_INFO0x0008// 4 words#defineSYS_INFO_BOOT_RANDOM0x0010// 2 words lsb first#defineSYS_INFO_NONCE0x0020// 4 words boot_info, boot_diagnostic, boot_param0, boot_param1#defineSYS_INFO_BOOT_INFO0x0040#defineBOOTROM_NS_API_get_sys_info0#defineBOOTROM_NS_API_checked_flash_op1#defineBOOTROM_NS_API_flash_runtime_to_storage_addr2#defineBOOTROM_NS_API_get_partition_table_info3#defineBOOTROM_NS_API_secure_call4#defineBOOTROM_NS_API_otp_access5#defineBOOTROM_NS_API_reboot6#defineBOOTROM_NS_API_get_b_partition7#defineBOOTROM_NS_API_COUNT825 defines#ifndef__ASSEMBLER__typedefstruct{uint32_tpermissions_and_location;uint32_tpermissions_and_flags;...}resident_partition_t;static_assert(sizeof(resident_partition_t)==8,"");#defineOTP_CMD_ROW_BITS0x0000ffffu#defineOTP_CMD_ROW_LSB0u#defineOTP_CMD_WRITE_BITS0x00010000u#defineOTP_CMD_ECC_BITS0x00020000utypedefstructotp_cmd{uint32_tflags;...}otp_cmd_t;typedefenum{BOOTROM_XIP_MODE_03H_SERIAL=0,BOOTROM_XIP_MODE_0BH_SERIAL,BOOTROM_XIP_MODE_BBH_DUAL,BOOTROM_XIP_MODE_EBH_QUAD,BOOTROM_XIP_MODE_N_MODES...}bootrom_xip_mode_t;// The checked flash API wraps the low-level flash routines from generic_flash, adding bounds// checking, permission checking against the resident partition table, and simple address// translation. The low-level API deals with flash offsets (i.e. distance from the start of the// first flash device, measured in bytes) but the checked flash API accepts one of two types of// address://// - Flash runtime addresses: the address of some flash-resident data or code in the currently// running image. The flash addresses your binary is "linked at" by the linker.// - Flash storage addresses: a flash offset, plus the address base where QSPI hardware is first// mapped on the system bus (XIP_BASE constant from addressmap.h)//// These addresses are one and the same *if* the currently running program is stored at the// beginning of flash. They are different if the start of your image has been "rolled" by the flash// boot path to make it appear at the address it was linked at even though it is stored at a// different location in flash, which is necessary when you have A/B images for example.//// The address translation between flash runtime and flash storage addresses is configured in// hardware by the QMI_ATRANSx registers, and this API assumes those registers contain a valid// address mapping which it can use to translate runtime to storage addresses.typedefstructcflash_flags{uint32_tflags;...}cflash_flags_t;// Bits which are permitted to be set in a flags variable -- any other bits being set is an error#defineCFLASH_FLAGS_BITS0x00070301u// Used to tell checked flash API which space a given address belongs to#defineCFLASH_ASPACE_BITS0x00000001u#defineCFLASH_ASPACE_LSB0u#defineCFLASH_ASPACE_VALUE_STORAGE0u#defineCFLASH_ASPACE_VALUE_RUNTIME1u// Used to tell checked flash APIs the effective security level of a flash access (may be forced to// one of these values for the NonSecure-exported version of this API)#defineCFLASH_SECLEVEL_BITS0x00000300u#defineCFLASH_SECLEVEL_LSB8u// Zero is not a valid security level:#defineCFLASH_SECLEVEL_VALUE_SECURE1u#defineCFLASH_SECLEVEL_VALUE_NONSECURE2u#defineCFLASH_SECLEVEL_VALUE_BOOTLOADER3u#defineCFLASH_OP_BITS0x00070000u#defineCFLASH_OP_LSB16u// Erase size_bytes bytes of flash, starting at address addr. Both addr and size_bytes must be a// multiple of 4096 bytes (one flash sector).#defineCFLASH_OP_VALUE_ERASE0u// Program size_bytes bytes of flash, starting at address addr. Both addr and size_bytes must be a// multiple of 256 bytes (one flash page).#defineCFLASH_OP_VALUE_PROGRAM1u// Read size_bytes bytes of flash, starting at address addr. There are no alignment restrictions on// addr or size_bytes.#defineCFLASH_OP_VALUE_READ2u#defineCFLASH_OP_MAX2u16 defines/* ... */#endif/* ... */#endif
Details
Show: from
Types: Columns:
All items filtered out
All items filtered out
This file uses the notable symbols shown below. Click anywhere in the file to view more details.