-
Notifications
You must be signed in to change notification settings - Fork 0
/
env.ps1
118 lines (98 loc) · 2.93 KB
/
env.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
param(
[switch] $init,
[switch] $upgrade
)
function Add-ToPath([string] $path)
{
if (-not (Test-Path -path $path))
{
throw "ERROR_NONEXISTENT_PATH"
}
$env:Path = "$Path;" + $env:Path
}
try {
$output = . choco
Write-Host -ForegroundColor Green "Chocolatey is installed"
}
catch {
Write-Host -ForegroundColor Yellow "Chocolatey is not installed"
# TODO: try to auto install chocolatey
Write-Host -ForegroundColor Red "Installing Chocolatey is not supported. Please install Chocolatey and re-run this script"
exit
}
$packages = @("git", "python", "ninja", "dtc-msys2", "gperf")
# Setup for first-time use
if ($init)
{
. choco install -y cmake --installargs 'ADD_CMAKE_TO_PATH=System'
. choco install -y git python ninja dtc-msys2 gperf nuget.commandline
# install ARM GCC toolchain
git submodule update --init
# run:
pip3 install --user -r zephyr/scripts/requirements.txt
# from zephyr project
nuget install autom8ed.com.compilers.arm-none-eabi-gcc -OutputDirectory "$PSScriptRoot\pkg"
}
$env:ZEPHYR_TOOLCHAIN_VARIANT="gccarmemb"
$env:GCCARMEMB_TOOLCHAIN_PATH="$PSScriptRoot\pkg\autom8ed.com.compilers.arm-none-eabi-gcc.6.3.1"
# Try to detect a J-Link installation
# Check Program Files (x86) first
$seggerPath = $null
if (Test-Path -Path "C:\Program Files (x86)" -PathType Container)
{
$seggerPath = ((Get-ChildItem -Path "C:\Program Files (x86)") | Where-Object {$_.Name -eq "SEGGER"})
}
if ($seggerPath -eq $null)
{
if (Test-Path -Path "C:\Program Files" -PathType Container)
{
$seggerPath = ((Get-ChildItem -Path "C:\Program Files") | Where-Object {$_.Name -eq "SEGGER"})
}
}
if ($seggerPath -ne $null)
{
$jlinkPath = $null
# found a SEGGER install folder. See if there are any J-Link installs there
if (($seggerPath -ne $null) -and ($seggerPath.Count -eq 1))
{
$jlinkVersions = ((Get-ChildItem -Path $seggerPath.FullName) | Where-Object {$_.Name.StartsWith("JLink_") })
$recentVersion = $null
foreach($version in $jlinkVersions)
{
if ($recentVersion -eq $null)
{
$recentVersion = $version
continue
}
if ($recentVersion -lt $version)
{
$recentVersion = $version
}
}
if ($recentVersion -ne $null)
{
$jlinkPath = $recentVersion.FullName
}
}
elseif ($seggerPath.Count -gt 1)
{
Write-Error "Multiple SEGGER folders found in C:\Program Files (x86)"
}
if ($jlinkPath -ne $null)
{
Write-Host "Using SEGGER install from $jlinkPath"
Add-ToPath -path $jlinkPath
}
else
{
Write-Warning "Could not find JLink install under $seggerPath. Live debugging and MCU Flashing commands will be unavailable."
Write-Warning "Install J-Link from SEGGER Website"
}
}
else
{
Write-Warning "Could not find SEGGER folder. Live debugging and MCU Flashing commands will be unavailable."
Write-Warning "Install J-Link from SEGGER Website"
}
$env:ZEPHYR_BASE="$PSScriptRoot\zephyr"
Set-Alias -Name west -Value ". py -3 $env:ZEPHYR_BASE\scripts\west-win.py" -Scope 1