// SPDX-License-Identifier: GPL-3.0-or-later #pragma once #include "config_export.h" #include // Transport/file bounds and STM32 vector sanity, not a signature or a board-ID // proof. Hardware and target version remain operator declarations for raw BIN. static QJsonObject inspectFirmwareImage(const QByteArray &raw, const QString &kind) { require(kind == "firmware" || kind == "bootloader", "Unknown image kind"); const int bound = kind == "bootloader" ? 65536 : 2 * 1024 * 1024; require(raw.size() >= 256 && raw.size() <= bound, "Image size outside the supported bound"); // This upload profile accepts raw STM32 BIN only. Encoded/compressed/Intel // HEX files must be deliberately converted by their owning Tool first. const auto sp = qFromLittleEndian(raw.constData()); const auto reset = qFromLittleEndian(raw.constData() + 4); require(sp >= 0x20000000 && sp <= 0x20040000 && (sp & 3) == 0, "Raw STM32 image has an invalid initial stack pointer"); require((reset & 1) && reset >= 0x08000001 && reset < 0x08200000, "Raw STM32 image has an invalid reset vector"); // fwUpload owns normalization. Require that it leaves this raw image intact // so the reviewed hash describes exactly the bytes passed to the uploader. require(Packet::crc16(reinterpret_cast(raw.constData()+6), raw.size()-6) != qFromBigEndian(raw.constData()+4), "Wrapped firmware is not a raw BIN image"); return {{"kind", kind}, {"bytes", raw.size()}, {"sha256", sha256(raw)}, {"format", "raw-stm32-bin"}, {"board_identity_embedded", false}}; }