/
makefile.iotlab.single.inc.mk
218 lines (189 loc) · 7.83 KB
/
makefile.iotlab.single.inc.mk
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
# Use a single iot-lab node with RIOT
# ===================================
#
# Supported:
# * flash
# * reset
# * term
#
# Tested on m3/a8-m3/samr21/arduino-zero nodes
#
# It can be run:
# * From your computer by setting IOTLAB_NODE to the full url like
# m3-380.grenoble.iot-lab.info or a8-1.grenoble.iot-lab.info
# * From IoT-LAB frontend by setting IOTLAB_NODE to the short url like
# m3-380 or a8-1
#
# # Usage
#
# make BOARD=iotlab-m3 IOTLAB_NODE=m3-380.grenoble.iot-lab.info flash term
#
# It is the user responsibility to start an experiment beforehand
#
# If the user has multiple running experiments, the one to use must be
# configured with the `IOTLAB_EXP_ID` setting
#
# Prerequisites
# -------------
#
# * Install iotlab-cli-tools: https://github.com/iot-lab/cli-tools
# * Configure your account with 'iotlab-auth'
# * Register your computer public key in your ssh keys list on your profile:
# https://www.iot-lab.info/tutorials/configure-your-ssh-access/
# * If using an A8 node from a frontend:
# * Register the frontend public key in your ssh keys list on your profile.
# https://www.iot-lab.info/tutorials/ssh-cli-client/
#
# Additional for A8 nodes
#
# * Install iotlab-ssh-cli-tools https://github.com/iot-lab/ssh-cli-tools
ifeq (,$(IOTLAB_NODE))
$(warning IOTLAB_NODE undefined, it should be defined to:)
$(warning * <type>-<number>.<site>.iot-lab.info when run from your computer)
$(warning Example: m3-380.grenoble.iot-lab.info or a8-1.grenoble.iot-lab.info)
$(warning * <type>-<number> when run from iot-lab frontend)
$(warning Example: m3-380 or a8-1)
$(warning * 'auto' or 'auto-ssh' to try auto-detecting the node from your experiment
$(error)
endif
IOTLAB_AUTH ?= $(HOME)/.iotlabrc
IOTLAB_USER ?= $(shell cut -f1 -d: $(IOTLAB_AUTH))
# Optional Experiment id. Required when having multiple experiments
IOTLAB_EXP_ID ?=
# Specify experiment-id option if provided
_IOTLAB_EXP_ID := $(if $(IOTLAB_EXP_ID),--id $(IOTLAB_EXP_ID))
# Number of the node to take from the list in 'auto' and 'auto-ssh' mode
# Default to 1 so the first one
IOTLAB_NODE_AUTO_NUM ?= 1
# board-archi mapping
IOTLAB_ARCHI_arduino-zero = arduino-zero:xbee
IOTLAB_ARCHI_b-l072z-lrwan1 = st-lrwan1:sx1276
IOTLAB_ARCHI_b-l475e-iot01a = st-iotnode:multi
IOTLAB_ARCHI_firefly = firefly:multi
IOTLAB_ARCHI_frdm-kw41z = frdm-kw41z:multi
IOTLAB_ARCHI_iotlab-a8-m3 = a8:at86rf231
IOTLAB_ARCHI_iotlab-m3 = m3:at86rf231
IOTLAB_ARCHI_microbit = microbit:ble
IOTLAB_ARCHI_nrf51dk = nrf51dk:ble
IOTLAB_ARCHI_nrf52dk = nrf52dk:ble
IOTLAB_ARCHI_nrf52832-mdk = nrf52832mdk:ble
IOTLAB_ARCHI_nrf52840dk = nrf52840dk:multi
IOTLAB_ARCHI_nrf52840-mdk = nrf52840mdk:multi
IOTLAB_ARCHI_pba-d-01-kw2x = phynode:kw2xrf
IOTLAB_ARCHI_samr21-xpro = samr21:at86rf233
IOTLAB_ARCHI_samr30-xpro = samr30:at86rf212b
IOTLAB_ARCHI := $(IOTLAB_ARCHI_$(BOARD))
# There are several deprecated and incompatible features used here that were
# introduced between versions 2 and 3 of the IoT-LAB cli tools.
# For backward compatibility, we manage these changes here.
_CLI_TOOLS_MAJOR_VERSION ?= $(shell iotlab-experiment --version | cut -f1 -d.)
ifeq (2,$(_CLI_TOOLS_MAJOR_VERSION))
_NODES_DEPLOYED = $(shell iotlab-experiment --jmespath='deploymentresults."0"' --format='" ".join' get $(_IOTLAB_EXP_ID) --print)
_NODES_LIST_OPTION = --resources
_NODES_FLASH_OPTION = --update
else
_NODES_DEPLOYED = $(shell iotlab-experiment --jmespath='"0"' --format='" ".join' get $(_IOTLAB_EXP_ID) --deployment)
_NODES_LIST_OPTION = --nodes
_NODES_FLASH_OPTION = --flash
ifneq (firefly,$(BOARD))
# All boards in IoT-LAB except firefly can be flashed using $(BINFILE).
# On IoT-LAB, firefly only accepts $(ELFFILE) and WSN320 boards on accept $(HEXFILE).
# Using $(BINFILE) speeds up the firmware upload since the file is much
# smaller than an elffile.
# This feature is only available in cli-tools version >= 3.
FLASHFILE = $(BINFILE)
endif
endif
# Try detecting the node automatically
# * It takes the first working node that match BOARD
# * Check correctly deployed nodes with 'deploymentresults == "0"'
# * Select nodes by architucture using the board-archi mapping
# * Nodes for current server in 'auto'
ifneq (,$(filter auto auto-ssh,$(IOTLAB_NODE)))
ifeq (,$(IOTLAB_ARCHI))
$(error Could not find 'archi' for $(BOARD), update mapping in $(lastword $(MAKEFILE_LIST)))
endif
ifeq (auto,$(IOTLAB_NODE))
_NODES_DEPLOYED := $(filter %.$(shell hostname).iot-lab.info, $(_NODES_DEPLOYED))
endif
_NODES_FOR_BOARD = $(shell iotlab-experiment --jmespath="items[?archi=='$(IOTLAB_ARCHI)'].network_address" --format='" ".join' get $(_IOTLAB_EXP_ID) $(_NODES_LIST_OPTION))
_IOTLAB_NODE := $(word $(IOTLAB_NODE_AUTO_NUM),$(filter $(_NODES_DEPLOYED),$(_NODES_FOR_BOARD)))
ifeq (auto,$(IOTLAB_NODE))
override IOTLAB_NODE := $(firstword $(subst ., ,$(_IOTLAB_NODE)))
else
override IOTLAB_NODE := $(_IOTLAB_NODE)
endif
ifeq (,$(IOTLAB_NODE))
$(error Could not automatically find a node for BOARD=$(BOARD))
endif
override IOTLAB_NODE := $(patsubst node-%,%,$(IOTLAB_NODE))
endif
# If the IOTLAB_NODE format is:
# * 'type-num.iot.lab.info' assume it is run from your computer
# * 'type-num' assume it is run from iot-lab frontend
ifneq (,$(filter %.iot-lab.info, $(IOTLAB_NODE)))
_IOTLAB_ON_FRONTEND =
else
_IOTLAB_ON_FRONTEND = 1
endif
# Work with node url without 'node-'
override IOTLAB_NODE := $(patsubst node-%,%,$(IOTLAB_NODE))
# Create node list and optionally frontend url
ifeq (,$(_IOTLAB_ON_FRONTEND))
# m3-380.grenoble.iot-lab.info -> grenoble,m3,380
# a8-1.grenoble.iot-lab.info -> grenoble,a8,1
_NODELIST_SED := 's/\([^.]*\)-\([^.]*\).\([^.]*\).*/\3,\1,\2/'
_IOTLAB_NODELIST := --list $(shell echo '$(IOTLAB_NODE)' | sed $(_NODELIST_SED))
# Remove the node type-number part
_IOTLAB_SERVER := $(shell echo '$(IOTLAB_NODE)' | sed 's/[^.]*.//')
_IOTLAB_AUTHORITY = $(IOTLAB_USER)@$(_IOTLAB_SERVER)
else
# m3-380 -> $(hostname),m3,380
# a8-1 -> $(hostname),a8,1
_NODELIST_SED := 's/\([^.]*\)-\([^.]*\)/$(shell hostname),\1,\2/'
_IOTLAB_NODELIST := --list $(shell echo '$(IOTLAB_NODE)' | sed $(_NODELIST_SED))
endif
# Display value of IOTLAB_NODE, useful to get the value calculated when using
# IOTLAB_NODE=auto or auto-ssh
.PHONY: info-iotlab-node
info-iotlab-node:
@echo $(IOTLAB_NODE)
# Configure FLASHER, RESET, TERMPROG depending on BOARD and if on frontend
# Command to check if 'stdin' is 0. Cannot use 'cmp - <(echo 0)' without bash shell
_STDIN_EQ_0 = grep 0
ifneq (iotlab-a8-m3,$(BOARD))
# M3 nodes
FLASHER = iotlab-node
RESET = iotlab-node
_NODE_FMT = --jmespath='keys(@)[0]' --format='int'
FFLAGS = $(_NODE_FMT) $(_IOTLAB_EXP_ID) $(_IOTLAB_NODELIST) $(_NODES_FLASH_OPTION) $(FLASHFILE) | $(_STDIN_EQ_0)
RESET_FLAGS = $(_NODE_FMT) $(_IOTLAB_EXP_ID) $(_IOTLAB_NODELIST) --reset | $(_STDIN_EQ_0)
ifeq (,$(_IOTLAB_ON_FRONTEND))
TERMPROG = ssh
TERMFLAGS = -t $(_IOTLAB_AUTHORITY) 'socat - tcp:$(IOTLAB_NODE):20000'
else
TERMPROG = socat
TERMFLAGS = - tcp:$(IOTLAB_NODE):20000
endif
else
# A8-M3 node
FLASHER = iotlab-ssh
RESET = iotlab-ssh
_NODE_FMT = --jmespath='keys(values(@)[0])[0]' --fmt='int'
FFLAGS = $(_NODE_FMT) $(_IOTLAB_EXP_ID) flash-m3 $(_IOTLAB_NODELIST) $(FLASHFILE) | $(_STDIN_EQ_0)
RESET_FLAGS = $(_NODE_FMT) $(_IOTLAB_EXP_ID) reset-m3 $(_IOTLAB_NODELIST) | $(_STDIN_EQ_0)
TERMPROG = ssh
ifeq (,$(_IOTLAB_ON_FRONTEND))
# Proxy ssh through the iot-lab frontend
TERMFLAGS = -oProxyCommand='ssh $(_IOTLAB_AUTHORITY) -W %h:%p'
else
# Empty existing RIOT TERMFLAGS
TERMFLAGS =
endif
TERMFLAGS += -oStrictHostKeyChecking=no -t root@node-$(IOTLAB_NODE) 'socat - open:/dev/ttyA8_M3,b$(BAUD),echo=0,raw'
endif
# Debugger not supported
DEBUGGER =
DEBUGGER_FLAGS =
DEBUGSERVER =
DEBUGSERVER_FLAGS =