diff mbox series

[U-Boot,2/5] net: Re-check prerequisites when autoloading

Message ID 20180704003643.10133-2-joe.hershberger@ni.com
State Accepted
Commit 3855cad62342c3268465bc760e2bd7e6d0ce7f31
Delegated to: Joe Hershberger
Headers show
Series [U-Boot,1/5] net: When checking prerequisites, consider boot_file_name | expand

Commit Message

Joe Hershberger July 4, 2018, 12:36 a.m. UTC
With net autoload, we check the prerequisites for the initial command,
but the greater prerequisites when autoloading are not checked.

If we would attempt to autoload, check those prerequisites too.

If we are not expecting a serverip from the server, then don't worry
about it not being set, but don't attempt to load if it isn't.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
---

 net/net.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Comments

Alexander Graf July 4, 2018, 9:20 a.m. UTC | #1
On 07/04/2018 02:36 AM, Joe Hershberger wrote:
> With net autoload, we check the prerequisites for the initial command,
> but the greater prerequisites when autoloading are not checked.
>
> If we would attempt to autoload, check those prerequisites too.
>
> If we are not expecting a serverip from the server, then don't worry
> about it not being set, but don't attempt to load if it isn't.
>
> Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
> ---
>
>   net/net.c | 20 ++++++++++++++++++++
>   1 file changed, 20 insertions(+)
>
> diff --git a/net/net.c b/net/net.c
> index bff3e9c5b5..42a50e60f8 100644
> --- a/net/net.c
> +++ b/net/net.c
> @@ -332,6 +332,16 @@ void net_auto_load(void)
>   	const char *s = env_get("autoload");
>   
>   	if (s != NULL && strcmp(s, "NFS") == 0) {
> +		if (net_check_prereq(NFS)) {
> +/* We aren't expecting to get a serverip, so just accept the assigned IP */
> +#ifdef CONFIG_BOOTP_SERVERIP
> +			net_set_state(NETLOOP_SUCCESS);
> +#else
> +			printf("Cannot autoload with NFS\n");
> +			net_set_state(NETLOOP_FAIL);
> +#endif

I don't understand the #ifdef. In the CONFIG_BOOTP_SERVERIP case, you 
should already have net_server_ip set from the variable setter, so when 
do you realistically get into the case where net_check_prereq() fails 
here? I can only see that happening when serverip is not set (read: 
net_server_ip == 0.0.0.0) in which case we should also error out in the 
CONFIG_BOOTP_SERVERIP case, no?


Alex
Joe Hershberger July 4, 2018, 4:23 p.m. UTC | #2
On Wed, Jul 4, 2018 at 4:20 AM, Alexander Graf <agraf@suse.de> wrote:
> On 07/04/2018 02:36 AM, Joe Hershberger wrote:
>>
>> With net autoload, we check the prerequisites for the initial command,
>> but the greater prerequisites when autoloading are not checked.
>>
>> If we would attempt to autoload, check those prerequisites too.
>>
>> If we are not expecting a serverip from the server, then don't worry
>> about it not being set, but don't attempt to load if it isn't.
>>
>> Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
>> ---
>>
>>   net/net.c | 20 ++++++++++++++++++++
>>   1 file changed, 20 insertions(+)
>>
>> diff --git a/net/net.c b/net/net.c
>> index bff3e9c5b5..42a50e60f8 100644
>> --- a/net/net.c
>> +++ b/net/net.c
>> @@ -332,6 +332,16 @@ void net_auto_load(void)
>>         const char *s = env_get("autoload");
>>         if (s != NULL && strcmp(s, "NFS") == 0) {
>> +               if (net_check_prereq(NFS)) {
>> +/* We aren't expecting to get a serverip, so just accept the assigned IP
>> */
>> +#ifdef CONFIG_BOOTP_SERVERIP
>> +                       net_set_state(NETLOOP_SUCCESS);
>> +#else
>> +                       printf("Cannot autoload with NFS\n");
>> +                       net_set_state(NETLOOP_FAIL);
>> +#endif
>
>
> I don't understand the #ifdef. In the CONFIG_BOOTP_SERVERIP case, you should
> already have net_server_ip set from the variable setter, so when do you
> realistically get into the case where net_check_prereq() fails here? I can

My thinking here was that if the user is in control of the serverip
and chooses not to set it, then at least populate the dhcp variables
that were successful. If we return a fail from here, even though DHCP
was successful, the result will not be saved to the env for the user.

> only see that happening when serverip is not set (read: net_server_ip ==
> 0.0.0.0) in which case we should also error out in the CONFIG_BOOTP_SERVERIP
> case, no?
>
>
> Alex
>
>
>
> _______________________________________________
> U-Boot mailing list
> U-Boot@lists.denx.de
> https://lists.denx.de/listinfo/u-boot
Alexander Graf July 5, 2018, 11:55 a.m. UTC | #3
On 07/04/2018 06:23 PM, Joe Hershberger wrote:
> On Wed, Jul 4, 2018 at 4:20 AM, Alexander Graf <agraf@suse.de> wrote:
>> On 07/04/2018 02:36 AM, Joe Hershberger wrote:
>>> With net autoload, we check the prerequisites for the initial command,
>>> but the greater prerequisites when autoloading are not checked.
>>>
>>> If we would attempt to autoload, check those prerequisites too.
>>>
>>> If we are not expecting a serverip from the server, then don't worry
>>> about it not being set, but don't attempt to load if it isn't.
>>>
>>> Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
>>> ---
>>>
>>>    net/net.c | 20 ++++++++++++++++++++
>>>    1 file changed, 20 insertions(+)
>>>
>>> diff --git a/net/net.c b/net/net.c
>>> index bff3e9c5b5..42a50e60f8 100644
>>> --- a/net/net.c
>>> +++ b/net/net.c
>>> @@ -332,6 +332,16 @@ void net_auto_load(void)
>>>          const char *s = env_get("autoload");
>>>          if (s != NULL && strcmp(s, "NFS") == 0) {
>>> +               if (net_check_prereq(NFS)) {
>>> +/* We aren't expecting to get a serverip, so just accept the assigned IP
>>> */
>>> +#ifdef CONFIG_BOOTP_SERVERIP
>>> +                       net_set_state(NETLOOP_SUCCESS);
>>> +#else
>>> +                       printf("Cannot autoload with NFS\n");
>>> +                       net_set_state(NETLOOP_FAIL);
>>> +#endif
>>
>> I don't understand the #ifdef. In the CONFIG_BOOTP_SERVERIP case, you should
>> already have net_server_ip set from the variable setter, so when do you
>> realistically get into the case where net_check_prereq() fails here? I can
> My thinking here was that if the user is in control of the serverip
> and chooses not to set it, then at least populate the dhcp variables
> that were successful. If we return a fail from here, even though DHCP
> was successful, the result will not be saved to the env for the user.

IMHO CONFIG_BOOTP_SERVERIP is a very esoteric use case already. Let's 
not interpret too much into it. Instead, I would prefer if we could just 
treat it the same as the normal case as often as we can ...

Or maybe just move its functionality (do not set serverip from dhcp 
command) into an environment variable.


Alex
Joe Hershberger July 26, 2018, 7:16 p.m. UTC | #4
Hi Joe,

https://patchwork.ozlabs.org/patch/939041/ was applied to http://git.denx.de/?p=u-boot/u-boot-net.git

Thanks!
-Joe
diff mbox series

Patch

diff --git a/net/net.c b/net/net.c
index bff3e9c5b5..42a50e60f8 100644
--- a/net/net.c
+++ b/net/net.c
@@ -332,6 +332,16 @@  void net_auto_load(void)
 	const char *s = env_get("autoload");
 
 	if (s != NULL && strcmp(s, "NFS") == 0) {
+		if (net_check_prereq(NFS)) {
+/* We aren't expecting to get a serverip, so just accept the assigned IP */
+#ifdef CONFIG_BOOTP_SERVERIP
+			net_set_state(NETLOOP_SUCCESS);
+#else
+			printf("Cannot autoload with NFS\n");
+			net_set_state(NETLOOP_FAIL);
+#endif
+			return;
+		}
 		/*
 		 * Use NFS to load the bootfile.
 		 */
@@ -347,6 +357,16 @@  void net_auto_load(void)
 		net_set_state(NETLOOP_SUCCESS);
 		return;
 	}
+	if (net_check_prereq(TFTPGET)) {
+/* We aren't expecting to get a serverip, so just accept the assigned IP */
+#ifdef CONFIG_BOOTP_SERVERIP
+		net_set_state(NETLOOP_SUCCESS);
+#else
+		printf("Cannot autoload with TFTPGET\n");
+		net_set_state(NETLOOP_FAIL);
+#endif
+		return;
+	}
 	tftp_start(TFTPGET);
 }