Skip to content

Commit

Permalink
add more P04_256k OSIDs. Use SI standard data sizes in more places
Browse files Browse the repository at this point in the history
  • Loading branch information
antus committed Jul 30, 2024
1 parent a30b01e commit 6d6e362
Show file tree
Hide file tree
Showing 6 changed files with 274 additions and 49 deletions.
4 changes: 2 additions & 2 deletions Apps/PcmLibrary/CKernelReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public async Task<Response<Stream>> ReadContents(CancellationToken cancellationT
null);
}

logger.AddUserMessage("Loader uploaded to PCM succesfully.");
logger.AddUserMessage("Loader uploaded to PCM successfully.");
}

// execute read kernel
Expand All @@ -117,7 +117,7 @@ public async Task<Response<Stream>> ReadContents(CancellationToken cancellationT
null);
}

logger.AddUserMessage("Kernel uploaded to PCM succesfully. Requesting data...");
logger.AddUserMessage("Kernel uploaded to PCM successfully. Requesting data...");

// Which flash chip?
await this.vehicle.SendToolPresentNotification();
Expand Down
4 changes: 2 additions & 2 deletions Apps/PcmLibrary/CKernelWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public async Task<bool> Write(
return false;
}

logger.AddUserMessage("Loader uploaded to PCM succesfully.");
logger.AddUserMessage("Loader uploaded to PCM successfully.");
}

response = await this.vehicle.LoadKernelFromFile(this.pcmInfo.KernelFileName);
Expand All @@ -126,7 +126,7 @@ public async Task<bool> Write(
return false;
}

logger.AddUserMessage("Kernel uploaded to PCM succesfully.");
logger.AddUserMessage("Kernel uploaded to PCM successfully.");
}

// Confirm operating system match
Expand Down
54 changes: 27 additions & 27 deletions Apps/PcmLibrary/Misc/FileValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,25 @@ public bool IsValid()
{
if (this.image.Length == 256 * 1024)
{
this.logger.AddUserMessage("Identifying 256kb file.");
this.logger.AddUserMessage("Identifying 256KiB file.");
}
else if (this.image.Length == 512 * 1024)
{
this.logger.AddUserMessage("Identifying 512kb file.");
this.logger.AddUserMessage("Identifying 512KiB file.");
}
else if (this.image.Length == 1024 * 1024)
{
this.logger.AddUserMessage("Identifying 1024Kb file.");
this.logger.AddUserMessage("Identifying 1024KiB file.");
}
else if (this.image.Length == 2048 * 1024)
{
this.logger.AddUserMessage("Identifying 2048Kb file.");
this.logger.AddUserMessage("Identifying 2048KiB file.");
}
else
{
this.logger.AddUserMessage(
string.Format(
"Files must be 256k, 512k, 1024k or 2048k. This file is {0} / {1:X} bytes long.",
"Files must be 256KiB, 512KiB, 1024KiB or 2048KiB. This file is {0} / {1:X} bytes long.",
this.image.Length,
this.image.Length));
return false;
Expand Down Expand Up @@ -366,10 +366,10 @@ private PcmType ValidateSignatures()
// P04 512Kb
if (image.Length == 256 * 1024)
{
this.logger.AddDebugMessage("Trying P04 256Kb");
this.logger.AddDebugMessage("Trying P04 256KiB");
if ((image[0x3FFFE] == 0xA5) && (image[0x3FFFF] == 0x5A))
{
this.logger.AddUserMessage("File is P04 256Kb.");
this.logger.AddUserMessage("File is P04 256KiB.");
return PcmType.P04_256k;
}
}
Expand All @@ -379,110 +379,110 @@ private PcmType ValidateSignatures()
{
// E54 512Kb
// Must be before P01, P01 can pass for a E54, but an E54 cannot pass as a P01
this.logger.AddDebugMessage("Trying E54 512Kb");
this.logger.AddDebugMessage("Trying E54 512KiB");
if ((image[0x1FFFE] == 0x4A) && (image[0x1FFFF] == 0xFC))
{
if ((image[0x7FFFC] == 0x4A) && (image[0x7FFFD] == 0xFC) && (image[0x7FFFE] == 0x4A) && (image[0x7FFFF] == 0xFC))
{
if ((image[0x3FFC] == 0) && (image[0x3FFD] == 0) && (image[0x3FFE] == 0) && (image[0x3FFF] == 0)) { // This prevents 98/99 Black Box being detected at E54
this.logger.AddUserMessage("File is E54 512Kb.");
this.logger.AddUserMessage("File is E54 512KiB.");
return PcmType.E54;
}
}
}

// BlackBox 512Kb. Thanks to Universal Patcher team for the logic in autodetect.xml
this.logger.AddDebugMessage("Trying Vortec BlackBox 512Kb");
this.logger.AddDebugMessage("Trying Vortec BlackBox 512KiB");
if ((image[0x1FFFE] == 0x4A) && (image[0x1FFFF] == 0xFC))
{
if ((image[0x7FFFE] == 0x4A) && (image[0x7FFFF] == 0xFC))
{
if ((image[0x20002] == 00) && (image[0x20003] == 01) && (image[0x2000A] == 01) && (image[0x2000B] == 00))
{
this.logger.AddUserMessage("File is Vortec BlackBox 512Kb.");
this.logger.AddUserMessage("File is Vortec BlackBox 512KiB.");
return PcmType.BlackBox;
}
}
}

// P01 512Kb
this.logger.AddDebugMessage("Trying P01 512Kb");
this.logger.AddDebugMessage("Trying P01 512KiB");
if ((image[0x1FFFE] == 0x4A) && (image[0x1FFFF] == 0xFC))
{
if ((image[0x7FFFE] == 0x4A) && (image[0x7FFFF] == 0xFC))
{
this.logger.AddUserMessage("File is P01 512Kb.");
this.logger.AddUserMessage("File is P01 512KiB.");
return PcmType.P01_P59;
}
}

// P04 512Kb
this.logger.AddDebugMessage("Trying P04 512Kb");
this.logger.AddDebugMessage("Trying P04 512KiB");
// Last 4 bytes:
// A5 5A FF FF = P04
// XX XX XX XX A5 5A = P04 (XX is the OSID)
if (((image[0x7FFFE] == 0xA5) && (image[0x7FFFF] == 0x5A)) || // most P04 OR
((image[0x7FFFC] == 0xA5) && (image[0x7FFFD] == 0x5A) && (image[0x7FFFE] == 0xFF) && (image[0x7FFFF] == 0xFF))) // Most 1998 512Kb eg Malibu 09369193, Olds 09352676, LeSabre 09379801...
{
this.logger.AddUserMessage("File is P04 512kb.");
this.logger.AddUserMessage("File is P04 512KiB.");
return PcmType.P04;
}

this.logger.AddDebugMessage("Trying P10 512Kb");
this.logger.AddDebugMessage("Trying P10 512KiB");
if ((image[0x17FFE] == 0x55) && (image[0x17FFF] == 0x55))
{
if ((image[0x7FFFC] == 0xA5) && (image[0x7FFFD] == 0x5A) && (image[0x7FFFE] == 0xA5) && (image[0x7FFFF] == 0xA5))
{
this.logger.AddUserMessage("File is P10 512Kb.");
this.logger.AddUserMessage("File is P10 512KiB.");
return PcmType.P10;
}
}

// P08 512Kb
this.logger.AddDebugMessage("Trying P08 512Kb");
this.logger.AddDebugMessage("Trying P08 512KiB");
if ((image[0x7FFFC] == 0xA5) && (image[0x7FFFD] == 0x5A) && (image[0x7FFFE] == 0xA5) && (image[0x7FFFF] == 0xA5))
{
this.logger.AddUserMessage("File is P08 512Kb.");
this.logger.AddUserMessage("File is P08 512KiB.");
return PcmType.P08;
}
}

// 1Mb types
if (image.Length == 1024 * 1024)
{
this.logger.AddDebugMessage("Trying P59 1Mb");
this.logger.AddDebugMessage("Trying P59 1024KiB");
if ((image[0x1FFFE] == 0x4A) && (image[0x1FFFF] == 0xFC))
{
if ((image[0xFFFFE] == 0x4A) && (image[0xFFFFF] == 0xFC))
{
this.logger.AddUserMessage("File is P59 1Mb.");
this.logger.AddUserMessage("File is P59 1024KiB.");
return PcmType.P01_P59;
}
}

// P05 1Mb
this.logger.AddDebugMessage("Trying P05 1Mb");
this.logger.AddDebugMessage("Trying P05 1024KiB");
if ((image[0xFFFFE] == 0xA5) && (image[0xFFFFF] == 0x5A))
{
this.logger.AddUserMessage("File is P05 1Mb.");
this.logger.AddUserMessage("File is P05 1024KiB.");
return PcmType.P05;
}

this.logger.AddDebugMessage("Trying P12 1Mb");
this.logger.AddDebugMessage("Trying P12 1024MiB");
if ((image[0xFFFF8] == 0xAA) && (image[0xFFFF9] == 0x55))
{
this.logger.AddUserMessage("File is P12 1Mb.");
this.logger.AddUserMessage("File is P12 1024MiB.");
return PcmType.P12;
}
}

// 2Mb types
if (image.Length == 2048 * 1024)
{
this.logger.AddDebugMessage("Trying P12 2Mb");
this.logger.AddDebugMessage("Trying P12 2048MiB");
if ((image[0x17FFF8] == 0xAA) && (image[0x17FFF9] == 0x55))
{
this.logger.AddUserMessage("File is P12 2Mb.");
this.logger.AddUserMessage("File is P12 2048MiB.");
return PcmType.P12;
}
}
Expand Down
18 changes: 9 additions & 9 deletions Apps/PcmLibrary/Misc/FlashChip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static FlashChip Create(UInt32 chipId, ILogger logger)
// This is not a real chip, its used as a default value, then overwritten with real data if the kernel supprot flashchipid.
case 0x12345678:
size = 512 * 1024;
description = "Default 512Kb";
description = "Default 512KiB";
memoryRanges = new MemoryRange[]
{
// Used by CKernelReader to initialise FlashChip default value
Expand All @@ -95,7 +95,7 @@ public static FlashChip Create(UInt32 chipId, ILogger logger)
case 0x00892274:
case 0x00892275:
size = 256 * 1024;
description = "Intel 28F200BX, 256kb";
description = "Intel 28F200BX, 256KiB";
memoryRanges = new MemoryRange[]
{
// These addresses are for a bottom fill chip (B) in byte mode (not word)
Expand All @@ -110,7 +110,7 @@ public static FlashChip Create(UInt32 chipId, ILogger logger)
// Intel 28F400B
case 0x00894471:
size = 512 * 1024;
description = "Intel 28F400B, 512kb";
description = "Intel 28F400B, 512KiB";
memoryRanges = new MemoryRange[]
{
// These addresses are for a bottom fill chip (B) in byte mode (not word)
Expand All @@ -127,7 +127,7 @@ public static FlashChip Create(UInt32 chipId, ILogger logger)
// Intel 28F800B
case 0x0089889D:
size = 1024 * 1024;
description = "Intel 28F800B, 1mb";
description = "Intel 28F800B, 1024KiB";
memoryRanges = new MemoryRange[]
{
// These addresses are for a bottom fill chip (B) in byte mode (not word)
Expand All @@ -148,7 +148,7 @@ public static FlashChip Create(UInt32 chipId, ILogger logger)
// AM29F400BB
case 0x000122AB:
size = 512 * 1024;
description = "AMD AM29F400BB, 512kb";
description = "AMD AM29F400BB, 512KiB";
memoryRanges = new MemoryRange[]
{
new MemoryRange(0x70000, 0x10000, BlockType.OperatingSystem), // 64kb main block
Expand All @@ -168,7 +168,7 @@ public static FlashChip Create(UInt32 chipId, ILogger logger)
// AM29F800BB
case 0x00012258:
size = 1024 * 1024;
description = "AMD AM29F800BB, 1mb";
description = "AMD AM29F800BB, 1024KiB";
memoryRanges = new MemoryRange[]
{
new MemoryRange(0xF0000, 0x10000, BlockType.OperatingSystem), // 64kb main block
Expand Down Expand Up @@ -196,7 +196,7 @@ public static FlashChip Create(UInt32 chipId, ILogger logger)
// AM29BL802C
case 0x00012281:
size = 1024 * 1024;
description = "AMD AM29BL802C, 1mb";
description = "AMD AM29BL802C, 1024KiB";
memoryRanges = new MemoryRange[]
{ // Start address, Size in Bytes
new MemoryRange(0xC0000, 0x40000, BlockType.OperatingSystem), // 256kb main block
Expand All @@ -214,7 +214,7 @@ public static FlashChip Create(UInt32 chipId, ILogger logger)
// AM29BL162C
case 0x00012203:
size = 2048 * 1024;
description = "AMD AM29BL162C, 2mb";
description = "AMD AM29BL162C, 2048KiB";
memoryRanges = new MemoryRange[]
{ // Start address, Size in Bytes
new MemoryRange(0x1C0000, 0x40000, BlockType.OperatingSystem), // 256kb main block
Expand Down Expand Up @@ -273,7 +273,7 @@ public static FlashChip Create(UInt32 chipId, ILogger logger)
UInt32 top = memoryRanges[index].Address + memoryRanges[index].Size;
if ((top != 256 * 1024) && (top != 512 * 1024) && (top != 1024 * 1024) && (top != 2048 * 1024))
{
throw new InvalidOperationException(chipIdString + " - Upper end of memory range must be 256k, 512k, 1024k or 2048k, is " + (top / 1024).ToString() + "k");
throw new InvalidOperationException(chipIdString + " - Upper end of memory range must be 256KiB, 512KiB, 1024KiB or 2048KiB, is " + (top / 1024).ToString() + "KiB");
}

if (size != top)
Expand Down
Loading

0 comments on commit 6d6e362

Please sign in to comment.