mirror of
https://github.com/Polprzewodnikowy/SummerCart64.git
synced 2025-04-14 21:51:27 +02:00
[SC64][SW] Added warning about unknown variant of IPL3
This commit is contained in:
parent
b520f9ace8
commit
e4c3f34fb0
@ -501,7 +501,16 @@ fn handle_upload_command(connection: Connection, args: &UploadArgs) -> Result<()
|
||||
sc64.set_tv_type(tv_type)?;
|
||||
}
|
||||
|
||||
sc64.calculate_cic_parameters(args.cic_seed)?;
|
||||
let (seed, checksum, matched) = sc64.calculate_cic_parameters(args.cic_seed)?;
|
||||
if !matched {
|
||||
println!(
|
||||
"{}",
|
||||
"Warning: IPL3 in the ROM does not match any known variant. It may fail to boot."
|
||||
.bright_yellow(),
|
||||
);
|
||||
println!("IPL3 has been automatically signed with the parameters listed below:");
|
||||
println!("[seed = 0x{seed:02X} | checksum = 0x{checksum:012X}]");
|
||||
}
|
||||
|
||||
if args.reboot && !sc64.try_notify_via_aux(sc64::AuxMessage::Reboot)? {
|
||||
println!(
|
||||
@ -616,7 +625,16 @@ fn handle_64dd_command(connection: Connection, args: &_64DDArgs) -> Result<(), s
|
||||
sc64.set_tv_type(tv_type)?;
|
||||
}
|
||||
|
||||
sc64.calculate_cic_parameters(args.cic_seed)?;
|
||||
let (seed, checksum, matched) = sc64.calculate_cic_parameters(args.cic_seed)?;
|
||||
if !matched {
|
||||
println!(
|
||||
"{}",
|
||||
"Warning: IPL3 in the ROM does not match any known variant. It may fail to boot."
|
||||
.bright_yellow(),
|
||||
);
|
||||
println!("IPL3 has been automatically signed with the parameters listed below:");
|
||||
println!("[seed = 0x{seed:02X} | checksum = 0x{checksum:012X}]");
|
||||
}
|
||||
|
||||
if args.disk.len() == 0 {
|
||||
let dd_mode = sc64::DdMode::DdIpl;
|
||||
|
@ -110,35 +110,35 @@ fn calculate_ipl3_checksum(ipl3: &[u8], seed: u8) -> Result<u64, Error> {
|
||||
Ok(checksum)
|
||||
}
|
||||
|
||||
pub fn sign_ipl3(ipl3: &[u8], custom_seed: Option<u8>) -> Result<(u8, u64), Error> {
|
||||
pub fn sign_ipl3(ipl3: &[u8], custom_seed: Option<u8>) -> Result<(u8, u64, bool), Error> {
|
||||
if let Some(seed) = custom_seed {
|
||||
Ok((seed, calculate_ipl3_checksum(ipl3, seed)?))
|
||||
} else {
|
||||
let known_seed_checksum_pairs = [
|
||||
(0xDD, 0x083C6C77E0B1u64), // 5167
|
||||
(0x3F, 0x45CC73EE317Au64), // 6101
|
||||
(0x3F, 0x44160EC5D9AFu64), // 7102
|
||||
(0x3F, 0xA536C0F1D859u64), // 6102/7102
|
||||
(0x78, 0x586FD4709867u64), // 6103/7103
|
||||
(0x91, 0x8618A45BC2D3u64), // 6105/7105
|
||||
(0x85, 0x2BBAD4E6EB74u64), // 6106/7106
|
||||
(0xDD, 0x6EE8D9E84970u64), // NDXJ0
|
||||
(0xDD, 0x6C216495C8B9u64), // NDDJ0
|
||||
(0xDD, 0xE27F43BA93ACu64), // NDDJ1
|
||||
(0xDD, 0x32B294E2AB90u64), // NDDJ2
|
||||
(0xDE, 0x05BA2EF0A5F1u64), // NDDE0
|
||||
];
|
||||
|
||||
for (seed, checksum) in known_seed_checksum_pairs {
|
||||
if calculate_ipl3_checksum(ipl3, seed)? == checksum {
|
||||
return Ok((seed, checksum));
|
||||
}
|
||||
}
|
||||
|
||||
// Unknown IPL3 detected, sign it with arbitrary seed (CIC6102/7101 value is used here)
|
||||
const DEFAULT_SEED: u8 = 0x3F;
|
||||
let checksum = calculate_ipl3_checksum(ipl3, DEFAULT_SEED)?;
|
||||
|
||||
Ok((DEFAULT_SEED, checksum))
|
||||
return Ok((seed, calculate_ipl3_checksum(ipl3, seed)?, true));
|
||||
}
|
||||
|
||||
let known_seed_checksum_pairs = [
|
||||
(0xDD, 0x083C6C77E0B1u64), // 5167
|
||||
(0x3F, 0x45CC73EE317Au64), // 6101
|
||||
(0x3F, 0x44160EC5D9AFu64), // 7102
|
||||
(0x3F, 0xA536C0F1D859u64), // 6102/7102
|
||||
(0x78, 0x586FD4709867u64), // 6103/7103
|
||||
(0x91, 0x8618A45BC2D3u64), // 6105/7105
|
||||
(0x85, 0x2BBAD4E6EB74u64), // 6106/7106
|
||||
(0xDD, 0x6EE8D9E84970u64), // NDXJ0
|
||||
(0xDD, 0x6C216495C8B9u64), // NDDJ0
|
||||
(0xDD, 0xE27F43BA93ACu64), // NDDJ1
|
||||
(0xDD, 0x32B294E2AB90u64), // NDDJ2
|
||||
(0xDE, 0x05BA2EF0A5F1u64), // NDDE0
|
||||
];
|
||||
|
||||
for (seed, checksum) in known_seed_checksum_pairs {
|
||||
if calculate_ipl3_checksum(ipl3, seed)? == checksum {
|
||||
return Ok((seed, checksum, true));
|
||||
}
|
||||
}
|
||||
|
||||
// Unknown IPL3 detected, sign it with arbitrary seed (CIC6102/7101 value is used here)
|
||||
const DEFAULT_SEED: u8 = 0x3F;
|
||||
let checksum = calculate_ipl3_checksum(ipl3, DEFAULT_SEED)?;
|
||||
|
||||
Ok((DEFAULT_SEED, checksum, false))
|
||||
}
|
||||
|
@ -488,7 +488,10 @@ impl SC64 {
|
||||
self.memory_read_chunked(writer, address, length)
|
||||
}
|
||||
|
||||
pub fn calculate_cic_parameters(&mut self, custom_seed: Option<u8>) -> Result<(), Error> {
|
||||
pub fn calculate_cic_parameters(
|
||||
&mut self,
|
||||
custom_seed: Option<u8>,
|
||||
) -> Result<(u8, u64, bool), Error> {
|
||||
let (address, cic_seed, boot_seed) = match get_config!(self, BootMode)? {
|
||||
BootMode::Menu => (BOOTLOADER_ADDRESS, None, None),
|
||||
BootMode::Rom => (BOOTLOADER_ADDRESS, None, custom_seed),
|
||||
@ -497,12 +500,12 @@ impl SC64 {
|
||||
BootMode::DirectDdIpl => (DDIPL_ADDRESS, custom_seed, None),
|
||||
};
|
||||
let ipl3 = self.command_memory_read(address + IPL3_OFFSET, IPL3_LENGTH)?;
|
||||
let (seed, checksum) = sign_ipl3(&ipl3, cic_seed)?;
|
||||
let (seed, checksum, matched) = sign_ipl3(&ipl3, cic_seed)?;
|
||||
self.command_cic_params_set(false, seed, checksum)?;
|
||||
if let Some(seed) = boot_seed {
|
||||
self.command_config_set(Config::CicSeed(CicSeed::Seed(seed)))?;
|
||||
}
|
||||
Ok(())
|
||||
Ok((seed, checksum, matched))
|
||||
}
|
||||
|
||||
pub fn set_boot_mode(&mut self, boot_mode: BootMode) -> Result<(), Error> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user