[CmdletBinding()]
param(
[Parameter(Mandatory=$true)][string]$ImagePath,
[Parameter(Mandatory=$true)][string]$VerifiedBootResult,
[Parameter(Mandatory=$true)][string]$VerifiedHostResult,
[string]$ToolsRoot,
[string]$Version='dev',
[string]$OutputDirectory
)
$ErrorActionPreference='Stop'
$taskRoot=[IO.Path]::GetFullPath((Join-Path $PSScriptRoot '../..'))
if($Version -cnotmatch '^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$'){throw 'Version must be a short filename-safe label.'}
# The launcher owns the same mandatory image, kernel, source and desktop gates.
$verified=. (Join-Path $PSScriptRoot 'Open.ps1') -ImagePath $ImagePath -VerifiedBootResult $VerifiedBootResult -ToolsRoot $ToolsRoot -ValidateOnly
if($verified.Packaged){throw 'Package a verified repository build, rather than repackaging an existing distribution.'}
# Validation-only dot-sourcing shares validators without opening a guest.
$hostPath=(Resolve-Path -LiteralPath $VerifiedHostResult).Path
$hostProof=Read-IndependentJson $hostPath
if($hostProof.HostOnly -ne $true -or $hostProof.GuestExecution -ne $false -or $hostProof.Passed -ne $true -or !$hostProof.SourceHashes -or !$hostProof.Suites) {
throw 'A passing source-bound host test receipt is required.'
}
Assert-IndependentSourceMap $hostProof.SourceHashes $taskRoot 'host verification'
if(!$hostProof.SourceHashes.PSObject.Properties['Source/XFESystem.NativeKernel/Ps2Decoder.cs'] -or
!$hostProof.SourceHashes.PSObject.Properties['Tests/XFESystem.Platform.Tests/XFESystem.Platform.Tests.csproj']) {
throw 'Host verification must include the independent Platform tests and the production PS/2 decoder.'
}
foreach($entry in $verified.Snapshot.PSObject.Properties) {
$hostEntry=$hostProof.SourceHashes.PSObject.Properties[$entry.Name]
if($hostEntry -and [string]$hostEntry.Value -cne [string]$entry.Value) { throw ('Host and guest source hashes differ: '+$entry.Name) }
}
$hostArtifacts=@()
$suiteNames=@()
foreach($suite in $hostProof.Suites) {
if([string]$suite.Suite -cnotmatch '^[A-Za-z0-9._-]+$' -or $suiteNames -contains $suite.Suite -or $suite.Failed -ne 0 -or [int]$suite.Passed -le 0) {
throw 'Host suite names and successful counters are required.'
}
$suiteNames+=([string]$suite.Suite)
$logPath=(Resolve-Path -LiteralPath $suite.Log).Path
if($suite.LogSha256){Assert-IndependentHash $logPath $suite.LogSha256 ('host log '+$suite.Suite)}
$hostArtifacts+= [pscustomobject]@{Source=$logPath;Destination=('Validation/Host/'+$suite.Suite+'.log');Sha256=(Get-IndependentHash $logPath)}
if($suite.Trx) {
$trxPath=(Resolve-Path -LiteralPath $suite.Trx).Path
if($suite.TrxSha256){Assert-IndependentHash $trxPath $suite.TrxSha256 ('host TRX '+$suite.Suite)}
[xml]$trx=Get-Content -LiteralPath $trxPath -Raw -Encoding UTF8
$counter=$trx.SelectSingleNode("//*[local-name()='Counters']")
if(!$counter -or [int]$counter.failed -ne 0 -or [int]$counter.passed -ne [int]$suite.Passed -or
[int]$counter.executed -ne [int]$counter.passed -or [int]$counter.total -ne [int]$counter.passed) {
throw ('Actual host TRX counters are incomplete or differ: '+$suite.Suite)
}
$hostArtifacts+= [pscustomobject]@{Source=$trxPath;Destination=('Validation/Host/'+$suite.Suite+'.trx');Sha256=(Get-IndependentHash $trxPath)}
} elseif($suite.Receipt -and $suite.ReceiptSha256) {
$nativePath=(Resolve-Path -LiteralPath $suite.Receipt).Path
Assert-IndependentHash $nativePath $suite.ReceiptSha256 ('native host receipt '+$suite.Suite)
$native=Read-IndependentJson $nativePath
if($native.Passed -ne $true -or $native.Failed -ne 0 -or $null -eq $native.ExitCode -or $native.ExitCode -ne 0 -or
[int]$native.PassedCount -ne [int]$suite.Passed) { throw ('Native host test execution did not pass: '+$suite.Suite) }
$hostArtifacts+= [pscustomobject]@{Source=$nativePath;Destination=('Validation/Host/'+$suite.Suite+'.json');Sha256=(Get-IndependentHash $nativePath)}
} else {throw ('Actual TRX or source-bound native execution receipt is required: '+$suite.Suite)}
}
if($suiteNames -notcontains 'Platform' -or $suiteNames -notcontains 'NativeContracts') {
throw 'The final host receipt must include Platform and NativeContracts suites.'
}
$licensesRoot=Join-Path $PSScriptRoot 'Licenses'
$licensesPath=Get-IndependentFile $licensesRoot 'Manifest.json'
$licenses=Read-IndependentJson $licensesPath
if($licenses.Schema -cne 'XFESystem.IndependentLicenses.V1' -or $licenses.ContainsCosmos -ne $false -or
$licenses.ExcludesLegacyCollectedGraph -ne $true -or !$licenses.Files -or [int]$licenses.PackageCount -ne @($licenses.Packages).Count) {
throw 'The complete independent application license manifest is required.'
}
Assert-IndependentHash (Get-IndependentFile $taskRoot 'Source/XFESystem.NativeRuntime/Application/packages.lock.json') $licenses.ApplicationLockSha256 'license application lock'
Assert-IndependentHash (Get-IndependentFile $taskRoot 'Tools/IndependentKernel/Runtime/NativeToolchain.json') $licenses.RuntimeToolchainLockSha256 'license runtime toolchain lock'
Assert-IndependentHash (Get-IndependentFile $taskRoot 'Tools/JintCleanupPatch/packages.lock.json') $licenses.JintPatchToolLockSha256 'license Jint patch tool lock'
Assert-IndependentHash (Get-IndependentFile $licensesRoot 'LicenseSources.json') $licenses.SourcesSha256 'license sources manifest'
$licenseNames=@()
foreach($entry in $licenses.Files) {
if($licenseNames -contains $entry.Path) {throw ('Duplicate license path: '+$entry.Path)}
$licenseNames+=([string]$entry.Path)
$path=Get-IndependentFile $licensesRoot $entry.Path
Assert-IndependentHash $path $entry.Sha256 ('license '+$entry.Path)
if((Get-Item -LiteralPath $path).Length -ne $entry.Bytes) {throw ('License length differs: '+$entry.Path)}
}
if(!$OutputDirectory){$OutputDirectory=Join-Path $taskRoot 'dist'}
$outputRoot=[IO.Path]::GetFullPath($OutputDirectory)
[void][IO.Directory]::CreateDirectory($outputRoot)
$packageId='XFESystem-Independent-RAM-'+$Version+'-'+[DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds()+'-'+[Guid]::NewGuid().ToString('N').Substring(0,8)
$package=Join-Path $outputRoot $packageId
$zipPath=$package+'.zip'
if((Test-Path -LiteralPath $package) -or (Test-Path -LiteralPath $zipPath)){throw 'Refusing to overwrite an existing package or ZIP.'}
[void][IO.Directory]::CreateDirectory($package)
function Copy-IndependentBoundFile([string]$Source,[string]$Relative,[string]$Expected) {
Assert-IndependentHash $Source $Expected ('package input '+$Relative)
if([IO.Path]::IsPathRooted($Relative)){throw 'Package destination must be relative.'}
$destination=[IO.Path]::GetFullPath((Join-Path $package $Relative))
if(!$destination.StartsWith($package+[IO.Path]::DirectorySeparatorChar,[StringComparison]::OrdinalIgnoreCase)) {throw 'Package destination escaped the output directory.'}
[void][IO.Directory]::CreateDirectory((Split-Path -Parent $destination))
Copy-Item -LiteralPath $Source -Destination $destination
Assert-IndependentHash $destination $Expected ('package copy '+$Relative)
}
try {
Copy-IndependentBoundFile $verified.ImagePath 'System.img' $verified.Boot.ImageSha256
Copy-IndependentBoundFile $verified.ImageManifestPath 'System.img.json' (Get-IndependentHash $verified.ImageManifestPath)
Copy-IndependentBoundFile $verified.KernelPath 'Kernel.elf' $verified.Boot.KernelSha256
Copy-IndependentBoundFile $verified.BootPath 'Validation/Boot.json' (Get-IndependentHash $verified.BootPath)
Copy-IndependentBoundFile $verified.BuildPath 'Validation/BuildReceipt.json' $verified.Boot.BuildReceiptSha256
Copy-IndependentBoundFile $verified.SnapshotPath 'Validation/SourceSnapshot.json' $verified.Boot.SourceSnapshotSha256
Copy-IndependentBoundFile $hostPath 'Validation/Host.json' (Get-IndependentHash $hostPath)
foreach($entry in $verified.Snapshot.PSObject.Properties) {
Copy-IndependentBoundFile (Get-IndependentFile $taskRoot $entry.Name) ('SourceSnapshot/'+$entry.Name) ([string]$entry.Value)
}
foreach($entry in $hostProof.SourceHashes.PSObject.Properties) {
Copy-IndependentBoundFile (Get-IndependentFile $taskRoot $entry.Name) ('HostSourceSnapshot/'+$entry.Name) ([string]$entry.Value)
}
foreach($artifact in $hostArtifacts) {Copy-IndependentBoundFile $artifact.Source $artifact.Destination $artifact.Sha256}
foreach($file in Get-ChildItem -LiteralPath $licensesRoot -File -Recurse) {
$relative=$file.FullName.Substring($licensesRoot.Length+1).Replace('\','/')
Copy-IndependentBoundFile $file.FullName ('Licenses/'+$relative) (Get-IndependentHash $file.FullName)
}
foreach($firmware in @($verified.FirmwareCode,$verified.FirmwareVars)) {
Copy-IndependentBoundFile $firmware ('Firmware/'+[IO.Path]::GetFileName($firmware)) (Get-IndependentHash $firmware)
}
[void][IO.Directory]::CreateDirectory((Join-Path $package 'Tools/IndependentKernel'))
Copy-IndependentBoundFile (Join-Path $PSScriptRoot 'Open.ps1') 'Tools/IndependentKernel/Open.ps1' (Get-IndependentHash (Join-Path $PSScriptRoot 'Open.ps1'))
Copy-IndependentBoundFile $PSCommandPath 'Tools/IndependentKernel/Package.ps1' (Get-IndependentHash $PSCommandPath)
Copy-IndependentBoundFile (Join-Path $taskRoot 'THIRD_PARTY.md') 'ThirdParty.md' (Get-IndependentHash (Join-Path $taskRoot 'THIRD_PARTY.md'))
foreach($file in Get-ChildItem -LiteralPath (Split-Path -Parent $verified.BootPath) -File) {
if($file.Extension -notin @('.png','.log','.txt') -or ($file.Attributes -band [IO.FileAttributes]::ReparsePoint)) {continue}
Copy-IndependentBoundFile $file.FullName ('Validation/Guest/'+$file.Name) (Get-IndependentHash $file.FullName)
}
[ordered]@{Kind='XfeIndependentFirmwareLock';Firmware=$verified.FirmwareLock.Firmware} | ConvertTo-Json -Depth 4 |
Set-Content -LiteralPath (Join-Path $package 'Validation/Firmware.json') -Encoding UTF8
@'
[CmdletBinding()]
param([string]$QemuPath,[ValidateSet('gtk','sdl')][string]$DisplayBackend='gtk',[switch]$Fullscreen,[switch]$PlanOnly)
$ErrorActionPreference='Stop'
& (Join-Path $PSScriptRoot 'Tools/IndependentKernel/Open.ps1') -ImagePath (Join-Path $PSScriptRoot 'System.img') -VerifiedBootResult (Join-Path $PSScriptRoot 'Validation/Boot.json') -QemuPath $QemuPath -DisplayBackend $DisplayBackend -Fullscreen:$Fullscreen -PlanOnly:$PlanOnly
'@ | Set-Content -LiteralPath (Join-Path $package 'Start.ps1') -Encoding UTF8
@'
# XFESystem 独立内核 RAM 实验版
此包使用自研 C# 内核/HAL/调度与 Microsoft .NET 10 NativeAOT 运行时,不包含 Cosmos 内核或运行时。完整第三方声明位于 Licenses;自研范围和外部引用见 ThirdParty.md。
文件保存在内存中,退出或关机后消失。当前执行一个 BSP,CPU 软件绘制,x87/SSE 上下文;没有持久化存储或独立进程隔离。
Validation/Boot.json 记录本包同一镜像的真实 QEMU 桌面、PS/2 输入和浏览器 DOM 验收;BrowserAcceptancePassed 字段单独说明 Monaco 验收结果。Validation/Host.json 与逐项 TRX/原生测试记录保留宿主结果,宿主通过不能替代来宾执行。
这是 RAM 实验版。实体启动、实体 USB HID 输入、网络、CUDA/GPU 和完整稳定性均未验收,不能标为完整发行版。CMOS RTC 按 UTC 解释;实体机的 RTC 配置和准确性尚未验收。
在 Windows 安装 QEMU 后执行:
powershell -NoProfile -ExecutionPolicy Bypass -File .\Start.ps1 -QemuPath "C:\Program Files\qemu\qemu-system-x86_64.exe"
默认打开 TCG / Q35 / x86_64 / 1 GiB 的 GTK 交互窗口,使用 Q35 内置 PS/2 键盘鼠标,RTC 设为 UTC。可选择 -DisplayBackend sdl 或 -Fullscreen。启动前核验完整包、镜像、ELF、固件、验收记录及所有编译源码快照;每次复制镜像和固件变量到新的 build/IndependentKernel/Interactive-* 会话目录,串口日志位于同目录 Serial.log。关闭 QEMU 窗口结束。
源码与资源快照在 SourceSnapshot,宿主测试源码快照在 HostSourceSnapshot,所有文件 SHA256 在 Manifest.json。它们保存本次实际构建和测试的字节;完整复现命令与版本锁要求见 Reproduce.md。
'@ | Set-Content -LiteralPath (Join-Path $package 'Readme.md') -Encoding UTF8
@'
# 复现与校验
在 XFESystem 仓库中使用 Manifest.json 的源码哈希核对 SourceSnapshot 中所有文件;保留仓库目录结构,按各 packages.lock.json 恢复固定依赖,工具版本锁位于 Tools/IndependentKernel/Runtime/NativeToolchain.json 与 Tools/CSharpBoot/BflatToolchain.json。
powershell -NoProfile -ExecutionPolicy Bypass -File Tools/IndependentKernel/BuildSystem.ps1
python Tools/IndependentKernel/TestBoot.py <新生成的Kernel.elf> --virtual-cpus 8 --desktop --browser --timeout 360
powershell -NoProfile -ExecutionPolicy Bypass -File Tools/TestCSharp.ps1
python Tools/IndependentKernel/CollectLicenses.py
powershell -NoProfile -ExecutionPolicy Bypass -File Tools/IndependentKernel/Package.ps1 -ImagePath <通过的System.img> -VerifiedBootResult <通过的Result.json> -VerifiedHostResult <宿主Result.json>
编译、链接成功不等于运行验收;每次新建产物需要新 guest/host 记录。本包原始精确编译命令保存在 Validation/BuildReceipt.json;完整包与携带的源码快照、固件可通过下列命令只读核验:
powershell -NoProfile -ExecutionPolicy Bypass -File Tools/IndependentKernel/Open.ps1 -ImagePath System.img -VerifiedBootResult Validation/Boot.json -ValidateOnly
SourceSnapshot 只保存实际编译输入,复现需要完整仓库中匹配的工具与锁文件。HostSourceSnapshot 保存实际宿主检查输入。各原始 JSON 的旧绝对路径用于出处记录;打包启动入口通过包内固定相对路径定位已验证文件。
'@ | Set-Content -LiteralPath (Join-Path $package 'Reproduce.md') -Encoding UTF8
Assert-IndependentSourceMap $verified.Snapshot $taskRoot 'final guest source snapshot'
Assert-IndependentSourceMap $hostProof.SourceHashes $taskRoot 'final host source snapshot'
$files=@(foreach($file in Get-ChildItem -LiteralPath $package -File -Recurse | Sort-Object FullName) {
[ordered]@{Path=$file.FullName.Substring($package.Length+1).Replace('\','/');Bytes=$file.Length;Sha256=(Get-IndependentHash $file.FullName)}
})
$manifest=[ordered]@{Kind='XfeIndependentRamDesktopPackage';Version=$Version;ContainsCosmos=$false;
RamOnly=$true;StorageEnabled=$false;FullReleaseQualified=$false;PhysicalHardwareAcceptancePassed=$false;
UsbHidAcceptancePassed=$false;NetworkAcceptancePassed=$false;GpuAcceptancePassed=$false;
GuestAcceptancePassed=$true;HostAcceptancePassed=$true;BrowserAcceptancePassed=[bool]$verified.Boot.BrowserAcceptancePassed;
NoRenderFailures=[bool]$verified.NoRenderFailures;MonacoRasterPaintCompleted=[bool]$verified.MonacoRasterPaintCompleted;
MonacoKeyboardEditedModel=[bool]$verified.MonacoKeyboardEditedModel;
ImageSha256=$verified.Boot.ImageSha256;KernelSha256=$verified.Boot.KernelSha256;
SourceSnapshotSha256=$verified.Boot.SourceSnapshotSha256;BootReceiptSha256=(Get-IndependentHash $verified.BootPath);
HostReceiptSha256=(Get-IndependentHash $hostPath);LicenseManifestSha256=(Get-IndependentHash $licensesPath);
Files=$files}
$manifest | ConvertTo-Json -Depth 6 | Set-Content -LiteralPath (Join-Path $package 'Manifest.json') -Encoding UTF8
# Exercise the relocated package's own verifier before creating the ZIP.
$null=& (Join-Path $package 'Tools/IndependentKernel/Open.ps1') -ImagePath (Join-Path $package 'System.img') -VerifiedBootResult (Join-Path $package 'Validation/Boot.json') -ValidateOnly
Compress-Archive -Path (Join-Path $package '*') -DestinationPath $zipPath -CompressionLevel Optimal
Add-Type -AssemblyName System.IO.Compression.FileSystem
$expectedEntries=[Collections.Generic.Dictionary[string,object]]::new([StringComparer]::Ordinal)
foreach($file in $files){$expectedEntries.Add([string]$file.Path,$file)}
$expectedEntries.Add('Manifest.json',[pscustomobject]@{Bytes=(Get-Item -LiteralPath (Join-Path $package 'Manifest.json')).Length;
Sha256=(Get-IndependentHash (Join-Path $package 'Manifest.json'))})
$zip= [IO.Compression.ZipFile]::OpenRead($zipPath)
try {
foreach($entry in $zip.Entries) {
$name=$entry.FullName.Replace('\','/')
if($name.EndsWith('/')){continue}
if(!$expectedEntries.ContainsKey($name)){throw ('Unexpected or duplicate ZIP entry: '+$name)}
$expected=$expectedEntries[$name]
if($entry.Length -ne $expected.Bytes){throw ('ZIP entry length changed: '+$name)}
$stream=$entry.Open();$sha=[Security.Cryptography.SHA256]::Create()
try {$actual=[BitConverter]::ToString($sha.ComputeHash($stream)).Replace('-','').ToLowerInvariant()}
finally {$stream.Dispose();$sha.Dispose()}
if($actual -cne $expected.Sha256){throw ('ZIP readback SHA256 differs: '+$name)}
[void]$expectedEntries.Remove($name)
}
if($expectedEntries.Count){throw ('ZIP is missing files: '+($expectedEntries.Keys -join ', '))}
} finally {$zip.Dispose()}
$receipt=[ordered]@{Kind='XfeIndependentKernelPackageReceipt';Passed=$true;PackageDirectory=$package;ZipPath=$zipPath;
ZipSha256=(Get-IndependentHash $zipPath);ManifestSha256=(Get-IndependentHash (Join-Path $package 'Manifest.json'));
ImageSha256=$verified.Boot.ImageSha256;KernelSha256=$verified.Boot.KernelSha256;GuestAcceptancePassed=$true;
HostAcceptancePassed=$true;RelocatedPackageVerificationPassed=$true;ZipReadbackPassed=$true;
NoRenderFailures=[bool]$verified.NoRenderFailures;MonacoRasterPaintCompleted=[bool]$verified.MonacoRasterPaintCompleted;
MonacoKeyboardEditedModel=[bool]$verified.MonacoKeyboardEditedModel;
FullReleaseQualified=$false;FinishedUtc=[DateTime]::UtcNow.ToString('o')}
$receipt | ConvertTo-Json -Depth 5 | Set-Content -LiteralPath ($package+'.json') -Encoding UTF8
Write-Host ('Independent RAM experiment package: '+$zipPath)
return [pscustomobject]$receipt
} catch {
[ordered]@{Kind='XfeIndependentKernelPackageReceipt';Passed=$false;PackageDirectory=$package;Error=$_.Exception.Message} |
ConvertTo-Json -Depth 4 | Set-Content -LiteralPath ($package+'.failure.json') -Encoding UTF8
throw
}
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)][string]$ImagePath,
[Parameter(Mandatory=$true)][string]$VerifiedBootResult,
[Parameter(Mandatory=$true)][string]$VerifiedHostResult,
[string]$ToolsRoot,
[string]$Version='dev',
[string]$OutputDirectory
)
$ErrorActionPreference='Stop'
$taskRoot=[IO.Path]::GetFullPath((Join-Path $PSScriptRoot '../..'))
if($Version -cnotmatch '^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$'){throw 'Version must be a short filename-safe label.'}
# The launcher owns the same mandatory image, kernel, source and desktop gates.
$verified=. (Join-Path $PSScriptRoot 'Open.ps1') -ImagePath $ImagePath -VerifiedBootResult $VerifiedBootResult -ToolsRoot $ToolsRoot -ValidateOnly
if($verified.Packaged){throw 'Package a verified repository build, rather than repackaging an existing distribution.'}
# Validation-only dot-sourcing shares validators without opening a guest.
$hostPath=(Resolve-Path -LiteralPath $VerifiedHostResult).Path
$hostProof=Read-IndependentJson $hostPath
if($hostProof.HostOnly -ne $true -or $hostProof.GuestExecution -ne $false -or $hostProof.Passed -ne $true -or !$hostProof.SourceHashes -or !$hostProof.Suites) {
throw 'A passing source-bound host test receipt is required.'
}
Assert-IndependentSourceMap $hostProof.SourceHashes $taskRoot 'host verification'
if(!$hostProof.SourceHashes.PSObject.Properties['Source/XFESystem.NativeKernel/Ps2Decoder.cs'] -or
!$hostProof.SourceHashes.PSObject.Properties['Tests/XFESystem.Platform.Tests/XFESystem.Platform.Tests.csproj']) {
throw 'Host verification must include the independent Platform tests and the production PS/2 decoder.'
}
foreach($entry in $verified.Snapshot.PSObject.Properties) {
$hostEntry=$hostProof.SourceHashes.PSObject.Properties[$entry.Name]
if($hostEntry -and [string]$hostEntry.Value -cne [string]$entry.Value) { throw ('Host and guest source hashes differ: '+$entry.Name) }
}
$hostArtifacts=@()
$suiteNames=@()
foreach($suite in $hostProof.Suites) {
if([string]$suite.Suite -cnotmatch '^[A-Za-z0-9._-]+$' -or $suiteNames -contains $suite.Suite -or $suite.Failed -ne 0 -or [int]$suite.Passed -le 0) {
throw 'Host suite names and successful counters are required.'
}
$suiteNames+=([string]$suite.Suite)
$logPath=(Resolve-Path -LiteralPath $suite.Log).Path
if($suite.LogSha256){Assert-IndependentHash $logPath $suite.LogSha256 ('host log '+$suite.Suite)}
$hostArtifacts+= [pscustomobject]@{Source=$logPath;Destination=('Validation/Host/'+$suite.Suite+'.log');Sha256=(Get-IndependentHash $logPath)}
if($suite.Trx) {
$trxPath=(Resolve-Path -LiteralPath $suite.Trx).Path
if($suite.TrxSha256){Assert-IndependentHash $trxPath $suite.TrxSha256 ('host TRX '+$suite.Suite)}
[xml]$trx=Get-Content -LiteralPath $trxPath -Raw -Encoding UTF8
$counter=$trx.SelectSingleNode("//*[local-name()='Counters']")
if(!$counter -or [int]$counter.failed -ne 0 -or [int]$counter.passed -ne [int]$suite.Passed -or
[int]$counter.executed -ne [int]$counter.passed -or [int]$counter.total -ne [int]$counter.passed) {
throw ('Actual host TRX counters are incomplete or differ: '+$suite.Suite)
}
$hostArtifacts+= [pscustomobject]@{Source=$trxPath;Destination=('Validation/Host/'+$suite.Suite+'.trx');Sha256=(Get-IndependentHash $trxPath)}
} elseif($suite.Receipt -and $suite.ReceiptSha256) {
$nativePath=(Resolve-Path -LiteralPath $suite.Receipt).Path
Assert-IndependentHash $nativePath $suite.ReceiptSha256 ('native host receipt '+$suite.Suite)
$native=Read-IndependentJson $nativePath
if($native.Passed -ne $true -or $native.Failed -ne 0 -or $null -eq $native.ExitCode -or $native.ExitCode -ne 0 -or
[int]$native.PassedCount -ne [int]$suite.Passed) { throw ('Native host test execution did not pass: '+$suite.Suite) }
$hostArtifacts+= [pscustomobject]@{Source=$nativePath;Destination=('Validation/Host/'+$suite.Suite+'.json');Sha256=(Get-IndependentHash $nativePath)}
} else {throw ('Actual TRX or source-bound native execution receipt is required: '+$suite.Suite)}
}
if($suiteNames -notcontains 'Platform' -or $suiteNames -notcontains 'NativeContracts') {
throw 'The final host receipt must include Platform and NativeContracts suites.'
}
$licensesRoot=Join-Path $PSScriptRoot 'Licenses'
$licensesPath=Get-IndependentFile $licensesRoot 'Manifest.json'
$licenses=Read-IndependentJson $licensesPath
if($licenses.Schema -cne 'XFESystem.IndependentLicenses.V1' -or $licenses.ContainsCosmos -ne $false -or
$licenses.ExcludesLegacyCollectedGraph -ne $true -or !$licenses.Files -or [int]$licenses.PackageCount -ne @($licenses.Packages).Count) {
throw 'The complete independent application license manifest is required.'
}
Assert-IndependentHash (Get-IndependentFile $taskRoot 'Source/XFESystem.NativeRuntime/Application/packages.lock.json') $licenses.ApplicationLockSha256 'license application lock'
Assert-IndependentHash (Get-IndependentFile $taskRoot 'Tools/IndependentKernel/Runtime/NativeToolchain.json') $licenses.RuntimeToolchainLockSha256 'license runtime toolchain lock'
Assert-IndependentHash (Get-IndependentFile $taskRoot 'Tools/JintCleanupPatch/packages.lock.json') $licenses.JintPatchToolLockSha256 'license Jint patch tool lock'
Assert-IndependentHash (Get-IndependentFile $licensesRoot 'LicenseSources.json') $licenses.SourcesSha256 'license sources manifest'
$licenseNames=@()
foreach($entry in $licenses.Files) {
if($licenseNames -contains $entry.Path) {throw ('Duplicate license path: '+$entry.Path)}
$licenseNames+=([string]$entry.Path)
$path=Get-IndependentFile $licensesRoot $entry.Path
Assert-IndependentHash $path $entry.Sha256 ('license '+$entry.Path)
if((Get-Item -LiteralPath $path).Length -ne $entry.Bytes) {throw ('License length differs: '+$entry.Path)}
}
if(!$OutputDirectory){$OutputDirectory=Join-Path $taskRoot 'dist'}
$outputRoot=[IO.Path]::GetFullPath($OutputDirectory)
[void][IO.Directory]::CreateDirectory($outputRoot)
$packageId='XFESystem-Independent-RAM-'+$Version+'-'+[DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds()+'-'+[Guid]::NewGuid().ToString('N').Substring(0,8)
$package=Join-Path $outputRoot $packageId
$zipPath=$package+'.zip'
if((Test-Path -LiteralPath $package) -or (Test-Path -LiteralPath $zipPath)){throw 'Refusing to overwrite an existing package or ZIP.'}
[void][IO.Directory]::CreateDirectory($package)
function Copy-IndependentBoundFile([string]$Source,[string]$Relative,[string]$Expected) {
Assert-IndependentHash $Source $Expected ('package input '+$Relative)
if([IO.Path]::IsPathRooted($Relative)){throw 'Package destination must be relative.'}
$destination=[IO.Path]::GetFullPath((Join-Path $package $Relative))
if(!$destination.StartsWith($package+[IO.Path]::DirectorySeparatorChar,[StringComparison]::OrdinalIgnoreCase)) {throw 'Package destination escaped the output directory.'}
[void][IO.Directory]::CreateDirectory((Split-Path -Parent $destination))
Copy-Item -LiteralPath $Source -Destination $destination
Assert-IndependentHash $destination $Expected ('package copy '+$Relative)
}
try {
Copy-IndependentBoundFile $verified.ImagePath 'System.img' $verified.Boot.ImageSha256
Copy-IndependentBoundFile $verified.ImageManifestPath 'System.img.json' (Get-IndependentHash $verified.ImageManifestPath)
Copy-IndependentBoundFile $verified.KernelPath 'Kernel.elf' $verified.Boot.KernelSha256
Copy-IndependentBoundFile $verified.BootPath 'Validation/Boot.json' (Get-IndependentHash $verified.BootPath)
Copy-IndependentBoundFile $verified.BuildPath 'Validation/BuildReceipt.json' $verified.Boot.BuildReceiptSha256
Copy-IndependentBoundFile $verified.SnapshotPath 'Validation/SourceSnapshot.json' $verified.Boot.SourceSnapshotSha256
Copy-IndependentBoundFile $hostPath 'Validation/Host.json' (Get-IndependentHash $hostPath)
foreach($entry in $verified.Snapshot.PSObject.Properties) {
Copy-IndependentBoundFile (Get-IndependentFile $taskRoot $entry.Name) ('SourceSnapshot/'+$entry.Name) ([string]$entry.Value)
}
foreach($entry in $hostProof.SourceHashes.PSObject.Properties) {
Copy-IndependentBoundFile (Get-IndependentFile $taskRoot $entry.Name) ('HostSourceSnapshot/'+$entry.Name) ([string]$entry.Value)
}
foreach($artifact in $hostArtifacts) {Copy-IndependentBoundFile $artifact.Source $artifact.Destination $artifact.Sha256}
foreach($file in Get-ChildItem -LiteralPath $licensesRoot -File -Recurse) {
$relative=$file.FullName.Substring($licensesRoot.Length+1).Replace('\','/')
Copy-IndependentBoundFile $file.FullName ('Licenses/'+$relative) (Get-IndependentHash $file.FullName)
}
foreach($firmware in @($verified.FirmwareCode,$verified.FirmwareVars)) {
Copy-IndependentBoundFile $firmware ('Firmware/'+[IO.Path]::GetFileName($firmware)) (Get-IndependentHash $firmware)
}
[void][IO.Directory]::CreateDirectory((Join-Path $package 'Tools/IndependentKernel'))
Copy-IndependentBoundFile (Join-Path $PSScriptRoot 'Open.ps1') 'Tools/IndependentKernel/Open.ps1' (Get-IndependentHash (Join-Path $PSScriptRoot 'Open.ps1'))
Copy-IndependentBoundFile $PSCommandPath 'Tools/IndependentKernel/Package.ps1' (Get-IndependentHash $PSCommandPath)
Copy-IndependentBoundFile (Join-Path $taskRoot 'THIRD_PARTY.md') 'ThirdParty.md' (Get-IndependentHash (Join-Path $taskRoot 'THIRD_PARTY.md'))
foreach($file in Get-ChildItem -LiteralPath (Split-Path -Parent $verified.BootPath) -File) {
if($file.Extension -notin @('.png','.log','.txt') -or ($file.Attributes -band [IO.FileAttributes]::ReparsePoint)) {continue}
Copy-IndependentBoundFile $file.FullName ('Validation/Guest/'+$file.Name) (Get-IndependentHash $file.FullName)
}
[ordered]@{Kind='XfeIndependentFirmwareLock';Firmware=$verified.FirmwareLock.Firmware} | ConvertTo-Json -Depth 4 |
Set-Content -LiteralPath (Join-Path $package 'Validation/Firmware.json') -Encoding UTF8
@'
[CmdletBinding()]
param([string]$QemuPath,[ValidateSet('gtk','sdl')][string]$DisplayBackend='gtk',[switch]$Fullscreen,[switch]$PlanOnly)
$ErrorActionPreference='Stop'
& (Join-Path $PSScriptRoot 'Tools/IndependentKernel/Open.ps1') -ImagePath (Join-Path $PSScriptRoot 'System.img') -VerifiedBootResult (Join-Path $PSScriptRoot 'Validation/Boot.json') -QemuPath $QemuPath -DisplayBackend $DisplayBackend -Fullscreen:$Fullscreen -PlanOnly:$PlanOnly
'@ | Set-Content -LiteralPath (Join-Path $package 'Start.ps1') -Encoding UTF8
@'
# XFESystem 独立内核 RAM 实验版
此包使用自研 C# 内核/HAL/调度与 Microsoft .NET 10 NativeAOT 运行时,不包含 Cosmos 内核或运行时。完整第三方声明位于 Licenses;自研范围和外部引用见 ThirdParty.md。
文件保存在内存中,退出或关机后消失。当前执行一个 BSP,CPU 软件绘制,x87/SSE 上下文;没有持久化存储或独立进程隔离。
Validation/Boot.json 记录本包同一镜像的真实 QEMU 桌面、PS/2 输入和浏览器 DOM 验收;BrowserAcceptancePassed 字段单独说明 Monaco 验收结果。Validation/Host.json 与逐项 TRX/原生测试记录保留宿主结果,宿主通过不能替代来宾执行。
这是 RAM 实验版。实体启动、实体 USB HID 输入、网络、CUDA/GPU 和完整稳定性均未验收,不能标为完整发行版。CMOS RTC 按 UTC 解释;实体机的 RTC 配置和准确性尚未验收。
在 Windows 安装 QEMU 后执行:
powershell -NoProfile -ExecutionPolicy Bypass -File .\Start.ps1 -QemuPath "C:\Program Files\qemu\qemu-system-x86_64.exe"
默认打开 TCG / Q35 / x86_64 / 1 GiB 的 GTK 交互窗口,使用 Q35 内置 PS/2 键盘鼠标,RTC 设为 UTC。可选择 -DisplayBackend sdl 或 -Fullscreen。启动前核验完整包、镜像、ELF、固件、验收记录及所有编译源码快照;每次复制镜像和固件变量到新的 build/IndependentKernel/Interactive-* 会话目录,串口日志位于同目录 Serial.log。关闭 QEMU 窗口结束。
源码与资源快照在 SourceSnapshot,宿主测试源码快照在 HostSourceSnapshot,所有文件 SHA256 在 Manifest.json。它们保存本次实际构建和测试的字节;完整复现命令与版本锁要求见 Reproduce.md。
'@ | Set-Content -LiteralPath (Join-Path $package 'Readme.md') -Encoding UTF8
@'
# 复现与校验
在 XFESystem 仓库中使用 Manifest.json 的源码哈希核对 SourceSnapshot 中所有文件;保留仓库目录结构,按各 packages.lock.json 恢复固定依赖,工具版本锁位于 Tools/IndependentKernel/Runtime/NativeToolchain.json 与 Tools/CSharpBoot/BflatToolchain.json。
powershell -NoProfile -ExecutionPolicy Bypass -File Tools/IndependentKernel/BuildSystem.ps1
python Tools/IndependentKernel/TestBoot.py <新生成的Kernel.elf> --virtual-cpus 8 --desktop --browser --timeout 360
powershell -NoProfile -ExecutionPolicy Bypass -File Tools/TestCSharp.ps1
python Tools/IndependentKernel/CollectLicenses.py
powershell -NoProfile -ExecutionPolicy Bypass -File Tools/IndependentKernel/Package.ps1 -ImagePath <通过的System.img> -VerifiedBootResult <通过的Result.json> -VerifiedHostResult <宿主Result.json>
编译、链接成功不等于运行验收;每次新建产物需要新 guest/host 记录。本包原始精确编译命令保存在 Validation/BuildReceipt.json;完整包与携带的源码快照、固件可通过下列命令只读核验:
powershell -NoProfile -ExecutionPolicy Bypass -File Tools/IndependentKernel/Open.ps1 -ImagePath System.img -VerifiedBootResult Validation/Boot.json -ValidateOnly
SourceSnapshot 只保存实际编译输入,复现需要完整仓库中匹配的工具与锁文件。HostSourceSnapshot 保存实际宿主检查输入。各原始 JSON 的旧绝对路径用于出处记录;打包启动入口通过包内固定相对路径定位已验证文件。
'@ | Set-Content -LiteralPath (Join-Path $package 'Reproduce.md') -Encoding UTF8
Assert-IndependentSourceMap $verified.Snapshot $taskRoot 'final guest source snapshot'
Assert-IndependentSourceMap $hostProof.SourceHashes $taskRoot 'final host source snapshot'
$files=@(foreach($file in Get-ChildItem -LiteralPath $package -File -Recurse | Sort-Object FullName) {
[ordered]@{Path=$file.FullName.Substring($package.Length+1).Replace('\','/');Bytes=$file.Length;Sha256=(Get-IndependentHash $file.FullName)}
})
$manifest=[ordered]@{Kind='XfeIndependentRamDesktopPackage';Version=$Version;ContainsCosmos=$false;
RamOnly=$true;StorageEnabled=$false;FullReleaseQualified=$false;PhysicalHardwareAcceptancePassed=$false;
UsbHidAcceptancePassed=$false;NetworkAcceptancePassed=$false;GpuAcceptancePassed=$false;
GuestAcceptancePassed=$true;HostAcceptancePassed=$true;BrowserAcceptancePassed=[bool]$verified.Boot.BrowserAcceptancePassed;
NoRenderFailures=[bool]$verified.NoRenderFailures;MonacoRasterPaintCompleted=[bool]$verified.MonacoRasterPaintCompleted;
MonacoKeyboardEditedModel=[bool]$verified.MonacoKeyboardEditedModel;
ImageSha256=$verified.Boot.ImageSha256;KernelSha256=$verified.Boot.KernelSha256;
SourceSnapshotSha256=$verified.Boot.SourceSnapshotSha256;BootReceiptSha256=(Get-IndependentHash $verified.BootPath);
HostReceiptSha256=(Get-IndependentHash $hostPath);LicenseManifestSha256=(Get-IndependentHash $licensesPath);
Files=$files}
$manifest | ConvertTo-Json -Depth 6 | Set-Content -LiteralPath (Join-Path $package 'Manifest.json') -Encoding UTF8
# Exercise the relocated package's own verifier before creating the ZIP.
$null=& (Join-Path $package 'Tools/IndependentKernel/Open.ps1') -ImagePath (Join-Path $package 'System.img') -VerifiedBootResult (Join-Path $package 'Validation/Boot.json') -ValidateOnly
Compress-Archive -Path (Join-Path $package '*') -DestinationPath $zipPath -CompressionLevel Optimal
Add-Type -AssemblyName System.IO.Compression.FileSystem
$expectedEntries=[Collections.Generic.Dictionary[string,object]]::new([StringComparer]::Ordinal)
foreach($file in $files){$expectedEntries.Add([string]$file.Path,$file)}
$expectedEntries.Add('Manifest.json',[pscustomobject]@{Bytes=(Get-Item -LiteralPath (Join-Path $package 'Manifest.json')).Length;
Sha256=(Get-IndependentHash (Join-Path $package 'Manifest.json'))})
$zip= [IO.Compression.ZipFile]::OpenRead($zipPath)
try {
foreach($entry in $zip.Entries) {
$name=$entry.FullName.Replace('\','/')
if($name.EndsWith('/')){continue}
if(!$expectedEntries.ContainsKey($name)){throw ('Unexpected or duplicate ZIP entry: '+$name)}
$expected=$expectedEntries[$name]
if($entry.Length -ne $expected.Bytes){throw ('ZIP entry length changed: '+$name)}
$stream=$entry.Open();$sha=[Security.Cryptography.SHA256]::Create()
try {$actual=[BitConverter]::ToString($sha.ComputeHash($stream)).Replace('-','').ToLowerInvariant()}
finally {$stream.Dispose();$sha.Dispose()}
if($actual -cne $expected.Sha256){throw ('ZIP readback SHA256 differs: '+$name)}
[void]$expectedEntries.Remove($name)
}
if($expectedEntries.Count){throw ('ZIP is missing files: '+($expectedEntries.Keys -join ', '))}
} finally {$zip.Dispose()}
$receipt=[ordered]@{Kind='XfeIndependentKernelPackageReceipt';Passed=$true;PackageDirectory=$package;ZipPath=$zipPath;
ZipSha256=(Get-IndependentHash $zipPath);ManifestSha256=(Get-IndependentHash (Join-Path $package 'Manifest.json'));
ImageSha256=$verified.Boot.ImageSha256;KernelSha256=$verified.Boot.KernelSha256;GuestAcceptancePassed=$true;
HostAcceptancePassed=$true;RelocatedPackageVerificationPassed=$true;ZipReadbackPassed=$true;
NoRenderFailures=[bool]$verified.NoRenderFailures;MonacoRasterPaintCompleted=[bool]$verified.MonacoRasterPaintCompleted;
MonacoKeyboardEditedModel=[bool]$verified.MonacoKeyboardEditedModel;
FullReleaseQualified=$false;FinishedUtc=[DateTime]::UtcNow.ToString('o')}
$receipt | ConvertTo-Json -Depth 5 | Set-Content -LiteralPath ($package+'.json') -Encoding UTF8
Write-Host ('Independent RAM experiment package: '+$zipPath)
return [pscustomobject]$receipt
} catch {
[ordered]@{Kind='XfeIndependentKernelPackageReceipt';Passed=$false;PackageDirectory=$package;Error=$_.Exception.Message} |
ConvertTo-Json -Depth 4 | Set-Content -LiteralPath ($package+'.failure.json') -Encoding UTF8
throw
}