[PATCH 3/5] sandbox: parse libftdi options

Antony Pavlov antonynpavlov at gmail.com
Mon Oct 16 07:10:11 PDT 2017


On Mon, 16 Oct 2017 10:21:58 +0200
Sascha Hauer <s.hauer at pengutronix.de> wrote:

> On Tue, Oct 10, 2017 at 03:26:29PM +0300, Antony Pavlov wrote:
> > Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
> > ---
> >  arch/sandbox/Makefile    |  2 +-
> >  arch/sandbox/os/common.c | 12 ++++++--
> >  arch/sandbox/os/ftdi.c   | 79 +++++++++++++++++++++++++++++++++++++++++++++++-
> >  3 files changed, 89 insertions(+), 4 deletions(-)
> > 
> > diff --git a/arch/sandbox/os/ftdi.c b/arch/sandbox/os/ftdi.c
> > index 34e9165787..e3e46ed12d 100644
> > --- a/arch/sandbox/os/ftdi.c
> > +++ b/arch/sandbox/os/ftdi.c
> > @@ -20,6 +20,7 @@
> >  #include <unistd.h>
> >  #include <ftdi.h>
> >  #include <errno.h>
> > +#include <string.h>
> >  #include <mach/linux.h>
> >  
> >  #define FTDI_VID		0x0403	/* Vendor Id */
> > @@ -38,6 +39,8 @@ struct ft2232_bitbang {
> >  
> >  static struct ft2232_bitbang ftbb;
> >  
> > +extern const char *libftdi_options;
> > +
> >  static inline int ftdi_flush(struct ftdi_context *ftdi)
> >  {
> >  	uint8_t buf[1];
> > @@ -116,6 +119,67 @@ void barebox_libftdi1_gpio_set_value(struct ft2232_bitbang *ftbb,
> >  		ftbb->odata &= ~BIT(off);
> >  }
> >  
> > +/* This is a somewhat hacked function similar in some ways to strtok().
> > + * It will look for needle with a subsequent '=' in haystack, return a copy of
> > + * needle and remove everything from the first occurrence of needle to the next
> > + * delimiter from haystack.
> > + */
> > +static char *extract_param(const char *const *haystack, const char *needle,
> > +			const char *delim)
> > +{
> 
> Parsing comma separated option lists is something we do more than once.
> Right now we already have parseopt_b and parseopt_hu. Would be nice to
> have this function alongside with the existing functions. Also
> parseopt_* look simpler to follow, it may be worth adopting the code for
> this function.

At the moment the parseopt_* functions are in the fs/parseopt.c file.
Adding the parseopt_ul() for parsing u32 option value in arch/sandbox/os/ftdi.c
will lead to moving fs/parseopt.c file to common code, e.g. to lib/.

Is it ok to add 'obj-y += parseopt.o' to the lib/Makefile file?

May be you prefere to introduce special Kconfig option for parseopt.o conditional
compilation?

-- 
Best regards,
  Antony Pavlov



More information about the barebox mailing list