diff --git a/espflash/src/cli/serial.rs b/espflash/src/cli/serial.rs index a9ecc610..0fdb8a6d 100644 --- a/espflash/src/cli/serial.rs +++ b/espflash/src/cli/serial.rs @@ -19,12 +19,21 @@ pub fn get_serial_port_info( // select a serial port. If some VID and PID were provided then the user will // also be prompted to select a port, unless there is only one found and its VID // and PID match the configured values. + // + // The call to canonicalize() was originally added to resolve https://github.com/esp-rs/espflash/issues/177, + // however, canonicalize doesn't work (on Windows) with "dummy" device paths like `COM4`. + // That's the reason we need to handle Windows/Posix differently. + let ports = detect_usb_serial_ports().unwrap_or_default(); if let Some(serial) = &matches.serial { - find_serial_port(&ports, &std::fs::canonicalize(serial)?.to_string_lossy()) + #[cfg(not(target_os = "windows"))] + let serial = std::fs::canonicalize(serial)?.to_string_lossy().to_string(); + find_serial_port(&ports, &serial) } else if let Some(serial) = &config.connection.serial { - find_serial_port(&ports, &std::fs::canonicalize(serial)?.to_string_lossy()) + #[cfg(not(target_os = "windows"))] + let serial = std::fs::canonicalize(serial)?.to_string_lossy().to_string(); + find_serial_port(&ports, &serial) } else { let (port, matches) = select_serial_port(ports, config)?; diff --git a/espflash/src/partition_table.rs b/espflash/src/partition_table.rs index 952c98da..d0d82d1c 100644 --- a/espflash/src/partition_table.rs +++ b/espflash/src/partition_table.rs @@ -29,7 +29,7 @@ const MD5_PART_MAGIC_BYTES: &[u8] = &[ ]; const END_MARKER: [u8; 32] = [0xFF; 32]; -#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, BinRead)] +#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq, BinRead)] #[repr(u8)] #[br(little, repr = u8)] #[serde(rename_all = "lowercase")] @@ -62,7 +62,7 @@ impl Display for Type { } } -#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, BinRead)] +#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq, BinRead)] #[repr(u8)] #[br(little, repr = u8)] pub enum AppType { @@ -104,7 +104,7 @@ pub enum AppType { Test = 0x20, } -#[derive(Copy, Clone, Debug, Deserialize, EnumIter, Serialize, PartialEq, BinRead)] +#[derive(Copy, Clone, Debug, Deserialize, EnumIter, Serialize, PartialEq, Eq, BinRead)] #[repr(u8)] #[br(little, repr = u8)] #[serde(rename_all = "lowercase")] @@ -127,7 +127,7 @@ impl DataType { } } -#[derive(Debug, Serialize, Deserialize, PartialEq, Copy, Clone, BinRead)] +#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Copy, Clone, BinRead)] #[serde(untagged)] pub enum SubType { App(AppType), @@ -162,7 +162,7 @@ impl SubType { } } -#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, BinRead)] +#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq, BinRead)] #[repr(u8)] #[br(little, repr = u8)] #[serde(rename_all = "lowercase")]