Skip to content

Commit baba78e

Browse files
committed
esp32c3: Add MCUboot support files for testing
Signed-off-by: Gustavo Henrique Nihei <[email protected]>
1 parent 557b21d commit baba78e

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

esp32c3-hal/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ smart-leds = "0.3"
4444
esp-println = { version = "0.2.0", features = ["esp32c3"] }
4545

4646
[features]
47-
default = ["idfboot", "rt"]
47+
default = ["mcuboot", "rt"]
4848
idfboot = []
4949
mcuboot = []
5050
direct-boot = []

esp32c3-hal/mcuboot-esp32c3.bin

20.3 KB
Binary file not shown.

esp32c3-hal/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ extern "C" {
5151
num: u32,
5252
fixed: u32,
5353
) -> i32;
54+
fn esp_rom_printf(format: *const u8, ...) -> i32;
5455

5556
/* IROM metadata:
5657
* - Destination address (VMA) for IROM region
@@ -395,6 +396,9 @@ pub fn mp_hook() -> bool {
395396
#[cfg(feature = "mcuboot")]
396397
unsafe {
397398
configure_mmu();
399+
400+
static MESSAGE: &[u8] = b"Welcome to Rust from MCUboot!\n\0";
401+
esp_rom_printf(MESSAGE.as_ptr());
398402
}
399403

400404
unsafe {

esp32c3-hal/test_mcuboot.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright (c) 2022 Espressif Systems (Shanghai) Co., Ltd.
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
#
7+
8+
SCRIPT_NAME=$(basename "${BASH_SOURCE[0]}")
9+
10+
set -eo pipefail
11+
12+
usage() {
13+
echo ""
14+
echo "USAGE: ${SCRIPT_NAME} <ELF>"
15+
echo ""
16+
}
17+
18+
if [ -z "${1}" ]; then
19+
echo "ERROR: Missing application ELF file."
20+
usage
21+
exit 1
22+
fi
23+
24+
# MCUboot's tool for image signing and key management
25+
if ! command -v imgtool &> /dev/null; then
26+
echo ""
27+
echo "imgtool not found. Please run: \"pip install imgtool\""
28+
echo ""
29+
exit 1
30+
fi
31+
32+
elf_file=${1}
33+
34+
objcopy -O ihex "${elf_file}" app.hex
35+
imgtool sign --pad --align 4 -v 0 -s auto -H 32 --pad-header -S 0x100000 app.hex app.bin
36+
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
37+
picocom -b 115200 /dev/ttyUSB0 --imap lfcrlf

0 commit comments

Comments
 (0)