2

I have already posted my question on NXP comunity forum but the team says that LWIP is open source and not related to NXP. which I agree. I have the following scenario :

  • PC will run a TFTP server containing all SW files
  • MCU will run a TFTP client that will ask (by file name) the server for the flash file
  • MCU will receive the flash file and start the SW update (erase all flash memory and write).

for TFTP server I used the TFTPD64 . MCU will run the client, most of the code is taking from this github repo TFTP client is started correctly on port 69, when I request a file from the server I get the error 'Failed to open file', even though the server is poiting to it and is available

void tftp_example_init_client(void)
{
  void *f;
  err_t err;
  ip_addr_t srv;
  int ret = ipaddr_aton(LWIP_TFTP_SERVER_IP, &srv);
  if(ret != 1)
  {
    printf("ipaddr_aton failed \r\n");
  }


  err = tftp_init_client(&tftp);
  if(err != ERR_OK)
  {
      printf("tftp_init_client failed, error : %d \r\n", err);
  }

  f = tftp_open_file(LWIP_TFTP_FILENAME, 1);
  if(f == NULL)
  {
     printf("failed to open file , %d \r\n", f);
  }

  err = tftp_get(f, &srv, TFTP_PORT, LWIP_TFTP_FILENAME, 
TFTP_MODE_OCTET);
  if(err != ERR_OK)
  {
      printf("tftp_get failed \r\n");
  }

}

the tftp_open_file function is defined as follow :

static void * tftp_open_file(const char* fname, u8_t is_write)
{
  snprintf(full_filename, sizeof(full_filename), "%s%s", LWIP_TFTP_BASE_DIR, 
fname);
  full_filename[sizeof(full_filename)-1] = 0;
  printf("%s \r\n",fname);
  if (is_write) {
    return (void*)fopen(full_filename, "wb");
  } else {
    return (void*)fopen(full_filename, "rb");
  }
}

static void* tftp_open(const char* fname, const char* mode, u8_t is_write)
{
  LWIP_UNUSED_ARG(mode);
  return tftp_open_file(fname, is_write);
}

EDIT

#define LWIP_TFTP_SERVER_IP "192.168.225.20"
#define LWIP_TFTP_FILENAME "0223.bin"
#define LWIP_TFTP_BASE_DIR "\\"

TFTP server return this error enter image description here

Thank you.

  • In `tftp_open_file` there's no need to explicitly add the string null-terminator, it will be added by `snprintf`. – Some programmer dude Jul 20 '22 at 13:13
  • As for your problem, try printing both `fname` and `full_filename`. Are the paths valid? Are (at least) `full_filename` an absolute path? If not, is the path valid from the process working directory? And what *is* `full_filename` by the way? How is it defined? – Some programmer dude Jul 20 '22 at 13:14
  • @Someprogrammerdude fname contain the correct file name "0223.bin", and full contain also the same name "0223.bin" . #define LWIP_TFTP_EXAMPLE_CLIENT_FILENAME "0223.bin" #define LWIP_TFTP_EXAMPLE_BASE_DIR "" – lily amazon Jul 20 '22 at 13:24
  • Since it's a relative path, not an absolute path, the servers [working directory](https://en.wikipedia.org/wiki/Working_directory) becomes very relevant, as all relative paths are from that directory. With the filename `0223.bin` the program looks only in the working directory, so you have to check the working directory of the process, and make sure the file is in the same directory. Or configure the `LWIP_TFTP_EXAMPLE_BASE_DIR` macro to be an absolute path (with trailing `/`). – Some programmer dude Jul 20 '22 at 14:46
  • @Someprogrammerdude the file exist in the working directory of my tftp server, i have tried a local client (not from MCU) and it working. in tftpd64 there is option to allow '\' as virtual root, i edit my question to include my tftp server settings, i also set '/' in LWIP_TFTP_EXAMPLE_BASE_DIR, i get now for the file name 0223.bin and for full file name /0223.bin. but still i get the same issue – lily amazon Jul 20 '22 at 17:42
  • @Someprogrammerdude i changed my corporate computer by another one (not in the same network), and now i can get the log in the TFTP server : Connection received from 192.168.225.2 on port 69 [21/07 13:19:27.213] Read request for file <0223.bin>. Mode octet [21/07 13:19:27.213] Using local port 56883 [21/07 13:19:27.213] Peer returns ERROR -> aborting transfer [21/07 13:19:27.214] – lily amazon Jul 21 '22 at 11:40
  • @Someprogrammerdude i used another TFTP server from solarWind, and i got the same issue, the client abort the connection for some reason ? any idea why – lily amazon Jul 26 '22 at 13:13

0 Answers0