In-app flash write, UF2 parser, remove picotool dependency, reboot command
This commit is contained in:
@@ -42,8 +42,8 @@ bool dispatch_cancel_timer(timer_handle h) {
|
||||
}
|
||||
|
||||
static usb_cdc usb;
|
||||
static static_vector<uint8_t, 256> usb_rx_buf;
|
||||
static std::array<uint8_t, 1514> tx_buf;
|
||||
static static_vector<uint8_t, 4096> usb_rx_buf;
|
||||
static std::array<uint8_t, 4096> tx_buf;
|
||||
|
||||
auto dispatch_msg = [&](const DecodedMessage& msg, std::function<void(std::span<const uint8_t>)> send) {
|
||||
auto it = handler_map.find(msg.type_id);
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
#include "handlers.h"
|
||||
#include "pico/unique_id.h"
|
||||
#include "pico/bootrom.h"
|
||||
#include "hardware/flash.h"
|
||||
#include "hardware/watchdog.h"
|
||||
#include "dispatch.h"
|
||||
#include "net.h"
|
||||
#include "debug_log.h"
|
||||
|
||||
static constexpr uint32_t XIP_BASE_ADDR = 0x10000000;
|
||||
static constexpr uint32_t FLASH_SIZE = 2 * 1024 * 1024;
|
||||
|
||||
std::optional<ResponsePICOBOOT> handle_picoboot(const responder&, const RequestPICOBOOT&) {
|
||||
dispatch_schedule_ms(100, []{ reset_usb_boot(0, 1); });
|
||||
return ResponsePICOBOOT{};
|
||||
@@ -28,3 +33,41 @@ std::optional<ResponseLog> handle_log(const responder&, const RequestLog&) {
|
||||
resp.entries.push_back(LogEntry{e.timestamp_us, std::move(e.message)});
|
||||
return resp;
|
||||
}
|
||||
|
||||
std::optional<ResponseFlashErase> handle_flash_erase(const responder&, const RequestFlashErase& req) {
|
||||
if (req.addr < XIP_BASE_ADDR || req.addr + req.len > XIP_BASE_ADDR + FLASH_SIZE) {
|
||||
dlogf("flash erase: out of range %08lx+%lu",
|
||||
static_cast<unsigned long>(req.addr), static_cast<unsigned long>(req.len));
|
||||
return std::nullopt;
|
||||
}
|
||||
uint32_t offset = req.addr - XIP_BASE_ADDR;
|
||||
if (offset % FLASH_SECTOR_SIZE != 0 || req.len % FLASH_SECTOR_SIZE != 0 || req.len == 0) {
|
||||
dlogf("flash erase: bad alignment %08lx+%lu",
|
||||
static_cast<unsigned long>(req.addr), static_cast<unsigned long>(req.len));
|
||||
return std::nullopt;
|
||||
}
|
||||
flash_range_erase(offset, req.len);
|
||||
return ResponseFlashErase{};
|
||||
}
|
||||
|
||||
std::optional<ResponseFlashWrite> handle_flash_write(const responder&, const RequestFlashWrite& req) {
|
||||
if (req.addr < XIP_BASE_ADDR || req.addr + req.data.size() > XIP_BASE_ADDR + FLASH_SIZE) {
|
||||
dlogf("flash write: out of range %08lx+%zu",
|
||||
static_cast<unsigned long>(req.addr), req.data.size());
|
||||
return std::nullopt;
|
||||
}
|
||||
uint32_t offset = req.addr - XIP_BASE_ADDR;
|
||||
if (offset % FLASH_PAGE_SIZE != 0 || req.data.size() % FLASH_PAGE_SIZE != 0 || req.data.empty()) {
|
||||
dlogf("flash write: bad alignment %08lx+%zu",
|
||||
static_cast<unsigned long>(req.addr), req.data.size());
|
||||
return std::nullopt;
|
||||
}
|
||||
flash_range_program(offset, req.data.data(), req.data.size());
|
||||
return ResponseFlashWrite{};
|
||||
}
|
||||
|
||||
std::optional<ResponseReboot> handle_reboot(const responder&, const RequestReboot&) {
|
||||
dispatch_schedule_ms(100, []{ watchdog_reboot(0, 0, 0); });
|
||||
return ResponseReboot{};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user