├── .gitignore ├── CHANGELOG ├── src ├── cargo_config.rs ├── blackmagic.rs ├── stlink │ ├── util.rs │ ├── constants.rs │ └── mod.rs ├── bobbin_config.rs ├── printer.rs ├── sysfs.rs ├── ioreg.rs ├── builder.rs ├── main.rs ├── console.rs ├── check.rs ├── config.rs ├── loader.rs ├── debugger.rs ├── app.rs ├── device.rs └── cmd.rs ├── Cargo.toml ├── LICENSE-MIT ├── FIRMWARE.md ├── LICENSE-APACHE ├── README.md └── Cargo.lock /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | **/*.rs.bk 3 | -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | 0.9.0: 2 | Added console options to configuation file 3 | Infer --target by reading .cargo/configuration 4 | Rewrite to use Serde to read configuration files 5 | Add support for remote operations using SSH 6 | Also search for openocd.cfg in .bobbin// and ~/.bobbin// 7 | Use -mmcu instead of --mcu option for teensy_loader_cli compatibility -------------------------------------------------------------------------------- /src/cargo_config.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashMap; 2 | 3 | #[derive(Debug, Deserialize)] 4 | pub struct CargoConfig { 5 | pub build: Option, 6 | pub target: Option>, 7 | } 8 | 9 | #[derive(Debug, Deserialize)] 10 | pub struct BuildConfig { 11 | pub target: Option, 12 | } 13 | 14 | #[derive(Debug, Deserialize)] 15 | pub struct Target { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/blackmagic.rs: -------------------------------------------------------------------------------- 1 | use clap::ArgMatches; 2 | use config::Config; 3 | use Result; 4 | 5 | pub fn blackmagic_scan(cfg: &Config, args: &ArgMatches, cmd_args: &ArgMatches) -> Result<&'static str> { 6 | let blackmagic_mode = if let Some(blackmagic_mode) = cfg.blackmagic_mode(cmd_args) { 7 | blackmagic_mode 8 | } else { 9 | String::from("swd") 10 | }; 11 | match blackmagic_mode.as_ref() { 12 | "jtag" => Ok("monitor jtag_scan"), 13 | "swd" => Ok("monitor swdp_scan"), 14 | _ => bail!("Unknown blackmagic-mode {}", blackmagic_mode), 15 | } 16 | } -------------------------------------------------------------------------------- /src/stlink/util.rs: -------------------------------------------------------------------------------- 1 | use std; 2 | 3 | // https://internals.rust-lang.org/t/safe-trasnsmute-for-slices-e-g-u64-u32-particularly-simd-types/2871 4 | #[inline(always)] 5 | #[allow(dead_code)] // Only used on 32-bit builds currently 6 | pub fn u32_as_u8<'a>(src: &'a [u32]) -> &'a [u8] { 7 | unsafe { std::slice::from_raw_parts(src.as_ptr() as *mut u8, src.len() * 4) } 8 | } 9 | 10 | // https://internals.rust-lang.org/t/safe-trasnsmute-for-slices-e-g-u64-u32-particularly-simd-types/2871 11 | #[inline(always)] 12 | #[allow(dead_code)] // Only used on 32-bit builds currently 13 | pub fn u32_as_u8_mut<'a>(src: &'a mut [u32]) -> &'a mut [u8] { 14 | unsafe { std::slice::from_raw_parts_mut(src.as_mut_ptr() as *mut u8, src.len() * 4) } 15 | } 16 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "bobbin-cli" 3 | version = "0.8.8" 4 | authors = ["Jonathan Soo "] 5 | description = "A command line tool for automating your embedded development workflow." 6 | homepage = "https://github.com/bobbin-rs/bobbin-cli/" 7 | repository = "https://github.com/bobbin-rs/bobbin-cli/" 8 | readme = "README.md" 9 | keywords = ["embedded"] 10 | license = "MIT/Apache-2.0" 11 | 12 | [[bin]] 13 | name = "bobbin" 14 | path = "src/main.rs" 15 | 16 | [features] 17 | stlink = ["libusb", "byteorder"] 18 | 19 | [dependencies] 20 | clap = "2.23" 21 | error-chain = "0.10" 22 | sha1 = "0.2.0" 23 | plist = "0.1" 24 | serial = "0.3" 25 | toml = "0.4" 26 | termcolor = "0.3.2" 27 | tempfile = "2.1.5" 28 | regex = "0.2" 29 | serde = "1.0" 30 | serde_derive = "1.0" 31 | byteorder = { version = "1.0", optional = true } 32 | libusb = { version = "0.3", optional = true } 33 | os_type = "2.2" 34 | semver = "0.9.0" -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017 Jonathan Soo 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without 7 | limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions 15 | of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /src/bobbin_config.rs: -------------------------------------------------------------------------------- 1 | 2 | #[derive(Debug, Deserialize)] 3 | pub struct BobbinConfig { 4 | pub filter: Option, 5 | pub console: Option, 6 | pub builder: Option, 7 | pub loader: Option, 8 | pub itm: Option, 9 | } 10 | 11 | #[derive(Debug, Deserialize)] 12 | pub struct FilterConfig { 13 | pub host: Option, 14 | pub device: Option, 15 | } 16 | 17 | #[derive(Debug, Deserialize)] 18 | pub struct BuilderConfig { 19 | pub target: Option, 20 | } 21 | 22 | #[derive(Debug, Deserialize)] 23 | pub struct ConsoleConfig { 24 | pub device: Option, 25 | pub path: Option, 26 | pub speed: Option, 27 | } 28 | 29 | #[derive(Debug, Deserialize)] 30 | pub struct ItmConfig { 31 | #[serde(rename = "target-clock")] 32 | pub target_clock: Option, 33 | } 34 | 35 | 36 | #[derive(Debug, Deserialize)] 37 | pub struct LoaderConfig { 38 | #[serde(rename = "jlink-device")] 39 | pub jlink_device: Option, 40 | #[serde(rename = "teensy-mcu")] 41 | pub teensy_mcu: Option, 42 | #[serde(rename = "blackmagic-mode")] 43 | pub blackmagic_mode: Option, 44 | pub offset: Option, 45 | } -------------------------------------------------------------------------------- /src/printer.rs: -------------------------------------------------------------------------------- 1 | use std::io::{self, Write}; 2 | use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor}; 3 | 4 | 5 | pub fn printer() -> Printer { 6 | Printer { 7 | out: StandardStream::stdout(ColorChoice::Always), 8 | verbose: false, 9 | } 10 | } 11 | 12 | pub struct Printer { 13 | out: StandardStream, 14 | verbose: bool, 15 | } 16 | 17 | impl Printer { 18 | pub fn is_verbose(&self) -> bool { 19 | self.verbose 20 | } 21 | 22 | pub fn with_verbose(self, value: bool) -> Self { 23 | Printer { 24 | out: self.out, 25 | verbose: value, 26 | } 27 | } 28 | 29 | pub fn out(&mut self) -> &mut StandardStream { 30 | &mut self.out 31 | } 32 | 33 | pub fn msg(&mut self, color: Color, label: &str, msg: &str) -> ::std::io::Result<()> { 34 | self.out.set_color( 35 | ColorSpec::new().set_bold(true).set_fg(Some(color)), 36 | )?; 37 | write!(self.out, "{:>12}", label)?; 38 | self.out.reset()?; 39 | writeln!(self.out(), " {}", msg) 40 | } 41 | 42 | pub fn verbose(&mut self, label: &str, msg: &str) -> ::std::io::Result<()> { 43 | if self.verbose { 44 | self.msg(Color::White, label, msg) 45 | } else { 46 | Ok(()) 47 | } 48 | } 49 | 50 | pub fn info(&mut self, label: &str, msg: &str) -> ::std::io::Result<()> { 51 | self.msg(Color::Green, label, msg) 52 | } 53 | 54 | pub fn error(&mut self, label: &str, msg: &str) -> ::std::io::Result<()> { 55 | self.msg(Color::Red, label, msg) 56 | } 57 | } 58 | 59 | impl Write for Printer { 60 | fn write(&mut self, buf: &[u8]) -> ::std::io::Result { 61 | self.out.write(buf) 62 | } 63 | fn flush(&mut self) -> io::Result<()> { 64 | self.out.flush() 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/sysfs.rs: -------------------------------------------------------------------------------- 1 | use errors::*; 2 | 3 | use std::io::Read; 4 | use std::path::Path; 5 | use std::fs::{self, File}; 6 | use std::vec::Vec; 7 | use device::UsbDevice; 8 | 9 | 10 | pub fn enumerate() -> Result> { 11 | let mut items: Vec = Vec::new(); 12 | let root = Path::new("/sys/bus/usb/devices"); 13 | 14 | for entry in fs::read_dir(root)? { 15 | let entry = entry?; 16 | let path = entry.path(); 17 | 18 | let id_vendor = if let Ok(id_vendor) = read_u16(&path.join("idVendor")) { 19 | id_vendor 20 | } else { 21 | continue; 22 | }; 23 | let id_product = if let Ok(id_product) = read_u16(&path.join("idProduct")) { 24 | id_product 25 | } else { 26 | continue; 27 | }; 28 | items.push(UsbDevice { 29 | vendor_id: id_vendor, 30 | vendor_string: read_file(&path.join("manufacturer")).unwrap_or(String::new()), 31 | product_id: id_product, 32 | product_string: read_file(&path.join("product")).unwrap_or(String::new()), 33 | serial_number: read_file(&path.join("serial")).unwrap_or(String::new()), 34 | location_id: None, 35 | path: Some(path), 36 | }); 37 | } 38 | 39 | Ok(items) 40 | } 41 | 42 | fn read_u16(path: &Path) -> Result { 43 | let s = read_file(path)?; 44 | Ok(u16::from_str_radix(&s[..4], 16)?) 45 | } 46 | 47 | fn read_file(path: &Path) -> Result { 48 | let mut f = File::open(path)?; 49 | let mut s = Vec::new(); 50 | f.read_to_end(&mut s)?; 51 | Ok(String::from( 52 | String::from_utf8_lossy(&s).split('\n').next().unwrap_or(""), 53 | )) 54 | } 55 | 56 | pub fn cdc_path(path: &Path, child: &str) -> Option { 57 | let root = Path::new("/sys/bus/usb/drivers/cdc_acm/abc.txt"); 58 | let name = format!("{}:{}", path.file_name().unwrap().to_str().unwrap(), child); 59 | let tty_dir = root.with_file_name(name).join("tty"); 60 | if !tty_dir.exists() { return None } 61 | for entry in fs::read_dir(tty_dir).unwrap() { 62 | let entry = entry.unwrap(); 63 | return Some(format!("/dev/{}", entry.file_name().to_str().unwrap())); 64 | } 65 | None 66 | } 67 | -------------------------------------------------------------------------------- /src/ioreg.rs: -------------------------------------------------------------------------------- 1 | use errors::*; 2 | 3 | use device::UsbDevice; 4 | use std::process::Command; 5 | use std::io::Cursor; 6 | use std::vec::Vec; 7 | use plist::Plist; 8 | 9 | // To list all serial devices: 10 | // ioreg -c IOSerialBSDClient -r -t 11 | // To list all media devices: 12 | // ioreg -c IOMedia -r -t 13 | 14 | impl<'a> From<&'a Plist> for UsbDevice { 15 | fn from(other: &Plist) -> Self { 16 | fn get_number(p: &Plist, key: &str) -> Option { 17 | if let Some(p_dict) = p.as_dictionary() { 18 | if let Some(v) = p_dict.get(key) { 19 | v.as_integer() 20 | } else { 21 | None 22 | } 23 | } else { 24 | None 25 | } 26 | } 27 | fn get_string(p: &Plist, key: &str) -> String { 28 | if let Some(p_dict) = p.as_dictionary() { 29 | if let Some(v) = p_dict.get(key) { 30 | if let Some(v_str) = v.as_string() { 31 | String::from(v_str) 32 | } else { 33 | String::from("") 34 | } 35 | } else { 36 | String::from("") 37 | } 38 | } else { 39 | String::from("") 40 | } 41 | } 42 | UsbDevice { 43 | vendor_id: get_number(other, "idVendor").map(|v| v as u16).unwrap(), 44 | vendor_string: get_string(other, "USB Vendor Name"), 45 | product_id: get_number(other, "idProduct").map(|v| v as u16).unwrap(), 46 | product_string: get_string(other, "USB Product Name"), 47 | serial_number: get_string(other, "USB Serial Number"), 48 | location_id: get_number(other, "locationID"), 49 | path: None, 50 | } 51 | } 52 | } 53 | 54 | 55 | pub fn enumerate() -> Result> { 56 | let output = try!( 57 | Command::new("ioreg") 58 | .arg("-p") 59 | .arg("IOUSB") 60 | .arg("-lxa") 61 | .output() 62 | ); 63 | let top = try!(Plist::read(Cursor::new(&output.stdout))); 64 | let mut items: Vec = Vec::new(); 65 | visit(&top, &mut |p| { items.push(UsbDevice::from(p)); }); 66 | Ok(items) 67 | } 68 | 69 | fn visit(p: &Plist, f: &mut F) { 70 | if let Some(p_dict) = p.as_dictionary() { 71 | if p_dict.contains_key("idVendor") { 72 | f(p); 73 | } 74 | } 75 | if let Some(p_children) = children(p) { 76 | for c in p_children.iter() { 77 | visit(c, f); 78 | } 79 | } 80 | } 81 | 82 | fn children(p: &Plist) -> Option<&Vec> { 83 | if let Some(p_dict) = p.as_dictionary() { 84 | if let Some(p_dict_entry) = p_dict.get("IORegistryEntryChildren") { 85 | return p_dict_entry.as_array(); 86 | } 87 | } 88 | None 89 | } 90 | -------------------------------------------------------------------------------- /src/builder.rs: -------------------------------------------------------------------------------- 1 | use std::path::PathBuf; 2 | use std::process::Command; 3 | use config::Config; 4 | use clap::ArgMatches; 5 | use printer::Printer; 6 | use Result; 7 | 8 | pub fn build_path(cfg: &Config, args: &ArgMatches, cmd_args: &ArgMatches) -> Result { 9 | if let Some(dst) = cmd_args.value_of("binary") { 10 | return Ok(PathBuf::from(dst)); 11 | } 12 | 13 | if cmd_args.is_present("stdin") { 14 | return Ok(PathBuf::from("--")) 15 | } 16 | 17 | let mut dst = PathBuf::from("target"); 18 | 19 | if let Some(t) = cmd_args.value_of("target") { 20 | dst.push(t) 21 | } else if let Some(t) = cfg.target() { 22 | dst.push(t) 23 | } else { 24 | bail!("No target specified"); 25 | } 26 | 27 | if cmd_args.is_present("release") { 28 | dst.push("release") 29 | } else { 30 | dst.push("debug") 31 | } 32 | 33 | if let Some(name) = cmd_args.value_of("example") { 34 | dst.push("examples"); 35 | dst.push(name); 36 | } else if let Some(name) = cmd_args.value_of("bin") { 37 | dst.push(name); 38 | } else { 39 | dst.push("main"); 40 | }; 41 | Ok(dst) 42 | } 43 | 44 | pub fn build( 45 | cfg: &Config, 46 | args: &ArgMatches, 47 | cmd_args: &ArgMatches, 48 | out: &mut Printer, 49 | ) -> Result> { 50 | if cmd_args.is_present("no-build") || cmd_args.is_present("binary") || cmd_args.is_present("stdin") { 51 | Ok(Some(build_path(cfg, args, cmd_args)?)) 52 | } else { 53 | build_xargo(cfg, args, cmd_args, out) 54 | } 55 | } 56 | pub fn build_xargo( 57 | cfg: &Config, 58 | args: &ArgMatches, 59 | cmd_args: &ArgMatches, 60 | out: &mut Printer, 61 | ) -> Result> { 62 | let (mut cmd, cmd_name) = if cmd_args.is_present("xargo") { 63 | (Command::new("xargo"), "xargo") 64 | } else { 65 | (Command::new("cargo"), "cargo") 66 | }; 67 | cmd.arg("build"); 68 | 69 | if let Some(name) = cmd_args.value_of("example") { 70 | cmd.arg("--example").arg(name); 71 | } 72 | if let Some(name) = cmd_args.value_of("bin") { 73 | cmd.arg("--bin").arg(name); 74 | } 75 | if cmd_args.is_present("release") { 76 | cmd.arg("--release"); 77 | } 78 | if let Some(value) = cmd_args.value_of("features") { 79 | cmd.arg("--features").arg(value); 80 | } 81 | if let Some(value) = cmd_args.value_of("target") { 82 | cmd.arg("--target").arg(value); 83 | } else if let Some(value) = cfg.target() { 84 | cmd.arg("--target").arg(value); 85 | } 86 | out.verbose(cmd_name, &format!("{:?}", cmd))?; 87 | if !cmd.status()?.success() { 88 | bail!("build failed"); 89 | } 90 | let dst = build_path(cfg, args, cmd_args)?; 91 | if dst.is_file() { 92 | let mut cmd = Command::new("arm-none-eabi-size"); 93 | out.verbose("size", &format!("{:?}", cmd))?; 94 | cmd.arg(&dst); 95 | if !cmd.status()?.success() { 96 | bail!("arm-none-eabi-size failed"); 97 | } 98 | Ok(Some(dst)) 99 | } else { 100 | Ok(None) 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | #![allow(dead_code, unused_variables, unused_doc_comments)] 2 | #![recursion_limit = "1024"] 3 | 4 | #[macro_use] 5 | extern crate error_chain; 6 | #[macro_use] 7 | extern crate clap; 8 | #[macro_use] 9 | extern crate serde_derive; 10 | extern crate toml; 11 | extern crate sha1; 12 | extern crate plist; 13 | extern crate serial; 14 | extern crate termcolor; 15 | extern crate tempfile; 16 | extern crate regex; 17 | extern crate os_type; 18 | extern crate semver; 19 | 20 | #[cfg(feature = "stlink")] 21 | extern crate byteorder; 22 | #[cfg(feature = "stlink")] 23 | extern crate libusb; 24 | 25 | mod app; 26 | mod cmd; 27 | mod config; 28 | mod bobbin_config; 29 | mod cargo_config; 30 | mod device; 31 | mod builder; 32 | mod loader; 33 | mod debugger; 34 | mod printer; 35 | mod console; 36 | mod check; 37 | mod blackmagic; 38 | 39 | #[cfg(feature = "stlink")] 40 | mod stlink; 41 | 42 | #[cfg(target_os = "macos")] 43 | mod ioreg; 44 | #[cfg(target_os = "linux")] 45 | mod sysfs; 46 | 47 | 48 | use errors::*; 49 | mod errors { 50 | // Create the Error, ErrorKind, ResultExt, and Result types 51 | error_chain! { 52 | links { 53 | } 54 | foreign_links { 55 | Io(::std::io::Error); 56 | ParseInt(::std::num::ParseIntError); 57 | PList(::plist::Error); 58 | Toml(::toml::de::Error); 59 | Serial(::serial::Error); 60 | LibUsb(::libusb::Error) #[cfg(feature="stlink")]; 61 | } 62 | } 63 | } 64 | 65 | fn main() { 66 | if let Err(ref e) = run() { 67 | use std::io::Write; 68 | let stderr = &mut ::std::io::stderr(); 69 | let errmsg = "Error writing to stderr"; 70 | 71 | writeln!(stderr, "error: {}", e).expect(errmsg); 72 | 73 | for e in e.iter().skip(1) { 74 | writeln!(stderr, "caused by: {}", e).expect(errmsg); 75 | } 76 | 77 | // The backtrace is not always generated. Try to run this example 78 | // with `RUST_BACKTRACE=1`. 79 | if let Some(backtrace) = e.backtrace() { 80 | writeln!(stderr, "backtrace: {:?}", backtrace).expect(errmsg); 81 | } 82 | 83 | ::std::process::exit(1); 84 | } 85 | } 86 | 87 | fn run() -> Result<()> { 88 | let args = app::app().get_matches(); 89 | let cfg = config::config(&args)?; 90 | let mut out = printer::printer().with_verbose(args.is_present("verbose")); 91 | 92 | if let Some(cmd_args) = args.subcommand_matches("check") { 93 | cmd::check(&cfg, &args, cmd_args, &mut out) 94 | } else if let Some(cmd_args) = args.subcommand_matches("list") { 95 | cmd::list(&cfg, &args, cmd_args, &mut out) 96 | } else if let Some(cmd_args) = args.subcommand_matches("info") { 97 | cmd::info(&cfg, &args, cmd_args, &mut out) 98 | } else if let Some(cmd_args) = args.subcommand_matches("build") { 99 | cmd::build(&cfg, &args, cmd_args, &mut out) 100 | } else if let Some(cmd_args) = args.subcommand_matches("load") { 101 | cmd::load(&cfg, &args, cmd_args, &mut out) 102 | } else if let Some(cmd_args) = args.subcommand_matches("run") { 103 | cmd::load(&cfg, &args, cmd_args, &mut out) 104 | } else if let Some(cmd_args) = args.subcommand_matches("test") { 105 | cmd::load(&cfg, &args, cmd_args, &mut out) 106 | } else if let Some(cmd_args) = args.subcommand_matches("halt") { 107 | cmd::control(&cfg, &args, cmd_args, &mut out) 108 | } else if let Some(cmd_args) = args.subcommand_matches("resume") { 109 | cmd::control(&cfg, &args, cmd_args, &mut out) 110 | } else if let Some(cmd_args) = args.subcommand_matches("reset") { 111 | cmd::control(&cfg, &args, cmd_args, &mut out) 112 | } else if let Some(cmd_args) = args.subcommand_matches("openocd") { 113 | cmd::openocd(&cfg, &args, cmd_args, &mut out) 114 | } else if let Some(cmd_args) = args.subcommand_matches("jlink") { 115 | cmd::jlink(&cfg, &args, cmd_args, &mut out) 116 | } else if let Some(cmd_args) = args.subcommand_matches("gdb") { 117 | cmd::gdb(&cfg, &args, cmd_args, &mut out) 118 | } else if let Some(cmd_args) = args.subcommand_matches("console") { 119 | cmd::console(&cfg, &args, cmd_args, &mut out) 120 | } else if let Some(cmd_args) = args.subcommand_matches("screen") { 121 | cmd::screen(&cfg, &args, cmd_args, &mut out) 122 | } else if let Some(cmd_args) = args.subcommand_matches("itm") { 123 | cmd::itm(&cfg, &args, cmd_args, &mut out) 124 | } else { 125 | println!("{}", args.usage()); 126 | Ok(()) 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/console.rs: -------------------------------------------------------------------------------- 1 | use serial::{self, SerialPort}; 2 | use clap::ArgMatches; 3 | use std::time::{Duration, Instant}; 4 | use std::io::{Read, Write}; 5 | use std::process; 6 | use std::thread::spawn; 7 | 8 | use Result; 9 | 10 | pub fn open(path: &str) -> Result { 11 | let mut port = try!(serial::open(path)); 12 | try!(port.reconfigure(&|settings| { 13 | settings.set_baud_rate(serial::Baud115200).unwrap(); 14 | settings.set_flow_control(serial::FlowControl::FlowNone); 15 | Ok(()) 16 | })); 17 | Ok(Console { port: port }) 18 | } 19 | 20 | pub struct Console { 21 | port: serial::SystemPort, 22 | } 23 | 24 | impl Console { 25 | pub fn clear(&mut self) -> Result<()> { 26 | let mut buf = [0u8; 1024]; 27 | self.port.set_timeout(Duration::from_millis(10))?; 28 | loop { 29 | match self.port.read(&mut buf[..]) { 30 | Ok(0) => return Ok(()), 31 | Ok(_) => {} 32 | Err(_) => return Ok(()), 33 | } 34 | } 35 | } 36 | 37 | pub fn view(&mut self) -> Result<()> { 38 | self.port.set_timeout(Duration::from_millis(100))?; 39 | let mut buf = [0u8; 1024]; 40 | let stdin = ::std::io::stdin(); 41 | let mut stdout = ::std::io::stdout(); 42 | 43 | let (stdin_tx, stdin_rx) = ::std::sync::mpsc::channel(); 44 | 45 | spawn(move || { 46 | loop { 47 | let mut stdin_input = String::new(); 48 | match stdin.read_line(&mut stdin_input) { 49 | Ok(0) => { 50 | // process::exit(0) 51 | }, 52 | Ok(_) => { 53 | let _ = stdin_tx.send(stdin_input); 54 | }, 55 | Err(_) => { 56 | process::exit(1) 57 | } 58 | } 59 | 60 | } 61 | }); 62 | 63 | loop { 64 | match self.port.read(&mut buf[..]) { 65 | Ok(n) => { 66 | try!(stdout.write(&buf[..n])); 67 | } 68 | Err(_) => {} 69 | } 70 | match stdin_rx.try_recv() { 71 | Ok(s) => { 72 | self.port.write(s.as_bytes())?; 73 | }, 74 | Err(_) => {}, 75 | } 76 | } 77 | //Ok(()) 78 | } 79 | 80 | pub fn test(&mut self, args: &ArgMatches, cmd_args: &ArgMatches) -> Result<()> { 81 | const LINE_TIMEOUT_MS: u64 = 5000; 82 | const TEST_TIMEOUT_MS: u64 = 15000; 83 | 84 | self.port.set_timeout(Duration::from_millis(100))?; 85 | let mut buf = [0u8; 1024]; 86 | let mut line: Vec = Vec::new(); 87 | let start_time: Instant = Instant::now(); 88 | let mut line_time: Instant = start_time; 89 | loop { 90 | match self.port.read(&mut buf[..]) { 91 | Ok(n) => { 92 | for b in (&buf[..n]).iter() { 93 | if *b == b'\n' { 94 | self.handle_line(line.as_ref())?; 95 | line_time = Instant::now(); 96 | line.clear(); 97 | } else { 98 | line.push(*b); 99 | } 100 | } 101 | } 102 | Err(_) => {} 103 | } 104 | let now = Instant::now(); 105 | if now.duration_since(line_time) > Duration::from_millis(LINE_TIMEOUT_MS) { 106 | println!("[timeout:line]"); 107 | process::exit(1); 108 | } 109 | if now.duration_since(start_time) > Duration::from_millis(TEST_TIMEOUT_MS) { 110 | println!("[timeout:test]"); 111 | process::exit(1); 112 | } 113 | } 114 | //Ok(()) 115 | } 116 | 117 | fn handle_line(&mut self, line: &[u8]) -> Result<()> { 118 | let mut out = ::std::io::stdout(); 119 | let line_str = String::from_utf8_lossy(line); 120 | out.write(line_str.as_bytes())?; 121 | out.write(b"\n")?; 122 | out.flush()?; 123 | if line_str.starts_with("[done]") { 124 | process::exit(0); 125 | } else if line_str.starts_with("[fail]") { 126 | process::exit(1); 127 | } else if line_str.contains("[exception]") { 128 | process::exit(2); 129 | } else if line_str.contains("[panic]") { 130 | process::exit(3); 131 | } 132 | Ok(()) 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /src/check.rs: -------------------------------------------------------------------------------- 1 | use std::io; 2 | use std::process::Command; 3 | use std::io::Write; 4 | use regex::bytes::Regex; 5 | use tempfile; 6 | 7 | #[derive(Debug)] 8 | pub enum Error { 9 | Io(io::Error), 10 | Status, 11 | Regex, 12 | } 13 | 14 | impl From for Error { 15 | fn from(other: io::Error) -> Self { 16 | Error::Io(other) 17 | } 18 | } 19 | 20 | 21 | pub fn which(exec: &str) -> Result { 22 | let out = Command::new("which").arg(exec).output()?; 23 | if out.status.success() { 24 | let re = Regex::new(r"(.*)").unwrap(); 25 | let caps = re.captures(&out.stdout).unwrap(); 26 | Ok(String::from_utf8_lossy(&caps[1]).into_owned()) 27 | } else { 28 | panic!("error"); 29 | } 30 | } 31 | 32 | pub fn rust_version() -> Result { 33 | let out = Command::new("rustc").arg("--version").output()?; 34 | if out.status.success() { 35 | let re = Regex::new(r"rustc (.*)").unwrap(); 36 | let caps = re.captures(&out.stdout).unwrap(); 37 | Ok(String::from_utf8_lossy(&caps[1]).into_owned()) 38 | } else { 39 | panic!("error"); 40 | } 41 | } 42 | pub fn cargo_version() -> Result { 43 | let out = Command::new("cargo").arg("--version").output()?; 44 | if out.status.success() { 45 | let re = Regex::new(r"cargo (.*)").unwrap(); 46 | let caps = re.captures(&out.stdout).unwrap(); 47 | Ok(String::from_utf8_lossy(&caps[1]).into_owned()) 48 | } else { 49 | panic!("error"); 50 | } 51 | } 52 | 53 | pub fn xargo_version() -> Result { 54 | let out = Command::new("xargo").arg("--version").output()?; 55 | if out.status.success() { 56 | let re = Regex::new(r"xargo (.*)\n").unwrap(); 57 | let caps = re.captures(&out.stderr).unwrap(); 58 | Ok(String::from_utf8_lossy(&caps[1]).into_owned()) 59 | } else { 60 | panic!("error"); 61 | } 62 | } 63 | 64 | 65 | pub fn openocd_version() -> Result { 66 | let out = Command::new("openocd").arg("--version").output()?; 67 | if out.status.success() { 68 | let re = Regex::new(r"Open On-Chip Debugger (.*)").unwrap(); 69 | let caps = re.captures(&out.stderr).unwrap(); 70 | Ok(String::from_utf8_lossy(&caps[1]).into_owned()) 71 | } else { 72 | Err(Error::Status) 73 | } 74 | } 75 | 76 | 77 | pub fn gcc_version() -> Result { 78 | let out = Command::new("arm-none-eabi-gcc").arg("--version").output()?; 79 | if out.status.success() { 80 | let re = Regex::new(r"arm-none-eabi-gcc \([^\)]*\) (.*)").unwrap(); 81 | if let Some(caps) = re.captures(&out.stdout) { 82 | Ok(String::from_utf8_lossy(&caps[1]).into_owned()) 83 | } else { 84 | Err(Error::Regex) 85 | } 86 | } else { 87 | Err(Error::Status) 88 | } 89 | } 90 | 91 | pub fn bossac_version() -> Result { 92 | let out = Command::new("bossac").arg("-h").output()?; 93 | let re = Regex::new(r"(?m).*\nBasic Open Source SAM-BA Application \(BOSSA\) Version (.*)\n").unwrap(); 94 | if let Some(caps) = re.captures(&out.stdout) { 95 | Ok(String::from_utf8_lossy(&caps[1]).into_owned()) 96 | } else { 97 | Err(Error::Regex) 98 | } 99 | } 100 | 101 | pub fn jlink_version() -> Result { 102 | let mut tmpfile: tempfile::NamedTempFile = tempfile::NamedTempFile::new().unwrap(); 103 | try!(writeln!(tmpfile, "exit")); 104 | 105 | let out = Command::new("JLinkExe") 106 | .arg("-ExitOnError") 107 | .arg("1") 108 | .arg("-CommanderScript") 109 | .arg(tmpfile.path()) 110 | .output()?; 111 | let re = Regex::new(r"(?m)SEGGER J-Link Commander (.*)\n").unwrap(); 112 | if let Some(caps) = re.captures(&out.stdout) { 113 | Ok(String::from_utf8_lossy(&caps[1]).into_owned()) 114 | } else { 115 | Err(Error::Regex) 116 | } 117 | } 118 | 119 | pub fn teensy_version() -> Result { 120 | let out = Command::new("teensy_loader_cli") 121 | .arg("-v") 122 | .arg("--mcu") 123 | .arg("mkl26z64") 124 | .arg("dummy") 125 | .output()?; 126 | let re = Regex::new(r"(?m)Teensy Loader, Command Line, Version (.*)\n").unwrap(); 127 | if let Some(caps) = re.captures(&out.stdout) { 128 | Ok(String::from_utf8_lossy(&caps[1]).into_owned()) 129 | } else { 130 | Err(Error::Regex) 131 | } 132 | } 133 | 134 | pub fn dfu_util_version() -> Result { 135 | let out = Command::new("dfu-util") 136 | .arg("-V") 137 | .output()?; 138 | let re = Regex::new(r"dfu-util (.*)\n").unwrap(); 139 | if let Some(caps) = re.captures(&out.stdout) { 140 | Ok(String::from_utf8_lossy(&caps[1]).into_owned()) 141 | } else { 142 | Err(Error::Regex) 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /src/stlink/constants.rs: -------------------------------------------------------------------------------- 1 | pub const DEBUG_ERR_OK: u8 = 0x80; 2 | pub const DEBUG_ERR_FAULT: u8 = 0x81; 3 | pub const SWD_AP_WAIT: u8 = 0x10; 4 | pub const SWD_AP_FAULT: u8 = 0x11; 5 | pub const SWD_AP_ERROR: u8 = 0x12; 6 | pub const SWD_AP_PARITY_ERROR: u8 = 0x13; 7 | pub const JTAG_WRITE_ERROR: u8 = 0x0c; 8 | pub const JTAG_WRITE_VERIF_ERROR: u8 = 0x0d; 9 | pub const SWD_DP_WAIT: u8 = 0x14; 10 | pub const SWD_DP_FAULT: u8 = 0x15; 11 | pub const SWD_DP_ERROR: u8 = 0x16; 12 | pub const SWD_DP_PARITY_ERROR: u8 = 0x17; 13 | 14 | pub const SWD_AP_WDATA_ERROR: u8 = 0x18; 15 | pub const SWD_AP_STICKY_ERROR: u8 = 0x19; 16 | pub const SWD_AP_STICKYORUN_ERROR: u8 = 0x1a; 17 | 18 | pub const CORE_RUNNING: u8 = 0x80; 19 | pub const CORE_HALTED: u8 = 0x81; 20 | 21 | pub const GET_VERSION: u8 = 0xF1; 22 | pub const DEBUG_COMMAND: u8 = 0xF2; 23 | pub const DFU_COMMAND: u8 = 0xF3; 24 | pub const SWIM_COMMAND: u8 = 0xF4; 25 | pub const GET_CURRENT_MODE: u8 = 0xF5; 26 | pub const GET_TARGET_VOLTAGE: u8 = 0xF7; 27 | 28 | pub const DEV_DFU_MODE: u8 = 0x00; 29 | pub const DEV_MASS_MODE: u8 = 0x01; 30 | pub const DEV_DEBUG_MODE: u8 = 0x02; 31 | pub const DEV_SWIM_MODE: u8 = 0x03; 32 | pub const DEV_BOOTLOADER_MODE: u8 = 0x04; 33 | 34 | pub const DFU_EXIT: u8 = 0x07; 35 | 36 | pub const SWIM_ENTER: u8 = 0x00; 37 | pub const SWIM_EXIT: u8 = 0x01; 38 | 39 | pub const DEBUG_ENTER_JTAG: u8 = 0x00; 40 | pub const DEBUG_GETSTATUS: u8 = 0x01; 41 | pub const DEBUG_FORCEDEBUG: u8 = 0x02; 42 | pub const DEBUG_APIV1_RESETSYS: u8 = 0x03; 43 | pub const DEBUG_APIV1_READALLREGS: u8 = 0x04; 44 | pub const DEBUG_APIV1_READREG: u8 = 0x05; 45 | pub const DEBUG_APIV1_WRITEREG: u8 = 0x06; 46 | pub const DEBUG_READMEM_32BIT: u8 = 0x07; 47 | pub const DEBUG_WRITEMEM_32BIT: u8 = 0x08; 48 | pub const DEBUG_RUNCORE: u8 = 0x09; 49 | pub const DEBUG_STEPCORE: u8 = 0x0a; 50 | pub const DEBUG_APIV1_SETFP: u8 = 0x0b; 51 | pub const DEBUG_READMEM_8BIT: u8 = 0x0c; 52 | pub const DEBUG_WRITEMEM_8BIT: u8 = 0x0d; 53 | pub const DEBUG_APIV1_CLEARFP: u8 = 0x0e; 54 | pub const DEBUG_APIV1_WRITEDEBUGREG: u8 = 0x0f; 55 | pub const DEBUG_APIV1_SETWATCHPOINT: u8 = 0x10; 56 | 57 | pub const DEBUG_ENTER_SWD: u8 = 0xa3; 58 | 59 | pub const DEBUG_APIV1_ENTER: u8 = 0x20; 60 | pub const DEBUG_EXIT: u8 = 0x21; 61 | pub const DEBUG_READCOREID: u8 = 0x22; 62 | 63 | pub const DEBUG_APIV2_ENTER: u8 = 0x30; 64 | pub const DEBUG_APIV2_READ_IDCODES: u8 = 0x31; 65 | pub const DEBUG_APIV2_RESETSYS: u8 = 0x32; 66 | pub const DEBUG_APIV2_READREG: u8 = 0x33; 67 | pub const DEBUG_APIV2_WRITEREG: u8 = 0x34; 68 | pub const DEBUG_APIV2_WRITEDEBUGREG: u8 = 0x35; 69 | pub const DEBUG_APIV2_READDEBUGREG: u8 = 0x36; 70 | 71 | pub const DEBUG_APIV2_READALLREGS: u8 = 0x3A; 72 | pub const DEBUG_APIV2_GETLASTRWSTATUS: u8 = 0x3B; 73 | pub const DEBUG_APIV2_DRIVE_NRST: u8 = 0x3C; 74 | 75 | pub const DEBUG_APIV2_START_TRACE_RX: u8 = 0x40; 76 | pub const DEBUG_APIV2_STOP_TRACE_RX: u8 = 0x41; 77 | pub const DEBUG_APIV2_GET_TRACE_NB: u8 = 0x42; 78 | pub const DEBUG_APIV2_SWD_SET_FREQ: u8 = 0x43; 79 | 80 | pub const DEBUG_APIV2_DRIVE_NRST_LOW: u8 = 0x00; 81 | pub const DEBUG_APIV2_DRIVE_NRST_HIGH: u8 = 0x01; 82 | pub const DEBUG_APIV2_DRIVE_NRST_PULSE: u8 = 0x02; 83 | 84 | // Temporary Register Constants 85 | 86 | pub const SCS_LAR_KEY: u32 = 0xC5ACCE55; 87 | pub const SCS_AIRCR: u32 = 0xe000ed0c; 88 | pub const SCS_AIRCR_KEY: u32 = (0x05fa << 16); 89 | pub const SCS_AIRCR_VECTCLRACTIVE: u32 = (1 << 1); 90 | 91 | pub const DCB_DEMCR: u32 = 0xE000EDFC; 92 | pub const DCB_DEMCR_TRCENA: u32 = (1 << 24); 93 | pub const DCB_DEMCR_VC_CORERESET: u32 = (1 << 0); // Enable Reset Vector Catch. This causes a Local reset to halt a running system. 94 | 95 | pub const DCB_DHCSR: u32 = 0xE000EDF0; 96 | pub const DCB_DHCSR_DBGKEY: u32 = (0xA05F << 16); 97 | pub const DCB_DHCSR_C_DEBUGEN: u32 = (1 << 0); 98 | pub const DCB_DHCSR_C_HALT: u32 = (1 << 1); 99 | 100 | pub const TPIU_CSPSR: u32 = 0xe0040004; 101 | pub const TPIU_ACPR: u32 = 0xE0040010; 102 | pub const TPIU_SPPR: u32 = 0xE00400F0; 103 | pub const TPIU_FFCR: u32 = 0xE0040304; 104 | pub const TPIU_SPPR_TXMODE_PARALELL: u32 = 0; 105 | pub const TPIU_SPPR_TXMODE_MANCHESTER: u32 = 1; 106 | pub const TPIU_SPPR_TXMODE_NRZ: u32 = 2; 107 | 108 | pub const ITM_LAR: u32 = 0xe0000fb0; 109 | pub const ITM_TER: u32 = 0xe0000e00; 110 | pub const ITM_TPR: u32 = 0xe0000e40; 111 | pub const ITM_TCR: u32 = 0xe0000e80; 112 | pub const ITM_TCR_SWOENA: u32 = (1 << 4); 113 | pub const ITM_TCR_TXENA: u32 = (1 << 3); 114 | pub const ITM_TCR_SYNCENA: u32 = (1 << 2); 115 | pub const ITM_TCR_TSENA: u32 = (1 << 1); 116 | pub const ITM_TCR_ITMENA: u32 = (1 << 0); 117 | 118 | pub const DWT_CTRL: u32 = 0xE0001000; 119 | 120 | // STM32 stuff 121 | pub const DBGMCU_CR: u32 = 0xe0042004; 122 | pub const DBGMCU_CR_DEBUG_SLEEP: u32 = (1 << 0); 123 | pub const DBGMCU_CR_DEBUG_STOP: u32 = (1 << 1); 124 | pub const DBGMCU_CR_DEBUG_STANDBY: u32 = (1 << 2); 125 | pub const DBGMCU_CR_DEBUG_TRACE_IOEN: u32 = (1 << 5); 126 | pub const DBGMCU_CR_RESERVED_MAGIC_UNKNOWN: u32 = (1 << 8); 127 | pub const DBGMCU_APB1_FZ: u32 = 0xe0042008; 128 | pub const DBGMCU_APB1_FZ_DBG_IWDG_STOP: u32 = (1 << 12); 129 | pub const DBGMCU_IDCODE: u32 = 0xE0042000; 130 | 131 | // Cortex-M3 Technical Reference Manual 132 | // Debug Halting Control and Status Register 133 | pub const DHCSR: u32 = 0xe000edf0; 134 | pub const DCRSR: u32 = 0xe000edf4; 135 | pub const DCRDR: u32 = 0xe000edf8; 136 | pub const DBGKEY: u32 = 0xa05f0000; 137 | -------------------------------------------------------------------------------- /src/config.rs: -------------------------------------------------------------------------------- 1 | use bobbin_config::BobbinConfig; 2 | use cargo_config::CargoConfig; 3 | use clap::ArgMatches; 4 | use Result; 5 | use toml; 6 | use std::io::Read; 7 | use std::fs::File; 8 | use std::path::Path; 9 | 10 | 11 | pub fn config(args: &ArgMatches) -> Result { 12 | Ok(Config { 13 | bobbin: read_bobbin()?, 14 | cargo: read_cargo()?, 15 | }) 16 | } 17 | 18 | #[derive(Debug)] 19 | pub struct Config { 20 | pub bobbin: Option, 21 | pub cargo: Option, 22 | } 23 | 24 | impl Config { 25 | pub fn target(&self) -> Option<&str> { 26 | if let Some(ref bobbin) = self.bobbin { 27 | if let Some(ref builder) = bobbin.builder { 28 | if let Some(ref target) = builder.target { 29 | return Some(target) 30 | } 31 | } 32 | } 33 | 34 | if let Some(ref cargo) = self.cargo { 35 | if let Some(ref build) = cargo.build { 36 | if let Some(ref target) = build.target { 37 | return Some(target) 38 | } 39 | 40 | } 41 | 42 | if let Some(ref target) = cargo.target { 43 | if target.keys().len() == 1 { 44 | for key in target.keys() { 45 | return Some(key) 46 | } 47 | } 48 | } 49 | } 50 | 51 | 52 | 53 | None 54 | } 55 | 56 | pub fn filter_host(&self) -> Option<&str> { 57 | if let Some(ref bobbin) = self.bobbin { 58 | if let Some(ref filter) = bobbin.filter { 59 | if let Some(ref host) = filter.host { 60 | return Some(host) 61 | } 62 | } 63 | } 64 | None 65 | } 66 | 67 | pub fn device(&self, args: &ArgMatches) -> Option { 68 | args.value_of("device").or_else(|| self.filter_device()).map(String::from) 69 | } 70 | 71 | pub fn filter_device(&self) -> Option<&str> { 72 | if let Some(ref bobbin) = self.bobbin { 73 | if let Some(ref filter) = bobbin.filter { 74 | if let Some(ref device) = filter.device { 75 | return Some(device) 76 | } 77 | } 78 | } 79 | None 80 | } 81 | 82 | pub fn console(&self, args: &ArgMatches) -> Option { 83 | args.value_of("console").or_else(|| self.cfg_console()).map(String::from) 84 | } 85 | 86 | pub fn cfg_console(&self) -> Option<&str> { 87 | if let Some(ref bobbin) = self.bobbin { 88 | if let Some(ref console) = bobbin.console { 89 | if let Some(ref path) = console.path { 90 | return Some(path) 91 | } 92 | } 93 | } 94 | None 95 | } 96 | 97 | pub fn itm_target_clock(&self) -> Option { 98 | if let Some(ref bobbin) = self.bobbin { 99 | if let Some(ref itm) = bobbin.itm { 100 | return itm.target_clock 101 | } 102 | } 103 | None 104 | } 105 | 106 | pub fn jlink_device(&self, args: &ArgMatches) -> Option { 107 | args.value_of("jlink-device").or_else(|| self.cfg_jlink_device()).map(String::from) 108 | } 109 | 110 | pub fn cfg_jlink_device(&self) -> Option<&str> { 111 | if let Some(ref bobbin) = self.bobbin { 112 | if let Some(ref loader) = bobbin.loader { 113 | if let Some(ref jlink_device) = loader.jlink_device { 114 | return Some(jlink_device) 115 | } 116 | } 117 | } 118 | None 119 | } 120 | 121 | pub fn teensy_mcu(&self, args: &ArgMatches) -> Option { 122 | args.value_of("teensy-mcu").or_else(|| self.cfg_teensy_mcu()).map(String::from) 123 | } 124 | 125 | pub fn cfg_teensy_mcu(&self) -> Option<&str> { 126 | if let Some(ref bobbin) = self.bobbin { 127 | if let Some(ref loader) = bobbin.loader { 128 | if let Some(ref teensy_mcu) = loader.teensy_mcu { 129 | return Some(teensy_mcu) 130 | } 131 | } 132 | } 133 | None 134 | } 135 | 136 | pub fn blackmagic_mode(&self, args: &ArgMatches) -> Option { 137 | args.value_of("blackmagic_mode").or_else(|| self.cfg_blackmagic_mode()).map(String::from) 138 | } 139 | 140 | pub fn cfg_blackmagic_mode(&self) -> Option<&str> { 141 | if let Some(ref bobbin) = self.bobbin { 142 | if let Some(ref loader) = bobbin.loader { 143 | if let Some(ref blackmagic_mode) = loader.blackmagic_mode { 144 | return Some(blackmagic_mode) 145 | } 146 | } 147 | } 148 | None 149 | } 150 | 151 | pub fn offset(&self, args: &ArgMatches) -> Option { 152 | args.value_of("offset").or_else(|| self.cfg_offset()).map(String::from) 153 | } 154 | 155 | pub fn cfg_offset(&self) -> Option<&str> { 156 | if let Some(ref bobbin) = self.bobbin { 157 | if let Some(ref loader) = bobbin.loader { 158 | if let Some(ref offset) = loader.offset { 159 | return Some(offset) 160 | } 161 | } 162 | } 163 | None 164 | } 165 | } 166 | 167 | pub fn read_file>(path: P) -> Result> { 168 | let path = path.as_ref(); 169 | if path.exists() { 170 | let mut data = String::new(); 171 | let mut file = File::open(path)?; 172 | file.read_to_string(&mut data)?; 173 | Ok(Some(data)) 174 | } else { 175 | Ok(None) 176 | } 177 | } 178 | 179 | pub fn read_bobbin() -> Result> { 180 | if let Some(s) = read_file("./.bobbin/config")? { 181 | Ok(Some(toml::from_str(&s)?)) 182 | } else { 183 | Ok(None) 184 | } 185 | } 186 | 187 | pub fn read_cargo() -> Result> { 188 | if let Some(s) = read_file("./.cargo/config")? { 189 | Ok(Some(toml::from_str(&s)?)) 190 | } else { 191 | Ok(None) 192 | } 193 | } 194 | -------------------------------------------------------------------------------- /FIRMWARE.md: -------------------------------------------------------------------------------- 1 | # Development Board Firmware 2 | 3 | ## Overview 4 | 5 | Development boards with integrated debug probes are cheap, convenient and common. They also 6 | have their own complexity - integrated debug probes have MCUs which may be more powerful than 7 | the target MCUs, and have firmware and bootloaders of their own. 8 | 9 | ## Architecture 10 | 11 | Most USB-connected development boards produced today have a similar architecture. 12 | 13 | ### Target MCU and Peripherals 14 | 15 | The Target MCU is the device that the development board is designed around; vendors typically 16 | will have development boards for each major variant of the MCUs that they produce. 17 | 18 | Depending on the MCU and the vendor, there may be additional peripherals and connectors 19 | connected to the MCU. Most development boards will include at least one LED and button and 20 | provide access to most device pins through convenient headers. 21 | 22 | ### Embedded Debug Probe 23 | 24 | Elsewhere on the development board will be an Embedded Debug Probe, a small MCU that is usually 25 | connected to an on-board USB micro or USB mini jack. The debug probe typically includes a 26 | power supply connected to the USB jack that may also be used to power the Target MCU, 27 | indicator LEDs, and a reset button. 28 | 29 | The debug probe will be connected to the Target MCU though a debugging interface such as JTAG 30 | or SWD, which it will use to control and program the Target MCU. It will also have a pin to control 31 | the RESET line of the Target MCU. In many cases, the debug probe will also be connected to 32 | a set of Target MCU UART TX / RX pins that can serve as a serial console. 33 | 34 | In some cases some of these pins may be brought out to headers so that they can be used to 35 | debug external devices. The debug pins of the Target MCU and the debug probe MCU itself may separately 36 | be brought out to headers so that an external debug probe can be used to debug the Target MCU 37 | and the embedded debug probe. 38 | 39 | The embedded debug probe will have its own firmware stored in flash memory to run an application that allows the debug probe to communicate through the USB port and with the Target MCU. We'll refer to this 40 | as the *Debug Application*. The *Debug Application* will usually provide some kind of low or high 41 | level debugging interface, sometimes a virtual USB mass storage device for drag-and-drop firmware 42 | uploads to the Target MCU, and sometimes a virtual USB serial port connected to the Target MCU 43 | serial port. 44 | 45 | There will also need to be a *Bootloader* to load the *Debug Application* into the debug probe's flash memory. Some common MCUs have built-in bootloaders using a protocol such as DFU that can be used for this 46 | purpose; many other debug probes use a specification called OpenSDA which provides a way to upload 47 | firmware by making the debug probe appear as a USB mass storage device. OpenSDA in particular provides 48 | a standard platform that allows different types of debug applications to be installed, one at a time. 49 | 50 | ## Debug Probe Platforms 51 | 52 | There are two major debug probe platforms being used today. 53 | 54 | ### ST-Link 55 | 56 | ST-Link is used in the popular STM32 Discovery and Nucleo boards, as well as in a large number of 57 | standalone debug probes including cheap clones. While not an official standard, ST-Link is based 58 | on a STM32F103 MCU. 59 | 60 | ST-Link debug probes are updating using DFU, but the firmware upload is encrypted. ST provides a 61 | [Firmware Upgrade Utility](http://www.st.com/en/embedded-software/stsw-link007.html) to update their boards with the latest firmware. 62 | 63 | J-Link also provides a Windows-only [STLinkReflash](https://www.segger.com/products/debug-probes/j-link/models/other-j-links/st-link-on-board/) utility 64 | that allows installing the J-Link debug application on ST-Link debug probes. 65 | 66 | ### OpenSDA 67 | 68 | OpenSDA is an open debug probe platform based around a standard hardware interface and USB debug 69 | protocol. OpenSDA provides a bootloader that allows installing debug applications via drag-and-drop 70 | to a virtual USB drive. In many cases the bootloader itself can be upgraded by using drag-and-drop. 71 | 72 | The most common debug applications running on OpenSDA devices are 73 | 74 | - [DAPLINK](https://github.com/mbedmicro/DAPLink) (formerly [CMSIS-DAP](https://developer.mbed.org/handbook/CMSIS-DAP)) 75 | - [J-Link](https://www.segger.com/downloads/jlink) 76 | - [PEMicro](http://www.pemicro.com/opensda/) 77 | 78 | ## Debug Applications 79 | 80 | *Debug Applications* run on the debug probe MCU and are responsible for implementing the USB debug 81 | interface, virtual USB serial ports, and virtual USB mass storage devices for drag-and-drop firmware 82 | uploads. Each debug application uses its own USB debug protocol which needs to be supported by 83 | software running on the debugging host. 84 | 85 | ### ST-Link 86 | 87 | ST-Link is the debug application used by STMicroelectronics on their popular Discover and Nucleo 88 | development boards and on their standalone ST-Link debuggers. Most devices are running ST-Link/V2 89 | or ST-Link/V2-1 and also support virtual serial ports and USB mass storage device protocol for 90 | drag-and-drop programming. 91 | 92 | ST-Link/V2 and ST-Link/V2-1 are supported by OpenOCD. 93 | 94 | ### DAPLINK 95 | 96 | [DAPLINK](https://github.com/mbedmicro/DAPLink) (the successor to CMSIS-DAP) is an open source 97 | debug application that runs on a wide variety of devices supporting the OpenSDA specification. It 98 | is found in NXP / Freescale products such as the popular FRDM development boards, as well as many 99 | others. Many debug probes support virtual serial ports and USB mass storage for drag-and-drop programming. 100 | 101 | DAPLINK is supported by OpenOCD using the CMSIS-DAP protocol. 102 | 103 | ### J-Link 104 | 105 | [J-Link](https://www.segger.com/products/debug-probes/j-link/) is a popular proprietary debug 106 | application that runs on J-Link standalone debug probes as well as a wide variety of development boards. 107 | Segger provides downloadable firmware that can be installed on OpenSDA boards, LPC-Link2 boards and even 108 | ST-Link development boards. Depending on the specific version, virtual serial ports and USB mass storage 109 | for drag-and-drop programming may be available. 110 | 111 | J-Link is supported by OpenOCD and by J-Link's own software. 112 | 113 | 114 | ### PEMicro 115 | 116 | [PEMicro](http://www.pemicro.com/opensda/) is a proprietary debug application that runs on PEMicro 117 | standalone debug probes and on a wide range of OpenSDA devices. It can support virtual serial ports 118 | as well as USB mass storage for drag-and-drop programming. 119 | 120 | PEMicro is not currently supported by OpenOCD (is osbdm currently available?) but PEMicro 121 | does provide [GDB Server for ARM Devices](http://www.pemicro.com/products/product_viewDetails.cfm?product_id=15320151). -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2017 Jonathan Soo 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /src/loader.rs: -------------------------------------------------------------------------------- 1 | use clap::ArgMatches; 2 | use std::io::Write; 3 | use std::process::{Command, ExitStatus}; 4 | use std::env; 5 | use config::Config; 6 | use printer::Printer; 7 | use device::Device; 8 | use std::path::{Path, PathBuf}; 9 | 10 | use tempfile; 11 | 12 | use Result; 13 | 14 | use blackmagic::blackmagic_scan; 15 | 16 | pub trait Load { 17 | fn load( 18 | &self, 19 | cfg: &Config, 20 | args: &ArgMatches, 21 | cmd_args: &ArgMatches, 22 | out: &mut Printer, 23 | device: &Device, 24 | target: &Path, 25 | ) -> Result<()>; 26 | } 27 | 28 | pub fn loader(loader_type: &str) -> Option> { 29 | match loader_type.to_lowercase().as_ref() { 30 | "openocd" => Some(Box::new(OpenOcdLoader {})), 31 | "jlink" => Some(Box::new(JLinkLoader {})), 32 | "bossa" => Some(Box::new(BossaLoader {})), 33 | "teensy" => Some(Box::new(TeensyLoader {})), 34 | "dfu-util" => Some(Box::new(DfuUtilLoader {})), 35 | "blackmagic" => Some(Box::new(BlackMagicLoader {})), 36 | _ => None, 37 | } 38 | } 39 | 40 | pub struct OpenOcdLoader {} 41 | 42 | impl OpenOcdLoader { 43 | fn find_config(&self, device: &Device) -> Option { 44 | let device_id = &device.hash()[..8]; 45 | 46 | // Look in current path 47 | let bobbin_openocd = Path::new("openocd.cfg"); 48 | if bobbin_openocd.exists() { 49 | return Some(bobbin_openocd.into()) 50 | } 51 | 52 | // Look in .bobbin// 53 | let mut bobbin_openocd = PathBuf::from(".bobbin"); 54 | bobbin_openocd.push(device_id); 55 | bobbin_openocd.push("openocd.cfg"); 56 | if bobbin_openocd.exists() { 57 | return Some(bobbin_openocd.into()) 58 | } 59 | 60 | // Look in ~/.bobbin// 61 | if let Some(home) = env::home_dir() { 62 | let mut bobbin_openocd = home; 63 | bobbin_openocd.push(".bobbin"); 64 | bobbin_openocd.push(device_id); 65 | bobbin_openocd.push("openocd.cfg"); 66 | if bobbin_openocd.exists() { 67 | return Some(bobbin_openocd) 68 | } 69 | } 70 | 71 | None 72 | } 73 | } 74 | 75 | impl Load for OpenOcdLoader { 76 | fn load( 77 | &self, 78 | cfg: &Config, 79 | args: &ArgMatches, 80 | cmd_args: &ArgMatches, 81 | out: &mut Printer, 82 | device: &Device, 83 | target: &Path, 84 | ) -> Result<()> { 85 | let mut cmd = Command::new("openocd"); 86 | if let Some(openocd_cfg) = self.find_config(device) { 87 | cmd.arg("--file").arg(openocd_cfg); 88 | } else { 89 | bail!("No openocd.cfg file was found."); 90 | } 91 | cmd.arg("--command").arg(&device.openocd_serial().unwrap()); 92 | cmd.arg("--command").arg("gdb_port disabled"); 93 | cmd.arg("--command").arg("tcl_port disabled"); 94 | cmd.arg("--command").arg("telnet_port disabled"); 95 | 96 | if args.is_present("run") || args.is_present("test") { 97 | cmd.arg("--command").arg(&format!( 98 | "program {} reset exit", 99 | target.display() 100 | )); 101 | } else { 102 | cmd.arg("--command").arg(&format!( 103 | "program {} exit", 104 | target.display() 105 | )); 106 | } 107 | 108 | out.verbose("openocd", &format!("{:?}", cmd))?; 109 | 110 | out.info("Loading", &format!("{}", target.display()))?; 111 | let status = if out.is_verbose() { 112 | cmd.status()? 113 | } else { 114 | cmd.output()?.status 115 | }; 116 | 117 | if status.success() { 118 | out.info( 119 | "Complete", 120 | &format!("Successfully flashed device"), 121 | )?; 122 | } else { 123 | bail!("Error flashing device"); 124 | } 125 | Ok(()) 126 | } 127 | } 128 | 129 | pub struct JLinkLoader {} 130 | 131 | impl Load for JLinkLoader { 132 | fn load( 133 | &self, 134 | cfg: &Config, 135 | args: &ArgMatches, 136 | cmd_args: &ArgMatches, 137 | out: &mut Printer, 138 | device: &Device, 139 | target: &Path, 140 | ) -> Result<()> { 141 | let mut dst = PathBuf::from(target); 142 | dst.set_extension("hex"); 143 | objcopy("ihex", target, &dst)?; 144 | 145 | let jlink_dev = if let Some(jlink_dev) = cfg.jlink_device(cmd_args) { 146 | jlink_dev 147 | } else { 148 | bail!("JLink Loader requires that --jlink-device is specified"); 149 | }; 150 | 151 | // Generate Script File 152 | 153 | let mut tmpfile: tempfile::NamedTempFile = tempfile::NamedTempFile::new().unwrap(); 154 | try!(writeln!(tmpfile, "r")); 155 | try!(writeln!(tmpfile, "h")); 156 | try!(writeln!(tmpfile, "loadfile {}", dst.display())); 157 | if args.is_present("run") || args.is_present("test") { 158 | try!(writeln!(tmpfile, "g")); 159 | } 160 | try!(writeln!(tmpfile, "exit")); 161 | 162 | // Execute Command 163 | 164 | let mut cmd = Command::new("JLinkExe"); 165 | cmd.arg("-device").arg(jlink_dev); 166 | cmd.arg("-if").arg("SWD"); 167 | cmd.arg("-autoconnect").arg("1"); 168 | cmd.arg("-speed").arg("4000"); 169 | cmd.arg("-SelectEmuBySN").arg( 170 | device.usb().serial_number.clone(), 171 | ); 172 | cmd.arg("-CommanderScript").arg(tmpfile.path()); 173 | cmd.arg("-ExitOnError").arg("1"); 174 | 175 | out.verbose("jlink", &format!("{:?}", cmd))?; 176 | 177 | out.info("Loading", &format!("{}", dst.display()))?; 178 | let status = if out.is_verbose() { 179 | cmd.status()? 180 | } else { 181 | cmd.output()?.status 182 | }; 183 | 184 | if status.success() { 185 | out.info( 186 | "Complete", 187 | &format!("Successfully flashed device"), 188 | )?; 189 | } else { 190 | bail!("Error flashing device"); 191 | } 192 | Ok(()) 193 | } 194 | } 195 | 196 | pub struct BossaLoader {} 197 | 198 | impl Load for BossaLoader { 199 | fn load( 200 | &self, 201 | cfg: &Config, 202 | args: &ArgMatches, 203 | cmd_args: &ArgMatches, 204 | out: &mut Printer, 205 | device: &Device, 206 | target: &Path, 207 | ) -> Result<()> { 208 | let mut dst = PathBuf::from(target); 209 | dst.set_extension("bin"); 210 | objcopy("binary", target, &dst)?; 211 | 212 | // Execute Command 213 | 214 | out.info("Loading", &format!("{}", dst.display()))?; 215 | 216 | let mut cmd = Command::new("bossac"); 217 | cmd.arg("-eivRw") 218 | .arg("-p") 219 | .arg(device.bossa_path().unwrap()); 220 | 221 | if let Some(offset) = cfg.offset(cmd_args) { 222 | cmd.arg("-o").arg(offset); 223 | } else { 224 | cmd.arg("-o").arg("0x2000"); 225 | } 226 | 227 | cmd.arg(dst); 228 | 229 | let status = if out.is_verbose() { 230 | cmd.status()? 231 | } else { 232 | cmd.output()?.status 233 | }; 234 | 235 | if status.success() { 236 | out.info( 237 | "Complete", 238 | &format!("Successfully flashed device"), 239 | )?; 240 | } else { 241 | bail!("Error flashing device"); 242 | } 243 | Ok(()) 244 | } 245 | } 246 | 247 | pub struct TeensyLoader {} 248 | 249 | impl Load for TeensyLoader { 250 | fn load( 251 | &self, 252 | cfg: &Config, 253 | args: &ArgMatches, 254 | cmd_args: &ArgMatches, 255 | out: &mut Printer, 256 | device: &Device, 257 | target: &Path, 258 | ) -> Result<()> { 259 | let mut dst = PathBuf::from(target); 260 | dst.set_extension("hex"); 261 | objcopy("ihex", target, &dst)?; 262 | 263 | // Execute Command 264 | 265 | let teensy_mcu = if let Some(teensy_mcu) = cfg.teensy_mcu(cmd_args) { 266 | teensy_mcu 267 | } else { 268 | bail!("Teensy Loader requires that --teensy-mcu is specified. Try 'teensy_loader_cli --list-mcus'."); 269 | }; 270 | 271 | out.info("Loading", &format!("{}", dst.display()))?; 272 | 273 | let mut cmd = Command::new("teensy_loader_cli"); 274 | cmd.arg(&format!("-mmcu={}", teensy_mcu)); 275 | cmd.arg("-v"); 276 | cmd.arg(dst); 277 | 278 | let status = if out.is_verbose() { 279 | cmd.status()? 280 | } else { 281 | cmd.output()?.status 282 | }; 283 | 284 | if status.success() { 285 | out.info( 286 | "Complete", 287 | &format!("Successfully flashed device"), 288 | )?; 289 | } else { 290 | bail!("Error flashing device"); 291 | } 292 | Ok(()) 293 | } 294 | } 295 | 296 | pub struct DfuUtilLoader {} 297 | 298 | impl Load for DfuUtilLoader { 299 | fn load( 300 | &self, 301 | cfg: &Config, 302 | args: &ArgMatches, 303 | cmd_args: &ArgMatches, 304 | out: &mut Printer, 305 | device: &Device, 306 | target: &Path, 307 | ) -> Result<()> { 308 | let mut dst = PathBuf::from(target); 309 | dst.set_extension("bin"); 310 | objcopy("binary", target, &dst)?; 311 | 312 | // Execute Command 313 | 314 | out.info("Loading", &format!("{}", dst.display()))?; 315 | 316 | let mut cmd = Command::new("dfu-util"); 317 | cmd.arg("-d").arg(format!("{:04x}:{:04x}", device.usb().vendor_id, device.usb().product_id)); 318 | cmd.arg("-a").arg("0"); 319 | cmd.arg("-s").arg("0x08000000"); 320 | cmd.arg("-D").arg(dst); 321 | 322 | let status = if out.is_verbose() { 323 | cmd.status()? 324 | } else { 325 | cmd.output()?.status 326 | }; 327 | 328 | if status.success() { 329 | out.info( 330 | "Complete", 331 | &format!("Successfully flashed device"), 332 | )?; 333 | } else { 334 | bail!("Error flashing device"); 335 | } 336 | Ok(()) 337 | } 338 | } 339 | 340 | pub struct BlackMagicLoader {} 341 | impl Load for BlackMagicLoader { 342 | fn load( 343 | &self, 344 | cfg: &Config, 345 | args: &ArgMatches, 346 | cmd_args: &ArgMatches, 347 | out: &mut Printer, 348 | device: &Device, 349 | target: &Path, 350 | ) -> Result<()> { 351 | 352 | let blackmagic_scan = blackmagic_scan(cfg, args, cmd_args)?; 353 | 354 | out.info("Loading", &format!("{}", target.display()))?; 355 | 356 | let mut cmd = Command::new("arm-none-eabi-gdb"); 357 | if let Some(gdb_path) = device.gdb_path() { 358 | cmd.arg("-ex").arg("set confirm off"); 359 | cmd.arg("-ex").arg(format!("target extended-remote {}", gdb_path)); 360 | // These commands are BlackMagic Probe Specific 361 | cmd.arg("-ex").arg(blackmagic_scan); 362 | cmd.arg("-ex").arg("attach 1"); 363 | cmd.arg("-ex").arg("load"); 364 | cmd.arg("-ex").arg("kill"); 365 | cmd.arg("-ex").arg("quit 0"); 366 | } 367 | cmd.arg(target); 368 | if out.is_verbose() { 369 | println!("{:?}", cmd); 370 | } 371 | let status = if out.is_verbose() { 372 | cmd.status()? 373 | } else { 374 | cmd.output()?.status 375 | }; 376 | 377 | if status.success() { 378 | out.info( 379 | "Complete", 380 | &format!("Successfully flashed device"), 381 | )?; 382 | } else { 383 | bail!("Error flashing device"); 384 | } 385 | Ok(()) 386 | } 387 | } 388 | 389 | pub fn objcopy(output: &str, src: &Path, dst: &Path) -> Result { 390 | let mut cmd = Command::new("arm-none-eabi-objcopy"); 391 | cmd.arg("-O").arg(output).arg(src).arg(dst); 392 | Ok(cmd.status()?) 393 | } 394 | 395 | // pub struct RemoteLoader {} 396 | // impl RemoteLoader { 397 | // pub fn load_remote( 398 | // &self, 399 | // cfg: &Config, 400 | // args: &ArgMatches, 401 | // cmd_args: &ArgMatches, 402 | // out: &mut Printer, 403 | // target: &Path, 404 | // host: &str, 405 | // ) -> Result<()> { 406 | // use std::process::*; 407 | // use std::os::unix::io::*; 408 | // use std::os::unix::process::CommandExt; 409 | 410 | // let bin = File::open(target)?; 411 | // let bin_fd = bin.into_raw_fd(); 412 | 413 | // let mut cmd = Command::new("ssh"); 414 | // cmd.arg(remote_host); 415 | // cmd.arg(".cargo/bin/bobbin"); 416 | // if args.is_present("verbose") { 417 | // cmd.arg("-v"); 418 | // } 419 | // if let Some(remote_device) = cmd_args.value_of("remote-device") { 420 | // cmd.arg("--device").arg(remote_device); 421 | // } 422 | // let subcmd = if args.is_present("load") { 423 | // "load" 424 | // } else if args.is_present("run") { 425 | // "run" 426 | // } else if args.is_present("test") { 427 | // "test" 428 | // } else { 429 | // bail!("Only load, run and test are supported for remote hosts") 430 | // }; 431 | // cmd.arg(subcmd); 432 | // cmd.arg("--stdin"); 433 | // if out.is_verbose() { 434 | // println!("{:?}", cmd); 435 | // } 436 | 437 | // let new_stdio = unsafe { Stdio::from_raw_fd(bin_fd) }; 438 | 439 | // cmd 440 | // .stdin(new_stdio) 441 | // .exec(); 442 | // unreachable!() 443 | // } 444 | // } -------------------------------------------------------------------------------- /src/debugger.rs: -------------------------------------------------------------------------------- 1 | use clap::ArgMatches; 2 | use config::Config; 3 | use printer::Printer; 4 | use device::Device; 5 | 6 | use std::process::Command; 7 | use std::io::Write; 8 | use std::path::{Path, PathBuf}; 9 | use std::env; 10 | 11 | use tempfile; 12 | use Result; 13 | 14 | use blackmagic::blackmagic_scan; 15 | 16 | pub fn debugger(debugger_type: &str) -> Option> { 17 | match debugger_type.to_lowercase().as_ref() { 18 | "openocd" => Some(Box::new(OpenOcdDebugger {})), 19 | "jlink" => Some(Box::new(JLinkDebugger {})), 20 | "blackmagic" => Some(Box::new(BlackMagicDebugger {})), 21 | _ => None, 22 | } 23 | } 24 | 25 | pub trait Control { 26 | fn halt( 27 | &self, 28 | cfg: &Config, 29 | args: &ArgMatches, 30 | cmd_args: &ArgMatches, 31 | out: &mut Printer, 32 | device: &Device, 33 | ) -> Result<()>; 34 | fn resume( 35 | &self, 36 | cfg: &Config, 37 | args: &ArgMatches, 38 | cmd_args: &ArgMatches, 39 | out: &mut Printer, 40 | device: &Device, 41 | ) -> Result<()>; 42 | fn reset( 43 | &self, 44 | cfg: &Config, 45 | args: &ArgMatches, 46 | cmd_args: &ArgMatches, 47 | out: &mut Printer, 48 | device: &Device, 49 | ) -> Result<()>; 50 | fn reset_halt( 51 | &self, 52 | cfg: &Config, 53 | args: &ArgMatches, 54 | cmd_args: &ArgMatches, 55 | out: &mut Printer, 56 | device: &Device, 57 | ) -> Result<()>; 58 | fn reset_run( 59 | &self, 60 | cfg: &Config, 61 | args: &ArgMatches, 62 | cmd_args: &ArgMatches, 63 | out: &mut Printer, 64 | device: &Device, 65 | ) -> Result<()>; 66 | fn reset_init( 67 | &self, 68 | cfg: &Config, 69 | args: &ArgMatches, 70 | cmd_args: &ArgMatches, 71 | out: &mut Printer, 72 | device: &Device, 73 | ) -> Result<()>; 74 | } 75 | 76 | pub struct OpenOcdDebugger {} 77 | 78 | impl OpenOcdDebugger { 79 | fn find_config(&self, device: &Device) -> Option { 80 | let device_id = &device.hash()[..8]; 81 | 82 | // Look in current path 83 | let bobbin_openocd = Path::new("openocd.cfg"); 84 | if bobbin_openocd.exists() { 85 | return Some(bobbin_openocd.into()) 86 | } 87 | 88 | // Look in .bobbin// 89 | let mut bobbin_openocd = PathBuf::from(".bobbin"); 90 | bobbin_openocd.push(device_id); 91 | bobbin_openocd.push("openocd.cfg"); 92 | if bobbin_openocd.exists() { 93 | return Some(bobbin_openocd.into()) 94 | } 95 | 96 | // Look in ~/.bobbin// 97 | if let Some(home) = env::home_dir() { 98 | let mut bobbin_openocd = home; 99 | bobbin_openocd.push(".bobbin"); 100 | bobbin_openocd.push(device_id); 101 | bobbin_openocd.push("openocd.cfg"); 102 | if bobbin_openocd.exists() { 103 | return Some(bobbin_openocd) 104 | } 105 | } 106 | 107 | None 108 | } 109 | 110 | pub fn command( 111 | &self, 112 | cfg: &Config, 113 | args: &ArgMatches, 114 | cmd_args: &ArgMatches, 115 | out: &mut Printer, 116 | device: &Device, 117 | action: &str, 118 | ) -> Result<()> { 119 | let mut cmd = Command::new("openocd"); 120 | if let Some(openocd_cfg) = self.find_config(device) { 121 | cmd.arg("--file").arg(openocd_cfg); 122 | } else { 123 | bail!("No openocd.cfg file was found."); 124 | } 125 | cmd.arg("--command").arg(&device.openocd_serial().unwrap()); 126 | cmd.arg("--command").arg("init"); 127 | cmd.arg("--command").arg(action); 128 | cmd.arg("--command").arg("exit"); 129 | 130 | out.verbose("openocd", &format!("{:?}", cmd))?; 131 | 132 | if out.is_verbose() { 133 | cmd.status()?; 134 | } else { 135 | cmd.output()?; 136 | } 137 | Ok(()) 138 | } 139 | 140 | pub fn run( 141 | &self, 142 | cfg: &Config, 143 | args: &ArgMatches, 144 | cmd_args: &ArgMatches, 145 | out: &mut Printer, 146 | device: &Device, 147 | ) -> Result<()> { 148 | use std::os::unix::process::CommandExt; 149 | 150 | let mut cmd = Command::new("openocd"); 151 | if let Some(openocd_cfg) = self.find_config(device) { 152 | cmd.arg("--file").arg(openocd_cfg); 153 | } else { 154 | bail!("No openocd.cfg file was found."); 155 | } 156 | cmd.arg("--command").arg(&device.openocd_serial().unwrap()); 157 | cmd.exec(); 158 | unreachable!(); 159 | } 160 | } 161 | 162 | 163 | impl Control for OpenOcdDebugger { 164 | fn halt( 165 | &self, 166 | cfg: &Config, 167 | args: &ArgMatches, 168 | cmd_args: &ArgMatches, 169 | out: &mut Printer, 170 | device: &Device, 171 | ) -> Result<()> { 172 | out.info("Halting", &format!("Halting Device"))?; 173 | self.command(cfg, args, cmd_args, out, device, "halt") 174 | } 175 | fn resume( 176 | &self, 177 | cfg: &Config, 178 | args: &ArgMatches, 179 | cmd_args: &ArgMatches, 180 | out: &mut Printer, 181 | device: &Device, 182 | ) -> Result<()> { 183 | out.info("Resuming", &format!("Resuming Device"))?; 184 | self.command(cfg, args, cmd_args, out, device, "resume") 185 | } 186 | fn reset( 187 | &self, 188 | cfg: &Config, 189 | args: &ArgMatches, 190 | cmd_args: &ArgMatches, 191 | out: &mut Printer, 192 | device: &Device, 193 | ) -> Result<()> { 194 | out.info("Resetting", &format!("Resetting Device"))?; 195 | self.command(cfg, args, cmd_args, out, device, "reset") 196 | } 197 | fn reset_halt( 198 | &self, 199 | cfg: &Config, 200 | args: &ArgMatches, 201 | cmd_args: &ArgMatches, 202 | out: &mut Printer, 203 | device: &Device, 204 | ) -> Result<()> { 205 | out.info( 206 | "Resetting", 207 | &format!("Resetting and Halting Device"), 208 | )?; 209 | self.command(cfg, args, cmd_args, out, device, "reset halt") 210 | } 211 | fn reset_run( 212 | &self, 213 | cfg: &Config, 214 | args: &ArgMatches, 215 | cmd_args: &ArgMatches, 216 | out: &mut Printer, 217 | device: &Device, 218 | ) -> Result<()> { 219 | out.info( 220 | "Resetting", 221 | &format!("Resetting and Running Device"), 222 | )?; 223 | self.command(cfg, args, cmd_args, out, device, "reset run") 224 | } 225 | fn reset_init( 226 | &self, 227 | cfg: &Config, 228 | args: &ArgMatches, 229 | cmd_args: &ArgMatches, 230 | out: &mut Printer, 231 | device: &Device, 232 | ) -> Result<()> { 233 | out.info( 234 | "Resetting", 235 | &format!("Resetting and Initializing Device"), 236 | )?; 237 | self.command(cfg, args, cmd_args, out, device, "reset init") 238 | } 239 | } 240 | 241 | 242 | pub struct JLinkDebugger {} 243 | impl JLinkDebugger { 244 | fn command( 245 | &self, 246 | cfg: &Config, 247 | args: &ArgMatches, 248 | cmd_args: &ArgMatches, 249 | out: &mut Printer, 250 | device: &Device, 251 | action: &str, 252 | ) -> Result<()> { 253 | 254 | let jlink_dev = if let Some(jlink_dev) = cfg.jlink_device(cmd_args) { 255 | jlink_dev 256 | } else { 257 | bail!("JLink Loader requires that --jlink-device is specified"); 258 | }; 259 | 260 | // Generate Script File 261 | let mut tmpfile: tempfile::NamedTempFile = tempfile::NamedTempFile::new().unwrap(); 262 | try!(writeln!(tmpfile, "{}", action)); 263 | try!(writeln!(tmpfile, "exit")); 264 | 265 | // Execute Command 266 | 267 | let mut cmd = Command::new("JLinkExe"); 268 | cmd.arg("-device").arg(jlink_dev); 269 | cmd.arg("-if").arg("SWD"); 270 | cmd.arg("-autoconnect").arg("1"); 271 | cmd.arg("-speed").arg("4000"); 272 | cmd.arg("-SelectEmuBySN").arg( 273 | device.usb().serial_number.clone(), 274 | ); 275 | cmd.arg("-ExitOnError").arg("1"); 276 | cmd.arg("-CommanderScript").arg(tmpfile.path()); 277 | 278 | out.verbose("jlink", &format!("{:?}", cmd))?; 279 | 280 | if out.is_verbose() { 281 | cmd.status()?; 282 | } else { 283 | cmd.output()?; 284 | } 285 | Ok(()) 286 | } 287 | } 288 | 289 | impl Control for JLinkDebugger { 290 | fn halt( 291 | &self, 292 | cfg: &Config, 293 | args: &ArgMatches, 294 | cmd_args: &ArgMatches, 295 | out: &mut Printer, 296 | device: &Device, 297 | ) -> Result<()> { 298 | //self.command(cfg, args, cmd_args, out, device, "halt") 299 | bail!("halt is not supported for this debugger") 300 | } 301 | fn resume( 302 | &self, 303 | cfg: &Config, 304 | args: &ArgMatches, 305 | cmd_args: &ArgMatches, 306 | out: &mut Printer, 307 | device: &Device, 308 | ) -> Result<()> { 309 | //self.command(cfg, args, cmd_args, out, device, "go") 310 | bail!("halt is not supported for this debugger") 311 | } 312 | fn reset( 313 | &self, 314 | cfg: &Config, 315 | args: &ArgMatches, 316 | cmd_args: &ArgMatches, 317 | out: &mut Printer, 318 | device: &Device, 319 | ) -> Result<()> { 320 | self.command(cfg, args, cmd_args, out, device, "r") 321 | } 322 | fn reset_halt( 323 | &self, 324 | cfg: &Config, 325 | args: &ArgMatches, 326 | cmd_args: &ArgMatches, 327 | out: &mut Printer, 328 | device: &Device, 329 | ) -> Result<()> { 330 | //self.command(cfg, args, cmd_args, out, device, "r") 331 | bail!("reset halt is not supported for this debugger") 332 | } 333 | fn reset_run( 334 | &self, 335 | cfg: &Config, 336 | args: &ArgMatches, 337 | cmd_args: &ArgMatches, 338 | out: &mut Printer, 339 | device: &Device, 340 | ) -> Result<()> { 341 | self.command(cfg, args, cmd_args, out, device, "r") 342 | } 343 | fn reset_init( 344 | &self, 345 | cfg: &Config, 346 | args: &ArgMatches, 347 | cmd_args: &ArgMatches, 348 | out: &mut Printer, 349 | device: &Device, 350 | ) -> Result<()> { 351 | bail!("reset init is not supported for this debugger") 352 | //self.command(cfg, args, cmd_args, out, device, "r") 353 | } 354 | } 355 | 356 | pub struct BlackMagicDebugger {} 357 | impl BlackMagicDebugger { 358 | fn command( 359 | &self, 360 | cfg: &Config, 361 | args: &ArgMatches, 362 | cmd_args: &ArgMatches, 363 | out: &mut Printer, 364 | device: &Device, 365 | action: &str, 366 | ) -> Result<()> { 367 | let blackmagic_scan = blackmagic_scan(cfg, args, cmd_args)?; 368 | 369 | let mut cmd = Command::new("arm-none-eabi-gdb"); 370 | if let Some(gdb_path) = device.gdb_path() { 371 | cmd.arg("-ex").arg("set confirm off"); 372 | cmd.arg("-ex").arg(format!("target extended-remote {}", gdb_path)); 373 | // These commands are BlackMagic Probe Specific 374 | cmd.arg("-ex").arg(blackmagic_scan); 375 | cmd.arg("-ex").arg("attach 1"); 376 | } 377 | cmd.arg("-ex").arg(action); 378 | cmd.arg("-ex").arg("quit"); 379 | out.verbose("blackmagic", &format!("{:?}", cmd))?; 380 | 381 | if out.is_verbose() { 382 | cmd.status()?; 383 | } else { 384 | cmd.output()?; 385 | } 386 | Ok(()) 387 | } 388 | } 389 | 390 | impl Control for BlackMagicDebugger { 391 | fn halt( 392 | &self, 393 | cfg: &Config, 394 | args: &ArgMatches, 395 | cmd_args: &ArgMatches, 396 | out: &mut Printer, 397 | device: &Device, 398 | ) -> Result<()> { 399 | // self.command(cfg, args, cmd_args, out, device, "interrupt") 400 | bail!("halt is not supported for this debugger") 401 | } 402 | fn resume( 403 | &self, 404 | cfg: &Config, 405 | args: &ArgMatches, 406 | cmd_args: &ArgMatches, 407 | out: &mut Printer, 408 | device: &Device, 409 | ) -> Result<()> { 410 | // self.command(cfg, args, cmd_args, out, device, "c&") 411 | bail!("resume is not supported for this debugger") 412 | } 413 | fn reset( 414 | &self, 415 | cfg: &Config, 416 | args: &ArgMatches, 417 | cmd_args: &ArgMatches, 418 | out: &mut Printer, 419 | device: &Device, 420 | ) -> Result<()> { 421 | self.command(cfg, args, cmd_args, out, device, "kill") 422 | } 423 | fn reset_halt( 424 | &self, 425 | cfg: &Config, 426 | args: &ArgMatches, 427 | cmd_args: &ArgMatches, 428 | out: &mut Printer, 429 | device: &Device, 430 | ) -> Result<()> { 431 | // self.command(cfg, args, cmd_args, out, device, "start") 432 | bail!("reset halt is not supported for this debugger") 433 | } 434 | fn reset_run( 435 | &self, 436 | cfg: &Config, 437 | args: &ArgMatches, 438 | cmd_args: &ArgMatches, 439 | out: &mut Printer, 440 | device: &Device, 441 | ) -> Result<()> { 442 | self.command(cfg, args, cmd_args, out, device, "kill") 443 | } 444 | fn reset_init( 445 | &self, 446 | cfg: &Config, 447 | args: &ArgMatches, 448 | cmd_args: &ArgMatches, 449 | out: &mut Printer, 450 | device: &Device, 451 | ) -> Result<()> { 452 | // self.command(cfg, args, cmd_args, out, device, "") 453 | bail!("reset init is not supported for this debugger") 454 | } 455 | } 456 | -------------------------------------------------------------------------------- /src/app.rs: -------------------------------------------------------------------------------- 1 | use clap::{Arg, App, SubCommand}; 2 | 3 | const ABOUT: &'static str = " 4 | bobbin-cli (bobbin) is a command line tool for automating your embedded development workflow. 5 | 6 | bobbin-cli (bobbin) is a tool designed to make it easy to build, deploy, test and debug embedded 7 | devices using a unified CLI. bobbin-cli understands Rust's cargo / cargo package managers 8 | but can also work with Make or any other build system. 9 | 10 | bobbin-cli has the following main areas of functionality: 11 | 12 | - Device enumeration and selection. bobbin-cli recognizes many types of USB debuggers and loaders 13 | and allows you to set per-project filters so that it knows which device to use even when 14 | multiple devices are connected to your computer. 15 | 16 | - Build management. bobbin-cli automatically uses cargo to build your project, and reads the 17 | command line parameters and your Cargo.toml file to automatically determine the output binary 18 | to use. 19 | 20 | - Deployment. For supported devices, bobbin-cli can automatically use the appropriate flash 21 | loading tool (OpenOCD, JLinkExe, bossac or teensy_cli_loader) to upload the output binary. 22 | 23 | - Testing and Debugging. bobbin-cli can automatically connect to and display the virtual serial 24 | console of the selected device if available. You can also start an instance of OpenOCD and gdb 25 | with the output binary produced by the build stage. 26 | 27 | If you have only a single debugging device connected to your computer, you should be able to view 28 | it using \"bobbin list\", which should produce output like this: 29 | 30 | $ bobbin list 31 | ID VID :PID Vendor Product Serial Number 32 | c2f3dc42 0483:374b STMicroelectronics STM32 STLink 0670FF484957847167071621 33 | 34 | or you may multiple devices connected: 35 | 36 | $ bobbin list 37 | ID VID :PID Vendor Product Serial Number 38 | 4c01a4ad 1366:0105 SEGGER J-Link 000621000000 39 | 14a7f5da 03eb:2157 Atmel Corp. EDBG CMSIS-DAP 00000000EZE000005574 40 | b7e67550 0483:374b STMicroelectronics STM32 STLink 0673FF485550755187121723 41 | a3ef65e3 0483:374b STMicroelectronics STM32 STLink 0667FF555654725187073723 42 | cb46720d 1cbe:00fd Texas Instruments In-Circuit Debug Interface 0F007E1A 43 | 8c6bbec5 0d28:0204 ARM DAPLink CMSIS-DAP 0260000025414e450049501247e0004e30f1000097969900 44 | f95f4aca 0d28:0204 ARM DAPLink CMSIS-DAP 0240000034544e45001b00028aa9001a2011000097969900 45 | c2f3dc42 0483:374b STMicroelectronics STM32 STLink 0670FF484957847167071621 46 | 47 | Most subcommands will take a global parameter \"-d\" to specify a specific device ID from the first column. You 48 | may use a unique prefix of the ID - for instance 4c01 instead of 4c01a4ad. 49 | 50 | To view additional information, you may use the \"info\" subcommand: 51 | 52 | $ bobbin -d 4c01 info 53 | ID c2f3dc42b4aadc58b6dfa98ce527dd436e3e4fa5 54 | Vendor ID 0483 55 | Product ID 374b 56 | Vendor STMicroelectronics 57 | Product STM32 STLink 58 | Serial Number 0670FF484957847167071621 59 | Type STLinkV21 60 | Loader Type OpenOCD 61 | Debugger Type OpenOCD 62 | CDC Device /dev/cu.usbmodem141413 63 | OpenOCD Serial hla_serial 0670FF484957847167071621 64 | 65 | Note that for this device, bobbin-cli has identified the virtual serial port and also knows the proper 66 | OpenOCD --command parameter to force use of this specific device. 67 | 68 | bobbin-cli will also look for a device filter directive in a YAML configuration file at ./bobbin/config 69 | 70 | $ cat .bobbin/config 71 | [filter] 72 | device = \"c2f3dc42\" 73 | 74 | To build and run a Rust embedded application, simply use \"bobbin run\" with optional--target, --bin, 75 | --example and --release parameters, just as you would use cargo or cargo directly. bobbin-cli will 76 | use these parameters as well as the local .cargo/config and Cargo.toml file to determine the path of 77 | the output file. It will then execute the appropriate flash loader application for your device (OpenOCD, 78 | JLinkExe, bossac or teensy_loader_cli), using objcopy as needed to convert to the required format. 79 | 80 | Some devices require manual intervention to enter bootloader mode. 81 | 82 | By default, if your selected debugger has a detected virtual serial port, bobbin-cli will connect to that 83 | serial port [NOTE: currently hard-coded to 115,200 baud] and display all output. Use Control-C to terminate 84 | this console viewer. You can use the --console parameter to manually specify a serial device, or 85 | --noconsole if you do not want run the console viewer at all. 86 | 87 | Finally, you may occasionally need to use OpenOCD (or some other GDB remote debugger) and GDB to debug 88 | a problem. \"bobbin openocd\" will automatically start OpenOCD with the appropriate parameters to 89 | connect to your specific device, and (in a separate window) \"bobbin gdb\" will build your application 90 | and then run arm-none-eabi-gdb with the appropiate output binary path as the first parameter. You may wish 91 | to have a .gdbinit file that automatically connects to your local OpenOCD instance. 92 | "; 93 | 94 | pub fn app() -> App<'static, 'static> { 95 | App::new("bobbin") 96 | .version(crate_version!()) 97 | .author("Jonathan Soo ") 98 | .about(ABOUT) 99 | .arg(Arg::with_name("verbose").long("verbose").short("v").help("Displays verbose output")) 100 | .arg(Arg::with_name("quiet").long("quiet").short("q").help("Suppress verbose output")) 101 | .arg(Arg::with_name("config").long("config").short("c").help("Specify the bobbin config file path")) 102 | .arg(Arg::with_name("host").long("host").takes_value(true).help("Specify the host to list.")) 103 | .arg(Arg::with_name("device").long("device").short("d").takes_value(true).help("Specify a device ID prefix for filtering")) 104 | // .arg(Arg::with_name("vendor-id").long("vendor-id").takes_value(true)) 105 | // .arg(Arg::with_name("product-id").long("product-id").takes_value(true)) 106 | // .arg(Arg::with_name("serial-number").long("serial-number").takes_value(true)) 107 | .subcommand(SubCommand::with_name("check") 108 | .about("Display version of all dependencies") 109 | ) 110 | .subcommand(SubCommand::with_name("list") 111 | .arg(Arg::with_name("all").long("all").help("Display all USB devices")) 112 | .about("Display a list of debug devices") 113 | ) 114 | .subcommand(SubCommand::with_name("info") 115 | .about("Display detailed information about selected debug devices") 116 | ) 117 | 118 | .subcommand(SubCommand::with_name("build") 119 | .arg(Arg::with_name("target").long("target").takes_value(true).help("Pass a --target parameter to cargo")) 120 | .arg(Arg::with_name("bin").long("bin").takes_value(true).help("Pass a --bin parameter to cargo")) 121 | .arg(Arg::with_name("example").long("example").takes_value(true).help("Pass a --example parameter to cargo")) 122 | .arg(Arg::with_name("release").long("release").help("Pass a --release parameter to cargo")) 123 | .arg(Arg::with_name("features").long("features").takes_value(true).help("Pass a --features parameter to cargo")) 124 | .arg(Arg::with_name("xargo").long("xargo").help("Use xargo instead of cargo")) 125 | .about("Build an application") 126 | ) 127 | .subcommand(SubCommand::with_name("load") 128 | .arg(Arg::with_name("binary").index(1).takes_value(true).help("Specify the path of the binary file to load.")) 129 | .arg(Arg::with_name("stdin").long("stdin").help("Read binary from stdin")) 130 | .arg(Arg::with_name("target").long("target").takes_value(true).help("Pass a --target parameter to cargo")) 131 | .arg(Arg::with_name("bin").long("bin").takes_value(true).help("Pass a --bin parameter to cargo")) 132 | .arg(Arg::with_name("example").long("example").takes_value(true).help("Pass a --example parameter to cargo")) 133 | .arg(Arg::with_name("release").long("release").help("Pass a --release parameter to cargo")) 134 | .arg(Arg::with_name("features").long("features").takes_value(true).help("Pass a --features parameter to cargo")) 135 | .arg(Arg::with_name("xargo").long("xargo").help("Use xargo instead of cargo")) 136 | .arg(Arg::with_name("jlink-device").long("jlink-device").takes_value(true).help("Specify the J-Link device identifier")) 137 | .arg(Arg::with_name("teensy-mcu").long("teensy-mcu").takes_value(true).help("Specify the Teensy MCU identifier")) 138 | .arg(Arg::with_name("blackmagic-mode").long("blackmagic-mode").takes_value(true).help("Specify the Black Magic mode (swd or jtag)")) 139 | .arg(Arg::with_name("offset").long("offset").takes_value(true).help("Specify an offset address to start flashing (BOSSA)")) 140 | .arg(Arg::with_name("no-build").long("no-build").help("Don't build before attempting to load.")) 141 | .about("Load an application onto the selected device after a successful build.") 142 | ) 143 | .subcommand(SubCommand::with_name("run") 144 | .arg(Arg::with_name("binary").index(1).takes_value(true).help("Specify the path of the binary file to load.")) 145 | .arg(Arg::with_name("stdin").long("stdin").help("Read binary from stdin")) 146 | .arg(Arg::with_name("target").long("target").takes_value(true).help("Pass a --target parameter to cargo")) 147 | .arg(Arg::with_name("bin").long("bin").takes_value(true).help("Pass a --bin parameter to cargo")) 148 | .arg(Arg::with_name("example").long("example").takes_value(true).help("Pass a --example parameter to cargo")) 149 | .arg(Arg::with_name("release").long("release").help("Pass a --release parameter to cargo")) 150 | .arg(Arg::with_name("features").long("features").takes_value(true).help("Pass a --features parameter to cargo")) 151 | .arg(Arg::with_name("xargo").long("xargo").help("Use xargo instead of cargo")) 152 | .arg(Arg::with_name("jlink-device").long("jlink-device").takes_value(true).help("Specify the J-Link device identifier")) 153 | .arg(Arg::with_name("teensy-mcu").long("teensy-mcu").takes_value(true).help("Specify the Teensy MCU identifier")) 154 | .arg(Arg::with_name("blackmagic-mode").long("blackmagic-mode").takes_value(true).help("Specify the Black Magic mode (swd or jtag)")) 155 | .arg(Arg::with_name("offset").long("offset").takes_value(true).help("Specify an offset address to start flashing (BOSSA)")) 156 | .arg(Arg::with_name("no-build").long("no-build").help("Don't build before attempting to load.")) 157 | .arg(Arg::with_name("console").long("console").takes_value(true) 158 | .help("Specify the serial device.") 159 | ) 160 | .arg(Arg::with_name("console-path").long("console-path").takes_value(true) 161 | .help("Specify the path to the serial device.") 162 | ) 163 | .arg(Arg::with_name("console-speed").long("console-speed").takes_value(true) 164 | .help("Specify the baud rate of the serial device.") 165 | ) 166 | .arg(Arg::with_name("noconsole").long("no-console").help("Don't attempt to open a serial console after running.")) 167 | .arg(Arg::with_name("itm").long("itm").help("Display the ITM trace output after running.")) 168 | .arg(Arg::with_name("itm-target-clock").long("itm-target-clock").min_values(0).max_values(1) 169 | .help("Set the ITM Target's Clock Speed")) 170 | .about("Load and run an application on the selected device after a successful build.") 171 | ) 172 | .subcommand(SubCommand::with_name("test") 173 | .arg(Arg::with_name("binary").index(1).takes_value(true).help("Specify the path of the binary file to load.")) 174 | .arg(Arg::with_name("stdin").long("stdin").help("Read binary from stdin")) 175 | .arg(Arg::with_name("target").long("target").takes_value(true).help("Pass a --bin parameter to cargo")) 176 | .arg(Arg::with_name("bin").long("bin").takes_value(true).help("Pass a --bin parameter to cargo")) 177 | .arg(Arg::with_name("example").long("example").takes_value(true).help("Pass a --example parameter to cargo")) 178 | .arg(Arg::with_name("release").long("release").help("Pass a --release parameter to cargo")) 179 | .arg(Arg::with_name("features").long("features").takes_value(true).help("Pass a --features parameter to cargo")) 180 | .arg(Arg::with_name("xargo").long("xargo").help("Use xargo instead of cargo")) 181 | .arg(Arg::with_name("jlink-device").long("jlink-device").takes_value(true).help("Specify the J-Link device identifier")) 182 | .arg(Arg::with_name("teensy-mcu").long("teensy-mcu").takes_value(true).help("Specify the Teensy MCU identifier")) 183 | .arg(Arg::with_name("blackmagic-mode").long("blackmagic-mode").takes_value(true).help("Specify the Black Magic mode (swd or jtag)")) 184 | .arg(Arg::with_name("offset").long("offset").takes_value(true).help("Specify an offset address to start flashing (BOSSA)")) 185 | .arg(Arg::with_name("no-build").long("no-build").help("Don't build before attempting to load.")) 186 | .arg(Arg::with_name("console").long("console").takes_value(true) 187 | .help("Specify the serial device.") 188 | ) 189 | .arg(Arg::with_name("console-path").long("console-path").takes_value(true) 190 | .help("Specify the path to the serial device.") 191 | ) 192 | .arg(Arg::with_name("console-speed").long("console-speed").takes_value(true) 193 | .help("Specify the baud rate of the serial device.") 194 | ) 195 | .arg(Arg::with_name("noconsole").long("no-console").help("Don't attempt to open a serial console after running.")) 196 | .arg(Arg::with_name("itm").long("itm").help("Display the ITM trace output after running.")) 197 | .arg(Arg::with_name("itm-target-clock").long("itm-target-clock").min_values(0).max_values(1) 198 | .help("Set the ITM Target's Clock Speed")) 199 | .about("Load and test an application on the selected device after a successful build.") 200 | ) 201 | .subcommand(SubCommand::with_name("halt").about("Halt the selected device.")) 202 | .subcommand(SubCommand::with_name("resume") 203 | .arg(Arg::with_name("console").long("console").takes_value(true) 204 | .help("Specify the serial device.") 205 | ) 206 | .arg(Arg::with_name("console-path").long("console-path").takes_value(true) 207 | .help("Specify the path to the serial device.") 208 | ) 209 | .arg(Arg::with_name("console-speed").long("console-speed").takes_value(true) 210 | .help("Specify the baud rate of the serial device.") 211 | ) 212 | .arg(Arg::with_name("noconsole").long("no-console") 213 | .help("Don't attempt to open a serial console after resuming.") 214 | ) 215 | .about("Resume the selected device.") 216 | ) 217 | .subcommand(SubCommand::with_name("reset") 218 | .arg(Arg::with_name("run").long("run").help("Run the device after reset.")) 219 | .arg(Arg::with_name("halt").long("halt").help("Halt the device after reset.")) 220 | .arg(Arg::with_name("init").long("init").help("Initialize the device after reset.")) 221 | .arg(Arg::with_name("console").long("console").takes_value(true) 222 | .help("Specify the serial device.") 223 | ) 224 | .arg(Arg::with_name("console-path").long("console-path").takes_value(true) 225 | .help("Specify the path to the serial device.") 226 | ) 227 | .arg(Arg::with_name("console-speed").long("console-speed").takes_value(true) 228 | .help("Specify the baud rate of the serial device.") 229 | ) 230 | .arg(Arg::with_name("noconsole").long("no-console") 231 | .help("Don't attempt to open a serial console after resuming.") 232 | ) 233 | .about("Reset the selected device.") 234 | ) 235 | .subcommand(SubCommand::with_name("console") 236 | .arg(Arg::with_name("console").long("console").takes_value(true) 237 | .help("Specify the serial device.") 238 | ) 239 | .arg(Arg::with_name("console-path").long("console-path").takes_value(true) 240 | .help("Specify the path to the serial device.") 241 | ) 242 | .arg(Arg::with_name("console-speed").long("console-speed").takes_value(true) 243 | .help("Specify the baud rate of the serial device.") 244 | ) 245 | .about("View the serial output of the selected device.") 246 | ) 247 | .subcommand(SubCommand::with_name("itm") 248 | .arg(Arg::with_name("itm-target-clock").long("itm-target-clock").help("Set the ITM Target's Clock Speed")) 249 | .about("View the ITM output of the selected device.") 250 | ) 251 | .subcommand(SubCommand::with_name("screen") 252 | .arg(Arg::with_name("console").long("console").takes_value(true) 253 | .help("Specify the serial device.") 254 | ) 255 | .arg(Arg::with_name("console-path").long("console-path").takes_value(true) 256 | .help("Specify the path to the serial device.") 257 | ) 258 | .arg(Arg::with_name("console-speed").long("console-speed").takes_value(true) 259 | .help("Specify the baud rate of the serial device.") 260 | ) 261 | .about("Connect to the serial port of the selected device using screen.") 262 | ) 263 | .subcommand(SubCommand::with_name("openocd") 264 | .about("Start OpenOCD for the selected device") 265 | ) 266 | .subcommand(SubCommand::with_name("jlink") 267 | .about("Start JLinkGDBServer for the selected device") 268 | ) 269 | .subcommand(SubCommand::with_name("gdb") 270 | .arg(Arg::with_name("binary").index(1).takes_value(true).help("Specify the path of the binary file to load.")) 271 | .arg(Arg::with_name("target").long("target").takes_value(true).help("Pass a --bin parameter to cargo")) 272 | .arg(Arg::with_name("bin").long("bin").takes_value(true).help("Pass a --bin parameter to cargo")) 273 | .arg(Arg::with_name("example").long("example").takes_value(true).help("Pass a --example parameter to cargo")) 274 | .arg(Arg::with_name("release").long("release").help("Pass a --release parameter to cargo")) 275 | .arg(Arg::with_name("features").long("features").takes_value(true).takes_value(true).help("Pass a --features parameter to cargo")) 276 | .arg(Arg::with_name("xargo").long("xargo").help("Use xargo instead of cargo")) 277 | .arg(Arg::with_name("blackmagic-mode").long("blackmagic-mode").takes_value(true).help("Specify the Black Magic mode (swd or jtag)")) 278 | .arg(Arg::with_name("no-build").long("no-build").help("Don't build before attempting to load.")) 279 | .about("Start gdb using the build output as the target.") 280 | ) 281 | //.subcommand(SubCommand::with_name("objdump")) 282 | } 283 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Bobbin-CLI 2 | 3 | bobbin-cli is a tool designed to make it easy to build, deploy, test and debug embedded 4 | devices using a unified CLI. bobbin-cli understands Rust's cargo / xargo package managers 5 | but can also work with Make or any other build system. 6 | 7 | bobbin-cli has the following main areas of functionality: 8 | 9 | - Device enumeration and selection. bobbin-cli recognizes many types of USB debuggers and loaders 10 | and allows you to set per-project filters so that it knows which device to use even when 11 | multiple devices are connected to your computer. 12 | 13 | - Build management. bobbin-cli automatically uses xargo to build your project, and reads the 14 | command line parameters and your Cargo.toml file to automatically determine the output binary 15 | to use. You can also use Make, with a required parameter to specify the output binary path. 16 | 17 | - Deployment. For supported devices, bobbin-cli can automatically use the appropriate flash 18 | loading tool (OpenOCD, JLinkExe, bossac or teensy_cli_loader) to upload the output binary. 19 | 20 | - Testing and Debugging. bobbin-cli can automatically connect to and display the virtual serial 21 | console of the selected device if available. You can also start an instance of OpenOCD and gdb with 22 | the output binary produced by the build stage. 23 | 24 | For a collection of LED blinking demos for a wide variety of popular development boards, 25 | see [bobbin-blinky](https://github.com/bobbin-rs/bobbin-blinky/). 26 | 27 | ## Host Platforms 28 | 29 | MacOS and Linux are currently supported, Windows support is planned. 30 | 31 | ## Supported Devices 32 | 33 | ### Debug Probes 34 | 35 | Currently Supported: 36 | 37 | - [J-Link](https://www.segger.com/products/debug-probes/j-link/) - including CDC (virtual serial port) support. 38 | - [ST-Link/V2](http://www.st.com/en/development-tools/st-link-v2.html) - V2 and V2.1 devices supported, 39 | including CDC (virtual serial port) and SWO Trace (optional, requires libusb). 40 | - [CMSIS-DAP](https://developer.mbed.org/handbook/CMSIS-DAP) - including CDC (virtual serial port) support. 41 | - [DAPLINK](https://github.com/mbedmicro/DAPLink) - including MSD (mass storage device) and CDC (virtual serial port) support. 42 | - [TI ICDI](http://www.ti.com/tool/stellaris_icdi_drivers) - including CDC (virtual serial port) support. 43 | - [Black Magic Probe](https://github.com/blacksphere/blackmagic) - including CDC (virtual serial port) support. 44 | 45 | Coming Soon: 46 | 47 | - [PEmicro](http://www.pemicro.com/opensda/) 48 | 49 | ### Development Boards with Embedded Debug Probes 50 | 51 | Boards from the following product families include embedded debug probes that should be supported. 52 | 53 | - [STM32 Discovery](http://www.st.com/en/evaluation-tools/stm32-mcu-discovery-kits.html?querycriteria=productId=LN1848) 54 | - [STM32 Nucleo](http://www.st.com/en/evaluation-tools/stm32-mcu-nucleo.html?querycriteria=productId=LN1847) 55 | - [Freescale FRDM](http://www.nxp.com/products/software-and-tools/hardware-development-tools/freedom-development-boards:FREDEVPLA) 56 | - [TI Launchpad](http://www.ti.com/lsds/ti/tools-software/launchpads/overview/overview.page) 57 | - [NXP S32K144EVB](http://www.nxp.com/products/automotive-products/microcontrollers-and-processors/arm-mcus-and-mpus/s32-processors-microcontrollers/s32k144-evaluation-board:S32K144EVB) 58 | - [Arduino Zero](https://www.arduino.cc/en/Guide/ArduinoZero) 59 | 60 | *Note:* Many development boards support OpenSDA, which allows a choice of firmware to be installed. Debug probes may support 61 | CMSIS-DAP, DAPLINK, J-Link and PEMicro firmware variants. Be sure to upgrade to the most recent firmware available, and ensure that 62 | a variant supporting OpenOCD (CMSIS-DAP/DAPLINK) or J-Link is installed. Please see [Upgrading Development Board Firmware](FIRMWARE.md). 63 | 64 | ### Development Boards with Flash Loader Support 65 | 66 | Boards from the following product families use flash loaders that are supported. 67 | 68 | - [Feather M0/M4](https://www.adafruit.com/feather) and other Adafruit boards with UF2 bootloaders 69 | - [Teensy 3.x and LC](https://www.pjrc.com/teensy/) 70 | - STM32 DFU Bootloader 71 | 72 | ## Prerequisites 73 | 74 | ### Build Tools 75 | 76 | These tools must be installed in your PATH. 77 | 78 | - [GNU ARM Embedded](https://developer.arm.com/open-source/gnu-toolchain/gnu-rm) 79 | - [xargo](https://github.com/japaric/xargo) 80 | 81 | ### Debugger / Loader Tools 82 | 83 | You must have the appropriate tools installed for the debug probes / dev boards that you wish to use. 84 | 85 | - [OpenOCD](http://openocd.org) - 0.10 or later required for STLink, DAPLINK, CMSIS-DAP, and TI ICDI debug probes 86 | - [J-Link](https://www.segger.com/downloads/jlink) - required for J-Link debug probes. 87 | - [Bossa](http://www.shumatech.com/web/products/bossa) - required for Arduino and Feather devices 88 | - [Teensy Loader](https://www.pjrc.com/teensy/loader_cli.html) - required for Teensy devices 89 | - [libusb](http://libusb.info) - required for STLink SWO Trace support. 90 | - [dfu-util](http://dfu-util.sourceforge.net) - required for STM32 DFU Bootloader support 91 | 92 | ### Development Board Firmware 93 | 94 | If you are using a development board with embedded debug probe, check that you know what debug firmware you have 95 | installed and that it is up to date. Please see [Development Board Firmware](FIRMWARE.md). 96 | 97 | ## Installation 98 | 99 | *Note:* Only Linux and macOS hosts are supported at this time. 100 | 101 | To install from cargo: 102 | 103 | ``` 104 | $ cargo install bobbin-cli 105 | ``` 106 | 107 | To install from github: 108 | 109 | ``` 110 | $ git clone https://github.com/bobbin-rs/bobbin-cli.git 111 | $ cd bobbin-cli 112 | $ cargo install 113 | ``` 114 | 115 | To install with ST-Link SWV Trace support: 116 | 117 | ``` 118 | $ cargo install --features stlink 119 | ``` 120 | 121 | ## Usage 122 | 123 | The name of the executable is `bobbin`. 124 | 125 | ### Help 126 | 127 | You can display detailed help text by using `bobbin -h`. 128 | 129 | ### Bobbin Check 130 | 131 | Use "bobbin check" to list the version numbers of all Bobbin dependencies. "Not Found" will be displayed if 132 | the dependency is not available. 133 | 134 | ``` 135 | $ bobbin check 136 | Rust 1.20.0-nightly (83c659ef6 2017-07-18) 137 | Cargo 0.21.0-nightly (f709c35a3 2017-07-13) 138 | Xargo 0.3.8 139 | GCC 5.4.1 20160919 (release) [ARM/embedded-5-branch revision 240496] 140 | OpenOCD 0.10.0+dev-00092-g77189db (2017-03-01-20:42) 141 | JLink V6.15c (Compiled Apr 24 2017 19:07:08) 142 | Bossa 1.7.0 143 | Teensy 2.1 144 | dfu-util 0.9 145 | ``` 146 | 147 | Please include the "bobbin check" output when reporting problems. 148 | 149 | ### Bobbin List 150 | 151 | Use "bobbin list" to view all debug probes and development boards connected to your host. 152 | 153 | ``` 154 | $ bobbin list 155 | ID VID :PID Vendor Product Serial Number 156 | 4c01a4ad 1366:0105 SEGGER J-Link 000621000000 157 | 14a7f5da 03eb:2157 Atmel Corp. EDBG CMSIS-DAP 00000000EZE000005574 158 | b7e67550 0483:374b STMicroelectronics STM32 STLink 0673FF485550755187121723 159 | a3ef65e3 0483:374b STMicroelectronics STM32 STLink 0667FF555654725187073723 160 | cb46720d 1cbe:00fd Texas Instruments In-Circuit Debug Interface 0F007E1A 161 | 8c6bbec5 0d28:0204 ARM DAPLink CMSIS-DAP 0260000025414e450049501247e0004e30f1000097969900 162 | f95f4aca 0d28:0204 ARM DAPLink CMSIS-DAP 0240000034544e45001b00028aa9001a2011000097969900 163 | c2f3dc42 0483:374b STMicroelectronics STM32 STLink 0670FF484957847167071621 164 | $ 165 | ``` 166 | 167 | The device ID is a hash of the USB Vendor ID, USB Product ID, and USB Serial Number (if available). "bobbin list" displays 168 | the first eight hex digits of the device ID, and "bobbin info" displays the full 64 bit ID. 169 | 170 | ### Bobbin Info 171 | 172 | To view detailed information about a devices, use the "bobbin info" subcommand. 173 | 174 | ``` 175 | $ bobbin -d 4c01 info 176 | ID c2f3dc42b4aadc58b6dfa98ce527dd436e3e4fa5 177 | Vendor ID 0483 178 | Product ID 374b 179 | Vendor STMicroelectronics 180 | Product STM32 STLink 181 | Serial Number 0670FF484957847167071621 182 | Type STLinkV21 183 | Loader Type OpenOCD 184 | Debugger Type OpenOCD 185 | CDC Device /dev/cu.usbmodem141413 186 | OpenOCD Serial hla_serial 0670FF484957847167071621 187 | $ 188 | ``` 189 | 190 | If you have more than one connected device, you can select a specific device by using the -d command line 191 | parameter. bobbin-cli will also look for a device filter directive in a YAML configuration file at ./bobbin/config 192 | 193 | ``` 194 | $ cat .bobbin/config 195 | [filter] 196 | device = "c2f3dc42" 197 | ``` 198 | 199 | ### Bobbin Build 200 | 201 | `bobbin build` runs xargo (by default) or make to build your application. If using xargo, bobbin-cli will 202 | pass through any --target, --bin, --example or --release parameters. 203 | 204 | On completion, bobbin-cli will run `arm-none-eabi-size` on the binary and display the output. 205 | 206 | ``` 207 | $ bobbin build 208 | Compiling blue-pill v0.1.0 (file:///home/bobbin/bobbin-blinky/blue-pill) 209 | Finished dev [optimized + debuginfo] target(s) in 0.50 secs 210 | text data bss dec hex filename 211 | 152 0 4 156 9c target/thumbv7em-none-eabihf/debug/blue-pill 212 | $ 213 | ``` 214 | 215 | ### Bobbin Load 216 | 217 | `bobbin load` runs `bobbin build` and then, if successful, load the binary onto the device 218 | using the selected debugger or loader, using objcopy as needed to convert to the appropriate 219 | format. You may include --target, --bin, --example or --release parameters which will be passed 220 | to `bobbin build`. 221 | 222 | `bobbin load` will interpret the build parameters as well as the Cargo.toml file to determine 223 | the path to the binary. 224 | 225 | ``` 226 | $ bobbin load 227 | Compiling blue-pill v0.1.0 (file:///home/bobbin/bobbin-blinky/blue-pill) 228 | Finished dev [optimized + debuginfo] target(s) in 0.13 secs 229 | text data bss dec hex filename 230 | 152 0 4 156 9c target/thumbv7em-none-eabihf/debug/blue-pill 231 | Loading target/thumbv7em-none-eabihf/debug/blue-pill.hex 232 | Complete Successfully flashed device 233 | Loader Load Complete 234 | $ 235 | ``` 236 | 237 | 238 | Some devices require manual intervention to enter bootloader mode; you should do this before 239 | running `bobbin load`. 240 | 241 | *Note: Many debuggers and loaders require additional configuration* 242 | 243 | - OpenOCD: a properly configured openocd.cfg file must be in the current directory. bobbin will add 244 | the appropriate OpenOCD command line parameters to select the specific device. 245 | - J-Link: you must specify the device type through the --jlink-device command line parameter or 246 | in the .bobbin/config file. 247 | - Teensy Loader: you must specify the device type through the --teensy-mcu command line parameter or 248 | in the .bobbin/config file. 249 | 250 | ### Bobbin Run 251 | 252 | `bobbin run` runs `bobbin load` and then, if successful, open the serial console of the 253 | connected device to display the output. Use Control-C to terminate this console viewer. 254 | 255 | If the selected device does not have an associated serial port, that step will be skipped. 256 | 257 | You can use the --console parameter to manually specify a serial device, or --noconsole if 258 | you do not want run the console viewer at all. 259 | 260 | *Note: the serial viewer is currently hard-coded to 115,200 baud* 261 | 262 | If bobbin-cli is compiled with support for SWO trace, you can pass the --itm parameter 263 | to display ITM output instead of running the serial console. You will also need to pass 264 | the --itm-target-clock parameter with the target's clock speed. 265 | 266 | ``` 267 | $ bobbin run 268 | Compiling blue-pill v0.1.0 (file:///home/bobbin/bobbin-hello/blue-pill) 269 | Finished dev [optimized + debuginfo] target(s) in 0.13 secs 270 | text data bss dec hex filename 271 | 152 0 4 156 9c target/thumbv7em-none-eabihf/debug/blue-pill 272 | Loading target/thumbv7em-none-eabihf/debug/blue-pill.hex 273 | Complete Successfully flashed device 274 | Loader Load Complete 275 | Console Opening Console 276 | Hello World 1 277 | Hello World 2 278 | Hello World 3 279 | ^C 280 | $ 281 | ``` 282 | 283 | ### Bobbin Test 284 | 285 | `bobbin test` runs `bobbin run` and then interprets the serial output, looking for 286 | tags indicating test progress and completion. 287 | 288 | ``` 289 | $ bobbin test 290 | Compiling frdm-k64f v0.1.0 (file:///home/bobbin/bobbin-boards/frdm-k64f) 291 | Finished dev [optimized + debuginfo] target(s) in 0.61 secs 292 | text data bss dec hex filename 293 | 6252 428 408 7088 1bb0 target/thumbv7em-none-eabihf/debug/frdm-k64f 294 | Loading target/thumbv7em-none-eabihf/debug/frdm-k64f 295 | Complete Successfully flashed device 296 | Loader Load Complete 297 | Console Opening Console 298 | [start] Running tests for frdm-k64f 299 | [pass] 0 300 | [pass] 1 301 | [pass] 2 302 | [pass] 3 303 | [pass] 4 304 | [done] All tests passed 305 | $ 306 | ``` 307 | 308 | `bobbin test` recognizes [start], [pass] and [done] tags, exiting with return code 0. It also recognizes 309 | [fail], [exception], and [panic] tags, which will cause it to exit with return codes 1, 2 or 3. All other 310 | output is ignored. 311 | 312 | The test runner will exit with return code 1 if there is a delay of more than 5 seconds between lines 313 | or 15 seconds to complete the entire test. In the future these timeouts will be configurable. 314 | 315 | ### Additional Subcommands 316 | 317 | `bobbin reset` resets the target device. 318 | 319 | `bobbin halt` halts the target device, if supported. 320 | 321 | `bobbin resume` resumes the target device, if supported. 322 | 323 | `bobbin console` starts a console viewer session using the selected device's serial port at a speed 324 | of 115,200. 325 | 326 | `bobbin itm` starts an itm viewer session using the selected device. 327 | 328 | `bobbin screen` starts a `screen` session using the selected device's serial port at a speed 329 | of 115,200. 330 | 331 | `bobbin openocd` starts an `openocd` session using the selected device. 332 | 333 | `bobbin jlink` starts a JLinkGDBServer session using the selected device. 334 | 335 | `bobbin gdb` starts a GDB session with the current target binary as the executable. For debug probes 336 | that are GDB native, this command will connect directly to the device; for debug probes using 337 | OpenOCD or JLinkGDBServer, you must use `target remote :3333` manually or in a .gdbinit file. 338 | 339 | ### Specifying Binary Targets 340 | 341 | If you are not using xargo / cargo as your build manager, you have the option of specifying the output binary 342 | path as the first unlabeled argument. For instance: 343 | 344 | $ bobbin run build/blinky.elf 345 | 346 | would use build/blinky.elf as the target binary to run. 347 | 348 | $ bobbin test build/blinky.elf 349 | 350 | would load and test build/blinky.elf 351 | 352 | ## Configuration 353 | 354 | ### Selecting a device 355 | 356 | If you have multiple debug probes connected, you can tell Bobbin which device to use on a per-directory basis. 357 | Bobbin will look for a TOML configuration file in the .bobbin directory (.bobbin/config). 358 | 359 | To select a specific device, create a [filter] section with a "device" key that includes the prefix of the 360 | device id. For instance, 361 | 362 | ``` 363 | $ bobbin list 364 | ID VID :PID Vendor Product Serial Number 365 | f95f4aca 0d28:0204 ARM DAPLink CMSIS-DAP 0240000034544e45001b00028aa9001a2011000097969900 366 | 8c6bbec5 0d28:0204 ARM DAPLink CMSIS-DAP 0260000025414e450049501247e0004e30f1000097969900 367 | cb46720d 1cbe:00fd Texas Instruments In-Circuit Debug Interface 0F007E1A 368 | 369 | $ mkdir .bobbin 370 | $ cat > test 371 | [filter] 372 | device = "f95f4aca" 373 | $ bobbin list 374 | ID VID :PID Vendor Product Serial Number 375 | f95f4aca 0d28:0204 ARM DAPLink CMSIS-DAP 0240000034544e45001b00028aa9001a2011000097969900 376 | ``` 377 | 378 | ### OpenOCD 379 | 380 | When using a debug probe / development board that uses OpenCD, you must have an openocd.cfg file in your 381 | project directory that provides the correct configuration for the debugger and device being used. 382 | 383 | For instance, for the FRDM-K64F: 384 | 385 | ``` 386 | $ cat openocd.cfg 387 | source [find interface/cmsis-dap.cfg] 388 | source [find target/kx.cfg] 389 | kx.cpu configure -event gdb-attach { reset init } 390 | ``` 391 | 392 | You should be able to run "openocd" and have it successfully connect to the device, assuming you only have 393 | a single debug probe of that type connected: 394 | 395 | ``` 396 | $ openocd 397 | Open On-Chip Debugger 0.10.0+dev-00092-g77189db (2017-03-01-20:42) 398 | Licensed under GNU GPL v2 399 | For bug reports, read 400 | http://openocd.org/doc/doxygen/bugs.html 401 | Info : auto-selecting first available session transport "swd". To override use 'transport select '. 402 | Info : add flash_bank kinetis kx.flash 403 | adapter speed: 1000 kHz 404 | none separate 405 | cortex_m reset_config sysresetreq 406 | Info : CMSIS-DAP: SWD Supported 407 | Info : CMSIS-DAP: Interface Initialised (SWD) 408 | Info : CMSIS-DAP: FW Version = 1.0 409 | Info : SWCLK/TCK = 0 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1 410 | Info : CMSIS-DAP: Interface ready 411 | Info : clock speed 1000 kHz 412 | Info : SWD DPIDR 0x2ba01477 413 | Info : MDM: Chip is unsecured. Continuing. 414 | Info : kx.cpu: hardware has 6 breakpoints, 4 watchpoints 415 | ^C 416 | $ 417 | ``` 418 | 419 | Bobbin will invoke OpenOCD with additional command line parameters specifying the USB serial number 420 | of the device to open. 421 | 422 | ### J-Link 423 | 424 | J-Link debug probes require a device identfier that specifies the target MCU. You must specify this by using the 425 | --jlink-device=<JLINK-DEVICE> command line parameter or by adding a jlink-device key to the [loader] section 426 | of your .bobbin/config file: 427 | 428 | ``` 429 | [loader] 430 | jlink-device = "S32K144" 431 | ``` 432 | 433 | You may view a list of devices at [J-Link - Supported Devices](https://www.segger.com/products/debug-probes/j-link/technology/cpus-and-devices/j-link-supported-devices/). 434 | 435 | ### Teensy Loader 436 | 437 | teensy_loader_cli requires an additional command line parameter --teensy-mcu=<MCU> that tells it the exact MCU being used. You 438 | will need to add a teensy-mcu key to the [loader] section of your .bobbin/config file: 439 | 440 | ``` 441 | [loader] 442 | teensy-mcu = "mk20dx256" # Teensy 3.2 443 | ``` 444 | ``` 445 | [loader] 446 | teensy-mcu = "mk64fx512" # Teensy 3.5 447 | ``` 448 | ``` 449 | [loader] 450 | teensy-mcu = "mk66fx1m0" # Teensy 3.6 451 | ``` 452 | ``` 453 | [loader] 454 | teensy-mcu = "mkl26z64" # Teensy LC 455 | ``` 456 | 457 | Use 'teensy_loader_cli --list-mcus' to view a list of supported MCUs. 458 | 459 | ### BOSSA 460 | 461 | If you have `bossac` 1.9 or later, or 1.8 and an M4 board, you may need to 462 | specify the offset address to start the flashing. This is because by default 463 | `bossac` will start flashing at address 0x0000, which is likely where your 464 | locked bootloader is located. 465 | 466 | These values seem to work for Adafruit M0/M4 devices with their UF2 bootloader, 467 | such as Feather M0/M4, Circuit Playground Express, and NeoTrellis M4: 468 | 469 | * For M0 devices, use `--offset 0x2000` 470 | * For M4 devices, use `--offset 0x4000` 471 | 472 | You can also specify this in the [loader] section of your .bobbin/config file: 473 | 474 | ``` 475 | [loader] 476 | offset = "0x2000" # M0 477 | ``` 478 | ``` 479 | [loader] 480 | offset = "0x4000" # M4 481 | ``` 482 | 483 | 484 | For more information about the UF2 bootloader and BOSSA, see Adafruit’s 485 | [UF2 Bootloader Details](https://learn.adafruit.com/adafruit-feather-m0-express-designed-for-circuit-python-circuitpython/uf2-bootloader-details) page. 486 | -------------------------------------------------------------------------------- /src/stlink/mod.rs: -------------------------------------------------------------------------------- 1 | mod util; 2 | mod constants; 3 | 4 | use libusb; 5 | pub use self::constants::*; 6 | 7 | 8 | use byteorder::{ByteOrder, LittleEndian}; 9 | 10 | use std::time::Duration; 11 | use std::thread; 12 | use std::convert::{AsRef, AsMut}; 13 | 14 | mod errors { 15 | error_chain!{ 16 | foreign_links { 17 | LibUsb(::libusb::Error); 18 | } 19 | } 20 | } 21 | 22 | pub use errors::*; 23 | 24 | #[derive(Debug, Clone)] 25 | pub struct Config { 26 | vendor_id: u16, 27 | product_id: u16, 28 | send_ep: u8, 29 | recv_ep: u8, 30 | trace_ep: u8, 31 | target_clk: u32, 32 | trace_clk: u32, 33 | serial_number: String, 34 | } 35 | 36 | impl Config { 37 | pub fn new( 38 | vendor_id: u16, 39 | product_id: u16, 40 | send_ep: u8, 41 | recv_ep: u8, 42 | trace_ep: u8, 43 | target_clk: u32, 44 | trace_clk: u32, 45 | serial_number: &str, 46 | ) -> Self { 47 | Config { 48 | vendor_id: vendor_id, 49 | product_id: product_id, 50 | send_ep: send_ep, 51 | recv_ep: recv_ep, 52 | trace_ep: trace_ep, 53 | target_clk: target_clk, 54 | trace_clk: trace_clk, 55 | serial_number: String::from(serial_number), 56 | } 57 | } 58 | } 59 | 60 | pub struct Context { 61 | inner: libusb::Context, 62 | timeout: Duration, 63 | } 64 | 65 | impl Context { 66 | pub fn connect(&mut self, cfg: Config) -> Result> { 67 | let timeout = self.timeout; 68 | //self.inner.set_log_level(libusb::LogLevel::Debug); 69 | for device in self.inner.devices()?.iter() { 70 | let device_desc = device.device_descriptor()?; 71 | 72 | if device_desc.vendor_id() != cfg.vendor_id || 73 | device_desc.product_id() != cfg.product_id 74 | { 75 | continue; 76 | } 77 | 78 | let device_handle = device.open()?; 79 | let lang = device_handle.read_languages(timeout)?[0]; 80 | 81 | if device_desc.serial_number_string_index().is_some() { 82 | if device_handle.read_serial_number_string( 83 | lang, 84 | &device_desc, 85 | timeout, 86 | )? == cfg.serial_number 87 | { 88 | return Ok(Some(Debugger { 89 | config: cfg, 90 | timeout: self.timeout, 91 | device: device, 92 | desc: device_desc, 93 | handle: device_handle, 94 | })); 95 | 96 | } 97 | } 98 | } 99 | Ok(None) 100 | } 101 | } 102 | 103 | pub struct Debugger<'a> { 104 | config: Config, 105 | timeout: Duration, 106 | device: libusb::Device<'a>, 107 | desc: libusb::DeviceDescriptor, 108 | handle: libusb::DeviceHandle<'a>, 109 | } 110 | 111 | impl<'a> Debugger<'a> { 112 | pub fn reinit(&mut self) -> Result<()> { 113 | println!("resetting device"); 114 | self.handle.release_interface(0)?; 115 | self.handle.reset()?; 116 | thread::sleep(Duration::from_millis(1000)); 117 | self.handle = self.device.open()?; 118 | Ok(()) 119 | } 120 | 121 | pub fn configure(&mut self, force: bool) -> Result<()> { 122 | if self.handle.active_configuration()? != 1 || force { 123 | self.handle.set_active_configuration(1)?; 124 | } 125 | self.handle.claim_interface(0)?; 126 | // self.handle.set_alternate_setting(0, 0)?; 127 | Ok(()) 128 | } 129 | 130 | pub fn dump(&mut self) -> Result<()> { 131 | let timeout = self.timeout; 132 | let lang = self.handle.read_languages(timeout)?[0]; 133 | println!("Vendor ID: {:04x}", self.desc.vendor_id()); 134 | println!("Product ID: {:04x}", self.desc.product_id()); 135 | println!( 136 | "Manufacturer: {}", 137 | self.handle.read_manufacturer_string( 138 | lang, 139 | &self.desc, 140 | timeout, 141 | )? 142 | ); 143 | println!( 144 | "Product: {}", 145 | self.handle.read_product_string(lang, &self.desc, timeout)? 146 | ); 147 | println!( 148 | "Serial #: {}", 149 | self.handle.read_serial_number_string( 150 | lang, 151 | &self.desc, 152 | timeout, 153 | )? 154 | ); 155 | Ok(()) 156 | } 157 | 158 | pub fn send(&self, src: &[u8]) -> Result { 159 | Ok(self.handle.write_bulk( 160 | self.config.send_ep, 161 | src, 162 | self.timeout, 163 | )?) 164 | } 165 | 166 | pub fn recv(&self, dst: &mut [u8]) -> Result { 167 | Ok(self.handle.read_bulk( 168 | self.config.recv_ep, 169 | dst, 170 | self.timeout, 171 | )?) 172 | } 173 | 174 | pub fn trace_recv(&self, dst: &mut [u8]) -> Result { 175 | Ok(self.handle.read_bulk( 176 | self.config.trace_ep, 177 | dst, 178 | self.timeout, 179 | )?) 180 | } 181 | 182 | pub fn send_u32(&self, src: &[u32]) -> Result { 183 | self.send(util::u32_as_u8(src)).map(|v| v >> 2) 184 | } 185 | 186 | pub fn recv_u32(&self, dst: &mut [u32]) -> Result { 187 | self.recv(util::u32_as_u8_mut(dst)).map(|v| v >> 2) 188 | } 189 | 190 | pub fn send_req>(&mut self, a: A) -> Result<()> { 191 | self.send(Request::new(a).as_ref())?; 192 | Ok(()) 193 | } 194 | 195 | pub fn recv_res(&mut self, len: usize) -> Result { 196 | let mut res = Response::new(len); 197 | self.recv(res.as_mut())?; 198 | Ok(res) 199 | } 200 | 201 | pub fn xfer>(&mut self, a: A, len: usize) -> Result { 202 | self.send_req(a)?; 203 | self.recv_res(len) 204 | } 205 | 206 | pub fn cmd>(&mut self, a: A) -> Result<()> { 207 | self.send_req(a)?; 208 | self.recv_res(2)?; 209 | Ok(()) 210 | } 211 | 212 | pub fn version(&mut self) -> Result { 213 | let mut buf = [0u8; 6]; 214 | self.send_req([GET_VERSION])?; 215 | self.recv(&mut buf)?; 216 | Ok(Version(buf)) 217 | } 218 | 219 | pub fn voltage(&mut self) -> Result { 220 | let mut res = self.xfer([GET_TARGET_VOLTAGE], 8)?; 221 | 222 | let adc0 = res.read_u32(); 223 | let adc1 = res.read_u32(); 224 | 225 | let v = if adc0 > 0 { 226 | 2.4 * (adc1 as f32) / (adc0 as f32) 227 | } else { 228 | 0.0 229 | }; 230 | 231 | Ok(v) 232 | } 233 | 234 | pub fn mode(&mut self) -> Result { 235 | Ok(match self.xfer([GET_CURRENT_MODE], 2)?.read_u16() { 236 | 0x00 => Mode::Dfu, 237 | 0x01 => Mode::Mass, 238 | 0x02 => Mode::Debug, 239 | 0x03 => Mode::Swim, 240 | 0x04 => Mode::Bootloader, 241 | m @ _ => bail!("Unrecognized Mode: 0x{:02x}", m), 242 | }) 243 | } 244 | 245 | pub fn core_id(&mut self) -> Result { 246 | Ok(self.xfer([DEBUG_COMMAND, DEBUG_READCOREID], 4)?.read_u32()) 247 | } 248 | 249 | pub fn enter_swd_mode(&mut self) -> Result<()> { 250 | self.cmd([DEBUG_COMMAND, DEBUG_APIV2_ENTER, DEBUG_ENTER_SWD]) 251 | } 252 | 253 | pub fn exit_dfu_mode(&mut self) -> Result<()> { 254 | self.send_req([DFU_COMMAND, DFU_EXIT]) 255 | } 256 | 257 | pub fn reset(&mut self) -> Result<()> { 258 | self.cmd([DEBUG_COMMAND, DEBUG_APIV2_RESETSYS]) 259 | } 260 | 261 | pub fn run(&mut self) -> Result<()> { 262 | self.cmd([DEBUG_COMMAND, DEBUG_RUNCORE]) 263 | } 264 | 265 | pub fn halt(&mut self) -> Result<()> { 266 | self.cmd([DEBUG_COMMAND, DEBUG_FORCEDEBUG]) 267 | } 268 | 269 | pub fn step(&mut self) -> Result<()> { 270 | self.cmd([DEBUG_COMMAND, DEBUG_STEPCORE]) 271 | } 272 | 273 | 274 | pub fn read_regs(&mut self) -> Result { 275 | let cmd = Request::new([DEBUG_COMMAND, DEBUG_APIV2_READALLREGS]); 276 | let mut res = self.xfer(cmd, 88)?; 277 | let _ = res.read_u32(); 278 | Ok(res) 279 | } 280 | 281 | pub fn read_reg(&mut self, reg: u8) -> Result { 282 | let cmd = Request::new([DEBUG_COMMAND, DEBUG_APIV2_READREG]).write_u8(reg); 283 | let mut res = self.xfer(cmd, 8)?; 284 | let _ = res.read_u32(); 285 | Ok(res.read_u32()) 286 | } 287 | 288 | pub fn write_reg(&mut self, reg: u8, value: u32) -> Result<()> { 289 | let cmd = Request::new([DEBUG_COMMAND, DEBUG_APIV2_WRITEREG]) 290 | .write_u8(reg) 291 | .write_u32(value); 292 | let mut res = self.xfer(cmd, 2)?; 293 | let _ = res.read_u16(); 294 | Ok(()) 295 | } 296 | 297 | pub fn check_rw_status(&mut self) -> Result<()> { 298 | self.cmd([DEBUG_COMMAND, DEBUG_APIV2_GETLASTRWSTATUS]) 299 | } 300 | 301 | pub fn read_mem8(&mut self, addr: u32, dst: &mut [u8]) -> Result<()> { 302 | let cmd = Request::new([DEBUG_COMMAND, DEBUG_READMEM_8BIT]) 303 | .write_u32(addr) 304 | .write_u16(dst.len() as u16); 305 | self.send_req(cmd)?; 306 | // Two bytes are returned if single byte is requested 307 | if dst.len() == 1 { 308 | let mut tmp = [0u8; 2]; 309 | self.recv(&mut tmp)?; 310 | dst[0] = tmp[0]; 311 | } else { 312 | self.recv(dst)?; 313 | } 314 | self.check_rw_status() 315 | } 316 | 317 | pub fn write_mem8(&mut self, addr: u32, src: &[u8]) -> Result<()> { 318 | let cmd = Request::new([DEBUG_COMMAND, DEBUG_WRITEMEM_8BIT]) 319 | .write_u32(addr) 320 | .write_u16(src.len() as u16); 321 | self.send_req(cmd)?; 322 | self.send(src)?; 323 | self.check_rw_status() 324 | } 325 | 326 | 327 | pub fn read_mem32(&mut self, addr: u32, dst: &mut [u32]) -> Result<()> { 328 | let cmd = Request::new([DEBUG_COMMAND, DEBUG_READMEM_32BIT]) 329 | .write_u32(addr) 330 | .write_u16((dst.len() * 4) as u16); 331 | self.send_req(cmd)?; 332 | self.recv_u32(dst)?; 333 | self.check_rw_status() 334 | } 335 | 336 | pub fn write_mem32(&mut self, addr: u32, src: &[u32]) -> Result<()> { 337 | let cmd = Request::new([DEBUG_COMMAND, DEBUG_WRITEMEM_32BIT]) 338 | .write_u32(addr) 339 | .write_u16((src.len() * 4) as u16); 340 | self.send_req(cmd)?; 341 | self.send_u32(src)?; 342 | self.check_rw_status() 343 | } 344 | 345 | pub fn read_32(&mut self, addr: u32) -> Result { 346 | let mut tmp = [0u32]; 347 | self.read_mem32(addr, &mut tmp)?; 348 | Ok(tmp[0]) 349 | } 350 | 351 | pub fn write_32(&mut self, addr: u32, value: u32) -> Result<()> { 352 | self.write_mem32(addr, &[value]) 353 | } 354 | 355 | pub fn read_mem(&mut self, addr: u32, dst: &mut [u8]) -> Result<()> { 356 | // TODO: Read chunks, add support for 32bit 357 | for i in 0..dst.len() { 358 | self.read_mem8(addr + i as u32, &mut dst[i..i + 1])?; 359 | } 360 | Ok(()) 361 | } 362 | 363 | pub fn write_mem(&mut self, addr: u32, src: &[u8]) -> Result<()> { 364 | // TODO: Write chunks, add support for 32bit 365 | for i in 0..src.len() { 366 | self.write_mem8(addr + i as u32, &src[i..i + 1])?; 367 | } 368 | Ok(()) 369 | } 370 | 371 | pub fn read_debug(&mut self, addr: u32) -> Result { 372 | let cmd = Request::new([DEBUG_COMMAND, DEBUG_APIV2_READDEBUGREG]).write_u32(addr); 373 | let mut res = self.xfer(cmd, 8)?; 374 | Ok(res.skip(4).read_u32()) 375 | } 376 | 377 | pub fn write_debug(&mut self, addr: u32, value: u32) -> Result<()> { 378 | self.cmd( 379 | Request::new([DEBUG_COMMAND, DEBUG_APIV2_WRITEDEBUGREG]) 380 | .write_u32(addr) 381 | .write_u32(value), 382 | ) 383 | } 384 | 385 | pub fn trace_start_rx(&mut self, source_hz: u32) -> Result<()> { 386 | self.cmd( 387 | Request::new([DEBUG_COMMAND, DEBUG_APIV2_START_TRACE_RX]) 388 | .write_u16(4096) 389 | .write_u32(source_hz), 390 | ) 391 | } 392 | 393 | pub fn trace_stop_rx(&mut self) -> Result<()> { 394 | self.cmd([DEBUG_COMMAND, DEBUG_APIV2_STOP_TRACE_RX]) 395 | } 396 | 397 | pub fn trace_bytes_available(&mut self) -> Result { 398 | Ok( 399 | self.xfer([DEBUG_COMMAND, DEBUG_APIV2_GET_TRACE_NB], 2)? 400 | .read_u16(), 401 | ) 402 | } 403 | 404 | pub fn trace_set_swdclk(&mut self, divisor: u16) -> Result<()> { 405 | self.cmd( 406 | Request::new([DEBUG_COMMAND, DEBUG_APIV2_SWD_SET_FREQ]).write_u16(divisor), 407 | ) 408 | } 409 | 410 | pub fn trace_read(&mut self, buf: &mut [u8]) -> Result { 411 | let bytes_available = self.trace_bytes_available()?; 412 | let buf = &mut buf[..bytes_available as usize]; 413 | if buf.len() > 0 { 414 | self.trace_recv(buf) 415 | } else { 416 | Ok(0) 417 | } 418 | } 419 | 420 | pub fn trace_setup( 421 | &mut self, 422 | stim_bits: u32, 423 | sync_packets: u32, 424 | cpu_hz: u32, 425 | swo_hz: u32, 426 | ) -> Result<()> { 427 | self.read_debug(DCB_DHCSR)?; 428 | self.write_debug(DCB_DEMCR, DCB_DEMCR_TRCENA)?; 429 | 430 | let mut reg = self.read_32(DBGMCU_CR)?; 431 | reg |= DBGMCU_CR_DEBUG_TRACE_IOEN | DBGMCU_CR_DEBUG_STOP | DBGMCU_CR_DEBUG_STANDBY | 432 | DBGMCU_CR_DEBUG_SLEEP; 433 | self.write_32(DBGMCU_CR, reg)?; 434 | // ST ref man says we set this to 1 even in async mode, it's still "one" pin wide 435 | self.write_32(TPIU_CSPSR, 1)?; // currently selelct parallel size register ==> 1 bit wide. 436 | let prescaler = (cpu_hz / swo_hz) - 1; 437 | self.write_32(TPIU_ACPR, prescaler)?; // async prescalar 438 | self.write_32(TPIU_SPPR, TPIU_SPPR_TXMODE_NRZ)?; 439 | self.write_32(TPIU_FFCR, 0)?; // Disable tpiu formatting 440 | self.write_32(ITM_LAR, SCS_LAR_KEY)?; 441 | self.write_32( 442 | ITM_TCR, 443 | ((1 << 16) | ITM_TCR_SYNCENA | ITM_TCR_ITMENA), 444 | )?; 445 | self.write_32(ITM_TER, stim_bits)?; 446 | self.write_32(ITM_TPR, stim_bits)?; 447 | self.set_dwt_sync_tap(sync_packets)?; 448 | Ok(()) 449 | } 450 | 451 | pub fn set_dwt_sync_tap(&mut self, syncbits: u32) -> Result<()> { 452 | // Selects the position of the synchronization packet counter tap 453 | // on the CYCCNT counter. This determines the 454 | // Synchronization packet rate: 455 | // 00 = Disabled. No Synchronization packets. 456 | // 01 = Synchronization counter tap at CYCCNT[24] 457 | // 10 = Synchronization counter tap at CYCCNT[26] 458 | // 11 = Synchronization counter tap at CYCCNT[28] 459 | // For more information see The synchronization packet timer 460 | // on page C1-874. 461 | 462 | let mut reg = self.read_32(DWT_CTRL)?; 463 | reg &= !(3 << 10); 464 | reg |= (syncbits << 10) | 1; // Must have cyccnt to have cyccnt tap! 465 | self.write_32(DWT_CTRL, reg)?; 466 | Ok(()) 467 | } 468 | 469 | pub fn run_trace(&mut self) -> Result<()> { 470 | use std::time::Duration; 471 | use std::thread; 472 | use std::io::{self, Write}; 473 | 474 | let mode = match self.mode() { 475 | Ok(mode) => mode, 476 | Err(_) => { 477 | self.reinit()?; 478 | self.configure(true)?; 479 | self.mode()? 480 | } 481 | }; 482 | if mode == Mode::Dfu { 483 | self.exit_dfu_mode()?; 484 | } 485 | if mode != Mode::Debug { 486 | self.enter_swd_mode()?; 487 | } 488 | 489 | if mode != Mode::Debug { 490 | bail!("Could not enter Debug mode"); 491 | } 492 | 493 | self.halt()?; 494 | 495 | let (target_clk, trace_clk) = (self.config.target_clk, self.config.trace_clk); 496 | 497 | self.trace_setup(0xffffffff, 0, target_clk, trace_clk)?; 498 | self.trace_start_rx(trace_clk)?; 499 | self.run()?; 500 | 501 | let mut trace_buf = [0u8; 4096]; 502 | let stdout = io::stdout(); 503 | let mut stdout = stdout.lock(); 504 | loop { 505 | let n = self.trace_read(&mut trace_buf)?; 506 | if n > 0 { 507 | let mut r = Reader::new(&trace_buf[..n]); 508 | while let Some((port, data)) = r.next() { 509 | if port == 0 { 510 | stdout.write_all(data)? 511 | } 512 | } 513 | stdout.flush()?; 514 | } 515 | thread::sleep(Duration::from_millis(10)); 516 | } 517 | } 518 | } 519 | 520 | pub fn context() -> Result { 521 | Ok(Context { 522 | inner: libusb::Context::new()?, 523 | timeout: Duration::from_millis(100), 524 | }) 525 | } 526 | 527 | #[derive(Debug, PartialEq)] 528 | pub enum Mode { 529 | Dfu = 0x0, 530 | Mass = 0x1, 531 | Debug = 0x2, 532 | Swim = 0x3, 533 | Bootloader = 0x4, 534 | } 535 | 536 | pub struct Version(pub [u8; 6]); 537 | 538 | impl Version { 539 | pub fn version(&self) -> u16 { 540 | LittleEndian::read_u16(&self.0[..2]) 541 | } 542 | 543 | pub fn stlink(&self) -> u8 { 544 | ((self.version() >> 12) & 0x0f) as u8 545 | } 546 | 547 | pub fn jtag(&self) -> u8 { 548 | ((self.version() >> 6) & 0x3f) as u8 549 | } 550 | 551 | pub fn swim(&self) -> u8 { 552 | (self.version() & 0x3f) as u8 553 | } 554 | 555 | pub fn vid(&self) -> u16 { 556 | LittleEndian::read_u16(&self.0[2..4]) 557 | } 558 | 559 | pub fn pid(&self) -> u16 { 560 | LittleEndian::read_u16(&self.0[4..6]) 561 | } 562 | } 563 | 564 | pub struct Request { 565 | buf: [u8; 64], 566 | len: usize, 567 | } 568 | 569 | impl Request { 570 | pub fn new>(a: A) -> Self { 571 | let mut buf = [0u8; 64]; 572 | let arg = a.as_ref(); 573 | &mut buf[..arg.len()].copy_from_slice(arg); 574 | Request { 575 | buf: buf, 576 | len: arg.len(), 577 | } 578 | } 579 | 580 | pub fn write_u8(mut self, value: u8) -> Self { 581 | self.buf[self.len] = value; 582 | self.len += 1; 583 | self 584 | } 585 | 586 | pub fn write_u16(mut self, value: u16) -> Self { 587 | LittleEndian::write_u16(&mut self.buf[self.len..], value); 588 | self.len += 2; 589 | self 590 | } 591 | 592 | pub fn write_u32(mut self, value: u32) -> Self { 593 | LittleEndian::write_u32(&mut self.buf[self.len..], value); 594 | self.len += 4; 595 | self 596 | } 597 | } 598 | 599 | impl AsRef<[u8]> for Request { 600 | fn as_ref(&self) -> &[u8] { 601 | &self.buf[..16] 602 | } 603 | } 604 | 605 | pub struct Response { 606 | buf: [u8; 128], 607 | cap: usize, 608 | pos: usize, 609 | } 610 | 611 | impl Response { 612 | pub fn new(cap: usize) -> Self { 613 | Response { 614 | buf: [0u8; 128], 615 | cap: cap, 616 | pos: 0, 617 | } 618 | } 619 | 620 | pub fn len(&self) -> usize { 621 | self.cap - self.pos 622 | } 623 | 624 | pub fn skip(&mut self, n: usize) -> &mut Self { 625 | self.pos += n; 626 | self 627 | } 628 | 629 | pub fn read_u8(&mut self) -> u8 { 630 | let v = self.buf[self.pos]; 631 | self.pos += 1; 632 | v 633 | } 634 | 635 | pub fn read_u16(&mut self) -> u16 { 636 | let v = LittleEndian::read_u16(&self.buf[self.pos..]); 637 | self.pos += 2; 638 | v 639 | } 640 | 641 | pub fn read_u32(&mut self) -> u32 { 642 | let v = LittleEndian::read_u32(&self.buf[self.pos..]); 643 | self.pos += 4; 644 | v 645 | } 646 | } 647 | 648 | impl AsRef<[u8]> for Response { 649 | fn as_ref(&self) -> &[u8] { 650 | &self.buf[..self.pos] 651 | } 652 | } 653 | 654 | 655 | impl AsMut<[u8]> for Response { 656 | fn as_mut(&mut self) -> &mut [u8] { 657 | &mut self.buf[..self.cap] 658 | } 659 | } 660 | 661 | 662 | pub struct Reader<'a> { 663 | buf: &'a [u8], 664 | pos: usize, 665 | } 666 | 667 | impl<'a> Reader<'a> { 668 | pub fn new(buf: &[u8]) -> Reader { 669 | Reader { buf: buf, pos: 0 } 670 | } 671 | 672 | pub fn next(&mut self) -> Option<(u8, &'a [u8])> { 673 | if self.pos >= self.buf.len() { 674 | return None; 675 | } 676 | let len = self.buf.len(); 677 | let pos = self.pos; 678 | let header = self.buf[pos]; 679 | let port = header >> 3; 680 | match header & 0b111 { 681 | 0b01 => { 682 | self.pos += 2; 683 | if pos + 2 > len { 684 | return None; 685 | }; 686 | Some((port, &self.buf[pos + 1..pos + 2])) 687 | } 688 | 0b10 => { 689 | self.pos += 3; 690 | if pos + 3 > len { 691 | return None; 692 | }; 693 | Some((port, &self.buf[pos + 1..pos + 3])) 694 | } 695 | 0b11 => { 696 | self.pos += 5; 697 | if pos + 5 > len { 698 | return None; 699 | }; 700 | Some((port, &self.buf[pos + 1..pos + 5])) 701 | } 702 | _ => None, 703 | } 704 | } 705 | } 706 | -------------------------------------------------------------------------------- /src/device.rs: -------------------------------------------------------------------------------- 1 | use sha1; 2 | #[cfg(target_os = "macos")] 3 | use ioreg; 4 | #[cfg(target_os = "linux")] 5 | use sysfs; 6 | use clap::ArgMatches; 7 | use std::path::{Path, PathBuf}; 8 | use std::fs; 9 | use std::io::Read; 10 | use std::fmt::Write; 11 | use config::Config; 12 | #[cfg(feature = "stlink")] 13 | use stlink; 14 | use Result; 15 | 16 | #[derive(Debug)] 17 | pub struct UsbDevice { 18 | pub vendor_id: u16, 19 | pub product_id: u16, 20 | pub vendor_string: String, 21 | pub product_string: String, 22 | pub serial_number: String, 23 | pub location_id: Option, 24 | pub path: Option, 25 | } 26 | 27 | impl UsbDevice { 28 | pub fn hash(&self) -> String { 29 | let mut h = sha1::Sha1::new(); 30 | h.update(self.vendor_string.as_bytes()); 31 | h.update(self.product_string.as_bytes()); 32 | h.update(self.serial_number.as_bytes()); 33 | h.digest().to_string() 34 | } 35 | } 36 | 37 | pub trait Device { 38 | fn usb(&self) -> &UsbDevice; 39 | fn hash(&self) -> String { 40 | self.usb().hash() 41 | } 42 | fn is_unknown(&self) -> bool { 43 | self.device_type().is_none() 44 | } 45 | fn device_type(&self) -> Option<&str> { 46 | None 47 | } 48 | fn loader_type(&self) -> Option<&str> { 49 | None 50 | } 51 | fn debugger_type(&self) -> Option<&str> { 52 | None 53 | } 54 | fn cdc_path(&self) -> Option { 55 | None 56 | } 57 | fn msd_path(&self) -> Option { 58 | None 59 | } 60 | fn bossa_path(&self) -> Option { 61 | None 62 | } 63 | fn gdb_path(&self) -> Option { 64 | None 65 | } 66 | 67 | fn jlink_supported(&self) -> bool { 68 | self.device_type() == Some("JLink") 69 | } 70 | 71 | fn openocd_supported(&self) -> bool { 72 | self.openocd_serial().is_some() 73 | } 74 | fn openocd_serial(&self) -> Option { 75 | None 76 | } 77 | 78 | fn can_trace_itm(&self) -> bool { 79 | false 80 | } 81 | fn trace_itm(&self, target_clk: u32, trace_clk: u32) -> Result<()> { 82 | unimplemented!() 83 | } 84 | } 85 | 86 | pub struct UnknownDevice { 87 | usb: UsbDevice, 88 | } 89 | 90 | impl Device for UnknownDevice { 91 | fn usb(&self) -> &UsbDevice { 92 | &self.usb 93 | } 94 | } 95 | 96 | pub struct JLinkDevice { 97 | usb: UsbDevice, 98 | } 99 | 100 | impl Device for JLinkDevice { 101 | fn usb(&self) -> &UsbDevice { 102 | &self.usb 103 | } 104 | 105 | fn device_type(&self) -> Option<&str> { 106 | Some("JLink") 107 | } 108 | 109 | fn loader_type(&self) -> Option<&str> { 110 | Some("JLink") 111 | } 112 | 113 | fn debugger_type(&self) -> Option<&str> { 114 | Some("JLink") 115 | } 116 | 117 | #[cfg(target_os = "macos")] 118 | fn cdc_path(&self) -> Option { 119 | let path = format!("/dev/cu.usbmodem{}{}", 120 | &format!("{:x}", self.usb.location_id.unwrap_or(0))[..4], 121 | 1, 122 | ); 123 | if Path::new(&path).exists() { 124 | Some(path) 125 | } else { 126 | None 127 | } 128 | } 129 | 130 | #[cfg(target_os = "linux")] 131 | fn cdc_path(&self) -> Option { 132 | if let Some(ref path) = self.usb().path { 133 | if let Some(cdc_path) = sysfs::cdc_path(path, "1.0") { 134 | if Path::new(&cdc_path).exists() { 135 | Some(cdc_path) 136 | } else { 137 | None 138 | } 139 | } else { 140 | None 141 | } 142 | } else { 143 | None 144 | } 145 | } 146 | 147 | 148 | fn openocd_serial(&self) -> Option { 149 | Some(format!("jlink_serial {}", self.usb.serial_number)) 150 | } 151 | } 152 | 153 | pub struct StLinkV2Device { 154 | usb: UsbDevice, 155 | } 156 | 157 | impl Device for StLinkV2Device { 158 | fn usb(&self) -> &UsbDevice { 159 | &self.usb 160 | } 161 | 162 | fn device_type(&self) -> Option<&str> { 163 | Some("STLinkV2") 164 | } 165 | 166 | fn loader_type(&self) -> Option<&str> { 167 | Some("OpenOCD") 168 | } 169 | 170 | fn debugger_type(&self) -> Option<&str> { 171 | Some("OpenOCD") 172 | } 173 | 174 | fn openocd_serial(&self) -> Option { 175 | // see https://armprojects.wordpress.com/2016/08/21/debugging-multiple-stm32-in-eclipse-with-st-link-v2-and-openocd/ 176 | // This assumes serial number is an 8-bit ASCII string that has been directly encoded as UTF-8 177 | // Additionally, assume that OpenOCD will replace non-ASCII characters with a question mark. 178 | 179 | let serial = self.usb.serial_number.clone().into_bytes(); 180 | let mut out = String::from("hla_serial \""); 181 | 182 | for c in self.usb.serial_number.chars() { 183 | let c = c as u8; 184 | let b = if c > 0x7f { 0x3f } else { c }; 185 | write!(out, "\\x{:02X}", b).unwrap(); 186 | } 187 | write!(out, "\"").unwrap(); 188 | Some(out) 189 | } 190 | 191 | #[cfg(feature = "stlink")] 192 | fn can_trace_itm(&self) -> bool { 193 | true 194 | } 195 | 196 | #[allow(unreachable_code)] 197 | #[cfg(feature = "stlink")] 198 | fn trace_itm(&self, target_clk: u32, trace_clk: u32) -> Result<()> { 199 | 200 | let mut ctx = stlink::context()?; 201 | let cfg = stlink::Config::new( 202 | self.usb.vendor_id, 203 | self.usb.product_id, 204 | 0x2, 205 | 0x81, 206 | 0x83, 207 | target_clk, 208 | trace_clk, 209 | &self.usb.serial_number, 210 | ); 211 | if let Some(mut d) = ctx.connect(cfg)? { 212 | println!("configure"); 213 | d.configure(false)?; 214 | println!("run trace"); 215 | d.run_trace()?; 216 | 217 | } else { 218 | bail!("No device found"); 219 | } 220 | unreachable!() 221 | } 222 | } 223 | 224 | pub struct StLinkV21Device { 225 | usb: UsbDevice, 226 | } 227 | 228 | impl Device for StLinkV21Device { 229 | fn usb(&self) -> &UsbDevice { 230 | &self.usb 231 | } 232 | 233 | fn device_type(&self) -> Option<&str> { 234 | Some("STLinkV21") 235 | } 236 | 237 | fn loader_type(&self) -> Option<&str> { 238 | Some("OpenOCD") 239 | } 240 | 241 | fn debugger_type(&self) -> Option<&str> { 242 | Some("OpenOCD") 243 | } 244 | 245 | #[cfg(target_os = "macos")] 246 | fn cdc_path(&self) -> Option { 247 | Some(format!("/dev/cu.usbmodem{}{}", 248 | &format!("{:x}", self.usb.location_id.unwrap_or(0))[..4], 249 | 3, 250 | )) 251 | } 252 | 253 | #[cfg(target_os = "linux")] 254 | fn cdc_path(&self) -> Option { 255 | if let Some(ref path) = self.usb().path { 256 | sysfs::cdc_path(path, "1.2") 257 | } else { 258 | None 259 | } 260 | } 261 | 262 | fn openocd_serial(&self) -> Option { 263 | Some(format!("hla_serial {}", self.usb.serial_number)) 264 | } 265 | 266 | #[cfg(feature = "stlink")] 267 | fn can_trace_itm(&self) -> bool { 268 | true 269 | } 270 | 271 | #[cfg(feature = "stlink")] 272 | #[allow(unreachable_code)] 273 | fn trace_itm(&self, target_clk: u32, trace_clk: u32) -> Result<()> { 274 | let mut ctx = stlink::context()?; 275 | let cfg = stlink::Config::new( 276 | self.usb.vendor_id, 277 | self.usb.product_id, 278 | 0x1, 279 | 0x81, 280 | 0x82, 281 | target_clk, 282 | trace_clk, 283 | &self.usb.serial_number, 284 | ); 285 | if let Some(mut d) = ctx.connect(cfg)? { 286 | d.configure(false)?; 287 | d.run_trace()?; 288 | 289 | } else { 290 | bail!("No device found"); 291 | } 292 | unreachable!() 293 | } 294 | } 295 | 296 | pub struct TiIcdiDevice { 297 | usb: UsbDevice, 298 | } 299 | 300 | impl Device for TiIcdiDevice { 301 | fn usb(&self) -> &UsbDevice { 302 | &self.usb 303 | } 304 | 305 | fn device_type(&self) -> Option<&str> { 306 | Some("TI-ICDI") 307 | } 308 | 309 | fn loader_type(&self) -> Option<&str> { 310 | Some("OpenOCD") 311 | } 312 | 313 | fn debugger_type(&self) -> Option<&str> { 314 | Some("OpenOCD") 315 | } 316 | 317 | #[cfg(target_os = "macos")] 318 | fn cdc_path(&self) -> Option { 319 | Some(format!( 320 | "/dev/cu.usbmodem{}{}", 321 | &self.usb.serial_number[..7], 322 | 1 323 | )) 324 | } 325 | 326 | #[cfg(target_os = "linux")] 327 | fn cdc_path(&self) -> Option { 328 | if let Some(ref path) = self.usb().path { 329 | sysfs::cdc_path(path, "1.0") 330 | } else { 331 | None 332 | } 333 | } 334 | 335 | fn openocd_serial(&self) -> Option { 336 | Some(format!("hla_serial {}", self.usb.serial_number)) 337 | } 338 | } 339 | 340 | pub struct CmsisDapDevice { 341 | usb: UsbDevice, 342 | } 343 | 344 | impl Device for CmsisDapDevice { 345 | fn usb(&self) -> &UsbDevice { 346 | &self.usb 347 | } 348 | 349 | fn device_type(&self) -> Option<&str> { 350 | Some("DAPLink") 351 | } 352 | 353 | fn loader_type(&self) -> Option<&str> { 354 | Some("OpenOCD") 355 | } 356 | 357 | fn debugger_type(&self) -> Option<&str> { 358 | Some("OpenOCD") 359 | } 360 | 361 | #[cfg(target_os = "macos")] 362 | fn cdc_path(&self) -> Option { 363 | Some(format!("/dev/cu.usbmodem{}{}", 364 | &format!("{:x}", self.usb.location_id.unwrap_or(0))[..4], 365 | 2, 366 | )) 367 | } 368 | 369 | #[cfg(target_os = "linux")] 370 | fn cdc_path(&self) -> Option { 371 | if let Some(ref path) = self.usb().path { 372 | sysfs::cdc_path(path, "1.1") 373 | } else { 374 | None 375 | } 376 | } 377 | 378 | 379 | fn openocd_serial(&self) -> Option { 380 | Some(format!("cmsis_dap_serial {}", self.usb.serial_number)) 381 | } 382 | } 383 | 384 | pub struct DapLinkDevice { 385 | usb: UsbDevice, 386 | } 387 | 388 | impl Device for DapLinkDevice { 389 | fn usb(&self) -> &UsbDevice { 390 | &self.usb 391 | } 392 | 393 | fn device_type(&self) -> Option<&str> { 394 | Some("DAPLink") 395 | } 396 | 397 | fn loader_type(&self) -> Option<&str> { 398 | Some("OpenOCD") 399 | } 400 | 401 | fn debugger_type(&self) -> Option<&str> { 402 | Some("OpenOCD") 403 | } 404 | 405 | #[cfg(target_os = "macos")] 406 | fn cdc_path(&self) -> Option { 407 | Some(format!("/dev/cu.usbmodem{}{}", 408 | &format!("{:x}", self.usb.location_id.unwrap_or(0))[..4], 409 | 2, 410 | )) 411 | } 412 | 413 | #[cfg(target_os = "linux")] 414 | fn cdc_path(&self) -> Option { 415 | if let Some(ref path) = self.usb().path { 416 | sysfs::cdc_path(path, "1.1") 417 | } else { 418 | None 419 | } 420 | } 421 | 422 | fn msd_path(&self) -> Option { 423 | // Look in /Volumes/DAPLINK*/ for DETAILS.TXT 424 | // Look for Unique ID line == serial number 425 | if let Ok(volumes) = fs::read_dir("/Volumes/") { 426 | for volume in volumes { 427 | if let Ok(volume) = volume { 428 | //println!("checking {:?} {}", volume.path(), volume.path().to_string_lossy().starts_with("/Volumes/DAPLINK") ); 429 | if volume.path().to_string_lossy().starts_with( 430 | "/Volumes/DAPLINK", 431 | ) 432 | { 433 | let details = volume.path().join("DETAILS.TXT"); 434 | let mut f = fs::File::open(details).expect("Error opening DETAILS.TXT"); 435 | let mut s = String::new(); 436 | f.read_to_string(&mut s).expect("Error reading details"); 437 | if s.contains(&self.usb.serial_number) { 438 | return Some(volume.path()); 439 | } 440 | } 441 | } 442 | } 443 | } 444 | None 445 | } 446 | 447 | fn openocd_serial(&self) -> Option { 448 | Some(format!("cmsis_dap_serial {}", self.usb.serial_number)) 449 | } 450 | } 451 | 452 | pub struct FeatherDevice { 453 | usb: UsbDevice, 454 | } 455 | 456 | impl Device for FeatherDevice { 457 | fn usb(&self) -> &UsbDevice { 458 | &self.usb 459 | } 460 | 461 | fn device_type(&self) -> Option<&str> { 462 | Some("Feather") 463 | } 464 | 465 | fn loader_type(&self) -> Option<&str> { 466 | Some("Bossa") 467 | } 468 | 469 | #[cfg(target_os = "macos")] 470 | fn bossa_path(&self) -> Option { 471 | // eprintln!("location id: 0x{:0x}", self.usb.location_id.unwrap()); 472 | let loc = format!("{:x}", self.usb.location_id.unwrap_or(0)); 473 | let loc = loc.split("0").next().unwrap(); 474 | if os_version_match("10.14") { 475 | Some(format!("/dev/cu.usbmodem{}01", loc)) 476 | } else { 477 | Some(format!("/dev/cu.usbmodem{}{}", 478 | &format!("{:x}", self.usb.location_id.unwrap_or(0))[..4], 479 | 1, 480 | )) 481 | } 482 | } 483 | } 484 | 485 | pub struct TeensyDevice { 486 | usb: UsbDevice, 487 | } 488 | 489 | fn os_version_match(required_version: &str) -> bool { 490 | let os = os_type::current_platform(); 491 | let os_version = semver::Version::parse(&os.version).unwrap(); 492 | 493 | let ver_str = ">= ".to_string() + required_version; 494 | let r = semver::VersionReq::parse(&ver_str).unwrap(); 495 | 496 | r.matches(&os_version) 497 | } 498 | 499 | impl Device for TeensyDevice { 500 | fn usb(&self) -> &UsbDevice { 501 | &self.usb 502 | } 503 | 504 | fn device_type(&self) -> Option<&str> { 505 | Some("Teensy") 506 | } 507 | 508 | fn loader_type(&self) -> Option<&str> { 509 | Some("Teensy") 510 | } 511 | } 512 | 513 | pub struct Stm32Device { 514 | usb: UsbDevice, 515 | } 516 | 517 | impl Device for Stm32Device { 518 | fn usb(&self) -> &UsbDevice { 519 | &self.usb 520 | } 521 | 522 | fn device_type(&self) -> Option<&str> { 523 | Some("STM32") 524 | } 525 | 526 | fn loader_type(&self) -> Option<&str> { 527 | Some("dfu-util") 528 | } 529 | } 530 | 531 | pub struct BlackMagicDevice { 532 | usb: UsbDevice, 533 | } 534 | 535 | impl Device for BlackMagicDevice { 536 | fn usb(&self) -> &UsbDevice { 537 | &self.usb 538 | } 539 | 540 | fn device_type(&self) -> Option<&str> { 541 | Some("BlackMagicProbe") 542 | } 543 | 544 | fn loader_type(&self) -> Option<&str> { 545 | Some("blackmagic") 546 | } 547 | 548 | fn debugger_type(&self) -> Option<&str> { 549 | Some("blackmagic") 550 | } 551 | 552 | #[cfg(target_os = "macos")] 553 | fn cdc_path(&self) -> Option { 554 | 555 | // Since Macos 10.14 the usbmodem serial number behaviour has changed 556 | // instead of replacing the last character with 1 or 3, it is actually 557 | // added after the last character 558 | if os_version_match("10.14") { 559 | Some(format!("/dev/cu.usbmodem{}3", &self.usb.serial_number)) 560 | } else { 561 | let serial_len = self.usb.serial_number.len(); 562 | Some(format!("/dev/cu.usbmodem{}3", &self.usb.serial_number[..serial_len - 1])) 563 | } 564 | } 565 | 566 | #[cfg(target_os = "linux")] 567 | fn cdc_path(&self) -> Option { 568 | if let Some(ref path) = self.usb().path { 569 | sysfs::cdc_path(path, "1.2") 570 | } else { 571 | None 572 | } 573 | } 574 | 575 | #[cfg(target_os = "macos")] 576 | fn gdb_path(&self) -> Option { 577 | 578 | // Since Macos 10.14 the cu.usbmodem serial number behaviour has changed 579 | // instead of replacing the last character with 1 or 3, it is actually 580 | // added after the last character 581 | if os_version_match("10.14") { 582 | Some(format!("/dev/cu.usbmodem{}1", &self.usb.serial_number)) 583 | } else { 584 | let serial_len = self.usb.serial_number.len(); 585 | Some(format!("/dev/cu.usbmodem{}1", &self.usb.serial_number[..serial_len - 1])) 586 | } 587 | } 588 | 589 | #[cfg(target_os = "linux")] 590 | fn gdb_path(&self) -> Option { 591 | if let Some(ref path) = self.usb().path { 592 | sysfs::cdc_path(path, "1.0") 593 | } else { 594 | None 595 | } 596 | } 597 | } 598 | 599 | pub struct Xds110Device { 600 | usb: UsbDevice, 601 | } 602 | 603 | impl Device for Xds110Device { 604 | fn usb(&self) -> &UsbDevice { 605 | &self.usb 606 | } 607 | 608 | fn device_type(&self) -> Option<&str> { 609 | Some("XDS110") 610 | } 611 | 612 | fn loader_type(&self) -> Option<&str> { 613 | Some("OpenOCD") 614 | } 615 | 616 | fn debugger_type(&self) -> Option<&str> { 617 | Some("OpenOCD") 618 | } 619 | 620 | #[cfg(target_os = "macos")] 621 | fn cdc_path(&self) -> Option { 622 | Some(format!( 623 | "/dev/cu.usbmodem{}{}", 624 | &self.usb.serial_number[..7], 625 | 4 626 | )) 627 | } 628 | 629 | #[cfg(target_os = "linux")] 630 | fn cdc_path(&self) -> Option { 631 | if let Some(ref path) = self.usb().path { 632 | sysfs::cdc_path(path, "1.0") 633 | } else { 634 | None 635 | } 636 | } 637 | 638 | fn openocd_serial(&self) -> Option { 639 | Some(format!("cmsis_dap_serial {}", self.usb.serial_number)) 640 | } 641 | } 642 | 643 | pub struct OlimexDevice { 644 | usb: UsbDevice, 645 | } 646 | 647 | impl Device for OlimexDevice { 648 | fn usb(&self) -> &UsbDevice { 649 | &self.usb 650 | } 651 | 652 | fn device_type(&self) -> Option<&str> { 653 | Some("Olimex") 654 | } 655 | 656 | fn loader_type(&self) -> Option<&str> { 657 | Some("OpenOCD") 658 | } 659 | 660 | fn debugger_type(&self) -> Option<&str> { 661 | Some("OpenOCD") 662 | } 663 | 664 | fn openocd_serial(&self) -> Option { 665 | Some(format!("ftdi_serial {}", self.usb.serial_number)) 666 | } 667 | } 668 | 669 | pub struct DeviceFilter { 670 | all: bool, 671 | device: Option, 672 | } 673 | 674 | impl<'a> From<&'a ArgMatches<'a>> for DeviceFilter { 675 | fn from(other: &ArgMatches) -> DeviceFilter { 676 | DeviceFilter { 677 | all: other.is_present("all"), 678 | device: other.value_of("device").map(String::from), 679 | } 680 | } 681 | } 682 | 683 | pub fn filter(cfg: &Config, args: &ArgMatches, cmd_args: &ArgMatches) -> DeviceFilter { 684 | let device = if let Some(d) = args.value_of("device") { 685 | Some(String::from(d)) 686 | } else if let Some(d) = cfg.filter_device() { 687 | Some(String::from(d)) 688 | } else { 689 | None 690 | }; 691 | 692 | DeviceFilter { 693 | all: args.is_present("all") || cmd_args.is_present("all"), 694 | device: device, 695 | } 696 | } 697 | 698 | pub fn lookup(usb: UsbDevice) -> Box { 699 | match (usb.vendor_id, usb.product_id) { 700 | (0x0d28, 0x0204) => Box::new(DapLinkDevice { usb: usb }), 701 | (0x03eb, 0x2157) => Box::new(CmsisDapDevice { usb: usb }), 702 | (0x0483, 0x3748) => Box::new(StLinkV2Device { usb: usb }), 703 | (0x0483, 0x374b) => Box::new(StLinkV21Device { usb: usb }), 704 | (0x1366, 0x0101) => Box::new(JLinkDevice { usb: usb }), 705 | (0x1366, 0x0105) => Box::new(JLinkDevice { usb: usb }), 706 | (0x1cbe, 0x00fd) => Box::new(TiIcdiDevice { usb: usb }), 707 | (0x0451, 0xbef3) => Box::new(Xds110Device { usb: usb }), 708 | (0x16c0, 0x0486) => Box::new(TeensyDevice { usb: usb }), 709 | (0x16c0, 0x0478) => Box::new(TeensyDevice { usb: usb }), 710 | (0x0483, 0xdf11) => Box::new(Stm32Device { usb: usb }), 711 | (0x1d50, 0x6018) => Box::new(BlackMagicDevice { usb: usb }), 712 | (0x15ba, 0x002a) => Box::new(OlimexDevice { usb: usb }), 713 | // Vendor Prefix Only 714 | (0x1366, _) => Box::new(JLinkDevice { usb: usb }), 715 | // Assume all Adafruit devices are FeatherDevices, which use 716 | // the BOSSA loader. 717 | (0x239a, _) => Box::new(FeatherDevice { usb: usb }), 718 | _ => Box::new(UnknownDevice { usb: usb }), 719 | } 720 | } 721 | 722 | 723 | pub fn enumerate() -> Result>> { 724 | #[cfg(target_os = "macos")] return Ok(ioreg::enumerate()?.into_iter().map(lookup).collect()); 725 | 726 | #[cfg(target_os = "linux")] return Ok(sysfs::enumerate()?.into_iter().map(lookup).collect()); 727 | } 728 | 729 | pub fn search(filter: &DeviceFilter) -> Result>> { 730 | Ok( 731 | enumerate()? 732 | .into_iter() 733 | .filter(|d| { 734 | if !filter.all { 735 | if d.is_unknown() { 736 | return false; 737 | } 738 | } 739 | 740 | if let Some(ref device) = filter.device { 741 | if !filter.all && !d.hash().starts_with(device) { 742 | return false; 743 | } 744 | } 745 | 746 | 747 | true 748 | }) 749 | .collect(), 750 | ) 751 | } 752 | -------------------------------------------------------------------------------- /src/cmd.rs: -------------------------------------------------------------------------------- 1 | use Result; 2 | use clap::ArgMatches; 3 | use config::Config; 4 | use printer::Printer; 5 | use std::io::{self, Read, Write}; 6 | use std::path::PathBuf; 7 | use std::process::*; 8 | // use std::os::unix::io::*; 9 | use std::os::unix::process::CommandExt; 10 | // use std::fs::File; 11 | 12 | use device; 13 | use builder; 14 | use loader; 15 | use debugger; 16 | use console; 17 | use check; 18 | use tempfile; 19 | 20 | pub fn check( 21 | cfg: &Config, 22 | args: &ArgMatches, 23 | cmd_args: &ArgMatches, 24 | out: &mut Printer, 25 | ) -> Result<()> { 26 | writeln!(out, " Bobbin {}", crate_version!())?; 27 | writeln!(out, " Rust {}", check::rust_version().unwrap_or(String::from("Not Found")))?; 28 | writeln!(out, " Cargo {}", check::cargo_version().unwrap_or(String::from("Not Found")))?; 29 | writeln!(out, " Xargo {}", check::xargo_version().unwrap_or(String::from("Not Found")))?; 30 | writeln!(out, " GCC {}", check::gcc_version().unwrap_or(String::from("Not Found")))?; 31 | writeln!(out, " OpenOCD {}", check::openocd_version().unwrap_or(String::from("Not Found")))?; 32 | writeln!(out, " JLink {}", check::jlink_version().unwrap_or(String::from("Not Found")))?; 33 | writeln!(out, " Bossa {}", check::bossac_version().unwrap_or(String::from("Not Found")))?; 34 | writeln!(out, " Teensy {}", check::teensy_version().unwrap_or(String::from("Not Found")))?; 35 | writeln!(out, " dfu-util {}", check::dfu_util_version().unwrap_or(String::from("Not Found")))?; 36 | Ok(()) 37 | } 38 | 39 | pub fn list( 40 | cfg: &Config, 41 | args: &ArgMatches, 42 | cmd_args: &ArgMatches, 43 | out: &mut Printer, 44 | ) -> Result<()> { 45 | if let Some(host) = args.value_of("host").or_else(|| cfg.filter_host()) { 46 | let mut cmd = Command::new("ssh"); 47 | cmd.arg("-q"); 48 | cmd.arg("-t"); 49 | cmd.arg(host); 50 | cmd.arg(".cargo/bin/bobbin"); 51 | if let Some(device) = cfg.device(args) { 52 | cmd.arg("--device").arg(device); 53 | } 54 | if args.is_present("verbose") { 55 | cmd.arg("--verbose"); 56 | } 57 | cmd.arg("list"); 58 | cmd.exec(); 59 | unreachable!() 60 | } 61 | 62 | let filter = device::filter(cfg, args, cmd_args); 63 | let devices = device::search(&filter); 64 | 65 | writeln!(out, "{:08} {:08} {:40} {:24}", 66 | "ID", 67 | " VID:PID", 68 | "Vendor / Product", 69 | "Serial Number", 70 | )?; 71 | for d in devices?.iter() { 72 | let u = d.usb(); 73 | write!(out, "{:08} {:04x}:{:04x} {:40} {:24}", 74 | &d.hash()[..8], 75 | u.vendor_id, 76 | u.product_id, 77 | format!("{} / {}", u.vendor_string, u.product_string), 78 | u.serial_number, 79 | )?; 80 | writeln!(out, "")?; 81 | } 82 | Ok(()) 83 | } 84 | 85 | 86 | pub fn info( 87 | cfg: &Config, 88 | args: &ArgMatches, 89 | cmd_args: &ArgMatches, 90 | out: &mut Printer, 91 | ) -> Result<()> { 92 | if let Some(host) = args.value_of("host").or_else(|| cfg.filter_host()) { 93 | let mut cmd = Command::new("ssh"); 94 | cmd.arg("-q"); 95 | cmd.arg("-t"); 96 | cmd.arg(host); 97 | cmd.arg(".cargo/bin/bobbin"); 98 | if let Some(device) = cfg.device(args) { 99 | cmd.arg("--device").arg(device); 100 | } 101 | if args.is_present("verbose") { 102 | cmd.arg("--verbose"); 103 | } 104 | cmd.arg("info"); 105 | cmd.exec(); 106 | unreachable!() 107 | } 108 | 109 | let filter = device::filter(cfg, args, cmd_args); 110 | let devices = device::search(&filter)?; 111 | 112 | for d in devices.iter() { 113 | let u = d.usb(); 114 | writeln!(out, "{:16} {}", "ID", d.hash())?; 115 | writeln!(out, "{:16} {:04x}", "Vendor ID", u.vendor_id)?; 116 | writeln!(out, "{:16} {:04x}", "Product ID", u.product_id)?; 117 | writeln!(out, "{:16} {}", "Vendor", u.vendor_string)?; 118 | writeln!(out, "{:16} {}", "Product", u.product_string)?; 119 | writeln!(out, "{:16} {}", "Serial Number", u.serial_number)?; 120 | writeln!( 121 | out, 122 | "{:16} {}", 123 | "Type", 124 | d.device_type().unwrap_or("Unknown") 125 | )?; 126 | if let Some(loader_type) = d.loader_type() { 127 | writeln!(out, "{:16} {}", "Loader Type", loader_type)?; 128 | } 129 | if let Some(debugger_type) = d.debugger_type() { 130 | writeln!(out, "{:16} {}", "Debugger Type", debugger_type)?; 131 | } 132 | 133 | if let Some(bossa_path) = d.bossa_path() { 134 | writeln!(out, "{:16} {}", "Bossac Device", bossa_path)?; 135 | } 136 | if let Some(cdc_path) = d.cdc_path() { 137 | writeln!(out, "{:16} {}", "CDC Device", cdc_path)?; 138 | } 139 | if let Some(msd_path) = d.msd_path() { 140 | writeln!(out, "{:16} {}", "MSD Device", msd_path.display())?; 141 | } 142 | if let Some(gdb_path) = d.gdb_path() { 143 | writeln!(out, "{:16} {}", "GDB Device", gdb_path)?; 144 | } 145 | if let Some(openocd_serial) = d.openocd_serial() { 146 | writeln!(out, "{:16} {}", "OpenOCD Serial", openocd_serial)?; 147 | } 148 | writeln!(out, "")?; 149 | } 150 | Ok(()) 151 | } 152 | 153 | pub fn build( 154 | cfg: &Config, 155 | args: &ArgMatches, 156 | cmd_args: &ArgMatches, 157 | out: &mut Printer, 158 | ) -> Result<()> { 159 | let dst = builder::build(cfg, args, cmd_args, out)?; 160 | Ok(()) 161 | } 162 | 163 | pub fn load( 164 | cfg: &Config, 165 | args: &ArgMatches, 166 | cmd_args: &ArgMatches, 167 | out: &mut Printer, 168 | ) -> Result<()> { 169 | 170 | let dst = if let Some(dst) = builder::build(cfg, args, cmd_args, out)? { 171 | dst 172 | } else { 173 | bail!("No build output available to load"); 174 | }; 175 | 176 | if let Some(host) = args.value_of("host").or_else(|| cfg.filter_host()) { 177 | let mut cmd = Command::new("rsync"); 178 | cmd.arg(dst.clone()); 179 | let device = args.value_of("device").or_else(|| cfg.filter_device()).unwrap_or_else(|| "bobbin"); 180 | cmd.arg(format!("{}:/tmp/{}/", host, device)); 181 | let status = cmd.status()?; 182 | if !status.success() { 183 | bail!("Unable to transfer file to {}", host); 184 | } 185 | let mut cmd = Command::new("ssh"); 186 | cmd.arg("-q"); 187 | cmd.arg("-t"); 188 | cmd.arg(host); 189 | cmd.arg(".cargo/bin/bobbin"); 190 | if let Some(device) = cfg.device(args) { 191 | cmd.arg("--device").arg(device); 192 | } 193 | if args.is_present("verbose") { 194 | cmd.arg("--verbose"); 195 | } 196 | let subcmd = if args.is_present("load") { 197 | "load" 198 | } else if args.is_present("run") { 199 | "run" 200 | } else if args.is_present("test") { 201 | "test" 202 | } else { 203 | bail!("Only load, run and test are supported for remote hosts") 204 | }; 205 | cmd.arg(subcmd); 206 | 207 | if let Some(arg) = cfg.jlink_device(cmd_args) { 208 | cmd.arg("--jlink-device").arg(arg); 209 | } 210 | 211 | if let Some(arg) = cfg.teensy_mcu(cmd_args) { 212 | cmd.arg("--teensy-mcu").arg(arg); 213 | } 214 | 215 | if let Some(arg) = cfg.blackmagic_mode(cmd_args) { 216 | cmd.arg("--blackmagic_mode").arg(arg); 217 | } 218 | 219 | if let Some(arg) = cfg.console(cmd_args) { 220 | cmd.arg("--console").arg(arg); 221 | } 222 | 223 | cmd.arg(format!("/tmp/{}/{}", device, dst.file_name().unwrap().to_str().unwrap())); 224 | out.verbose("Remote", &format!("{:?}", cmd))?; 225 | 226 | cmd.exec(); 227 | unreachable!() 228 | } 229 | 230 | let filter = device::filter(cfg, args, cmd_args); 231 | let mut devices = device::search(&filter)?; 232 | 233 | let device = if devices.len() == 0 { 234 | bail!("No matching devices found."); 235 | } else if devices.len() > 1 { 236 | bail!("More than one device found ({})", devices.len()); 237 | } else { 238 | devices.remove(0) 239 | }; 240 | 241 | let ldr = if let Some(ldr) = device.loader_type() { 242 | out.verbose("loader", ldr)?; 243 | if let Some(ldr) = loader::loader(ldr) { 244 | ldr 245 | } else { 246 | bail!("Unknown loader type: {}", ldr); 247 | } 248 | } else { 249 | bail!("Selected device has no associated loader"); 250 | }; 251 | 252 | let con = if !cmd_args.is_present("noconsole") && !cmd_args.is_present("itm") { 253 | if args.is_present("run") || args.is_present("test") { 254 | if let Some(cdc_path) = cfg.console(cmd_args) { 255 | let mut con = console::open(&cdc_path)?; 256 | con.clear()?; 257 | Some(con) 258 | } else if let Some(cdc_path) = device.cdc_path() { 259 | let mut con = console::open(&cdc_path)?; 260 | con.clear()?; 261 | Some(con) 262 | } else { 263 | None 264 | } 265 | } else { 266 | None 267 | } 268 | } else { 269 | None 270 | }; 271 | 272 | if dst == PathBuf::from("--") { 273 | let mut buffer: Vec = Vec::new(); 274 | io::stdin().read_to_end(&mut buffer)?; 275 | out.verbose("stdin", &format!("Read {} bytes from stdin", buffer.len()))?; 276 | let mut tmpfile = tempfile::NamedTempFile::new()?; 277 | tmpfile.write(buffer.as_ref())?; 278 | tmpfile.flush()?; 279 | ldr.load( 280 | cfg, 281 | args, 282 | cmd_args, 283 | out, 284 | device.as_ref(), 285 | tmpfile.path() 286 | )?; 287 | out.verbose("stdin", "Removing temporary file.")?; 288 | } else { 289 | ldr.load( 290 | cfg, 291 | args, 292 | cmd_args, 293 | out, 294 | device.as_ref(), 295 | dst.as_path(), 296 | )?; 297 | } 298 | out.info("Loader", "Load Complete")?; 299 | 300 | if cmd_args.is_present("itm") { 301 | if device.can_trace_itm() { 302 | out.info("ITM", "Starting ITM Trace")?; 303 | let target_clk = if let Some(v) = cmd_args.value_of("itm-target-clock") { 304 | v.parse::()? 305 | } else { 306 | if let Some(v) = cfg.itm_target_clock() { 307 | v 308 | } else { 309 | bail!("itm-target-clock is required for ITM trace.") 310 | } 311 | }; 312 | let trace_clk = 2_000_000; 313 | device.trace_itm(target_clk, trace_clk)?; 314 | 315 | } else { 316 | bail!("Currently selected device does not support ITM trace"); 317 | } 318 | } else if let Some(mut con) = con { 319 | out.info("Console", "Opening Console")?; 320 | if args.is_present("test") { 321 | con.test(&args, &cmd_args)?; 322 | } else { 323 | con.view()?; 324 | } 325 | } 326 | 327 | Ok(()) 328 | } 329 | 330 | pub fn control( 331 | cfg: &Config, 332 | args: &ArgMatches, 333 | cmd_args: &ArgMatches, 334 | out: &mut Printer, 335 | ) -> Result<()> { 336 | if let Some(host) = args.value_of("host").or_else(|| cfg.filter_host()) { 337 | let mut cmd = Command::new("ssh"); 338 | cmd.arg("-q"); 339 | cmd.arg("-t"); 340 | cmd.arg(host); 341 | cmd.arg(".cargo/bin/bobbin"); 342 | if let Some(device) = cfg.device(args) { 343 | cmd.arg("--device").arg(device); 344 | } 345 | if args.is_present("verbose") { 346 | cmd.arg("--verbose"); 347 | } 348 | let subcmd = if args.is_present("halt") { 349 | cmd.arg("halt"); 350 | } else if args.is_present("resume") { 351 | cmd.arg("resume"); 352 | } else if args.is_present("reset") { 353 | cmd.arg("reset"); 354 | if cmd_args.is_present("run") { 355 | cmd.arg("--run"); 356 | } else if cmd_args.is_present("halt") { 357 | cmd.arg("--halt"); 358 | } else if cmd_args.is_present("init") { 359 | cmd.arg("--init"); 360 | } 361 | }; 362 | 363 | if let Some(arg) = cfg.jlink_device(cmd_args) { 364 | cmd.arg("--jlink-device").arg(arg); 365 | } 366 | 367 | if let Some(arg) = cfg.teensy_mcu(cmd_args) { 368 | cmd.arg("--teensy-mcu").arg(arg); 369 | } 370 | 371 | if let Some(arg) = cfg.blackmagic_mode(cmd_args) { 372 | cmd.arg("--blackmagic_mode").arg(arg); 373 | } 374 | 375 | if let Some(arg) = cfg.console(cmd_args) { 376 | cmd.arg("--console").arg(arg); 377 | } 378 | out.verbose("Remote", &format!("{:?}", cmd))?; 379 | 380 | cmd.exec(); 381 | unreachable!() 382 | } 383 | 384 | let filter = device::filter(cfg, args, cmd_args); 385 | let mut devices = device::search(&filter)?; 386 | 387 | let device = if devices.len() == 0 { 388 | bail!("No matching devices found."); 389 | } else if devices.len() > 1 { 390 | bail!("More than one device found ({})", devices.len()); 391 | } else { 392 | devices.remove(0) 393 | }; 394 | 395 | let dbg = if let Some(dbg) = device.debugger_type() { 396 | out.verbose("debugger", dbg)?; 397 | if let Some(dbg) = debugger::debugger(dbg) { 398 | dbg 399 | } else { 400 | bail!("Unknown debugger type: {}", dbg); 401 | } 402 | } else { 403 | bail!("Selected device has no associated loader"); 404 | }; 405 | 406 | if let Some(_) = args.subcommand_matches("halt") { 407 | dbg.halt(cfg, args, cmd_args, out, device.as_ref())?; 408 | } else if let Some(_) = args.subcommand_matches("resume") { 409 | dbg.resume(cfg, args, cmd_args, out, device.as_ref())?; 410 | } else if let Some(_) = args.subcommand_matches("reset") { 411 | if cmd_args.is_present("run") { 412 | dbg.reset_run(cfg, args, cmd_args, out, device.as_ref())?; 413 | } else if cmd_args.is_present("halt") { 414 | dbg.reset_halt(cfg, args, cmd_args, out, device.as_ref())?; 415 | } else if cmd_args.is_present("init") { 416 | dbg.reset_init(cfg, args, cmd_args, out, device.as_ref())?; 417 | } else { 418 | dbg.reset(cfg, args, cmd_args, out, device.as_ref())?; 419 | } 420 | } 421 | 422 | Ok(()) 423 | } 424 | 425 | pub fn openocd( 426 | cfg: &Config, 427 | args: &ArgMatches, 428 | cmd_args: &ArgMatches, 429 | out: &mut Printer, 430 | ) -> Result<()> { 431 | if let Some(host) = args.value_of("host").or_else(|| cfg.filter_host()) { 432 | let mut cmd = Command::new("ssh"); 433 | cmd.arg("-q"); 434 | cmd.arg("-t"); 435 | cmd.arg("-L").arg("3333:localhost:3333"); 436 | cmd.arg(host); 437 | cmd.arg(".cargo/bin/bobbin"); 438 | if let Some(device) = cfg.device(args) { 439 | cmd.arg("--device").arg(device); 440 | } 441 | if args.is_present("verbose") { 442 | cmd.arg("--verbose"); 443 | } 444 | cmd.arg("openocd"); 445 | println!("{:?}", cmd); 446 | cmd.exec(); 447 | unreachable!() 448 | } 449 | 450 | let filter = device::filter(cfg, args, cmd_args); 451 | let mut devices = device::search(&filter)?; 452 | 453 | let device = if devices.len() == 0 { 454 | bail!("No matching devices found."); 455 | } else if devices.len() > 1 { 456 | bail!("More than one device found ({})", devices.len()); 457 | } else { 458 | devices.remove(0) 459 | }; 460 | 461 | let dbg = debugger::OpenOcdDebugger {}; 462 | dbg.run(cfg, args, cmd_args, out, device.as_ref())?; 463 | unreachable!() 464 | } 465 | 466 | 467 | pub fn jlink( 468 | cfg: &Config, 469 | args: &ArgMatches, 470 | cmd_args: &ArgMatches, 471 | out: &mut Printer, 472 | ) -> Result<()> { 473 | if let Some(host) = args.value_of("host").or_else(|| cfg.filter_host()) { 474 | let mut cmd = Command::new("ssh"); 475 | cmd.arg("-q"); 476 | cmd.arg("-t"); 477 | cmd.arg("-L").arg("3333:localhost:3333"); 478 | cmd.arg(host); 479 | cmd.arg(".cargo/bin/bobbin"); 480 | if let Some(device) = cfg.device(args) { 481 | cmd.arg("--device").arg(device); 482 | } 483 | if args.is_present("verbose") { 484 | cmd.arg("--verbose"); 485 | } 486 | cmd.arg("jlink"); 487 | if let Some(arg) = cfg.jlink_device(cmd_args) { 488 | cmd.arg("--jlink-device").arg(arg); 489 | } 490 | cmd.exec(); 491 | unreachable!() 492 | } 493 | 494 | let filter = device::filter(cfg, args, cmd_args); 495 | let mut devices = device::search(&filter)?; 496 | 497 | let device = if devices.len() == 0 { 498 | bail!("No matching devices found."); 499 | } else if devices.len() > 1 { 500 | bail!("More than one device found ({})", devices.len()); 501 | } else { 502 | devices.remove(0) 503 | }; 504 | 505 | let jlink_dev = if let Some(jlink_dev) = cfg.jlink_device(cmd_args) { 506 | jlink_dev 507 | } else { 508 | bail!("JLink Loader requires that --jlink-device is specified"); 509 | }; 510 | 511 | let mut cmd = Command::new("JLinkGDBServer"); 512 | cmd.arg("-device").arg(jlink_dev); 513 | cmd.arg("-if").arg("SWD"); 514 | cmd.arg("-speed").arg("4000"); 515 | cmd.arg("-port").arg("3333"); 516 | cmd.arg("-select").arg( 517 | format!("usb={}",device.usb().serial_number), 518 | ); 519 | 520 | cmd.exec(); 521 | 522 | let status = cmd.status()?; 523 | if !status.success() { 524 | bail!("jlink failed") 525 | } 526 | Ok(()) 527 | } 528 | 529 | 530 | pub fn gdb( 531 | cfg: &Config, 532 | args: &ArgMatches, 533 | cmd_args: &ArgMatches, 534 | out: &mut Printer, 535 | ) -> Result<()> { 536 | let dst = if let Some(dst) = builder::build(cfg, args, cmd_args, out)? { 537 | dst 538 | } else { 539 | bail!("No build output available for gdb"); 540 | }; 541 | 542 | if let Some(host) = args.value_of("host").or_else(|| cfg.filter_host()) { 543 | let mut cmd = Command::new("arm-none-eabi-gdb"); 544 | cmd.arg("-ex").arg(format!("target extended-remote :3333")); 545 | cmd.arg(dst); 546 | cmd.exec(); 547 | unreachable!() 548 | } 549 | 550 | let filter = device::filter(cfg, args, cmd_args); 551 | let mut devices = device::search(&filter)?; 552 | 553 | let device = if devices.len() == 0 { 554 | bail!("No matching devices found."); 555 | } else if devices.len() > 1 { 556 | bail!("More than one device found ({})", devices.len()); 557 | } else { 558 | devices.remove(0) 559 | }; 560 | 561 | let mut cmd = Command::new("arm-none-eabi-gdb"); 562 | if let Some(gdb_path) = device.gdb_path() { 563 | cmd.arg("-ex").arg(format!("target extended-remote {}", gdb_path)); 564 | // These commands are BlackMagic Probe Specific 565 | cmd.arg("-ex").arg("monitor swdp_scan"); 566 | cmd.arg("-ex").arg("attach 1"); 567 | } 568 | cmd.stdout(Stdio::inherit()).stderr(Stdio::inherit()).arg( 569 | dst, 570 | ); 571 | out.verbose("gdb", &format!("{:?}", cmd))?; 572 | 573 | cmd.exec(); 574 | 575 | let status = cmd.status()?; 576 | if !status.success() { 577 | bail!("gdb failed") 578 | } 579 | Ok(()) 580 | } 581 | 582 | pub fn console( 583 | cfg: &Config, 584 | args: &ArgMatches, 585 | cmd_args: &ArgMatches, 586 | out: &mut Printer, 587 | ) -> Result<()> { 588 | if let Some(host) = args.value_of("host").or_else(|| cfg.filter_host()) { 589 | let mut cmd = Command::new("ssh"); 590 | cmd.arg("-q"); 591 | cmd.arg("-t"); 592 | cmd.arg(host); 593 | cmd.arg(".cargo/bin/bobbin"); 594 | if let Some(device) = cfg.device(args) { 595 | cmd.arg("--device").arg(device); 596 | } 597 | if args.is_present("verbose") { 598 | cmd.arg("--verbose"); 599 | } 600 | cmd.arg("console"); 601 | if let Some(arg) = cfg.console(cmd_args) { 602 | cmd.arg("--console").arg(arg); 603 | } 604 | cmd.exec(); 605 | unreachable!() 606 | } 607 | 608 | let filter = device::filter(cfg, args, cmd_args); 609 | let mut devices = device::search(&filter)?; 610 | 611 | let device = if devices.len() == 0 { 612 | bail!("No matching devices found."); 613 | } else if devices.len() > 1 { 614 | bail!("More than one device found ({})", devices.len()); 615 | } else { 616 | devices.remove(0) 617 | }; 618 | 619 | if let Some(cdc_path) = cfg.console(cmd_args) { 620 | let mut con = console::open(&cdc_path)?; 621 | con.view()? 622 | } else if let Some(cdc_path) = device.cdc_path() { 623 | let mut con = console::open(&cdc_path)?; 624 | con.view()? 625 | } else { 626 | bail!("No console found for device"); 627 | } 628 | 629 | Ok(()) 630 | } 631 | 632 | pub fn screen( 633 | cfg: &Config, 634 | args: &ArgMatches, 635 | cmd_args: &ArgMatches, 636 | out: &mut Printer, 637 | ) -> Result<()> { 638 | if let Some(host) = args.value_of("host").or_else(|| cfg.filter_host()) { 639 | let mut cmd = Command::new("ssh"); 640 | cmd.arg("-q"); 641 | cmd.arg("-t"); 642 | cmd.arg(host); 643 | cmd.arg(".cargo/bin/bobbin"); 644 | if let Some(device) = cfg.device(args) { 645 | cmd.arg("--device").arg(device); 646 | } 647 | if args.is_present("verbose") { 648 | cmd.arg("--verbose"); 649 | } 650 | cmd.arg("screen"); 651 | if let Some(arg) = cfg.console(cmd_args) { 652 | cmd.arg("--console").arg(arg); 653 | } 654 | cmd.exec(); 655 | unreachable!() 656 | } 657 | 658 | let filter = device::filter(cfg, args, cmd_args); 659 | let mut devices = device::search(&filter)?; 660 | 661 | let device = if devices.len() == 0 { 662 | bail!("No matching devices found."); 663 | } else if devices.len() > 1 { 664 | bail!("More than one device found ({})", devices.len()); 665 | } else { 666 | devices.remove(0) 667 | }; 668 | 669 | let mut cmd = Command::new("screen"); 670 | if let Some(cdc_path) = cfg.console(cmd_args) { 671 | cmd.arg(cdc_path); 672 | } else if let Some(cdc_path) = device.cdc_path() { 673 | cmd.arg(cdc_path); 674 | } else { 675 | bail!("No serial device path found"); 676 | } 677 | cmd.arg("115200"); 678 | cmd.exec(); 679 | 680 | let status = cmd.status()?; 681 | if !status.success() { 682 | bail!("screen failed") 683 | } 684 | Ok(()) 685 | } 686 | 687 | pub fn objdump( 688 | cfg: &Config, 689 | args: &ArgMatches, 690 | cmd_args: &ArgMatches, 691 | out: &mut Printer, 692 | ) -> Result<()> { 693 | Ok(()) 694 | } 695 | 696 | pub fn itm( 697 | cfg: &Config, 698 | args: &ArgMatches, 699 | cmd_args: &ArgMatches, 700 | out: &mut Printer, 701 | ) -> Result<()> { 702 | if let Some(host) = args.value_of("host").or_else(|| cfg.filter_host()) { 703 | let mut cmd = Command::new("ssh"); 704 | cmd.arg("-q"); 705 | cmd.arg("-t"); 706 | cmd.arg(host); 707 | cmd.arg(".cargo/bin/bobbin"); 708 | if let Some(device) = cfg.device(args) { 709 | cmd.arg("--device").arg(device); 710 | } 711 | if args.is_present("verbose") { 712 | cmd.arg("--verbose"); 713 | } 714 | cmd.arg("itm"); 715 | cmd.exec(); 716 | unreachable!() 717 | } 718 | 719 | let filter = device::filter(cfg, args, cmd_args); 720 | let mut devices = device::search(&filter)?; 721 | 722 | let device = if devices.len() == 0 { 723 | bail!("No matching devices found."); 724 | } else if devices.len() > 1 { 725 | bail!("More than one device found ({})", devices.len()); 726 | } else { 727 | devices.remove(0) 728 | }; 729 | 730 | if device.can_trace_itm() { 731 | out.info("ITM", "Starting ITM Trace")?; 732 | let target_clk = if let Some(v) = cmd_args.value_of("itm-target-clock") { 733 | v.parse::()? 734 | } else { 735 | if let Some(v) = cfg.itm_target_clock() { 736 | v 737 | } else { 738 | bail!("itm-target-clock is required for ITM trace.") 739 | } 740 | }; 741 | let trace_clk = 2_000_000; 742 | device.trace_itm(target_clk, trace_clk)?; 743 | } else { 744 | bail!("Currently selected device does not support ITM trace"); 745 | } 746 | Ok(()) 747 | } 748 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "aho-corasick" 5 | version = "0.6.9" 6 | source = "registry+https://github.com/rust-lang/crates.io-index" 7 | dependencies = [ 8 | "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 9 | ] 10 | 11 | [[package]] 12 | name = "ansi_term" 13 | version = "0.9.0" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | 16 | [[package]] 17 | name = "atty" 18 | version = "0.2.2" 19 | source = "registry+https://github.com/rust-lang/crates.io-index" 20 | dependencies = [ 21 | "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 22 | "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)", 23 | "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 24 | ] 25 | 26 | [[package]] 27 | name = "backtrace" 28 | version = "0.3.0" 29 | source = "registry+https://github.com/rust-lang/crates.io-index" 30 | dependencies = [ 31 | "backtrace-sys 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", 32 | "cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 33 | "dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 34 | "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 35 | "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)", 36 | "rustc-demangle 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", 37 | "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 38 | ] 39 | 40 | [[package]] 41 | name = "backtrace-sys" 42 | version = "0.1.10" 43 | source = "registry+https://github.com/rust-lang/crates.io-index" 44 | dependencies = [ 45 | "gcc 0.3.45 (registry+https://github.com/rust-lang/crates.io-index)", 46 | "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)", 47 | ] 48 | 49 | [[package]] 50 | name = "bit-set" 51 | version = "0.2.0" 52 | source = "registry+https://github.com/rust-lang/crates.io-index" 53 | dependencies = [ 54 | "bit-vec 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", 55 | ] 56 | 57 | [[package]] 58 | name = "bit-vec" 59 | version = "0.4.4" 60 | source = "registry+https://github.com/rust-lang/crates.io-index" 61 | 62 | [[package]] 63 | name = "bitflags" 64 | version = "0.7.0" 65 | source = "registry+https://github.com/rust-lang/crates.io-index" 66 | 67 | [[package]] 68 | name = "bitflags" 69 | version = "0.8.2" 70 | source = "registry+https://github.com/rust-lang/crates.io-index" 71 | 72 | [[package]] 73 | name = "bobbin-cli" 74 | version = "0.8.8" 75 | dependencies = [ 76 | "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", 77 | "clap 2.24.1 (registry+https://github.com/rust-lang/crates.io-index)", 78 | "error-chain 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", 79 | "libusb 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 80 | "os_type 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 81 | "plist 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", 82 | "regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 83 | "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", 84 | "serde 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", 85 | "serde_derive 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", 86 | "serial 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", 87 | "sha1 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 88 | "tempfile 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 89 | "termcolor 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", 90 | "toml 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", 91 | ] 92 | 93 | [[package]] 94 | name = "byteorder" 95 | version = "0.5.3" 96 | source = "registry+https://github.com/rust-lang/crates.io-index" 97 | 98 | [[package]] 99 | name = "byteorder" 100 | version = "1.0.0" 101 | source = "registry+https://github.com/rust-lang/crates.io-index" 102 | 103 | [[package]] 104 | name = "cfg-if" 105 | version = "0.1.0" 106 | source = "registry+https://github.com/rust-lang/crates.io-index" 107 | 108 | [[package]] 109 | name = "chrono" 110 | version = "0.2.25" 111 | source = "registry+https://github.com/rust-lang/crates.io-index" 112 | dependencies = [ 113 | "num 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", 114 | "time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", 115 | ] 116 | 117 | [[package]] 118 | name = "clap" 119 | version = "2.24.1" 120 | source = "registry+https://github.com/rust-lang/crates.io-index" 121 | dependencies = [ 122 | "ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", 123 | "atty 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 124 | "bitflags 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", 125 | "strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 126 | "term_size 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 127 | "unicode-segmentation 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 128 | "unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", 129 | "vec_map 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 130 | ] 131 | 132 | [[package]] 133 | name = "dbghelp-sys" 134 | version = "0.2.0" 135 | source = "registry+https://github.com/rust-lang/crates.io-index" 136 | dependencies = [ 137 | "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 138 | "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 139 | ] 140 | 141 | [[package]] 142 | name = "error-chain" 143 | version = "0.10.0" 144 | source = "registry+https://github.com/rust-lang/crates.io-index" 145 | dependencies = [ 146 | "backtrace 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 147 | ] 148 | 149 | [[package]] 150 | name = "gcc" 151 | version = "0.3.45" 152 | source = "registry+https://github.com/rust-lang/crates.io-index" 153 | 154 | [[package]] 155 | name = "ioctl-rs" 156 | version = "0.1.5" 157 | source = "registry+https://github.com/rust-lang/crates.io-index" 158 | dependencies = [ 159 | "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)", 160 | ] 161 | 162 | [[package]] 163 | name = "kernel32-sys" 164 | version = "0.2.2" 165 | source = "registry+https://github.com/rust-lang/crates.io-index" 166 | dependencies = [ 167 | "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 168 | "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 169 | ] 170 | 171 | [[package]] 172 | name = "lazy_static" 173 | version = "1.2.0" 174 | source = "registry+https://github.com/rust-lang/crates.io-index" 175 | 176 | [[package]] 177 | name = "libc" 178 | version = "0.2.22" 179 | source = "registry+https://github.com/rust-lang/crates.io-index" 180 | 181 | [[package]] 182 | name = "libusb" 183 | version = "0.3.0" 184 | source = "registry+https://github.com/rust-lang/crates.io-index" 185 | dependencies = [ 186 | "bit-set 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 187 | "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)", 188 | "libusb-sys 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", 189 | ] 190 | 191 | [[package]] 192 | name = "libusb-sys" 193 | version = "0.2.3" 194 | source = "registry+https://github.com/rust-lang/crates.io-index" 195 | dependencies = [ 196 | "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)", 197 | "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", 198 | ] 199 | 200 | [[package]] 201 | name = "memchr" 202 | version = "1.0.1" 203 | source = "registry+https://github.com/rust-lang/crates.io-index" 204 | dependencies = [ 205 | "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)", 206 | ] 207 | 208 | [[package]] 209 | name = "memchr" 210 | version = "2.2.0" 211 | source = "registry+https://github.com/rust-lang/crates.io-index" 212 | 213 | [[package]] 214 | name = "num" 215 | version = "0.1.37" 216 | source = "registry+https://github.com/rust-lang/crates.io-index" 217 | dependencies = [ 218 | "num-integer 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", 219 | "num-iter 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)", 220 | "num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", 221 | ] 222 | 223 | [[package]] 224 | name = "num-integer" 225 | version = "0.1.34" 226 | source = "registry+https://github.com/rust-lang/crates.io-index" 227 | dependencies = [ 228 | "num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", 229 | ] 230 | 231 | [[package]] 232 | name = "num-iter" 233 | version = "0.1.33" 234 | source = "registry+https://github.com/rust-lang/crates.io-index" 235 | dependencies = [ 236 | "num-integer 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", 237 | "num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", 238 | ] 239 | 240 | [[package]] 241 | name = "num-traits" 242 | version = "0.1.37" 243 | source = "registry+https://github.com/rust-lang/crates.io-index" 244 | 245 | [[package]] 246 | name = "os_type" 247 | version = "2.2.0" 248 | source = "registry+https://github.com/rust-lang/crates.io-index" 249 | dependencies = [ 250 | "regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 251 | ] 252 | 253 | [[package]] 254 | name = "pkg-config" 255 | version = "0.3.9" 256 | source = "registry+https://github.com/rust-lang/crates.io-index" 257 | 258 | [[package]] 259 | name = "plist" 260 | version = "0.1.3" 261 | source = "registry+https://github.com/rust-lang/crates.io-index" 262 | dependencies = [ 263 | "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", 264 | "chrono 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)", 265 | "rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)", 266 | "serde 0.9.15 (registry+https://github.com/rust-lang/crates.io-index)", 267 | "xml-rs 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", 268 | ] 269 | 270 | [[package]] 271 | name = "quote" 272 | version = "0.3.15" 273 | source = "registry+https://github.com/rust-lang/crates.io-index" 274 | 275 | [[package]] 276 | name = "rand" 277 | version = "0.3.15" 278 | source = "registry+https://github.com/rust-lang/crates.io-index" 279 | dependencies = [ 280 | "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)", 281 | ] 282 | 283 | [[package]] 284 | name = "redox_syscall" 285 | version = "0.1.17" 286 | source = "registry+https://github.com/rust-lang/crates.io-index" 287 | 288 | [[package]] 289 | name = "regex" 290 | version = "0.2.2" 291 | source = "registry+https://github.com/rust-lang/crates.io-index" 292 | dependencies = [ 293 | "aho-corasick 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", 294 | "memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 295 | "regex-syntax 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", 296 | "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", 297 | "utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", 298 | ] 299 | 300 | [[package]] 301 | name = "regex" 302 | version = "1.1.0" 303 | source = "registry+https://github.com/rust-lang/crates.io-index" 304 | dependencies = [ 305 | "aho-corasick 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", 306 | "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 307 | "regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", 308 | "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", 309 | "utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", 310 | ] 311 | 312 | [[package]] 313 | name = "regex-syntax" 314 | version = "0.4.1" 315 | source = "registry+https://github.com/rust-lang/crates.io-index" 316 | 317 | [[package]] 318 | name = "regex-syntax" 319 | version = "0.6.5" 320 | source = "registry+https://github.com/rust-lang/crates.io-index" 321 | dependencies = [ 322 | "ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", 323 | ] 324 | 325 | [[package]] 326 | name = "rustc-demangle" 327 | version = "0.1.4" 328 | source = "registry+https://github.com/rust-lang/crates.io-index" 329 | 330 | [[package]] 331 | name = "rustc-serialize" 332 | version = "0.3.24" 333 | source = "registry+https://github.com/rust-lang/crates.io-index" 334 | 335 | [[package]] 336 | name = "rustc_version" 337 | version = "0.1.7" 338 | source = "registry+https://github.com/rust-lang/crates.io-index" 339 | dependencies = [ 340 | "semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)", 341 | ] 342 | 343 | [[package]] 344 | name = "semver" 345 | version = "0.1.20" 346 | source = "registry+https://github.com/rust-lang/crates.io-index" 347 | 348 | [[package]] 349 | name = "semver" 350 | version = "0.9.0" 351 | source = "registry+https://github.com/rust-lang/crates.io-index" 352 | dependencies = [ 353 | "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 354 | ] 355 | 356 | [[package]] 357 | name = "semver-parser" 358 | version = "0.7.0" 359 | source = "registry+https://github.com/rust-lang/crates.io-index" 360 | 361 | [[package]] 362 | name = "serde" 363 | version = "0.9.15" 364 | source = "registry+https://github.com/rust-lang/crates.io-index" 365 | 366 | [[package]] 367 | name = "serde" 368 | version = "1.0.11" 369 | source = "registry+https://github.com/rust-lang/crates.io-index" 370 | 371 | [[package]] 372 | name = "serde_derive" 373 | version = "1.0.11" 374 | source = "registry+https://github.com/rust-lang/crates.io-index" 375 | dependencies = [ 376 | "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", 377 | "serde_derive_internals 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)", 378 | "syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)", 379 | ] 380 | 381 | [[package]] 382 | name = "serde_derive_internals" 383 | version = "0.15.1" 384 | source = "registry+https://github.com/rust-lang/crates.io-index" 385 | dependencies = [ 386 | "syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)", 387 | "synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", 388 | ] 389 | 390 | [[package]] 391 | name = "serial" 392 | version = "0.3.4" 393 | source = "registry+https://github.com/rust-lang/crates.io-index" 394 | dependencies = [ 395 | "ioctl-rs 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 396 | "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)", 397 | "termios 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 398 | ] 399 | 400 | [[package]] 401 | name = "sha1" 402 | version = "0.2.0" 403 | source = "registry+https://github.com/rust-lang/crates.io-index" 404 | 405 | [[package]] 406 | name = "strsim" 407 | version = "0.6.0" 408 | source = "registry+https://github.com/rust-lang/crates.io-index" 409 | 410 | [[package]] 411 | name = "syn" 412 | version = "0.11.11" 413 | source = "registry+https://github.com/rust-lang/crates.io-index" 414 | dependencies = [ 415 | "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", 416 | "synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", 417 | "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", 418 | ] 419 | 420 | [[package]] 421 | name = "synom" 422 | version = "0.11.3" 423 | source = "registry+https://github.com/rust-lang/crates.io-index" 424 | dependencies = [ 425 | "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", 426 | ] 427 | 428 | [[package]] 429 | name = "tempfile" 430 | version = "2.1.5" 431 | source = "registry+https://github.com/rust-lang/crates.io-index" 432 | dependencies = [ 433 | "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 434 | "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)", 435 | "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", 436 | "rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", 437 | "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 438 | ] 439 | 440 | [[package]] 441 | name = "term_size" 442 | version = "0.3.0" 443 | source = "registry+https://github.com/rust-lang/crates.io-index" 444 | dependencies = [ 445 | "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 446 | "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)", 447 | "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 448 | ] 449 | 450 | [[package]] 451 | name = "termcolor" 452 | version = "0.3.2" 453 | source = "registry+https://github.com/rust-lang/crates.io-index" 454 | dependencies = [ 455 | "wincolor 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", 456 | ] 457 | 458 | [[package]] 459 | name = "termios" 460 | version = "0.2.2" 461 | source = "registry+https://github.com/rust-lang/crates.io-index" 462 | dependencies = [ 463 | "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)", 464 | ] 465 | 466 | [[package]] 467 | name = "thread_local" 468 | version = "0.3.6" 469 | source = "registry+https://github.com/rust-lang/crates.io-index" 470 | dependencies = [ 471 | "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 472 | ] 473 | 474 | [[package]] 475 | name = "time" 476 | version = "0.1.37" 477 | source = "registry+https://github.com/rust-lang/crates.io-index" 478 | dependencies = [ 479 | "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 480 | "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)", 481 | "redox_syscall 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", 482 | "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 483 | ] 484 | 485 | [[package]] 486 | name = "toml" 487 | version = "0.4.5" 488 | source = "registry+https://github.com/rust-lang/crates.io-index" 489 | dependencies = [ 490 | "serde 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", 491 | ] 492 | 493 | [[package]] 494 | name = "ucd-util" 495 | version = "0.1.3" 496 | source = "registry+https://github.com/rust-lang/crates.io-index" 497 | 498 | [[package]] 499 | name = "unicode-segmentation" 500 | version = "1.1.0" 501 | source = "registry+https://github.com/rust-lang/crates.io-index" 502 | 503 | [[package]] 504 | name = "unicode-width" 505 | version = "0.1.4" 506 | source = "registry+https://github.com/rust-lang/crates.io-index" 507 | 508 | [[package]] 509 | name = "unicode-xid" 510 | version = "0.0.4" 511 | source = "registry+https://github.com/rust-lang/crates.io-index" 512 | 513 | [[package]] 514 | name = "utf8-ranges" 515 | version = "1.0.2" 516 | source = "registry+https://github.com/rust-lang/crates.io-index" 517 | 518 | [[package]] 519 | name = "vec_map" 520 | version = "0.7.0" 521 | source = "registry+https://github.com/rust-lang/crates.io-index" 522 | 523 | [[package]] 524 | name = "winapi" 525 | version = "0.2.8" 526 | source = "registry+https://github.com/rust-lang/crates.io-index" 527 | 528 | [[package]] 529 | name = "winapi-build" 530 | version = "0.1.1" 531 | source = "registry+https://github.com/rust-lang/crates.io-index" 532 | 533 | [[package]] 534 | name = "wincolor" 535 | version = "0.1.3" 536 | source = "registry+https://github.com/rust-lang/crates.io-index" 537 | dependencies = [ 538 | "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 539 | "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 540 | ] 541 | 542 | [[package]] 543 | name = "xml-rs" 544 | version = "0.3.6" 545 | source = "registry+https://github.com/rust-lang/crates.io-index" 546 | dependencies = [ 547 | "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 548 | ] 549 | 550 | [metadata] 551 | "checksum aho-corasick 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "1e9a933f4e58658d7b12defcf96dc5c720f20832deebe3e0a19efd3b6aaeeb9e" 552 | "checksum ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "23ac7c30002a5accbf7e8987d0632fa6de155b7c3d39d0067317a391e00a2ef6" 553 | "checksum atty 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d912da0db7fa85514874458ca3651fe2cddace8d0b0505571dbdcd41ab490159" 554 | "checksum backtrace 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f551bc2ddd53aea015d453ef0b635af89444afa5ed2405dd0b2062ad5d600d80" 555 | "checksum backtrace-sys 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "d192fd129132fbc97497c1f2ec2c2c5174e376b95f535199ef4fe0a293d33842" 556 | "checksum bit-set 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e6e1e6fb1c9e3d6fcdec57216a74eaa03e41f52a22f13a16438251d8e88b89da" 557 | "checksum bit-vec 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "02b4ff8b16e6076c3e14220b39fbc1fabb6737522281a388998046859400895f" 558 | "checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" 559 | "checksum bitflags 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1370e9fc2a6ae53aea8b7a5110edbd08836ed87c88736dfabccade1c2b44bff4" 560 | "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" 561 | "checksum byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c40977b0ee6b9885c9013cd41d9feffdd22deb3bb4dc3a71d901cc7a77de18c8" 562 | "checksum cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de1e760d7b6535af4241fca8bd8adf68e2e7edacc6b29f5d399050c5e48cf88c" 563 | "checksum chrono 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)" = "9213f7cd7c27e95c2b57c49f0e69b1ea65b27138da84a170133fd21b07659c00" 564 | "checksum clap 2.24.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b7541069be0b8aec41030802abe8b5cdef0490070afaa55418adea93b1e431e0" 565 | "checksum dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97590ba53bcb8ac28279161ca943a924d1fd4a8fb3fa63302591647c4fc5b850" 566 | "checksum error-chain 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d9435d864e017c3c6afeac1654189b06cdb491cf2ff73dbf0d73b0f292f42ff8" 567 | "checksum gcc 0.3.45 (registry+https://github.com/rust-lang/crates.io-index)" = "40899336fb50db0c78710f53e87afc54d8c7266fb76262fecc78ca1a7f09deae" 568 | "checksum ioctl-rs 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c733bd6be680c4365bfeb89ac48d4c39ee2c47d933da3601689131471aaf3267" 569 | "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" 570 | "checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1" 571 | "checksum libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)" = "babb8281da88cba992fa1f4ddec7d63ed96280a1a53ec9b919fd37b53d71e502" 572 | "checksum libusb 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5f990ddd929cbe53de4ecd6cf26e1f4e0c5b9796e4c629d9046570b03738aa53" 573 | "checksum libusb-sys 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4c53b6582563d64ad3e692f54ef95239c3ea8069e82c9eb70ca948869a7ad767" 574 | "checksum memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1dbccc0e46f1ea47b9f17e6d67c5a96bd27030519c519c9c91327e31275a47b4" 575 | "checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39" 576 | "checksum num 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "98b15ba84e910ea7a1973bccd3df7b31ae282bf9d8bd2897779950c9b8303d40" 577 | "checksum num-integer 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)" = "ef1a4bf6f9174aa5783a9b4cc892cacd11aebad6c69ad027a0b65c6ca5f8aa37" 578 | "checksum num-iter 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)" = "f7d1891bd7b936f12349b7d1403761c8a0b85a18b148e9da4429d5d102c1a41e" 579 | "checksum num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "e1cbfa3781f3fe73dc05321bed52a06d2d491eaa764c52335cf4399f046ece99" 580 | "checksum os_type 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7edc011af0ae98b7f88cf7e4a83b70a54a75d2b8cb013d6efd02e5956207e9eb" 581 | "checksum pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3a8b4c6b8165cd1a1cd4b9b120978131389f64bdaf456435caa41e630edba903" 582 | "checksum plist 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0f6c4f04356eb9ad7fb1d004eb19369324daa46db1fc7ee89246a2fc224a9ce9" 583 | "checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" 584 | "checksum rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "022e0636ec2519ddae48154b028864bdce4eaf7d35226ab8e65c611be97b189d" 585 | "checksum redox_syscall 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)" = "29dbdfd4b9df8ab31dec47c6087b7b13cbf4a776f335e4de8efba8288dda075b" 586 | "checksum regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1731164734096285ec2a5ec7fea5248ae2f5485b3feeb0115af4fda2183b2d1b" 587 | "checksum regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "37e7cbbd370869ce2e8dff25c7018702d10b21a20ef7135316f8daecd6c25b7f" 588 | "checksum regex-syntax 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad890a5eef7953f55427c50575c680c42841653abd2b028b68cd223d157f62db" 589 | "checksum regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8c2f35eedad5295fdf00a63d7d4b238135723f92b434ec06774dad15c7ab0861" 590 | "checksum rustc-demangle 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3058a43ada2c2d0b92b3ae38007a2d0fa5e9db971be260e0171408a4ff471c95" 591 | "checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" 592 | "checksum rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c5f5376ea5e30ce23c03eb77cbe4962b988deead10910c372b226388b594c084" 593 | "checksum semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "d4f410fedcf71af0345d7607d246e7ad15faaadd49d240ee3b24e5dc21a820ac" 594 | "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" 595 | "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" 596 | "checksum serde 0.9.15 (registry+https://github.com/rust-lang/crates.io-index)" = "34b623917345a631dc9608d5194cc206b3fe6c3554cd1c75b937e55e285254af" 597 | "checksum serde 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)" = "f7726f29ddf9731b17ff113c461e362c381d9d69433f79de4f3dd572488823e9" 598 | "checksum serde_derive 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cf823e706be268e73e7747b147aa31c8f633ab4ba31f115efb57e5047c3a76dd" 599 | "checksum serde_derive_internals 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)" = "37aee4e0da52d801acfbc0cc219eb1eda7142112339726e427926a6f6ee65d3a" 600 | "checksum serial 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "cb5e265c52312c3e72a08afb6ac62ba3b9d1778c2193f57d74e307334689c7c8" 601 | "checksum sha1 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cc30b1e1e8c40c121ca33b86c23308a090d19974ef001b4bf6e61fd1a0fb095c" 602 | "checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694" 603 | "checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" 604 | "checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" 605 | "checksum tempfile 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3213fd2b7ed87e39306737ccfac04b1233b57a33ca64cfbf52f2ffaa2b765e2f" 606 | "checksum term_size 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2b6b55df3198cc93372e85dd2ed817f0e38ce8cc0f22eb32391bfad9c4bf209" 607 | "checksum termcolor 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9a5193a56b8d82014662c4b933dea6bec851daf018a2b01722e007daaf5f9dca" 608 | "checksum termios 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d5d9cf598a6d7ce700a4e6a9199da127e6819a61e64b68609683cc9a01b5683a" 609 | "checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" 610 | "checksum time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "ffd7ccbf969a892bf83f1e441126968a07a3941c24ff522a26af9f9f4585d1a3" 611 | "checksum toml 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a7540f4ffc193e0d3c94121edb19b055670d369f77d5804db11ae053a45b6e7e" 612 | "checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86" 613 | "checksum unicode-segmentation 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18127285758f0e2c6cf325bb3f3d138a12fee27de4f23e146cd6a179f26c2cf3" 614 | "checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f" 615 | "checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" 616 | "checksum utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737" 617 | "checksum vec_map 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8cdc8b93bd0198ed872357fb2e667f7125646b1762f16d60b2c96350d361897" 618 | "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" 619 | "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" 620 | "checksum wincolor 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "99c2af1426e2166e6f66d88b09b2a4d63afce06875f149174e386f2f1ee9779b" 621 | "checksum xml-rs 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7ec6c39eaa68382c8e31e35239402c0a9489d4141a8ceb0c716099a0b515b562" 622 | --------------------------------------------------------------------------------