Skip to content

Commit

Permalink
Implement POC for Surface Duo FFUs
Browse files Browse the repository at this point in the history
  • Loading branch information
gus33000 committed Jan 14, 2024
1 parent d3f9439 commit 39600a3
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 18 deletions.
3 changes: 3 additions & 0 deletions Img2Ffu/Manifest/FullFlashManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ internal class FullFlashManifest
public string OSVersion;
public string Description = "Update on: " + DateTime.Now.ToString("u") + "::\r\n";
public string Version = "2.0";
public string DevicePlatformId3;
public string DevicePlatformId2;
public string DevicePlatformId1;
public string DevicePlatformId0;
}
}
53 changes: 38 additions & 15 deletions Img2Ffu/Manifest/ManifestIni.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,61 +53,84 @@ internal static string BuildUpManifest(FullFlashManifest fullFlash, StoreManifes
Manifest += $"Version = {fullFlash.Version}\r\n";
}

if (!string.IsNullOrEmpty(fullFlash.DevicePlatformId3))
{
Manifest += $"DevicePlatformId3 = {fullFlash.DevicePlatformId3}\r\n";
}

if (!string.IsNullOrEmpty(fullFlash.DevicePlatformId2))
{
Manifest += $"DevicePlatformId2 = {fullFlash.DevicePlatformId2}\r\n";
}

if (!string.IsNullOrEmpty(fullFlash.DevicePlatformId1))
{
Manifest += $"DevicePlatformId1 = {fullFlash.DevicePlatformId1}\r\n";
}

if (!string.IsNullOrEmpty(fullFlash.DevicePlatformId0))
{
Manifest += $"DevicePlatformId0 = {fullFlash.DevicePlatformId0}\r\n";
}

Manifest += "\r\n[Store]\r\n";
Manifest += $"OnlyAllocateDefinedGptEntries = False\r\n";
Manifest += $"StoreId = {{5a585bae-900b-41b5-b736-a4cecffc34b4}}\r\n";
Manifest += $"IsMainOSStore = False\r\n";
Manifest += $"DevicePath = VenHw(860845C1-BE09-4355-8BC1-30D64FF8E63A)\r\n";
Manifest += $"StoreType = Default\r\n";
Manifest += $"MinSectorCount = {store.MinSectorCount}\r\n";
Manifest += $"SectorSize = {store.SectorSize}\r\n";
Manifest += "\r\n";

foreach (PartitionManifest partition in partitions)
{
Manifest += "[Partition]\r\n";
if (partition.RequiredToFlash.HasValue)

if (partition.ByteAlignment.HasValue)
{
Manifest += $"RequiredToFlash = {(partition.RequiredToFlash.Value ? "True" : "False")}\r\n";
Manifest += $"ByteAlignment = {partition.ByteAlignment.Value}\r\n";
}

if (!string.IsNullOrEmpty(partition.Name))
if (!string.IsNullOrEmpty(partition.FileSystem))
{
Manifest += $"Name = {partition.Name}\r\n";
Manifest += $"FileSystem = {partition.FileSystem}\r\n";
}

Manifest += $"UsedSectors = {partition.UsedSectors}\r\n";

if (partition.UseAllSpace.HasValue)
{
Manifest += $"UseAllSpace = {(partition.UseAllSpace.Value ? "True" : "False")}\r\n";
}

if (partition.Type != null)
{
Manifest += $"Type = {partition.Type}\r\n";
}

Manifest += $"TotalSectors = {partition.TotalSectors}\r\n";
if (!string.IsNullOrEmpty(partition.Primary))

if (partition.RequiredToFlash.HasValue)
{
Manifest += $"Primary = {partition.Primary}\r\n";
Manifest += $"RequiredToFlash = {(partition.RequiredToFlash.Value ? "True" : "False")}\r\n";
}

if (!string.IsNullOrEmpty(partition.FileSystem))
if (!string.IsNullOrEmpty(partition.Primary))
{
Manifest += $"FileSystem = {partition.FileSystem}\r\n";
Manifest += $"Primary = {partition.Primary}\r\n";
}

if (partition.ByteAlignment.HasValue)
if (!string.IsNullOrEmpty(partition.Name))
{
Manifest += $"ByteAlignment = {partition.ByteAlignment.Value}\r\n";
Manifest += $"Name = {partition.Name}\r\n";
}

if (partition.ClusterSize.HasValue)
{
Manifest += $"ClusterSize = {partition.ClusterSize.Value}\r\n";
}

if (partition.UseAllSpace.HasValue)
{
Manifest += $"UseAllSpace = {(partition.UseAllSpace.Value ? "True" : "False")}\r\n";
}

Manifest += "\r\n";
}

Expand Down
26 changes: 23 additions & 3 deletions Img2Ffu/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,13 @@ private static (uint MinSectorCount, List<GPT.Partition> partitions, byte[] Stor
WriteDescriptorLength = (uint)WriteDescriptorBuffer.Length,
PlatformIds = PlatformIDs,
BlockSize = BlockSize,

// POC Begins
NumberOfStores = 1,
StoreIndex = 1,
DevicePath = "VenHw(860845C1-BE09-4355-8BC1-30D64FF8E63A)",
StorePayloadSize = (ulong)BlockPayloads.Count * BlockSize // TODO: Verify this!
// POC Ends
};

byte[] StoreHeaderBuffer = store.GetResultingBuffer(FlashUpdateVersion, FlashUpdateType.Full, CompressionAlgorithm.None);
Expand All @@ -329,9 +336,20 @@ private static void GenerateFFU(string InputFile, string FFUFile, string Platfor
return;
}

FlashUpdateVersion FlashUpdateVersion = FlashUpdateVersion.V1;
//FlashUpdateVersion FlashUpdateVersion = FlashUpdateVersion.V1;
List<DeviceTargetInfo> deviceTargetInfos = [];
string[] PlatformIDs = [PlatformID];
//string[] PlatformIDs = [PlatformID];

// POC Begins
FlashUpdateVersion FlashUpdateVersion = FlashUpdateVersion.V2;
string[] PlatformIDs =
[
"Microsoft Corporation.Surface.Surface Duo.1930",
"OEMB1.*.OEMB1 Product.*",
"OEMEP.*.OEMEP Product.*"
];
SectorSize = 4096;
// POC Ends

Logging.Log($"Input image: {InputFile}");
Logging.Log($"Destination image: {FFUFile}");
Expand All @@ -349,7 +367,9 @@ private static void GenerateFFU(string InputFile, string FFUFile, string Platfor
FullFlashManifest FullFlash = new()
{
OSVersion = OperatingSystemVersion,
DevicePlatformId0 = PlatformID,
DevicePlatformId2 = PlatformIDs[2],
DevicePlatformId1 = PlatformIDs[1],
DevicePlatformId0 = PlatformIDs[0],
AntiTheftVersion = AntiTheftVersion
};

Expand Down

0 comments on commit 39600a3

Please sign in to comment.