-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
executable file
·241 lines (207 loc) · 7.25 KB
/
install
File metadata and controls
executable file
·241 lines (207 loc) · 7.25 KB
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
#!/usr/bin/env perl
#====================================================================================
# install
#
# Installation script for easy_nrf52
#
# This file is part of easy_nrf52
# License: LGPL 2.1
# General and full license information is available at:
# https://github.com/plerup/easy_nrf52
#
# Copyright (c) 2022-2024 Peter Lerup. All rights reserved.
#
#====================================================================================
use strict;
use File::Basename;
use Cwd 'abs_path';
$| = 1;
my $env_name = "easy_nrf52";
my $this_dir = dirname(abs_path(__FILE__));
my $bin_dir = "/usr/local/bin";
my $lib_dir = "/usr/lib/x86_64-linux-gnu";
my $py_env_dir;
my $gcc_version = "gcc-arm-none-eabi-10.3-2021.10";
my @tool_list = (
"https://developer.arm.com/-/media/Files/downloads/gnu-rm/10.3-2021.10/$gcc_version-x86_64-linux.tar.bz2",
"https://nsscprodmedia.blob.core.windows.net/prod/software-and-other-downloads/desktop-software/nrf-command-line-tools/sw/versions-10-x-x/10-24-2/nrf-command-line-tools_10.24.2_amd64.deb",
);
sub prompt {
my ($mess, $def) = @_;
print $mess, " [$def]: ";
my $resp = <STDIN>;
$resp =~ s/\s*$//;
return $resp || $def;
}
#--------------------------------------------------------------------
sub find_sdk {
my ($vers) = @_;
my $main_ver = $1 if $vers =~ /^(\d+)/;
die "Invalid version: $vers\n" unless $main_ver;
my $url = "https://files.nordicsemi.com/artifactory/nRF5-SDK/external/nRF5_SDK_v$main_ver.x.x/";
my $list = `wget -O - $url 2>/dev/null`;
my $zip;
while ($list =~ s/href\=\"(nRF5_SDK_$vers\S+.zip)\"//m) {
$zip = "$url$1" unless $1 =~ /_doc/;
}
die "Unable to find version $vers\n" unless $zip;
return $zip;
}
#--------------------------------------------------------------------
sub command {
#print "* @_\n";
`@_`;
die "** Command failed! **\n@_\n" if $?;
}
#--------------------------------------------------------------------
sub mk_dir {
command("mkdir -p @_");
}
#--------------------------------------------------------------------
sub download {
my ($url, $dst_dir) = @_;
my $name = basename($url);
my $dst = "$dst_dir/$name";
print " $name\n";
return if -f $dst;
command("wget -q \"$url\" -O \"$dst\"");
}
#--------------------------------------------------------------------
sub string_to_file {
my $f;
open($f, ">$_[0]") || return 0;
print $f $_[1];
close($f);
return 1;
}
#--------------------------------------------------------------------
sub file_to_string {
local($/);
my $f;
open($f, $_[0]) || return "";
my $res = <$f>;
close($f);
return $res;
}
#--------------------------------------------------------------------
sub create_command {
my $dst = "$bin_dir/$_[0]";
command("sudo rm $dst") if -e $dst;
if ($_[1]) {
command("sudo sh -c 'echo $py_env_dir/bin/python3 $this_dir/tools/$_[0] \\\"\\\$\@\\\" >$dst'");
command("sudo chmod +x $dst");
} else {
command("sudo ln -s -f $this_dir/tools/$_[0] $dst");
}
}
#--------------------------------------------------------------------
sub fix_missing {
my ($dst, $alt) = @_;
if (!-e "$lib_dir/$dst" && -e "$lib_dir/$alt") {
command("sudo ln -sf $lib_dir/$alt $lib_dir/$dst");
}
}
#--------------------------------------------------------------------
print "==== Installing required tools for easy_nrf52 ====\n";
print "Admin rights are required\n";
command("sudo echo");
my $install_root = prompt("Installation root directory", "$ENV{'HOME'}/.$env_name");
my $sdk_list = prompt("Nordic SDK version(s)", "15 17");
my $nrfutil = "$install_root/nrfutil";
$py_env_dir = "$install_root/python_env";
my %sdks;
print "Validating SDKs...\n";
foreach (split(/\s+/, $sdk_list)) {
$sdks{$_} = find_sdk($_), "\n";
}
my @sdk_names = sort keys %sdks;
my $def_sdk;
do {
$def_sdk = prompt("Select default SDK", $sdk_names[0]);
} while (!$sdks{$def_sdk});
print "Checking/Installing required system tools...\n";
command("sudo apt update -qq -y >/dev/null 2>&1");
command("sudo apt install python3 python3-pip python3-venv ccache srecord openocd libzip-dev stlink-tools bluez bzip2 unzip curl libncurses5* -qq -y >/dev/null 2>&1");
command("sudo usermod -a -G dialout $ENV{'USER'}");
my $setup_dir = $install_root . "/setup";
mk_dir($setup_dir);
print "Downloading SDK(s) and tools...\n";
foreach (@sdk_names) {
download($sdks{$_}, $setup_dir);
}
foreach (@tool_list) {
download($_, $setup_dir);
}
print "Unpacking...\n";
foreach (glob("$setup_dir/*")) {
if (/nRF5_SDK/) {
/([^\/]+)\.zip/;
my $dir = "$install_root/$1";
print " $1\n";
command("rm -rf $dir") if -d $dir;
my $extract_dir = $dir =~ /SDK_17/ ? $dir : $install_root;
command("unzip -q -o -d $extract_dir $_");
# Patch the common makefiles in order to make them use the gcc installed here
my $mk_file = "$dir/components/toolchain/gcc/Makefile.posix";
my $txt = file_to_string($mk_file);
$txt =~ s/(GNU_INSTALL_ROOT \S=).+/$1 $install_root\/$gcc_version\/bin\//;
string_to_file($mk_file, $txt);
$mk_file = "$dir/components/toolchain/gcc/Makefile.common";
$txt = file_to_string($mk_file);
$txt =~ s/mkdir/mkdir -p/;
string_to_file($mk_file, $txt);
} elsif (/gcc-arm/) {
/(.+)\.bz/;
my $tar = $1;
print " ", basename($tar), "\n";
command("rm -rf $install_root/gcc-arm*");
command("bunzip2 -k $_");
command("tar -xf $tar -C $install_root");
command("rm $tar");
}
}
print "Installing...\n";
print" Packages\n";
command("sudo dpkg -i $setup_dir/*.deb >/dev/null");
print" Python requirements\n";
command("python3 -m venv $py_env_dir");
command("$py_env_dir/bin/pip -qq install pyserial bleak aioconsole");
print " Nordic tools\n";
command("curl -s https://files.nordicsemi.com/artifactory/swtools/external/nrfutil/executables/x86_64-unknown-linux-gnu/nrfutil " .
"-o $nrfutil");
command("chmod +x $nrfutil");
command("$nrfutil install -f device nrf5sdk-tools 2>/dev/null");
if (!`which JLinkConfig`) {
my $jlink_deb = "/tmp/JLink_Linux_x86_64.deb";
command("curl -s -X POST https://www.segger.com/downloads/jlink/JLink_Linux_x86_64.deb " .
"-H \"Content-Type: application/x-www-form-urlencoded\" " .
"-d \"accept_license_agreement=accepted\" -o $jlink_deb");
command("sudo apt install $jlink_deb -qq -y >/dev/null 2>&1");
}
if (`which code`) {
command("code --install-extension marus25.cortex-debug >/dev/null")
}
# Some fixes for required libraries missing in newer Ubuntu versions
fix_missing("libzip.so.5", "libzip.so.4");
fix_missing("libncurses.so.5", "libncursesw.so.6.4");
fix_missing("libtinfo.so.5", "libtinfo.so.6");
print" Creating command line commands\n";
create_command("enrfmake");
create_command("enrfuart", 1);
create_command("eenrfuart", 1);
create_command("enrfpath");
create_command("enrfscan", 1);
create_command("eenrfscan", 1);
my $def_priv_key = "$this_dir/bootloader/dev_priv_key.pem";
my $nrfutil_cmd = "$nrfutil nrf5sdk-tools";
command("$nrfutil_cmd keys generate $def_priv_key") unless -f $def_priv_key;
my $conf_dir = "$ENV{'HOME'}/.config/$env_name";
mk_dir($conf_dir);
string_to_file("$conf_dir/install",
"# $env_name installation information\n" .
"INSTALL_ROOT = $install_root\n" .
"SDK_VERSION = $def_sdk\n" .
"PATH := $py_env_dir/bin:\$(PATH)\n" .
"NRFUTIL = $nrfutil_cmd\n");
print "\n";
print "==== Installation completed ==== \n";