Loading...
Searching...
No Matches
picoboot.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 _BOOT_PICOBOOT_H
8#define _BOOT_PICOBOOT_H
9
10#include <stdint.h>
11#include <stdbool.h>
12#include <assert.h>
13
14#ifndef NO_PICO_PLATFORM
15#include "pico/platform.h"
16#endif
17
23
24#include "picoboot_constants.h"
25
26#define PICOBOOT_MAGIC 0x431fd10bu
27
28// --------------------------------------------
29// CONTROL REQUESTS FOR THE PICOBOOT INTERFACE
30// --------------------------------------------
31
32// size 0 OUT - un-stall EPs and reset
33#define PICOBOOT_IF_RESET 0x41
34
35// size 16 IN - return the status of the last command
36#define PICOBOOT_IF_CMD_STATUS 0x42
37
38// --------------------------------------------------
39// COMMAND REQUESTS SENT TO THE PICOBOOT OUT ENDPOINT
40// --------------------------------------------------
41//
42// picoboot_cmd structure of size 32 is sent to OUT endpoint
43// transfer_length bytes are transferred via IN/OUT
44// device responds on success with 0 length ACK packet set via OUT/IN
45// device may stall the transferring endpoint in case of error
46
47enum picoboot_cmd_id {
48 PC_EXCLUSIVE_ACCESS = 0x1,
49 PC_REBOOT = 0x2, // RP2040 only
50 PC_FLASH_ERASE = 0x3,
51 PC_READ = 0x84, // either ROM or RAM or FLASH
52 PC_WRITE = 0x5, // either RAM or FLASH (does no erase)
53 PC_EXIT_XIP = 0x6, // has no additional parameters (bCmdSize == 0)
54 PC_ENTER_CMD_XIP = 0x7, // has no additional parameters (bCmdSize == 0)
55 PC_EXEC = 0x8, // RP2040 only
56 PC_VECTORIZE_FLASH = 0x9, // RP2040 only
57 // RP2350 only below here
58 PC_REBOOT2 = 0xa,
59 PC_GET_INFO = 0x8b,
60 PC_OTP_READ = 0x8c,
61 PC_OTP_WRITE = 0xd,
62};
63
64enum picoboot_status {
65 PICOBOOT_OK = 0,
66 PICOBOOT_UNKNOWN_CMD = 1,
67 PICOBOOT_INVALID_CMD_LENGTH = 2,
68 PICOBOOT_INVALID_TRANSFER_LENGTH = 3,
69 PICOBOOT_INVALID_ADDRESS = 4,
70 PICOBOOT_BAD_ALIGNMENT = 5,
71 PICOBOOT_INTERLEAVED_WRITE = 6,
72 PICOBOOT_REBOOTING = 7,
73 PICOBOOT_UNKNOWN_ERROR = 8,
74 PICOBOOT_INVALID_STATE = 9,
75 PICOBOOT_NOT_PERMITTED = 10,
76 PICOBOOT_INVALID_ARG = 11,
77 PICOBOOT_BUFFER_TOO_SMALL = 12,
78 PICOBOOT_PRECONDITION_NOT_MET = 13,
79 PICOBOOT_MODIFIED_DATA = 14,
80 PICOBOOT_INVALID_DATA = 15,
81 PICOBOOT_NOT_FOUND = 16,
82 PICOBOOT_UNSUPPORTED_MODIFICATION = 17,
83};
84
90struct __packed picoboot_reboot_cmd {
91 uint32_t dPC;
92 uint32_t dSP;
93 uint32_t dDelayMS;
94};
95
101struct __packed picoboot_reboot2_cmd {
102 uint32_t dFlags;
103 uint32_t dDelayMS;
104 uint32_t dParam0;
105 uint32_t dParam1;
106};
107
115 uint32_t dAddr;
116};
117
123struct __packed picoboot_range_cmd {
124 uint32_t dAddr;
125 uint32_t dSize;
126};
127
128// remains defined for backwards compatibility with RP2350 bootrom builds
129struct __packed picoboot_exec2_cmd {
130 uint32_t dummy;
131};
132
141
147struct __packed picoboot_exclusive_cmd {
148 uint8_t bExclusive;
149};
150
156struct __packed picoboot_otp_cmd {
157 uint16_t wRow;
158 uint16_t wRowCount;
159 uint8_t bEcc;
160};
161
167struct __packed picoboot_get_info_cmd {
168 uint8_t bType;
169 uint8_t bParam;
170 uint16_t wParam;
171 uint32_t dParams[3];
172};
173
174// little endian
183struct __packed __aligned(4) picoboot_cmd {
184 uint32_t dMagic;
185 uint32_t dToken;
186 uint8_t bCmdId;
187 uint8_t bCmdSize;
188 uint16_t _unused;
189 uint32_t dTransferLength;
190 union {
191 uint8_t args[16];
192 struct picoboot_reboot_cmd reboot_cmd;
193 struct picoboot_range_cmd range_cmd;
194 struct picoboot_address_only_cmd address_only_cmd;
195 struct picoboot_exclusive_cmd exclusive_cmd;
196 struct picoboot_reboot2_cmd reboot2_cmd;
198 struct picoboot_get_info_cmd get_info_cmd;
199 };
200};
201static_assert(32 == sizeof(struct picoboot_cmd), "picoboot_cmd must be 32 bytes big");
202
209struct __packed __aligned(4) picoboot_cmd_status {
210 uint32_t dToken;
211 uint32_t dStatusCode;
212 uint8_t bCmdId;
213 uint8_t bInProgress;
214 uint8_t _pad[6];
215};
216
217static_assert(16 == sizeof(struct picoboot_cmd_status), "picoboot_cmd_status must be 16 bytes big");
218
219#endif
picoboot_exclusive_type
Exclusivity level for a PC_EXCLUSIVE_ACCESS command.
Definition picoboot.h:136
@ EXCLUSIVE
Disable USB Mass Storage writes (any active UF2 download will be aborted).
Definition picoboot.h:138
@ EXCLUSIVE_AND_EJECT
Lock out USB Mass Storage by marking the drive media as not present (eject the drive).
Definition picoboot.h:139
@ NOT_EXCLUSIVE
No restriction on USB Mass Storage operation.
Definition picoboot.h:137
Definition bootrom_constants.h:282
Parameters for a command that operates on a single address (RP2040 only).
Definition picoboot.h:114
uint32_t dAddr
Target address.
Definition picoboot.h:115
Parameters for an exclusive-access command.
Definition picoboot.h:147
uint8_t bExclusive
Exclusivity level; one of the picoboot_exclusive_type values.
Definition picoboot.h:148
Definition picoboot.h:129
Parameters for a get-info command (not available on RP2040).
Definition picoboot.h:167
uint8_t bParam
Unused.
Definition picoboot.h:169
uint32_t dParams[3]
Additional parameters for the selected info type.
Definition picoboot.h:171
uint16_t wParam
Unused.
Definition picoboot.h:170
uint8_t bType
Info type selector.
Definition picoboot.h:168
Parameters for an OTP read or write command (not available on RP2040).
Definition picoboot.h:156
uint8_t bEcc
Non-zero to use ECC (16-bit per register); zero for raw 24-bit access (stored as 32-bit).
Definition picoboot.h:159
uint16_t wRow
OTP row index to start from.
Definition picoboot.h:157
uint16_t wRowCount
Number of rows to transfer.
Definition picoboot.h:158
Parameters for a command that operates on an address range.
Definition picoboot.h:123
uint32_t dAddr
Start address of the range.
Definition picoboot.h:124
uint32_t dSize
Size of the range in bytes.
Definition picoboot.h:125
Parameters for an extended reboot command (not available on RP2040).
Definition picoboot.h:101
uint32_t dDelayMS
Delay in milliseconds before rebooting.
Definition picoboot.h:103
uint32_t dFlags
Reboot flags controlling the boot path.
Definition picoboot.h:102
uint32_t dParam0
First reboot parameter (interpretation depends on flags).
Definition picoboot.h:104
uint32_t dParam1
Second reboot parameter (interpretation depends on flags).
Definition picoboot.h:105
Parameters for a reboot command (RP2040 only).
Definition picoboot.h:90
uint32_t dPC
Program counter to reboot to; 0 means reset into the regular boot path, otherwise must be a RAM addre...
Definition picoboot.h:91
uint32_t dDelayMS
Delay in milliseconds before rebooting.
Definition picoboot.h:93
uint32_t dSP
Stack pointer value at reboot; ignored unless dPC is a RAM address.
Definition picoboot.h:92