Skip to content

Commit

Permalink
warn when console is on
Browse files Browse the repository at this point in the history
  • Loading branch information
Polprzewodnikowy committed Sep 28, 2024
1 parent 8ba2f95 commit 6dbd773
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
17 changes: 17 additions & 0 deletions sw/deployer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,23 @@ fn handle_sd_command(connection: Connection, command: &SDCommands) -> Result<(),
}
}

if sc64.is_console_powered_on()? {
println!(
"{}\n{}\n{}",
"========== [WARNING] ==========".bold().bright_yellow(),
"The console is powered on. To avoid potential data corruption it's strongly"
.bright_yellow(),
"recommended to access the SD card only when the console is powered off."
.bright_yellow()
);
let answer = prompt(format!("{}", "Continue anyways? [y/N] ".bold()));
if answer.to_ascii_lowercase() != "y" {
sc64.deinit_sd_card()?;
println!("{}", "SD card access aborted".red());
return Ok(());
}
}

sc64.reset_state()?;

sc64::ff::run(sc64, |ff| {
Expand Down
12 changes: 10 additions & 2 deletions sw/deployer/src/sc64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub use self::{
link::list_local_devices,
server::ServerEvent,
types::{
AuxMessage, BootMode, ButtonMode, ButtonState, CicSeed, DataPacket, DdDiskState,
AuxMessage, BootMode, ButtonMode, ButtonState, CicSeed, CicStep, DataPacket, DdDiskState,
DdDriveType, DdMode, DebugPacket, DiagnosticData, DiskPacket, DiskPacketKind,
FpgaDebugData, ISViewer, MemoryTestPattern, MemoryTestPatternResult, SaveType,
SaveWriteback, SdCardInfo, SdCardOpPacket, SdCardResult, SdCardStatus, SpeedTestDirection,
Expand Down Expand Up @@ -98,7 +98,7 @@ const SRAM_1M_LENGTH: usize = 128 * 1024;

const BOOTLOADER_ADDRESS: u32 = 0x04E0_0000;

const SD_CARD_BUFFER_ADDRESS: u32 = 0x03BA_0000; // Arbitrary offset in SDRAM memory
const SD_CARD_BUFFER_ADDRESS: u32 = 0x03FE_0000; // Arbitrary offset in SDRAM memory
const SD_CARD_BUFFER_LENGTH: usize = 128 * 1024; // Arbitrary length in SDRAM memory

pub const SD_CARD_SECTOR_SIZE: usize = 512;
Expand Down Expand Up @@ -767,6 +767,14 @@ impl SC64 {
self.command_state_reset()
}

pub fn is_console_powered_on(&mut self) -> Result<bool, Error> {
let debug_data = self.command_fpga_debug_data_get()?;
Ok(match debug_data.cic_step {
CicStep::Unavailable | CicStep::PowerOff => false,
_ => true,
})
}

pub fn backup_firmware(&mut self) -> Result<Vec<u8>, Error> {
self.command_state_reset()?;
let (status, length) = self.command_firmware_backup(FIRMWARE_ADDRESS_SDRAM)?;
Expand Down

0 comments on commit 6dbd773

Please sign in to comment.