diff --git a/FirmwareGen/GPT/Constants.cs b/FirmwareGen/DeviceProfiles/Constants.cs similarity index 97% rename from FirmwareGen/GPT/Constants.cs rename to FirmwareGen/DeviceProfiles/Constants.cs index 86dae3f..1568377 100644 --- a/FirmwareGen/GPT/Constants.cs +++ b/FirmwareGen/DeviceProfiles/Constants.cs @@ -1,6 +1,7 @@ using System; +using FirmwareGen.GPT; -namespace FirmwareGen.GPT +namespace FirmwareGen.DeviceProfiles { internal static class Constants { diff --git a/FirmwareGen/DeviceProfiles/EpsilonHalfSplit128GB.cs b/FirmwareGen/DeviceProfiles/EpsilonHalfSplit128GB.cs new file mode 100644 index 0000000..ef68daa --- /dev/null +++ b/FirmwareGen/DeviceProfiles/EpsilonHalfSplit128GB.cs @@ -0,0 +1,100 @@ +using FirmwareGen.GPT; +using FirmwareGen.VirtualDisks; +using System.IO; + +namespace FirmwareGen.DeviceProfiles +{ + public class EpsilonHalfSplit128GB : IDeviceProfile + { + public byte[] GetPrimaryGPT() + { + //ulong DiskSize = 239_683_502_080; // 256GB (Bigger variant); + //ulong DiskSize = 239_651_758_080; // 256GB (Smaller variant); + ulong DiskSize = 111_723_675_648; // 128GB; + ulong SectorSize = 4096; + + byte[] PrimaryMBR = new byte[SectorSize]; + PrimaryMBR[0x1C0] = 0x01; + PrimaryMBR[0x1C2] = 0xEE; + PrimaryMBR[0x1C3] = 0xFF; + PrimaryMBR[0x1C4] = 0xFF; + PrimaryMBR[0x1C5] = 0xFF; + PrimaryMBR[0x1C6] = 0x01; + PrimaryMBR[0x1CA] = 0xFF; + PrimaryMBR[0x1CB] = 0xFF; + PrimaryMBR[0x1CC] = 0xFF; + PrimaryMBR[0x1CD] = 0xFF; + PrimaryMBR[0x1FE] = 0x55; + PrimaryMBR[0x1FF] = 0xAA; + + return [ + .. PrimaryMBR, + .. GPTUtils.MakeGPT(DiskSize, SectorSize, Constants.OEMEP_UFS_LUN_0_PARTITIONS, IsBackupGPT: false) + ]; + } + + public byte[] GetBackupGPT() + { + //ulong DiskSize = 239_683_502_080; // 256GB (Bigger variant); + //ulong DiskSize = 239_651_758_080; // 256GB (Smaller variant); + ulong DiskSize = 111_723_675_648; // 128GB; + ulong SectorSize = 4096; + + return GPTUtils.MakeGPT(DiskSize, SectorSize, Constants.OEMEP_UFS_LUN_0_PARTITIONS, IsBackupGPT: true); + } + + public string GetBlankVHD() + { + //ulong DiskSize = 239_683_502_080; // 256GB (Bigger variant); + //ulong DiskSize = 239_651_758_080; // 256GB (Smaller variant); + ulong DiskSize = 111_723_675_648; // 128GB; + uint SectorSize = 4096; + + const string tmp = "tmp"; + const string TmpVHD = $@"{tmp}\temp.vhdx"; + + if (!Directory.Exists(tmp)) + { + _ = Directory.CreateDirectory(tmp); + } + + if (File.Exists(TmpVHD)) + { + File.Delete(TmpVHD); + } + + Logging.Log("Generating Primary GPT"); + byte[] PrimaryGPT = GetPrimaryGPT(); + + Logging.Log("Generating Backup GPT"); + byte[] BackupGPT = GetBackupGPT(); + + Logging.Log("Generating Main VHD"); + VHDUtils.CreateVHDX(TmpVHD, SectorSize, DiskSize); + + BlankVHDUtils.PrepareVHD(TmpVHD, PrimaryGPT, BackupGPT); + + return TmpVHD; + } + + public string[] SupplementaryBCDCommands() + { + return []; + } + + public string PlatformID() + { + return "Microsoft Corporation.Surface.Surface Duo.1930"; + } + + public string FFUFileName(string OSVersion, string Language, string Sku) + { + return $"OEMEP_128GB_HalfSplit_{OSVersion}_CLIENT{Sku}_a64fre_{Language}_unsigned.ffu"; + } + + public string DriverCommand(string DriverFolder) + { + return $@"{DriverFolder}\definitions\Desktop\ARM64\Internal\epsilon.xml"; + } + } +} diff --git a/FirmwareGen/DeviceProfiles/EpsilonHalfSplit256GB.cs b/FirmwareGen/DeviceProfiles/EpsilonHalfSplit256GB.cs new file mode 100644 index 0000000..53301f1 --- /dev/null +++ b/FirmwareGen/DeviceProfiles/EpsilonHalfSplit256GB.cs @@ -0,0 +1,100 @@ +using FirmwareGen.GPT; +using FirmwareGen.VirtualDisks; +using System.IO; + +namespace FirmwareGen.DeviceProfiles +{ + internal class EpsilonHalfSplit256GB : IDeviceProfile + { + public byte[] GetPrimaryGPT() + { + //ulong DiskSize = 239_683_502_080; // 256GB (Bigger variant); + ulong DiskSize = 239_651_758_080; // 256GB (Smaller variant); + //ulong DiskSize = 111_723_675_648; // 128GB; + ulong SectorSize = 4096; + + byte[] PrimaryMBR = new byte[SectorSize]; + PrimaryMBR[0x1C0] = 0x01; + PrimaryMBR[0x1C2] = 0xEE; + PrimaryMBR[0x1C3] = 0xFF; + PrimaryMBR[0x1C4] = 0xFF; + PrimaryMBR[0x1C5] = 0xFF; + PrimaryMBR[0x1C6] = 0x01; + PrimaryMBR[0x1CA] = 0xFF; + PrimaryMBR[0x1CB] = 0xFF; + PrimaryMBR[0x1CC] = 0xFF; + PrimaryMBR[0x1CD] = 0xFF; + PrimaryMBR[0x1FE] = 0x55; + PrimaryMBR[0x1FF] = 0xAA; + + return [ + .. PrimaryMBR, + .. GPTUtils.MakeGPT(DiskSize, SectorSize, Constants.OEMEP_UFS_LUN_0_PARTITIONS, IsBackupGPT: false) + ]; + } + + public byte[] GetBackupGPT() + { + //ulong DiskSize = 239_683_502_080; // 256GB (Bigger variant); + ulong DiskSize = 239_651_758_080; // 256GB (Smaller variant); + //ulong DiskSize = 111_723_675_648; // 128GB; + ulong SectorSize = 4096; + + return GPTUtils.MakeGPT(DiskSize, SectorSize, Constants.OEMEP_UFS_LUN_0_PARTITIONS, IsBackupGPT: true); + } + + public string GetBlankVHD() + { + //ulong DiskSize = 239_683_502_080; // 256GB (Bigger variant); + ulong DiskSize = 239_651_758_080; // 256GB (Smaller variant); + //ulong DiskSize = 111_723_675_648; // 128GB; + uint SectorSize = 4096; + + const string tmp = "tmp"; + const string TmpVHD = $@"{tmp}\temp.vhdx"; + + if (!Directory.Exists(tmp)) + { + _ = Directory.CreateDirectory(tmp); + } + + if (File.Exists(TmpVHD)) + { + File.Delete(TmpVHD); + } + + Logging.Log("Generating Primary GPT"); + byte[] PrimaryGPT = GetPrimaryGPT(); + + Logging.Log("Generating Backup GPT"); + byte[] BackupGPT = GetBackupGPT(); + + Logging.Log("Generating Main VHD"); + VHDUtils.CreateVHDX(TmpVHD, SectorSize, DiskSize); + + BlankVHDUtils.PrepareVHD(TmpVHD, PrimaryGPT, BackupGPT); + + return TmpVHD; + } + + public string[] SupplementaryBCDCommands() + { + return []; + } + + public string PlatformID() + { + return "Microsoft Corporation.Surface.Surface Duo.1930"; + } + + public string FFUFileName(string OSVersion, string Language, string Sku) + { + return $"OEMEP_256GB_HalfSplit_{OSVersion}_CLIENT{Sku}_a64fre_{Language}_unsigned.ffu"; + } + + public string DriverCommand(string DriverFolder) + { + return $@"{DriverFolder}\definitions\Desktop\ARM64\Internal\epsilon.xml"; + } + } +} diff --git a/FirmwareGen/DeviceProfiles/EpsilonMaximizedForWindows.cs b/FirmwareGen/DeviceProfiles/EpsilonMaximizedForWindows.cs new file mode 100644 index 0000000..3dc3758 --- /dev/null +++ b/FirmwareGen/DeviceProfiles/EpsilonMaximizedForWindows.cs @@ -0,0 +1,100 @@ +using FirmwareGen.GPT; +using FirmwareGen.VirtualDisks; +using System.IO; + +namespace FirmwareGen.DeviceProfiles +{ + internal class EpsilonMaximizedForWindows : IDeviceProfile + { + public byte[] GetPrimaryGPT() + { + //ulong DiskSize = 239_683_502_080; // 256GB (Bigger variant); + //ulong DiskSize = 239_651_758_080; // 256GB (Smaller variant); + ulong DiskSize = 111_723_675_648; // 128GB; + ulong SectorSize = 4096; + + byte[] PrimaryMBR = new byte[SectorSize]; + PrimaryMBR[0x1C0] = 0x01; + PrimaryMBR[0x1C2] = 0xEE; + PrimaryMBR[0x1C3] = 0xFF; + PrimaryMBR[0x1C4] = 0xFF; + PrimaryMBR[0x1C5] = 0xFF; + PrimaryMBR[0x1C6] = 0x01; + PrimaryMBR[0x1CA] = 0xFF; + PrimaryMBR[0x1CB] = 0xFF; + PrimaryMBR[0x1CC] = 0xFF; + PrimaryMBR[0x1CD] = 0xFF; + PrimaryMBR[0x1FE] = 0x55; + PrimaryMBR[0x1FF] = 0xAA; + + return [ + .. PrimaryMBR, + .. GPTUtils.MakeGPT(DiskSize, SectorSize, Constants.OEMEP_UFS_LUN_0_PARTITIONS, IsBackupGPT: false, SplitInHalf: false) + ]; + } + + public byte[] GetBackupGPT() + { + //ulong DiskSize = 239_683_502_080; // 256GB (Bigger variant); + //ulong DiskSize = 239_651_758_080; // 256GB (Smaller variant); + ulong DiskSize = 111_723_675_648; // 128GB; + ulong SectorSize = 4096; + + return GPTUtils.MakeGPT(DiskSize, SectorSize, Constants.OEMEP_UFS_LUN_0_PARTITIONS, IsBackupGPT: true, SplitInHalf: false); + } + + public string GetBlankVHD() + { + //ulong DiskSize = 239_683_502_080; // 256GB (Bigger variant); + //ulong DiskSize = 239_651_758_080; // 256GB (Smaller variant); + ulong DiskSize = 111_723_675_648; // 128GB; + uint SectorSize = 4096; + + const string tmp = "tmp"; + const string TmpVHD = $@"{tmp}\temp.vhdx"; + + if (!Directory.Exists(tmp)) + { + _ = Directory.CreateDirectory(tmp); + } + + if (File.Exists(TmpVHD)) + { + File.Delete(TmpVHD); + } + + Logging.Log("Generating Primary GPT"); + byte[] PrimaryGPT = GetPrimaryGPT(); + + Logging.Log("Generating Backup GPT"); + byte[] BackupGPT = GetBackupGPT(); + + Logging.Log("Generating Main VHD"); + VHDUtils.CreateVHDX(TmpVHD, SectorSize, DiskSize); + + BlankVHDUtils.PrepareVHD(TmpVHD, PrimaryGPT, BackupGPT); + + return TmpVHD; + } + + public string[] SupplementaryBCDCommands() + { + return []; + } + + public string PlatformID() + { + return "Microsoft Corporation.Surface.Surface Duo.1930"; + } + + public string FFUFileName(string OSVersion, string Language, string Sku) + { + return $"OEMEP_MaximizedForWindows_{OSVersion}_CLIENT{Sku}_a64fre_{Language}_unsigned.ffu"; + } + + public string DriverCommand(string DriverFolder) + { + return $@"{DriverFolder}\definitions\Desktop\ARM64\Internal\epsilon.xml"; + } + } +} diff --git a/FirmwareGen/GPT/GPTUtils.cs b/FirmwareGen/GPT/GPTUtils.cs index 0281dc1..d62904a 100644 --- a/FirmwareGen/GPT/GPTUtils.cs +++ b/FirmwareGen/GPT/GPTUtils.cs @@ -7,81 +7,7 @@ namespace FirmwareGen.GPT { internal class GPTUtils { - internal static byte[] Generate128GBOEMEPPrimaryGPT() - { - //ulong DiskSize = 239_683_502_080; // 256GB (Bigger variant); - //ulong DiskSize = 239_651_758_080; // 256GB (Smaller variant); - ulong DiskSize = 111_723_675_648; // 128GB; - ulong SectorSize = 4096; - - byte[] PrimaryMBR = new byte[SectorSize]; - PrimaryMBR[0x1C0] = 0x01; - PrimaryMBR[0x1C2] = 0xEE; - PrimaryMBR[0x1C3] = 0xFF; - PrimaryMBR[0x1C4] = 0xFF; - PrimaryMBR[0x1C5] = 0xFF; - PrimaryMBR[0x1C6] = 0x01; - PrimaryMBR[0x1CA] = 0xFF; - PrimaryMBR[0x1CB] = 0xFF; - PrimaryMBR[0x1CC] = 0xFF; - PrimaryMBR[0x1CD] = 0xFF; - PrimaryMBR[0x1FE] = 0x55; - PrimaryMBR[0x1FF] = 0xAA; - - return [ - .. PrimaryMBR, - .. MakeGPT(DiskSize, SectorSize, IsBackupGPT: false) - ]; - } - - internal static byte[] Generate128GBOEMEPBackupGPT() - { - //ulong DiskSize = 239_683_502_080; // 256GB (Bigger variant); - //ulong DiskSize = 239_651_758_080; // 256GB (Smaller variant); - ulong DiskSize = 111_723_675_648; // 128GB; - ulong SectorSize = 4096; - - return MakeGPT(DiskSize, SectorSize, IsBackupGPT: true); - } - - internal static byte[] Generate256GBOEMEPPrimaryGPT() - { - //ulong DiskSize = 239_683_502_080; // 256GB (Bigger variant); - ulong DiskSize = 239_651_758_080; // 256GB (Smaller variant); - //ulong DiskSize = 111_723_675_648; // 128GB; - ulong SectorSize = 4096; - - byte[] PrimaryMBR = new byte[SectorSize]; - PrimaryMBR[0x1C0] = 0x01; - PrimaryMBR[0x1C2] = 0xEE; - PrimaryMBR[0x1C3] = 0xFF; - PrimaryMBR[0x1C4] = 0xFF; - PrimaryMBR[0x1C5] = 0xFF; - PrimaryMBR[0x1C6] = 0x01; - PrimaryMBR[0x1CA] = 0xFF; - PrimaryMBR[0x1CB] = 0xFF; - PrimaryMBR[0x1CC] = 0xFF; - PrimaryMBR[0x1CD] = 0xFF; - PrimaryMBR[0x1FE] = 0x55; - PrimaryMBR[0x1FF] = 0xAA; - - return [ - .. PrimaryMBR, - .. MakeGPT(DiskSize, SectorSize, IsBackupGPT: false) - ]; - } - - internal static byte[] Generate256GBOEMEPBackupGPT() - { - //ulong DiskSize = 239_683_502_080; // 256GB (Bigger variant); - ulong DiskSize = 239_651_758_080; // 256GB (Smaller variant); - //ulong DiskSize = 111_723_675_648; // 128GB; - ulong SectorSize = 4096; - - return MakeGPT(DiskSize, SectorSize, IsBackupGPT: true); - } - - private static byte[] MakeGPT(ulong DiskSize, ulong SectorSize, bool IsBackupGPT = false) + internal static byte[] MakeGPT(ulong DiskSize, ulong SectorSize, GPTPartition[] DefaultPartitionTable, bool IsBackupGPT = false, bool SplitInHalf = true) { ulong FirstLBA = 1; ulong LastLBA = DiskSize / SectorSize - 1; @@ -90,15 +16,15 @@ private static byte[] MakeGPT(ulong DiskSize, ulong SectorSize, bool IsBackupGPT ulong TotalGPTLBACount = 1 /* GPT Header */ + PartitionArrayLBACount /* Partition Table */; ulong LastUsableLBA = LastLBA - TotalGPTLBACount; - List Partitions = new(Constants.OEMEP_UFS_LUN_0_PARTITIONS); + List Partitions = new(DefaultPartitionTable); Partitions[^1].LastLBA = LastUsableLBA; - InjectWindowsPartitions(Partitions, SectorSize, 4); + InjectWindowsPartitions(Partitions, SectorSize, 4, SplitInHalf); return MakeGPT(FirstLBA, LastLBA, SectorSize, [.. Partitions], PartitionArrayLBACount: PartitionArrayLBACount, IsBackupGPT: IsBackupGPT); } - private static void InjectWindowsPartitions(List Partitions, ulong SectorSize, ulong BlockSize, bool SplitInHalf = true) + private static void InjectWindowsPartitions(List Partitions, ulong SectorSize, ulong BlockSize, bool SplitInHalf) { ulong FirstUsableLBA = Partitions.Last().FirstLBA; ulong LastUsableLBA = Partitions.Last().LastLBA; diff --git a/FirmwareGen/IDeviceProfile.cs b/FirmwareGen/IDeviceProfile.cs new file mode 100644 index 0000000..85db282 --- /dev/null +++ b/FirmwareGen/IDeviceProfile.cs @@ -0,0 +1,11 @@ +namespace FirmwareGen +{ + public interface IDeviceProfile + { + string GetBlankVHD(); + string[] SupplementaryBCDCommands(); + string PlatformID(); + string FFUFileName(string OSVersion, string Language, string Sku); + string DriverCommand(string DriverFolder); + } +} \ No newline at end of file diff --git a/FirmwareGen/MainLogic.cs b/FirmwareGen/MainLogic.cs index 213f5ff..7e9d01c 100644 --- a/FirmwareGen/MainLogic.cs +++ b/FirmwareGen/MainLogic.cs @@ -1,4 +1,5 @@ using FirmwareGen.CommandLine; +using FirmwareGen.DeviceProfiles; using FirmwareGen.VirtualDisks; using System.IO; using System.Linq; @@ -7,6 +8,13 @@ namespace FirmwareGen { public static class MainLogic { + private static readonly IDeviceProfile[] deviceProfiles = + [ + new EpsilonHalfSplit128GB(), + new EpsilonHalfSplit256GB(), + new EpsilonMaximizedForWindows() + ]; + public static bool VerifyAllComponentsArePresent() { const string wimlib = "wimlib-imagex.exe"; @@ -41,67 +49,49 @@ public static void GenerateWindowsFFU(GenerateWindowsFFUOptions options) const string DriverUpdater = "DriverUpdater.exe"; const string SystemPartition = "Y:"; - - - Logging.Log("Generating 128GB Main VHD"); - string TmpVHD = BlankVHDUtils.CreateBlankVHDForOEMEP128GB(); - string DiskId = VolumeUtils.MountVirtualHardDisk(TmpVHD, false); - string VHDLetter = VolumeUtils.GetVirtualHardDiskLetterFromDiskID(DiskId); - - VolumeUtils.ApplyWindowsImageFromDVD(wimlib, options.WindowsDVD, options.WindowsIndex, VHDLetter); - VolumeUtils.PerformSlabOptimization(VHDLetter); - VolumeUtils.ApplyCompactFlagsToImage(VHDLetter); - VolumeUtils.MountSystemPartition(DiskId, SystemPartition); - VolumeUtils.ConfigureBootManager(VHDLetter, SystemPartition); - VolumeUtils.UnmountSystemPartition(DiskId, SystemPartition); - - Logging.Log("Adding drivers"); - VolumeUtils.RunProgram(DriverUpdater, $@"-d ""{options.DriverPack}\\definitions\Desktop\ARM64\Internal\epsilon.xml"" -r ""{options.DriverPack}"" -p ""{VHDLetter}"""); - - VolumeUtils.DismountVirtualHardDisk(TmpVHD); - - Logging.Log("Making FFU"); - string version = options.WindowsVer; - if (version.Split(".").Length == 4) - { - version = string.Join(".", version.Split(".").Skip(2)); - } - - VolumeUtils.RunProgram(Img2Ffu, $@"-i {TmpVHD} -f ""{options.Output}\OEMEP_128GB_Windows_11_{version}.ffu"" -c 16384 -s 4096 -p ""Microsoft Corporation.Surface.Surface Duo.1930"" -o {options.WindowsVer} -b 4000"); - - Logging.Log("Deleting Temp VHD"); - File.Delete(TmpVHD); - - - - Logging.Log("Generating 256GB Main VHD"); - TmpVHD = BlankVHDUtils.CreateBlankVHDForOEMEP256GB(); - DiskId = VolumeUtils.MountVirtualHardDisk(TmpVHD, false); - VHDLetter = VolumeUtils.GetVirtualHardDiskLetterFromDiskID(DiskId); - - VolumeUtils.ApplyWindowsImageFromDVD(wimlib, options.WindowsDVD, options.WindowsIndex, VHDLetter); - VolumeUtils.PerformSlabOptimization(VHDLetter); - VolumeUtils.ApplyCompactFlagsToImage(VHDLetter); - VolumeUtils.MountSystemPartition(DiskId, SystemPartition); - VolumeUtils.ConfigureBootManager(VHDLetter, SystemPartition); - VolumeUtils.UnmountSystemPartition(DiskId, SystemPartition); - - Logging.Log("Adding drivers"); - VolumeUtils.RunProgram(DriverUpdater, $@"-d ""{options.DriverPack}\\definitions\Desktop\ARM64\Internal\epsilon.xml"" -r ""{options.DriverPack}"" -p ""{VHDLetter}"""); - - VolumeUtils.DismountVirtualHardDisk(TmpVHD); - - Logging.Log("Making FFU"); - version = options.WindowsVer; - if (version.Split(".").Length == 4) + foreach (IDeviceProfile deviceProfile in deviceProfiles) { - version = string.Join(".", version.Split(".").Skip(2)); + string TmpVHD = deviceProfile.GetBlankVHD(); + string DiskId = VolumeUtils.MountVirtualHardDisk(TmpVHD, false); + string VHDLetter = VolumeUtils.GetVirtualHardDiskLetterFromDiskID(DiskId); + + VolumeUtils.ApplyWindowsImageFromDVD(wimlib, options.WindowsDVD, options.WindowsIndex, VHDLetter); + VolumeUtils.PerformSlabOptimization(VHDLetter); + VolumeUtils.ApplyCompactFlagsToImage(VHDLetter); + VolumeUtils.MountSystemPartition(DiskId, SystemPartition); + VolumeUtils.ConfigureBootManager(VHDLetter, SystemPartition); + VolumeUtils.UnmountSystemPartition(DiskId, SystemPartition); + + if (deviceProfile.SupplementaryBCDCommands().Length > 0) + { + VolumeUtils.MountSystemPartition(DiskId, SystemPartition); + + Logging.Log("Configuring supplemental boot"); + foreach (string command in deviceProfile.SupplementaryBCDCommands()) + { + VolumeUtils.RunProgram("bcdedit.exe", $"{$@"/store {SystemPartition}\EFI\Microsoft\Boot\BCD "}{command}"); + } + + VolumeUtils.UnmountSystemPartition(DiskId, SystemPartition); + } + + Logging.Log("Adding drivers"); + VolumeUtils.RunProgram(DriverUpdater, $@"-d ""{deviceProfile.DriverCommand(options.DriverPack)}"" -r ""{options.DriverPack}"" -p ""{VHDLetter}"""); + + VolumeUtils.DismountVirtualHardDisk(TmpVHD); + + Logging.Log("Making FFU"); + string version = options.WindowsVer; + if (version.Split(".").Length == 4) + { + version = string.Join(".", version.Split(".").Skip(2)); + } + + VolumeUtils.RunProgram(Img2Ffu, $@"-i {TmpVHD} -f ""{options.Output}\{deviceProfile.FFUFileName(version, "en-us", "PROFESSIONAL")}"" -c 16384 -s 4096 -p ""{deviceProfile.PlatformID()}"" -o {options.WindowsVer} -b 4000"); + + Logging.Log("Deleting Temp VHD"); + File.Delete(TmpVHD); } - - VolumeUtils.RunProgram(Img2Ffu, $@"-i {TmpVHD} -f ""{options.Output}\OEMEP_256GB_Windows_11_{version}.ffu"" -c 16384 -s 4096 -p ""Microsoft Corporation.Surface.Surface Duo.1930"" -o {options.WindowsVer} -b 4000"); - - Logging.Log("Deleting Temp VHD"); - File.Delete(TmpVHD); } } } diff --git a/FirmwareGen/VirtualDisks/BlankVHDUtils.cs b/FirmwareGen/VirtualDisks/BlankVHDUtils.cs index f9465af..03879d3 100644 --- a/FirmwareGen/VirtualDisks/BlankVHDUtils.cs +++ b/FirmwareGen/VirtualDisks/BlankVHDUtils.cs @@ -7,74 +7,6 @@ namespace FirmwareGen.VirtualDisks { internal class BlankVHDUtils { - internal static string CreateBlankVHDForOEMEP128GB() - { - //ulong DiskSize = 239_683_502_080; // 256GB (Bigger variant); - //ulong DiskSize = 239_651_758_080; // 256GB (Smaller variant); - ulong DiskSize = 111_723_675_648; // 128GB; - uint SectorSize = 4096; - - const string tmp = "tmp"; - const string TmpVHD = $@"{tmp}\temp.vhdx"; - - if (!Directory.Exists(tmp)) - { - _ = Directory.CreateDirectory(tmp); - } - - if (File.Exists(TmpVHD)) - { - File.Delete(TmpVHD); - } - - Logging.Log("Generating Primary GPT"); - byte[] PrimaryGPT = GPTUtils.Generate128GBOEMEPPrimaryGPT(); - - Logging.Log("Generating Backup GPT"); - byte[] BackupGPT = GPTUtils.Generate128GBOEMEPBackupGPT(); - - Logging.Log("Generating Main VHD"); - VHDUtils.CreateVHDX(TmpVHD, SectorSize, DiskSize); - - PrepareVHD(TmpVHD, PrimaryGPT, BackupGPT); - - return TmpVHD; - } - - internal static string CreateBlankVHDForOEMEP256GB() - { - //ulong DiskSize = 239_683_502_080; // 256GB (Bigger variant); - ulong DiskSize = 239_651_758_080; // 256GB (Smaller variant); - //ulong DiskSize = 111_723_675_648; // 128GB; - uint SectorSize = 4096; - - const string tmp = "tmp"; - const string TmpVHD = $@"{tmp}\temp.vhdx"; - - if (!Directory.Exists(tmp)) - { - _ = Directory.CreateDirectory(tmp); - } - - if (File.Exists(TmpVHD)) - { - File.Delete(TmpVHD); - } - - Logging.Log("Generating Primary GPT"); - byte[] PrimaryGPT = GPTUtils.Generate256GBOEMEPPrimaryGPT(); - - Logging.Log("Generating Backup GPT"); - byte[] BackupGPT = GPTUtils.Generate256GBOEMEPBackupGPT(); - - Logging.Log("Generating Main VHD"); - VHDUtils.CreateVHDX(TmpVHD, SectorSize, DiskSize); - - PrepareVHD(TmpVHD, PrimaryGPT, BackupGPT); - - return TmpVHD; - } - private static void WriteGPTToDisk(string DiskId, byte[] PrimaryGPT, byte[] BackupGPT) { const int chunkSize = 4096; @@ -115,7 +47,7 @@ private static void WriteGPTToDisk(string DiskId, byte[] PrimaryGPT, byte[] Back ds.Dispose(); } - private static void PrepareVHD(string TmpVHD, byte[] PrimaryGPT, byte[] BackupGPT) + public static void PrepareVHD(string TmpVHD, byte[] PrimaryGPT, byte[] BackupGPT) { const string SystemPartition = "Y:";