[PATCH] env: Leave invalid env for nowhere location

Kunihiko Hayashi hayashi.kunihiko at socionext.com
Tue May 25 08:30:31 CEST 2021


Hi Tim,

How about this fix?

You already tested Marek's patch, and I'd like to hear your comment
about this patch, or know whether it occurs the issue with
CONFIG_ENV_IS_NOWHERE if possible.

Thank you,

On 2021/05/17 2:19, Marek Vasut wrote:
> On 5/12/21 4:09 PM, Kunihiko Hayashi wrote:
>> When CONFIG_ENV_IS_NOWHERE is enabled, env_nowhere_init() sets ENV_INVALID
>> to gd->env_valid, and sets default_environment before relocation to
>> gd->env_addr. After that, env_init() switches gd->env_valid to ENV_VALID
>> by the previous fix.
>>
>> If gd->env_valid is ENV_INVALID, env_get_char() returns relocated
>> default_environment, however, env_get_char() returns gd->env_addr before
>> relocation since gd->env_valid is ENV_VALID, and access to gd->env_addr
>> will cause a fault.
>>
>> This leaves gd->env_valid as ENV_INVALID for "nowhere" location.
>>
>> Cc: Marek Vasut <marex at denx.de>
>> Fixes: 5557eec01cbf ("env: Fix invalid env handling in env_init()")
>> Signed-off-by: Kunihiko Hayashi <hayashi.kunihiko at socionext.com>
>> ---
>>    env/env.c | 3 ++-
>>    1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/env/env.c b/env/env.c
>> index e534008..3233172 100644
>> --- a/env/env.c
>> +++ b/env/env.c
>> @@ -336,7 +336,8 @@ int env_init(void)
>>    		debug("%s: Environment %s init done (ret=%d)\n", __func__,
>>    		      drv->name, ret);
>>    
>> -		if (gd->env_valid == ENV_INVALID)
>> +		if (gd->env_valid == ENV_INVALID
>> +		    && drv->location != ENVL_NOWHERE)
>>    			ret = -ENOENT;
>>    	}
> 
> I'm CCing Tim, it would be good to get a TB from him.
> 

---
Best Regards
Kunihiko Hayashi


More information about the U-Boot mailing list