[PATCH 10/17] net: tftp: Add IPv6 support for tftpboot
Simon Glass
sjg at chromium.org
Thu Sep 1 04:26:58 CEST 2022
Hi Viacheslav,
On Tue, 30 Aug 2022 at 07:02, Viacheslav Mitrofanov
<v.v.mitrofanov at yadro.com> wrote:
>
> The command tftpboot uses IPv4 by default. Add the possibility to use IPv6
> instead. If an address in the command is an IPv6 address it will use IPv6
> to boot or if there is a suffix -ipv6 in the end of the command it also
> force using IPv6. All other tftpboot features and parameters are left
> the same.
>
> Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov at yadro.com>
> ---
> cmd/net.c | 22 +++++++++++++++++++
> net/net.c | 34 ++++++++++++++++++++++++++++--
> net/tftp.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++-------
> 3 files changed, 108 insertions(+), 10 deletions(-)
>
> diff --git a/cmd/net.c b/cmd/net.c
> index 3619c843d8..0225f9ce3e 100644
> --- a/cmd/net.c
> +++ b/cmd/net.c
> @@ -14,6 +14,7 @@
> #include <env.h>
> #include <image.h>
> #include <net.h>
> +#include <net6.h>
> #include <net/udp.h>
> #include <net/sntp.h>
>
> @@ -44,12 +45,22 @@ int do_tftpb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
> return ret;
> }
>
> +#if IS_ENABLED(CONFIG_IPV6)
> +U_BOOT_CMD(
> + tftpboot, 4, 1, do_tftpb,
> + "boot image via network using TFTP protocol\n"
> + "To use IPv6 add -ipv6 parameter or use IPv6 hostIPaddr framed "
> + "with [] brackets",
> + "[loadAddress] [[hostIPaddr:]bootfilename] [" USE_IP6_CMD_PARAM "]"
> +);
> +#else
> U_BOOT_CMD(
> tftpboot, 3, 1, do_tftpb,
> "boot image via network using TFTP protocol",
> "[loadAddress] [[hostIPaddr:]bootfilename]"
> );
> #endif
> +#endif
>
> #ifdef CONFIG_CMD_TFTPPUT
> static int do_tftpput(struct cmd_tbl *cmdtp, int flag, int argc,
> @@ -205,6 +216,17 @@ static int netboot_common(enum proto_t proto, struct cmd_tbl *cmdtp, int argc,
> if (s != NULL)
> image_load_addr = hextoul(s, NULL);
>
> + if (IS_ENABLED(CONFIG_IPV6)) {
> + use_ip6 = false;
> +
> + /* IPv6 parameter has to be always *last* */
> + if (!strcmp(argv[argc - 1], USE_IP6_CMD_PARAM)) {
> + use_ip6 = true;
> + /* It is a hack not to break switch/case code */
> + --argc;
> + }
> + }
> +
> switch (argc) {
> case 1:
> /* refresh bootfile name from env */
> diff --git a/net/net.c b/net/net.c
> index f818170930..77f42d1d59 100644
> --- a/net/net.c
> +++ b/net/net.c
> @@ -449,6 +449,23 @@ restart:
> debug_cond(DEBUG_INT_STATE, "--- net_loop Init\n");
> net_init_loop();
>
> + /* Find out what protocol to use */
> + if (IS_ENABLED(CONFIG_IPV6) && !use_ip6) {
> + char *s, *e;
> + char str_ip6[16];
> +
> + s = strchr(net_boot_file_name, '[');
> + e = strchr(net_boot_file_name, ']');
> + if (s && e) {
> + size_t len = e - s;
> +
> + memcpy(str_ip6, s + 1, len);
> + str_ip6[len - 1] = '\0';
> + if (!string_to_ip6(str_ip6, &net_server_ip6))
Should string_to_ip6 take a length param so the string does not need
to be nul-terminated?
> + use_ip6 = true;
> + }
> + }
> +
[..]
Regards,
Simon
More information about the U-Boot
mailing list