Replace serial 0.4 with serialport 4 to fix baud rate on modern glibc
Browse filesThe flashing tool failed to connect to the BL602 bootrom on systems
with glibc 2.42 or later. The handshake timed out, because the port
never ran at the requested speed.
Root cause:
glibc 2.42 changed the termios speed API. Speeds are now numeric
values, and the Bxxx code constants (for example B115200 = 0o10002)
are no longer accepted. glibc added new symbol versions for
cfsetispeed/cfsetospeed with these new rules.
The serial 0.4 crate (with termios 0.2) calls these functions without
a symbol version, so it binds to the new default. But it passes the
old-style octal code constant. New glibc treats that value as a
literal speed of 4098 baud and silently ignores the request. The
port stays at a wrong speed, the bootrom auto-baud never locks on,
and every handshake attempt fails.
The serial 0.4 crate is also unmaintained, so this problem would not
get fixed upstream.
Solution:
Replace serial 0.4 with its maintained successor, serialport 4.10.
On Linux, serialport sets the baud rate the modern way: BOTHER flag
with numeric c_ispeed/c_ospeed values. This works on both old and
new glibc, and supports arbitrary baud rates.
Changes:
- blflash/Cargo.toml: replace serial with serialport 4.10.1; disable
default features (libudev is not needed, blflash does not list
ports)
- blflash/src/connection.rs: port to the serialport API. set_rts/
set_dtr become write_request_to_send/write_data_terminal_ready.
BaudRate becomes plain u32. Remove the temporary libc workaround
for the baud rate.
- blflash/src/flasher.rs, lib.rs, error.rs: update signatures for
Box<dyn serialport::SerialPort> and u32 speeds. Error::Serial now
wraps serialport::Error.
- cargo-blflash/Cargo.toml: remove unused serial dependency.
Notes:
- serialport uses flock for exclusive access to the port. If another
process (for example ModemManager) holds the port, the tool now
reports "Unable to acquire exclusive lock on serial port".
- Verified on the BL602: full erase, program, and verify of all
segments at 1 Mbaud, and stty confirms the port is left at the
requested speed.
- Cargo.lock +213 -86
- blflash/Cargo.toml +1 -2
- blflash/src/connection.rs +15 -92
- blflash/src/error.rs +1 -1
- blflash/src/flasher.rs +5 -5
- blflash/src/lib.rs +7 -16
- cargo-blflash/Cargo.toml +0 -1
|
@@ -73,6 +73,12 @@ version = "1.3.2"
|
|
| 73 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 74 |
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
| 75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
[[package]]
|
| 77 |
name = "bitvec"
|
| 78 |
version = "1.0.1"
|
|
@@ -96,16 +102,15 @@ dependencies = [
|
|
| 96 |
"env_logger",
|
| 97 |
"hex",
|
| 98 |
"indicatif",
|
| 99 |
-
"libc",
|
| 100 |
"log",
|
| 101 |
"main_error",
|
| 102 |
"parse_int",
|
| 103 |
"paw",
|
| 104 |
"serde",
|
| 105 |
-
"
|
| 106 |
"sha2",
|
| 107 |
"structopt",
|
| 108 |
-
"thiserror",
|
| 109 |
"toml 0.5.10",
|
| 110 |
"xmas-elf",
|
| 111 |
]
|
|
@@ -141,7 +146,6 @@ dependencies = [
|
|
| 141 |
"env_logger",
|
| 142 |
"main_error",
|
| 143 |
"paw",
|
| 144 |
-
"serial",
|
| 145 |
"structopt",
|
| 146 |
]
|
| 147 |
|
|
@@ -156,7 +160,7 @@ dependencies = [
|
|
| 156 |
"rustc-cfg",
|
| 157 |
"serde",
|
| 158 |
"serde_derive",
|
| 159 |
-
"thiserror",
|
| 160 |
"toml 0.4.10",
|
| 161 |
]
|
| 162 |
|
|
@@ -180,7 +184,7 @@ checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c"
|
|
| 180 |
dependencies = [
|
| 181 |
"ansi_term",
|
| 182 |
"atty",
|
| 183 |
-
"bitflags",
|
| 184 |
"strsim 0.8.0",
|
| 185 |
"textwrap",
|
| 186 |
"unicode-width",
|
|
@@ -223,9 +227,25 @@ dependencies = [
|
|
| 223 |
"encode_unicode",
|
| 224 |
"lazy_static",
|
| 225 |
"libc",
|
| 226 |
-
"windows-sys",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
]
|
| 228 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
[[package]]
|
| 230 |
name = "cpufeatures"
|
| 231 |
version = "0.2.5"
|
|
@@ -275,7 +295,7 @@ dependencies = [
|
|
| 275 |
"proc-macro2",
|
| 276 |
"quote",
|
| 277 |
"strsim 0.10.0",
|
| 278 |
-
"syn",
|
| 279 |
]
|
| 280 |
|
| 281 |
[[package]]
|
|
@@ -286,7 +306,7 @@ checksum = "7618812407e9402654622dd402b0a89dff9ba93badd6540781526117b92aab7e"
|
|
| 286 |
dependencies = [
|
| 287 |
"darling_core",
|
| 288 |
"quote",
|
| 289 |
-
"syn",
|
| 290 |
]
|
| 291 |
|
| 292 |
[[package]]
|
|
@@ -309,7 +329,7 @@ dependencies = [
|
|
| 309 |
"proc-macro-crate",
|
| 310 |
"proc-macro2",
|
| 311 |
"quote",
|
| 312 |
-
"syn",
|
| 313 |
]
|
| 314 |
|
| 315 |
[[package]]
|
|
@@ -470,22 +490,23 @@ dependencies = [
|
|
| 470 |
]
|
| 471 |
|
| 472 |
[[package]]
|
| 473 |
-
name = "io-
|
| 474 |
-
version = "
|
| 475 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 476 |
-
checksum = "
|
| 477 |
dependencies = [
|
| 478 |
-
"
|
| 479 |
-
"
|
| 480 |
]
|
| 481 |
|
| 482 |
[[package]]
|
| 483 |
-
name = "
|
| 484 |
-
version = "
|
| 485 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 486 |
-
checksum = "
|
| 487 |
dependencies = [
|
| 488 |
"libc",
|
|
|
|
| 489 |
]
|
| 490 |
|
| 491 |
[[package]]
|
|
@@ -497,7 +518,7 @@ dependencies = [
|
|
| 497 |
"hermit-abi 0.2.6",
|
| 498 |
"io-lifetimes",
|
| 499 |
"rustix",
|
| 500 |
-
"windows-sys",
|
| 501 |
]
|
| 502 |
|
| 503 |
[[package]]
|
|
@@ -527,6 +548,15 @@ dependencies = [
|
|
| 527 |
"cfg-if",
|
| 528 |
]
|
| 529 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 530 |
[[package]]
|
| 531 |
name = "main_error"
|
| 532 |
version = "0.1.2"
|
|
@@ -548,6 +578,17 @@ dependencies = [
|
|
| 548 |
"adler",
|
| 549 |
]
|
| 550 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 551 |
[[package]]
|
| 552 |
name = "num-traits"
|
| 553 |
version = "0.2.15"
|
|
@@ -611,7 +652,7 @@ checksum = "0f35583365be5d148e959284f42526841917b7bfa09e2d1a7ad5dde2cf0eaa39"
|
|
| 611 |
dependencies = [
|
| 612 |
"proc-macro2",
|
| 613 |
"quote",
|
| 614 |
-
"syn",
|
| 615 |
]
|
| 616 |
|
| 617 |
[[package]]
|
|
@@ -633,7 +674,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
| 633 |
checksum = "eda0fc3b0fb7c975631757e14d9049da17374063edb6ebbcbc54d880d4fe94e9"
|
| 634 |
dependencies = [
|
| 635 |
"once_cell",
|
| 636 |
-
"thiserror",
|
| 637 |
"toml 0.5.10",
|
| 638 |
]
|
| 639 |
|
|
@@ -646,7 +687,7 @@ dependencies = [
|
|
| 646 |
"proc-macro-error-attr",
|
| 647 |
"proc-macro2",
|
| 648 |
"quote",
|
| 649 |
-
"syn",
|
| 650 |
"version_check",
|
| 651 |
]
|
| 652 |
|
|
@@ -663,18 +704,18 @@ dependencies = [
|
|
| 663 |
|
| 664 |
[[package]]
|
| 665 |
name = "proc-macro2"
|
| 666 |
-
version = "1.0.
|
| 667 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 668 |
-
checksum = "
|
| 669 |
dependencies = [
|
| 670 |
"unicode-ident",
|
| 671 |
]
|
| 672 |
|
| 673 |
[[package]]
|
| 674 |
name = "quote"
|
| 675 |
-
version = "1.0.
|
| 676 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 677 |
-
checksum = "
|
| 678 |
dependencies = [
|
| 679 |
"proc-macro2",
|
| 680 |
]
|
|
@@ -708,7 +749,7 @@ version = "0.5.0"
|
|
| 708 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 709 |
checksum = "9ddf7a5e441e8003a5a88aab97f1c6113043ddde252d789ef9dea3871b78633a"
|
| 710 |
dependencies = [
|
| 711 |
-
"thiserror",
|
| 712 |
]
|
| 713 |
|
| 714 |
[[package]]
|
|
@@ -723,14 +764,20 @@ version = "0.36.6"
|
|
| 723 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 724 |
checksum = "4feacf7db682c6c329c4ede12649cd36ecab0f3be5b7d74e6a20304725db4549"
|
| 725 |
dependencies = [
|
| 726 |
-
"bitflags",
|
| 727 |
"errno",
|
| 728 |
"io-lifetimes",
|
| 729 |
"libc",
|
| 730 |
"linux-raw-sys",
|
| 731 |
-
"windows-sys",
|
| 732 |
]
|
| 733 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 734 |
[[package]]
|
| 735 |
name = "serde"
|
| 736 |
version = "1.0.152"
|
|
@@ -748,49 +795,25 @@ checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e"
|
|
| 748 |
dependencies = [
|
| 749 |
"proc-macro2",
|
| 750 |
"quote",
|
| 751 |
-
"syn",
|
| 752 |
-
]
|
| 753 |
-
|
| 754 |
-
[[package]]
|
| 755 |
-
name = "serial"
|
| 756 |
-
version = "0.4.0"
|
| 757 |
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 758 |
-
checksum = "a1237a96570fc377c13baa1b88c7589ab66edced652e43ffb17088f003db3e86"
|
| 759 |
-
dependencies = [
|
| 760 |
-
"serial-core",
|
| 761 |
-
"serial-unix",
|
| 762 |
-
"serial-windows",
|
| 763 |
]
|
| 764 |
|
| 765 |
[[package]]
|
| 766 |
-
name = "
|
| 767 |
-
version = "
|
| 768 |
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 769 |
-
checksum = "3f46209b345401737ae2125fe5b19a77acce90cd53e1658cda928e4fe9a64581"
|
| 770 |
-
dependencies = [
|
| 771 |
-
"libc",
|
| 772 |
-
]
|
| 773 |
-
|
| 774 |
-
[[package]]
|
| 775 |
-
name = "serial-unix"
|
| 776 |
-
version = "0.4.0"
|
| 777 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 778 |
-
checksum = "
|
| 779 |
dependencies = [
|
| 780 |
-
"
|
| 781 |
-
"
|
| 782 |
-
"
|
| 783 |
-
"
|
| 784 |
-
|
| 785 |
-
|
| 786 |
-
|
| 787 |
-
|
| 788 |
-
|
| 789 |
-
|
| 790 |
-
checksum = "15c6d3b776267a75d31bbdfd5d36c0ca051251caafc285827052bc53bcdc8162"
|
| 791 |
-
dependencies = [
|
| 792 |
-
"libc",
|
| 793 |
-
"serial-core",
|
| 794 |
]
|
| 795 |
|
| 796 |
[[package]]
|
|
@@ -847,7 +870,7 @@ dependencies = [
|
|
| 847 |
"proc-macro-error",
|
| 848 |
"proc-macro2",
|
| 849 |
"quote",
|
| 850 |
-
"syn",
|
| 851 |
]
|
| 852 |
|
| 853 |
[[package]]
|
|
@@ -861,6 +884,17 @@ dependencies = [
|
|
| 861 |
"unicode-ident",
|
| 862 |
]
|
| 863 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 864 |
[[package]]
|
| 865 |
name = "tap"
|
| 866 |
version = "1.0.1"
|
|
@@ -876,15 +910,6 @@ dependencies = [
|
|
| 876 |
"winapi-util",
|
| 877 |
]
|
| 878 |
|
| 879 |
-
[[package]]
|
| 880 |
-
name = "termios"
|
| 881 |
-
version = "0.2.2"
|
| 882 |
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 883 |
-
checksum = "d5d9cf598a6d7ce700a4e6a9199da127e6819a61e64b68609683cc9a01b5683a"
|
| 884 |
-
dependencies = [
|
| 885 |
-
"libc",
|
| 886 |
-
]
|
| 887 |
-
|
| 888 |
[[package]]
|
| 889 |
name = "textwrap"
|
| 890 |
version = "0.11.0"
|
|
@@ -900,7 +925,16 @@ version = "1.0.38"
|
|
| 900 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 901 |
checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0"
|
| 902 |
dependencies = [
|
| 903 |
-
"thiserror-impl",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 904 |
]
|
| 905 |
|
| 906 |
[[package]]
|
|
@@ -911,7 +945,18 @@ checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f"
|
|
| 911 |
dependencies = [
|
| 912 |
"proc-macro2",
|
| 913 |
"quote",
|
| 914 |
-
"syn",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 915 |
]
|
| 916 |
|
| 917 |
[[package]]
|
|
@@ -989,6 +1034,15 @@ version = "1.16.0"
|
|
| 989 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 990 |
checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
|
| 991 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 992 |
[[package]]
|
| 993 |
name = "unicode-ident"
|
| 994 |
version = "1.0.6"
|
|
@@ -1062,13 +1116,38 @@ version = "0.42.0"
|
|
| 1062 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1063 |
checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7"
|
| 1064 |
dependencies = [
|
| 1065 |
-
"windows_aarch64_gnullvm",
|
| 1066 |
-
"windows_aarch64_msvc",
|
| 1067 |
-
"windows_i686_gnu",
|
| 1068 |
-
"windows_i686_msvc",
|
| 1069 |
-
"windows_x86_64_gnu",
|
| 1070 |
-
"windows_x86_64_gnullvm",
|
| 1071 |
-
"windows_x86_64_msvc",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1072 |
]
|
| 1073 |
|
| 1074 |
[[package]]
|
|
@@ -1077,42 +1156,90 @@ version = "0.42.1"
|
|
| 1077 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1078 |
checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608"
|
| 1079 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1080 |
[[package]]
|
| 1081 |
name = "windows_aarch64_msvc"
|
| 1082 |
version = "0.42.1"
|
| 1083 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1084 |
checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7"
|
| 1085 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1086 |
[[package]]
|
| 1087 |
name = "windows_i686_gnu"
|
| 1088 |
version = "0.42.1"
|
| 1089 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1090 |
checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640"
|
| 1091 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1092 |
[[package]]
|
| 1093 |
name = "windows_i686_msvc"
|
| 1094 |
version = "0.42.1"
|
| 1095 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1096 |
checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605"
|
| 1097 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1098 |
[[package]]
|
| 1099 |
name = "windows_x86_64_gnu"
|
| 1100 |
version = "0.42.1"
|
| 1101 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1102 |
checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45"
|
| 1103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1104 |
[[package]]
|
| 1105 |
name = "windows_x86_64_gnullvm"
|
| 1106 |
version = "0.42.1"
|
| 1107 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1108 |
checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463"
|
| 1109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1110 |
[[package]]
|
| 1111 |
name = "windows_x86_64_msvc"
|
| 1112 |
version = "0.42.1"
|
| 1113 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1114 |
checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd"
|
| 1115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1116 |
[[package]]
|
| 1117 |
name = "wyz"
|
| 1118 |
version = "0.5.1"
|
|
|
|
| 73 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 74 |
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
| 75 |
|
| 76 |
+
[[package]]
|
| 77 |
+
name = "bitflags"
|
| 78 |
+
version = "2.13.1"
|
| 79 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 80 |
+
checksum = "b588b76d00fde79687d7646a9b5bdf3cc0f655e0bbd080335a95d7e96f3587da"
|
| 81 |
+
|
| 82 |
[[package]]
|
| 83 |
name = "bitvec"
|
| 84 |
version = "1.0.1"
|
|
|
|
| 102 |
"env_logger",
|
| 103 |
"hex",
|
| 104 |
"indicatif",
|
|
|
|
| 105 |
"log",
|
| 106 |
"main_error",
|
| 107 |
"parse_int",
|
| 108 |
"paw",
|
| 109 |
"serde",
|
| 110 |
+
"serialport",
|
| 111 |
"sha2",
|
| 112 |
"structopt",
|
| 113 |
+
"thiserror 1.0.38",
|
| 114 |
"toml 0.5.10",
|
| 115 |
"xmas-elf",
|
| 116 |
]
|
|
|
|
| 146 |
"env_logger",
|
| 147 |
"main_error",
|
| 148 |
"paw",
|
|
|
|
| 149 |
"structopt",
|
| 150 |
]
|
| 151 |
|
|
|
|
| 160 |
"rustc-cfg",
|
| 161 |
"serde",
|
| 162 |
"serde_derive",
|
| 163 |
+
"thiserror 1.0.38",
|
| 164 |
"toml 0.4.10",
|
| 165 |
]
|
| 166 |
|
|
|
|
| 184 |
dependencies = [
|
| 185 |
"ansi_term",
|
| 186 |
"atty",
|
| 187 |
+
"bitflags 1.3.2",
|
| 188 |
"strsim 0.8.0",
|
| 189 |
"textwrap",
|
| 190 |
"unicode-width",
|
|
|
|
| 227 |
"encode_unicode",
|
| 228 |
"lazy_static",
|
| 229 |
"libc",
|
| 230 |
+
"windows-sys 0.42.0",
|
| 231 |
+
]
|
| 232 |
+
|
| 233 |
+
[[package]]
|
| 234 |
+
name = "core-foundation"
|
| 235 |
+
version = "0.10.1"
|
| 236 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 237 |
+
checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6"
|
| 238 |
+
dependencies = [
|
| 239 |
+
"core-foundation-sys",
|
| 240 |
+
"libc",
|
| 241 |
]
|
| 242 |
|
| 243 |
+
[[package]]
|
| 244 |
+
name = "core-foundation-sys"
|
| 245 |
+
version = "0.8.7"
|
| 246 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 247 |
+
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
|
| 248 |
+
|
| 249 |
[[package]]
|
| 250 |
name = "cpufeatures"
|
| 251 |
version = "0.2.5"
|
|
|
|
| 295 |
"proc-macro2",
|
| 296 |
"quote",
|
| 297 |
"strsim 0.10.0",
|
| 298 |
+
"syn 1.0.107",
|
| 299 |
]
|
| 300 |
|
| 301 |
[[package]]
|
|
|
|
| 306 |
dependencies = [
|
| 307 |
"darling_core",
|
| 308 |
"quote",
|
| 309 |
+
"syn 1.0.107",
|
| 310 |
]
|
| 311 |
|
| 312 |
[[package]]
|
|
|
|
| 329 |
"proc-macro-crate",
|
| 330 |
"proc-macro2",
|
| 331 |
"quote",
|
| 332 |
+
"syn 1.0.107",
|
| 333 |
]
|
| 334 |
|
| 335 |
[[package]]
|
|
|
|
| 490 |
]
|
| 491 |
|
| 492 |
[[package]]
|
| 493 |
+
name = "io-kit-sys"
|
| 494 |
+
version = "0.4.1"
|
| 495 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 496 |
+
checksum = "617ee6cf8e3f66f3b4ea67a4058564628cde41901316e19f559e14c7c72c5e7b"
|
| 497 |
dependencies = [
|
| 498 |
+
"core-foundation-sys",
|
| 499 |
+
"mach2",
|
| 500 |
]
|
| 501 |
|
| 502 |
[[package]]
|
| 503 |
+
name = "io-lifetimes"
|
| 504 |
+
version = "1.0.4"
|
| 505 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 506 |
+
checksum = "e7d6c6f8c91b4b9ed43484ad1a938e393caf35960fce7f82a040497207bd8e9e"
|
| 507 |
dependencies = [
|
| 508 |
"libc",
|
| 509 |
+
"windows-sys 0.42.0",
|
| 510 |
]
|
| 511 |
|
| 512 |
[[package]]
|
|
|
|
| 518 |
"hermit-abi 0.2.6",
|
| 519 |
"io-lifetimes",
|
| 520 |
"rustix",
|
| 521 |
+
"windows-sys 0.42.0",
|
| 522 |
]
|
| 523 |
|
| 524 |
[[package]]
|
|
|
|
| 548 |
"cfg-if",
|
| 549 |
]
|
| 550 |
|
| 551 |
+
[[package]]
|
| 552 |
+
name = "mach2"
|
| 553 |
+
version = "0.4.3"
|
| 554 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 555 |
+
checksum = "d640282b302c0bb0a2a8e0233ead9035e3bed871f0b7e81fe4a1ec829765db44"
|
| 556 |
+
dependencies = [
|
| 557 |
+
"libc",
|
| 558 |
+
]
|
| 559 |
+
|
| 560 |
[[package]]
|
| 561 |
name = "main_error"
|
| 562 |
version = "0.1.2"
|
|
|
|
| 578 |
"adler",
|
| 579 |
]
|
| 580 |
|
| 581 |
+
[[package]]
|
| 582 |
+
name = "nix"
|
| 583 |
+
version = "0.26.4"
|
| 584 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 585 |
+
checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b"
|
| 586 |
+
dependencies = [
|
| 587 |
+
"bitflags 1.3.2",
|
| 588 |
+
"cfg-if",
|
| 589 |
+
"libc",
|
| 590 |
+
]
|
| 591 |
+
|
| 592 |
[[package]]
|
| 593 |
name = "num-traits"
|
| 594 |
version = "0.2.15"
|
|
|
|
| 652 |
dependencies = [
|
| 653 |
"proc-macro2",
|
| 654 |
"quote",
|
| 655 |
+
"syn 1.0.107",
|
| 656 |
]
|
| 657 |
|
| 658 |
[[package]]
|
|
|
|
| 674 |
checksum = "eda0fc3b0fb7c975631757e14d9049da17374063edb6ebbcbc54d880d4fe94e9"
|
| 675 |
dependencies = [
|
| 676 |
"once_cell",
|
| 677 |
+
"thiserror 1.0.38",
|
| 678 |
"toml 0.5.10",
|
| 679 |
]
|
| 680 |
|
|
|
|
| 687 |
"proc-macro-error-attr",
|
| 688 |
"proc-macro2",
|
| 689 |
"quote",
|
| 690 |
+
"syn 1.0.107",
|
| 691 |
"version_check",
|
| 692 |
]
|
| 693 |
|
|
|
|
| 704 |
|
| 705 |
[[package]]
|
| 706 |
name = "proc-macro2"
|
| 707 |
+
version = "1.0.107"
|
| 708 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 709 |
+
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
|
| 710 |
dependencies = [
|
| 711 |
"unicode-ident",
|
| 712 |
]
|
| 713 |
|
| 714 |
[[package]]
|
| 715 |
name = "quote"
|
| 716 |
+
version = "1.0.47"
|
| 717 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 718 |
+
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
|
| 719 |
dependencies = [
|
| 720 |
"proc-macro2",
|
| 721 |
]
|
|
|
|
| 749 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 750 |
checksum = "9ddf7a5e441e8003a5a88aab97f1c6113043ddde252d789ef9dea3871b78633a"
|
| 751 |
dependencies = [
|
| 752 |
+
"thiserror 1.0.38",
|
| 753 |
]
|
| 754 |
|
| 755 |
[[package]]
|
|
|
|
| 764 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 765 |
checksum = "4feacf7db682c6c329c4ede12649cd36ecab0f3be5b7d74e6a20304725db4549"
|
| 766 |
dependencies = [
|
| 767 |
+
"bitflags 1.3.2",
|
| 768 |
"errno",
|
| 769 |
"io-lifetimes",
|
| 770 |
"libc",
|
| 771 |
"linux-raw-sys",
|
| 772 |
+
"windows-sys 0.42.0",
|
| 773 |
]
|
| 774 |
|
| 775 |
+
[[package]]
|
| 776 |
+
name = "scopeguard"
|
| 777 |
+
version = "1.2.0"
|
| 778 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 779 |
+
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
| 780 |
+
|
| 781 |
[[package]]
|
| 782 |
name = "serde"
|
| 783 |
version = "1.0.152"
|
|
|
|
| 795 |
dependencies = [
|
| 796 |
"proc-macro2",
|
| 797 |
"quote",
|
| 798 |
+
"syn 1.0.107",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 799 |
]
|
| 800 |
|
| 801 |
[[package]]
|
| 802 |
+
name = "serialport"
|
| 803 |
+
version = "4.10.1"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 804 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 805 |
+
checksum = "6ba5f8f29aa20853c4e3e85a33ec580eb66be1f057142e77a333834a318bacf2"
|
| 806 |
dependencies = [
|
| 807 |
+
"bitflags 2.13.1",
|
| 808 |
+
"cfg-if",
|
| 809 |
+
"core-foundation",
|
| 810 |
+
"core-foundation-sys",
|
| 811 |
+
"io-kit-sys",
|
| 812 |
+
"mach2",
|
| 813 |
+
"nix",
|
| 814 |
+
"scopeguard",
|
| 815 |
+
"unescaper",
|
| 816 |
+
"windows-sys 0.52.0",
|
|
|
|
|
|
|
|
|
|
|
|
|
| 817 |
]
|
| 818 |
|
| 819 |
[[package]]
|
|
|
|
| 870 |
"proc-macro-error",
|
| 871 |
"proc-macro2",
|
| 872 |
"quote",
|
| 873 |
+
"syn 1.0.107",
|
| 874 |
]
|
| 875 |
|
| 876 |
[[package]]
|
|
|
|
| 884 |
"unicode-ident",
|
| 885 |
]
|
| 886 |
|
| 887 |
+
[[package]]
|
| 888 |
+
name = "syn"
|
| 889 |
+
version = "3.0.5"
|
| 890 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 891 |
+
checksum = "12df2e0110f65b775f769bb17ef989067a1d931b2eb822bd4346631eeada89f9"
|
| 892 |
+
dependencies = [
|
| 893 |
+
"proc-macro2",
|
| 894 |
+
"quote",
|
| 895 |
+
"unicode-ident",
|
| 896 |
+
]
|
| 897 |
+
|
| 898 |
[[package]]
|
| 899 |
name = "tap"
|
| 900 |
version = "1.0.1"
|
|
|
|
| 910 |
"winapi-util",
|
| 911 |
]
|
| 912 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 913 |
[[package]]
|
| 914 |
name = "textwrap"
|
| 915 |
version = "0.11.0"
|
|
|
|
| 925 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 926 |
checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0"
|
| 927 |
dependencies = [
|
| 928 |
+
"thiserror-impl 1.0.38",
|
| 929 |
+
]
|
| 930 |
+
|
| 931 |
+
[[package]]
|
| 932 |
+
name = "thiserror"
|
| 933 |
+
version = "2.0.20"
|
| 934 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 935 |
+
checksum = "ec86235f5fcc2a73650310756d2ac5b138a5780bbbdfae3eeccec992c435ba4f"
|
| 936 |
+
dependencies = [
|
| 937 |
+
"thiserror-impl 2.0.20",
|
| 938 |
]
|
| 939 |
|
| 940 |
[[package]]
|
|
|
|
| 945 |
dependencies = [
|
| 946 |
"proc-macro2",
|
| 947 |
"quote",
|
| 948 |
+
"syn 1.0.107",
|
| 949 |
+
]
|
| 950 |
+
|
| 951 |
+
[[package]]
|
| 952 |
+
name = "thiserror-impl"
|
| 953 |
+
version = "2.0.20"
|
| 954 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 955 |
+
checksum = "bc04cd3e1236dd4a98afca4569f2deb3f120e5422a4023be2cb683f8486292af"
|
| 956 |
+
dependencies = [
|
| 957 |
+
"proc-macro2",
|
| 958 |
+
"quote",
|
| 959 |
+
"syn 3.0.5",
|
| 960 |
]
|
| 961 |
|
| 962 |
[[package]]
|
|
|
|
| 1034 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1035 |
checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
|
| 1036 |
|
| 1037 |
+
[[package]]
|
| 1038 |
+
name = "unescaper"
|
| 1039 |
+
version = "0.1.10"
|
| 1040 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1041 |
+
checksum = "7285e83a80ce76f5e7bce79fa41f68d78ba62d1003cf27bf748ab24413808cf4"
|
| 1042 |
+
dependencies = [
|
| 1043 |
+
"thiserror 2.0.20",
|
| 1044 |
+
]
|
| 1045 |
+
|
| 1046 |
[[package]]
|
| 1047 |
name = "unicode-ident"
|
| 1048 |
version = "1.0.6"
|
|
|
|
| 1116 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1117 |
checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7"
|
| 1118 |
dependencies = [
|
| 1119 |
+
"windows_aarch64_gnullvm 0.42.1",
|
| 1120 |
+
"windows_aarch64_msvc 0.42.1",
|
| 1121 |
+
"windows_i686_gnu 0.42.1",
|
| 1122 |
+
"windows_i686_msvc 0.42.1",
|
| 1123 |
+
"windows_x86_64_gnu 0.42.1",
|
| 1124 |
+
"windows_x86_64_gnullvm 0.42.1",
|
| 1125 |
+
"windows_x86_64_msvc 0.42.1",
|
| 1126 |
+
]
|
| 1127 |
+
|
| 1128 |
+
[[package]]
|
| 1129 |
+
name = "windows-sys"
|
| 1130 |
+
version = "0.52.0"
|
| 1131 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1132 |
+
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
|
| 1133 |
+
dependencies = [
|
| 1134 |
+
"windows-targets",
|
| 1135 |
+
]
|
| 1136 |
+
|
| 1137 |
+
[[package]]
|
| 1138 |
+
name = "windows-targets"
|
| 1139 |
+
version = "0.52.6"
|
| 1140 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1141 |
+
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
|
| 1142 |
+
dependencies = [
|
| 1143 |
+
"windows_aarch64_gnullvm 0.52.6",
|
| 1144 |
+
"windows_aarch64_msvc 0.52.6",
|
| 1145 |
+
"windows_i686_gnu 0.52.6",
|
| 1146 |
+
"windows_i686_gnullvm",
|
| 1147 |
+
"windows_i686_msvc 0.52.6",
|
| 1148 |
+
"windows_x86_64_gnu 0.52.6",
|
| 1149 |
+
"windows_x86_64_gnullvm 0.52.6",
|
| 1150 |
+
"windows_x86_64_msvc 0.52.6",
|
| 1151 |
]
|
| 1152 |
|
| 1153 |
[[package]]
|
|
|
|
| 1156 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1157 |
checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608"
|
| 1158 |
|
| 1159 |
+
[[package]]
|
| 1160 |
+
name = "windows_aarch64_gnullvm"
|
| 1161 |
+
version = "0.52.6"
|
| 1162 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1163 |
+
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
|
| 1164 |
+
|
| 1165 |
[[package]]
|
| 1166 |
name = "windows_aarch64_msvc"
|
| 1167 |
version = "0.42.1"
|
| 1168 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1169 |
checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7"
|
| 1170 |
|
| 1171 |
+
[[package]]
|
| 1172 |
+
name = "windows_aarch64_msvc"
|
| 1173 |
+
version = "0.52.6"
|
| 1174 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1175 |
+
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
|
| 1176 |
+
|
| 1177 |
[[package]]
|
| 1178 |
name = "windows_i686_gnu"
|
| 1179 |
version = "0.42.1"
|
| 1180 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1181 |
checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640"
|
| 1182 |
|
| 1183 |
+
[[package]]
|
| 1184 |
+
name = "windows_i686_gnu"
|
| 1185 |
+
version = "0.52.6"
|
| 1186 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1187 |
+
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
|
| 1188 |
+
|
| 1189 |
+
[[package]]
|
| 1190 |
+
name = "windows_i686_gnullvm"
|
| 1191 |
+
version = "0.52.6"
|
| 1192 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1193 |
+
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
|
| 1194 |
+
|
| 1195 |
[[package]]
|
| 1196 |
name = "windows_i686_msvc"
|
| 1197 |
version = "0.42.1"
|
| 1198 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1199 |
checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605"
|
| 1200 |
|
| 1201 |
+
[[package]]
|
| 1202 |
+
name = "windows_i686_msvc"
|
| 1203 |
+
version = "0.52.6"
|
| 1204 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1205 |
+
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
|
| 1206 |
+
|
| 1207 |
[[package]]
|
| 1208 |
name = "windows_x86_64_gnu"
|
| 1209 |
version = "0.42.1"
|
| 1210 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1211 |
checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45"
|
| 1212 |
|
| 1213 |
+
[[package]]
|
| 1214 |
+
name = "windows_x86_64_gnu"
|
| 1215 |
+
version = "0.52.6"
|
| 1216 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1217 |
+
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
|
| 1218 |
+
|
| 1219 |
[[package]]
|
| 1220 |
name = "windows_x86_64_gnullvm"
|
| 1221 |
version = "0.42.1"
|
| 1222 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1223 |
checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463"
|
| 1224 |
|
| 1225 |
+
[[package]]
|
| 1226 |
+
name = "windows_x86_64_gnullvm"
|
| 1227 |
+
version = "0.52.6"
|
| 1228 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1229 |
+
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
|
| 1230 |
+
|
| 1231 |
[[package]]
|
| 1232 |
name = "windows_x86_64_msvc"
|
| 1233 |
version = "0.42.1"
|
| 1234 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1235 |
checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd"
|
| 1236 |
|
| 1237 |
+
[[package]]
|
| 1238 |
+
name = "windows_x86_64_msvc"
|
| 1239 |
+
version = "0.52.6"
|
| 1240 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1241 |
+
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
| 1242 |
+
|
| 1243 |
[[package]]
|
| 1244 |
name = "wyz"
|
| 1245 |
version = "0.5.1"
|
|
@@ -15,8 +15,7 @@ path = "src/main.rs"
|
|
| 15 |
[lib]
|
| 16 |
|
| 17 |
[dependencies]
|
| 18 |
-
|
| 19 |
-
libc = "0.2"
|
| 20 |
xmas-elf = "0.9.0"
|
| 21 |
main_error = "0.1.1"
|
| 22 |
serde = { version = "1.0", features = ["derive"] }
|
|
|
|
| 15 |
[lib]
|
| 16 |
|
| 17 |
[dependencies]
|
| 18 |
+
serialport = { version = "4.10.1", default-features = false }
|
|
|
|
| 19 |
xmas-elf = "0.9.0"
|
| 20 |
main_error = "0.1.1"
|
| 21 |
serde = { version = "1.0", features = ["derive"] }
|
|
@@ -7,9 +7,9 @@ use std::io::{Cursor, Read, Write};
|
|
| 7 |
use std::thread::sleep;
|
| 8 |
use std::time::Duration;
|
| 9 |
|
| 10 |
-
use
|
| 11 |
|
| 12 |
-
pub const DEFAULT_BAUDRATE:
|
| 13 |
|
| 14 |
macro_rules! impl_command(
|
| 15 |
($id: expr, $t:ty, $r:ty) => (
|
|
@@ -60,17 +60,14 @@ pub trait Command: DekuContainerWrite {
|
|
| 60 |
|
| 61 |
pub struct Connection {
|
| 62 |
serial: Box<dyn SerialPort>,
|
| 63 |
-
baud_rate: Option<
|
| 64 |
-
fd: std::os::unix::io::RawFd,
|
| 65 |
}
|
| 66 |
|
| 67 |
impl Connection {
|
| 68 |
-
pub fn new(serial:
|
| 69 |
-
let fd = serial.as_raw_fd();
|
| 70 |
Connection {
|
| 71 |
-
serial
|
| 72 |
baud_rate: None,
|
| 73 |
-
fd,
|
| 74 |
}
|
| 75 |
}
|
| 76 |
|
|
@@ -79,24 +76,24 @@ impl Connection {
|
|
| 79 |
}
|
| 80 |
|
| 81 |
pub fn reset(&mut self) -> Result<(), Error> {
|
| 82 |
-
self.serial.
|
| 83 |
sleep(Duration::from_millis(50));
|
| 84 |
-
self.serial.
|
| 85 |
sleep(Duration::from_millis(50));
|
| 86 |
-
self.serial.
|
| 87 |
sleep(Duration::from_millis(50));
|
| 88 |
|
| 89 |
Ok(())
|
| 90 |
}
|
| 91 |
|
| 92 |
pub fn reset_to_flash(&mut self) -> Result<(), Error> {
|
| 93 |
-
self.serial.
|
| 94 |
sleep(Duration::from_millis(50));
|
| 95 |
-
self.serial.
|
| 96 |
sleep(Duration::from_millis(50));
|
| 97 |
-
self.serial.
|
| 98 |
sleep(Duration::from_millis(50));
|
| 99 |
-
self.serial.
|
| 100 |
sleep(Duration::from_millis(50));
|
| 101 |
|
| 102 |
Ok(())
|
|
@@ -107,86 +104,12 @@ impl Connection {
|
|
| 107 |
Ok(())
|
| 108 |
}
|
| 109 |
|
| 110 |
-
pub fn set_baud(&mut self, speed:
|
| 111 |
self.baud_rate = Some(speed);
|
| 112 |
-
self.serial
|
| 113 |
-
.reconfigure(&|setup: &mut dyn SerialPortSettings| setup.set_baud_rate(speed))?;
|
| 114 |
-
// Workaround: serial-unix 0.4 / termios 0.2 fail to apply the baud rate on
|
| 115 |
-
// modern glibc (the speed never reaches the kernel, leaving the port at a
|
| 116 |
-
// bogus rate). Set it directly through libc instead.
|
| 117 |
-
Self::set_baud_libc(self.fd, speed.speed() as u32)?;
|
| 118 |
-
Ok(())
|
| 119 |
-
}
|
| 120 |
-
|
| 121 |
-
fn set_baud_libc(fd: std::os::unix::io::RawFd, speed: u32) -> Result<(), Error> {
|
| 122 |
-
unsafe {
|
| 123 |
-
let mut t: libc::termios = std::mem::zeroed();
|
| 124 |
-
if libc::tcgetattr(fd, &mut t) != 0 {
|
| 125 |
-
return Err(Error::IO(std::io::Error::last_os_error()));
|
| 126 |
-
}
|
| 127 |
-
// glibc >= 2.42 changed the termios speed API: speeds are numeric and
|
| 128 |
-
// the Bxxx code constants are no longer accepted (silently ignored).
|
| 129 |
-
// Numeric speeds also work on older glibc, which looks them up in its
|
| 130 |
-
// speed table. Fall back to the code constants just in case.
|
| 131 |
-
let r1 = libc::cfsetispeed(&mut t, speed);
|
| 132 |
-
let r2 = libc::cfsetospeed(&mut t, speed);
|
| 133 |
-
if r1 != 0 || r2 != 0 {
|
| 134 |
-
let code = Self::baud_code(speed)?;
|
| 135 |
-
if libc::cfsetispeed(&mut t, code) != 0
|
| 136 |
-
|| libc::cfsetospeed(&mut t, code) != 0
|
| 137 |
-
{
|
| 138 |
-
return Err(Error::IO(std::io::Error::last_os_error()));
|
| 139 |
-
}
|
| 140 |
-
}
|
| 141 |
-
if libc::tcsetattr(fd, libc::TCSANOW, &t) != 0 {
|
| 142 |
-
return Err(Error::IO(std::io::Error::last_os_error()));
|
| 143 |
-
}
|
| 144 |
-
}
|
| 145 |
Ok(())
|
| 146 |
}
|
| 147 |
|
| 148 |
-
fn baud_code(speed: u32) -> Result<u32, Error> {
|
| 149 |
-
let code = match speed {
|
| 150 |
-
50 => libc::B50,
|
| 151 |
-
75 => libc::B75,
|
| 152 |
-
110 => libc::B110,
|
| 153 |
-
134 => libc::B134,
|
| 154 |
-
150 => libc::B150,
|
| 155 |
-
200 => libc::B200,
|
| 156 |
-
300 => libc::B300,
|
| 157 |
-
600 => libc::B600,
|
| 158 |
-
1200 => libc::B1200,
|
| 159 |
-
1800 => libc::B1800,
|
| 160 |
-
2400 => libc::B2400,
|
| 161 |
-
4800 => libc::B4800,
|
| 162 |
-
9600 => libc::B9600,
|
| 163 |
-
19200 => libc::B19200,
|
| 164 |
-
38400 => libc::B38400,
|
| 165 |
-
57600 => libc::B57600,
|
| 166 |
-
115200 => libc::B115200,
|
| 167 |
-
230400 => libc::B230400,
|
| 168 |
-
460800 => libc::B460800,
|
| 169 |
-
500000 => libc::B500000,
|
| 170 |
-
576000 => libc::B576000,
|
| 171 |
-
921600 => libc::B921600,
|
| 172 |
-
1000000 => libc::B1000000,
|
| 173 |
-
1152000 => libc::B1152000,
|
| 174 |
-
1500000 => libc::B1500000,
|
| 175 |
-
2000000 => libc::B2000000,
|
| 176 |
-
2500000 => libc::B2500000,
|
| 177 |
-
3000000 => libc::B3000000,
|
| 178 |
-
3500000 => libc::B3500000,
|
| 179 |
-
4000000 => libc::B4000000,
|
| 180 |
-
_ => {
|
| 181 |
-
return Err(Error::IO(std::io::Error::new(
|
| 182 |
-
std::io::ErrorKind::InvalidInput,
|
| 183 |
-
format!("unsupported baud rate {}", speed),
|
| 184 |
-
)))
|
| 185 |
-
}
|
| 186 |
-
};
|
| 187 |
-
Ok(code)
|
| 188 |
-
}
|
| 189 |
-
|
| 190 |
pub fn with_timeout<T, F: FnMut(&mut Connection) -> Result<T, Error>>(
|
| 191 |
&mut self,
|
| 192 |
timeout: Duration,
|
|
@@ -231,7 +154,7 @@ impl Connection {
|
|
| 231 |
}
|
| 232 |
|
| 233 |
pub fn calc_duration_length(&mut self, duration: Duration) -> usize {
|
| 234 |
-
self.baud_rate.unwrap_or(DEFAULT_BAUDRATE)
|
| 235 |
* (duration.as_millis() as usize)
|
| 236 |
}
|
| 237 |
|
|
|
|
| 7 |
use std::thread::sleep;
|
| 8 |
use std::time::Duration;
|
| 9 |
|
| 10 |
+
use serialport::SerialPort;
|
| 11 |
|
| 12 |
+
pub const DEFAULT_BAUDRATE: u32 = 115_200;
|
| 13 |
|
| 14 |
macro_rules! impl_command(
|
| 15 |
($id: expr, $t:ty, $r:ty) => (
|
|
|
|
| 60 |
|
| 61 |
pub struct Connection {
|
| 62 |
serial: Box<dyn SerialPort>,
|
| 63 |
+
baud_rate: Option<u32>,
|
|
|
|
| 64 |
}
|
| 65 |
|
| 66 |
impl Connection {
|
| 67 |
+
pub fn new(serial: Box<dyn SerialPort>) -> Self {
|
|
|
|
| 68 |
Connection {
|
| 69 |
+
serial,
|
| 70 |
baud_rate: None,
|
|
|
|
| 71 |
}
|
| 72 |
}
|
| 73 |
|
|
|
|
| 76 |
}
|
| 77 |
|
| 78 |
pub fn reset(&mut self) -> Result<(), Error> {
|
| 79 |
+
self.serial.write_request_to_send(false)?;
|
| 80 |
sleep(Duration::from_millis(50));
|
| 81 |
+
self.serial.write_data_terminal_ready(true)?;
|
| 82 |
sleep(Duration::from_millis(50));
|
| 83 |
+
self.serial.write_data_terminal_ready(false)?;
|
| 84 |
sleep(Duration::from_millis(50));
|
| 85 |
|
| 86 |
Ok(())
|
| 87 |
}
|
| 88 |
|
| 89 |
pub fn reset_to_flash(&mut self) -> Result<(), Error> {
|
| 90 |
+
self.serial.write_request_to_send(true)?;
|
| 91 |
sleep(Duration::from_millis(50));
|
| 92 |
+
self.serial.write_data_terminal_ready(true)?;
|
| 93 |
sleep(Duration::from_millis(50));
|
| 94 |
+
self.serial.write_data_terminal_ready(false)?;
|
| 95 |
sleep(Duration::from_millis(50));
|
| 96 |
+
self.serial.write_request_to_send(false)?;
|
| 97 |
sleep(Duration::from_millis(50));
|
| 98 |
|
| 99 |
Ok(())
|
|
|
|
| 104 |
Ok(())
|
| 105 |
}
|
| 106 |
|
| 107 |
+
pub fn set_baud(&mut self, speed: u32) -> Result<(), Error> {
|
| 108 |
self.baud_rate = Some(speed);
|
| 109 |
+
self.serial.set_baud_rate(speed)?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
Ok(())
|
| 111 |
}
|
| 112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
pub fn with_timeout<T, F: FnMut(&mut Connection) -> Result<T, Error>>(
|
| 114 |
&mut self,
|
| 115 |
timeout: Duration,
|
|
|
|
| 154 |
}
|
| 155 |
|
| 156 |
pub fn calc_duration_length(&mut self, duration: Duration) -> usize {
|
| 157 |
+
(self.baud_rate.unwrap_or(DEFAULT_BAUDRATE) as usize) / 10 / 1000
|
| 158 |
* (duration.as_millis() as usize)
|
| 159 |
}
|
| 160 |
|
|
@@ -4,7 +4,7 @@ use thiserror::Error;
|
|
| 4 |
#[non_exhaustive]
|
| 5 |
pub enum Error {
|
| 6 |
#[error("IO error while using serial port: {0}")]
|
| 7 |
-
Serial(#[from]
|
| 8 |
#[error("IO error: {0}")]
|
| 9 |
IO(#[from] std::io::Error),
|
| 10 |
#[error("Failed to connect to the device")]
|
|
|
|
| 4 |
#[non_exhaustive]
|
| 5 |
pub enum Error {
|
| 6 |
#[error("IO error while using serial port: {0}")]
|
| 7 |
+
Serial(#[from] serialport::Error),
|
| 8 |
#[error("IO error: {0}")]
|
| 9 |
IO(#[from] std::io::Error),
|
| 10 |
#[error("Failed to connect to the device")]
|
|
@@ -2,7 +2,7 @@ use crate::chip::Chip;
|
|
| 2 |
use crate::Error;
|
| 3 |
use crate::{connection::Connection, elf::RomSegment};
|
| 4 |
use indicatif::{HumanBytes, ProgressBar, ProgressStyle};
|
| 5 |
-
use
|
| 6 |
use sha2::{Digest, Sha256};
|
| 7 |
use std::{
|
| 8 |
io::{Cursor, Read, Write},
|
|
@@ -24,15 +24,15 @@ pub struct Flasher {
|
|
| 24 |
connection: Connection,
|
| 25 |
boot_info: protocol::BootInfo,
|
| 26 |
chip: Box<dyn Chip>,
|
| 27 |
-
flash_speed:
|
| 28 |
}
|
| 29 |
|
| 30 |
impl Flasher {
|
| 31 |
pub fn connect(
|
| 32 |
chip: impl Chip + 'static,
|
| 33 |
-
serial:
|
| 34 |
-
initial_speed:
|
| 35 |
-
flash_speed:
|
| 36 |
) -> Result<Self, Error> {
|
| 37 |
let mut flasher = Flasher {
|
| 38 |
connection: Connection::new(serial),
|
|
|
|
| 2 |
use crate::Error;
|
| 3 |
use crate::{connection::Connection, elf::RomSegment};
|
| 4 |
use indicatif::{HumanBytes, ProgressBar, ProgressStyle};
|
| 5 |
+
use serialport::SerialPort;
|
| 6 |
use sha2::{Digest, Sha256};
|
| 7 |
use std::{
|
| 8 |
io::{Cursor, Read, Write},
|
|
|
|
| 24 |
connection: Connection,
|
| 25 |
boot_info: protocol::BootInfo,
|
| 26 |
chip: Box<dyn Chip>,
|
| 27 |
+
flash_speed: u32,
|
| 28 |
}
|
| 29 |
|
| 30 |
impl Flasher {
|
| 31 |
pub fn connect(
|
| 32 |
chip: impl Chip + 'static,
|
| 33 |
+
serial: Box<dyn SerialPort>,
|
| 34 |
+
initial_speed: u32,
|
| 35 |
+
flash_speed: u32,
|
| 36 |
) -> Result<Self, Error> {
|
| 37 |
let mut flasher = Flasher {
|
| 38 |
connection: Connection::new(serial),
|
|
@@ -16,11 +16,12 @@ use crate::{
|
|
| 16 |
elf::{FirmwareImage, RomSegment},
|
| 17 |
image::BootHeaderCfgFile,
|
| 18 |
};
|
| 19 |
-
use
|
| 20 |
use std::{
|
| 21 |
borrow::Cow,
|
| 22 |
fs::{read, File},
|
| 23 |
path::PathBuf,
|
|
|
|
| 24 |
};
|
| 25 |
use structopt::StructOpt;
|
| 26 |
|
|
@@ -104,25 +105,15 @@ pub enum Opt {
|
|
| 104 |
}
|
| 105 |
|
| 106 |
impl Connection {
|
| 107 |
-
pub fn open_serial(&self) -> Result<
|
| 108 |
-
let
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
setup.set_stop_bits(StopBits::Stop1);
|
| 112 |
-
setup.set_parity(Parity::ParityNone);
|
| 113 |
-
setup.set_flow_control(FlowControl::FlowNone);
|
| 114 |
-
Ok(())
|
| 115 |
-
})?;
|
| 116 |
Ok(serial)
|
| 117 |
}
|
| 118 |
pub fn create_flasher(&self, chip: impl Chip + 'static) -> Result<Flasher, Error> {
|
| 119 |
let serial = self.open_serial()?;
|
| 120 |
-
Flasher::connect(
|
| 121 |
-
chip,
|
| 122 |
-
serial,
|
| 123 |
-
BaudRate::from_speed(self.initial_baud_rate),
|
| 124 |
-
BaudRate::from_speed(self.baud_rate),
|
| 125 |
-
)
|
| 126 |
}
|
| 127 |
}
|
| 128 |
|
|
|
|
| 16 |
elf::{FirmwareImage, RomSegment},
|
| 17 |
image::BootHeaderCfgFile,
|
| 18 |
};
|
| 19 |
+
use serialport::SerialPort;
|
| 20 |
use std::{
|
| 21 |
borrow::Cow,
|
| 22 |
fs::{read, File},
|
| 23 |
path::PathBuf,
|
| 24 |
+
time::Duration,
|
| 25 |
};
|
| 26 |
use structopt::StructOpt;
|
| 27 |
|
|
|
|
| 105 |
}
|
| 106 |
|
| 107 |
impl Connection {
|
| 108 |
+
pub fn open_serial(&self) -> Result<Box<dyn SerialPort>, Error> {
|
| 109 |
+
let serial = serialport::new(&self.port, self.initial_baud_rate as u32)
|
| 110 |
+
.timeout(Duration::from_millis(100))
|
| 111 |
+
.open()?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
Ok(serial)
|
| 113 |
}
|
| 114 |
pub fn create_flasher(&self, chip: impl Chip + 'static) -> Result<Flasher, Error> {
|
| 115 |
let serial = self.open_serial()?;
|
| 116 |
+
Flasher::connect(chip, serial, self.initial_baud_rate as u32, self.baud_rate as u32)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
}
|
| 118 |
}
|
| 119 |
|
|
@@ -12,7 +12,6 @@ repository = "https://github.com/spacemeowx2/blflash"
|
|
| 12 |
cargo-project = "0.3.0"
|
| 13 |
blflash = { version = "=0.3.5", path = "../blflash" }
|
| 14 |
main_error = "0.1.1"
|
| 15 |
-
serial = "0.4"
|
| 16 |
color-eyre = "0.6.2"
|
| 17 |
structopt = "0.3.21"
|
| 18 |
paw = "1.0.0"
|
|
|
|
| 12 |
cargo-project = "0.3.0"
|
| 13 |
blflash = { version = "=0.3.5", path = "../blflash" }
|
| 14 |
main_error = "0.1.1"
|
|
|
|
| 15 |
color-eyre = "0.6.2"
|
| 16 |
structopt = "0.3.21"
|
| 17 |
paw = "1.0.0"
|