Skip to content

Commit

Permalink
Allow overriding the disk guid
Browse files Browse the repository at this point in the history
  • Loading branch information
gus33000 committed Feb 27, 2024
1 parent 823ce0f commit 246f7aa
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 6 deletions.
4 changes: 2 additions & 2 deletions FirmwareGen/CommonLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static byte[] GetPrimaryGPT(IDeviceProfile deviceProfile)

return [
.. PrimaryMBR,
.. GPTUtils.MakeGPT(DiskSize, SectorSize, deviceProfile.GetPartitionLayout(), IsBackupGPT: false, SplitInHalf: deviceProfile.GetSplittingStrategy() == SplittingStrategy.HalfSplit)
.. GPTUtils.MakeGPT(DiskSize, SectorSize, deviceProfile.GetPartitionLayout(), deviceProfile.GetDiskGuid(), IsBackupGPT: false, SplitInHalf: deviceProfile.GetSplittingStrategy() == SplittingStrategy.HalfSplit)
];
}

Expand All @@ -36,7 +36,7 @@ public static byte[] GetBackupGPT(IDeviceProfile deviceProfile)
ulong DiskSize = deviceProfile.GetDiskTotalSize();
uint SectorSize = deviceProfile.GetDiskSectorSize();

return GPTUtils.MakeGPT(DiskSize, SectorSize, deviceProfile.GetPartitionLayout(), IsBackupGPT: true, SplitInHalf: deviceProfile.GetSplittingStrategy() == SplittingStrategy.HalfSplit);
return GPTUtils.MakeGPT(DiskSize, SectorSize, deviceProfile.GetPartitionLayout(), deviceProfile.GetDiskGuid(), IsBackupGPT: true, SplitInHalf: deviceProfile.GetSplittingStrategy() == SplittingStrategy.HalfSplit);
}

public static string GetBlankVHD(IDeviceProfile deviceProfile)
Expand Down
5 changes: 5 additions & 0 deletions FirmwareGen/DeviceProfiles/EpsilonHalfSplit128GB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,10 @@ public SplittingStrategy GetSplittingStrategy()
{
return SplittingStrategy.HalfSplit;
}

public Guid GetDiskGuid()
{
return new Guid("efa6243a-085f-e745-f2ce-54d39ef34351");
}
}
}
5 changes: 5 additions & 0 deletions FirmwareGen/DeviceProfiles/EpsilonHalfSplit256GB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,10 @@ public SplittingStrategy GetSplittingStrategy()
{
return SplittingStrategy.HalfSplit;
}

public Guid GetDiskGuid()
{
return new Guid("efa6243a-085f-e745-f2ce-54d39ef34351");
}
}
}
5 changes: 5 additions & 0 deletions FirmwareGen/DeviceProfiles/EpsilonMaximizedForWindows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,10 @@ public SplittingStrategy GetSplittingStrategy()
{
return SplittingStrategy.MaximizedForWindows;
}

public Guid GetDiskGuid()
{
return new Guid("efa6243a-085f-e745-f2ce-54d39ef34351");
}
}
}
5 changes: 5 additions & 0 deletions FirmwareGen/DeviceProfiles/MTP8150MaximizedForWindows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,10 @@ public SplittingStrategy GetSplittingStrategy()
{
return SplittingStrategy.MaximizedForWindows;
}

public Guid GetDiskGuid()
{
return new Guid("efa6243a-085f-e745-f2ce-54d39ef34351");
}
}
}
5 changes: 5 additions & 0 deletions FirmwareGen/DeviceProfiles/ZetaHalfSplit128GB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,10 @@ public SplittingStrategy GetSplittingStrategy()
{
return SplittingStrategy.HalfSplit;
}

public Guid GetDiskGuid()
{
return new Guid("efa6243a-085f-e745-f2ce-54d39ef34351");
}
}
}
5 changes: 5 additions & 0 deletions FirmwareGen/DeviceProfiles/ZetaHalfSplit256GB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,10 @@ public SplittingStrategy GetSplittingStrategy()
{
return SplittingStrategy.HalfSplit;
}

public Guid GetDiskGuid()
{
return new Guid("efa6243a-085f-e745-f2ce-54d39ef34351");
}
}
}
5 changes: 5 additions & 0 deletions FirmwareGen/DeviceProfiles/ZetaHalfSplit512GB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,10 @@ public SplittingStrategy GetSplittingStrategy()
{
return SplittingStrategy.HalfSplit;
}

public Guid GetDiskGuid()
{
return new Guid("efa6243a-085f-e745-f2ce-54d39ef34351");
}
}
}
5 changes: 5 additions & 0 deletions FirmwareGen/DeviceProfiles/ZetaMaximizedForWindows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,10 @@ public SplittingStrategy GetSplittingStrategy()
{
return SplittingStrategy.MaximizedForWindows;
}

public Guid GetDiskGuid()
{
return new Guid("efa6243a-085f-e745-f2ce-54d39ef34351");
}
}
}
8 changes: 4 additions & 4 deletions FirmwareGen/GPT/GPTUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace FirmwareGen.GPT
{
internal class GPTUtils
{
internal static byte[] MakeGPT(ulong DiskSize, ulong SectorSize, GPTPartition[] DefaultPartitionTable, bool IsBackupGPT = false, bool SplitInHalf = true)
internal static byte[] MakeGPT(ulong DiskSize, ulong SectorSize, GPTPartition[] DefaultPartitionTable, Guid DiskGuid, bool IsBackupGPT = false, bool SplitInHalf = true)
{
ulong FirstLBA = 1;
ulong LastLBA = (DiskSize / SectorSize) - 1;
Expand All @@ -27,7 +27,7 @@ internal static byte[] MakeGPT(ulong DiskSize, ulong SectorSize, GPTPartition[]

InjectWindowsPartitions(Partitions, SectorSize, 4, SplitInHalf);

return MakeGPT(FirstLBA, LastLBA, SectorSize, [.. Partitions], PartitionArrayLBACount: PartitionArrayLBACount, IsBackupGPT: IsBackupGPT);
return MakeGPT(FirstLBA, LastLBA, SectorSize, [.. Partitions], DiskGuid, PartitionArrayLBACount: PartitionArrayLBACount, IsBackupGPT: IsBackupGPT);
}

private static void InjectWindowsPartitions(List<GPTPartition> Partitions, ulong SectorSize, ulong BlockSize, bool SplitInHalf)
Expand Down Expand Up @@ -141,7 +141,7 @@ private static void InjectWindowsPartitions(List<GPTPartition> Partitions, ulong
Partitions[^3].LastLBA = ESPFirstLBA - 1;
}

private static byte[] MakeGPT(ulong FirstLBA, ulong LastLBA, ulong SectorSize, GPTPartition[] Partitions, ulong PartitionArrayLBACount = 4, bool IsBackupGPT = false)
private static byte[] MakeGPT(ulong FirstLBA, ulong LastLBA, ulong SectorSize, GPTPartition[] Partitions, Guid DiskGuid, ulong PartitionArrayLBACount = 4, bool IsBackupGPT = false)
{
// -------------------
// 0: Reserved/MBR
Expand Down Expand Up @@ -200,7 +200,7 @@ private static byte[] MakeGPT(ulong FirstLBA, ulong LastLBA, ulong SectorSize, G
BackupLBA = IsBackupGPT ? FirstLBA : LastLBA,
FirstUsableLBA = FirstUsableLBA,
LastUsableLBA = LastUsableLBA,
DiskGUID = new Guid("efa6243a-085f-e745-f2ce-54d39ef34351"),
DiskGUID = DiskGuid,
PartitionArrayLBA = IsBackupGPT ? LastLBA - TotalGPTLBACount + 1 : FirstLBA + 1,
PartitionEntryCount = PartitionEntryCount,
PartitionEntrySize = 128,
Expand Down
2 changes: 2 additions & 0 deletions FirmwareGen/IDeviceProfile.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FirmwareGen.GPT;
using System;

namespace FirmwareGen
{
Expand All @@ -12,5 +13,6 @@ public interface IDeviceProfile
uint GetDiskSectorSize();
GPTPartition[] GetPartitionLayout();
SplittingStrategy GetSplittingStrategy();
Guid GetDiskGuid();
}
}

0 comments on commit 246f7aa

Please sign in to comment.