diff --git a/esp32c3-hal/Cargo.toml b/esp32c3-hal/Cargo.toml index 7068620b68..8749e63f4d 100644 --- a/esp32c3-hal/Cargo.toml +++ b/esp32c3-hal/Cargo.toml @@ -44,7 +44,7 @@ smart-leds = "0.3" esp-println = { version = "0.2.0", features = ["esp32c3"] } [features] -default = ["idfboot", "rt", "vectored"] +default = ["mcuboot", "rt", "vectored"] idfboot = [] mcuboot = [] direct-boot = [] diff --git a/esp32c3-hal/mcuboot-esp32c3.bin b/esp32c3-hal/mcuboot-esp32c3.bin new file mode 100644 index 0000000000..b4057a2db4 Binary files /dev/null and b/esp32c3-hal/mcuboot-esp32c3.bin differ diff --git a/esp32c3-hal/src/lib.rs b/esp32c3-hal/src/lib.rs index cf391b1656..986f30b203 100644 --- a/esp32c3-hal/src/lib.rs +++ b/esp32c3-hal/src/lib.rs @@ -69,6 +69,7 @@ extern "C" { num: u32, fixed: u32, ) -> i32; + fn esp_rom_printf(format: *const u8, ...) -> i32; /* IROM metadata: * - Destination address (VMA) for IROM region @@ -409,6 +410,9 @@ pub fn mp_hook() -> bool { #[cfg(feature = "mcuboot")] unsafe { configure_mmu(); + + static MESSAGE: &[u8] = b"Welcome to Rust from MCUboot!\n\0"; + esp_rom_printf(MESSAGE.as_ptr()); } unsafe { diff --git a/esp32c3-hal/test_mcuboot.sh b/esp32c3-hal/test_mcuboot.sh new file mode 100755 index 0000000000..6a34c5ab63 --- /dev/null +++ b/esp32c3-hal/test_mcuboot.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +# +# Copyright (c) 2022 Espressif Systems (Shanghai) Co., Ltd. +# +# SPDX-License-Identifier: Apache-2.0 +# + +SCRIPT_NAME=$(basename "${BASH_SOURCE[0]}") + +set -eo pipefail + +usage() { + echo "" + echo "USAGE: ${SCRIPT_NAME} " + echo "" +} + +if [ -z "${1}" ]; then + echo "ERROR: Missing application ELF file." + usage + exit 1 +fi + +# MCUboot's tool for image signing and key management +if ! command -v imgtool &> /dev/null; then + echo "" + echo "imgtool not found. Please run: \"pip install imgtool\"" + echo "" + exit 1 +fi + +elf_file=${1} + +objcopy -O ihex "${elf_file}" app.hex +imgtool sign --pad --align 4 -v 0 -s auto -H 32 --pad-header -S 0x100000 app.hex app.bin +esptool.py -c esp32c3 -p /dev/ttyUSB0 -b 921600 --after no_reset write_flash -fs 4MB -fm dio -ff 40m 0x0 ./mcuboot-esp32c3.bin 0x110000 ./app.bin +picocom -b 115200 /dev/ttyUSB0 --imap lfcrlf