@@ -125,6 +125,13 @@ TFTP_IPRANGE ?= 192.168.100
125
125
export TFTP_IPRANGE
126
126
TFTPD_DIR ?= build/tftpd/
127
127
128
+ # Well known TFTP Server Port is UDP/69
129
+ # Default to high numbered port so we can run TFTP server as non-root
130
+ # (export into shell environment to use during building firmware BIOS)
131
+ #
132
+ TFTP_SERVER_PORT ?= 6069
133
+ export TFTP_SERVER_PORT
134
+
128
135
# Couple of Python settings.
129
136
# ---------------------------------
130
137
# Turn off Python's hash randomization
@@ -298,6 +305,16 @@ bios-flash: $(BIOS_FILE) bios-flash-$(PLATFORM)
298
305
# TFTP booting stuff
299
306
# --------------------------------------
300
307
# TFTP server for minisoc to load firmware from
308
+ #
309
+ # We can run the TFTP server as the user if port >= 1024
310
+ # otherwise we need to run as root using sudo
311
+
312
+ ATFTPD =$(shell which atftpd)
313
+ ATFTPD? =/usr/sbin/atftpd
314
+
315
+ IN_TFTPD =$(shell which in.tfptd)
316
+ IN_TFTPD=? =/usr/sbin/in.tftpd
317
+
301
318
tftp : $(FIRMWARE_FILEBASE ) .bin
302
319
mkdir -p $(TFTPD_DIR )
303
320
cp $(FIRMWARE_FILEBASE ) .bin $(TFTPD_DIR ) /boot.bin
@@ -308,13 +325,24 @@ tftpd_stop:
308
325
309
326
tftpd_start :
310
327
mkdir -p $(TFTPD_DIR )
311
- sudo true
312
- @if sudo which atftpd > /dev/null ; then \
328
+ @if [ $( TFTP_SERVER_PORT) -lt 1024 ]; then \
329
+ echo " Root required to run TFTP Server, will use sudo" ; \
330
+ sudo true ; \
331
+ fi
332
+ @if [ -x " $( ATFTPD) " ]; then \
313
333
echo " Starting aftpd" ; \
314
- sudo atftpd --verbose --bind-address $(TFTP_IPRANGE ) .100 --daemon --logfile /dev/stdout --no-fork --user $(shell whoami) --group $(shell id -gn) $(TFTPD_DIR ) & \
315
- elif sudo which in.tftpd > /dev/null; then \
334
+ if [ $( TFTP_SERVER_PORT) -lt 1024 ]; then \
335
+ sudo " $( ATFTPD) " --verbose --bind-address $(TFTP_IPRANGE ) .100 --port $(TFTP_SERVER_PORT ) --daemon --logfile /dev/stdout --no-fork --user $(shell whoami) --group $(shell id -gn) $(TFTPD_DIR ) & \
336
+ else \
337
+ " $( ATFTPD) " --verbose --bind-address $(TFTP_IPRANGE ) .100 --port $(TFTP_SERVER_PORT ) --daemon --logfile /dev/stdout --no-fork --user $(shell whoami) --group $(shell id -gn) $(TFTPD_DIR ) & \
338
+ fi \
339
+ elif [ -x " $( IN_TFTPD) " ]; then \
316
340
echo " Starting in.tftpd" ; \
317
- sudo in.tftpd --verbose --listen --address $(TFTP_IPRANGE ) .100 --user $(shell whoami) -s $(TFTPD_DIR ) & \
341
+ if [ $( TFTP_SERVER_PORT) -lt 1024 ]; then \
342
+ sudo " $( IN_TFTPD) " --verbose --listen --address $(TFTP_IPRANGE ) .100 --port-range $(TFTP_SERVER_PORT ) :$(TFTP_SERVER_PORT ) --user $(shell whoami) -s $(TFTPD_DIR ) & \
343
+ else \
344
+ " $( IN_TFTPD) " --verbose --listen --address $(TFTP_IPRANGE ) .100 --port-range $(TFTP_SERVER_PORT ) :$(TFTP_SERVER_PORT ) --user $(shell whoami) -s $(TFTPD_DIR ) & \
345
+ fi \
318
346
else \
319
347
echo " Cannot find an appropriate tftpd binary to launch the server." ; \
320
348
false ; \
354
382
@echo " export BIOS_FILE='$( BIOS_FILE) '"
355
383
@# Network settings
356
384
@echo " export TFTP_IPRANGE='$( TFTP_IPRANGE) '"
385
+ @echo " export TFTP_SERVER_PORT='$( TFTP_SERVER_PORT) '"
357
386
@echo " export TFTPD_DIR='$( TFTPD_DIR) '"
358
387
359
388
info :
0 commit comments