|
1 | 1 | use anyhow::{anyhow, bail, Context};
|
2 | 2 | use cargo_metadata::Message;
|
3 | 3 | use clap::{App, Arg, SubCommand};
|
4 |
| -use espflash::{Config, Flasher}; |
| 4 | +use espflash::{Config, Flasher, PartitionTable}; |
5 | 5 | use serial::{BaudRate, SerialPort};
|
6 | 6 |
|
7 | 7 | use std::{
|
8 |
| - fs::read, |
| 8 | + fs, |
9 | 9 | path::PathBuf,
|
10 | 10 | process::{exit, Command, ExitStatus, Stdio},
|
11 | 11 | string::ToString,
|
@@ -51,6 +51,13 @@ fn main() -> anyhow::Result<()> {
|
51 | 51 | .value_name("FEATURES")
|
52 | 52 | .help("Comma delimited list of build features"),
|
53 | 53 | )
|
| 54 | + .arg( |
| 55 | + Arg::with_name("partition_table") |
| 56 | + .long("partition-table") |
| 57 | + .takes_value(true) |
| 58 | + .value_name("PATH") |
| 59 | + .help("Path to a CSV file containing partition table"), |
| 60 | + ) |
54 | 61 | .arg(
|
55 | 62 | Arg::with_name("speed")
|
56 | 63 | .long("speed")
|
@@ -128,12 +135,26 @@ fn main() -> anyhow::Result<()> {
|
128 | 135 | return Ok(());
|
129 | 136 | }
|
130 | 137 |
|
| 138 | + // If the '--partition-table' option is provided, load the partition table from |
| 139 | + // the CSV at the specified path. |
| 140 | + let partition_table = if let Some(path) = matches.value_of("partition_table") { |
| 141 | + let path = fs::canonicalize(path)?; |
| 142 | + let data = fs::read_to_string(path)?; |
| 143 | + |
| 144 | + match PartitionTable::try_from_str(data) { |
| 145 | + Ok(t) => Some(t), |
| 146 | + Err(e) => bail!("{}", e), |
| 147 | + } |
| 148 | + } else { |
| 149 | + None |
| 150 | + }; |
| 151 | + |
131 | 152 | // Read the ELF data from the build path and load it to the target.
|
132 |
| - let elf_data = read(path.unwrap())?; |
| 153 | + let elf_data = fs::read(path.unwrap())?; |
133 | 154 | if matches.is_present("ram") {
|
134 | 155 | flasher.load_elf_to_ram(&elf_data)?;
|
135 | 156 | } else {
|
136 |
| - flasher.load_elf_to_flash(&elf_data)?; |
| 157 | + flasher.load_elf_to_flash(&elf_data, partition_table)?; |
137 | 158 | }
|
138 | 159 |
|
139 | 160 | // We're all done!
|
|
0 commit comments