-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ps1
312 lines (266 loc) · 14.1 KB
/
build.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# Powershell-script for building and flashing unto nRF-DK with nRF Connect SDK toolchain.
# The Powershell extension, by Microsoft is needed to run this script in VS Code.
# Fill out the local variables before first run.
#
# Press "F5" to start powershell and run script,
# press "F8" to run current line or marked content.
#
# This file should be placed above the src-folder.
# To avoid messy terminal log, press: CTRL+Shift+P, and search for tclear command.
Clear-Host
Write-Host "STARTING SCRIPT" -ForegroundColor Magenta
$startTime = Get-Date
Write-Host "...Setting variables" -ForegroundColor Magenta
## Paths
$currentPath = $PSScriptRoot
$ncsFolder = west topdir
$buildFileCheck = "\build\zephyr\zephyr.hex"
## Process settings
$deleteBuildFiles = $true # Buildfiles are deleted before each build.
$buildWithoutBoard = $false # Build without connecting a board
$fakeBoard = @("nrf5340dk_nrf5340_cpuapp", "nrf5340dk_nrf5340_cpunet")
$forceFlash = $false # Flash regardless of build success
$flashAfterBuild = $true # Flash after each build
$confirmEveryPerformedFlash = $false # Only functional for 53 and 91
$nrf91Check = $false
$logFlashProcess = $false # Not inmplemented yet
$reset840AfterFlash = $true # Temporary fix for 840 not booting correctly
## Supported board types
$BoardSpecs = @(
[pscustomobject]@{ DevKit = 'NRF5340 DK 0.11';
DeviceVersion = 'NRF5340_xxAA_ENGD';
CoreVariants = @("nrf5340dk_nrf5340_cpuapp",
"nrf5340dk_nrf5340_cpunet");
CoreNames = @("Applikasjonskjernen",
"Nettverkskjernen");
FilePaths = @("$currentPath",
"$ncsFolder\nrf_midi_priv\samples\hci_rpmsg\");
ProjectSupport = $true
Boards2Flash = 0
BoardSerials = $null
}
[pscustomobject]@{ DevKit = 'NRF9160';
DeviceVersion = 'NRF9160_xxAA_REV2';
CoreVariants = @("nrf9160dk_nrf9160ns",
"nrf52840dk_nrf52840");
CoreNames = @("Modem-delen",
"BLE-delen");
FilePaths = @("$currentPath",
"$ncsFolder\nrf_midi_priv\samples\hci_rpmsg\")
ProjectSupport = $false
Boards2Flash = 0
BoardSerials = $null
}
[pscustomobject]@{ DevKit = 'NRF52840 REV1'; # On nRF9160 Rev2 DK
DeviceVersion = 'NRF52840_xxAA_REV1';
CoreVariants = @("nrf52840dk_nrf52840");
CoreNames = @("840-en");
FilePaths = @("$currentPath")
ProjectSupport = $false
Boards2Flash = 0
BoardSerials = $null
}
[pscustomobject]@{ DevKit = 'NRF52840 REV2';
DeviceVersion = 'NRF52840_xxAA_REV2';
CoreVariants = @("nrf52840dk_nrf52840");
CoreNames = @("8-40-en");
FilePaths = @("$currentPath")
ProjectSupport = $true
Boards2Flash = 0
BoardSerials = $null
}
[pscustomobject]@{ DevKit = 'NRF52832 REV2';
DeviceVersion = 'NRF52832_xxAA_REV2';
CoreVariants = @("nrf52dk_nrf52832");
CoreNames = @("8-32-en");
FilePaths = @("$currentPath")
ProjectSupport = $false
Boards2Flash = 0
BoardSerials = $null
}
)
$nrf5340pdkA = 0
$nrf5340pdkB = 1
$nrf5340dk = 2
$nrf9160 = 3
$nrf52840r1 = 4 # On nRF9160 Rev2 DK
$nrf52840r2 = 5
$nrf52832 = 6
## Checks how many boards are connected
Write-Host "...Checking for connected boards" -ForegroundColor Magenta
$allSerials = @(nrfjprog -i)
nrfjprog -i
$amountOfBoardsConnected = $allSerials.Count
## Check what type of boards are connected, no building or flashing.
if ($allSerials.Count -eq 0) {
#No boards connected
if ($buildWithoutBoard) {
Write-Host "...No boards connected, no flashing will be performed" -ForegroundColor Magenta
$flashAfterBuild = $false
## For each type of board spec available
for ($spec=0 ;$spec -lt $BoardSpecs.Count; $spec++){
## For each fake board "connected"
for ($board=0 ;$board -lt $fakeBoard.Count; $board++){
$boardFamily = $fakeBoard[$board]
$matchCheck = $boardFamily -Match $BoardSpecs[$spec].DeviceVersion
if ($matchCheck) {
$BoardSpecs[$spec].Boards2Flash++
## Add board serial to flash list
if ($BoardSpecs[$spec].BoardSerials -eq $null) {
$BoardSpecs[$spec].BoardSerials = @($allSerials[$board])
} else {
$BoardSpecs[$spec].BoardSerials += $allSerials[$board]
}
}
}
$printVal1 = $BoardSpecs[$spec].DevKit
$printVal2 = $BoardSpecs[$spec].Boards2Flash
$printVal3 = $BoardSpecs[$spec].BoardSerials
Write-Host "$printVal2 x$printVal1 : $printVal3`r"
}
# Build only
} else {
Write-Host "...No boards connected, aborting script" -ForegroundColor Magenta
exit
}
} else {
Write-Host "...$amountOfBoardsConnected board(s) connected, checking board variant(s)" -ForegroundColor Magenta
## For each type of board spec available
for ($spec=0 ;$spec -lt $BoardSpecs.Count; $spec++){
## For each board connected
for ($board=0 ;$board -lt $allSerials.Count; $board++){
$boardFamily = nrfjprog --snr $allSerials[$board] --deviceversion
$matchCheck = $boardFamily -Match $BoardSpecs[$spec].DeviceVersion
if ($matchCheck) {
## Checks wether the 840 should have been a 91.
if ($BoardSpecs[$spec].DevKit -eq "NRF52840" -and $nrf91Check -and $BoardSpecs[$nrf9160].Boards2Flash -eq 0 -and $BoardSpecs[$nrf9160].ProjectSupport) {
$coreChanged = $false
$BoardSpecs[$nrf9160].BoardSerials = $null
while (-Not $coreChanged) {
Read-Host "No nRF91 connected, switch to it and press enter to continue"
$allSerials = @(nrfjprog -i)
## For each board connected
for ($board=0 ;$board -lt $allSerials.Count; $board++){
$boardFamily = nrfjprog --snr $allSerials[$board] --deviceversion
$matchCheck = $boardFamily -Match $BoardSpecs[$nrf9160].DeviceVersion
if ($matchCheck) {
$coreChanged = $true
}
}
}
#This might create an bug.
$spec = 0
$board = 0
break
}
$BoardSpecs[$spec].Boards2Flash++
## Add board serial to flash list
if ($BoardSpecs[$spec].BoardSerials -eq $null) {
$BoardSpecs[$spec].BoardSerials = @($allSerials[$board])
} else {
$BoardSpecs[$spec].BoardSerials += $allSerials[$board]
}
}
}
$printVal1 = $BoardSpecs[$spec].DevKit
$printVal2 = $BoardSpecs[$spec].Boards2Flash
$printVal3 = $BoardSpecs[$spec].BoardSerials
Write-Host "$printVal2 x$printVal1 : $printVal3`r"
}
}
## Build and flash to every supported board variant
for ($build = 0; $build -lt $BoardSpecs.Count; $build++) {
## Amount of boards to flash
if ($BoardSpecs[$build].Boards2Flash -gt 0 -and $BoardSpecs[$build].ProjectSupport) {
$printVal = $BoardSpecs[$build].DevKit
Write-Host "...Building and flashing to $printVal" -ForegroundColor Magenta
for ($cores = 0; $cores -lt $BoardSpecs[$build].CoreVariants.Count; $cores++) {
# Change directory for application sample
$activeDirectory = $BoardSpecs[$build].FilePaths[$cores]
Write-Host "...Changing directory" -ForegroundColor Magenta
Write-Host "Set-Location $activeDirectory" -ForegroundColor Yellow
Set-Location $activeDirectory
## Delete old build
if ($deleteBuildFiles) {
Write-Host "...Deleting old build-files" -ForegroundColor Magenta
Write-Host "Remove-Item -LiteralPath 'build' -Force -Recurse" -ForegroundColor Yellow
Remove-Item -LiteralPath "build" -Force -Recurse
}
$printVal = $BoardSpecs[$build].CoreNames[$cores]
Write-Host "...$printVal" -ForegroundColor Magenta
## Build
$printVal = $BoardSpecs[$build].CoreVariants[$cores]
Write-Host "west build -b $printVal" -ForegroundColor Yellow
west build -b $BoardSpecs[$build].CoreVariants[$cores]
[System.Console]::Beep(440,100)
[System.Console]::Beep(523,100)
## Checks whether build was succesfull or not.
if ((Test-Path "$activeDirectory$buildFileCheck" -PathType leaf) -Or $forceFlash) {
[System.Console]::Beep(659,600)
$printVal = $BoardSpecs[$build].CoreNames[$cores]
Write-Host "...Sucessfull build to $printVal!" -ForegroundColor Magenta
if ($flashAfterBuild) {
## Flash
Write-Host "...Running West Flash on $printVal" -ForegroundColor Magenta
for ($flash = 0; $flash -lt $BoardSpecs[$build].Boards2Flash; $flash++) {
$printVal1 = $flash + 1
$printVal2 = $BoardSpecs[$build].Boards2Flash
Write-Host "...Flashing board $printVal1/$printVal2"-ForegroundColor Magenta
$printVal = $BoardSpecs[$build].BoardSerials[$flash]
if ($logFlashProcess) {
Write-Host "west flash --snr $printVal" -ForegroundColor Yellow
west flash --snr $BoardSpecs[$build].BoardSerials[$flash]
} else {
Write-Host "west flash --snr $printVal" -ForegroundColor Yellow
west flash --snr $BoardSpecs[$build].BoardSerials[$flash]
}
}
$printVal = $BoardSpecs[$build].CoreNames[$cores]
Write-Host "...Flashing of $printVal performed" -ForegroundColor Magenta
## If nRF91, prompt change to 840.
if ($BoardSpecs[$build].DevKit -eq "NRF9160" -and $cores -eq 0) {
$coreChanged = $false
while (-Not $coreChanged) {
read-host "Change to nRF52 and Press ENTER to continue..."
$allSerials = @(nrfjprog -i)
## For each board connected
for ($board=0 ;$board -lt $allSerials.Count; $board++){
$boardFamily = nrfjprog --snr $allSerials[$board] --deviceversion
$matchCheck = $boardFamily -Match $BoardSpecs[$nrf52840r1].DeviceVersion
if ($matchCheck) {
$coreChanged = $true
}
}
}
} elseif ($confirmEveryPerformedFlash) {
read-host "Press ENTER to continue..."
}
if ($BoardSpecs[$build].DevKit -eq "NRF52840 REV2" -and $reset840AfterFlash -eq $true) {
Write-Host "...Resetting 840 (cause it doesn't always work..." -ForegroundColor Magenta
for ($resetb = 0; $resetb -lt $BoardSpecs[$build].Boards2Flash; $resetb++) {
$printVal = $BoardSpecs[$build].BoardSerials[$resetb]
Write-Host "nrfjprog --snr $printVal --reset" -ForegroundColor Yellow
nrfjprog --snr $BoardSpecs[$build].BoardSerials[$resetb] --reset
}
}
} else {
Write-Host "...Flash turned off" -ForegroundColor Magenta
}
} else {
[System.Console]::Beep(420,600)
$printVal = $BoardSpecs[$build].CoreNames[$cores]
Write-Host "...Failed to build sample, aborting" -ForegroundColor Magenta
break
}
}
} elseif ($BoardSpecs[$build].Boards2Flash -gt 0 -and -Not $BoardSpecs[$build].ProjectSupport){
$printVal = $BoardSpecs[$build].DevKit
Write-Host "...Board $printVal not supported" -ForegroundColor Magenta
}
}
## Resetting and changing directory to default
Set-Location $ncsFolder
$endTime = Get-Date
$timePassed = $endTime - $startTime
[system.media.systemsounds]::Hand.play()
Write-Host "$endTime Script finished after $timePassed! To remove terminal log: click CTRL+Shift+P and search for Terminal Clear." -ForegroundColor Magenta