Fix parsing xml from firehose#14
Conversation
daae138 to
5d979ed
Compare
|
Huh, interesting.. the spec doesn't really enforce there's only a single XML per transfer, but this hasn't been an issue on devices I've tested so far. Could you share some details about your setup? |
|
Hi @quic-kdybcio ! Yes my board is based on sa8155p, when I try to flash with this tool I noticed that it failed and I investigated, what i noticed is that I received multiple xml on one transfer. I do not know the spec of firehose and I'm not so expert on that. Maybe is an edge case. If you need some specific test I can try. QDL and QFIL never failed by the way so i think that they handle that. |
|
@gfabiano I came up with this diff to reduce copying and loosen the encoding/whitespace requirements, I only compile-tested it - can you give it a shot? index b15029b89f04..16960e8e8930 100644
--- a/qdl/src/lib.rs
+++ b/qdl/src/lib.rs
@@ -9,6 +9,7 @@ use serial::setup_serial_device;
use std::cmp::min;
use std::io::Read;
use std::io::Write;
+use std::str;
use std::str::FromStr;
use types::FirehoseResetMode;
use types::FirehoseStatus;
@@ -96,15 +97,13 @@ pub fn firehose_read<T: Read + Write + QdlChan>(
got_any_data = true;
- let xml_declaration = r#"<?xml version="1.0" encoding="UTF-8" ?>"#;
let xml_fragments: Vec<&str> = str::from_utf8(&buf[..bytes_read])?
- .split(xml_declaration)
+ .split_inclusive("<?xml")
.filter(|s| !s.is_empty())
.collect();
for fragment in xml_fragments.iter() {
- let full_xml_string = format!("{}{}", xml_declaration, fragment);
- let xml = xmltree::Element::parse(full_xml_string.as_bytes())?;
+ let xml = xmltree::Element::parse(fragment.as_bytes())?;
if xml.name != "data" {
// TODO: define a more verbose level
@@ -113,7 +112,7 @@ pub fn firehose_read<T: Read + Write + QdlChan>(
}
bail!("Got a firehose packet without a data tag");
}
-
+
// The spec expects there's always a single node only
if let Some(XMLNode::Element(e)) = xml.children.first() {
// Check for a 'log' node and print out the message |
|
Yes for sure, I fetch and try to flash something |
|
Hi @quic-kdybcio, split_inclusive unfortunately add the delimiter not in the right place. So I modified the implementation to use indexes and slices to better optimize and avoid unintended copies. I flashed without problems on my board. Give me some feedback if it is ok or it needs reworks. |
|
I solved the feedback as requested |
… on the same data transfer Signed-off-by: Giuseppe Fabiano <gfabiano40@gmail.com>
dac9e0d to
50a4659
Compare
|
Squashed your commits and resolved a cosmetic merge conflit - now just waiting for CI to run |
Fix parsing xml from firehose when multiple xml are sent sequentially on the same data transfer.