From 246f7aac2d5c413fdc24fb153af80d9e474f5db8 Mon Sep 17 00:00:00 2001 From: Gustave Monce Date: Tue, 27 Feb 2024 22:29:33 +0100 Subject: [PATCH] Allow overriding the disk guid --- FirmwareGen/CommonLogic.cs | 4 ++-- FirmwareGen/DeviceProfiles/EpsilonHalfSplit128GB.cs | 5 +++++ FirmwareGen/DeviceProfiles/EpsilonHalfSplit256GB.cs | 5 +++++ FirmwareGen/DeviceProfiles/EpsilonMaximizedForWindows.cs | 5 +++++ FirmwareGen/DeviceProfiles/MTP8150MaximizedForWindows.cs | 5 +++++ FirmwareGen/DeviceProfiles/ZetaHalfSplit128GB.cs | 5 +++++ FirmwareGen/DeviceProfiles/ZetaHalfSplit256GB.cs | 5 +++++ FirmwareGen/DeviceProfiles/ZetaHalfSplit512GB.cs | 5 +++++ FirmwareGen/DeviceProfiles/ZetaMaximizedForWindows.cs | 5 +++++ FirmwareGen/GPT/GPTUtils.cs | 8 ++++---- FirmwareGen/IDeviceProfile.cs | 2 ++ 11 files changed, 48 insertions(+), 6 deletions(-) diff --git a/FirmwareGen/CommonLogic.cs b/FirmwareGen/CommonLogic.cs index 57a0c1f..0ebc746 100644 --- a/FirmwareGen/CommonLogic.cs +++ b/FirmwareGen/CommonLogic.cs @@ -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) ]; } @@ -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) diff --git a/FirmwareGen/DeviceProfiles/EpsilonHalfSplit128GB.cs b/FirmwareGen/DeviceProfiles/EpsilonHalfSplit128GB.cs index c9e32d0..9dc970d 100644 --- a/FirmwareGen/DeviceProfiles/EpsilonHalfSplit128GB.cs +++ b/FirmwareGen/DeviceProfiles/EpsilonHalfSplit128GB.cs @@ -103,5 +103,10 @@ public SplittingStrategy GetSplittingStrategy() { return SplittingStrategy.HalfSplit; } + + public Guid GetDiskGuid() + { + return new Guid("efa6243a-085f-e745-f2ce-54d39ef34351"); + } } } diff --git a/FirmwareGen/DeviceProfiles/EpsilonHalfSplit256GB.cs b/FirmwareGen/DeviceProfiles/EpsilonHalfSplit256GB.cs index a17239d..8e2fd61 100644 --- a/FirmwareGen/DeviceProfiles/EpsilonHalfSplit256GB.cs +++ b/FirmwareGen/DeviceProfiles/EpsilonHalfSplit256GB.cs @@ -103,5 +103,10 @@ public SplittingStrategy GetSplittingStrategy() { return SplittingStrategy.HalfSplit; } + + public Guid GetDiskGuid() + { + return new Guid("efa6243a-085f-e745-f2ce-54d39ef34351"); + } } } diff --git a/FirmwareGen/DeviceProfiles/EpsilonMaximizedForWindows.cs b/FirmwareGen/DeviceProfiles/EpsilonMaximizedForWindows.cs index e0b17b1..2bc86cb 100644 --- a/FirmwareGen/DeviceProfiles/EpsilonMaximizedForWindows.cs +++ b/FirmwareGen/DeviceProfiles/EpsilonMaximizedForWindows.cs @@ -103,5 +103,10 @@ public SplittingStrategy GetSplittingStrategy() { return SplittingStrategy.MaximizedForWindows; } + + public Guid GetDiskGuid() + { + return new Guid("efa6243a-085f-e745-f2ce-54d39ef34351"); + } } } diff --git a/FirmwareGen/DeviceProfiles/MTP8150MaximizedForWindows.cs b/FirmwareGen/DeviceProfiles/MTP8150MaximizedForWindows.cs index f112cd0..058a24b 100644 --- a/FirmwareGen/DeviceProfiles/MTP8150MaximizedForWindows.cs +++ b/FirmwareGen/DeviceProfiles/MTP8150MaximizedForWindows.cs @@ -155,5 +155,10 @@ public SplittingStrategy GetSplittingStrategy() { return SplittingStrategy.MaximizedForWindows; } + + public Guid GetDiskGuid() + { + return new Guid("efa6243a-085f-e745-f2ce-54d39ef34351"); + } } } diff --git a/FirmwareGen/DeviceProfiles/ZetaHalfSplit128GB.cs b/FirmwareGen/DeviceProfiles/ZetaHalfSplit128GB.cs index b199d98..0075a2d 100644 --- a/FirmwareGen/DeviceProfiles/ZetaHalfSplit128GB.cs +++ b/FirmwareGen/DeviceProfiles/ZetaHalfSplit128GB.cs @@ -122,5 +122,10 @@ public SplittingStrategy GetSplittingStrategy() { return SplittingStrategy.HalfSplit; } + + public Guid GetDiskGuid() + { + return new Guid("efa6243a-085f-e745-f2ce-54d39ef34351"); + } } } diff --git a/FirmwareGen/DeviceProfiles/ZetaHalfSplit256GB.cs b/FirmwareGen/DeviceProfiles/ZetaHalfSplit256GB.cs index c4411a3..412b949 100644 --- a/FirmwareGen/DeviceProfiles/ZetaHalfSplit256GB.cs +++ b/FirmwareGen/DeviceProfiles/ZetaHalfSplit256GB.cs @@ -122,5 +122,10 @@ public SplittingStrategy GetSplittingStrategy() { return SplittingStrategy.HalfSplit; } + + public Guid GetDiskGuid() + { + return new Guid("efa6243a-085f-e745-f2ce-54d39ef34351"); + } } } diff --git a/FirmwareGen/DeviceProfiles/ZetaHalfSplit512GB.cs b/FirmwareGen/DeviceProfiles/ZetaHalfSplit512GB.cs index 3472f2a..33b644d 100644 --- a/FirmwareGen/DeviceProfiles/ZetaHalfSplit512GB.cs +++ b/FirmwareGen/DeviceProfiles/ZetaHalfSplit512GB.cs @@ -122,5 +122,10 @@ public SplittingStrategy GetSplittingStrategy() { return SplittingStrategy.HalfSplit; } + + public Guid GetDiskGuid() + { + return new Guid("efa6243a-085f-e745-f2ce-54d39ef34351"); + } } } diff --git a/FirmwareGen/DeviceProfiles/ZetaMaximizedForWindows.cs b/FirmwareGen/DeviceProfiles/ZetaMaximizedForWindows.cs index 580bb8b..c82fb27 100644 --- a/FirmwareGen/DeviceProfiles/ZetaMaximizedForWindows.cs +++ b/FirmwareGen/DeviceProfiles/ZetaMaximizedForWindows.cs @@ -122,5 +122,10 @@ public SplittingStrategy GetSplittingStrategy() { return SplittingStrategy.MaximizedForWindows; } + + public Guid GetDiskGuid() + { + return new Guid("efa6243a-085f-e745-f2ce-54d39ef34351"); + } } } diff --git a/FirmwareGen/GPT/GPTUtils.cs b/FirmwareGen/GPT/GPTUtils.cs index c0e7f24..cf539b1 100644 --- a/FirmwareGen/GPT/GPTUtils.cs +++ b/FirmwareGen/GPT/GPTUtils.cs @@ -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; @@ -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 Partitions, ulong SectorSize, ulong BlockSize, bool SplitInHalf) @@ -141,7 +141,7 @@ private static void InjectWindowsPartitions(List 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 @@ -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, diff --git a/FirmwareGen/IDeviceProfile.cs b/FirmwareGen/IDeviceProfile.cs index 8360f86..6624ea8 100644 --- a/FirmwareGen/IDeviceProfile.cs +++ b/FirmwareGen/IDeviceProfile.cs @@ -1,4 +1,5 @@ using FirmwareGen.GPT; +using System; namespace FirmwareGen { @@ -12,5 +13,6 @@ public interface IDeviceProfile uint GetDiskSectorSize(); GPTPartition[] GetPartitionLayout(); SplittingStrategy GetSplittingStrategy(); + Guid GetDiskGuid(); } } \ No newline at end of file