Skip to content

Commit 6d07426

Browse files
authored
Merge pull request #10 from ewen-naos-nz/tftp-alt-port
TFTP: Support alternate TFTP Server Port
2 parents 04756ea + 920d512 commit 6d07426

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

Makefile

+34-5
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ TFTP_IPRANGE ?= 192.168.100
125125
export TFTP_IPRANGE
126126
TFTPD_DIR ?= build/tftpd/
127127

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+
128135
# Couple of Python settings.
129136
# ---------------------------------
130137
# Turn off Python's hash randomization
@@ -298,6 +305,16 @@ bios-flash: $(BIOS_FILE) bios-flash-$(PLATFORM)
298305
# TFTP booting stuff
299306
# --------------------------------------
300307
# 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+
301318
tftp: $(FIRMWARE_FILEBASE).bin
302319
mkdir -p $(TFTPD_DIR)
303320
cp $(FIRMWARE_FILEBASE).bin $(TFTPD_DIR)/boot.bin
@@ -308,13 +325,24 @@ tftpd_stop:
308325

309326
tftpd_start:
310327
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 \
313333
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 \
316340
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 \
318346
else \
319347
echo "Cannot find an appropriate tftpd binary to launch the server."; \
320348
false; \
@@ -354,6 +382,7 @@ env:
354382
@echo "export BIOS_FILE='$(BIOS_FILE)'"
355383
@# Network settings
356384
@echo "export TFTP_IPRANGE='$(TFTP_IPRANGE)'"
385+
@echo "export TFTP_SERVER_PORT='$(TFTP_SERVER_PORT)'"
357386
@echo "export TFTPD_DIR='$(TFTPD_DIR)'"
358387

359388
info:

0 commit comments

Comments
 (0)