diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml new file mode 100644 index 00000000..f80f02f7 --- /dev/null +++ b/.github/workflows/audit.yml @@ -0,0 +1,69 @@ +name: "Audit Dependencies" +on: + push: + paths: + # Run if workflow changes + - '.github/workflows/audit.yml' + # Run on changed dependencies + - '**/Cargo.toml' + - '**/Cargo.lock' + # Run if the configuration file changes + - '**/audit.toml' + # Rerun periodicly to pick up new advisories + schedule: + - cron: '0 0 * * *' + # Run manually + workflow_dispatch: + +permissions: read-all + +jobs: + audit: + runs-on: ubuntu-latest + permissions: + issues: write + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - uses: dtolnay/rust-toolchain@nightly + - uses: actions-rust-lang/audit@v1 + name: Audit Rust Dependencies + with: + ignore: RUSTSEC-2020-0071,RUSTSEC-2021-0139 + + deny: + runs-on: ubuntu-latest + permissions: + issues: write + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - uses: dtolnay/rust-toolchain@nightly + - name: cargo-binstall + run: | + mkdir -p ~/.cargo/bin + wget https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-x86_64-unknown-linux-musl.tgz + tar xf cargo-binstall*.tgz -C ~/.cargo/bin + - run: cargo binstall --no-confirm cargo-deny + - name: Cargo Deny + run: cargo deny check licenses + + pants: + runs-on: ubuntu-latest + permissions: + issues: write + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - uses: dtolnay/rust-toolchain@nightly + - name: cargo-binstall + run: | + mkdir -p ~/.cargo/bin + wget https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-x86_64-unknown-linux-musl.tgz + tar xf cargo-binstall*.tgz -C ~/.cargo/bin + - run: cargo binstall --no-confirm cargo-pants + - name: Cargo Pants + run: cargo pants diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 83bc7d23..5cdf1bee 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,9 +1,14 @@ -name: Build Environment +name: Legacy Makefile Build Environment on: [push, pull_request] env: PIPENV_ACTIVE: 1 + deb_packages: >- + libreadline-dev + libwxgtk3.0-gtk3-dev + wx-common + wx3.0-headers jobs: linux: @@ -11,17 +16,19 @@ jobs: strategy: fail-fast: false steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + - name: Fetch tags + run: git fetch --prune --unshallow --tags - name: Install dependencies run: | sudo apt-get update - sudo apt-get install libwxgtk3.0-dev libreadline-dev -y + sudo apt-get install -y ${{ env.deb_packages }} - name: Build run: | make -j make install bin/bossac --help - - uses: actions/upload-artifact@v1 + - uses: actions/upload-artifact@v3 if: always() with: name: linux @@ -32,7 +39,9 @@ jobs: strategy: fail-fast: false steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + - name: Fetch tags + run: git fetch --prune --unshallow --tags - name: Install dependencies run: | brew update @@ -42,29 +51,49 @@ jobs: make -j make install bin/bossac --help - - uses: actions/upload-artifact@v1 + - uses: actions/upload-artifact@v3 if: always() with: name: macos path: bin + # TODO: Not working currently! windows: runs-on: windows-latest strategy: fail-fast: false + matrix: + include: + - { sys: mingw32, env: i686 } steps: - - uses: actions/checkout@v2 - - uses: numworks/setup-msys2@v1 + - uses: actions/checkout@v4 + - name: Fetch tags + run: git fetch --prune --unshallow --tags + - uses: msys2/setup-msys2@v2 with: - msystem: MSYS32 - - run: msys2do pacman --noconfirm -S -noconfirm --noprogressbar - - run: msys2do pacman --noconfirm -U mingw-w64-*-any.pkg.tar.xz - - run: | + msystem: ${{matrix.sys}} + install: >- + base-devel + git + pacboy: >- + make + binutils + gcc + wxwidgets3.2-common + wxwidgets3.2-common-libs + wxwidgets3.2-gtk3 + wxwidgets3.2-gtk3-libs + wxwidgets3.2-msw + wxwidgets3.2-msw-cb_headers + wxwidgets3.2-msw-libs + - name: Build + shell: msys2 {0} + run: | set MSYSTEM=MINGW32 - msys2do make -j - msys2do make install + mingw32-make -j + mingw32-make install bin/bossac --help - - uses: actions/upload-artifact@v1 + - uses: actions/upload-artifact@v3 if: always() with: name: windows diff --git a/.github/workflows/rust_linux.yml b/.github/workflows/rust_linux.yml new file mode 100644 index 00000000..63bbce09 --- /dev/null +++ b/.github/workflows/rust_linux.yml @@ -0,0 +1,92 @@ +name: Rust Linux + +on: [push, pull_request] + +env: + deb_packages: >- + libreadline-dev + libwxgtk3.0-gtk3-dev + +jobs: + check: + name: Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@nightly + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y ${{ env.deb_packages }} + - name: Cargo Check + run: cargo check --all + + build: + name: Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@nightly + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y ${{ env.deb_packages }} + - name: ls + run: | + ls + pwd + - name: Cargo Build + run: cargo build --all + - name: Cargo Install + run: cargo install --path bossac --bins --root dist + - uses: actions/upload-artifact@v3 + with: + name: linux_release_binaries + path: dist/bin + + fmt: + name: Rustfmt + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@nightly + with: + components: rustfmt + - name: Rustfmt Check + uses: actions-rust-lang/rustfmt@v1 + + clippy: + name: Clippy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@nightly + with: + components: clippy + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y ${{ env.deb_packages }} + - name: Cargo Clippy + run: cargo clippy --all-targets -- -D warnings + + udeps: + name: cargo-udeps + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - uses: dtolnay/rust-toolchain@nightly + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y ${{ env.deb_packages }} + - name: cargo-binstall + run: | + mkdir -p ~/.cargo/bin + wget https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-x86_64-unknown-linux-musl.tgz + tar xf cargo-binstall*.tgz -C ~/.cargo/bin + - run: cargo binstall --no-confirm cargo-udeps + - name: Cargo Udeps + run: cargo udeps --all-targets diff --git a/.github/workflows/rust_macos.yml b/.github/workflows/rust_macos.yml new file mode 100644 index 00000000..260ecd8d --- /dev/null +++ b/.github/workflows/rust_macos.yml @@ -0,0 +1,17 @@ +name: Rust macOS + +on: [push, pull_request] + +jobs: + build: + name: Build + runs-on: macOS-latest + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@nightly + - name: Cargo Install + run: cargo install --path bossac --bins --root dist + - uses: actions/upload-artifact@v3 + with: + name: macos_release_binaries + path: dist/bin diff --git a/.github/workflows/rust_windows.yml b/.github/workflows/rust_windows.yml new file mode 100644 index 00000000..7f6b874a --- /dev/null +++ b/.github/workflows/rust_windows.yml @@ -0,0 +1,17 @@ +name: Rust Windows + +on: [push, pull_request] + +jobs: + build: + name: Build + runs-on: windows-latest + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@nightly + - name: Cargo Install + run: cargo install --path bossac --bins --root dist + - uses: actions/upload-artifact@v3 + with: + name: win_release_binaries + path: dist/bin diff --git a/.gitignore b/.gitignore index eb3e6d84..d1ef865d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,8 +2,6 @@ obj *.exe *~ -bossa -bossac bin *.swp tags @@ -11,6 +9,9 @@ tags install/*.crt install/*.p12 +Cargo.lock +target/ + # Extras for building with MSVC x64/ ipch/ diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 00000000..4d2daa07 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "bossa" +version = "2.0.0" +authors = ["Jacob Alexander , Scott Shumate "] +description = "Rust cxx wrapper around BOSSA SAM-BA library" +edition = "2021" +license = "BSD-3-Clause" +repository = "https://github.com/kiibohd/BOSSA" + +[workspace] +members = [ + "bossac" +] + +[dependencies] +cxx = "1.0" + +[build-dependencies] +cxx-build = "1.0" diff --git a/Makefile b/Makefile index 63b2b017..0206a1ab 100644 --- a/Makefile +++ b/Makefile @@ -35,11 +35,12 @@ OS:=$(shell uname -s | cut -c -7) # ifeq ($(OS),MINGW32) # Use wxWindows development branch to work around font scaling issues on Windows -WXVERSION=3.1 +WXVERSION=3.2 EXE=.exe COMMON_SRCS+=WinSerialPort.cpp WinPortFactory.cpp COMMON_LDFLAGS=-Wl,--enable-auto-import -static -static-libstdc++ -static-libgcc -COMMON_LIBS=-ltermcap -Wl,--as-needed -lsetupapi +COMMON_LIBS=-ltermcap -Wl,--as-needed -lsetupapi -lole32 +COMMON_CXXFLAGS=-std=c++14 BOSSA_RC=BossaRes.rc WIXDIR="C:\Program Files (x86)\WiX Toolset v3.11\bin" CODE_SIGN=$(INSTALLDIR)\\code_sign.p12 @@ -85,7 +86,7 @@ endif ifeq ($(OS),Linux) COMMON_SRCS+=PosixSerialPort.cpp LinuxPortFactory.cpp COMMON_LIBS=-Wl,--as-needed -COMMON_CXXFLAGS=-std=c++11 +COMMON_CXXFLAGS=-std=c++14 WX_LIBS+=-lX11 MACHINE:=$(shell uname -m) @@ -98,9 +99,10 @@ endif # OS X rules # ifeq ($(OS),Darwin) +WXVERSION=3.2 COMMON_SRCS+=PosixSerialPort.cpp OSXPortFactory.cpp -COMMON_CXXFLAGS=-arch x86_64 -mmacosx-version-min=10.9 -COMMON_LDFLAGS=-arch x86_64 -mmacosx-version-min=10.9 +COMMON_CXXFLAGS=-arch x86_64 -mmacosx-version-min=11 -std=c++14 +COMMON_LDFLAGS=-arch x86_64 -mmacosx-version-min=11 APP=BOSSA.app DMG=bossa-$(VERSION).dmg VOLUME=BOSSA diff --git a/README.md b/README.md index 174d4151..0a745338 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,48 @@ -BOSSA 1.9.1 ------------ +BOSSA (Rust-edition) +-------------------- -[![Travis Status](https://travis-ci.org/kiibohd/BOSSA.svg?branch=master)](https://travis-ci.org/kiibohd/BOSSA) [![Appveyor Status](https://ci.appveyor.com/api/projects/status/fwbiiefsowxx071n?svg=true)](https://ci.appveyor.com/project/kiibohd/bossa) +[![Rust Linux Status](https://github.com/kiibohd/BOSSA/workflows/rust_linux.yml/badge.svg)](https://github.com/kiibohd/BOSSA/actions/workflows/rust_linux.yml) +[![Rust macOS Status](https://github.com/kiibohd/BOSSA/workflows/rust_macos.yml/badge.svg)](https://github.com/kiibohd/BOSSA/actions/workflows/rust_macos.yml) +[![Rust Windows Status](https://github.com/kiibohd/BOSSA/workflows/rust_windows.yml/badge.svg)](https://github.com/kiibohd/BOSSA/actions/workflows/rust_windows.yml) +[![Legacy Makefile Build Environment](https://github.com/kiibohd/BOSSA/workflows/build.yml/badge.svg)](https://github.com/kiibohd/BOSSA/actions/workflows/build.yml) + + +[![docs.rs](https://docs.rs/bossa/badge.svg)](https://docs.rs/bossa) +[![Crates.io](https://img.shields.io/crates/v/bossa.svg)](https://crates.io/crates/bossa) +[![Crates.io](https://img.shields.io/crates/l/bossa.svg)](https://crates.io/crates/bossa) +[![Crates.io](https://img.shields.io/crates/d/bossa.svg)](https://crates.io/crates/bossa) BOSSA is a flash programming utility for Atmel's SAM family of flash-based ARM microcontrollers. The motivation behind BOSSA is to create a simple, easy-to-use, open source utility to replace Atmel's SAM-BA software. BOSSA is an acronym for Basic Open Source SAM-BA Application to reflect that goal. -The software was created by Scott Shumate with contributions from several -[contributors](../../graphs/contributors). +The software was originally by Scott Shumate with contributions from several [contributors](../../graphs/contributors). Scott has not been active in a number of years and HaaTa needed a rust-lib version of BOSSA, hence this fork. The software is released under the terms of the BSD license as specified in the LICENSE file. +Supported Builds +---------------- + +* Rust (libbossa, bossac) + - `cargo build` + - `cd bossac; cargo build; cargo run -- --help` + - Supports: msvc, macos, linux +* C++ (bossa, bossac, bossash) + - `make -j` + - Supports: mingw, macos, linux + msvc support hasn't been tested recently + +Please see the [GitHub Actions](.github/workflows) for build specifics. + +Installation +------------ + +If you already have rust on your system, you can use it to easily install bossac. + +```bash +cargo install bossac +``` + Supported Device Families ------------------------- * SAM7S @@ -41,7 +72,9 @@ Supported Device Families \* Device families which are not tested for each release and could stop working. -Do you want to help make sure a device family is tested or do you want to see a new device family added? Then contribute a development board with a device from that family to the BOSSA project to make it happen. Contact scott at shumatech.com if you are interested in helping the project. +Please submit a PR if you're interested in fixing or adding support. + +*Actively looking for a co-maintainer for BOSSA* The following individuals and companies graciously provided development boards to assist the BOSSA project. * Atmel Corporation (SAM3N, SAM3S, SAM3U) diff --git a/bossac/Cargo.toml b/bossac/Cargo.toml new file mode 100644 index 00000000..93367d1d --- /dev/null +++ b/bossac/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "bossac" +version = "2.0.0" +authors = ["Jacob Alexander , Scott Shumate "] +description = "Rust cxx version of the BOSSA SAM-BA utility" +edition = "2021" +license = "BSD-3-Clause" +repository = "https://github.com/kiibohd/BOSSA" + +[dependencies] +bossa = { path = ".." } +clap = { version = "4.4", features = ["derive"] } +cxx = "1.0" +log = "0.4" +flexi_logger = "0.25" diff --git a/bossac/README.md b/bossac/README.md new file mode 100644 index 00000000..cf8ded93 --- /dev/null +++ b/bossac/README.md @@ -0,0 +1,21 @@ +bossac (Rust-edition) +--------------------- + +[![Rust Linux Status](https://github.com/kiibohd/BOSSA/workflows/Rust%20Linux/badge.svg)](https://github.com/kiibohd/BOSSA/actions) +[![macOS Linux Status](https://github.com/kiibohd/BOSSA/workflows/Rust%20macOS/badge.svg)](https://github.com/kiibohd/BOSSA/actions) +[![Windows Linux Status](https://github.com/kiibohd/BOSSA/workflows/Rust%20Windows/badge.svg)](https://github.com/kiibohd/BOSSA/actions) + +[![Crates.io](https://img.shields.io/crates/v/bossac.svg)](https://crates.io/crates/bossac) +[![Crates.io](https://img.shields.io/crates/l/bossac.svg)](https://crates.io/crates/bossac) +[![Crates.io](https://img.shields.io/crates/d/bossac.svg)](https://crates.io/crates/bossac) + +This is the rust version of the bossac utility (reimplements bossac.cpp). + +Installation +------------ + +If you already have rust on your system, you can use it to easily install bossac. + +```bash +cargo install bossac +``` diff --git a/bossac/src/main.rs b/bossac/src/main.rs new file mode 100644 index 00000000..9480435a --- /dev/null +++ b/bossac/src/main.rs @@ -0,0 +1,393 @@ +use bossa::bossa; +use clap::Parser; +use cxx::let_cxx_string; +use flexi_logger::Logger; +use log::{debug, error}; +use std::path::PathBuf; +use std::time::Instant; + +#[derive(Parser, Debug)] +#[command( + author, + version, + about = "Basic Open Source SAM-BA Application (BOSSA) +Flash programmer for Atmel SAM devices. +Copyright (C) 2009-2020 ShumaTech (http://www.shumatech.com/) +Copyright (C) 2018-2023 Jacob Alexander (haata@kiibohd.com) + +Examples: + bossac -e -w -v -b image.bin # Erase flash, write flash with image.bin, + # verify the write, and set boot from flash + bossac -r0x10000 image.bin # Read 64KB from flash and store in image.bin", + long_about = None +)] +struct Args { + /// .bin file to operate on + file: Option, + + /// erase the entire flash starting at the offset + #[arg(short, long, default_value = "false")] + erase: bool, + + /// write FILE to the flash; accelerated when combined with erase option + #[arg(short, long, requires = "file", default_value = "false")] + write: bool, + + /// read SIZE from flash and store in FILE; + /// read entire flash if SIZE not specified + #[arg( + short, + long, + require_equals = true, + value_name = "SIZE", + num_args = 0..=1, + requires = "file", + default_value = None, + default_missing_value = "0" + )] + read: Option, + + /// verify FILE matches flash contents + #[arg(short, long, requires = "file", default_value = "false")] + verify: bool, + + /// start erase/write/read/verify operation at flash OFFSET; + /// OFFSET must be aligned to a flash page boundary + #[arg(short, long, default_value_t = 0)] + offset: u32, + + /// use serial PORT to communicate to device; + /// default behavior is to use first serial port + #[arg(short, long, default_value = None)] + port: Option, + + /// boot from ROM if BOOL is false; + /// boot from FLASH if BOOL is true [default]; + /// option is ignored on unsupported devices + #[arg( + short, + long, + require_equals = true, + value_name = "BOOL", + num_args = 0..=1, + default_value = None, + default_missing_value = "true" + )] + boot: Option, + + /// no brownout detection if BOOL is 0; + /// brownout detection is on if BOOL is 1 [default] + #[arg( + short = 'c', + long, + require_equals = true, + value_name = "BOOL", + num_args = 0..=1, + default_value = None, + default_missing_value = "true" + )] + bod: Option, + + /// no brownout reset if BOOL is 0; + /// brownout reset is on if BOOL is 1 [default] + #[arg( + short = 't', + long, + require_equals = true, + value_name = "BOOL", + num_args = 0..=1, + default_value = None, + default_missing_value = "true" + )] + bor: Option, + + /// lock the flash REGION as a comma-separated list; + /// lock all if not given [default] + #[arg( + short, + long, + value_name = "REGION", + value_delimiter = ',', + num_args = 0.., + value_parser = clap::value_parser!(u16).range(0..), + default_value = None + )] + lock: Option>, + + /// unlock the flash REGION as a comma-separated list; + /// unlock all if not given [default] + #[arg( + short, + long, + value_name = "REGION", + value_delimiter = ',', + num_args = 0.., + value_parser = clap::value_parser!(u16).range(0..), + default_value = None + )] + unlock: Option>, + + /// set the flash security flag + #[arg(short, long, default_value = "false")] + security: bool, + + /// display device information + #[arg(short, long, default_value = "false")] + info: bool, + + /// print debug messages + #[arg(short, long, default_value = "false")] + debug: bool, + + /// force serial port detection to USB if BOOL is 1 [default] or to RS-232 if BOOL is 0 + #[arg(short = 'U', long, value_name = "BOOL", default_value = "true")] + usb_port: bool, + + /// reset CPU (if supported) + #[arg(short = 'R', long, default_value = "false")] + reset: bool, + + /// erase and reset via Arduino 1200 baud hack + #[arg(short = 'a', long, default_value = "false")] + arduino_erase: bool, +} + +/// Lite logging setup +fn setup_logging_lite() -> Result<(), ()> { + match Logger::try_with_env_or_str("") + .unwrap() + .format(flexi_logger::colored_default_format) + .format_for_files(flexi_logger::colored_detailed_format) + .duplicate_to_stderr(flexi_logger::Duplicate::All) + .start() + { + Err(_) => Err(()), + Ok(_) => Ok(()), + } +} + +pub fn main() -> std::process::ExitCode { + let args = Args::parse(); + setup_logging_lite().unwrap(); + + let mut samba = bossa::new_samba(); + let mut port_factory = bossa::new_port_factory(); + + if args.debug { + debug!("Debug mode enabled"); + samba.pin_mut().setDebug(true); + } + + let port = if let Some(port) = args.port { + port + } else { + debug!("No port specified, using default"); + port_factory.pin_mut().default_name().to_string() + }; + debug!("Connecting to port: {}", port); + + let_cxx_string!(port = port); + if args.arduino_erase { + debug!("Arduino erase"); + let mut port = port_factory.pin_mut().create_port(&port, args.usb_port); + + println!("Arduino 1200 baud reset"); + if !port.pin_mut().open( + 1200, + 8, + bossa::Parity::ParityNone, + bossa::StopBit::StopBitOne, + ) { + error!("Failed to open port at 1200bps"); + return std::process::ExitCode::FAILURE; + } + + port.pin_mut().setRTS(true); + port.pin_mut().setDTR(false); + port.pin_mut().close(); + + // wait for chip to reboot and USB prot to re-appear + if args.debug { + println!("Arduino reset done"); + } + } + + // Attempt to connect to the port + if !samba.pin_mut().connect( + port_factory.pin_mut().create_port(&port, args.usb_port), + 115200, + ) { + error!("Failed to connect to port: {}", port); + return std::process::ExitCode::FAILURE; + } + + // Setup device connection + let mut device = bossa::new_device(samba.pin_mut()); + device.pin_mut().create(); + let mut observer = bossa::new_bossa_observer(); + let mut flasher = bossa::new_flasher(samba.pin_mut(), device.pin_mut(), observer.pin_mut()); + + if args.info { + debug!("Printing device info"); + let mut flasher_info = bossa::new_flasher_info(); + flasher.pin_mut().info(flasher_info.pin_mut()); + flasher_info.pin_mut().print(); + } + + if let Some(regions) = args.unlock { + if regions.is_empty() { + debug!("Unlocking all regions"); + let_cxx_string!(regions = ""); + flasher.pin_mut().lock(®ions, false); + } else { + debug!("Unlocking regions: {:?}", regions); + let_cxx_string!( + regions = regions + .iter() + .map(|region| region.to_string()) + .collect::>() + .join(",") + ); + flasher.pin_mut().lock(®ions, false); + } + } + + if args.erase { + debug!("Erasing flash at offset: {}", args.offset); + let start = Instant::now(); + flasher.pin_mut().erase(args.offset); + println!("Done in {:?}", start.elapsed()); + } + + // Convert PathBuf to const char* (XXX hopefully cross-platform) + let mut path_buf = Vec::new(); + if let Some(path) = args.file { + #[cfg(unix)] + { + use std::os::unix::ffi::OsStrExt; + path_buf.extend(path.as_os_str().as_bytes()); + path_buf.push(0); + } + + #[cfg(windows)] + { + use std::os::windows::ffi::OsStrExt; + path_buf.extend( + path.as_os_str() + .encode_wide() + .chain(Some(0)) + .map(|b| { + let b = b.to_ne_bytes(); + b.get(0).map(|s| *s).into_iter().chain(b.get(1).map(|s| *s)) + }) + .flatten(), + ); + } + } + + if args.write { + debug!( + "Writing flash with {:?} at offset: {}", + path_buf, args.offset + ); + let start = Instant::now(); + unsafe { + flasher + .pin_mut() + .write(path_buf.as_ptr() as *const i8, args.offset); + } + println!("\nDone in {:?}", start.elapsed()); + } + + if args.verify { + let mut page_errors = 0; + let mut total_errors = 0; + + debug!( + "Verifying flash with {:?} at offset: {}", + path_buf, args.offset + ); + let start = Instant::now(); + if !unsafe { + flasher.pin_mut().verify( + path_buf.as_ptr() as *const i8, + &mut page_errors, + &mut total_errors, + args.offset, + ) + } { + error!("Verify failed {:?}", start.elapsed()); + error!("Page errors: {}", page_errors); + error!("Byte errors: {}", total_errors); + return std::process::ExitCode::FAILURE; + } + println!("\nDone in {:?}", start.elapsed()); + } + + if let Some(size) = args.read { + debug!( + "Reading flash into {:?} at offset: {}", + path_buf, args.offset + ); + let start = Instant::now(); + unsafe { + flasher + .pin_mut() + .read(path_buf.as_ptr() as *const i8, size, args.offset); + } + println!("\nDone in {:?}", start.elapsed()); + } + + if let Some(boot) = args.boot { + if boot { + println!("Setting boot: Flash"); + } else { + println!("Setting boot: ROM"); + } + flasher.pin_mut().setBootFlash(boot); + } + + if let Some(brownout) = args.bod { + println!("Setting brownout detect: {}", brownout); + flasher.pin_mut().setBod(brownout); + } + + if let Some(brownout) = args.bor { + println!("Setting brownout reset: {}", brownout); + flasher.pin_mut().setBor(brownout); + } + + if args.security { + println!("Set security"); + flasher.pin_mut().setSecurity(); + } + + if let Some(regions) = args.lock { + if regions.is_empty() { + debug!("Locking all regions"); + let_cxx_string!(regions = ""); + flasher.pin_mut().lock(®ions, true); + } else { + debug!("Locking regions: {:?}", regions); + let_cxx_string!( + regions = regions + .iter() + .map(|region| region.to_string()) + .collect::>() + .join(",") + ); + flasher.pin_mut().lock(®ions, true); + } + } + + debug!("Write options"); + flasher.pin_mut().writeOptions(); + + if args.reset { + debug!("Reset"); + flasher.pin_mut().reset(); + } + + debug!("Done"); + std::process::ExitCode::SUCCESS +} diff --git a/build.rs b/build.rs new file mode 100644 index 00000000..7860c9ac --- /dev/null +++ b/build.rs @@ -0,0 +1,76 @@ +fn main() { + let cpp_files = vec![ + "src/Applet.cpp", + "src/BossaObserver.cpp", + "src/D2xNvmFlash.cpp", + "src/D5xNvmFlash.cpp", + "src/Device.cpp", + "src/EefcFlash.cpp", + "src/EfcFlash.cpp", + "src/Flash.cpp", + "src/Flasher.cpp", + #[cfg(target_os = "linux")] + "src/LinuxPortFactory.cpp", + #[cfg(target_os = "macos")] + "src/OSXPortFactory.cpp", + "src/PortFactory.cpp", + #[cfg(target_family = "unix")] + "src/PosixSerialPort.cpp", + "src/Samba.cpp", + #[cfg(target_os = "windows")] + "src/WinPortFactory.cpp", + #[cfg(target_os = "windows")] + "src/WinSerialPort.cpp", + "src/WordCopyApplet.cpp", + "src/WordCopyArm.cpp", + ]; + let h_files = vec![ + "src/Applet.h", + "src/BossaObserver.h", + "src/D2xNvmFlash.h", + "src/D5xNvmFlash.h", + "src/Device.h", + "src/EefcFlash.h", + "src/EfcFlash.h", + "src/Flash.h", + "src/Flasher.h", + #[cfg(target_os = "linux")] + "src/LinuxPortFactory.h", + #[cfg(target_os = "macos")] + "src/OSXPortFactory.h", + "src/PortFactory.h", + #[cfg(target_family = "unix")] + "src/PosixSerialPort.h", + "src/Samba.h", + "src/SerialPort.h", + #[cfg(target_os = "windows")] + "src/WinPortFactory.h", + #[cfg(target_os = "windows")] + "src/WinSerialPort.h", + "src/WordCopyApplet.h", + "src/WordCopyArm.h", + ]; + let rs_files = vec!["src/lib.rs"]; + + // Setup cxx build + // cpp files to watch + build + // h files to watch + // rs files to watch + let mut build = cxx_build::bridge("src/lib.rs"); + for cpp in cpp_files { + build.file(cpp); + println!("cargo:rerun-if-changed={}", cpp); + } + for h in h_files { + println!("cargo:rerun-if-changed={}", h); + } + for rs in rs_files { + println!("cargo:rerun-if-changed={}", rs); + } + + // Extra includes needed for msvc environments + #[cfg(target_env = "msvc")] + build.include("src/msvc"); + + build.flag_if_supported("-std=c++14").compile("bossa"); +} diff --git a/deny.toml b/deny.toml new file mode 100644 index 00000000..9f90cad6 --- /dev/null +++ b/deny.toml @@ -0,0 +1,270 @@ +# This template contains all of the possible sections and their default values + +# Note that all fields that take a lint level have these possible values: +# * deny - An error will be produced and the check will fail +# * warn - A warning will be produced, but the check will not fail +# * allow - No warning or error will be produced, though in some cases a note +# will be + +# The values provided in this template are the default values that will be used +# when any section or field is not specified in your own configuration + +# Root options + +# If 1 or more target triples (and optionally, target_features) are specified, +# only the specified targets will be checked when running `cargo deny check`. +# This means, if a particular package is only ever used as a target specific +# dependency, such as, for example, the `nix` crate only being used via the +# `target_family = "unix"` configuration, that only having windows targets in +# this list would mean the nix crate, as well as any of its exclusive +# dependencies not shared by any other crates, would be ignored, as the target +# list here is effectively saying which targets you are building for. +targets = [ + # The triple can be any string, but only the target triples built in to + # rustc (as of 1.40) can be checked against actual config expressions + #{ triple = "x86_64-unknown-linux-musl" }, + # You can also specify which target_features you promise are enabled for a + # particular target. target_features are currently not validated against + # the actual valid features supported by the target architecture. + #{ triple = "wasm32-unknown-unknown", features = ["atomics"] }, +] +# When creating the dependency graph used as the source of truth when checks are +# executed, this field can be used to prune crates from the graph, removing them +# from the view of cargo-deny. This is an extremely heavy hammer, as if a crate +# is pruned from the graph, all of its dependencies will also be pruned unless +# they are connected to another crate in the graph that hasn't been pruned, +# so it should be used with care. The identifiers are [Package ID Specifications] +# (https://doc.rust-lang.org/cargo/reference/pkgid-spec.html) +#exclude = [] +# If true, metadata will be collected with `--all-features`. Note that this can't +# be toggled off if true, if you want to conditionally enable `--all-features` it +# is recommended to pass `--all-features` on the cmd line instead +all-features = false +# If true, metadata will be collected with `--no-default-features`. The same +# caveat with `all-features` applies +no-default-features = false +# If set, these feature will be enabled when collecting metadata. If `--features` +# is specified on the cmd line they will take precedence over this option. +#features = [] +# When outputting inclusion graphs in diagnostics that include features, this +# option can be used to specify the depth at which feature edges will be added. +# This option is included since the graphs can be quite large and the addition +# of features from the crate(s) to all of the graph roots can be far too verbose. +# This option can be overridden via `--feature-depth` on the cmd line +feature-depth = 1 + +# This section is considered when running `cargo deny check advisories` +# More documentation for the advisories section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/advisories/cfg.html +[advisories] +# The path where the advisory database is cloned/fetched into +db-path = "~/.cargo/advisory-db" +# The url(s) of the advisory databases to use +db-urls = ["https://github.com/rustsec/advisory-db"] +# The lint level for security vulnerabilities +vulnerability = "deny" +# The lint level for unmaintained crates +unmaintained = "warn" +# The lint level for crates that have been yanked from their source registry +yanked = "warn" +# The lint level for crates with security notices. Note that as of +# 2019-12-17 there are no security notice advisories in +# https://github.com/rustsec/advisory-db +notice = "warn" +# A list of advisory IDs to ignore. Note that ignored advisories will still +# output a note when they are encountered. +ignore = [ + #"RUSTSEC-0000-0000", +] +# Threshold for security vulnerabilities, any vulnerability with a CVSS score +# lower than the range specified will be ignored. Note that ignored advisories +# will still output a note when they are encountered. +# * None - CVSS Score 0.0 +# * Low - CVSS Score 0.1 - 3.9 +# * Medium - CVSS Score 4.0 - 6.9 +# * High - CVSS Score 7.0 - 8.9 +# * Critical - CVSS Score 9.0 - 10.0 +#severity-threshold = + +# If this is true, then cargo deny will use the git executable to fetch advisory database. +# If this is false, then it uses a built-in git library. +# Setting this to true can be helpful if you have special authentication requirements that cargo-deny does not support. +# See Git Authentication for more information about setting up git authentication. +#git-fetch-with-cli = true + +# This section is considered when running `cargo deny check licenses` +# More documentation for the licenses section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/licenses/cfg.html +[licenses] +# The lint level for crates which do not have a detectable license +unlicensed = "deny" +# List of explicitly allowed licenses +# See https://spdx.org/licenses/ for list of possible licenses +# [possible values: any SPDX 3.11 short identifier (+ optional exception)]. +allow = [ + "Apache-2.0", + "BSD-3-Clause", + "MIT", + "Unicode-DFS-2016", +] +# List of explicitly disallowed licenses +# See https://spdx.org/licenses/ for list of possible licenses +# [possible values: any SPDX 3.11 short identifier (+ optional exception)]. +deny = [ + #"Nokia", +] +# Lint level for licenses considered copyleft +copyleft = "warn" +# Blanket approval or denial for OSI-approved or FSF Free/Libre licenses +# * both - The license will be approved if it is both OSI-approved *AND* FSF +# * either - The license will be approved if it is either OSI-approved *OR* FSF +# * osi-only - The license will be approved if is OSI-approved *AND NOT* FSF +# * fsf-only - The license will be approved if is FSF *AND NOT* OSI-approved +# * neither - This predicate is ignored and the default lint level is used +allow-osi-fsf-free = "neither" +# Lint level used when no other predicates are matched +# 1. License isn't in the allow or deny lists +# 2. License isn't copyleft +# 3. License isn't OSI/FSF, or allow-osi-fsf-free = "neither" +default = "deny" +# The confidence threshold for detecting a license from license text. +# The higher the value, the more closely the license text must be to the +# canonical license text of a valid SPDX license file. +# [possible values: any between 0.0 and 1.0]. +confidence-threshold = 0.8 +# Allow 1 or more licenses on a per-crate basis, so that particular licenses +# aren't accepted for every possible crate as with the normal allow list +exceptions = [ + # Each entry is the crate and version constraint, and its specific allow + # list + #{ allow = ["Zlib"], name = "adler32", version = "*" }, +] + +# Some crates don't have (easily) machine readable licensing information, +# adding a clarification entry for it allows you to manually specify the +# licensing information +[[licenses.clarify]] +# The name of the crate the clarification applies to +name = "ring" +# The optional version constraint for the crate +#version = "*" +# The SPDX expression for the license requirements of the crate +expression = "MIT AND ISC AND OpenSSL" +# One or more files in the crate's source used as the "source of truth" for +# the license expression. If the contents match, the clarification will be used +# when running the license check, otherwise the clarification will be ignored +# and the crate will be checked normally, which may produce warnings or errors +# depending on the rest of your configuration +license-files = [ + # Each entry is a crate relative path, and the (opaque) hash of its contents + { path = "LICENSE", hash = 0xbd0eed23 } +] + +[licenses.private] +# If true, ignores workspace crates that aren't published, or are only +# published to private registries. +# To see how to mark a crate as unpublished (to the official registry), +# visit https://doc.rust-lang.org/cargo/reference/manifest.html#the-publish-field. +ignore = false +# One or more private registries that you might publish crates to, if a crate +# is only published to private registries, and ignore is true, the crate will +# not have its license(s) checked +registries = [ + #"https://sekretz.com/registry +] + +# This section is considered when running `cargo deny check bans`. +# More documentation about the 'bans' section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/bans/cfg.html +[bans] +# Lint level for when multiple versions of the same crate are detected +multiple-versions = "warn" +# Lint level for when a crate version requirement is `*` +wildcards = "allow" +# The graph highlighting used when creating dotgraphs for crates +# with multiple versions +# * lowest-version - The path to the lowest versioned duplicate is highlighted +# * simplest-path - The path to the version with the fewest edges is highlighted +# * all - Both lowest-version and simplest-path are used +highlight = "all" +# The default lint level for `default` features for crates that are members of +# the workspace that is being checked. This can be overriden by allowing/denying +# `default` on a crate-by-crate basis if desired. +workspace-default-features = "allow" +# The default lint level for `default` features for external crates that are not +# members of the workspace. This can be overriden by allowing/denying `default` +# on a crate-by-crate basis if desired. +external-default-features = "allow" +# List of crates that are allowed. Use with care! +allow = [ + #{ name = "ansi_term", version = "=0.11.0" }, +] +# List of crates to deny +deny = [ + # Each entry the name of a crate and a version range. If version is + # not specified, all versions will be matched. + #{ name = "ansi_term", version = "=0.11.0" }, + # + # Wrapper crates can optionally be specified to allow the crate when it + # is a direct dependency of the otherwise banned crate + #{ name = "ansi_term", version = "=0.11.0", wrappers = [] }, +] + +# List of features to allow/deny +# Each entry the name of a crate and a version range. If version is +# not specified, all versions will be matched. +#[[bans.features]] +#name = "reqwest" +# Features to not allow +#deny = ["json"] +# Features to allow +#allow = [ +# "rustls", +# "__rustls", +# "__tls", +# "hyper-rustls", +# "rustls", +# "rustls-pemfile", +# "rustls-tls-webpki-roots", +# "tokio-rustls", +# "webpki-roots", +#] +# If true, the allowed features must exactly match the enabled feature set. If +# this is set there is no point setting `deny` +#exact = true + +# Certain crates/versions that will be skipped when doing duplicate detection. +skip = [ + #{ name = "ansi_term", version = "=0.11.0" }, +] +# Similarly to `skip` allows you to skip certain crates during duplicate +# detection. Unlike skip, it also includes the entire tree of transitive +# dependencies starting at the specified crate, up to a certain depth, which is +# by default infinite. +skip-tree = [ + #{ name = "ansi_term", version = "=0.11.0", depth = 20 }, +] + +# This section is considered when running `cargo deny check sources`. +# More documentation about the 'sources' section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/sources/cfg.html +[sources] +# Lint level for what to happen when a crate from a crate registry that is not +# in the allow list is encountered +unknown-registry = "warn" +# Lint level for what to happen when a crate from a git repository that is not +# in the allow list is encountered +unknown-git = "warn" +# List of URLs for allowed crate registries. Defaults to the crates.io index +# if not specified. If it is specified but empty, no registries are allowed. +allow-registry = ["https://github.com/rust-lang/crates.io-index"] +# List of URLs for allowed Git repositories +allow-git = [] + +[sources.allow-org] +# 1 or more github.com organizations to allow git sources for +github = [""] +# 1 or more gitlab.com organizations to allow git sources for +gitlab = [""] +# 1 or more bitbucket.org organizations to allow git sources for +bitbucket = [""] diff --git a/src/BossaForm.cpp b/src/BossaForm.cpp index ffb62e1f..8af38d45 100644 --- a/src/BossaForm.cpp +++ b/src/BossaForm.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Mar 9 2018) +// C++ code generated with wxFormBuilder (version 3.10.1-d4a3afd) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -13,113 +13,113 @@ MainFrame::MainFrame( wxWindow* parent, wxWindowID id, const wxString& title, co { this->SetSizeHints( wxDefaultSize, wxDefaultSize ); this->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_3DLIGHT ) ); - + wxBoxSizer* _topBoxSizer; _topBoxSizer = new wxBoxSizer( wxVERTICAL ); - + wxBoxSizer* _titleBoxSizer; _titleBoxSizer = new wxBoxSizer( wxHORIZONTAL ); - + _bossaBitmap = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 ); _titleBoxSizer->Add( _bossaBitmap, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - + _titleText = new wxStaticText( this, wxID_ANY, wxT("Flash Programmer for Atmel SAM Devices"), wxDefaultPosition, wxDefaultSize, 0 ); _titleText->Wrap( -1 ); _titleBoxSizer->Add( _titleText, 0, wxALL|wxALIGN_BOTTOM, 5 ); - - + + _titleBoxSizer->Add( 0, 0, 1, wxEXPAND, 5 ); - + _aboutButton = new wxButton( this, wxID_ANY, wxT("About"), wxDefaultPosition, wxDefaultSize, 0 ); _aboutButton->SetToolTip( wxT("Display information about BOSSA") ); - + _titleBoxSizer->Add( _aboutButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - - + + _topBoxSizer->Add( _titleBoxSizer, 0, wxALL|wxEXPAND, 5 ); - + wxStaticBoxSizer* _portBoxSizer; _portBoxSizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, wxT("Serial Port") ), wxHORIZONTAL ); - - _portComboBox = new wxComboBox( _portBoxSizer->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY ); + + _portComboBox = new wxComboBox( _portBoxSizer->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY ); _portBoxSizer->Add( _portComboBox, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - - + + _portBoxSizer->Add( 0, 0, 1, wxEXPAND, 5 ); - + _refreshButton = new wxButton( _portBoxSizer->GetStaticBox(), wxID_ANY, wxT("Refresh"), wxDefaultPosition, wxDefaultSize, 0 ); _refreshButton->SetToolTip( wxT("Refresh the list of available serial ports") ); - + _portBoxSizer->Add( _refreshButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - - + + _topBoxSizer->Add( _portBoxSizer, 3, wxALL|wxEXPAND, 5 ); - + wxStaticBoxSizer* _fileBoxSizer; _fileBoxSizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, wxT("File") ), wxHORIZONTAL ); - + _filePicker = new wxFilePickerCtrl( _fileBoxSizer->GetStaticBox(), wxID_ANY, wxEmptyString, wxT("Select a file"), wxT("*.*"), wxDefaultPosition, wxDefaultSize, wxFLP_OPEN|wxFLP_USE_TEXTCTRL ); _filePicker->SetToolTip( wxT("Select the file to use for write/verify/read operations") ); - + _fileBoxSizer->Add( _filePicker, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - - + + _topBoxSizer->Add( _fileBoxSizer, 3, wxALL|wxEXPAND, 5 ); - + wxBoxSizer* _buttonBoxSizer; _buttonBoxSizer = new wxBoxSizer( wxHORIZONTAL ); - - + + _buttonBoxSizer->Add( 0, 0, 1, wxEXPAND, 5 ); - + _writeButton = new wxButton( this, wxID_ANY, wxT("Write"), wxDefaultPosition, wxDefaultSize, 0 ); _writeButton->SetToolTip( wxT("Write the flash with the file above") ); - + _buttonBoxSizer->Add( _writeButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - - + + _buttonBoxSizer->Add( 0, 0, 1, wxEXPAND, 5 ); - + _verifyButton = new wxButton( this, wxID_ANY, wxT("Verify"), wxDefaultPosition, wxDefaultSize, 0 ); _verifyButton->SetToolTip( wxT("Verify the flash matches the file above") ); - + _buttonBoxSizer->Add( _verifyButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - - + + _buttonBoxSizer->Add( 0, 0, 1, wxEXPAND, 5 ); - + _readButton = new wxButton( this, wxID_ANY, wxT("Read"), wxDefaultPosition, wxDefaultSize, 0 ); _readButton->SetToolTip( wxT("Read the flash into the file above") ); - + _buttonBoxSizer->Add( _readButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - - + + _buttonBoxSizer->Add( 0, 0, 1, wxEXPAND, 5 ); - + _infoButton = new wxButton( this, wxID_ANY, wxT("Info"), wxDefaultPosition, wxDefaultSize, 0 ); _infoButton->SetToolTip( wxT("Display inforamtion aboth the connected processor") ); - + _buttonBoxSizer->Add( _infoButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - - + + _buttonBoxSizer->Add( 0, 0, 1, wxEXPAND, 5 ); - + _exitButton = new wxButton( this, wxID_ANY, wxT("Exit"), wxDefaultPosition, wxDefaultSize, 0 ); _exitButton->SetToolTip( wxT("Exit and close BOSSA") ); - + _buttonBoxSizer->Add( _exitButton, 0, wxALL, 5 ); - - + + _buttonBoxSizer->Add( 0, 0, 1, wxEXPAND, 5 ); - - + + _topBoxSizer->Add( _buttonBoxSizer, 0, wxALL|wxEXPAND, 5 ); - - + + this->SetSizer( _topBoxSizer ); this->Layout(); - _statusBar = this->CreateStatusBar( 2, wxST_SIZEGRIP, wxID_ANY ); - + _statusBar = this->CreateStatusBar( 2, wxSTB_SIZEGRIP, wxID_ANY ); + this->Centre( wxBOTH ); } @@ -131,38 +131,38 @@ ProgressDialog::ProgressDialog( wxWindow* parent, wxWindowID id, const wxString& { this->SetSizeHints( wxDefaultSize, wxDefaultSize ); this->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_3DLIGHT ) ); - + wxBoxSizer* _progressBoxSizer; _progressBoxSizer = new wxBoxSizer( wxVERTICAL ); - - + + _progressBoxSizer->Add( 0, 0, 1, wxEXPAND, 5 ); - + _infoStaticText = new wxStaticText( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); _infoStaticText->Wrap( -1 ); - _progressBoxSizer->Add( _infoStaticText, 0, wxALL|wxEXPAND, 5 ); // DC do not use wxALIGN_CENTER with wxEXPAND, it triggers an assertion failure in wxWidgets - + _progressBoxSizer->Add( _infoStaticText, 0, wxALIGN_CENTER|wxALL|wxEXPAND, 5 ); + _statusGauge = new wxGauge( this, wxID_ANY, 100, wxDefaultPosition, wxDefaultSize, wxGA_HORIZONTAL ); - _statusGauge->SetValue( 0 ); + _statusGauge->SetValue( 0 ); _progressBoxSizer->Add( _statusGauge, 0, wxALL|wxEXPAND, 5 ); - - + + _progressBoxSizer->Add( 0, 0, 1, wxEXPAND, 5 ); - + _sdbSizer = new wxStdDialogButtonSizer(); _sdbSizerCancel = new wxButton( this, wxID_CANCEL ); _sdbSizer->AddButton( _sdbSizerCancel ); _sdbSizer->Realize(); - + _progressBoxSizer->Add( _sdbSizer, 0, wxALIGN_CENTER|wxALL, 5 ); - - + + _progressBoxSizer->Add( 0, 0, 1, wxEXPAND, 5 ); - - + + this->SetSizer( _progressBoxSizer ); this->Layout(); - + this->Centre( wxBOTH ); } @@ -174,62 +174,62 @@ AboutDialog::AboutDialog( wxWindow* parent, wxWindowID id, const wxString& title { this->SetSizeHints( wxDefaultSize, wxDefaultSize ); this->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_3DLIGHT ) ); - + wxBoxSizer* _topBoxSizer; _topBoxSizer = new wxBoxSizer( wxVERTICAL ); - + _bossaBitmap = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 ); _topBoxSizer->Add( _bossaBitmap, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5 ); - + _titleStaticText = new wxStaticText( this, wxID_ANY, wxT("Basic Open Source SAM-BA Application"), wxDefaultPosition, wxDefaultSize, 0 ); _titleStaticText->Wrap( -1 ); _topBoxSizer->Add( _titleStaticText, 0, wxALL, 5 ); - + _githubHyperlink = new wxHyperlinkCtrl( this, wxID_ANY, wxT("https://github.com/kiibohd/BOSSA"), wxT("https://github.com/kiibohd/BOSSA"), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE ); _topBoxSizer->Add( _githubHyperlink, 0, wxALL, 5 ); - + _versionStaticText = new wxStaticText( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); _versionStaticText->Wrap( -1 ); _topBoxSizer->Add( _versionStaticText, 0, wxALL, 5 ); - + _wxStaticText = new wxStaticText( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); _wxStaticText->Wrap( -1 ); _topBoxSizer->Add( _wxStaticText, 0, wxALL, 5 ); - + m_staticline1 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); _topBoxSizer->Add( m_staticline1, 0, wxEXPAND | wxALL, 5 ); - + _shumatechBitmap = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 ); _topBoxSizer->Add( _shumatechBitmap, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5 ); - + _copyrightStaticText = new wxStaticText( this, wxID_ANY, wxT("(c) 2011-2018 ShumaTech. All rights reserved."), wxDefaultPosition, wxDefaultSize, 0 ); _copyrightStaticText->Wrap( -1 ); _topBoxSizer->Add( _copyrightStaticText, 0, wxALL, 5 ); - + _shumatechHyperlink = new wxHyperlinkCtrl( this, wxID_ANY, wxT("http://www.shumatech.com"), wxT("http://www.shumatech.com"), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE ); _topBoxSizer->Add( _shumatechHyperlink, 0, wxALL, 5 ); - + m_staticline2 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); _topBoxSizer->Add( m_staticline2, 0, wxEXPAND | wxALL, 5 ); - + m_disclaimerStaticText = new wxStaticText( this, wxID_ANY, wxT("This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."), wxDefaultPosition, wxDefaultSize, 0 ); m_disclaimerStaticText->Wrap( 280 ); _topBoxSizer->Add( m_disclaimerStaticText, 0, wxALL, 5 ); - + m_staticline3 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); _topBoxSizer->Add( m_staticline3, 0, wxEXPAND | wxALL, 5 ); - + _sdbSizer = new wxStdDialogButtonSizer(); _sdbSizerOK = new wxButton( this, wxID_OK ); _sdbSizer->AddButton( _sdbSizerOK ); _sdbSizer->Realize(); - + _topBoxSizer->Add( _sdbSizer, 1, wxALL|wxEXPAND, 10 ); - - + + this->SetSizer( _topBoxSizer ); this->Layout(); - + this->Centre( wxBOTH ); } @@ -241,135 +241,135 @@ InfoDialog::InfoDialog( wxWindow* parent, wxWindowID id, const wxString& title, { this->SetSizeHints( wxDefaultSize, wxDefaultSize ); this->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_3DLIGHT ) ); - + wxBoxSizer* _topBoxSizer; _topBoxSizer = new wxBoxSizer( wxVERTICAL ); - + wxBoxSizer* _deviceBoxSizer; _deviceBoxSizer = new wxBoxSizer( wxHORIZONTAL ); - + _deviceStaticText = new wxStaticText( this, wxID_ANY, wxT("Device:"), wxDefaultPosition, wxDefaultSize, 0 ); _deviceStaticText->Wrap( -1 ); _deviceBoxSizer->Add( _deviceStaticText, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - + _deviceTextCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY ); _deviceBoxSizer->Add( _deviceTextCtrl, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - - + + _topBoxSizer->Add( _deviceBoxSizer, 0, wxALL|wxEXPAND, 5 ); - + wxBoxSizer* _versionBoxSizer; _versionBoxSizer = new wxBoxSizer( wxHORIZONTAL ); - + _versionStaticText = new wxStaticText( this, wxID_ANY, wxT("Version:"), wxDefaultPosition, wxDefaultSize, 0 ); _versionStaticText->Wrap( -1 ); _versionBoxSizer->Add( _versionStaticText, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - + _versionTextCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY ); _versionBoxSizer->Add( _versionTextCtrl, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - - + + _topBoxSizer->Add( _versionBoxSizer, 0, wxALL|wxEXPAND, 5 ); - + wxBoxSizer* _middleBoxSizer; _middleBoxSizer = new wxBoxSizer( wxHORIZONTAL ); - + wxStaticBoxSizer* _flashBoxSizer; _flashBoxSizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, wxT("Flash") ), wxVERTICAL ); - + wxFlexGridSizer* _flashGridSizer; _flashGridSizer = new wxFlexGridSizer( 0, 2, 0, 0 ); _flashGridSizer->SetFlexibleDirection( wxBOTH ); _flashGridSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); - + _pagesStaticText = new wxStaticText( _flashBoxSizer->GetStaticBox(), wxID_ANY, wxT("Pages:"), wxDefaultPosition, wxDefaultSize, 0 ); _pagesStaticText->Wrap( -1 ); _flashGridSizer->Add( _pagesStaticText, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - + _pagesTextCtrl = new wxTextCtrl( _flashBoxSizer->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY ); _flashGridSizer->Add( _pagesTextCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - + _pageSizeStaticText = new wxStaticText( _flashBoxSizer->GetStaticBox(), wxID_ANY, wxT("Page Size:"), wxDefaultPosition, wxDefaultSize, 0 ); _pageSizeStaticText->Wrap( -1 ); _flashGridSizer->Add( _pageSizeStaticText, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - + _pageSizeTextCtrl = new wxTextCtrl( _flashBoxSizer->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY ); _flashGridSizer->Add( _pageSizeTextCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - + _totalSizeStaticText = new wxStaticText( _flashBoxSizer->GetStaticBox(), wxID_ANY, wxT("Total Size:"), wxDefaultPosition, wxDefaultSize, 0 ); _totalSizeStaticText->Wrap( -1 ); _flashGridSizer->Add( _totalSizeStaticText, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - + _totalSizeTextCtrl = new wxTextCtrl( _flashBoxSizer->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY ); _flashGridSizer->Add( _totalSizeTextCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - + _planesStaticText = new wxStaticText( _flashBoxSizer->GetStaticBox(), wxID_ANY, wxT("Planes:"), wxDefaultPosition, wxDefaultSize, 0 ); _planesStaticText->Wrap( -1 ); _flashGridSizer->Add( _planesStaticText, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - + _planesTextCtrl = new wxTextCtrl( _flashBoxSizer->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY ); _flashGridSizer->Add( _planesTextCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - - + + _flashBoxSizer->Add( _flashGridSizer, 1, wxEXPAND, 5 ); - - + + _middleBoxSizer->Add( _flashBoxSizer, 0, wxALL|wxEXPAND, 5 ); - + wxStaticBoxSizer* _optionsBoxSizer; _optionsBoxSizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, wxT("Options") ), wxVERTICAL ); - + wxFlexGridSizer* _gpnvGridSizer; _gpnvGridSizer = new wxFlexGridSizer( 0, 2, 0, 0 ); _gpnvGridSizer->SetFlexibleDirection( wxBOTH ); _gpnvGridSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); - + _bootCheckBox = new wxCheckBox( _optionsBoxSizer->GetStaticBox(), wxID_ANY, wxT("Boot to flash"), wxDefaultPosition, wxDefaultSize, 0 ); _gpnvGridSizer->Add( _bootCheckBox, 0, wxALL, 5 ); - + _bodCheckBox = new wxCheckBox( _optionsBoxSizer->GetStaticBox(), wxID_ANY, wxT("Brownout detect"), wxDefaultPosition, wxDefaultSize, 0 ); _gpnvGridSizer->Add( _bodCheckBox, 0, wxALL, 5 ); - + _securityCheckBox = new wxCheckBox( _optionsBoxSizer->GetStaticBox(), wxID_ANY, wxT("Security"), wxDefaultPosition, wxDefaultSize, 0 ); _gpnvGridSizer->Add( _securityCheckBox, 0, wxALL, 5 ); - + _borCheckBox = new wxCheckBox( _optionsBoxSizer->GetStaticBox(), wxID_ANY, wxT("Brownout reset"), wxDefaultPosition, wxDefaultSize, 0 ); _gpnvGridSizer->Add( _borCheckBox, 0, wxALL, 5 ); - - + + _optionsBoxSizer->Add( _gpnvGridSizer, 0, wxEXPAND, 5 ); - + wxBoxSizer* bSizer13; bSizer13 = new wxBoxSizer( wxVERTICAL ); - + _lockStaticText = new wxStaticText( _optionsBoxSizer->GetStaticBox(), wxID_ANY, wxT("Lock Regions:"), wxDefaultPosition, wxDefaultSize, 0 ); _lockStaticText->Wrap( -1 ); - bSizer13->Add( _lockStaticText, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - + bSizer13->Add( _lockStaticText, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5 ); + _lockTextCtrl = new wxTextCtrl( _optionsBoxSizer->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY ); bSizer13->Add( _lockTextCtrl, 0, wxALL|wxEXPAND, 5 ); - - + + _optionsBoxSizer->Add( bSizer13, 1, wxEXPAND, 5 ); - - + + _middleBoxSizer->Add( _optionsBoxSizer, 0, wxALL|wxEXPAND, 5 ); - - + + _topBoxSizer->Add( _middleBoxSizer, 0, wxEXPAND, 5 ); - + _sdbSizer = new wxStdDialogButtonSizer(); _sdbSizerOK = new wxButton( this, wxID_OK ); _sdbSizer->AddButton( _sdbSizerOK ); _sdbSizer->Realize(); - + _topBoxSizer->Add( _sdbSizer, 1, wxALL|wxEXPAND, 10 ); - - + + this->SetSizer( _topBoxSizer ); this->Layout(); _topBoxSizer->Fit( this ); - + this->Centre( wxBOTH ); } diff --git a/src/BossaForm.fbp b/src/BossaForm.fbp index b92f7310..3dfddf6a 100644 --- a/src/BossaForm.fbp +++ b/src/BossaForm.fbp @@ -1,6 +1,6 @@ - + C++ @@ -14,6 +14,7 @@ BossaForm 1000 none + 0 Bossa @@ -25,6 +26,7 @@ 1 1 UI + 0 0 0 @@ -50,45 +52,11 @@ BOSSA - Kiibohd + 0 wxTAB_TRAVERSAL 1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - _topBoxSizer @@ -159,29 +127,6 @@ - - - - - - - - - - - - - - - - - - - - - - - @@ -217,6 +162,7 @@ 0 wxID_ANY Flash Programmer for Atmel SAM Devices + 0 0 @@ -242,29 +188,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -290,27 +213,34 @@ + 0 + 1 0 1 1 + 0 0 + Dock 0 Left 1 1 + 0 0 wxID_ANY About + + 0 0 @@ -325,6 +255,8 @@ protected 1 + + Resizable 1 @@ -339,30 +271,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -379,7 +287,6 @@ wxHORIZONTAL 1 none - 5 wxALIGN_CENTER_VERTICAL|wxALL @@ -443,34 +350,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -496,27 +375,34 @@ + 0 + 1 0 1 1 + 0 0 + Dock 0 Left 1 1 + 0 0 wxID_ANY Refresh + + 0 0 @@ -531,6 +417,8 @@ protected 1 + + Resizable 1 @@ -545,30 +433,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -585,7 +449,6 @@ wxHORIZONTAL 1 none - 5 wxALIGN_CENTER_VERTICAL|wxALL @@ -649,30 +512,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -709,27 +548,34 @@ + 0 + 1 0 1 1 + 0 0 + Dock 0 Left 1 1 + 0 0 wxID_ANY Write + + 0 0 @@ -744,6 +590,8 @@ protected 1 + + Resizable 1 @@ -758,30 +606,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -807,27 +631,34 @@ + 0 + 1 0 1 1 + 0 0 + Dock 0 Left 1 1 + 0 0 wxID_ANY Verify + + 0 0 @@ -842,6 +673,8 @@ protected 1 + + Resizable 1 @@ -856,30 +689,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -905,27 +714,34 @@ + 0 + 1 0 1 1 + 0 0 + Dock 0 Left 1 1 + 0 0 wxID_ANY Read + + 0 0 @@ -940,6 +756,8 @@ protected 1 + + Resizable 1 @@ -954,30 +772,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -1003,27 +797,34 @@ + 0 + 1 0 1 1 + 0 0 + Dock 0 Left 1 1 + 0 0 wxID_ANY Info + + 0 0 @@ -1038,6 +839,8 @@ protected 1 + + Resizable 1 @@ -1052,30 +855,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -1101,27 +880,34 @@ + 0 + 1 0 1 1 + 0 0 + Dock 0 Left 1 1 + 0 0 wxID_ANY Exit + + 0 0 @@ -1136,6 +922,8 @@ protected 1 + + Resizable 1 @@ -1150,30 +938,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -1205,35 +969,12 @@ protected - wxST_SIZEGRIP + wxSTB_SIZEGRIP - - - - - - - - - - - - - - - - - - - - - - - @@ -1259,45 +1000,10 @@ Progress + 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - _progressBoxSizer @@ -1346,6 +1052,7 @@ 0 wxID_ANY + 0 0 @@ -1371,29 +1078,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -1458,29 +1142,6 @@ - - - - - - - - - - - - - - - - - - - - - - - @@ -1509,14 +1170,6 @@ _sdbSizer protected - - - - - - - - @@ -1554,45 +1207,10 @@ About BOSSA + 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - _topBoxSizer @@ -1654,29 +1272,6 @@ - - - - - - - - - - - - - - - - - - - - - - - @@ -1712,6 +1307,7 @@ 0 wxID_ANY Basic Open Source SAM-BA Application + 0 0 @@ -1737,29 +1333,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -1823,30 +1396,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -1882,6 +1431,7 @@ 0 wxID_ANY + 0 0 @@ -1907,29 +1457,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -1965,6 +1492,7 @@ 0 wxID_ANY + 0 0 @@ -1990,29 +1518,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -2071,29 +1576,6 @@ - - - - - - - - - - - - - - - - - - - - - - - @@ -2152,29 +1634,6 @@ - - - - - - - - - - - - - - - - - - - - - - - @@ -2210,6 +1669,7 @@ 0 wxID_ANY (c) 2011-2018 ShumaTech. All rights reserved. + 0 0 @@ -2235,29 +1695,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -2321,30 +1758,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -2403,29 +1816,6 @@ - - - - - - - - - - - - - - - - - - - - - - - @@ -2461,6 +1851,7 @@ 0 wxID_ANY This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + 0 0 @@ -2486,29 +1877,6 @@ 280 - - - - - - - - - - - - - - - - - - - - - - - @@ -2567,29 +1935,6 @@ - - - - - - - - - - - - - - - - - - - - - - - @@ -2608,14 +1953,6 @@ _sdbSizer protected - - - - - - - - @@ -2643,45 +1980,10 @@ Info + 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - _topBoxSizer @@ -2729,6 +2031,7 @@ 0 wxID_ANY Device: + 0 0 @@ -2754,29 +2057,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -2841,33 +2121,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -2914,6 +2167,7 @@ 0 wxID_ANY Version: + 0 0 @@ -2939,29 +2193,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -3026,33 +2257,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -3078,7 +2282,6 @@ wxVERTICAL 1 none - 5 wxEXPAND @@ -3128,6 +2331,7 @@ 0 wxID_ANY Pages: + 0 0 @@ -3153,29 +2357,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -3240,33 +2421,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -3302,6 +2456,7 @@ 0 wxID_ANY Page Size: + 0 0 @@ -3327,29 +2482,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -3414,33 +2546,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -3476,6 +2581,7 @@ 0 wxID_ANY Total Size: + 0 0 @@ -3501,29 +2607,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -3588,33 +2671,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -3650,6 +2706,7 @@ 0 wxID_ANY Planes: + 0 0 @@ -3675,29 +2732,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -3762,33 +2796,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -3807,7 +2814,6 @@ wxVERTICAL 1 none - 5 wxEXPAND @@ -3886,30 +2892,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -3974,30 +2956,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -4062,30 +3020,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -4150,30 +3084,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -4189,7 +3099,7 @@ none 5 - wxALIGN_CENTER_VERTICAL|wxALL + wxALIGN_CENTER_HORIZONTAL|wxALL 0 1 @@ -4220,6 +3130,7 @@ 0 wxID_ANY Lock Regions: + 0 0 @@ -4245,29 +3156,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -4332,33 +3220,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -4383,14 +3244,6 @@ _sdbSizer protected - - - - - - - - diff --git a/src/BossaForm.h b/src/BossaForm.h index c0752c5c..080a98ff 100644 --- a/src/BossaForm.h +++ b/src/BossaForm.h @@ -1,12 +1,11 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Mar 9 2018) +// C++ code generated with wxFormBuilder (version 3.10.1-d4a3afd) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! /////////////////////////////////////////////////////////////////////////// -#ifndef __BOSSAFORM_H__ -#define __BOSSAFORM_H__ +#pragma once #include #include @@ -40,10 +39,10 @@ /////////////////////////////////////////////////////////////////////////////// /// Class MainFrame /////////////////////////////////////////////////////////////////////////////// -class MainFrame : public wxFrame +class MainFrame : public wxFrame { private: - + protected: wxStaticBitmap* _bossaBitmap; wxStaticText* _titleText; @@ -57,42 +56,43 @@ class MainFrame : public wxFrame wxButton* _infoButton; wxButton* _exitButton; wxStatusBar* _statusBar; - + public: - + MainFrame( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("BOSSA - Kiibohd"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 550,400 ), long style = wxCAPTION|wxCLOSE_BOX|wxICONIZE|wxMINIMIZE|wxMINIMIZE_BOX|wxSYSTEM_MENU|wxTAB_TRAVERSAL ); - + ~MainFrame(); - + }; /////////////////////////////////////////////////////////////////////////////// /// Class ProgressDialog /////////////////////////////////////////////////////////////////////////////// -class ProgressDialog : public wxDialog +class ProgressDialog : public wxDialog { private: - + protected: wxStaticText* _infoStaticText; wxGauge* _statusGauge; wxStdDialogButtonSizer* _sdbSizer; wxButton* _sdbSizerCancel; - + public: - - ProgressDialog( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("Progress"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 300,150 ), long style = wxCAPTION ); + + ProgressDialog( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("Progress"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 300,150 ), long style = wxCAPTION ); + ~ProgressDialog(); - + }; /////////////////////////////////////////////////////////////////////////////// /// Class AboutDialog /////////////////////////////////////////////////////////////////////////////// -class AboutDialog : public wxDialog +class AboutDialog : public wxDialog { private: - + protected: wxStaticBitmap* _bossaBitmap; wxStaticText* _titleStaticText; @@ -108,21 +108,22 @@ class AboutDialog : public wxDialog wxStaticLine* m_staticline3; wxStdDialogButtonSizer* _sdbSizer; wxButton* _sdbSizerOK; - + public: - - AboutDialog( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("About BOSSA"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 300,-1 ), long style = wxDEFAULT_DIALOG_STYLE ); + + AboutDialog( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("About BOSSA"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 300,-1 ), long style = wxDEFAULT_DIALOG_STYLE ); + ~AboutDialog(); - + }; /////////////////////////////////////////////////////////////////////////////// /// Class InfoDialog /////////////////////////////////////////////////////////////////////////////// -class InfoDialog : public wxDialog +class InfoDialog : public wxDialog { private: - + protected: wxStaticText* _deviceStaticText; wxTextCtrl* _deviceTextCtrl; @@ -144,12 +145,12 @@ class InfoDialog : public wxDialog wxTextCtrl* _lockTextCtrl; wxStdDialogButtonSizer* _sdbSizer; wxButton* _sdbSizerOK; - + public: - - InfoDialog( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("Info"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE ); + + InfoDialog( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("Info"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE ); + ~InfoDialog(); - + }; -#endif //__BOSSAFORM_H__ diff --git a/src/BossaObserver.cpp b/src/BossaObserver.cpp new file mode 100644 index 00000000..e08b17b6 --- /dev/null +++ b/src/BossaObserver.cpp @@ -0,0 +1,46 @@ +#include +#include + +#include "BossaObserver.h" + +void +BossaObserver::onStatus(const char *message, ...) +{ + va_list ap; + + va_start(ap, message); + vprintf(message, ap); + va_end(ap); +} + +void +BossaObserver::onProgress(int num, int div) +{ + int ticks; + int bars = 30; + + ticks = num * bars / div; + + if (ticks == _lastTicks) + return; + + printf("\r["); + while (ticks-- > 0) + { + putchar('='); + bars--; + } + while (bars-- > 0) + { + putchar(' '); + } + printf("] %d%% (%d/%d pages)", num * 100 / div, num, div); + fflush(stdout); + + _lastTicks = 0; +} + +std::unique_ptr new_bossa_observer() +{ + return std::unique_ptr(new BossaObserver()); +} diff --git a/src/BossaObserver.h b/src/BossaObserver.h new file mode 100644 index 00000000..d7291876 --- /dev/null +++ b/src/BossaObserver.h @@ -0,0 +1,20 @@ +#ifndef _BOSSAOBSERVER_H +#define _BOSSAOBSERVER_H + +#include "Flasher.h" + +class BossaObserver : public FlasherObserver +{ +public: + BossaObserver() : _lastTicks(-1) {} + virtual ~BossaObserver() {} + + virtual void onStatus(const char *message, ...); + virtual void onProgress(int num, int div); +private: + int _lastTicks; +}; + +std::unique_ptr new_bossa_observer(); + +#endif // _BOSSAOBSERVER_H diff --git a/src/Device.cpp b/src/Device.cpp index 2a38ab6b..a02161ef 100644 --- a/src/Device.cpp +++ b/src/Device.cpp @@ -734,4 +734,7 @@ Device::reset() } } - +std::unique_ptr new_device(Samba& samba) +{ + return std::unique_ptr(new Device(samba)); +} diff --git a/src/Device.h b/src/Device.h index c16eb135..fca0bea7 100644 --- a/src/Device.h +++ b/src/Device.h @@ -101,5 +101,7 @@ class Device void readChipId(uint32_t& chipId, uint32_t& extChipId); }; +std::unique_ptr new_device(Samba& samba); + #endif // _DEVICE_H diff --git a/src/Flasher.cpp b/src/Flasher.cpp index bd3f04fb..b233b578 100644 --- a/src/Flasher.cpp +++ b/src/Flasher.cpp @@ -99,7 +99,7 @@ Flasher::write(const char* filename, uint32_t foffset) if (foffset % pageSize != 0 || foffset >= _flash->totalSize()) throw FlashOffsetError(); - + infile = fopen(filename, "rb"); if (!infile) throw FileOpenError(errno); @@ -108,7 +108,7 @@ Flasher::write(const char* filename, uint32_t foffset) { if (fseek(infile, 0, SEEK_END) != 0 || (fsize = ftell(infile)) < 0) throw FileIoError(errno); - + rewind(infile); numPages = (fsize + pageSize - 1) / pageSize; @@ -122,20 +122,20 @@ Flasher::write(const char* filename, uint32_t foffset) uint32_t offset = 0; uint32_t bufferSize = _samba.writeBufferSize(); std::vector buffer(bufferSize); - + while ((fbytes = fread(buffer.data(), 1, bufferSize, infile)) > 0) { _observer.onProgress(offset / pageSize, numPages); - + if (fbytes < bufferSize) { memset(buffer.data() + fbytes, 0, bufferSize - fbytes); fbytes = (fbytes + pageSize - 1) / pageSize * pageSize; } - + _flash->loadBuffer(buffer.data(), (uint16_t)fbytes); _flash->writeBuffer(foffset + offset, (uint32_t)fbytes); - offset += (uint32_t)fbytes; + offset += (uint32_t)fbytes; } } @@ -163,7 +163,7 @@ Flasher::write(const char* filename, uint32_t foffset) fclose(infile); throw; } - + fclose(infile); _observer.onProgress(numPages, numPages); } @@ -188,9 +188,9 @@ Flasher::verify(const char* filename, uint32_t& pageErrors, uint32_t& totalError if (foffset % pageSize != 0 || foffset >= _flash->totalSize()) throw FlashOffsetError(); - + pageOffset = foffset / pageSize; - + infile = fopen(filename, "rb"); if (!infile) throw FileOpenError(errno); @@ -199,7 +199,7 @@ Flasher::verify(const char* filename, uint32_t& pageErrors, uint32_t& totalError { if (fseek(infile, 0, SEEK_END) != 0 || (fsize = ftell(infile)) < 0) throw FileIoError(errno); - + rewind(infile); numPages = (fsize + pageSize - 1) / pageSize; @@ -211,7 +211,7 @@ Flasher::verify(const char* filename, uint32_t& pageErrors, uint32_t& totalError while ((fbytes = fread(bufferA.data(), 1, pageSize, infile)) > 0) { byteErrors = 0; - + _observer.onProgress(pageNum, numPages); if (_samba.canChecksumBuffer()) @@ -219,9 +219,9 @@ Flasher::verify(const char* filename, uint32_t& pageErrors, uint32_t& totalError uint16_t calcCrc = 0; for (uint32_t i = 0; i < fbytes; i++) calcCrc = _samba.checksumCalc(bufferA[i], calcCrc); - + flashCrc = _samba.checksumBuffer((pageOffset + pageNum) * pageSize, (uint32_t)fbytes); - + if (flashCrc != calcCrc) { _flash->readPage(pageOffset + pageNum, bufferB.data()); @@ -243,7 +243,7 @@ Flasher::verify(const char* filename, uint32_t& pageErrors, uint32_t& totalError byteErrors++; } } - + if (byteErrors != 0) { pageErrors++; @@ -260,11 +260,11 @@ Flasher::verify(const char* filename, uint32_t& pageErrors, uint32_t& totalError fclose(infile); throw; } - + fclose(infile); _observer.onProgress(numPages, numPages); - + if (pageErrors != 0) return false; @@ -284,7 +284,7 @@ Flasher::read(const char* filename, uint32_t fsize, uint32_t foffset) if (foffset % pageSize != 0 || foffset >= _flash->totalSize()) throw FlashOffsetError(); - + pageOffset = foffset / pageSize; if (fsize == 0) @@ -293,13 +293,13 @@ Flasher::read(const char* filename, uint32_t fsize, uint32_t foffset) numPages = (fsize + pageSize - 1) / pageSize; if (pageOffset + numPages > _flash->numPages()) throw FileSizeError(); - + outfile = fopen(filename, "wb"); if (!outfile) throw FileOpenError(errno); - + _observer.onStatus("Read %d bytes from flash\n", fsize); - + try { for (pageNum = 0; pageNum < numPages; pageNum++) @@ -320,14 +320,14 @@ Flasher::read(const char* filename, uint32_t fsize, uint32_t foffset) fclose(outfile); throw; } - + _observer.onProgress(numPages, numPages); - + fclose(outfile); } void -Flasher::lock(string& regionArg, bool enable) +Flasher::lock(const string& regionArg, bool enable) { if (regionArg.empty()) { @@ -381,3 +381,50 @@ Flasher::info(FlasherInfo& info) info.canChecksumBuffer = _samba.canChecksumBuffer(); info.lockRegions = _flash->getLockRegions(); } + +void +Flasher::setSecurity() +{ + _flash->setSecurity(); +} + +void +Flasher::setBod(bool enable) +{ + _flash->setBod(enable); +} + +void +Flasher::setBor(bool enable) +{ + _flash->setBor(enable); +} + +void +Flasher::setBootFlash(bool enable) +{ + _flash->setBootFlash(enable); +} + +void +Flasher::writeOptions() +{ + _flash->writeOptions(); +} + +void +Flasher::reset() +{ + _flash->ready(); + _device.reset(); +} + +std::unique_ptr new_flasher_info() +{ + return std::unique_ptr(new FlasherInfo()); +} + +std::unique_ptr new_flasher(Samba& samba, Device& device, FlasherObserver& observer) +{ + return std::unique_ptr(new Flasher(samba, device, observer)); +} diff --git a/src/Flasher.h b/src/Flasher.h index 4f5c0566..14ba61ae 100644 --- a/src/Flasher.h +++ b/src/Flasher.h @@ -3,7 +3,7 @@ // // Copyright (c) 2011-2018, ShumaTech // All rights reserved. -// +// // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // * Redistributions of source code must retain the above copyright @@ -14,7 +14,7 @@ // * Neither the name of the nor the // names of its contributors may be used to endorse or promote products // derived from this software without specific prior written permission. -// +// // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -50,7 +50,7 @@ class FlasherObserver public: FlasherObserver() {} virtual ~FlasherObserver() {} - + virtual void onStatus(const char *message, ...) = 0; virtual void onProgress(int num, int div) = 0; }; @@ -60,9 +60,9 @@ class FlasherInfo public: FlasherInfo() {} virtual ~FlasherInfo() {} - + void print(); - + std::string name; uint32_t chipId; uint32_t extChipId; @@ -72,40 +72,53 @@ class FlasherInfo uint32_t pageSize; uint32_t totalSize; uint32_t numPlanes; - + bool security; bool bootFlash; bool bod; bool bor; - + bool canBootFlash; bool canBod; bool canBor; bool canChipErase; bool canWriteBuffer; bool canChecksumBuffer; - + std::vector lockRegions; std::vector uniqueId; }; +std::unique_ptr new_flasher_info(); + class Flasher { public: - Flasher(Samba& samba, Device& device, FlasherObserver& observer) : _samba(samba), _flash(device.getFlash()), _observer(observer) {} + Flasher(Samba& samba, Device& device, FlasherObserver& observer) : _samba(samba), _flash(device.getFlash()), _device(device), _observer(observer) {} virtual ~Flasher() {} void erase(uint32_t foffset); void write(const char* filename, uint32_t foffset = 0); bool verify(const char* filename, uint32_t& pageErrors, uint32_t& totalErrors, uint32_t foffset = 0); void read(const char* filename, uint32_t fsize, uint32_t foffset = 0); - void lock(std::string& regionArg, bool enable); + void lock(const std::string& regionArg, bool enable); void info(FlasherInfo& info); + void setSecurity(); + void setBod(bool enable); + void setBor(bool enable); + void setBootFlash(bool enable); + + void writeOptions(); + void reset(); + private: Samba& _samba; Device::FlashPtr& _flash; + Device& _device; FlasherObserver& _observer; }; +std::unique_ptr new_flasher(Samba& samba, Device& device, FlasherObserver& observer); + #endif // _FLASHER_H diff --git a/src/LinuxPortFactory.cpp b/src/LinuxPortFactory.cpp index 80499bf9..85f6f224 100644 --- a/src/LinuxPortFactory.cpp +++ b/src/LinuxPortFactory.cpp @@ -3,7 +3,7 @@ // // Copyright (c) 2011-2018, ShumaTech // All rights reserved. -// +// // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // * Redistributions of source code must retain the above copyright @@ -14,7 +14,7 @@ // * Neither the name of the nor the // names of its contributors may be used to endorse or promote products // derived from this software without specific prior written permission. -// +// // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE diff --git a/src/LinuxPortFactory.h b/src/LinuxPortFactory.h index 50f60f95..18d4165e 100644 --- a/src/LinuxPortFactory.h +++ b/src/LinuxPortFactory.h @@ -3,7 +3,7 @@ // // Copyright (c) 2011-2018, ShumaTech // All rights reserved. -// +// // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // * Redistributions of source code must retain the above copyright @@ -14,7 +14,7 @@ // * Neither the name of the nor the // names of its contributors may be used to endorse or promote products // derived from this software without specific prior written permission. -// +// // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE diff --git a/src/PortFactory.cpp b/src/PortFactory.cpp new file mode 100644 index 00000000..aa1a8b87 --- /dev/null +++ b/src/PortFactory.cpp @@ -0,0 +1,14 @@ +#include "PortFactory.h" + +std::unique_ptr new_port_factory() { + return std::make_unique(); +} + +std::unique_ptr PortFactoryBase::create_port(const std::string& name, bool is_usb) { + return create(name, is_usb); +} + +const std::string &PortFactoryBase::default_name() { + port_name = def(); + return port_name; +} diff --git a/src/PortFactory.h b/src/PortFactory.h index 495b6852..2852a519 100644 --- a/src/PortFactory.h +++ b/src/PortFactory.h @@ -3,7 +3,7 @@ // // Copyright (c) 2011-2018, ShumaTech // All rights reserved. -// +// // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // * Redistributions of source code must retain the above copyright @@ -14,7 +14,7 @@ // * Neither the name of the nor the // names of its contributors may be used to endorse or promote products // derived from this software without specific prior written permission. -// +// // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -46,6 +46,12 @@ class PortFactoryBase virtual SerialPort::Ptr create(const std::string& name) = 0; virtual SerialPort::Ptr create(const std::string& name, bool isUsb) = 0; + + std::unique_ptr create_port(const std::string& name, bool is_usb); + const std::string &default_name(); + +private: + std::string port_name; }; #if defined(__WIN32__) || defined(_WIN64) @@ -65,4 +71,7 @@ typedef BSDPortFactory PortFactory; #error "Platform is not supported" #endif +std::unique_ptr new_port_factory(); + + #endif // _PORTFACTORY_H diff --git a/src/PosixSerialPort.cpp b/src/PosixSerialPort.cpp index 93c8dfb6..c6c9074b 100644 --- a/src/PosixSerialPort.cpp +++ b/src/PosixSerialPort.cpp @@ -3,7 +3,7 @@ // // Copyright (c) 2011-2018, ShumaTech // All rights reserved. -// +// // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // * Redistributions of source code must retain the above copyright @@ -14,7 +14,7 @@ // * Neither the name of the nor the // names of its contributors may be used to endorse or promote products // derived from this software without specific prior written permission. -// +// // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -62,8 +62,8 @@ PosixSerialPort::~PosixSerialPort() bool PosixSerialPort::open(int baud, int data, - SerialPort::Parity parity, - SerialPort::StopBit stop) + Parity parity, + StopBit stop) { struct termios options; speed_t speed; @@ -144,17 +144,17 @@ PosixSerialPort::open(int baud, switch (parity) { - case SerialPort::ParityNone: + case ParityNone: options.c_cflag &= ~PARENB; options.c_cflag &= ~PARODD; options.c_iflag &= ~(INPCK | ISTRIP); break; - case SerialPort::ParityOdd: + case ParityOdd: options.c_cflag |= PARENB; options.c_cflag |= PARODD; options.c_iflag |= (INPCK | ISTRIP); break; - case SerialPort::ParityEven: + case ParityEven: options.c_cflag |= PARENB; options.c_cflag &= ~PARODD; options.c_iflag |= (INPCK | ISTRIP); diff --git a/src/PosixSerialPort.h b/src/PosixSerialPort.h index a79fe889..2cf32caa 100644 --- a/src/PosixSerialPort.h +++ b/src/PosixSerialPort.h @@ -3,7 +3,7 @@ // // Copyright (c) 2011-2018, ShumaTech // All rights reserved. -// +// // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // * Redistributions of source code must retain the above copyright @@ -14,7 +14,7 @@ // * Neither the name of the nor the // names of its contributors may be used to endorse or promote products // derived from this software without specific prior written permission. -// +// // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -39,8 +39,8 @@ class PosixSerialPort : public SerialPort bool open(int baud = 115200, int data = 8, - SerialPort::Parity parity = SerialPort::ParityNone, - SerialPort::StopBit stop = SerialPort::StopBitOne); + Parity parity = ParityNone, + StopBit stop = StopBitOne); void close(); bool isUsb() { return _isUsb; }; diff --git a/src/Samba.cpp b/src/Samba.cpp index 89378759..8714fa85 100644 --- a/src/Samba.cpp +++ b/src/Samba.cpp @@ -550,8 +550,8 @@ Samba::go(uint32_t addr) _port->flush(); } -std::string -Samba::version() +const std::string +&Samba::version() { uint8_t cmd[256]; char* str; @@ -576,12 +576,12 @@ Samba::version() } str[pos] = '\0'; - std::string ver(str); + _version = str; if (_debug) - printf("%s()=%s\n", __FUNCTION__, ver.c_str()); + printf("%s()=%s\n", __FUNCTION__, _version.c_str()); - return ver; + return _version; } void @@ -613,7 +613,7 @@ Samba::writeBuffer(uint32_t src_addr, uint32_t dst_addr, uint32_t size) if (size > checksumBufferSize()) throw SambaError(); - + if (_debug) printf("%s(scr_addr=%#x, dst_addr=%#x, size=%#x)\n", __FUNCTION__, src_addr, dst_addr, size); @@ -647,7 +647,7 @@ Samba::checksumBuffer(uint32_t start_addr, uint32_t size) if (size > checksumBufferSize()) throw SambaError(); - + if (_debug) printf("%s(start_addr=%#x, size=%#x) = ", __FUNCTION__, start_addr, size); @@ -672,3 +672,7 @@ Samba::checksumBuffer(uint32_t start_addr, uint32_t size) return res; } +std::unique_ptr new_samba() { + return std::make_unique(); +} + diff --git a/src/Samba.h b/src/Samba.h index 84bea406..d1503c8e 100644 --- a/src/Samba.h +++ b/src/Samba.h @@ -66,7 +66,7 @@ class Samba void go(uint32_t addr); - std::string version(); + const std::string &version(); void chipId(uint32_t& chipId, uint32_t& extChipId); @@ -83,7 +83,7 @@ class Samba bool canWriteBuffer() { return _canWriteBuffer; } void writeBuffer(uint32_t src_addr, uint32_t dst_addr, uint32_t size); uint32_t writeBufferSize() { return 4096; } - + bool canChecksumBuffer() { return _canChecksumBuffer; } uint16_t checksumBuffer(uint32_t start_addr, uint32_t size); uint32_t checksumBufferSize() { return 4096; } @@ -97,6 +97,7 @@ class Samba bool _debug; bool _isUsb; SerialPort::Ptr _port; + std::string _version; bool init(); @@ -111,5 +112,7 @@ class Samba }; +std::unique_ptr new_samba(); + #endif // _SAMBA_H diff --git a/src/SerialPort.h b/src/SerialPort.h index 6ebbcc7b..9acd35b2 100644 --- a/src/SerialPort.h +++ b/src/SerialPort.h @@ -3,7 +3,7 @@ // // Copyright (c) 2011-2018, ShumaTech // All rights reserved. -// +// // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // * Redistributions of source code must retain the above copyright @@ -14,7 +14,7 @@ // * Neither the name of the nor the // names of its contributors may be used to endorse or promote products // derived from this software without specific prior written permission. -// +// // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -33,26 +33,26 @@ #include #include +enum Parity +{ + ParityNone, + ParityOdd, + ParityEven, +}; + +enum StopBit +{ + StopBitOne, + StopBitOneFive, + StopBitTwo, +}; + class SerialPort { public: SerialPort(const std::string& name) : _name(name) {} virtual ~SerialPort() {} - enum Parity - { - ParityNone, - ParityOdd, - ParityEven, - }; - - enum StopBit - { - StopBitOne, - StopBitOneFive, - StopBitTwo, - }; - virtual bool open(int baud = 115200, int data = 8, Parity parity = ParityNone, @@ -71,7 +71,7 @@ class SerialPort virtual void setDTR(bool dtr) = 0; virtual void setRTS(bool rts) = 0; - virtual std::string name() const { return _name; } + virtual const std::string &name() const { return _name; } typedef std::unique_ptr Ptr; diff --git a/src/WinPortFactory.cpp b/src/WinPortFactory.cpp index 978eb7c0..2ec26322 100644 --- a/src/WinPortFactory.cpp +++ b/src/WinPortFactory.cpp @@ -3,7 +3,7 @@ // // Copyright (c) 2011-2018, ShumaTech // All rights reserved. -// +// // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // * Redistributions of source code must retain the above copyright @@ -14,7 +14,7 @@ // * Neither the name of the nor the // names of its contributors may be used to endorse or promote products // derived from this software without specific prior written permission. -// +// // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE diff --git a/src/WinPortFactory.h b/src/WinPortFactory.h index 912d065f..43f1fff7 100644 --- a/src/WinPortFactory.h +++ b/src/WinPortFactory.h @@ -3,7 +3,7 @@ // // Copyright (c) 2011-2018, ShumaTech // All rights reserved. -// +// // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // * Redistributions of source code must retain the above copyright @@ -14,7 +14,7 @@ // * Neither the name of the nor the // names of its contributors may be used to endorse or promote products // derived from this software without specific prior written permission. -// +// // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE diff --git a/src/WinSerialPort.cpp b/src/WinSerialPort.cpp index ba00de36..a839ded1 100644 --- a/src/WinSerialPort.cpp +++ b/src/WinSerialPort.cpp @@ -3,7 +3,7 @@ // // Copyright (c) 2011-2018, ShumaTech // All rights reserved. -// +// // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // * Redistributions of source code must retain the above copyright @@ -14,7 +14,7 @@ // * Neither the name of the nor the // names of its contributors may be used to endorse or promote products // derived from this software without specific prior written permission. -// +// // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -70,7 +70,7 @@ printLastError() #endif bool -WinSerialPort::open(int baud, int data, SerialPort::Parity parity, SerialPort::StopBit stop) +WinSerialPort::open(int baud, int data, Parity parity, StopBit stop) { DCB dcbSerialParams; diff --git a/src/WinSerialPort.h b/src/WinSerialPort.h index 2627ef07..2485823f 100644 --- a/src/WinSerialPort.h +++ b/src/WinSerialPort.h @@ -3,7 +3,7 @@ // // Copyright (c) 2011-2018, ShumaTech // All rights reserved. -// +// // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // * Redistributions of source code must retain the above copyright @@ -14,7 +14,7 @@ // * Neither the name of the nor the // names of its contributors may be used to endorse or promote products // derived from this software without specific prior written permission. -// +// // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -42,8 +42,8 @@ class WinSerialPort : public SerialPort bool open(int baud = 115200, int data = 8, - SerialPort::Parity parity = SerialPort::ParityNone, - SerialPort::StopBit stop = SerialPort::StopBitOne); + Parity parity = ParityNone, + StopBit stop = StopBitOne); void close(); bool isUsb() { return _isUsb; }; diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 00000000..59b1a882 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,121 @@ +#[cxx::bridge] +pub mod bossa { + #[repr(u32)] + enum Parity { + ParityNone, + ParityOdd, + ParityEven, + } + + #[repr(u32)] + enum StopBit { + StopBitOne, + StopBitOneFive, + StopBitTwo, + } + + unsafe extern "C++" { + include!("bossa/src/BossaObserver.h"); + include!("bossa/src/Device.h"); + include!("bossa/src/Flash.h"); + include!("bossa/src/Flasher.h"); + include!("bossa/src/PortFactory.h"); + include!("bossa/src/Samba.h"); + include!("bossa/src/SerialPort.h"); + + /* SerialPort */ + type SerialPort; + + type Parity; + type StopBit; + + fn open( + self: Pin<&mut SerialPort>, + baud: i32, + data: i32, + parity: Parity, + stop: StopBit, + ) -> bool; + fn close(self: Pin<&mut SerialPort>); + fn setDTR(self: Pin<&mut SerialPort>, dtr: bool); + fn setRTS(self: Pin<&mut SerialPort>, rts: bool); + + /* PortFactory */ + type PortFactory; + + fn new_port_factory() -> UniquePtr; + + fn default_name(self: Pin<&mut PortFactory>) -> &CxxString; + + fn create_port( + self: Pin<&mut PortFactory>, + name: &CxxString, + is_usb: bool, + ) -> UniquePtr; + + /* Device */ + type Device; + + fn new_device(samba: Pin<&mut Samba>) -> UniquePtr; + + fn create(self: Pin<&mut Device>); + fn getFlash(self: Pin<&mut Device>) -> &UniquePtr; + + /* FlasherObserver */ + type FlasherObserver; + + fn new_bossa_observer() -> UniquePtr; + + /* Flash */ + type Flash; + + /* Flasher */ + type Flasher; + + fn new_flasher( + samba: Pin<&mut Samba>, + device: Pin<&mut Device>, + observer: Pin<&mut FlasherObserver>, + ) -> UniquePtr; + + fn erase(self: Pin<&mut Flasher>, foffset: u32); + /// # Safety + unsafe fn write(self: Pin<&mut Flasher>, filename: *const c_char, foffset: u32); + /// # Safety + unsafe fn verify( + self: Pin<&mut Flasher>, + filename: *const c_char, + pageErrors: &mut u32, + totalErrors: &mut u32, + foffset: u32, + ) -> bool; + /// # Safety + unsafe fn read(self: Pin<&mut Flasher>, filename: *const c_char, fsize: u32, foffset: u32); + fn lock(self: Pin<&mut Flasher>, regionArg: &CxxString, enable: bool); + fn info(self: Pin<&mut Flasher>, info: Pin<&mut FlasherInfo>); + + fn setBod(self: Pin<&mut Flasher>, enable: bool); + fn setBootFlash(self: Pin<&mut Flasher>, enable: bool); + fn setBor(self: Pin<&mut Flasher>, enable: bool); + fn setSecurity(self: Pin<&mut Flasher>); + + fn writeOptions(self: Pin<&mut Flasher>); + fn reset(self: Pin<&mut Flasher>); + + /* FlasherInfo */ + type FlasherInfo; + + fn print(self: Pin<&mut FlasherInfo>); + + fn new_flasher_info() -> UniquePtr; + + /* Samba */ + type Samba; + + pub fn new_samba() -> UniquePtr; + + fn connect(self: Pin<&mut Samba>, port: UniquePtr, bps: i32) -> bool; + + fn setDebug(self: Pin<&mut Samba>, debug: bool); + } +}