Skip to content

Commit 2bc6f35

Browse files
kilograhamwill-v-pilurchgraham sanderson
committed
Support for RP2350 A2/A3/A4 along with code improvements (#267)
* Support for RP2350 A2/A4/A4 along with code improvements, replacing the ocean of one-off IFs with a more OO abstraction Co-authored-by: William Vinnicombe <william.vinnicombe@raspberrypi.com> Co-authored-by: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Co-authored-by: Andrew Scheller <andrew.scheller@raspberrypi.com> Co-authored-by: graham sanderson <graham@spiff.local>
1 parent a7eb398 commit 2bc6f35

23 files changed

Lines changed: 882 additions & 418 deletions

BUILD.bazel

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ package(default_visibility = ["//visibility:public"])
44

55
PICOTOOL_SDK_VERSION_STRING = module_version() if module_version() != None else "0.0.1-WORKSPACE"
66

7-
picotool_binary_data_header(
8-
name = "rp2350_rom",
9-
src = "bootrom.end.bin",
10-
out = "rp2350.rom.h",
11-
)
12-
137
# TODO: Make it possible to build the prebuilt from source.
148
picotool_binary_data_header(
159
name = "xip_ram_perms_elf",
@@ -38,6 +32,24 @@ picotool_binary_data_header(
3832
out = "flash_id_bin.h",
3933
)
4034

35+
picotool_binary_data_header(
36+
name = "rp2350_a2_rom_end",
37+
src = "//model:rp2350_a2_rom_end_bin",
38+
out = "rp2350_a2_rom_end.h",
39+
)
40+
41+
picotool_binary_data_header(
42+
name = "rp2350_a3_rom_end",
43+
src = "//model:rp2350_a3_rom_end_bin",
44+
out = "rp2350_a3_rom_end.h",
45+
)
46+
47+
picotool_binary_data_header(
48+
name = "rp2350_a4_rom_end",
49+
src = "//model:rp2350_a4_rom_end_bin",
50+
out = "rp2350_a4_rom_end.h",
51+
)
52+
4153
cc_library(
4254
name = "xip_ram_perms",
4355
srcs = ["get_xip_ram_perms.cpp"],
@@ -88,7 +100,6 @@ cc_binary(
88100
"main.cpp",
89101
"otp.cpp",
90102
"otp.h",
91-
"rp2350.rom.h",
92103
"get_xip_ram_perms.cpp",
93104
"get_enc_bootloader.cpp",
94105
] + select({

CMakeLists.txt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,16 +217,8 @@ else()
217217
endif()
218218

219219
add_custom_target(embedded_data DEPENDS
220-
${CMAKE_CURRENT_BINARY_DIR}/rp2350.rom.h
221220
${CMAKE_CURRENT_BINARY_DIR}/xip_ram_perms_elf.h
222221
${CMAKE_CURRENT_BINARY_DIR}/flash_id_bin.h)
223-
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/rp2350.rom.h
224-
COMMAND ${CMAKE_COMMAND}
225-
-D BINARY_FILE=${CMAKE_CURRENT_LIST_DIR}/bootrom.end.bin
226-
-D OUTPUT_NAME=rp2350.rom
227-
-P ${CMAKE_CURRENT_LIST_DIR}/cmake/binh.cmake
228-
COMMENT "Configuring rp2350.rom.h"
229-
VERBATIM)
230222
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xip_ram_perms_elf.h
231223
COMMAND ${CMAKE_COMMAND}
232224
-D BINARY_FILE=${XIP_RAM_PERMS_ELF}
@@ -260,6 +252,7 @@ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/flash_id_bin.h
260252
COMMENT "Configuring flash_id_bin.h"
261253
VERBATIM)
262254

255+
add_subdirectory(model)
263256
add_subdirectory(errors)
264257

265258
add_subdirectory(picoboot_connection)
@@ -305,7 +298,7 @@ target_compile_definitions(picotool PRIVATE
305298
PICOTOOL_VERSION="${PICOTOOL_VERSION}"
306299
SYSTEM_VERSION="${SYSTEM_VERSION}"
307300
COMPILER_INFO="${COMPILER_INFO}"
308-
SUPPORT_A2=1
301+
SUPPORT_RP2350_A2=1
309302
CODE_OTP=${PICOTOOL_CODE_OTP}
310303
)
311304
# for OTP info
@@ -321,6 +314,7 @@ target_link_libraries(picotool
321314
pico_platform_headers
322315
pico_usb_reset_interface_headers
323316
regs_headers
317+
model
324318
bintool
325319
elf2uf2
326320
errors

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -821,8 +821,8 @@ UF2 CONVERT:
821821
Convert ELF/BIN to UF2.
822822
823823
SYNOPSIS:
824-
picotool uf2 convert [--quiet] [--verbose] <infile> [-t <type>] <outfile> [-t <type>] [-o <offset>] [--family <family_id>]
825-
[[--abs-block] [<abs_block_loc>]]
824+
picotool uf2 convert [--quiet] [--verbose] <infile> [-t <type>] <outfile> [-t <type>] [-o <offset>] [--family <family_id>] [--platform
825+
<platform>] [[--abs-block] [<abs_block_loc>]]
826826
827827
OPTIONS:
828828
--quiet
@@ -847,6 +847,9 @@ OPTIONS:
847847
UF2 Family options
848848
<family_id>
849849
family ID for UF2
850+
Platform options
851+
<platform>
852+
optional platform for memory verification (eg rp2040, rp2350)
850853
Errata RP2350-E10 Fix
851854
--abs-block
852855
Add an absolute block

elf/BUILD.bazel

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ cc_library(
44
name = "elf",
55
srcs = ["elf_file.cpp"],
66
hdrs = [
7-
"addresses.h",
87
"elf.h",
98
"elf_file.h",
109
"portable_endian.h",
@@ -16,5 +15,5 @@ cc_library(
1615
],
1716
}),
1817
includes = ["."],
19-
deps = ["//errors"],
18+
deps = ["//model", "//errors"],
2019
)

elf/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ add_library(elf STATIC
33

44
target_include_directories(elf PUBLIC ${CMAKE_CURRENT_LIST_DIR})
55

6-
target_link_libraries(elf PRIVATE errors)
6+
target_link_libraries(elf PUBLIC model errors)

elf2uf2/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ add_library(elf2uf2 STATIC
33

44
target_include_directories(elf2uf2 PUBLIC ${CMAKE_CURRENT_LIST_DIR})
55

6-
target_link_libraries(elf2uf2 PRIVATE boot_uf2_headers elf errors)
6+
target_link_libraries(elf2uf2 PUBLIC elf errors)

elf2uf2/elf2uf2.cpp

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "elf2uf2.h"
1919
#include "errors.h"
20+
#include "model.h"
2021

2122
#define FLASH_SECTOR_ERASE_SIZE 4096u
2223

@@ -156,11 +157,11 @@ bool check_abs_block(uf2_block block) {
156157
!(block.flags & UF2_FLAG_EXTENSION_FLAGS_PRESENT && *(uint32_t*)&(block.data[UF2_PAGE_SIZE]) != UF2_EXTENSION_RP2_IGNORE_BLOCK);
157158
}
158159

159-
int pages2uf2(std::map<uint32_t, std::vector<page_fragment>>& pages, std::shared_ptr<std::iostream> in, std::shared_ptr<std::iostream> out, uint32_t family_id, uint32_t abs_block_loc=0) {
160+
int pages2uf2(std::map<uint32_t, std::vector<page_fragment>>& pages, std::shared_ptr<std::iostream> in, std::shared_ptr<std::iostream> out, uint32_t family_id, model_t model, uint32_t abs_block_loc=0) {
160161
// RP2350-E10: add absolute block to start of flash UF2s, targeting end of flash by default
161-
if (family_id != ABSOLUTE_FAMILY_ID && family_id != RP2040_FAMILY_ID && abs_block_loc) {
162+
if (family_id != ABSOLUTE_FAMILY_ID && model->chip() == rp2350 && abs_block_loc) {
162163
uint32_t base_addr = pages.begin()->first;
163-
address_ranges flash_range = rp2350_address_ranges_flash;
164+
address_ranges flash_range = address_ranges_flash(model);
164165
if (is_address_initialized(flash_range, base_addr)) {
165166
uf2_block block = gen_abs_block(abs_block_loc);
166167
out->write((char*)&block, sizeof(uf2_block));
@@ -196,7 +197,7 @@ int pages2uf2(std::map<uint32_t, std::vector<page_fragment>>& pages, std::shared
196197
return 0;
197198
}
198199

199-
int bin2uf2(std::shared_ptr<std::iostream> in, std::shared_ptr<std::iostream> out, uint32_t address, uint32_t family_id, uint32_t abs_block_loc, bool verbose) {
200+
int bin2uf2(std::shared_ptr<std::iostream> in, std::shared_ptr<std::iostream> out, uint32_t address, uint32_t family_id, model_t model, uint32_t abs_block_loc, bool verbose) {
200201
g_verbose = verbose;
201202
std::map<uint32_t, std::vector<page_fragment>> pages;
202203

@@ -232,10 +233,10 @@ int bin2uf2(std::shared_ptr<std::iostream> in, std::shared_ptr<std::iostream> ou
232233
remaining -= len;
233234
}
234235

235-
return pages2uf2(pages, in, out, family_id, abs_block_loc);
236+
return pages2uf2(pages, in, out, family_id, model, abs_block_loc);
236237
}
237238

238-
int elf2uf2(std::shared_ptr<std::iostream> in, std::shared_ptr<std::iostream> out, uint32_t family_id, uint32_t package_addr, uint32_t abs_block_loc, bool verbose) {
239+
int elf2uf2(std::shared_ptr<std::iostream> in, std::shared_ptr<std::iostream> out, uint32_t family_id, model_t model, uint32_t package_addr, uint32_t abs_block_loc, bool verbose) {
239240
elf_file source_file(verbose);
240241
g_verbose = verbose;
241242
elf_file *elf = &source_file;
@@ -244,14 +245,8 @@ int elf2uf2(std::shared_ptr<std::iostream> in, std::shared_ptr<std::iostream> ou
244245
int rc = elf->read_file(in);
245246
bool ram_style = false;
246247
address_ranges valid_ranges = {};
247-
address_ranges flash_range; address_ranges ram_range;
248-
if (family_id == RP2040_FAMILY_ID) {
249-
flash_range = rp2040_address_ranges_flash;
250-
ram_range = rp2040_address_ranges_ram;
251-
} else {
252-
flash_range = rp2350_address_ranges_flash;
253-
ram_range = rp2350_address_ranges_ram;
254-
}
248+
address_ranges flash_range = address_ranges_flash(model);
249+
address_ranges ram_range = address_ranges_ram(model);
255250
if (!rc) {
256251
rc = rp_determine_binary_type(elf->header(), elf->segments(), flash_range, ram_range, &ram_style);
257252
if (!rc) {
@@ -284,9 +279,9 @@ int elf2uf2(std::shared_ptr<std::iostream> in, std::shared_ptr<std::iostream> ou
284279
}
285280
}
286281
uint32_t expected_ep = (UINT32_MAX != expected_ep_main_ram) ? expected_ep_main_ram : expected_ep_xip_sram;
287-
if (eh.entry == expected_ep_xip_sram && family_id == RP2040_FAMILY_ID) {
282+
if (eh.entry == expected_ep_xip_sram && model->chip() == rp2040) {
288283
fail(ERROR_INCOMPATIBLE, "RP2040 B0/B1/B2 Boot ROM does not support direct entry into XIP_SRAM\n");
289-
} else if (eh.entry != expected_ep && family_id == RP2040_FAMILY_ID) {
284+
} else if (eh.entry != expected_ep && model->chip() == rp2040) {
290285
fail(ERROR_INCOMPATIBLE, "A RP2040 RAM binary should have an entry point at the beginning: %08x (not %08x)\n", expected_ep, eh.entry);
291286
}
292287
static_assert(0 == (SRAM_START & (UF2_PAGE_SIZE - 1)), "");
@@ -344,5 +339,5 @@ int elf2uf2(std::shared_ptr<std::iostream> in, std::shared_ptr<std::iostream> ou
344339
}
345340
}
346341

347-
return pages2uf2(pages, in, out, family_id, abs_block_loc);
342+
return pages2uf2(pages, in, out, family_id, model, abs_block_loc);
348343
}

elf2uf2/elf2uf2.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@
1414
#include "boot/uf2.h"
1515

1616
#include "elf_file.h"
17+
#include "model.h"
1718

1819
// we require 256 (as this is the page size supported by the device)
1920
#define LOG2_PAGE_SIZE 8u
2021
#define UF2_PAGE_SIZE (1u << LOG2_PAGE_SIZE)
2122

2223

2324
bool check_abs_block(uf2_block block);
24-
int bin2uf2(std::shared_ptr<std::iostream> in, std::shared_ptr<std::iostream> out, uint32_t address, uint32_t family_id, uint32_t abs_block_loc=0, bool verbose=false);
25-
int elf2uf2(std::shared_ptr<std::iostream> in, std::shared_ptr<std::iostream> out, uint32_t family_id, uint32_t package_addr=0, uint32_t abs_block_loc=0, bool verbose=false);
25+
int bin2uf2(std::shared_ptr<std::iostream> in, std::shared_ptr<std::iostream> out, uint32_t address, uint32_t family_id, model_t model, uint32_t abs_block_loc=0, bool verbose=false);
26+
int elf2uf2(std::shared_ptr<std::iostream> in, std::shared_ptr<std::iostream> out, uint32_t family_id, model_t model, uint32_t package_addr=0, uint32_t abs_block_loc=0, bool verbose=false);
2627

2728

2829
#endif

errors/errors.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "errors.h"
44

55
void fail(int code, std::string msg) {
6-
throw command_failure(code, std::move(msg));
6+
throw failure_error(code, std::move(msg));
77
}
88

99
void fail(int code, const char *format, ...) {

errors/errors.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
#define ERROR_UNKNOWN (-99)
2222

2323

24-
struct command_failure : std::exception {
25-
command_failure(int code, std::string s) : c(code), s(std::move(s)) {}
24+
struct failure_error : std::exception {
25+
failure_error(int code, std::string s) : c(code), s(std::move(s)) {}
2626

2727
const char *what() const noexcept override {
2828
return s.c_str();

0 commit comments

Comments
 (0)