[U-Boot] [RFC PATCH] env: Add a setenv that allows passing flags

Chris Packham Chris.Packham at alliedtelesis.co.nz
Wed Jun 15 07:43:22 CEST 2016


On 06/15/2016 08:47 AM, Chris Packham wrote:
> Hi Joe,
>
> On 06/15/2016 07:01 AM, Joe Hershberger wrote:
>> In some cases an interactive feature will be implemented using the
>> programmatic APIs, so the developer will want "interactive" behavior as
>> a result, so provide an API that will allow that to be specified.
>>
>> Signed-off-by: Joe Hershberger <joe.hershberger at ni.com>
>
> Thanks looks great
>
> Reviewed-by: Chris Packham <chris.packham at alliedtelesis.co.nz>
>
> I'll also give it a test on some of our setups here and report back.

Matt did the testing for me so:

Tested-by: Matthew Bright <matthew.bright at alliedtelesis.co.nz>

One other corner case I think I spotted was that if you use the dns 
command to set one of these net variables it won't stick

e.g.
   setenv serverip 127.0.0.1
   setenv dnsip 192.168.1.1
   dns bootserver.example.com serverip
   tftpboot

So maybe we want this as well (warning totally untested and my mailer is 
probably going to eat the whitespace)

--- 8< ---
[PATCH] net: use setenv_w_flags when updating environment variable

The serverip environment variable is special in that it is not updated
unless set from the CLI. The other places it is set (e.g. bootp/dhcp)
this is handled correctly but as the dns command can take an arbitrary
environment variable we need to use the H_INTERACTIVE flag to make the
setting stick.

Signed-off-by: Chris Packham <chris.packham at alliedtelesis.co.nz>
---
  net/dns.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/dns.c b/net/dns.c
index 7017bac..f0c8744 100644
--- a/net/dns.c
+++ b/net/dns.c
@@ -184,7 +184,8 @@ static void dns_handler(uchar *pkt, unsigned dest, 
struct in_addr sip,
                         ip_to_string(ip_addr, ip_str);
                         printf("%s\n", ip_str);
                         if (net_dns_env_var)
-                               setenv(net_dns_env_var, ip_str);
+                               setenv_w_flags(net_dns_env_var, ip_str,
+                                              H_INTERACTIVE);
                 } else {
                         puts("server responded with invalid IP number\n");
                 }
-- 
2.8.4
--- 8< ---

>
>> ---
>>
>>    cmd/nvedit.c     | 11 ++++++++---
>>    include/common.h |  5 +++--
>>    2 files changed, 11 insertions(+), 5 deletions(-)
>>
>> diff --git a/cmd/nvedit.c b/cmd/nvedit.c
>> index b67563b..c7c24e3 100644
>> --- a/cmd/nvedit.c
>> +++ b/cmd/nvedit.c
>> @@ -284,7 +284,7 @@ static int _do_env_set(int flag, int argc, char * const argv[], int env_flag)
>>    	return 0;
>>    }
>>
>> -int setenv(const char *varname, const char *varvalue)
>> +int setenv_w_flags(const char *varname, const char *varvalue, int flags)
>>    {
>>    	const char * const argv[4] = { "setenv", varname, varvalue, NULL };
>>
>> @@ -293,9 +293,14 @@ int setenv(const char *varname, const char *varvalue)
>>    		return 1;
>>
>>    	if (varvalue == NULL || varvalue[0] == '\0')
>> -		return _do_env_set(0, 2, (char * const *)argv, H_PROGRAMMATIC);
>> +		return _do_env_set(0, 2, (char * const *)argv, flags);
>>    	else
>> -		return _do_env_set(0, 3, (char * const *)argv, H_PROGRAMMATIC);
>> +		return _do_env_set(0, 3, (char * const *)argv, flags);
>> +}
>> +
>> +int setenv(const char *varname, const char *varvalue)
>> +{
>> +	return setenv_w_flags(varname, varvalue, H_PROGRAMMATIC);
>>    }
>>
>>    /**
>> diff --git a/include/common.h b/include/common.h
>> index f9f4605..199e0e2 100644
>> --- a/include/common.h
>> +++ b/include/common.h
>> @@ -377,8 +377,9 @@ ulong getenv_hex(const char *varname, ulong default_val);
>>     * Return -1 if variable does not exist (default to true)
>>     */
>>    int getenv_yesno(const char *var);
>> -int	saveenv	     (void);
>> -int	setenv	     (const char *, const char *);
>> +int saveenv(void);
>> +int setenv_w_flags(const char *varname, const char *varvalue, int flags);
>> +int setenv(const char *varname, const char *varvalue);
>>    int setenv_ulong(const char *varname, ulong value);
>>    int setenv_hex(const char *varname, ulong value);
>>    /**
>>
>
>



More information about the U-Boot mailing list