Skip to content

Commit

Permalink
reworked reboot into an arg, setup defaults for known supported bootl…
Browse files Browse the repository at this point in the history
…oaders, added a compatibality section to readme
  • Loading branch information
carlossless committed Mar 9, 2024
1 parent 02b9862 commit 23b364c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ sinowealth-kb-tool write \
| Royal Kludge RK68 BT Dual | cfc8661da8c9d7e351b36c0a763426aa | SH68F90? | BYK901 |||
| Royal Kludge RK68 ISO Return || SH68F90? | BYK916 |||
| [Royal Kludge RK71](http://en.rkgaming.com/product/12/) | cfc8661da8c9d7e351b36c0a763426aa | SH68F90? ||||
| [Royal Kludge RK84](http://en.rkgaming.com/product/16/) | 7658c72d2cdc04ab66f1216a206f6913 | SH68F90? | BYK916 |||
| [Royal Kludge RK84](http://en.rkgaming.com/product/16/) | cfc8661da8c9d7e351b36c0a763426aa | SH68F90? | BYK916 |||
| Terport TR95 | 2d169670eae0d36eae8188562c1f66e8 | SH68F90A | BYK916 |||
| Weikav Sugar65 | 2d169670eae0d36eae8188562c1f66e8 | SH68F90 | SH68F90S |||
| Xinmeng K916 | cfc8661da8c9d7e351b36c0a763426aa | SH68F90 ||||
Expand All @@ -101,6 +101,18 @@ SUBSYSTEMS=="usb", ATTRS{idVendor}=="0603", ATTRS{idProduct}=="1020", MODE="0660

Make sure your user is part of the `plugdev` group.

### macOS

## Platform Support

| Bootloader | Windows | macOS | Linux |
| -------------------------------- | ------- | ----- | ----- |
| 3e0ebd0c440af5236d7ff8872343f85d | true | true | true |
| cfc8661da8c9d7e351b36c0a763426aa | true | false | true |
| 2d169670eae0d36eae8188562c1f66e8 | check | check | check |
| e57490acebcaabfcff84a0ff013955d9 | check | check | check |
| 13df4ce2933f9654ffef80d6a3c27199 | check | check | check |

## Acknowledgments

Thanks to [@gashtaan](https://github.com/gashtaan) for analyzing and explaining the inner workings of the ISP bootloaders. Without his help, this tool wouldn't be here!
9 changes: 6 additions & 3 deletions src/isp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const CMD_ENABLE_FIRMWARE: u8 = 0x55;
const CMD_INIT_READ: u8 = 0x52;
const CMD_INIT_WRITE: u8 = 0x57;
const CMD_ERASE: u8 = 0x45;

const CMD_REBOOT: u8 = 0x5a;

const XFER_READ_PAGE: u8 = 0x72;
Expand Down Expand Up @@ -293,7 +292,9 @@ impl ISPDevice {
ReadType::Full => self.read(0, self.part.firmware_size + self.part.bootloader_size)?,
};

self.reboot()?;
if self.part.reboot {
self.reboot()?;
}

return Ok(firmware);
}
Expand All @@ -315,7 +316,9 @@ impl ISPDevice {

self.enable_firmware()?;

self.reboot()?;
if self.part.reboot {
self.reboot()?;
}

Ok(())
}
Expand Down
7 changes: 6 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
process::ExitCode,
};

use clap::{arg, ArgMatches, Command};
use clap::{arg, value_parser, ArgMatches, Command};
use clap_num::maybe_hex;
use log::{error, info};
use simple_logger::SimpleLogger;
Expand Down Expand Up @@ -183,6 +183,7 @@ impl PartCommand for Command {
.arg(arg!(--isp_usage_page <PAGE>).value_parser(maybe_hex::<u16>))
.arg(arg!(--isp_usage <USAGE>).value_parser(maybe_hex::<u16>))
.arg(arg!(--isp_index <INDEX>).value_parser(maybe_hex::<usize>))
.arg(arg!(--reboot <BOOL>).value_parser(value_parser!(bool)))
}
}

Expand All @@ -203,6 +204,7 @@ fn get_part_from_matches(sub_matches: &ArgMatches) -> Part {
let isp_usage_page = sub_matches.get_one::<u16>("isp_usage_page");
let isp_usage = sub_matches.get_one::<u16>("isp_usage");
let isp_index = sub_matches.get_one::<usize>("isp_index");
let reboot = sub_matches.get_one::<bool>("reboot");

if let Some(firmware_size) = firmware_size {
part.firmware_size = *firmware_size;
Expand Down Expand Up @@ -231,5 +233,8 @@ fn get_part_from_matches(sub_matches: &ArgMatches) -> Part {
if let Some(isp_index) = isp_index {
part.isp_index = *isp_index;
}
if let Some(reboot) = reboot {
part.reboot = *reboot;
}
return part;
}
8 changes: 8 additions & 0 deletions src/part.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pub struct Part {
pub isp_usage: u16,
/// Index of matching (usage_page && usage) collection at which the ISP report appears in.
pub isp_index: usize,

pub reboot: bool,
}

pub const PART_BASE_DEFAULT: Part = Part {
Expand All @@ -32,6 +34,8 @@ pub const PART_BASE_DEFAULT: Part = Part {
isp_usage_page: 0xff00,
isp_usage: 0x0001,
isp_index: 0,

reboot: false,
};

pub const PART_BASE_SH68F90: Part = Part {
Expand Down Expand Up @@ -118,24 +122,28 @@ pub const PART_ROYALKLUDGE_RK68_ISO_RETURN: Part = Part {
pub const PART_ROYALKLUDGE_RK68_BT_DUAL: Part = Part {
vendor_id: 0x258a,
product_id: 0x008b,
reboot: true,
..PART_BASE_SH68F90
};

pub const PART_ROYALKLUDGE_RK71: Part = Part {
vendor_id: 0x258a,
product_id: 0x00ea,
reboot: true,
..PART_BASE_SH68F90
};

pub const PART_ROYALKLUDGE_RK84_ISO_RETURN: Part = Part {
vendor_id: 0x258a,
product_id: 0x00f4,
reboot: true,
..PART_BASE_SH68F90
};

pub const PART_ROYALKLUDGE_RK100: Part = Part {
vendor_id: 0x258a,
product_id: 0x0056,
reboot: true,
..PART_BASE_SH68F90
};

Expand Down

0 comments on commit 23b364c

Please sign in to comment.