Commit 4a49b1d8 authored by romain pelletant's avatar romain pelletant Committed by Carles Cufi
Browse files

sample: net: add tftp client sample

Add simple TFTP client code using TFTP client library
Initiate connection (IPv4) with optional DNS resolution
Operate get operation then put operation in octet mode
Tested on native_posix
Issue/Discussion #60985

Signed-off-by: default avatarromain pelletant <romain.pelletant@fullfreqs.com>
parent f764e7e7
Loading
Loading
Loading
Loading
+10 −0
Changes for samples/net/tftp_client/CMakeLists.txt: 10 added lines, 0 removed lines.
Original line number Diff line number Diff line
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(tftp_client)

FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})

include(${ZEPHYR_BASE}/samples/net/common/common.cmake)
+21 −0
Changes for samples/net/tftp_client/Kconfig: 21 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Private config options for TFTP client sample

# Copyright (c) 2023 Kickmaker
# SPDX-License-Identifier: Apache-2.0

mainmenu "TFTP Client sample"

config TFTP_APP_PORT
	string "TFTP port used"
	default "69"
	help
	  TFTP port used.

config TFTP_APP_SERVER
	string "TFTP server address"
	default "192.0.2.2"
	help
	  TFTP server address. Write as a full URI including optional port number.
	  When DNS resolver is enabled, DNS domain names could be used as well.

source "Kconfig.zephyr"
+87 −0
Changes for samples/net/tftp_client/README.rst: 87 added lines, 0 removed lines.
Original line number Diff line number Diff line
.. _tftp-client-sample:

TFTP client
############

Overview
********

Trivial File Transfer Protocol (TFTP) is a simple lockstep File Transfer Protocol
based on UDP, and is designed to get a file from or put a file onto a remote host.

This TFTP client sample application for Zephyr implements the TFTP client library
and establishes a connection to a TFTP server on standard port 69.

The source code for this sample application can be found at:
:zephyr_file:`samples/net/tftp_client`.

Requirements
************

- :ref:`networking_with_eth_qemu`, :ref:`networking_with_qemu` or :ref:`networking_with_native_posix`
- Linux machine

Building and Running
********************

There are configuration files for various setups in the
samples/net/tftp_client directory:

- :file:`prj.conf`
  This is the standard default config.

Build the tftp-client sample application like this:

.. zephyr-app-commands::
   :zephyr-app: samples/net/tftp_client
   :board: <board to use>
   :conf: <config file to use>
   :goals: build
   :compact:

The easiest way to setup this sample application is to build and run it
as native POSIX application or as a QEMU target using the default configuration :file:`prj.conf`.
This requires a small amount of setup described in :ref:`networking_with_eth_qemu`, :ref:`networking_with_qemu` and :ref:`networking_with_native_posix`.

Build the tftp-client sample application for native_posix like this:

.. zephyr-app-commands::
   :zephyr-app: samples/net/tftp_client
   :host-os: unix
   :board: native_posix
   :goals: run
   :compact:

Download and run a TFTP server (like TFTPd), then create file1.bin (with data) and newfile.bin.

Please note that default IP server address is 192.0.2.2 and default port is 69.
To specify an IP server address and/or port, change configurations in ``prj.conf``::

    CONFIG_TFTP_APP_SERVER="10.0.0.10"
    CONFIG_TFTP_APP_PORT="70"

To connect to server using hostname, enable DNS resolver by changing these two
configurations in ``prj.conf``::

    CONFIG_DNS_RESOLVER=y
    CONFIG_TFTP_APP_SERVER="my-tftp-server.org"

Sample output
==================================

Sample run on native_posix platform with TFTP server on host machine
Launch net-setup.sh in net-tools
.. code-block:: console

   net-setup.sh

.. code-block:: console

    <inf> net_config: Initializing network
    <inf> net_config: IPv4 address: 192.0.2.1
    <inf> net_tftp_client_app: Run TFTP client
    <inf> net_tftp_client_app: Received data:
            74 65 73 74 74 66 74 70  66 6f 72 7a 65 70 68 79 |testtftp forzephy
            72 0a                                            |r.
    <inf> net_tftp_client_app: TFTP client get done
    <inf> net_tftp_client_app: TFTP client put done
+3 −0
Changes for samples/net/tftp_client/boards/native_posix.conf: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
CONFIG_DNS_RESOLVER=y
CONFIG_DNS_SERVER_IP_ADDRESSES=y
CONFIG_DNS_SERVER1="192.0.2.2"
+4 −0
Changes for samples/net/tftp_client/boards/qemu_cortex_m3.conf: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
CONFIG_NET_L2_ETHERNET=y
CONFIG_ETH_DRIVER=y
CONFIG_ETH_STELLARIS=y
CONFIG_NET_QEMU_ETHERNET=y
Loading