diff --git a/config.json.example b/src/config.json.example similarity index 84% rename from config.json.example rename to src/config.json.example index 0d201b8..6e952ce 100644 --- a/config.json.example +++ b/src/config.json.example @@ -2,7 +2,7 @@ "forceLocalPrograms": false, "params": { "awesomeMinerAPIConfig": { - enabled: false, + "enabled": false, "awesomeHostURL": "", "awesomeAPIKey": "" } diff --git a/configs/default.json b/src/configs/default.json similarity index 100% rename from configs/default.json rename to src/configs/default.json diff --git a/configs/gi-enabled.json b/src/configs/gi-enabled.json similarity index 100% rename from configs/gi-enabled.json rename to src/configs/gi-enabled.json diff --git a/configs/tests.json b/src/configs/tests.json similarity index 100% rename from configs/tests.json rename to src/configs/tests.json diff --git a/gen_expected.ps1 b/src/gen_expected.ps1 similarity index 96% rename from gen_expected.ps1 rename to src/gen_expected.ps1 index ad0b037..8bad1b0 100644 --- a/gen_expected.ps1 +++ b/src/gen_expected.ps1 @@ -1,4 +1,4 @@ -. .\p7zip_util.ps1 +. .\include\p7zip_util.ps1 if (Test-Path -Path '.\instance.json') { $instance = (Get-Content '.\instance.json') | ConvertFrom-Json @@ -12,7 +12,7 @@ else -$test_dirs = '.\tests\Amd', '.\tests\Baseboards', '.\tests\Nvidia' +$test_dirs = '..\tests\Amd', '..\tests\Baseboards', '..\tests\Nvidia' foreach ($test_path in $test_dirs) { if (Test-Path $test_path) diff --git a/glt_launcher.ps1 b/src/glt_launcher.ps1 similarity index 99% rename from glt_launcher.ps1 rename to src/glt_launcher.ps1 index 76302d1..499b352 100644 --- a/glt_launcher.ps1 +++ b/src/glt_launcher.ps1 @@ -1,6 +1,6 @@ <#PSScriptInfo -.VERSION 0.2.6 +.VERSION 0.2.7 .GUID fe8bfeb4-23ab-4a96-824c-6a36d85d61b3 @@ -199,7 +199,7 @@ try catch { Throw 'ERROR (Failed Operation: Unable to load WPF Dependencies)' } -$GUI_PATH = '.\GUI.xaml' +$GUI_PATH = '.\ui\GUI.xaml' [xml]$XML_WPF = Get-Content -Path $GUI_PATH if (! $XML_WPF) { Throw "ERROR (Failed Operation: Unabled to find 'GUI.xaml' in script directory.)" } diff --git a/gpu_lookup_tableGUI.ps1 b/src/gpu_lookup_tableGUI.ps1 similarity index 78% rename from gpu_lookup_tableGUI.ps1 rename to src/gpu_lookup_tableGUI.ps1 index 09b5add..f70e044 100644 --- a/gpu_lookup_tableGUI.ps1 +++ b/src/gpu_lookup_tableGUI.ps1 @@ -3,6 +3,10 @@ Param ( [string]$ConfigFile ) +# Includes +. .\include\pirq.ps1 +. .\include\util.ps1 + if (! $ConfigFile) { $ConfigFile = '.\instance.json' } $config = (Get-Content $ConfigFile) | ConvertFrom-Json @@ -16,7 +20,7 @@ $plink = $config.programs.plink if (-not $config.tests.testMode) { - . .\p7zip_util.ps1 + . .\include\p7zip.ps1 $P7Zip = $config.programs.p7zip } @@ -25,43 +29,6 @@ if (-not $config.tests.testMode) [Regex]$BUSID_REGEX = '(:[0-9a-f]{2}){2}\.\d' [Regex]$GPU_BUSID_REGEX = '(:[0-9a-f]{2})(:00)\.\d' -# Supported baseboard names -$SUPPORTED_BASEBOARDS = @( - 'BTC-T37', - 'BTC-S37', - 'ONDA B250 BTC V1.05', - 'TB85', - # OctoMiner - '12XTREME', - 'X12ULTRA', - 'B85 ULTRA', - 'CRESCENTBAY', - 'B75', - 'skylake' -) - -## PIRQ MAPS -# ONDA B250 -$b250_pirq_hard_map = @(16, 37, 38, 39, 40, 41, 42, 43, 48, 53, 54, 55) -# BTC-T37, BTC-S37 -$x37_pirq_hard_map = @(16, 9, 10, 16, 17, 18, 33, 34) -# TB85 -$tb85_pirq_hard_map = @(16, 33, 34, 8, 9, 10) -# Octo 8x (ULTRA) -$octo8_pirq_hard_map = @(34, 33, 32, 39, 35, 36, 37, 38) -# CRESCENTBAY -$crescentbay_pirq_hard_map = @(16, 33, 34, 35, 36, 37, 38, 39) -# B75 -$b75_pirq_hard_map = @(33, 34, 8, 9, 10, 6, 17, 18) #slot 6 doesn't have a slot number -# skylake -$skylake_pirq_hard_map = @(32, 37, 36, 35, 40, 43, 41, 33) - -## End PIRQ MAPS - -# OctoMiner 12x (XTREME/ULTRA) -$octo12_hard_map = @('01', '07', '0c', '0d', '0b', '05', '0a', '04', '09', '03', '08', '02') - - # FUNCTIONS @@ -260,195 +227,6 @@ Function Read-PCI-Slot-Info } -Function Get-PCI-Handle-Count -{ - $pci_handles = @((Get-Content .\dmidecodet9.txt | Select-String -Pattern 'Handle ' -AllMatches) | ForEach-Object { $_ | Show-Column -Column 1 }) - return $pci_handles.Count -} - - -Function Get-Baseboard-Product-Name -{ - return (Get-Content .\mb_product_name.txt) -} - - -# PIRQ TABLE FUNCS - - -Function Test-For-PIRQ-Table -{ - if ((Get-Content .\biosdecode.txt | Select-String -Pattern 'PCI Interrupt Routing').Matches) { return 0 } - return 1 -} - - -Function Read-Baseboard-BIOS -{ - return (Get-Content .\dmidecodebios.txt) -} - - -Function Update-Baseboard-Product-Name -{ - for ($idx = 0; $idx -lt $SUPPORTED_BASEBOARDS.Count; $idx++) - { - if ($SUPPORTED_BASEBOARDS[$idx] -eq $mb_product_name) - { - return ( $idx + 1 ) - } - } - return $mb_product_name -} - - -Function Search-PIRQ-Hard-Maps -{ - $support_idx = $mb_product -as [int] - if ($null -eq $support_idx) - { Throw "ERROR (Unsupported: The detected motherboard model is not supported: $mb_product)" } - - switch ($support_idx) - { - # BTC-S37, BTC-T37 - { ($_ -eq 1) -or ($_ -eq 2) } { return Write-Output -NoEnumerate $x37_pirq_hard_map } - # ONDA B250 - 3 { return Write-Output -NoEnumerate $b250_pirq_hard_map } - # TB85 - 4 { return Write-Output -NoEnumerate $tb85_pirq_hard_map } - # 12XTREME, X12ULTRA - { ($_ -eq 5) -or ($_ -eq 6) } { return Write-Output -NoEnumerate $octo12_hard_map } - # B85 ULTRA - 7 { return Write-Output -NoEnumerate $octo8_pirq_hard_map } - # CRESCENTBAY - 8 { return Write-Output -NoEnumerate $crescentbay_pirq_hard_map } - # B75 - 9 { return Write-Output -NoEnumerate $b75_pirq_hard_map } - # skylake - 10 { return Write-Output -NoEnumerate $skylake_pirq_hard_map } - } -} - - -Function Read-PIRQ-Device-Slot-Ids -{ - $devices = $gpu_busids - if ((Get-Content .\gpu_driver.txt | Select-String -Pattern 'amdgpu').Matches -and (Find-GPU-Context-Offset) -ne 1) - { - $devices = $pci_busids - } - $pirq_device_slot_ids = @() - # OctoMiner 12x - if ($mb_product_name -eq '12XTREME' -or $mb_product_name -eq 'X12ULTRA') - { - foreach ($bus in $devices) - { - for ($idx = 0; $idx -lt $pirq_map.Count; $idx++) - { - if ("$bus".Substring(0, 2) -eq $pirq_map[$idx]) - { - $pirq_device_slot_ids += $idx - break - } - } - } - return Write-Output -NoEnumerate $pirq_device_slot_ids - } - $cp_of_pirq_map = $pirq_map.Clone() - foreach ($bus in $devices) - { - if ($bus -eq 'MISSING') { continue } - $is_pirq_slot_number_match = (Get-Content .\biosdecode.txt | Select-String -Pattern $bus.Split('.')[0] | Out-String -Stream | Select-String -Pattern 'slot(?: number | )([0-9]{1,})') - try - { - $pirq_slot_number = $is_pirq_slot_number_match.Matches.Groups[1].Value - } - catch - { - # - } - - # little bit of headache to get around multiple "16" entries with crescentbay boards - if ($bus -eq '01:00.0' -and $pirq_slot_number -eq '16') - { - $pirq_device_slot_ids += 0 - $cp_of_pirq_map[0] = '' - continue - } - elseif ($pirq_slot_number -eq '16' -and $bus -ne '01:00.0') - { - $cp_of_pirq_map[0] = '' - } - # fix BTC-X37 showing slot 1 MISSING when slot 7 is MISSING - if ($mb_product_name -eq 'BTC-T37' -or $mb_product_name -eq 'BTC-S37') - { - if ($pirq_slot_number -eq '33' -and $bus -eq '01:00.0') - { - $pirq_device_slot_ids += 0 - $cp_of_pirq_map[0] = '' - continue - } - } - # fix B75 slot 6 not having slot number - if ($mb_product_name -eq 'B75') - { - if ($null -eq $is_pirq_slot_number_match) - { - $pirq_device_slot_ids += 5 - $cp_of_pirq_map[5] = '' - continue - } - } - for ($idx = 0; $idx -lt $cp_of_pirq_map.Count; $idx++) - { - if ($cp_of_pirq_map[$idx] -eq $pirq_slot_number) - { - $pirq_device_slot_ids += $idx - $cp_of_pirq_map[$idx] = '' - break - } - } - } - Remove-Variable devices - Remove-Variable cp_of_pirq_map - return Write-Output -NoEnumerate $pirq_device_slot_ids -} - - -Function Get-Missing-Slot-Ids -{ - $missing_slot_ids = @() - if ($PIRQ_FOUND) - { - $slot_ids = @(0..($pirq_map.Count - 1)) - } - else - { $slot_ids = @(0..((Get-PCI-Handle-Count) - 1)) } - foreach ($id in $slot_ids) - { - if ($pci_info_ids -notcontains $id) - { - $missing_slot_ids += $id - } - } - return Write-Output -NoEnumerate $missing_slot_ids -} - - -Function Get-PIRQ-Device-Designations -{ - $pirq_device_slot_designations = @() - foreach ($id in $pci_info_ids) - { - $pirq_device_slot_designations += "PCIE $( $id + 1 )" - } - return Write-Output -NoEnumerate $pirq_device_slot_designations -} - - -## END PIRQ TABLE FUNCS - - Function Request-Data { # Need to make manual connection first to accept remote host key @@ -699,31 +477,6 @@ Function Show-Table } -Function Show-Column -{ - param ( - [Parameter(Mandatory, ValueFromPipeline)][string]$line, - [string]$Delimiter, - [int]$Column - ) - if (! $Delimiter) { $Delimiter = ' ' } - ($line -split $Delimiter)[$Column] -} - - -Function Unprotect-SecureString -{ - param ( - [System.Security.SecureString]$SecureString - ) - $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecureString) - $Plain = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) - [System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($BSTR) - $SecureString = $SecureString.Dispose() - Return $Plain -} - - if ($config.debug.debugMode) { $DebugPreference = 'Continue' diff --git a/help_man.ps1 b/src/help_man.ps1 similarity index 100% rename from help_man.ps1 rename to src/help_man.ps1 diff --git a/p7zip_util.ps1 b/src/include/p7zip.ps1 similarity index 99% rename from p7zip_util.ps1 rename to src/include/p7zip.ps1 index c060c4c..00512ba 100644 --- a/p7zip_util.ps1 +++ b/src/include/p7zip.ps1 @@ -44,4 +44,4 @@ Function Update-Tar } else { & $P7Zip -bso0 -bsp0 a $tarFile $(, $files) } -} \ No newline at end of file +} diff --git a/src/include/pirq.ps1 b/src/include/pirq.ps1 new file mode 100644 index 0000000..d507987 --- /dev/null +++ b/src/include/pirq.ps1 @@ -0,0 +1,211 @@ +# Supported baseboard names +$SUPPORTED_BASEBOARDS = @( + 'BTC-T37', + 'BTC-S37', + 'ONDA B250 BTC V1.05', + 'TB85', + # OctoMiner + '12XTREME', + 'X12ULTRA', + 'B85 ULTRA', + 'CRESCENTBAY', + 'B75', + 'skylake' +) + +## PIRQ MAPS +# ONDA B250 +$b250_pirq_hard_map = @(16, 37, 38, 39, 40, 41, 42, 43, 48, 53, 54, 55) +# BTC-T37, BTC-S37 +$x37_pirq_hard_map = @(16, 9, 10, 16, 17, 18, 33, 34) +# TB85 +$tb85_pirq_hard_map = @(16, 33, 34, 8, 9, 10) +# Octo 8x (ULTRA) +$octo8_pirq_hard_map = @(34, 33, 32, 39, 35, 36, 37, 38) +# CRESCENTBAY +$crescentbay_pirq_hard_map = @(16, 33, 34, 35, 36, 37, 38, 39) +# B75 +$b75_pirq_hard_map = @(33, 34, 8, 9, 10, 6, 17, 18) #slot 6 doesn't have a slot number +# skylake +$skylake_pirq_hard_map = @(32, 37, 36, 35, 40, 43, 41, 33) + +## End PIRQ MAPS + +# OctoMiner 12x (XTREME/ULTRA) +$octo12_hard_map = @('01', '07', '0c', '0d', '0b', '05', '0a', '04', '09', '03', '08', '02') + + +# PIRQ TABLE FUNCS + + +Function Test-For-PIRQ-Table +{ + if ((Get-Content .\biosdecode.txt | Select-String -Pattern 'PCI Interrupt Routing').Matches) { return 0 } + return 1 +} + + +Function Read-Baseboard-BIOS +{ + return (Get-Content .\dmidecodebios.txt) +} + + +Function Update-Baseboard-Product-Name +{ + for ($idx = 0; $idx -lt $SUPPORTED_BASEBOARDS.Count; $idx++) + { + if ($SUPPORTED_BASEBOARDS[$idx] -eq $mb_product_name) + { + return ( $idx + 1 ) + } + } + return $mb_product_name +} + + +Function Search-PIRQ-Hard-Maps +{ + $support_idx = $mb_product -as [int] + if ($null -eq $support_idx) + { Throw "ERROR (Unsupported: The detected motherboard model is not supported: $mb_product)" } + + switch ($support_idx) + { + # BTC-S37, BTC-T37 + { ($_ -eq 1) -or ($_ -eq 2) } { return Write-Output -NoEnumerate $x37_pirq_hard_map } + # ONDA B250 + 3 { return Write-Output -NoEnumerate $b250_pirq_hard_map } + # TB85 + 4 { return Write-Output -NoEnumerate $tb85_pirq_hard_map } + # 12XTREME, X12ULTRA + { ($_ -eq 5) -or ($_ -eq 6) } { return Write-Output -NoEnumerate $octo12_hard_map } + # B85 ULTRA + 7 { return Write-Output -NoEnumerate $octo8_pirq_hard_map } + # CRESCENTBAY + 8 { return Write-Output -NoEnumerate $crescentbay_pirq_hard_map } + # B75 + 9 { return Write-Output -NoEnumerate $b75_pirq_hard_map } + # skylake + 10 { return Write-Output -NoEnumerate $skylake_pirq_hard_map } + } +} + + +Function Read-PIRQ-Device-Slot-Ids +{ + $devices = $gpu_busids + if ((Get-Content .\gpu_driver.txt | Select-String -Pattern 'amdgpu').Matches -and (Find-GPU-Context-Offset) -ne 1) + { + $devices = $pci_busids + } + $pirq_device_slot_ids = @() + # OctoMiner 12x + if ($mb_product_name -eq '12XTREME' -or $mb_product_name -eq 'X12ULTRA') + { + foreach ($bus in $devices) + { + for ($idx = 0; $idx -lt $pirq_map.Count; $idx++) + { + if ("$bus".Substring(0, 2) -eq $pirq_map[$idx]) + { + $pirq_device_slot_ids += $idx + break + } + } + } + return Write-Output -NoEnumerate $pirq_device_slot_ids + } + $cp_of_pirq_map = $pirq_map.Clone() + foreach ($bus in $devices) + { + if ($bus -eq 'MISSING') { continue } + $is_pirq_slot_number_match = (Get-Content .\biosdecode.txt | Select-String -Pattern $bus.Split('.')[0] | Out-String -Stream | Select-String -Pattern 'slot(?: number | )([0-9]{1,})') + try + { + $pirq_slot_number = $is_pirq_slot_number_match.Matches.Groups[1].Value + } + catch + { + # + } + + # little bit of headache to get around multiple "16" entries with crescentbay boards + if ($bus -eq '01:00.0' -and $pirq_slot_number -eq '16') + { + $pirq_device_slot_ids += 0 + $cp_of_pirq_map[0] = '' + continue + } + elseif ($pirq_slot_number -eq '16' -and $bus -ne '01:00.0') + { + $cp_of_pirq_map[0] = '' + } + # fix BTC-X37 showing slot 1 MISSING when slot 7 is MISSING + if ($mb_product_name -eq 'BTC-T37' -or $mb_product_name -eq 'BTC-S37') + { + if ($pirq_slot_number -eq '33' -and $bus -eq '01:00.0') + { + $pirq_device_slot_ids += 0 + $cp_of_pirq_map[0] = '' + continue + } + } + # fix B75 slot 6 not having slot number + if ($mb_product_name -eq 'B75') + { + if ($null -eq $is_pirq_slot_number_match) + { + $pirq_device_slot_ids += 5 + $cp_of_pirq_map[5] = '' + continue + } + } + for ($idx = 0; $idx -lt $cp_of_pirq_map.Count; $idx++) + { + if ($cp_of_pirq_map[$idx] -eq $pirq_slot_number) + { + $pirq_device_slot_ids += $idx + $cp_of_pirq_map[$idx] = '' + break + } + } + } + Remove-Variable devices + Remove-Variable cp_of_pirq_map + return Write-Output -NoEnumerate $pirq_device_slot_ids +} + + +Function Get-Missing-Slot-Ids +{ + $missing_slot_ids = @() + if ($PIRQ_FOUND) + { + $slot_ids = @(0..($pirq_map.Count - 1)) + } + else + { $slot_ids = @(0..((Get-PCI-Handle-Count) - 1)) } + foreach ($id in $slot_ids) + { + if ($pci_info_ids -notcontains $id) + { + $missing_slot_ids += $id + } + } + return Write-Output -NoEnumerate $missing_slot_ids +} + + +Function Get-PIRQ-Device-Designations +{ + $pirq_device_slot_designations = @() + foreach ($id in $pci_info_ids) + { + $pirq_device_slot_designations += "PCIE $( $id + 1 )" + } + return Write-Output -NoEnumerate $pirq_device_slot_designations +} + + +## END PIRQ TABLE FUNCS diff --git a/src/include/util.ps1 b/src/include/util.ps1 new file mode 100644 index 0000000..d433a03 --- /dev/null +++ b/src/include/util.ps1 @@ -0,0 +1,38 @@ +## GETTERS +Function Get-Baseboard-Product-Name +{ + return (Get-Content .\mb_product_name.txt) +} + + +Function Get-PCI-Handle-Count +{ + $pci_handles = @((Get-Content .\dmidecodet9.txt | Select-String -Pattern 'Handle ' -AllMatches) | ForEach-Object { $_ | Show-Column -Column 1 }) + return $pci_handles.Count +} +## END GETTERS + + +Function Show-Column +{ + param ( + [Parameter(Mandatory, ValueFromPipeline)][string]$line, + [string]$Delimiter, + [int]$Column + ) + if (! $Delimiter) { $Delimiter = ' ' } + ($line -split $Delimiter)[$Column] +} + + +Function Unprotect-SecureString +{ + param ( + [System.Security.SecureString]$SecureString + ) + $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecureString) + $Plain = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) + [System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($BSTR) + $SecureString = $SecureString.Dispose() + Return $Plain +} diff --git a/src/pirq_gen.ps1 b/src/pirq_gen.ps1 new file mode 100644 index 0000000..6f35f78 --- /dev/null +++ b/src/pirq_gen.ps1 @@ -0,0 +1,248 @@ +[CmdletBinding()] +Param ( + [string]$ConfigFile +) + +# Includes +. .\include\p7zip.ps1 +. .\include\pirq.ps1 +. .\include\util.ps1 + +if (! $ConfigFile) { $ConfigFile = '.\instance.json' } +$config = (Get-Content $ConfigFile) | ConvertFrom-Json + +# External Programs +$P7Zip = $config.programs.p7zip +$plink = $config.programs.plink +$CMD = 'C:\Windows\System32\cmd.exe' + +$get_system = @" +for d in system-manufacturer system-product-name bios-release-date bios-version; do echo `"`${d^} : `" `$(echo `"$pl_passwd`" | sudo -S -k dmidecode -s `$d); done > /tmp/dmidecodebios.txt +echo `"$pl_passwd`" | sudo -S -k dmidecode -s baseboard-product-name > /tmp/mb_product_name.txt +echo `"$pl_passwd`" | sudo -S -k biosdecode > /tmp/biosdecode.txt +lspci -mm > /tmp/lspcimm.txt +cd /tmp && tar -jcf - dmidecodebios.txt mb_product_name.txt biosdecode.txt lspcimm.txt +"@ + +$get_pirq_slot = @" +echo `"$pl_passwd`" | sudo -S -k biosdecode +"@ +# echo `"$pl_passwd`" | sudo -S -k shutdown now + + +Function Request-Data +{ + param ( + [switch]$StoreAsArchive = $FALSE, + [string]$OutName = 'data', + [Parameter(Mandatory)][string]$Payload + ) + + if ($StoreAsArchive) + { + $OutName = "$OutName.tar.bz2" + } + $Payload | Out-File -Encoding ascii -FilePath .\payload + + # Need to make manual connection first to accept remote host key + Write-Output 'Ensuring remote host is trusted and can connect...' + Write-Output 'y' | & $plink -ssh $username@$remote_ip 2> $null + $cmd_string = "`"$plink`" -ssh -pw `"$pl_passwd`" -batch $username@$remote_ip -m .\payload > $OutName" + & $CMD /c $cmd_string 2> $null + + if ($StoreAsArchive) + { + $tar_name = $OutName.Replace('.bz2', '') + Expand-Tar $OutName . + Expand-Tar $tar_name . + Remove-Item $tar_name + } + + Remove-Item .\payload -ErrorAction SilentlyContinue +} + + +# Load in WPF depends +Write-Verbose 'Loading in WPF dependecies...' +try +{ + Add-Type -AssemblyName PresentationCore, PresentationFramework, WindowsBase, System.Windows.Forms +} +catch +{ Throw 'ERROR (Failed Operation: Unable to load WPF Dependencies)' } + +[xml]$XML_WPF_INPUT = Get-Content -Path .\ui\Input.xaml +[xml]$XML_WPF_POPUP = Get-Content -Path .\ui\Popup.xaml +$XAML_INPUT = [System.Windows.Markup.XamlReader]::Load((New-Object System.Xml.XmlNodeReader $XML_WPF_INPUT)) +$XAML_POPUP = [System.Windows.Markup.XamlReader]::Load((New-Object System.Xml.XmlNodeReader $XML_WPF_POPUP)) + +# Import named components as variables +Write-Verbose 'Importing objects from Input xaml...' +$XML_WPF_INPUT.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | ForEach-Object { + Set-Variable -Name ($_.Name) -Value $XAML_INPUT.FindName($_.Name) +} + +Write-Verbose 'Importing objects from Popup xaml...' +$XML_WPF_POPUP.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | ForEach-Object { + Set-Variable -Name ($_.Name) -Value $XAML_POPUP.FindName($_.Name) +} +# Get window icon uri +$icon_uri = New-Object System.uri((Get-ChildItem '.\resources\icons\BitCapLngLogo_BLK-04.png').FullName) + +# UserInput +$UserInput.Icon = New-Object System.Windows.Media.Imaging.BitmapImage $icon_uri +$UserInput.Title = '$PIRQ Map Generation: Configuration' +$YesButton.add_click( + { + Set-Variable -Name USER_CONTINUE -Value $TRUE -Scope Global + $UserInput.Close() + } +) +$NoButton.add_click( + { + Set-Variable -Name USER_CONTINUE -Value $FALSE -Scope Global + $UserInput.Close() + } +) + +# Popup +$Popup.Icon = New-Object System.Windows.Media.Imaging.BitmapImage $icon_uri +$Popup.Title = 'Information Dialog' +$AcceptButton.add_click( + { + $Popup.Hide() + } +) + +$remote_ip = $config.options.input.remoteIP +$username = $config.options.input.username +$remote_passwd = $config.options.input.passwd + +Write-Verbose "Setting up remote connection to $remote_ip..." +if (! $username.Length) +{ + $username = 'user' +} +if (! $remote_passwd.Length) +{ + if (! $env:Default) { Throw 'ERROR (Missing Credentials: No password for remote target supplied)' } + $remote_passwd = $env:Default | ConvertTo-SecureString +} +else +{ $remote_passwd = $remote_passwd | ConvertTo-SecureString } +$pl_passwd = Unprotect-SecureString $remote_passwd +$remote_passwd = $remote_passwd.Dispose() + +# initial system check +Write-Verbose "Getting system info from $remote_ip..." +Request-Data -Payload $get_system -OutName $remote_ip -StoreAsArchive + +Remove-Variable pl_passwd -ErrorAction SilentlyContinue + +# Get baseboard name +$mb_product_name = (Get-Baseboard-Product-Name) +$mb_product = (Update-Baseboard-Product-Name) + +if ($mb_product_name -ne $mb_product) # if mb_product_name isnt return back +{ + $TextInformation.Text = "$mb_product_name is already supported within the script. No further action needed." + $XAML_POPUP.Activate | Out-Null + $result = $XAML_POPUP.ShowDialog() + if (-not $result) + { + Write-Verbose 'Dialog closed, Exitting...' + Exit 0 + } +} + +if ((Test-For-PIRQ-Table) -eq 1) +{ + $TextInformation.Text = "$mb_product_name has no `$PIRQ Table available. Exitting..." + $XAML_POPUP.Activate | Out-Null + $result = $XAML_POPUP.ShowDialog() + if (-not $result) + { + Write-Verbose 'Dialog closed, Exitting...' + Exit 0 + } +} + +# Generate the PIRQ MAP + +# Show user what we found +$TextInformation.Text = " +IP Addr: $remote_ip +`$PIRQ FOUND! +Baseboard Name: $mb_product_name +Manufacturer:$(Get-Content .\dmidecodebios.txt | Select-String -Pattern 'System-manufacturer' | Show-Column -Delimiter ':' -Column 1) +BIOS Release:$(Get-Content .\dmidecodebios.txt | Select-String -Pattern 'Bios-release-date' | Show-Column -Delimiter ':' -Column 1) +BIOS Version:$(Get-Content .\dmidecodebios.txt | Select-String -Pattern 'Bios-version' | Show-Column -Delimiter ':' -Column 1) +" +$XAML_POPUP.Activate | Out-Null +$XAML_POPUP.ShowDialog() +if ($XAML_POPUP.Visibility -eq 'Hidden') +{ + $TextQuestion.Text = 'How many system PCI(E) slots are available?' + $XAML_INPUT.Activate | Out-Null + $result = $XAML_INPUT.ShowDialog() + if (-not $result) + { + + } +} + +if ($USER_CONTINUE) +{ + $n_system_slots = $TextInput.Text -as [int] + if ($null -eq $n_system_slots) + { Throw 'ERROR (Invalid Input: Please input number of PCI(E) slots)' } + Write-Verbose $n_system_slots + $pirq_map = @() + $busid_ignore = @() + # figure out ethernet bus id to ignore + $eth_bus_id = (Get-Content .\lspcimm.txt | Select-String -Pattern "Ethernet").Line | Show-Column -Column 0 + $busid_ignore += $eth_bus_id.Split('.')[0] + $Popup.Title = '$PIRQ Map Generation: Setup' + $TextInformation.Text = 'Starting $PIRQ Map generation! Have access to the system. Remove the GPU devices from the system and follow the on-screen instructions. Press Ok to start.' + $result = $XAML_POPUP.ShowDialog() + if (-not $result) + { + for ($i = 0; $i -lt $n_system_slots; $i++) + { + $slot_number = $($i + 1) + $Popup.Title = "`$PIRQ Map Generation : Slot $slot_number" + $TextInformation.Text = "Please install an GPU device in Slot $slot_number and boot up system. Once online, press Ok." + $result = $XAML_POPUP.ShowDialog() + if (-not $result) + { + # wait for ip + if (Test-Connection -ComputerName $remote_ip -Quiet) + { + Request-Data -Payload $get_pirq_slot -OutName biosdecode.txt + # parse and record new slot number + $pirq_slot_number_line_matches = (Get-Content .\biosdecode.txt | Select-string -Pattern 'slot(?: number | )([0-9]{1,})').Line + foreach ($line in $pirq_slot_number_line_matches) + { + $is_ignore = $FALSE + foreach ($bus in $busid_ignore) + { + if (($line | Select-String -Pattern $bus).Matches) + { + $is_ignore = $TRUE + break + } + } + if ($is_ignore) { continue } + $bus_id = ($line | Select-String -Pattern 'ID (:[0-9a-f]{2})(:00)') + $pirq_slot_number = ($line | Select-String -Pattern 'slot(?: number | )([0-9]{1,})').Matches.Groups[1].Value + $pirq_map += $pirq_slot_number + $busid_ignore += $bus_id + break + } + } + } + } + # output map + Write-Verbose "$pirq_map" + } +} diff --git a/resources/icons/BitCapLngLogo_BLK-04.ico b/src/resources/icons/BitCapLngLogo_BLK-04.ico similarity index 100% rename from resources/icons/BitCapLngLogo_BLK-04.ico rename to src/resources/icons/BitCapLngLogo_BLK-04.ico diff --git a/resources/icons/BitCapLngLogo_BLK-04.png b/src/resources/icons/BitCapLngLogo_BLK-04.png similarity index 100% rename from resources/icons/BitCapLngLogo_BLK-04.png rename to src/resources/icons/BitCapLngLogo_BLK-04.png diff --git a/run_tests.ps1 b/src/run_tests.ps1 similarity index 98% rename from run_tests.ps1 rename to src/run_tests.ps1 index e05ff96..5d43caf 100644 --- a/run_tests.ps1 +++ b/src/run_tests.ps1 @@ -1,4 +1,4 @@ -. .\p7zip_util.ps1 +. .\include\p7zip.ps1 if (Test-Path -Path '.\instance.json') { $instance = (Get-Content '.\instance.json') | ConvertFrom-Json @@ -68,7 +68,7 @@ Function Test-Expected-Value $test_results = @() -$test_dirs = '.\tests\Amd', '.\tests\Baseboards', '.\tests\Nvidia' +$test_dirs = '..\tests\Amd', '..\tests\Baseboards', '..\tests\Nvidia' foreach ($test_path in $test_dirs) { if (Test-Path $test_path) diff --git a/GUI.xaml b/src/ui/GUI.xaml similarity index 98% rename from GUI.xaml rename to src/ui/GUI.xaml index 2bce5de..c079ba2 100644 --- a/GUI.xaml +++ b/src/ui/GUI.xaml @@ -27,6 +27,9 @@ + + + diff --git a/src/ui/Input.xaml b/src/ui/Input.xaml new file mode 100644 index 0000000..67aa959 --- /dev/null +++ b/src/ui/Input.xaml @@ -0,0 +1,22 @@ + + + + + + + + + + + +