# Ensure the script runs as Administrator
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Warning "You do not have Administrator rights to run this script! Please run PowerShell as an Administrator."
exit
}
# Check if Chocolatey is installed
if (!(Get-Command choco.exe -ErrorAction SilentlyContinue)) {
Write-Host "Chocolatey is not installed. Installing Chocolatey..."
Set-ExecutionPolicy Bypass -Scope Process -Force
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
} else {
Write-Host "Chocolatey is already installed."
}
# Install ARM GCC Toolchain
choco install -y gcc-arm-embedded
# Install OpenOCD
choco install -y openocd
# Install QEMU
choco install -y qemu
# Install GNU Make
choco install -y make
# Install LLVM (clang-format)
choco install -y llvm
# Install Go
choco install -y golang
# Ensure the Go bin path is set
$goBinPath = "$env:USERPROFILE\go\bin"
if (-not (Test-Path $goBinPath\go.exe)) {
Write-Host "Go binary not found in expected path, retrying with chocolatey path..."
$goBinPath = "$env:ProgramFiles\Go\bin"
}
if ($env:Path -notlike "*$goBinPath*") {
$env:Path += ";$goBinPath"
[System.Environment]::SetEnvironmentVariable("Path", $env:Path, [System.EnvironmentVariableTarget]::Machine)
Write-Host "Added Go bin to PATH."
} else {
Write-Host "Go bin already in PATH."
}
# Refresh the current session's environment variables
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::Machine)
# Verify Go installation
if (!(Get-Command go.exe -ErrorAction SilentlyContinue)) {
Write-Host "Go installation failed or Go binary not found."
exit
}
# Install Asmfmt using Go
go install github.com/klauspost/asmfmt/cmd/asmfmt@latest
# Verify Installations
Write-Host "Verifying installations..."
function Verify-Command {
param (
[string]$Command,
[string]$Name
)
Write-Host "Checking $Name..."
try {
& $Command --version
if ($LASTEXITCODE -ne 0) {
Write-Host "$Name installation failed"
}
} catch {
Write-Host "$Name installation failed"
}
}
Verify-Command "arm-none-eabi-gcc" "ARM GCC"
Verify-Command "openocd" "OpenOCD"
Verify-Command "qemu-system-arm" "QEMU"
Verify-Command "make" "GNU Make"
Verify-Command "clang-format" "LLVM (clang-format)"
Verify-Command "go" "Go"
Verify-Command "asmfmt" "Asmfmt"
Write-Host "Setup complete!"
# Open PowerShell as Administrator and then run these commands
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force
.\setup_environment.ps1