Prepare for espflash 2.0
This commit is contained in:
parent
3b512ffd4c
commit
a62036bc96
1194
Cargo.lock
generated
1194
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
10
Cargo.toml
10
Cargo.toml
@ -5,7 +5,9 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
rocket = "0.5.0-rc.2"
|
||||
espflash = { rev = "55bce336c6718c1c7f019e4da718f97c8cdf1b95", git = "https://github.com/esp-rs/espflash" }
|
||||
clap = { version = "4.1.4", features = ["env", "derive"] }
|
||||
opener = "0.5.2"
|
||||
anyhow = "1.0.69"
|
||||
espflash = "2.0.0-rc.1"
|
||||
esp-idf-part = "0.1.1"
|
||||
clap = { version = "3.1.18", features=["env", "derive"] }
|
||||
opener = "0.5.0"
|
||||
anyhow = "1.0.57"
|
||||
xmas-elf = "0.8.0"
|
||||
|
5
Rocket.toml
Normal file
5
Rocket.toml
Normal file
@ -0,0 +1,5 @@
|
||||
[default.shutdown]
|
||||
ctrlc = true
|
||||
signals = ["term", "hup"]
|
||||
grace = 5
|
||||
mercy = 4
|
58
src/main.rs
58
src/main.rs
@ -3,7 +3,8 @@ use anyhow::Result;
|
||||
use std::{path::PathBuf, time::Duration};
|
||||
|
||||
use clap::Parser;
|
||||
use espflash::{elf::FirmwareImageBuilder, Chip, FlashSize, PartitionTable};
|
||||
use esp_idf_part::PartitionTable;
|
||||
use espflash::{elf::ElfFirmwareImage, flasher::FlashSize::Flash4Mb, targets::Chip};
|
||||
use rocket::{response::content, State};
|
||||
|
||||
#[macro_use]
|
||||
@ -47,6 +48,19 @@ fn index() -> content::RawHtml<&'static str> {
|
||||
content::RawHtml(
|
||||
"
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
body {
|
||||
background-color: #cdcdcd;
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
color: #343434;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin-left: 40px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<center>
|
||||
<h1>ESP Web Flasher</h1>
|
||||
@ -58,7 +72,9 @@ fn index() -> content::RawHtml<&'static str> {
|
||||
</script>
|
||||
<esp-web-install-button id=\"installButton\" manifest=\"manifest.json\"></esp-web-install-button>
|
||||
<br>
|
||||
<span><i>NOTE: Make sure to close anything using your devices com port (e.g. Serial monitor)</i></span>
|
||||
<br>
|
||||
<br>
|
||||
<span><i>NOTE: Make sure to close anything using your device's com port (e.g. serial monitor)</i></span>
|
||||
</div>
|
||||
<div id=\"notSupported\" style=\"display: none;\">
|
||||
Your browser does not support the Web Serial API. Try Chrome
|
||||
@ -123,6 +139,23 @@ fn manifest() -> content::RawJson<&'static str> {
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"chipFamily": "ESP32-C2",
|
||||
"parts": [
|
||||
{
|
||||
"path": "bootloader.bin",
|
||||
"offset": 0
|
||||
},
|
||||
{
|
||||
"path": "partitions.bin",
|
||||
"offset": 32768
|
||||
},
|
||||
{
|
||||
"path": "firmware.bin",
|
||||
"offset": 65536
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"chipFamily": "ESP32-S2",
|
||||
"parts": [
|
||||
@ -164,7 +197,7 @@ fn manifest() -> content::RawJson<&'static str> {
|
||||
}
|
||||
|
||||
struct PartsData {
|
||||
chip: String,
|
||||
_chip: String,
|
||||
bootloader: Vec<u8>,
|
||||
partitions: Vec<u8>,
|
||||
firmware: Vec<u8>,
|
||||
@ -174,6 +207,7 @@ fn prepare() -> Result<PartsData> {
|
||||
let opts = Args::parse();
|
||||
|
||||
let elf = std::fs::read(opts.elf)?;
|
||||
let elf = xmas_elf::ElfFile::new(&elf).expect("Invalid elf file");
|
||||
|
||||
let p = if let Some(p) = &opts.partition_table {
|
||||
Some(PartitionTable::try_from_bytes(std::fs::read(p)?)?)
|
||||
@ -187,9 +221,7 @@ fn prepare() -> Result<PartsData> {
|
||||
None
|
||||
};
|
||||
|
||||
let firmware = FirmwareImageBuilder::new(&elf)
|
||||
.flash_size(Some(FlashSize::Flash4Mb)) // TODO make configurable
|
||||
.build()?;
|
||||
let firmware = ElfFirmwareImage::new(elf);
|
||||
|
||||
let chip = opts.chip;
|
||||
let chip_name = match chip {
|
||||
@ -198,16 +230,26 @@ fn prepare() -> Result<PartsData> {
|
||||
Chip::Esp32s2 => "ESP32-S2",
|
||||
Chip::Esp32s3 => "ESP32-S3",
|
||||
Chip::Esp8266 => "ESP8266",
|
||||
Chip::Esp32c2 => "ESP32-C2",
|
||||
};
|
||||
|
||||
let image = chip.get_flash_image(&firmware, b, p, None, None)?;
|
||||
let image = chip.into_target().get_flash_image(
|
||||
&firmware,
|
||||
b,
|
||||
p,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
Some(Flash4Mb),
|
||||
None,
|
||||
)?;
|
||||
let parts: Vec<_> = image.flash_segments().collect();
|
||||
let bootloader = &parts[0];
|
||||
let partitions = &parts[1];
|
||||
let app = &parts[2];
|
||||
|
||||
Ok(PartsData {
|
||||
chip: chip_name.to_string(),
|
||||
_chip: chip_name.to_string(),
|
||||
bootloader: bootloader.data.to_vec(),
|
||||
partitions: partitions.data.to_vec(),
|
||||
firmware: app.data.to_vec(),
|
||||
|
Loading…
Reference in New Issue
Block a user