Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ package(default_visibility = ["//visibility:public"])

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

picotool_binary_data_header(
name = "rp2350_rom",
src = "bootrom.end.bin",
out = "rp2350.rom.h",
)

# TODO: Make it possible to build the prebuilt from source.
picotool_binary_data_header(
name = "xip_ram_perms_elf",
Expand Down Expand Up @@ -38,6 +32,24 @@ picotool_binary_data_header(
out = "flash_id_bin.h",
)

picotool_binary_data_header(
name = "rp2350_a2_rom_end",
src = "//model:rp2350_a2_rom_end_bin",
out = "rp2350_a2_rom_end.h",
)

picotool_binary_data_header(
name = "rp2350_a3_rom_end",
src = "//model:rp2350_a3_rom_end_bin",
out = "rp2350_a3_rom_end.h",
)

picotool_binary_data_header(
name = "rp2350_a4_rom_end",
src = "//model:rp2350_a4_rom_end_bin",
out = "rp2350_a4_rom_end.h",
)

cc_library(
name = "xip_ram_perms",
srcs = ["get_xip_ram_perms.cpp"],
Expand Down Expand Up @@ -88,7 +100,6 @@ cc_binary(
"main.cpp",
"otp.cpp",
"otp.h",
"rp2350.rom.h",
"get_xip_ram_perms.cpp",
"get_enc_bootloader.cpp",
] + select({
Expand Down
12 changes: 3 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,8 @@ else()
endif()

add_custom_target(embedded_data DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/rp2350.rom.h
${CMAKE_CURRENT_BINARY_DIR}/xip_ram_perms_elf.h
${CMAKE_CURRENT_BINARY_DIR}/flash_id_bin.h)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/rp2350.rom.h
COMMAND ${CMAKE_COMMAND}
-D BINARY_FILE=${CMAKE_CURRENT_LIST_DIR}/bootrom.end.bin
-D OUTPUT_NAME=rp2350.rom
-P ${CMAKE_CURRENT_LIST_DIR}/cmake/binh.cmake
COMMENT "Configuring rp2350.rom.h"
VERBATIM)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xip_ram_perms_elf.h
COMMAND ${CMAKE_COMMAND}
-D BINARY_FILE=${XIP_RAM_PERMS_ELF}
Expand Down Expand Up @@ -260,6 +252,7 @@ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/flash_id_bin.h
COMMENT "Configuring flash_id_bin.h"
VERBATIM)

add_subdirectory(model)
add_subdirectory(errors)

add_subdirectory(picoboot_connection)
Expand Down Expand Up @@ -305,7 +298,7 @@ target_compile_definitions(picotool PRIVATE
PICOTOOL_VERSION="${PICOTOOL_VERSION}"
SYSTEM_VERSION="${SYSTEM_VERSION}"
COMPILER_INFO="${COMPILER_INFO}"
SUPPORT_A2=1
SUPPORT_RP2350_A2=1
CODE_OTP=${PICOTOOL_CODE_OTP}
)
# for OTP info
Expand All @@ -321,6 +314,7 @@ target_link_libraries(picotool
pico_platform_headers
pico_usb_reset_interface_headers
regs_headers
model
bintool
elf2uf2
errors
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -821,8 +821,8 @@ UF2 CONVERT:
Convert ELF/BIN to UF2.
SYNOPSIS:
picotool uf2 convert [--quiet] [--verbose] <infile> [-t <type>] <outfile> [-t <type>] [-o <offset>] [--family <family_id>]
[[--abs-block] [<abs_block_loc>]]
picotool uf2 convert [--quiet] [--verbose] <infile> [-t <type>] <outfile> [-t <type>] [-o <offset>] [--family <family_id>] [--platform
<platform>] [[--abs-block] [<abs_block_loc>]]
OPTIONS:
--quiet
Expand All @@ -847,6 +847,9 @@ OPTIONS:
UF2 Family options
<family_id>
family ID for UF2
Platform options
<platform>
optional platform for memory verification (eg rp2040, rp2350)
Comment thread
lurch marked this conversation as resolved.
Errata RP2350-E10 Fix
--abs-block
Add an absolute block
Expand Down
3 changes: 1 addition & 2 deletions elf/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ cc_library(
name = "elf",
srcs = ["elf_file.cpp"],
hdrs = [
"addresses.h",
"elf.h",
"elf_file.h",
"portable_endian.h",
Expand All @@ -16,5 +15,5 @@ cc_library(
],
}),
includes = ["."],
deps = ["//errors"],
deps = ["//model", "//errors"],
)
2 changes: 1 addition & 1 deletion elf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ add_library(elf STATIC

target_include_directories(elf PUBLIC ${CMAKE_CURRENT_LIST_DIR})

target_link_libraries(elf PRIVATE errors)
target_link_libraries(elf PUBLIC model errors)
2 changes: 1 addition & 1 deletion elf2uf2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ add_library(elf2uf2 STATIC

target_include_directories(elf2uf2 PUBLIC ${CMAKE_CURRENT_LIST_DIR})

target_link_libraries(elf2uf2 PRIVATE boot_uf2_headers elf errors)
target_link_libraries(elf2uf2 PUBLIC elf errors)
29 changes: 12 additions & 17 deletions elf2uf2/elf2uf2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "elf2uf2.h"
#include "errors.h"
#include "model.h"

#define FLASH_SECTOR_ERASE_SIZE 4096u

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

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) {
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) {
// RP2350-E10: add absolute block to start of flash UF2s, targeting end of flash by default
if (family_id != ABSOLUTE_FAMILY_ID && family_id != RP2040_FAMILY_ID && abs_block_loc) {
if (family_id != ABSOLUTE_FAMILY_ID && model->chip() == rp2350 && abs_block_loc) {
uint32_t base_addr = pages.begin()->first;
address_ranges flash_range = rp2350_address_ranges_flash;
address_ranges flash_range = address_ranges_flash(model);
if (is_address_initialized(flash_range, base_addr)) {
uf2_block block = gen_abs_block(abs_block_loc);
out->write((char*)&block, sizeof(uf2_block));
Expand Down Expand Up @@ -196,7 +197,7 @@ int pages2uf2(std::map<uint32_t, std::vector<page_fragment>>& pages, std::shared
return 0;
}

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) {
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) {
g_verbose = verbose;
std::map<uint32_t, std::vector<page_fragment>> pages;

Expand Down Expand Up @@ -232,10 +233,10 @@ int bin2uf2(std::shared_ptr<std::iostream> in, std::shared_ptr<std::iostream> ou
remaining -= len;
}

return pages2uf2(pages, in, out, family_id, abs_block_loc);
return pages2uf2(pages, in, out, family_id, model, abs_block_loc);
}

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) {
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) {
elf_file source_file(verbose);
g_verbose = verbose;
elf_file *elf = &source_file;
Expand All @@ -244,14 +245,8 @@ int elf2uf2(std::shared_ptr<std::iostream> in, std::shared_ptr<std::iostream> ou
int rc = elf->read_file(in);
bool ram_style = false;
address_ranges valid_ranges = {};
address_ranges flash_range; address_ranges ram_range;
if (family_id == RP2040_FAMILY_ID) {
flash_range = rp2040_address_ranges_flash;
ram_range = rp2040_address_ranges_ram;
} else {
flash_range = rp2350_address_ranges_flash;
ram_range = rp2350_address_ranges_ram;
}
address_ranges flash_range = address_ranges_flash(model);
address_ranges ram_range = address_ranges_ram(model);
if (!rc) {
rc = rp_determine_binary_type(elf->header(), elf->segments(), flash_range, ram_range, &ram_style);
if (!rc) {
Expand Down Expand Up @@ -284,9 +279,9 @@ int elf2uf2(std::shared_ptr<std::iostream> in, std::shared_ptr<std::iostream> ou
}
}
uint32_t expected_ep = (UINT32_MAX != expected_ep_main_ram) ? expected_ep_main_ram : expected_ep_xip_sram;
if (eh.entry == expected_ep_xip_sram && family_id == RP2040_FAMILY_ID) {
if (eh.entry == expected_ep_xip_sram && model->chip() == rp2040) {
fail(ERROR_INCOMPATIBLE, "RP2040 B0/B1/B2 Boot ROM does not support direct entry into XIP_SRAM\n");
} else if (eh.entry != expected_ep && family_id == RP2040_FAMILY_ID) {
} else if (eh.entry != expected_ep && model->chip() == rp2040) {
fail(ERROR_INCOMPATIBLE, "A RP2040 RAM binary should have an entry point at the beginning: %08x (not %08x)\n", expected_ep, eh.entry);
}
static_assert(0 == (SRAM_START & (UF2_PAGE_SIZE - 1)), "");
Expand Down Expand Up @@ -344,5 +339,5 @@ int elf2uf2(std::shared_ptr<std::iostream> in, std::shared_ptr<std::iostream> ou
}
}

return pages2uf2(pages, in, out, family_id, abs_block_loc);
return pages2uf2(pages, in, out, family_id, model, abs_block_loc);
}
5 changes: 3 additions & 2 deletions elf2uf2/elf2uf2.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
#include "boot/uf2.h"

#include "elf_file.h"
#include "model.h"

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


bool check_abs_block(uf2_block block);
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);
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);
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);
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);


#endif
2 changes: 1 addition & 1 deletion errors/errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "errors.h"

void fail(int code, std::string msg) {
throw command_failure(code, std::move(msg));
throw failure_error(code, std::move(msg));
}

void fail(int code, const char *format, ...) {
Expand Down
4 changes: 2 additions & 2 deletions errors/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#define ERROR_UNKNOWN (-99)


struct command_failure : std::exception {
command_failure(int code, std::string s) : c(code), s(std::move(s)) {}
struct failure_error : std::exception {
failure_error(int code, std::string s) : c(code), s(std::move(s)) {}

const char *what() const noexcept override {
return s.c_str();
Expand Down
Loading
Loading