Skip to content

Commit

Permalink
Remodel from device profile interface to device profile data structure
Browse files Browse the repository at this point in the history
  • Loading branch information
gus33000 committed Feb 27, 2024
1 parent 313a00c commit be3841c
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 124 deletions.
22 changes: 11 additions & 11 deletions FirmwareGen/CommonLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ namespace FirmwareGen
{
internal class CommonLogic
{
public static byte[] GetPrimaryGPT(IDeviceProfile deviceProfile)
public static byte[] GetPrimaryGPT(DeviceProfile deviceProfile)
{
ulong DiskSize = deviceProfile.GetDiskTotalSize();
uint SectorSize = deviceProfile.GetDiskSectorSize();
ulong DiskSize = deviceProfile.DiskTotalSize;
uint SectorSize = deviceProfile.DiskSectorSize;

byte[] PrimaryMBR = new byte[SectorSize];
PrimaryMBR[0x1C0] = 0x01;
Expand All @@ -27,22 +27,22 @@ public static byte[] GetPrimaryGPT(IDeviceProfile deviceProfile)

return [
.. PrimaryMBR,
.. GPTUtils.MakeGPT(DiskSize, SectorSize, deviceProfile.GetPartitionLayout(), deviceProfile.GetDiskGuid(), IsBackupGPT: false, SplitInHalf: deviceProfile.GetSplittingStrategy() == SplittingStrategy.HalfSplit, AndroidDesiredSpace: deviceProfile.GetSplittingStrategy() == SplittingStrategy.Custom ? deviceProfile.GetCustomSplittingAndroidDesiredSpace() : 4_294_967_296)
.. GPTUtils.MakeGPT(DiskSize, SectorSize, deviceProfile.PartitionLayout, deviceProfile.DiskGuid, IsBackupGPT: false, SplitInHalf: deviceProfile.SplittingStrategy == SplittingStrategy.HalfSplit, AndroidDesiredSpace: deviceProfile.SplittingStrategy == SplittingStrategy.Custom ? deviceProfile.CustomSplittingAndroidDesiredSpace : 4_294_967_296)
];
}

public static byte[] GetBackupGPT(IDeviceProfile deviceProfile)
public static byte[] GetBackupGPT(DeviceProfile deviceProfile)
{
ulong DiskSize = deviceProfile.GetDiskTotalSize();
uint SectorSize = deviceProfile.GetDiskSectorSize();
ulong DiskSize = deviceProfile.DiskTotalSize;
uint SectorSize = deviceProfile.DiskSectorSize;

return GPTUtils.MakeGPT(DiskSize, SectorSize, deviceProfile.GetPartitionLayout(), deviceProfile.GetDiskGuid(), IsBackupGPT: true, SplitInHalf: deviceProfile.GetSplittingStrategy() == SplittingStrategy.HalfSplit, AndroidDesiredSpace: deviceProfile.GetSplittingStrategy() == SplittingStrategy.Custom ? deviceProfile.GetCustomSplittingAndroidDesiredSpace() : 4_294_967_296);
return GPTUtils.MakeGPT(DiskSize, SectorSize, deviceProfile.PartitionLayout, deviceProfile.DiskGuid, IsBackupGPT: true, SplitInHalf: deviceProfile.SplittingStrategy == SplittingStrategy.HalfSplit, AndroidDesiredSpace: deviceProfile.SplittingStrategy == SplittingStrategy.Custom ? deviceProfile.CustomSplittingAndroidDesiredSpace : 4_294_967_296);
}

public static string GetBlankVHD(IDeviceProfile deviceProfile)
public static string GetBlankVHD(DeviceProfile deviceProfile)
{
ulong DiskSize = deviceProfile.GetDiskTotalSize();
uint SectorSize = deviceProfile.GetDiskSectorSize();
ulong DiskSize = deviceProfile.DiskTotalSize;
uint SectorSize = deviceProfile.DiskSectorSize;

const string tmp = "tmp";
const string TmpVHD = $@"{tmp}\temp.vhdx";
Expand Down
19 changes: 19 additions & 0 deletions FirmwareGen/DeviceProfile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using FirmwareGen.GPT;
using System;

namespace FirmwareGen
{
public class DeviceProfile
{
public virtual string[] SupplementaryBCDCommands { get; set; }
public virtual string[] PlatformIDs { get; set; }
public virtual string FFUFileName { get; set; }
public virtual string DriverDefinitionPath { get; set; }
public virtual ulong DiskTotalSize { get; set; }
public virtual uint DiskSectorSize { get; set; }
public virtual GPTPartition[] PartitionLayout { get; set; }
public virtual SplittingStrategy SplittingStrategy { get; set; }
public virtual ulong CustomSplittingAndroidDesiredSpace { get; set; }
public virtual Guid DiskGuid { get; set; }
}
}
22 changes: 11 additions & 11 deletions FirmwareGen/DeviceProfiles/EpsilonHalfSplit128GB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@

namespace FirmwareGen.DeviceProfiles
{
public class EpsilonHalfSplit128GB : IDeviceProfile
public class EpsilonHalfSplit128GB : DeviceProfile
{
public string[] GetSupplementaryBCDCommands() => [];
public override string[] SupplementaryBCDCommands => [];

public string[] GetPlatformIDs() => ["Microsoft Corporation.Surface.Surface Duo.1930", "OEMB1.*.OEMB1 Product.*", "OEMEP.*.OEMEP Product.*"];
public override string[] PlatformIDs => ["Microsoft Corporation.Surface.Surface Duo.1930", "OEMB1.*.OEMB1 Product.*", "OEMEP.*.OEMEP Product.*"];

public string GetFFUFileName() => $"OEMEP_128GB_HalfSplit.ffu";
public override string FFUFileName => $"OEMEP_128GB_HalfSplit.ffu";

public string GetDriverDefinitionPath() => $@"\definitions\Desktop\ARM64\Internal\epsilon.xml";
public override string DriverDefinitionPath => $@"\definitions\Desktop\ARM64\Internal\epsilon.xml";

public ulong GetDiskTotalSize() =>
public override ulong DiskTotalSize =>
//return 239_683_502_080; // 256GB (Bigger variant);
//return 239_651_758_080; // 256GB (Smaller variant);
111_723_675_648; // 128GB;

public uint GetDiskSectorSize() => 4096;
public override uint DiskSectorSize => 4096;

// OEMEP DV UFS LUN 0 Partition Layout
public GPTPartition[] GetPartitionLayout() => [
public override GPTPartition[] PartitionLayout => [
new()
{
TypeGUID = new Guid("2c86e742-745e-4fdd-bfd8-b6a7ac638772"),
Expand Down Expand Up @@ -78,10 +78,10 @@ public GPTPartition[] GetPartitionLayout() => [
}
];

public SplittingStrategy GetSplittingStrategy() => SplittingStrategy.HalfSplit;
public override SplittingStrategy SplittingStrategy => SplittingStrategy.HalfSplit;

public Guid GetDiskGuid() => new Guid("efa6243a-085f-e745-f2ce-54d39ef34351");
public override Guid DiskGuid => new Guid("efa6243a-085f-e745-f2ce-54d39ef34351");

public ulong GetCustomSplittingAndroidDesiredSpace() => 4_294_967_296;
public override ulong CustomSplittingAndroidDesiredSpace => 4_294_967_296;
}
}
22 changes: 11 additions & 11 deletions FirmwareGen/DeviceProfiles/EpsilonHalfSplit256GB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@

namespace FirmwareGen.DeviceProfiles
{
internal class EpsilonHalfSplit256GB : IDeviceProfile
internal class EpsilonHalfSplit256GB : DeviceProfile
{
public string[] GetSupplementaryBCDCommands() => [];
public override string[] SupplementaryBCDCommands => [];

public string[] GetPlatformIDs() => ["Microsoft Corporation.Surface.Surface Duo.1930", "OEMB1.*.OEMB1 Product.*", "OEMEP.*.OEMEP Product.*"];
public override string[] PlatformIDs => ["Microsoft Corporation.Surface.Surface Duo.1930", "OEMB1.*.OEMB1 Product.*", "OEMEP.*.OEMEP Product.*"];

public string GetFFUFileName() => $"OEMEP_256GB_HalfSplit.ffu";
public override string FFUFileName => $"OEMEP_256GB_HalfSplit.ffu";

public string GetDriverDefinitionPath() => $@"\definitions\Desktop\ARM64\Internal\epsilon.xml";
public override string DriverDefinitionPath => $@"\definitions\Desktop\ARM64\Internal\epsilon.xml";

public ulong GetDiskTotalSize() =>
public override ulong DiskTotalSize =>
//return 239_683_502_080; // 256GB (Bigger variant);
239_651_758_080; // 256GB (Smaller variant);//return 111_723_675_648; // 128GB;

public uint GetDiskSectorSize() => 4096;
public override uint DiskSectorSize => 4096;

// OEMEP DV UFS LUN 0 Partition Layout
public GPTPartition[] GetPartitionLayout() => [
public override GPTPartition[] PartitionLayout => [
new()
{
TypeGUID = new Guid("2c86e742-745e-4fdd-bfd8-b6a7ac638772"),
Expand Down Expand Up @@ -77,10 +77,10 @@ public GPTPartition[] GetPartitionLayout() => [
}
];

public SplittingStrategy GetSplittingStrategy() => SplittingStrategy.HalfSplit;
public override SplittingStrategy SplittingStrategy => SplittingStrategy.HalfSplit;

public Guid GetDiskGuid() => new Guid("efa6243a-085f-e745-f2ce-54d39ef34351");
public override Guid DiskGuid => new Guid("efa6243a-085f-e745-f2ce-54d39ef34351");

public ulong GetCustomSplittingAndroidDesiredSpace() => 4_294_967_296;
public override ulong CustomSplittingAndroidDesiredSpace => 4_294_967_296;
}
}
22 changes: 11 additions & 11 deletions FirmwareGen/DeviceProfiles/EpsilonMaximizedForWindows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@

namespace FirmwareGen.DeviceProfiles
{
internal class EpsilonMaximizedForWindows : IDeviceProfile
internal class EpsilonMaximizedForWindows : DeviceProfile
{
public string[] GetSupplementaryBCDCommands() => [];
public override string[] SupplementaryBCDCommands => [];

public string[] GetPlatformIDs() => ["Microsoft Corporation.Surface.Surface Duo.1930", "OEMB1.*.OEMB1 Product.*", "OEMEP.*.OEMEP Product.*"];
public override string[] PlatformIDs => ["Microsoft Corporation.Surface.Surface Duo.1930", "OEMB1.*.OEMB1 Product.*", "OEMEP.*.OEMEP Product.*"];

public string GetFFUFileName() => $"OEMEP_128GB_HalfSplit.ffu";
public override string FFUFileName => $"OEMEP_128GB_HalfSplit.ffu";

public string GetDriverDefinitionPath() => $@"\definitions\Desktop\ARM64\Internal\epsilon.xml";
public override string DriverDefinitionPath => $@"\definitions\Desktop\ARM64\Internal\epsilon.xml";

public ulong GetDiskTotalSize() =>
public override ulong DiskTotalSize =>
//return 239_683_502_080; // 256GB (Bigger variant);
//return 239_651_758_080; // 256GB (Smaller variant);
111_723_675_648; // 128GB;

public uint GetDiskSectorSize() => 4096;
public override uint DiskSectorSize => 4096;

// OEMEP DV UFS LUN 0 Partition Layout
public GPTPartition[] GetPartitionLayout() => [
public override GPTPartition[] PartitionLayout => [
new()
{
TypeGUID = new Guid("2c86e742-745e-4fdd-bfd8-b6a7ac638772"),
Expand Down Expand Up @@ -78,10 +78,10 @@ public GPTPartition[] GetPartitionLayout() => [
}
];

public SplittingStrategy GetSplittingStrategy() => SplittingStrategy.MaximizedForWindows;
public override SplittingStrategy SplittingStrategy => SplittingStrategy.MaximizedForWindows;

public Guid GetDiskGuid() => new Guid("efa6243a-085f-e745-f2ce-54d39ef34351");
public override Guid DiskGuid => new Guid("efa6243a-085f-e745-f2ce-54d39ef34351");

public ulong GetCustomSplittingAndroidDesiredSpace() => 4_294_967_296;
public override ulong CustomSplittingAndroidDesiredSpace => 4_294_967_296;
}
}
22 changes: 11 additions & 11 deletions FirmwareGen/DeviceProfiles/MTP8150MaximizedForWindows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@

namespace FirmwareGen.DeviceProfiles
{
internal class MTP8150MaximizedForWindows : IDeviceProfile
internal class MTP8150MaximizedForWindows : DeviceProfile
{
public string[] GetSupplementaryBCDCommands() => [];
public override string[] SupplementaryBCDCommands => [];

public string[] GetPlatformIDs() => ["Microsoft Corporation.Surface.MTP.SM8150"];
public override string[] PlatformIDs => ["Microsoft Corporation.Surface.MTP.SM8150"];

public string GetFFUFileName() => $"QCOM_MTP_8150_MaximizedForWindows.ffu";
public override string FFUFileName => $"QCOM_MTP_8150_MaximizedForWindows.ffu";

public string GetDriverDefinitionPath() => $@"\definitions\Desktop\ARM64\Internal\mtp855.xml";
public override string DriverDefinitionPath => $@"\definitions\Desktop\ARM64\Internal\mtp855.xml";

public ulong GetDiskTotalSize() => 123_371_257_856; // 128GB;
public override ulong DiskTotalSize => 123_371_257_856; // 128GB;

public uint GetDiskSectorSize() => 4096;
public override uint DiskSectorSize => 4096;

// MTP855 UFS LUN 0 Partition Layout
public GPTPartition[] GetPartitionLayout() => [
public override GPTPartition[] PartitionLayout => [
new()
{
TypeGUID = new Guid("2c86e742-745e-4fdd-bfd8-b6a7ac638772"),
Expand Down Expand Up @@ -129,10 +129,10 @@ public GPTPartition[] GetPartitionLayout() => [
}
];

public SplittingStrategy GetSplittingStrategy() => SplittingStrategy.MaximizedForWindows;
public override SplittingStrategy SplittingStrategy => SplittingStrategy.MaximizedForWindows;

public Guid GetDiskGuid() => new Guid("efa6243a-085f-e745-f2ce-54d39ef34351");
public override Guid DiskGuid => new Guid("efa6243a-085f-e745-f2ce-54d39ef34351");

public ulong GetCustomSplittingAndroidDesiredSpace() => 4_294_967_296;
public override ulong CustomSplittingAndroidDesiredSpace => 4_294_967_296;
}
}
22 changes: 11 additions & 11 deletions FirmwareGen/DeviceProfiles/ZetaHalfSplit128GB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@

namespace FirmwareGen.DeviceProfiles
{
public class ZetaHalfSplit128GB : IDeviceProfile
public class ZetaHalfSplit128GB : DeviceProfile
{
public string[] GetSupplementaryBCDCommands() => [];
public override string[] SupplementaryBCDCommands => [];

public string[] GetPlatformIDs() => ["Microsoft Corporation.Surface.Surface Duo 2.1995",
public override string[] PlatformIDs => ["Microsoft Corporation.Surface.Surface Duo 2.1995",
"Microsoft Corporation.Surface.Surface Duo 2.1968",
"OEMC1.*.OEMC1 Product.*",
"OEMZE.*.OEMZE Product.*"];

public string GetFFUFileName() => $"OEMZE_128GB_HalfSplit.ffu";
public override string FFUFileName => $"OEMZE_128GB_HalfSplit.ffu";

public string GetDriverDefinitionPath() => $@"\definitions\Desktop\ARM64\Internal\zeta.xml";
public override string DriverDefinitionPath => $@"\definitions\Desktop\ARM64\Internal\zeta.xml";

public ulong GetDiskTotalSize() => 110_394_081_280; // 128GB;
public override ulong DiskTotalSize => 110_394_081_280; // 128GB;

public uint GetDiskSectorSize() => 4096;
public override uint DiskSectorSize => 4096;

// OEMZE MP UFS LUN 0 Partition Layout
public GPTPartition[] GetPartitionLayout() => [
public override GPTPartition[] PartitionLayout => [
new()
{
TypeGUID = new Guid("2c86e742-745e-4fdd-bfd8-b6a7ac638772"),
Expand Down Expand Up @@ -96,10 +96,10 @@ public GPTPartition[] GetPartitionLayout() => [
}
];

public SplittingStrategy GetSplittingStrategy() => SplittingStrategy.HalfSplit;
public override SplittingStrategy SplittingStrategy => SplittingStrategy.HalfSplit;

public Guid GetDiskGuid() => new Guid("efa6243a-085f-e745-f2ce-54d39ef34351");
public override Guid DiskGuid => new Guid("efa6243a-085f-e745-f2ce-54d39ef34351");

public ulong GetCustomSplittingAndroidDesiredSpace() => 4_294_967_296;
public override ulong CustomSplittingAndroidDesiredSpace => 4_294_967_296;
}
}
22 changes: 11 additions & 11 deletions FirmwareGen/DeviceProfiles/ZetaHalfSplit256GB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@

namespace FirmwareGen.DeviceProfiles
{
internal class ZetaHalfSplit256GB : IDeviceProfile
internal class ZetaHalfSplit256GB : DeviceProfile
{
public string[] GetSupplementaryBCDCommands() => [];
public override string[] SupplementaryBCDCommands => [];

public string[] GetPlatformIDs() => ["Microsoft Corporation.Surface.Surface Duo 2.1995",
public override string[] PlatformIDs => ["Microsoft Corporation.Surface.Surface Duo 2.1995",
"Microsoft Corporation.Surface.Surface Duo 2.1968",
"OEMC1.*.OEMC1 Product.*",
"OEMZE.*.OEMZE Product.*"];

public string GetFFUFileName() => $"OEMZE_256GB_HalfSplit.ffu";
public override string FFUFileName => $"OEMZE_256GB_HalfSplit.ffu";

public string GetDriverDefinitionPath() => $@"\definitions\Desktop\ARM64\Internal\zeta.xml";
public override string DriverDefinitionPath => $@"\definitions\Desktop\ARM64\Internal\zeta.xml";

public ulong GetDiskTotalSize() => 238_353_907_712; // 256GB;
public override ulong DiskTotalSize => 238_353_907_712; // 256GB;

public uint GetDiskSectorSize() => 4096;
public override uint DiskSectorSize => 4096;

// OEMZE MP UFS LUN 0 Partition Layout
public GPTPartition[] GetPartitionLayout() => [
public override GPTPartition[] PartitionLayout => [
new()
{
TypeGUID = new Guid("2c86e742-745e-4fdd-bfd8-b6a7ac638772"),
Expand Down Expand Up @@ -96,10 +96,10 @@ public GPTPartition[] GetPartitionLayout() => [
}
];

public SplittingStrategy GetSplittingStrategy() => SplittingStrategy.HalfSplit;
public override SplittingStrategy SplittingStrategy => SplittingStrategy.HalfSplit;

public Guid GetDiskGuid() => new Guid("efa6243a-085f-e745-f2ce-54d39ef34351");
public override Guid DiskGuid => new Guid("efa6243a-085f-e745-f2ce-54d39ef34351");

public ulong GetCustomSplittingAndroidDesiredSpace() => 4_294_967_296;
public override ulong CustomSplittingAndroidDesiredSpace => 4_294_967_296;
}
}
22 changes: 11 additions & 11 deletions FirmwareGen/DeviceProfiles/ZetaHalfSplit512GB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@

namespace FirmwareGen.DeviceProfiles
{
internal class ZetaHalfSplit512GB : IDeviceProfile
internal class ZetaHalfSplit512GB : DeviceProfile
{
public string[] GetSupplementaryBCDCommands() => [];
public override string[] SupplementaryBCDCommands => [];

public string[] GetPlatformIDs() => ["Microsoft Corporation.Surface.Surface Duo 2.1995",
public override string[] PlatformIDs => ["Microsoft Corporation.Surface.Surface Duo 2.1995",
"Microsoft Corporation.Surface.Surface Duo 2.1968",
"OEMC1.*.OEMC1 Product.*",
"OEMZE.*.OEMZE Product.*"];

public string GetFFUFileName() => $"OEMZE_512GB_HalfSplit.ffu";
public override string FFUFileName => $"OEMZE_512GB_HalfSplit.ffu";

public string GetDriverDefinitionPath() => $@"\definitions\Desktop\ARM64\Internal\zeta.xml";
public override string DriverDefinitionPath => $@"\definitions\Desktop\ARM64\Internal\zeta.xml";

public ulong GetDiskTotalSize() => throw new NotImplementedException();
public override ulong DiskTotalSize => throw new NotImplementedException();

public uint GetDiskSectorSize() => 4096;
public override uint DiskSectorSize => 4096;

// OEMZE MP UFS LUN 0 Partition Layout
public GPTPartition[] GetPartitionLayout() => [
public override GPTPartition[] PartitionLayout => [
new()
{
TypeGUID = new Guid("2c86e742-745e-4fdd-bfd8-b6a7ac638772"),
Expand Down Expand Up @@ -96,10 +96,10 @@ public GPTPartition[] GetPartitionLayout() => [
}
];

public SplittingStrategy GetSplittingStrategy() => SplittingStrategy.HalfSplit;
public override SplittingStrategy SplittingStrategy => SplittingStrategy.HalfSplit;

public Guid GetDiskGuid() => new Guid("efa6243a-085f-e745-f2ce-54d39ef34351");
public override Guid DiskGuid => new Guid("efa6243a-085f-e745-f2ce-54d39ef34351");

public ulong GetCustomSplittingAndroidDesiredSpace() => 4_294_967_296;
public override ulong CustomSplittingAndroidDesiredSpace => 4_294_967_296;
}
}
Loading

0 comments on commit be3841c

Please sign in to comment.