[PATCH 1/2] bsps/stm32h7: move BSP start hooks into boards subdirectories
The idea here is to prepare for better per-board specialization of the hooks function code. Sponsored-By: Precidata --- .../stm/nucleo-h743zi/stm32h7-bspstarthooks.c | 78 +++ .../stm32h743i-eval/stm32h7-bspstarthooks.c | 78 +++ .../stm32h747i-disco/stm32h7-bspstarthooks.c | 78 +++ .../stm32h757i-eval/stm32h7-bspstarthooks.c | 78 +++ .../stm/stm32h7b3i-dk/stm32h7-bspstarthooks.c | 78 +++ bsps/arm/stm32h7/include/bsp.h| 6 ++ bsps/arm/stm32h7/start/bspstarthooks.c| 48 +--- .../bsps/arm/stm32h7/bspnucleoh743zi.yml | 1 + spec/build/bsps/arm/stm32h7/bspstm32h7.yml| 1 + .../arm/stm32h7/bspstm32h747i-disco-m4.yml| 1 + .../bsps/arm/stm32h7/bspstm32h747i-disco.yml | 1 + .../arm/stm32h7/bspstm32h757i-eval-m4.yml | 1 + .../bsps/arm/stm32h7/bspstm32h757i-eval.yml | 1 + .../bsps/arm/stm32h7/bspstm32h7b3i-dk.yml | 1 + 14 files changed, 407 insertions(+), 44 deletions(-) create mode 100644 bsps/arm/stm32h7/boards/stm/nucleo-h743zi/stm32h7-bspstarthooks.c create mode 100644 bsps/arm/stm32h7/boards/stm/stm32h743i-eval/stm32h7-bspstarthooks.c create mode 100644 bsps/arm/stm32h7/boards/stm/stm32h747i-disco/stm32h7-bspstarthooks.c create mode 100644 bsps/arm/stm32h7/boards/stm/stm32h757i-eval/stm32h7-bspstarthooks.c create mode 100644 bsps/arm/stm32h7/boards/stm/stm32h7b3i-dk/stm32h7-bspstarthooks.c diff --git a/bsps/arm/stm32h7/boards/stm/nucleo-h743zi/stm32h7-bspstarthooks.c b/bsps/arm/stm32h7/boards/stm/nucleo-h743zi/stm32h7-bspstarthooks.c new file mode 100644 index 00..8d34e357ee --- /dev/null +++ b/bsps/arm/stm32h7/boards/stm/nucleo-h743zi/stm32h7-bspstarthooks.c @@ -0,0 +1,78 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/* + * Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +void bsp_start_hook_0(void) +{ + if ((RCC->AHB3ENR & RCC_AHB3ENR_FMCEN) == 0) { +/* + * Only perform the low-level initialization if necessary. An initialized + * FMC indicates that a boot loader already performed the low-level + * initialization. + */ +SystemInit(); +stm32h7_init_power(); +stm32h7_init_oscillator(); +stm32h7_init_clocks(); +stm32h7_init_peripheral_clocks(); +HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSI, RCC_MCODIV_1); +HAL_Init(); +SystemInit_ExtMemCtl(); + } + +#if __CORTEX_M == 0x07U + if ((SCB->CCR & SCB_CCR_IC_Msk) == 0) { +SCB_EnableICache(); + } + + if ((SCB->CCR & SCB_CCR_DC_Msk) == 0) { +SCB_EnableDCache(); + } + + _ARMV7M_MPU_Setup(stm32h7_config_mpu_region, stm32h7_config_mpu_region_count); +#endif +} + +void bsp_start_hook_1(void) +{ + bsp_start_copy_sections_compact(); +#if __CORTEX_M == 0x07U + SCB_CleanDCache(); + SCB_InvalidateICache(); +#endif + bsp_start_clear_bss(); +} diff --git a/bsps/arm/stm32h7/boards/stm/stm32h743i-eval/stm32h7-bspstarthooks.c b/bsps/arm/stm32h7/boards/stm/stm32h743i-eval/stm32h7-bspstarthooks.c new file mode 100644 index 00..8d34e357ee --- /dev/null +++ b/bsps/arm/stm32h7/boards/stm/stm32h743i-eval/stm32h7-bspstarthooks.c @@ -0,0 +1,78 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/* + * Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright
[PATCH 2/2] bsps/stm32h7: remove external memory initialization from nucleo-h743zi BSP
Nucleo board does not provide any external memory so code does not have any function here anyway. Sponsored-By: Precidata --- .../boards/stm/nucleo-h743zi/ext-mem-ctl.c| 478 -- .../stm/nucleo-h743zi/stm32h7-bspstarthooks.c | 1 - .../bsps/arm/stm32h7/bspnucleoh743zi.yml | 1 - 3 files changed, 480 deletions(-) delete mode 100644 bsps/arm/stm32h7/boards/stm/nucleo-h743zi/ext-mem-ctl.c diff --git a/bsps/arm/stm32h7/boards/stm/nucleo-h743zi/ext-mem-ctl.c b/bsps/arm/stm32h7/boards/stm/nucleo-h743zi/ext-mem-ctl.c deleted file mode 100644 index a2ab9d8f1f..00 --- a/bsps/arm/stm32h7/boards/stm/nucleo-h743zi/ext-mem-ctl.c +++ /dev/null @@ -1,478 +0,0 @@ -/** - ** - * @filesystem_stm32h7xx.c - * @author MCD Application Team - * @brief CMSIS Cortex-M Device Peripheral Access Layer System Source File. - * - * This file provides two functions and one global variable to be called from - * user application: - * - SystemInit(): This function is called at startup just after reset and - * before branch to main program. This call is made inside - * the "startup_stm32h7xx.s" file. - * - * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used - * by the user application to setup the SysTick - * timer or configure other parameters. - * - * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must - * be called whenever the core clock is changed - * during program execution. - * - * - ** - * @attention - * - * © Copyright (c) 2017 STMicroelectronics. - * All rights reserved. - * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - *opensource.org/licenses/BSD-3-Clause - * - ** - */ - -#include - -#define DATA_IN_ExtSRAM -#define DATA_IN_ExtSDRAM - -void SystemInit_ExtMemCtl(void) -{ - - #define FMC_BMAP_Value0x0200/* FMC Bank Mapping 2 (SDRAM Bank2 remapped) */ - - __IO uint32_t tmp = 0; - - - /** SDRAM + SRAM ***/ - - #if defined (DATA_IN_ExtSDRAM) && defined (DATA_IN_ExtSRAM) - - register uint32_t tmpreg = 0, timeout = 0x; - register __IO uint32_t index; - - /*-- I/O Ports Configuration --*/ - - /* Enable GPIOD, GPIOE, GPIOF, GPIOG, GPIOH and GPIOI interface clock */ - RCC->AHB4ENR |= 0x01F8; - - /* Delay after an RCC peripheral clock enabling */ - tmp = READ_BIT(RCC->AHB4ENR, RCC_AHB4ENR_GPIOEEN); - - /* Connect PDx pins to FMC Alternate function */ - GPIOD->AFR[0] = 0x00CC00CC; - GPIOD->AFR[1] = 0x; - /* Configure PDx pins in Alternate function mode */ - GPIOD->MODER = 0xFAFA; - /* Configure PDx pins speed to 100 MHz */ - GPIOD->OSPEEDR = 0x0F0F; - /* Configure PDx pins Output type to push-pull */ - GPIOD->OTYPER = 0x; - /* Configure PDx pins in Pull-up */ - GPIOD->PUPDR = 0x0505; - - /* Connect PEx pins to FMC Alternate function */ - GPIOE->AFR[0] = 0xC00CC0CC; - GPIOE->AFR[1] = 0x; - /* Configure PEx pins in Alternate function mode */ - GPIOE->MODER = 0xBEBA; - /* Configure PEx pins speed to 100 MHz */ - GPIOE->OSPEEDR = 0xC3CF; - /* Configure PEx pins Output type to push-pull */ - GPIOE->OTYPER = 0x; - /* Configure PEx pins in Pull-up */ - GPIOE->PUPDR = 0x4145; - - /* Connect PFx pins to FMC Alternate function */ - GPIOF->AFR[0] = 0x00CC; - GPIOF->AFR[1] = 0xC000; - /* Configure PFx pins in Alternate function mode */ - GPIOF->MODER = 0xAABFFAAA; - /* Configure PFx pins speed to 100 MHz */ - GPIOF->OSPEEDR = 0xFFC00FFF; - /* Configure PFx pins Output type to push-pull */ - GPIOF->OTYPER = 0x; - /* Configure PFx pins in Pull-up */ - GPIOF->PUPDR = 0x55400555; - - /* Connect PGx pins to FMC Alternate function */ - GPIOG->AFR[0] = 0x00CC; - GPIOG->AFR[1] = 0xCC0C; - /* Configure PGx pins in Alternate function mode */ - GPIOG->MODER = 0xBFEEFAAA; - /* Configure PGx pins speed to 100 MHz */ - GPIOG->OSPEEDR = 0xC0330FFF; - /* Configure PGx pins Output type to push-pull */ - GPIOG->OTYPER = 0x; - /* Configure PGx pins in Pull-up */ - GPIOG->PUPDR = 0x40110555; - - /* Connect PHx pins to FMC Alternate function */ -
[PATCH rtems-docs 0/1] TFTPFS: Add block and window size options
From: Frank Kühndel Hello all, I extended the TFTP file system to support the block size and the window size options (RFCs 2347, 2348, 7440). Essentially, this significantly improves the download and upload speeds provided the TFTP server on the other side also supports at least one of these options. To implement it I had to substantially change the network related part of the code. I also created a test suite for the TFTP code. Indeed the test suite is by far the largest part. Moreover, I wrote a documentation. This patch set provides the new documentation. It replaces the already existing but basically empty chapter "Trivial FTP Client Filesystem" in the "RTEMS Filesystem Design Guide". There are also two image files - an .svg and an .png - which are used in the text. These are not in this patch set as I believe no one will review SVG code or binary PNG. Instead I put the generated PDF (including the diagram) for download at the link shown below. I hope the PDF is more convenient to read than the patch itself. https://share.embedded-brains.de/index.php/s/6MkMHkyRLKR2XBp/download/filesystem.pdf Please, remind that only chapter "Trivial FTP Client Filesystem" in this PDF is new. There is one issue with the copyright which is not clear to me. I adapted the copyright notice in filesystem/index.rst. This copyright notice appears in a box just before chapter "PREFACE". Yet, there is a second different copyright notice "1988, 2020 RTEMS Project and contributors" which appears at the first page of the PDF and at the bottom of each HTML page. I do not want to complain about this. I just found it a bit inconsistent. Next I will send the changed code as an own patch set to the mailing list. Thanks in advance for your review efforts, any questions and comments. Note, due to a bank holiday I will response to your emails no earlier than Tuesday. Greetings Frank Frank Kühndel (1): TFTPFS: New documentation filesystem/index.rst | 1 + filesystem/trivial_ftp.rst | 638 - 2 files changed, 636 insertions(+), 3 deletions(-) -- 2.35.3 ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
[PATCH rtems-docs 1/1] TFTPFS: New documentation
From: Frank Kühndel --- filesystem/index.rst | 1 + filesystem/trivial_ftp.rst | 638 - 2 files changed, 636 insertions(+), 3 deletions(-) diff --git a/filesystem/index.rst b/filesystem/index.rst index f4e2ed6..64a2f1d 100644 --- a/filesystem/index.rst +++ b/filesystem/index.rst @@ -9,6 +9,7 @@ RTEMS Filesystem Design Guide (|version|). .. topic:: Copyrights and License | |copy| 1988, 2015 On-Line Applications Research Corporation (OAR) +| |copy| 2022 embedded brains GmbH (http://www.embedded-brains.de) .. include:: ../common/license.rst diff --git a/filesystem/trivial_ftp.rst b/filesystem/trivial_ftp.rst index e43c036..f5940c6 100644 --- a/filesystem/trivial_ftp.rst +++ b/filesystem/trivial_ftp.rst @@ -3,7 +3,639 @@ Trivial FTP Client Filesystem * -This chapter describes the Trivial FTP (TFTP) Client Filesystem. +This chapter describes the Trivial File Transfer Protocol (TFTP) Client +Filesystem. TFTP is designed to be an especially simple protocol which +uses the User Datagram Protocol (UDP) for data transfer over the Internet. +Its purpose is to send a single file between to network nodes (client and +server). A file can be sent in both directions, i.e. a client can either +read a file from a server or write a file to the server. -This chapter should be written after the IMFS chapter is completed and describe -the implementation of the TFTP. +Besides reading or writing a file no other operations are supported. That +is, one cannot seek the file, not append to the end of a file, not open +the file for reading and writing at the same time, not list directories, +not move files and so on. + +TFTP is inherent insecure as it does not provide any means for +authentication or encryption. Therefore, it cannot be used over the public +Internet. Nevertheless, it is still widely used to load software and +configuration data during early boot stages over a Local Area Network +(LAN). + +RTEMS TFTP Filesystem Implementation + + +The RTEMS TFTP filesystem implements a TFTP client which can be used +through the file system. With other words, one needs to mount the +TFTP filesystem and can afterwards open a file for reading or writing +below that mount point. The content of that file is then effectively +read from or written to the remote server. The RTEMS implementation +implements the following features: + +* RFC 1350 *The TFTP Protocol (Revision 2)* +* RFC 2347 *TFTP Option Extension* +* RFC 2348 *TFTP Blocksize Option* +* RFC 7440 *TFTP Windowsize Option* + +Many simple TFTP server do not support options (RFC 2347). Therefore, in +case the server rejects the first request with options, the RTEMS client +makes automatically a second attempt using only the "classical" RFC 1350. + +The implementation has the following shortcomings: + +* IPv6 is not supported (yet). + +* No congestion control is implemented. + + (Congestion is simply expressed a network traffic jam which involves + package loss.) This implementation would worsen a congestion situation + and squeeze out TCP connections. If that is a concern in your setup, + it can be prevented by using value `1` as `windowsize`. + +* One must call ``open()``, ``read()``, ``write()`` and ``close()`` + at a good pace. + + TFTP uses timeouts (of unspecified length). It does not know keep-alive + messages. If the client does not respond to the server in due time, + the server sets the connection faulty and drops it. To avoid this, + the user must read or write enough data fast enough. + + "Enough data" means at least so much data which fills a single data + package or all packages of a window if windows are used. The data + can be read or written in anything from one single large chunk to + byte-by-byte pieces. The point is, one cannot pause the reading + or writing for longer periods of time. + +* The transfer mode is always ``octet``. The only alternative + ``netascii`` cannot be selected. + +* Block number roll-over is currently not supported. Therefore, + the maximum file size is limited to max-block-number times blocksize. + For RFC 1350 blocksize is would be 65535 * 512 = 32 MB. For the + default blocksize is would be 65535 * 1456 = 90 MB. + +* The inherent insecurity of the protocol has already be mentioned but + it is worth repeating. + +Prerequisites += + +To use the RTEMS TFTP filesystem one needs: + +* The RTEMS tools (cross-compiler, linker, debugger etc.) compiled + for the target architecture and installed at a prefix +* The RTEMS Board Support Package (BSP) compiled for the + target board and installed at the same prefix +* The RTEMS libbsd compiled to match the BSP and installed at the same + prefix + +Note, this text does not cover RTEMS legacy networking because it is +outdated. + +As an example the ARM architecture and a xilinx_zynq_a9 BSP is used below. +The instructi
[PATCH 1/7] TFTPFS: Cleanup: Remove spaces at lines ends
From: Frank Kühndel --- cpukit/libfs/src/ftpfs/tftpDriver.c | 20 ++-- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/cpukit/libfs/src/ftpfs/tftpDriver.c b/cpukit/libfs/src/ftpfs/tftpDriver.c index bebe748ca5..d0eadcf99a 100644 --- a/cpukit/libfs/src/ftpfs/tftpDriver.c +++ b/cpukit/libfs/src/ftpfs/tftpDriver.c @@ -233,12 +233,12 @@ int rtems_tftpfs_initialize( fs->flags = 0; fs->nStreams = 0; fs->tftpStreams = 0; - + mt_entry->fs_info = fs; mt_entry->mt_fs_root->location.node_access = root_path; mt_entry->mt_fs_root->location.handlers = &rtems_tftp_handlers; mt_entry->ops = &rtems_tftp_ops; - + /* * Now allocate a semaphore for mutual exclusion. * @@ -258,7 +258,7 @@ int rtems_tftpfs_initialize( token = strtok_r (NULL, " ", &saveptr); } } - + return 0; error: @@ -563,7 +563,7 @@ static int rtems_tftp_open_worker( * Get the file system info. */ fs = tftpfs_info_iop (iop); - + /* * Extract the host name component */ @@ -595,7 +595,7 @@ static int rtems_tftp_open_worker( return ENOENT; memcpy (&farAddress, he->h_addr, sizeof (farAddress)); } - + /* * Extract file pathname component */ @@ -803,7 +803,7 @@ static ssize_t rtems_tftp_read( if (!tp) rtems_set_errno_and_return_minus_one( EIO ); - + /* * Read till user request is satisfied or EOF is reached */ @@ -918,15 +918,15 @@ static int rtems_tftp_close( tftpfs_info_t *fs; struct tftpStream *tp = iop->data1; inte = 0; - + /* * Get the file system info. */ fs = tftpfs_info_iop (iop); - -if (!tp) + +if (!tp) rtems_set_errno_and_return_minus_one (EIO); - + if (tp->writing) e = rtems_tftp_flush (tp); if (!tp->eof && !tp->firstReply) { -- 2.35.3 ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
[PATCH 2/7] TFTPFS: Duplicate tftpDriver.c to tftpfs.c
From: Frank Kühndel --- cpukit/libfs/src/ftpfs/{tftpDriver.c => tftpfs.c} | 0 spec/build/cpukit/libtftpfs.yml | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) rename cpukit/libfs/src/ftpfs/{tftpDriver.c => tftpfs.c} (100%) diff --git a/cpukit/libfs/src/ftpfs/tftpDriver.c b/cpukit/libfs/src/ftpfs/tftpfs.c similarity index 100% rename from cpukit/libfs/src/ftpfs/tftpDriver.c rename to cpukit/libfs/src/ftpfs/tftpfs.c diff --git a/spec/build/cpukit/libtftpfs.yml b/spec/build/cpukit/libtftpfs.yml index 90a0eabc80..f63a50c933 100644 --- a/spec/build/cpukit/libtftpfs.yml +++ b/spec/build/cpukit/libtftpfs.yml @@ -2,7 +2,7 @@ SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause build-type: library cflags: [] copyrights: -- Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de) +- Copyright (C) 2020, 2022 embedded brains GmbH (http://www.embedded-brains.de) cppflags: [] cxxflags: [] enabled-by: true @@ -15,6 +15,6 @@ install: install-path: ${BSP_LIBDIR} links: [] source: -- cpukit/libfs/src/ftpfs/tftpDriver.c +- cpukit/libfs/src/ftpfs/tftpfs.c target: tftpfs type: build -- 2.35.3 ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
[PATCH 3/7] TFTPFS: Restore tftpDriver.c
From: Frank Kühndel --- cpukit/libfs/src/ftpfs/tftpDriver.c | 1088 +++ 1 file changed, 1088 insertions(+) create mode 100644 cpukit/libfs/src/ftpfs/tftpDriver.c diff --git a/cpukit/libfs/src/ftpfs/tftpDriver.c b/cpukit/libfs/src/ftpfs/tftpDriver.c new file mode 100644 index 00..d0eadcf99a --- /dev/null +++ b/cpukit/libfs/src/ftpfs/tftpDriver.c @@ -0,0 +1,1088 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * Trivial File Transfer Protocol file system (TFTP client) for RFC 1350. + * + * Transfer file to/from remote host + */ + +/* + * Copyright (c) 1998 Eric Norum + * + * Modifications to support reference counting in the file system are + * Copyright (c) 2012 embedded brains GmbH. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef RTEMS_NETWORKING +#include +#endif + +#ifdef RTEMS_TFTP_DRIVER_DEBUG +int rtems_tftp_driver_debug = 1; +#endif + +/* + * Range of UDP ports to try + */ +#define UDP_PORT_BASE3180 + +/* + * Default limits + */ +#define PACKET_FIRST_TIMEOUT_MILLISECONDS 400L +#define PACKET_TIMEOUT_MILLISECONDS6000L +#define OPEN_RETRY_LIMIT 10 +#define IO_RETRY_LIMIT 10 + +/* + * TFTP opcodes + */ +#define TFTP_OPCODE_RRQ 1 +#define TFTP_OPCODE_WRQ 2 +#define TFTP_OPCODE_DATA3 +#define TFTP_OPCODE_ACK 4 +#define TFTP_OPCODE_ERROR 5 + +/* + * Largest data transfer + */ +#define TFTP_BUFSIZE512 + +/* + * Packets transferred between machines + */ +union tftpPacket { +/* + * RRQ/WRQ packet + */ +struct tftpRWRQ { +uint16_t opcode; +charfilename_mode[TFTP_BUFSIZE]; +} tftpRWRQ; + +/* + * DATA packet + */ +struct tftpDATA { +uint16_t opcode; +uint16_t blocknum; +uint8_t data[TFTP_BUFSIZE]; +} tftpDATA; + +/* + * ACK packet + */ +struct tftpACK { +uint16_t opcode; +uint16_t blocknum; +} tftpACK; + +/* + * ERROR packet + */ +struct tftpERROR { +uint16_t opcode; +uint16_t errorCode; +charerrorMessage[TFTP_BUFSIZE]; +} tftpERROR; +}; + +/* + * State of each TFTP stream + */ +struct tftpStream { +/* + * Buffer for storing most recently-received packet + */ +union tftpPacketpkbuf; + +/* + * Last block number transferred + */ +uint16_t blocknum; + +/* + * Data transfer socket + */ +int socket; +struct sockaddr_in myAddress; +struct sockaddr_in farAddress; + +/* + * Indices into buffer + */ +int nleft; +int nused; + +/* + * Flags + */ +int firstReply; +int eof; +int writing; +}; + +/* + * Flags for filesystem info. + */ +#define TFTPFS_VERBOSE (1 << 0) + +/* + * TFTP File system info. + */ +typedef struct tftpfs_info_s { + uint32_t flags; + rtems_mutex tftp_mutex; + int nStreams; + struct tftpStream ** volatile tftpStreams; +} tftpfs_info_t; + +#define tftpfs_info_mount_table(_mt) ((tftpfs_info_t*) ((_mt)->fs_info)) +#define tftpfs_info_pathloc(_pl) ((tftpfs_info_t*) ((_pl)->mt_entry->fs_info)) +#define tftpfs_info_iop(_iop)(tftpfs_info_pathloc (&((_iop)->pathinfo))) + +/* + * Number of streams open at the same time + */ + +static const rtems_filesystem_operations_table rtems_
[PATCH 0/7] TFTPFS: Add block and window size options
From: Frank Kühndel The following patches extend the TFTP file system to support * RFC 2347 TFTP Option Extension * RFC 2348 TFTP Blocksize Option * RFC 7440 TFTP Windowsize Option To benefit from improved download and upload speeds, a TFTP server which supports at least the blocksize option must be used. The code is still downward compatible to simple/old servers which implement only RFC 1350. The patches contain an extensive test suite. The original code was in the single file tftpDriver.c where the file system and the network aspects where entangled. The patches split the code into files tftpfs.c for the file system part and tftpDriver.c for the network related part. Since both files are derived from the original tftpDriver.c, it is possible to keep the git history working for both files when committing the patches to the git repository. For example, as described here: https://devblogs.microsoft.com/oldnewthing/20190919-00/?p=102904 Yet, this method requires a merge and the history gets lost when the commits are "rebased". I cannot say whether this would be worth the trouble. TFTP Files -- ``cpukit/include/rtems/tftp.h`` This file declares the public constants, structures, and functions of the Trivial File Transfer Protocol (TFTP) file system. ``cpukit/libfs/src/ftpfs/tftpDriver.c`` This source file contains the implementation of a Trivial File Transfer Protocol (TFTP) client library --- the network related part of the code. ``cpukit/libfs/src/ftpfs/tftp_driver.h`` This file declares private functions of the Trivial File Transfer Protocol (TFTP) client library. ``cpukit/libfs/src/ftpfs/tftpfs.c`` This source file contains the implementation of the Trivial File Transfer Protocol (TFTP) filesystem. The code in this file handles the file system operations (such as ``mount()``, ``open()``, ``read()``, ``write()``, ``close()`` etc.). ``spec/build/cpukit/libtftpfs.yml`` This file specifies how the RTEMS WAF build system has to compile, link and install ``libtftpfs``. ``spec/build/testsuites/fstests/grp.yml`` This file specifies how the RTEMS WAF build system has to compile, link and install all filesystem test suites. The TFTP test suite must be mentioned in this file to be build. ``spec/build/testsuites/fstests/tftpfs.yml`` This file specifies how the RTEMS WAF build system has to compile, link and install the TFTP test suite. ``testsuites/fstests/tftpfs/init.c`` This source file contains the test suite with all tests for ``libtftpfs``. The test suite uses functions from files ``tftpfs_interactions.c`` and ``tftpfs_udp_network_fake.c`` as private helpers. ``testsuites/fstests/tftpfs/tftpfs_interactions.h`` This header file provides definitions and declarations of data structures and functions used to implement network interactions of the UDP network fake for ``libtftpfs`` tests. ``testsuites/fstests/tftpfs/tftpfs_interactions.c`` This source file contains the implementation of network interaction functions related to the UDP network fake for ``libtftpfs`` tests. ``testsuites/fstests/tftpfs/tftpfs_udp_network_fake.h`` This header file provides definitions and declarations of data structures and functions used to implement the UDP network fake for ``libtftpfs`` tests. ``testsuites/fstests/tftpfs/tftpfs_udp_network_fake.c`` This source file contains the implementation of UDP network fake functions related to ``libtftpfs`` testing. This code provides fake implementations for functions like ``socket()``, ``bind()``, ``sendto()``, ``recvfrom()``, etc. which would normally be provided by libbsd. Frank Kühndel (7): TFTPFS: Cleanup: Remove spaces at lines ends TFTPFS: Duplicate tftpDriver.c to tftpfs.c TFTPFS: Restore tftpDriver.c TFTPFS: Implement block and window size options TFTPFS: Add test suite framework TFTPFS: Add tests TFTPFS: Add more tests cpukit/include/rtems/tftp.h | 404 +- cpukit/libfs/src/ftpfs/tftpDriver.c | 1780 ++-- cpukit/libfs/src/ftpfs/tftp_driver.h | 76 + cpukit/libfs/src/ftpfs/tftpfs.c | 624 ++ spec/build/cpukit/libtftpfs.yml |3 +- spec/build/testsuites/fstests/grp.yml |2 + spec/build/testsuites/fstests/tftpfs.yml | 25 + testsuites/fstests/tftpfs/init.c | 7318 + .../fstests/tftpfs/tftpfs_interactions.c | 984 +++ .../fstests/tftpfs/tftpfs_interactions.h | 205 + .../fstests/tftpfs/tftpfs_udp_network_fake.c | 983 +++ .../fstests/tftpfs/tftpfs_udp_network_fake.h | 283 + 12 files changed, 12024 insertions(+), 663 deletions(-) create mode 100644 cpukit/libfs/src/ftpfs/tftp_driver.h create mode 100644 cpukit/libfs/src/ftpfs/tftpfs.c create mode 100644 spec/build/testsuites/fstests/tftpfs.yml create mode 100644 testsuites/fstests/tftpfs/init.c create mode 100644 testsuites/fstests/tftpfs/tftpfs_interactions.c create mode 100
[PATCH 7/7] TFTPFS: Add more tests
From: Frank Kühndel --- testsuites/fstests/tftpfs/init.c | 3397 ++ 1 file changed, 3397 insertions(+) diff --git a/testsuites/fstests/tftpfs/init.c b/testsuites/fstests/tftpfs/init.c index a7ef03cf74..0c6df5fa5c 100644 --- a/testsuites/fstests/tftpfs/init.c +++ b/testsuites/fstests/tftpfs/init.c @@ -171,6 +171,47 @@ static const T_fixture fixture_default_options = { .initial_context = &tftp_context }; +static void setup_large_blocksize( void *context ) +{ + tftp_test_context *ctx = context; + _Tftp_Reset(); + ctx->fd0 = -1; + ctx->tftp_handle = NULL; + mount_tftp_fs( +tftpfs_mount_point, +"verbose,blocksize=" RTEMS_XSTRING(LARGE_BLOCK_SIZE) ",windowsize=1" + ); +} + +static const T_fixture fixture_large_blocksize = { + .setup = setup_large_blocksize, + .stop = NULL, + .teardown = teardown, + .scope = NULL, + .initial_context = &tftp_context +}; + +static void setup_small_opt_size( void *context ) +{ + tftp_test_context *ctx = context; + _Tftp_Reset(); + ctx->fd0 = -1; + ctx->tftp_handle = NULL; + mount_tftp_fs( +tftpfs_mount_point, +"blocksize=" RTEMS_XSTRING(SMALL_BLOCK_SIZE) +",windowsize=" RTEMS_XSTRING(SMALL_WINDOW_SIZE) + ); +} + +static const T_fixture fixture_small_opt_size = { + .setup = setup_small_opt_size, + .stop = NULL, + .teardown = teardown, + .scope = NULL, + .initial_context = &tftp_context +}; + static void setup_mount_point( void *context ) { int result; @@ -240,6 +281,15 @@ static uint8_t get_file_content( size_t pos ) } } +/* + * Produce bad file content. + */ +static uint8_t get_bad_file_content( size_t pos ) +{ + static const char buf[] = "BAD!"; + return (uint8_t) buf[ pos % strlen( buf ) ]; +} + static const char *create_tftpfs_path( const char *sever_addr, const char *file_name @@ -3836,6 +3886,3353 @@ T_TEST_CASE_FIXTURE( write_simple_file, &fixture_rfc1350 ) } #endif /* ENABLE_ALL_TESTS */ +#if ENABLE_ALL_TESTS +/* + * Write a file to the server using only RFC1350. + * As response to the first DATA packet, the server sends an error packet. + * Tests: + * * The code supports requests without options (RFC1350 only). + * * The code supports the use of an IPv4 address instead of a server name. + * * The first packet is sent to standard port 69 of server. + * * All other packets are sent to the port used for this connection. + * * The first data packet is full. + * * The second packet from the server is an error packet. + * * The TFTP client ends the connection after receiving an error packet. + * * The test writes a file to the file system with a call to write() + * for each byte. + */ +T_TEST_CASE_FIXTURE( write_simple_file_disk_full, &fixture_rfc1350 ) +{ + tftp_test_context *ctx = T_fixture_context(); + int bytes_written; + uint16_t block_num = 0; + size_t pos_in_file = 0; + + /* T_set_verbosity( T_VERBOSE ); */ + _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD ); +#ifdef RTEMS_NETWORKING + _Tftp_Add_interaction_bind( TFTP_FIRST_FD, AF_INET, 0 ); +#endif + _Tftp_Add_interaction_send_wrq( +TFTP_FIRST_FD, +tftpfs_file, +TFTP_STD_PORT, +tftpfs_ipv4_loopback, +NO_BLOCK_SIZE_OPTION, +NO_WINDOW_SIZE_OPTION, +true + ); + _Tftp_Add_interaction_recv_ack( +TFTP_FIRST_FD, +FIRST_TIMEOUT_MILLISECONDS, +SERV_PORT, +tftpfs_ipv4_loopback, +block_num++, +true + ); + _Tftp_Add_interaction_send_data( +TFTP_FIRST_FD, +block_num, +pos_in_file, +TFTP_RFC1350_BLOCK_SIZE, +get_file_content, +SERV_PORT, +tftpfs_ipv4_loopback, +true + ); + pos_in_file += TFTP_RFC1350_BLOCK_SIZE; + _Tftp_Add_interaction_recv_error( +TFTP_FIRST_FD, +FIRST_TIMEOUT_MILLISECONDS, +SERV_PORT, +tftpfs_ipv4_loopback, +TFTP_ERROR_CODE_DISK_FULL, +"disk full", +true + ); + _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 ); + + bytes_written = write_tftp_file( +create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ), +pos_in_file, /* Size of file */ +1, /* Bytes written per call to write() */ +&ctx->fd0 + ); + T_eq_int( errno, ENOSPC ); + T_eq_int( bytes_written, pos_in_file - 1 ); + T_no_more_interactions(); +} +#endif /* ENABLE_ALL_TESTS */ + +#if ENABLE_ALL_TESTS +/* + * Write a file to the server using only RFC1350. + * The file is one and a half data packet long. + * The server sends a malformed packet. + * Tests: + * * The code supports requests without options (RFC1350 only). + * * The code supports the use of an IPv4 address instead of a server name. + * * The first packet is sent to standard port 69 of server. + * * All other packets are sent to the port used for this connection. + * * The first ACK to the WRQ packet is malformed. + * It is only one byte long. + * * The client sends an error upon the reception of a malformed packet + * and terminates the file transfer. + */ +T_TEST_CASE_FIXTURE( write_file_malforme
[PATCH 5/7] TFTPFS: Add test suite framework
From: Frank Kühndel --- spec/build/testsuites/fstests/grp.yml |2 + spec/build/testsuites/fstests/tftpfs.yml | 25 + testsuites/fstests/tftpfs/init.c | 1054 + .../fstests/tftpfs/tftpfs_interactions.c | 984 +++ .../fstests/tftpfs/tftpfs_interactions.h | 205 .../fstests/tftpfs/tftpfs_udp_network_fake.c | 983 +++ .../fstests/tftpfs/tftpfs_udp_network_fake.h | 283 + 7 files changed, 3536 insertions(+) create mode 100644 spec/build/testsuites/fstests/tftpfs.yml create mode 100644 testsuites/fstests/tftpfs/init.c create mode 100644 testsuites/fstests/tftpfs/tftpfs_interactions.c create mode 100644 testsuites/fstests/tftpfs/tftpfs_interactions.h create mode 100644 testsuites/fstests/tftpfs/tftpfs_udp_network_fake.c create mode 100644 testsuites/fstests/tftpfs/tftpfs_udp_network_fake.h diff --git a/spec/build/testsuites/fstests/grp.yml b/spec/build/testsuites/fstests/grp.yml index 378157d3dc..ed8917504a 100644 --- a/spec/build/testsuites/fstests/grp.yml +++ b/spec/build/testsuites/fstests/grp.yml @@ -138,6 +138,8 @@ links: uid: mrfsfssymlink - role: build-dependency uid: mrfsfstime +- role: build-dependency + uid: tftpfs type: build use-after: [] use-before: diff --git a/spec/build/testsuites/fstests/tftpfs.yml b/spec/build/testsuites/fstests/tftpfs.yml new file mode 100644 index 00..37d55d4132 --- /dev/null +++ b/spec/build/testsuites/fstests/tftpfs.yml @@ -0,0 +1,25 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +build-type: test-program +cflags: [] +copyrights: +- Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de) +cppflags: [] +cxxflags: [] +enabled-by: true +features: c cprogram +includes: +- cpukit/libfs/src/ftpfs +ldflags: +- -Wl,--wrap=close +links: [] +source: +- cpukit/libtest/testwrappers.c +- testsuites/fstests/tftpfs/init.c +- testsuites/fstests/tftpfs/tftpfs_udp_network_fake.c +- testsuites/fstests/tftpfs/tftpfs_interactions.c +stlib: +- tftpfs +target: testsuites/fstests/tftpfs.exe +type: build +use-after: [] +use-before: [] diff --git a/testsuites/fstests/tftpfs/init.c b/testsuites/fstests/tftpfs/init.c new file mode 100644 index 00..91308ec75b --- /dev/null +++ b/testsuites/fstests/tftpfs/init.c @@ -0,0 +1,1054 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSTestSuiteTestsTftpfs + * + * @brief This source file contains the implementation of tests for libtftpfs. + * + * The tested source files are: + * + @ref tftpfs.c "tftpfs.c: TFTP file system" + * + @ref tftpDriver.c "tftpDriver.c: TFTP client library" + * These tests focus on testing the UDP network interaction of libtftpfs. + */ + +/* + * Copyright (C) 2022 embedded brains GmbH (http://www.embedded-brains.de) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @defgroup RTEMSTestSuiteTestsTftpfs Test suite for libtftpsfs tests + * + * @ingroup RTEMSTestSuites + * + * @brief This test suite provides a tests for libtftpfs. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include /* malloc(), free() */ +#include /* isprint() */ +#include +#include /* mkdir(), open() */ +#include /* mkdir(), open() */ +#include /* AF_INET, SOCK_DGRAM */ +#include /* open() */ +#include /* read(), close(), rmdir() */ + +#include +#include /* mount(), RTEMS_FILESYSTEM_TYPE_TFTPFS */ +#include +#include +#include /* RTEMS_TEST_VERBOSITY */ +#include + +#include "tftpfs_udp_network_fake.h" +#include "tftpfs_interactions.h" +#include "tftp_driver.h" + +#define SERV_PORT 12345 +#define FIRST_TIMEOUT_MILLISECONDS 400 +#define TIMEOUT_MILLISECONDS1000 +#define
[PATCH 6/7] TFTPFS: Add tests
From: Frank Kühndel --- testsuites/fstests/tftpfs/init.c | 3197 -- 1 file changed, 3032 insertions(+), 165 deletions(-) diff --git a/testsuites/fstests/tftpfs/init.c b/testsuites/fstests/tftpfs/init.c index 91308ec75b..a7ef03cf74 100644 --- a/testsuites/fstests/tftpfs/init.c +++ b/testsuites/fstests/tftpfs/init.c @@ -171,6 +171,32 @@ static const T_fixture fixture_default_options = { .initial_context = &tftp_context }; +static void setup_mount_point( void *context ) +{ + int result; + + _Tftp_Reset(); + result = mkdir( tftpfs_mount_point, S_IRWXU | S_IRWXG | S_IRWXO ); + T_assert_eq_int( result, 0 ); +} + +static void teardown_mount_point( void *context ) +{ + int result; + + result = rmdir( tftpfs_mount_point ); + T_assert_eq_int( result, 0 ); + _Tftp_Reset(); +} + +static const T_fixture fixture_mount_point = { + .setup = setup_mount_point, + .stop = NULL, + .teardown = teardown_mount_point, + .scope = NULL, + .initial_context = &tftp_context +}; + /* * Test helper functions */ @@ -618,191 +644,540 @@ static int rdwt_tftp_client_file( } /* - * Test cases for the TFTP client interface - * - * Since the TFTP file system uses the TFTP client interface for all - * file transfers, the function of the TFTP client is almost - * completely tested by the tests for the file system interface. - * The test cases here - for the TFTP client interface - test only - * those aspects not (easily) testable through the file system interface. + * Unit test cases */ -#if ENABLE_ALL_TESTS /* - * Write a file to the server using the TFTP client interface. - * The test uses the default options. - * The file is 2 and a half data packet long. No timeouts, packet loss, ... + * This is a classical unit test for the function tftp_initialize_net_config(). * Tests: - * * The default options (windowsize = 8 and blocksize = 1456) are used. - * * tftp_open() is called with default configuration values. - * * The test writes a file using only the TFTP client (i.e. not using the - * file system) - * * The code supports the use of a server name instead of an IP address. - * * The first window is also the last window. - * * The only ACK packet is the one at the end of window. - * * Between sending data packets, the client checks whether any packets - * are received. - * * The client handles files correctly which end in the middle of a window. + * * tftp_initialize_net_config() sets correct default values as defined + * in the documentation of the data structures tftp_net_config + * and tftp_options. */ -T_TEST_CASE_FIXTURE( client_write_simple_file, &fixture_default_options ) +T_TEST_CASE( tftp_initialize_net_config ) { - tftp_test_context *ctx = T_fixture_context(); tftp_net_config config; - int bytes_written; - uint16_t block_num = 1; - size_t pos_in_file = 0; - const char options[] = -TFTP_OPTION_BLKSIZE "\0" -RTEMS_XSTRING( TFTP_DEFAULT_BLOCK_SIZE ) "\0" -TFTP_OPTION_WINDOWSIZE "\0" -RTEMS_XSTRING( TFTP_DEFAULT_WINDOW_SIZE ); + memset( &config, 0, sizeof( config ) ); + tftp_initialize_net_config( &config ); + T_eq_u16( config.retransmissions, 6 ); + T_eq_u16( config.server_port, 69 ); + T_eq_u32( config.timeout, 1000 ); + T_eq_u32( config.first_timeout, 400 ); + T_eq_u16( config.options.block_size, 1456 ); + T_eq_u16( config.options.window_size, 8 ); +} - /* T_set_verbosity( T_VERBOSE ); */ - _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD ); -#ifdef RTEMS_NETWORKING - _Tftp_Add_interaction_bind( TFTP_FIRST_FD, AF_INET, 0 ); -#endif - _Tftp_Add_interaction_send_wrq( -TFTP_FIRST_FD, +/* + * This is a classical unit test for the function tftp_initialize_net_config(). + * Tests: + * * tftp_initialize_net_config() does not crash when called with a + * NULL pointer. + */ +T_TEST_CASE( tftp_initialize_net_config_null ) +{ + tftp_initialize_net_config( NULL ); +} + +/* + * This is a classical unit test for the function tftp_open(). + * Tests: + * * tftp_open() returns an error when called with a NULL pointer + * for hostname. + */ +T_TEST_CASE_FIXTURE( tftp_open_null_hostname, &fixture_rfc1350 ) +{ + tftp_test_context *ctx = T_fixture_context(); + int res; + + res = tftp_open( +NULL, /* hostname */ tftpfs_file, -TFTP_STD_PORT, -tftpfs_server0_ipv4, -TFTP_DEFAULT_BLOCK_SIZE, -TFTP_DEFAULT_WINDOW_SIZE, -true - ); - _Tftp_Add_interaction_recv_oack( -TFTP_FIRST_FD, -FIRST_TIMEOUT_MILLISECONDS, -SERV_PORT, -tftpfs_server0_ipv4, -options, -sizeof( options ), -true - ); - _Tftp_Add_interaction_send_data( -TFTP_FIRST_FD, -block_num++, -pos_in_file, -TFTP_DEFAULT_BLOCK_SIZE, -get_file_content, -SERV_PORT, -tftpfs_server0_ipv4, -true - ); - pos_in_file += TFTP_DEFAULT_BLOCK_SIZE; - _Tftp_Add_interaction_recv_nothing( -TFTP_FIRST_FD, -DO_NOT_WAIT_FOR_ANY_TIMEOUT - ); - _T
Re: [PATCH 3/7] TFTPFS: Restore tftpDriver.c
Is this really just a move/rename? Does it preserve the git blame info? --joel On Fri, Jun 3, 2022, 10:22 AM Frank Kuehndel < frank.kuehn...@embedded-brains.de> wrote: > From: Frank Kühndel > > --- > cpukit/libfs/src/ftpfs/tftpDriver.c | 1088 +++ > 1 file changed, 1088 insertions(+) > create mode 100644 cpukit/libfs/src/ftpfs/tftpDriver.c > > diff --git a/cpukit/libfs/src/ftpfs/tftpDriver.c > b/cpukit/libfs/src/ftpfs/tftpDriver.c > new file mode 100644 > index 00..d0eadcf99a > --- /dev/null > +++ b/cpukit/libfs/src/ftpfs/tftpDriver.c > @@ -0,0 +1,1088 @@ > +/* SPDX-License-Identifier: BSD-2-Clause */ > + > +/** > + * @file > + * > + * Trivial File Transfer Protocol file system (TFTP client) for RFC 1350. > + * > + * Transfer file to/from remote host > + */ > + > +/* > + * Copyright (c) 1998 Eric Norum > + * > + * Modifications to support reference counting in the file system are > + * Copyright (c) 2012 embedded brains GmbH. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * 1. Redistributions of source code must retain the above copyright > + *notice, this list of conditions and the following disclaimer. > + * 2. Redistributions in binary form must reproduce the above copyright > + *notice, this list of conditions and the following disclaimer in the > + *documentation and/or other materials provided with the distribution. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > "AS IS" > + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, > THE > + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR > PURPOSE > + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS > BE > + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR > + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF > + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR > BUSINESS > + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN > + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) > + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF > THE > + * POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#ifdef HAVE_CONFIG_H > +#include "config.h" > +#endif > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#ifdef RTEMS_NETWORKING > +#include > +#endif > + > +#ifdef RTEMS_TFTP_DRIVER_DEBUG > +int rtems_tftp_driver_debug = 1; > +#endif > + > +/* > + * Range of UDP ports to try > + */ > +#define UDP_PORT_BASE3180 > + > +/* > + * Default limits > + */ > +#define PACKET_FIRST_TIMEOUT_MILLISECONDS 400L > +#define PACKET_TIMEOUT_MILLISECONDS6000L > +#define OPEN_RETRY_LIMIT 10 > +#define IO_RETRY_LIMIT 10 > + > +/* > + * TFTP opcodes > + */ > +#define TFTP_OPCODE_RRQ 1 > +#define TFTP_OPCODE_WRQ 2 > +#define TFTP_OPCODE_DATA3 > +#define TFTP_OPCODE_ACK 4 > +#define TFTP_OPCODE_ERROR 5 > + > +/* > + * Largest data transfer > + */ > +#define TFTP_BUFSIZE512 > + > +/* > + * Packets transferred between machines > + */ > +union tftpPacket { > +/* > + * RRQ/WRQ packet > + */ > +struct tftpRWRQ { > +uint16_t opcode; > +charfilename_mode[TFTP_BUFSIZE]; > +} tftpRWRQ; > + > +/* > + * DATA packet > + */ > +struct tftpDATA { > +uint16_t opcode; > +uint16_t blocknum; > +uint8_t data[TFTP_BUFSIZE]; > +} tftpDATA; > + > +/* > + * ACK packet > + */ > +struct tftpACK { > +uint16_t opcode; > +uint16_t blocknum; > +} tftpACK; > + > +/* > + * ERROR packet > + */ > +struct tftpERROR { > +uint16_t opcode; > +uint16_t errorCode; > +charerrorMessage[TFTP_BUFSIZE]; > +} tftpERROR; > +}; > + > +/* > + * State of each TFTP stream > + */ > +struct tftpStream { > +/* > + * Buffer for storing most recently-received packet > + */ > +union tftpPacketpkbuf; > + > +/* > + * Last block number transferred > + */ > +uint16_t blocknum; > + > +/* > + * Data transfer socket > + */ > +int socket; > +struct sockaddr_in myAddress; > +struct sockaddr_in farAddress; > + > +/* > + * Indices into buffer > + */ > +int nleft; > +int nused; > + > +/* > + * Flags > + */ > +int firstReply; > +int eof; > +int writing; > +}; > + > +/* > + * Flags for filesystem info. > + */ > +#define TFTPFS_VERBOSE (1 << 0)