[U-Boot] [PATCH 4/8] dfu: tftp: update: Provide tftp support for the DFU subsystem

Lukasz Majewski l.majewski at majess.pl
Mon Jul 20 21:03:02 CEST 2015


On Fri, 17 Jul 2015 14:35:39 -0500
Joe Hershberger <joe.hershberger at gmail.com> wrote:

> Hi Lukasz,
> 
> On Thu, Jul 16, 2015 at 3:06 PM, Lukasz Majewski
> <l.majewski at majess.pl> wrote:
> > Hi Joe,
> >
> >> Hi Lukasz,
> >>
> >> On Sun, Jul 12, 2015 at 10:30 AM, Lukasz Majewski
> >> <l.majewski at majess.pl> wrote:
> >> > This commit adds initial support for using tftp for downloading
> >> > and upgrading firmware on the device.
> >> >
> >> > Signed-off-by: Lukasz Majewski <l.majewski at majess.pl>
> >> > ---
> >> >  drivers/dfu/Makefile   |  1 +
> >> >  drivers/dfu/dfu_tftp.c | 76
> >> > ++++++++++++++++++++++++++++++++++++++++++++++++++
> >> > include/dfu.h          | 11 ++++++++ 3 files changed, 88
> >> > insertions(+) create mode 100644 drivers/dfu/dfu_tftp.c
> >> >
> >> > diff --git a/drivers/dfu/Makefile b/drivers/dfu/Makefile
> >> > index 5cc535e..43249ce 100644
> >> > --- a/drivers/dfu/Makefile
> >> > +++ b/drivers/dfu/Makefile
> >> > @@ -10,3 +10,4 @@ obj-$(CONFIG_DFU_MMC) += dfu_mmc.o
> >> >  obj-$(CONFIG_DFU_NAND) += dfu_nand.o
> >> >  obj-$(CONFIG_DFU_RAM) += dfu_ram.o
> >> >  obj-$(CONFIG_DFU_SF) += dfu_sf.o
> >> > +obj-$(CONFIG_DFU_TFTP) += dfu_tftp.o
> >> > diff --git a/drivers/dfu/dfu_tftp.c b/drivers/dfu/dfu_tftp.c
> >> > new file mode 100644
> >> > index 0000000..26539f2
> >> > --- /dev/null
> >> > +++ b/drivers/dfu/dfu_tftp.c
> >> > @@ -0,0 +1,76 @@
> >> > +/*
> >> > + * (C) Copyright 2015
> >> > + * Lukasz Majewski <l.majewski at majess.pl>
> >> > + *
> >> > + * SPDX-License-Identifier:    GPL-2.0+
> >> > + */
> >> > +
> >> > +#include <common.h>
> >> > +#include <malloc.h>
> >> > +#include <errno.h>
> >> > +#include <dfu.h>
> >> > +
> >> > +int dfu_tftp_write(char *dfu_entity_name, unsigned int addr,
> >> > unsigned int len) +{
> >> > +       char *s, *sb, *interface, *devstring;
> >> > +       int alt_setting_num, ret;
> >> > +       struct dfu_entity *dfu;
> >> > +
> >> > +       debug("%s: name: %s addr: 0x%x len: %d\n", __func__,
> >> > dfu_entity_name,
> >> > +             addr, len);
> >> > +
> >> > +       interface = getenv("update_tftp_dfu_interface");
> >> > +       if (interface == NULL) {
> >> > +               error("TFTP DFU: 'interface' not defined\n");
> >> > +               return -EINVAL;
> >> > +       }
> >> > +
> >> > +       devstring = getenv("update_tftp_dfu_devstring");
> >> > +       if (devstring == NULL) {
> >> > +               error("TFTP DFU: 'devstring' not defined\n");
> >> > +               return -EINVAL;
> >> > +       }
> >>
> >> It would be great if these env vars could be moved to command
> >> parameters.
> >
> > Those parameters are necessary to perform update (via update_tftp())
> > during boot time.
> 
> This is just the old method, right? Not the new DFU stuff.

Yes, this is the part of legacy code.

> 
> > Normally - when user call 'dfutftp' command he/she needs to specify
> > this informaiton. (e.g. 'dfutftp 0 mmc 1').
> 
> Perfect - so specify it when you call it from preboot.

I think that it would be feasible to use preboot variable for early
booting.

The problem is with CONFIG_UPDATE_TFTP flag. I will try to find
solution for this issue.

> 
> >> > +
> >> > +       ret = dfu_init_env_entities(interface, devstring);
> >> > +       if (ret)
> >> > +               goto done;
> >> > +
> >> > +       /*
> >> > +        * We need to copy name pointed by *dfu_entity_name since
> >> > this text
> >> > +        * is the integral part of the FDT image.
> >> > +        * Any implicit modification (i.e. done by strsep()) will
> >> > corrupt
> >> > +        * the FDT image and prevent other images to be stored.
> >> > +        */
> >> > +       s = strdup(dfu_entity_name);
> >> > +       sb = s;
> >> > +       if (!s) {
> >> > +               ret = -ENOMEM;
> >> > +               goto done;
> >> > +       }
> >> > +
> >> > +       strsep(&s, "@");
> >> > +       debug("%s: image name: %s strlen: %d\n", __func__, sb,
> >> > strlen(sb)); +
> >> > +       alt_setting_num = dfu_get_alt(sb);
> >> > +       free(sb);
> >> > +       if (alt_setting_num < 0) {
> >> > +               error("Alt setting [%d] to write not found!",
> >> > +                     alt_setting_num);
> >> > +               ret = -ENODEV;
> >> > +               goto done;
> >> > +       }
> >> > +
> >> > +       dfu = dfu_get_entity(alt_setting_num);
> >> > +       if (!dfu) {
> >> > +               error("DFU entity for alt: %d not found!",
> >> > alt_setting_num);
> >> > +               ret = -ENODEV;
> >> > +               goto done;
> >> > +       }
> >> > +
> >> > +       ret = dfu_write_from_mem_addr(dfu, (void *)addr, len);
> >> > +
> >> > +done:
> >> > +       dfu_free_entities();
> >> > +
> >> > +       return ret;
> >> > +}
> >> > diff --git a/include/dfu.h b/include/dfu.h
> >> > index 7d31abd..adad863 100644
> >> > --- a/include/dfu.h
> >> > +++ b/include/dfu.h
> >> > @@ -207,5 +207,16 @@ static inline int dfu_fill_entity_sf(struct
> >> > dfu_entity *dfu, char *devstr, }
> >> >  #endif
> >> >
> >> > +#ifdef CONFIG_DFU_TFTP
> >> > +int dfu_tftp_write(char *dfu_entity_name, unsigned int addr,
> >> > unsigned int len); +#else
> >> > +static inline int dfu_tftp_write(char *dfu_entity_name, unsigned
> >> > int addr,
> >> > +                                unsigned int len)
> >> > +{
> >> > +       puts("TFTP write support for DFU not available!\n");
> >> > +       return -1;
> >>
> >> This should be -ENOSYS probably.
> >
> > Good point - thanks!
> >
> >>
> >> > +}
> >> > +#endif
> >> > +
> >> >  int dfu_add(struct usb_configuration *c);
> >> >  #endif /* __DFU_ENTITY_H_ */
> >> > --
> >> > 2.1.4
> >> >
> >> > _______________________________________________
> >> > U-Boot mailing list
> >> > U-Boot at lists.denx.de
> >> > http://lists.denx.de/mailman/listinfo/u-boot
> >
> > Best regards,
> > Lukasz Majewski

Best regards,
Lukasz Majewski
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150720/a2aeddcc/attachment.sig>


More information about the U-Boot mailing list