From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
To: Maxim Uvarov <maxim.uvarov@linaro.org>
Cc: u-boot@lists.denx.de, pbrobinson@redhat.com,
joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com,
goldsimon@gmx.de, lwip-devel@nongnu.org
Subject: Re: [PATCHv6 05/14] net/lwip: implement tftp cmd
Date: Mon, 14 Aug 2023 17:25:26 +0300 [thread overview]
Message-ID: <ZNo5Vlg8pgvnW8hw@hades> (raw)
In-Reply-To: <20230814133253.4150-6-maxim.uvarov@linaro.org>
> +// SPDX-License-Identifier: GPL-2.0
> +
> +/*
> + * (C) Copyright 2023 Linaro Ltd. <maxim.uvarov@linaro.org>
> + */
> +
> +#include <common.h>
> +#include <command.h>
> +#include <console.h>
> +#include <bootstage.h>
> +
> +#include "lwip/apps/tftp_client.h"
> +#include "lwip/apps/tftp_server.h"
> +#include <tftp_example.h>
> +
> +#include <string.h>
> +
> +#include <net/ulwip.h>
> +
> +#if LWIP_UDP
Why do we have this? I dont think it makes sense to start reasoning about
LWIP config options from within U-Boot code. Instead U-Boot makefiles
should enable all the LWIP features we need when a command is included
> +
> +static ulong daddr;
> +static ulong size;
> +
> +static void *tftp_open(const char *fname, const char *mode, u8_t is_write)
> +{
> + LWIP_UNUSED_ARG(mode);
> + return NULL;
> +}
> +
> +static void tftp_close(void *handle)
> +{
> + log_info("\ndone\n");
> + log_info("Bytes transferred = %ld (0x%lx hex)\n", size, size);
> +
> + bootstage_mark_name(BOOTSTAGE_KERNELREAD_STOP, "tftp_done");
> + env_set_ulong("filesize", size);
> + ulwip_exit(0);
> +}
> +
> +static int tftp_read(void *handle, void *buf, int bytes)
> +{
> + return 0;
> +}
> +
> +static int tftp_write(void *handle, struct pbuf *p)
> +{
> + struct pbuf *q;
> +
> + for (q = p; q != NULL; q = q->next) {
> + memcpy((void *)daddr, q->payload, q->len);
> + daddr += q->len;
> + size += q->len;
> + log_info("#");
> + }
> +
> + return 0;
> +}
> +
> +static void tftp_error(void *handle, int err, const char *msg, int size)
> +{
> + char message[100];
> +
> + LWIP_UNUSED_ARG(handle);
> +
> + memset(message, 0, sizeof(message));
> + MEMCPY(message, msg, LWIP_MIN(sizeof(message)-1, (size_t)size));
> +
> + log_info("TFTP error: %d (%s)", err, message);
> +}
> +
> +static const struct tftp_context tftp = {
> + tftp_open,
> + tftp_close,
> + tftp_read,
> + tftp_write,
> + tftp_error
> +};
> +
> +int ulwip_tftp(ulong addr, char *fname)
> +{
> + void *f = (void *)0x1; /* unused fake file handle*/
> + err_t err;
> + ip_addr_t srv;
> + int ret;
> + char *server_ip;
> +
> + if (!fname || addr == 0)
> + return CMD_RET_FAILURE;
> +
> + size = 0;
> + daddr = addr;
> + server_ip = env_get("serverip");
> + if (!server_ip) {
> + log_err("error: serverip variable has to be set\n");
> + return CMD_RET_FAILURE;
> + }
> +
> + ret = ipaddr_aton(server_ip, &srv);
> + if (!ret) {
> + log_err("error: ipaddr_aton\n");
> + return CMD_RET_FAILURE;
> + }
> +
> + log_info("TFTP from server %s; our IP address is %s\n",
> + server_ip, env_get("ipaddr"));
> + log_info("Filename '%s'.\n", fname);
> + log_info("Load address: 0x%lx\n", daddr);
> + log_info("Loading:");
> +
> + bootstage_mark_name(BOOTSTAGE_KERNELREAD_START, "tftp_start");
> +
> + err = tftp_init_client(&tftp);
> + if (!(err == ERR_OK || err == ERR_USE))
> + log_err("tftp_init_client err: %d\n", err);
> +
> + err = tftp_get(f, &srv, TFTP_PORT, fname, TFTP_MODE_OCTET);
Shouldn't this be part of tftp_read()?
> + /* might return different errors, like routing problems */
> + if (err != ERR_OK) {
> + log_err("tftp_get err=%d\n", err);
> + return CMD_RET_FAILURE;
> + }
> +
> + env_set_hex("fileaddr", addr);
> + return err;
> +}
> +#else
> +#error "UDP has to be supported"
> +#endif /* LWIP_UDP */
> --
> 2.30.2
>
next prev parent reply other threads:[~2023-08-14 14:25 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-14 13:32 [PATCHv6 00/14] net/lwip: add lwip library for the network stack Maxim Uvarov
2023-08-14 13:32 ` [PATCHv6 01/14] net/lwip: add doc/develop/net_lwip.rst Maxim Uvarov
2023-08-14 14:10 ` Ilias Apalodimas
2023-08-14 13:32 ` [PATCHv6 02/14] net/lwip: integrate lwIP library Maxim Uvarov
2023-08-14 14:13 ` Ilias Apalodimas
2023-08-14 13:32 ` [PATCHv6 03/14] net/lwip: implement dns cmd Maxim Uvarov
2023-08-14 14:19 ` Ilias Apalodimas
2023-08-14 15:15 ` Maxim Uvarov
2023-08-15 12:42 ` Maxim Uvarov
2023-08-15 14:42 ` Tom Rini
2023-08-16 10:26 ` Ilias Apalodimas
2023-08-16 11:01 ` Maxim Uvarov
2023-08-16 11:54 ` Ilias Apalodimas
2023-08-16 12:24 ` Maxim Uvarov
2023-08-14 13:32 ` [PATCHv6 04/14] net/lwip: implement dhcp cmd Maxim Uvarov
2023-08-14 14:21 ` Ilias Apalodimas
2023-08-14 15:18 ` Maxim Uvarov
2023-08-14 15:29 ` Tom Rini
2023-08-17 13:46 ` Maxim Uvarov
2023-08-17 14:04 ` Peter Robinson
2023-08-17 14:55 ` Maxim Uvarov
2023-08-17 15:10 ` Tom Rini
2023-08-18 9:39 ` Maxim Uvarov
2023-08-18 11:14 ` Peter Robinson
2023-08-18 14:24 ` Tom Rini
2023-08-14 13:32 ` [PATCHv6 05/14] net/lwip: implement tftp cmd Maxim Uvarov
2023-08-14 14:25 ` Ilias Apalodimas [this message]
2023-08-14 18:54 ` Maxim Uvarov
2023-08-14 13:32 ` [PATCHv6 06/14] net/lwip: implement wget cmd Maxim Uvarov
2023-08-16 8:38 ` Ilias Apalodimas
2023-08-14 13:32 ` [PATCHv6 07/14] net/lwip: implement ping cmd Maxim Uvarov
2023-08-16 8:42 ` Ilias Apalodimas
2023-08-16 9:09 ` Maxim Uvarov
2023-08-16 14:39 ` Simon Glass
2023-08-16 20:15 ` Maxim Uvarov
2023-08-18 3:10 ` Simon Glass
2023-08-18 9:27 ` Maxim Uvarov
2023-08-22 18:56 ` Simon Glass
2023-08-14 13:32 ` [PATCHv6 08/14] net/lwip: add lwIP configuration Maxim Uvarov
2023-08-14 13:32 ` [PATCHv6 09/14] net/lwip: implement lwIP port to U-Boot Maxim Uvarov
2023-08-16 9:01 ` Ilias Apalodimas
2023-08-18 12:53 ` Maxim Uvarov
2023-08-18 18:21 ` Simon Goldschmidt
2023-08-14 13:32 ` [PATCHv6 10/14] net/lwip: update .gitignore with lwIP Maxim Uvarov
2023-08-14 13:32 ` [PATCHv6 11/14] net/lwip: connection between cmd and lwip apps Maxim Uvarov
2023-08-16 9:12 ` Ilias Apalodimas
2023-08-14 13:32 ` [PATCHv6 12/14] net/lwip: replace original net commands with lwip Maxim Uvarov
2023-08-14 13:32 ` [PATCHv6 13/14] net/lwip: split net.h to net.h, arp.h and eth.h Maxim Uvarov
2023-08-14 13:32 ` [PATCHv6 14/14] net/lwip: drop old net/wget Maxim Uvarov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZNo5Vlg8pgvnW8hw@hades \
--to=ilias.apalodimas@linaro.org \
--cc=goldsimon@gmx.de \
--cc=joe.hershberger@ni.com \
--cc=lwip-devel@nongnu.org \
--cc=maxim.uvarov@linaro.org \
--cc=pbrobinson@redhat.com \
--cc=rfried.dev@gmail.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox