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]
|
[dependencies]
|
||||||
rocket = "0.5.0-rc.2"
|
rocket = "0.5.0-rc.2"
|
||||||
espflash = { rev = "55bce336c6718c1c7f019e4da718f97c8cdf1b95", git = "https://github.com/esp-rs/espflash" }
|
espflash = "2.0.0-rc.1"
|
||||||
clap = { version = "4.1.4", features = ["env", "derive"] }
|
esp-idf-part = "0.1.1"
|
||||||
opener = "0.5.2"
|
clap = { version = "3.1.18", features=["env", "derive"] }
|
||||||
anyhow = "1.0.69"
|
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 std::{path::PathBuf, time::Duration};
|
||||||
|
|
||||||
use clap::Parser;
|
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};
|
use rocket::{response::content, State};
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
@ -47,6 +48,19 @@ fn index() -> content::RawHtml<&'static str> {
|
|||||||
content::RawHtml(
|
content::RawHtml(
|
||||||
"
|
"
|
||||||
<html>
|
<html>
|
||||||
|
<head>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background-color: #cdcdcd;
|
||||||
|
font-family: Arial, Helvetica, sans-serif;
|
||||||
|
color: #343434;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
margin-left: 40px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<center>
|
<center>
|
||||||
<h1>ESP Web Flasher</h1>
|
<h1>ESP Web Flasher</h1>
|
||||||
@ -58,7 +72,9 @@ fn index() -> content::RawHtml<&'static str> {
|
|||||||
</script>
|
</script>
|
||||||
<esp-web-install-button id=\"installButton\" manifest=\"manifest.json\"></esp-web-install-button>
|
<esp-web-install-button id=\"installButton\" manifest=\"manifest.json\"></esp-web-install-button>
|
||||||
<br>
|
<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>
|
||||||
<div id=\"notSupported\" style=\"display: none;\">
|
<div id=\"notSupported\" style=\"display: none;\">
|
||||||
Your browser does not support the Web Serial API. Try Chrome
|
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",
|
"chipFamily": "ESP32-S2",
|
||||||
"parts": [
|
"parts": [
|
||||||
@ -164,7 +197,7 @@ fn manifest() -> content::RawJson<&'static str> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct PartsData {
|
struct PartsData {
|
||||||
chip: String,
|
_chip: String,
|
||||||
bootloader: Vec<u8>,
|
bootloader: Vec<u8>,
|
||||||
partitions: Vec<u8>,
|
partitions: Vec<u8>,
|
||||||
firmware: Vec<u8>,
|
firmware: Vec<u8>,
|
||||||
@ -174,6 +207,7 @@ fn prepare() -> Result<PartsData> {
|
|||||||
let opts = Args::parse();
|
let opts = Args::parse();
|
||||||
|
|
||||||
let elf = std::fs::read(opts.elf)?;
|
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 {
|
let p = if let Some(p) = &opts.partition_table {
|
||||||
Some(PartitionTable::try_from_bytes(std::fs::read(p)?)?)
|
Some(PartitionTable::try_from_bytes(std::fs::read(p)?)?)
|
||||||
@ -187,9 +221,7 @@ fn prepare() -> Result<PartsData> {
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let firmware = FirmwareImageBuilder::new(&elf)
|
let firmware = ElfFirmwareImage::new(elf);
|
||||||
.flash_size(Some(FlashSize::Flash4Mb)) // TODO make configurable
|
|
||||||
.build()?;
|
|
||||||
|
|
||||||
let chip = opts.chip;
|
let chip = opts.chip;
|
||||||
let chip_name = match chip {
|
let chip_name = match chip {
|
||||||
@ -198,16 +230,26 @@ fn prepare() -> Result<PartsData> {
|
|||||||
Chip::Esp32s2 => "ESP32-S2",
|
Chip::Esp32s2 => "ESP32-S2",
|
||||||
Chip::Esp32s3 => "ESP32-S3",
|
Chip::Esp32s3 => "ESP32-S3",
|
||||||
Chip::Esp8266 => "ESP8266",
|
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 parts: Vec<_> = image.flash_segments().collect();
|
||||||
let bootloader = &parts[0];
|
let bootloader = &parts[0];
|
||||||
let partitions = &parts[1];
|
let partitions = &parts[1];
|
||||||
let app = &parts[2];
|
let app = &parts[2];
|
||||||
|
|
||||||
Ok(PartsData {
|
Ok(PartsData {
|
||||||
chip: chip_name.to_string(),
|
_chip: chip_name.to_string(),
|
||||||
bootloader: bootloader.data.to_vec(),
|
bootloader: bootloader.data.to_vec(),
|
||||||
partitions: partitions.data.to_vec(),
|
partitions: partitions.data.to_vec(),
|
||||||
firmware: app.data.to_vec(),
|
firmware: app.data.to_vec(),
|
||||||
|
Loading…
Reference in New Issue
Block a user