Skip to content

Commit

Permalink
Initial changes to split bestool
Browse files Browse the repository at this point in the history
- Change into a workspace.
- Create `beslib` - TODO: Move logic from `oldbestool` here.
- Begin creating logical structure for `bestool` - a `beslib` frontend.

Signed-off-by: Dom Rodriguez <[email protected]>
  • Loading branch information
shymega committed Feb 18, 2024
1 parent 13c15ff commit 27011eb
Show file tree
Hide file tree
Showing 8 changed files with 720 additions and 0 deletions.
465 changes: 465 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[workspace]
resolver = "2"
members = [
"src/beslib",
"src/bestool",
]

[workspace.package]
authors = ["Ben V. Brown <>", "Dom Rodriguez <[email protected]>"]
edition = "2021"
homepage = "https://github.com/Ralim/bestool"
readme = "/README.md"
repository = "https://github.com/Ralim/bestool.git"
rust-version = "1.67.0"
version = "0.3.0"

[workspace.dependencies]
anyhow = "1.0.79"
clap = { version = "4.5.1", features = ["derive"] }
crc = "3.0.1"
serde = { version = "1.0.196", features = ["derive"] }
serde_json = "1.0.113"
serialport = "4.3.0"
thiserror = "1.0"
tracing = "0.1.40"
tracing-subscriber = "0.3.18"
16 changes: 16 additions & 0 deletions src/beslib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
authors = { workspace = true }
description = "Support library for `bestool`; a command-line utility for BES2300 chips."
edition = { workspace = true }
homepage = { workspace = true }
# license = { workspace = true } # TODO: Specify license with REUSE.
name = "beslib"
repository = { workspace = true }
rust-version = { workspace = true }
version = { workspace = true }

[dependencies]
anyhow = { workspace = true }
crc = { workspace = true }
serialport = { workspace = true }
thiserror = { workspace = true }
127 changes: 127 additions & 0 deletions src/beslib/src/boot/enums.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#![allow(non_camel_case_types)]

#[derive(Debug, Default, PartialEq, Eq)]
pub enum MsgTypeKind {
TYPE_SYS = 0x00,
TYPE_READ = 0x01,
TYPE_WRITE = 0x02,
TYPE_BULK_READ = 0x03,
TYPE_EXT_WRITE = 0x04,
TYPE_BULK_WRITE_START = 0x05,
TYPE_BULK_WRITE_DATA = 0x06,
TYPE_NOTIF = 0x10,
TYPE_SYNC = 0x50,
TYPE_SIG_INFO = 0x51,
TYPE_SIG = 0x52,
TYPE_CODE_INFO = 0x53,
TYPE_CODE = 0x54,
TYPE_RUN = 0x55,
TYPE_SECTOR_SIZE = 0x60,
TYPE_ERASE_BURN_START = 0x61,
TYPE_ERASE_BURN_DATA = 0x62,
TYPE_OBSOLETED_63 = 0x63,
TYPE_OBSOLETED_64 = 0x64,
TYPE_FLASH_CMD = 0x65,
TYPE_GET_SECTOR_INFO = 0x66,
TYPE_SEC_REG_ERASE_BURN_START = 0x67,
TYPE_SEC_REG_ERASE_BURN_DATA = 0x68,

// Extended types
TYPE_PROD_TEST = 0x81,
TYPE_RUNTIME_CMD = 0x82,
TYPE_BT_CALIB_CMD = 0x83,
TYPE_PROTO_EL = 0xA0,

TYPE_INVALID = 0xFF,

#[default]
Unknown,
}

#[derive(Debug, Default, PartialEq, Eq)]
pub enum SysCmdKind {
SYS_CMD_REBOOT = 0xF1,
SYS_CMD_SHUTDOWN = 0xF2,
SYS_CMD_FLASH_BOOT = 0xF3,
SYS_CMD_SET_BOOTMODE = 0xE1,
SYS_CMD_CLR_BOOTMODE = 0xE2,
SYS_CMD_GET_BOOTMODE = 0xE3,
SYS_CMD_SET_DLD_RATE = 0xD1,

#[default]
Unknown,
}

#[derive(Debug, Default, PartialEq, Eq)]
pub enum ErrCodeKind {
ERR_NONE = 0x00,
ERR_LEN = 0x01,
ERR_CHECKSUM = 0x02,
ERR_NOT_SYNC = 0x03,
ERR_NOT_SEC = 0x04,
ERR_SYNC_WORD = 0x05,
ERR_SYS_CMD = 0x06,
ERR_DATA_ADDR = 0x07,
ERR_DATA_LEN = 0x08,
ERR_ACCESS_RIGHT = 0x09,

ERR_TYPE_INVALID = 0x0F,

ERR_BOOT_OK = 0x10,
ERR_BOOT_MAGIC = 0x11,
ERR_BOOT_SEC = 0x12,
ERR_BOOT_HASH_TYPE = 0x13,
ERR_BOOT_KEY_TYPE = 0x14,
ERR_BOOT_KEY_LEN = 0x15,
ERR_BOOT_SIG_LEN = 0x16,
ERR_BOOT_SIG = 0x17,
ERR_BOOT_CRC = 0x18,
ERR_BOOT_LEN = 0x19,
ERR_SIG_CODE_SIZE = 0x1A,
ERR_SIG_SIG_LEN = 0x1B,
ERR_SIG_INFO_MISSING = 0x1C,
ERR_BOOT_KEY_ID = 0x1D,
ERR_BOOT_HASH = 0x1E,

ERR_CODE_OK = 0x20,
ERR_BOOT_MISSING = 0x21,
ERR_CODE_SIZE_SIG = 0x22,
ERR_CODE_ADDR_SIZE = 0x23,
ERR_CODE_INFO_MISSING = 0x24,
ERR_CODE_CRC = 0x25,
ERR_CODE_SIG = 0x26,

ERR_CODE_MISSING = 0x31,
ERR_VERSION = 0x32,

ERR_BURN_OK = 0x60,
ERR_SECTOR_SIZE = 0x61,
ERR_SECTOR_SEQ_OVERFLOW = 0x62,
ERR_BURN_INFO_MISSING = 0x63,
ERR_SECTOR_DATA_LEN = 0x64,
ERR_SECTOR_DATA_CRC = 0x65,
ERR_SECTOR_SEQ = 0x66,
ERR_ERASE_FLSH = 0x67,
ERR_BURN_FLSH = 0x68,
ERR_VERIFY_FLSH = 0x69,
ERR_FLASH_CMD = 0x6A,

ERR_TYPE_MISMATCHED = 0xE1,
ERR_SEQ_MISMATCHED = 0xE2,
ERR_BUF_TOO_SMALL = 0xE3,

ERR_INTERNAL = 0xFF,

#[default]
Unknown,
}

#[derive(Debug, Default, PartialEq, Eq)]
pub enum ParseState {
PARSE_HEADER,
PARSE_DATA,
PARSE_EXTRA,

#[default]
Unknown,
}
9 changes: 9 additions & 0 deletions src/beslib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pub mod boot {
pub mod enums;
pub mod consts {
pub const BOOT_MAGIC_NUMBER: u32 = 0xBE57EC1C;
pub const BOOT_HASH_TYPE_MD5: u8 = 1;
}
pub const MAX_READ_DATA_LEN: u16 = 16;
pub const MAX_WRITE_DATA_LEN: u16 = 16;
}
18 changes: 18 additions & 0 deletions src/bestool/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
authors = { workspace = true }
description = "Command-line utility for BES2300 chips."
edition = { workspace = true }
homepage = { workspace = true }
# license = { workspace = true } # TODO: Specify license with REUSE.
name = "bestool"
repository = { workspace = true }
rust-version = { workspace = true }
version = { workspace = true }

[dependencies]
anyhow = { workspace = true }
beslib = { path = "../beslib" }
clap = { workspace = true }
crc = { workspace = true }
serialport = { workspace = true }
thiserror = { workspace = true }
20 changes: 20 additions & 0 deletions src/bestool/src/command/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use clap::Subcommand;
use anyhow::Result;

#[derive(Subcommand)]
#[command(infer_subcommands = true)]
pub(crate) enum BestoolCmd {
Flash,
Read,
SerialMonitor,
}

impl BestoolCmd {
pub(crate) fn run(self) -> Result<()> {
match self {
Self::Flash => unimplemented!(),
Self::Read => unimplemented!(),
Self::SerialMonitor => unimplemented!(),
}
}
}
39 changes: 39 additions & 0 deletions src/bestool/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#![warn(clippy::pedantic, clippy::nursery)]

use clap::Parser;
mod command;
use anyhow::Result;
use command::BestoolCmd;

pub(crate) const VER: &'static str = env!("CARGO_PKG_VERSION");

static HELP_TEMPLATE: &'static str = "\
{before-help}{name} {version}
{author}
{about}
{usage-heading}
{usage}
{all-args}{after-help}";

#[derive(Parser)]
#[command(
author = "Ben V. Brown <>",
version = VER,
help_template = HELP_TEMPLATE,
)]
struct Bestool {
#[command(subcommand)]
bestool: BestoolCmd,
}

impl Bestool {
fn run(self) -> Result<()> {
self.bestool.run()
}
}

fn main() -> Result<()> {
Ok(Bestool::parse().run()?)
}

0 comments on commit 27011eb

Please sign in to comment.