Re: [U-Boot] [PATCH 1/2] net: Add option to prefer bootp/dhcp serverip

2018-06-13 Thread Joe Hershberger
On Wed, Jun 13, 2018 at 3:46 AM, Rick Chen  wrote:
> Hi Joe and Alex
>
>
> After trace, I found that in store_net_params( )
> if CONFIG_BOOTP_SERVERIP is not define,
> net_boot_file_name will be replaced by bp->bp_file
>
> copy_filename(net_boot_file_name, bp->bp_file,sizeof(net_boot_file_name));
>
> That is why the file name will become pxelinux.0, after remove
> CONFIG_BOOTP_SERVERIP.
>
> But I try to find where pxelinux.0 came from.
> It seems come from packet payload in dhcp_handler( ).
>

OK, that makes sense. It seems this will need to change as part of
this patch. Thanks for tracking it down.

>
> Rick
> ___
> U-Boot mailing list
> U-Boot@lists.denx.de
> https://lists.denx.de/listinfo/u-boot
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH 1/2] net: Add option to prefer bootp/dhcp serverip

2018-06-13 Thread Rick Chen
2018-06-13 9:42 GMT+08:00 Rick Chen :
> 2018-06-13 3:59 GMT+08:00 Joe Hershberger :
>> On Wed, Jun 6, 2018 at 8:54 PM, Rick Chen  wrote:
 From: Alexander Graf [mailto:ag...@suse.de]
 Sent: Wednesday, June 06, 2018 8:32 PM
 To: u-boot@lists.denx.de
 Cc: Rick Jian-Zhi Chen(陳建志); Joe Hershberger; Simon Glass
 Subject: [PATCH 1/2] net: Add option to prefer bootp/dhcp serverip

 Currently we can choose between 2 different types of behavior for the 
 serverip
 variable:

   1) Always overwrite it with the DHCP server IP address (default)
   2) Ignore what the DHCP server says (CONFIG_BOOTP_SERVERIP)

 This patch adds a 3rd option:

   3) Use serverip from DHCP if no serverip is given
  (CONFIG_BOOTP_PREFER_SERVERIP)

 With this new option, we can have the default case that a boot file gets 
 loaded
 from the DHCP provided TFTP server work while allowing users to specify 
 their
 own serverip variable to explicitly use a different tftp server.

 Signed-off-by: Alexander Graf 
 ---
  README  | 5 +
  cmd/Kconfig | 9 +
  net/bootp.c | 7 ++-
  3 files changed, 20 insertions(+), 1 deletion(-)

 diff --git a/README b/README
 index fb331f910d..d8a99281ca 100644
 --- a/README
 +++ b/README
 @@ -1511,10 +1511,15 @@ The following options need to be configured:
   CONFIG_BOOTP_TIMEOFFSET
   CONFIG_BOOTP_VENDOREX
   CONFIG_BOOTP_MAY_FAIL
 + CONFIG_BOOTP_PREFER_SERVERIP

   CONFIG_BOOTP_SERVERIP - TFTP server will be the serverip
   environment variable, not the BOOTP server.

 + CONFIG_BOOTP_PREFER_SERVERIP - TFTP server will be the
 + serverip environment variable if previously unset, otherwise
 + the DHCP provided serverip is used.
 +
   CONFIG_BOOTP_MAY_FAIL - If the DHCP server is not found
   after the configured retry count, the call will fail
   instead of starting over.  This can be used to fail over 
 diff --git
 a/cmd/Kconfig b/cmd/Kconfig index e283cb9a8a..e77a4131b3 100644
 --- a/cmd/Kconfig
 +++ b/cmd/Kconfig
 @@ -1121,6 +1121,15 @@ config BOOTP_HOSTNAME
   help
 The name may or may not be qualified with the local domain name.

 +config BOOTP_PREFER_SERVERIP
 + bool "Leave serverip variable in place if existing"
 + default n
 + depends on CMD_BOOTP
 + help
 +   By default a BOOTP/DHCP reply will overwrite the tftp target ip
 +   address. With this option enabled, it will leave it alone if
 +   already specified, but populate it if no serverip is specified.
 +
  config BOOTP_SUBNETMASK
   bool "Request & store 'netmask' from BOOTP/DHCP server"
   default y
 diff --git a/net/bootp.c b/net/bootp.c
 index 9d7cb5d30c..91de4cd426 100644
 --- a/net/bootp.c
 +++ b/net/bootp.c
 @@ -147,9 +147,14 @@ static void store_net_params(struct bootp_hdr *bp)
 {  #if !defined(CONFIG_BOOTP_SERVERIP)
   struct in_addr tmp_ip;
 + bool overwrite_serverip = true;
 +
 +#if defined(CONFIG_BOOTP_PREFER_SERVERIP)
 + overwrite_serverip = false;
 +#endif

   net_copy_ip(_ip, >bp_siaddr);
 - if (tmp_ip.s_addr != 0)
 + if (tmp_ip.s_addr != 0 && (overwrite_serverip ||
 +!net_server_ip.s_addr))
   net_copy_ip(_server_ip, >bp_siaddr);
   memcpy(net_server_ethaddr,
  ((struct ethernet_hdr *)net_rx_packet)->et_src, 6);
 --
 2.12.3
>>>
>>> Hi Alex
>>>
>>> I have apply those two patchs and verify
>>> U-Boot-1-2-net-Add-option-to-prefer-bootp-dhcp-serverip.patch
>>> U-Boot-2-2-ax25-Switch-to-CONFIG_BOOTP_PREFER_SERVERIP.patch
>>>
>>> But it still fail in dhcp command as below
>>>
>>> case 1
>>> serverip is null
>>>
>>> RISC-V # set serverip
>>> RISC-V # env print
>>> baudrate=38400
>>> bootcmd=fatload mmc 0:1 0x2000 ae350_64.dtb;fatload mmc 0:1 0x0
>>> bbl-ae350.bin;go 0x0
>>> bootdelay=3
>>> bootfile=pxelinux.0
>>> ethact=mac@e010
>>> fdtcontroladdr=3fedf290
>>> fileaddr=60
>>> filesize=1bb7d34
>>> stderr=serial@f030
>>> stdin=serial@f030
>>> stdout=serial@f030
>>>
>>> Environment size: 304/8188 bytes
>>> RISC-V # dhcp 0x60 10.0.4.97:boomimage-310y-ag101p.bin
>>
>> You are explicitly setting the server IP in the DHCP command line, so
>> why would you expect the DHCP server IP to be used?
>>
>>> BOOTP broadcast 1
>>> BOOTP broadcast 2
>>> BOOTP broadcast 3
>>> BOOTP broadcast 4
>>> DHCP client bound to address 10.0.4.191 (4603 ms)
>>> Using mac@e010 device
>>> TFTP from server 255.255.255.255; our IP address is 10.0.4.191;
>>
>> This broadcast address is clearly not right. It should have been 

Re: [U-Boot] [PATCH 1/2] net: Add option to prefer bootp/dhcp serverip

2018-06-12 Thread Rick Chen
2018-06-13 3:59 GMT+08:00 Joe Hershberger :
> On Wed, Jun 6, 2018 at 8:54 PM, Rick Chen  wrote:
>>> From: Alexander Graf [mailto:ag...@suse.de]
>>> Sent: Wednesday, June 06, 2018 8:32 PM
>>> To: u-boot@lists.denx.de
>>> Cc: Rick Jian-Zhi Chen(陳建志); Joe Hershberger; Simon Glass
>>> Subject: [PATCH 1/2] net: Add option to prefer bootp/dhcp serverip
>>>
>>> Currently we can choose between 2 different types of behavior for the 
>>> serverip
>>> variable:
>>>
>>>   1) Always overwrite it with the DHCP server IP address (default)
>>>   2) Ignore what the DHCP server says (CONFIG_BOOTP_SERVERIP)
>>>
>>> This patch adds a 3rd option:
>>>
>>>   3) Use serverip from DHCP if no serverip is given
>>>  (CONFIG_BOOTP_PREFER_SERVERIP)
>>>
>>> With this new option, we can have the default case that a boot file gets 
>>> loaded
>>> from the DHCP provided TFTP server work while allowing users to specify 
>>> their
>>> own serverip variable to explicitly use a different tftp server.
>>>
>>> Signed-off-by: Alexander Graf 
>>> ---
>>>  README  | 5 +
>>>  cmd/Kconfig | 9 +
>>>  net/bootp.c | 7 ++-
>>>  3 files changed, 20 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/README b/README
>>> index fb331f910d..d8a99281ca 100644
>>> --- a/README
>>> +++ b/README
>>> @@ -1511,10 +1511,15 @@ The following options need to be configured:
>>>   CONFIG_BOOTP_TIMEOFFSET
>>>   CONFIG_BOOTP_VENDOREX
>>>   CONFIG_BOOTP_MAY_FAIL
>>> + CONFIG_BOOTP_PREFER_SERVERIP
>>>
>>>   CONFIG_BOOTP_SERVERIP - TFTP server will be the serverip
>>>   environment variable, not the BOOTP server.
>>>
>>> + CONFIG_BOOTP_PREFER_SERVERIP - TFTP server will be the
>>> + serverip environment variable if previously unset, otherwise
>>> + the DHCP provided serverip is used.
>>> +
>>>   CONFIG_BOOTP_MAY_FAIL - If the DHCP server is not found
>>>   after the configured retry count, the call will fail
>>>   instead of starting over.  This can be used to fail over diff 
>>> --git
>>> a/cmd/Kconfig b/cmd/Kconfig index e283cb9a8a..e77a4131b3 100644
>>> --- a/cmd/Kconfig
>>> +++ b/cmd/Kconfig
>>> @@ -1121,6 +1121,15 @@ config BOOTP_HOSTNAME
>>>   help
>>> The name may or may not be qualified with the local domain name.
>>>
>>> +config BOOTP_PREFER_SERVERIP
>>> + bool "Leave serverip variable in place if existing"
>>> + default n
>>> + depends on CMD_BOOTP
>>> + help
>>> +   By default a BOOTP/DHCP reply will overwrite the tftp target ip
>>> +   address. With this option enabled, it will leave it alone if
>>> +   already specified, but populate it if no serverip is specified.
>>> +
>>>  config BOOTP_SUBNETMASK
>>>   bool "Request & store 'netmask' from BOOTP/DHCP server"
>>>   default y
>>> diff --git a/net/bootp.c b/net/bootp.c
>>> index 9d7cb5d30c..91de4cd426 100644
>>> --- a/net/bootp.c
>>> +++ b/net/bootp.c
>>> @@ -147,9 +147,14 @@ static void store_net_params(struct bootp_hdr *bp)
>>> {  #if !defined(CONFIG_BOOTP_SERVERIP)
>>>   struct in_addr tmp_ip;
>>> + bool overwrite_serverip = true;
>>> +
>>> +#if defined(CONFIG_BOOTP_PREFER_SERVERIP)
>>> + overwrite_serverip = false;
>>> +#endif
>>>
>>>   net_copy_ip(_ip, >bp_siaddr);
>>> - if (tmp_ip.s_addr != 0)
>>> + if (tmp_ip.s_addr != 0 && (overwrite_serverip ||
>>> +!net_server_ip.s_addr))
>>>   net_copy_ip(_server_ip, >bp_siaddr);
>>>   memcpy(net_server_ethaddr,
>>>  ((struct ethernet_hdr *)net_rx_packet)->et_src, 6);
>>> --
>>> 2.12.3
>>
>> Hi Alex
>>
>> I have apply those two patchs and verify
>> U-Boot-1-2-net-Add-option-to-prefer-bootp-dhcp-serverip.patch
>> U-Boot-2-2-ax25-Switch-to-CONFIG_BOOTP_PREFER_SERVERIP.patch
>>
>> But it still fail in dhcp command as below
>>
>> case 1
>> serverip is null
>>
>> RISC-V # set serverip
>> RISC-V # env print
>> baudrate=38400
>> bootcmd=fatload mmc 0:1 0x2000 ae350_64.dtb;fatload mmc 0:1 0x0
>> bbl-ae350.bin;go 0x0
>> bootdelay=3
>> bootfile=pxelinux.0
>> ethact=mac@e010
>> fdtcontroladdr=3fedf290
>> fileaddr=60
>> filesize=1bb7d34
>> stderr=serial@f030
>> stdin=serial@f030
>> stdout=serial@f030
>>
>> Environment size: 304/8188 bytes
>> RISC-V # dhcp 0x60 10.0.4.97:boomimage-310y-ag101p.bin
>
> You are explicitly setting the server IP in the DHCP command line, so
> why would you expect the DHCP server IP to be used?
>
>> BOOTP broadcast 1
>> BOOTP broadcast 2
>> BOOTP broadcast 3
>> BOOTP broadcast 4
>> DHCP client bound to address 10.0.4.191 (4603 ms)
>> Using mac@e010 device
>> TFTP from server 255.255.255.255; our IP address is 10.0.4.191;
>
> This broadcast address is clearly not right. It should have been what
> you had in the dhcp command. That should be assigned in net/tftp.c:
> 757...
>
>>> tftp_remote_ip = string_to_ip(net_boot_file_name);
>
> So 

Re: [U-Boot] [PATCH 1/2] net: Add option to prefer bootp/dhcp serverip

2018-06-12 Thread Joe Hershberger
On Wed, Jun 6, 2018 at 8:54 PM, Rick Chen  wrote:
>> From: Alexander Graf [mailto:ag...@suse.de]
>> Sent: Wednesday, June 06, 2018 8:32 PM
>> To: u-boot@lists.denx.de
>> Cc: Rick Jian-Zhi Chen(陳建志); Joe Hershberger; Simon Glass
>> Subject: [PATCH 1/2] net: Add option to prefer bootp/dhcp serverip
>>
>> Currently we can choose between 2 different types of behavior for the 
>> serverip
>> variable:
>>
>>   1) Always overwrite it with the DHCP server IP address (default)
>>   2) Ignore what the DHCP server says (CONFIG_BOOTP_SERVERIP)
>>
>> This patch adds a 3rd option:
>>
>>   3) Use serverip from DHCP if no serverip is given
>>  (CONFIG_BOOTP_PREFER_SERVERIP)
>>
>> With this new option, we can have the default case that a boot file gets 
>> loaded
>> from the DHCP provided TFTP server work while allowing users to specify their
>> own serverip variable to explicitly use a different tftp server.
>>
>> Signed-off-by: Alexander Graf 
>> ---
>>  README  | 5 +
>>  cmd/Kconfig | 9 +
>>  net/bootp.c | 7 ++-
>>  3 files changed, 20 insertions(+), 1 deletion(-)
>>
>> diff --git a/README b/README
>> index fb331f910d..d8a99281ca 100644
>> --- a/README
>> +++ b/README
>> @@ -1511,10 +1511,15 @@ The following options need to be configured:
>>   CONFIG_BOOTP_TIMEOFFSET
>>   CONFIG_BOOTP_VENDOREX
>>   CONFIG_BOOTP_MAY_FAIL
>> + CONFIG_BOOTP_PREFER_SERVERIP
>>
>>   CONFIG_BOOTP_SERVERIP - TFTP server will be the serverip
>>   environment variable, not the BOOTP server.
>>
>> + CONFIG_BOOTP_PREFER_SERVERIP - TFTP server will be the
>> + serverip environment variable if previously unset, otherwise
>> + the DHCP provided serverip is used.
>> +
>>   CONFIG_BOOTP_MAY_FAIL - If the DHCP server is not found
>>   after the configured retry count, the call will fail
>>   instead of starting over.  This can be used to fail over diff 
>> --git
>> a/cmd/Kconfig b/cmd/Kconfig index e283cb9a8a..e77a4131b3 100644
>> --- a/cmd/Kconfig
>> +++ b/cmd/Kconfig
>> @@ -1121,6 +1121,15 @@ config BOOTP_HOSTNAME
>>   help
>> The name may or may not be qualified with the local domain name.
>>
>> +config BOOTP_PREFER_SERVERIP
>> + bool "Leave serverip variable in place if existing"
>> + default n
>> + depends on CMD_BOOTP
>> + help
>> +   By default a BOOTP/DHCP reply will overwrite the tftp target ip
>> +   address. With this option enabled, it will leave it alone if
>> +   already specified, but populate it if no serverip is specified.
>> +
>>  config BOOTP_SUBNETMASK
>>   bool "Request & store 'netmask' from BOOTP/DHCP server"
>>   default y
>> diff --git a/net/bootp.c b/net/bootp.c
>> index 9d7cb5d30c..91de4cd426 100644
>> --- a/net/bootp.c
>> +++ b/net/bootp.c
>> @@ -147,9 +147,14 @@ static void store_net_params(struct bootp_hdr *bp)
>> {  #if !defined(CONFIG_BOOTP_SERVERIP)
>>   struct in_addr tmp_ip;
>> + bool overwrite_serverip = true;
>> +
>> +#if defined(CONFIG_BOOTP_PREFER_SERVERIP)
>> + overwrite_serverip = false;
>> +#endif
>>
>>   net_copy_ip(_ip, >bp_siaddr);
>> - if (tmp_ip.s_addr != 0)
>> + if (tmp_ip.s_addr != 0 && (overwrite_serverip ||
>> +!net_server_ip.s_addr))
>>   net_copy_ip(_server_ip, >bp_siaddr);
>>   memcpy(net_server_ethaddr,
>>  ((struct ethernet_hdr *)net_rx_packet)->et_src, 6);
>> --
>> 2.12.3
>
> Hi Alex
>
> I have apply those two patchs and verify
> U-Boot-1-2-net-Add-option-to-prefer-bootp-dhcp-serverip.patch
> U-Boot-2-2-ax25-Switch-to-CONFIG_BOOTP_PREFER_SERVERIP.patch
>
> But it still fail in dhcp command as below
>
> case 1
> serverip is null
>
> RISC-V # set serverip
> RISC-V # env print
> baudrate=38400
> bootcmd=fatload mmc 0:1 0x2000 ae350_64.dtb;fatload mmc 0:1 0x0
> bbl-ae350.bin;go 0x0
> bootdelay=3
> bootfile=pxelinux.0
> ethact=mac@e010
> fdtcontroladdr=3fedf290
> fileaddr=60
> filesize=1bb7d34
> stderr=serial@f030
> stdin=serial@f030
> stdout=serial@f030
>
> Environment size: 304/8188 bytes
> RISC-V # dhcp 0x60 10.0.4.97:boomimage-310y-ag101p.bin

You are explicitly setting the server IP in the DHCP command line, so
why would you expect the DHCP server IP to be used?

> BOOTP broadcast 1
> BOOTP broadcast 2
> BOOTP broadcast 3
> BOOTP broadcast 4
> DHCP client bound to address 10.0.4.191 (4603 ms)
> Using mac@e010 device
> TFTP from server 255.255.255.255; our IP address is 10.0.4.191;

This broadcast address is clearly not right. It should have been what
you had in the dhcp command. That should be assigned in net/tftp.c:
757...

>> tftp_remote_ip = string_to_ip(net_boot_file_name);

So something must be wrong with that somehow.

> sending through gateway 10.0.4.254
> Filename 'pxelinux.0'.

Why is this filename still set? That's from the environment and is set
by a env callback 

Re: [U-Boot] [PATCH 1/2] net: Add option to prefer bootp/dhcp serverip

2018-06-12 Thread Joe Hershberger
On Wed, Jun 6, 2018 at 7:32 AM, Alexander Graf  wrote:
> Currently we can choose between 2 different types of behavior for the
> serverip variable:
>
>   1) Always overwrite it with the DHCP server IP address (default)
>   2) Ignore what the DHCP server says (CONFIG_BOOTP_SERVERIP)
>
> This patch adds a 3rd option:
>
>   3) Use serverip from DHCP if no serverip is given
>  (CONFIG_BOOTP_PREFER_SERVERIP)
>
> With this new option, we can have the default case that a boot file gets
> loaded from the DHCP provided TFTP server work while allowing users to
> specify their own serverip variable to explicitly use a different tftp
> server.
>
> Signed-off-by: Alexander Graf 
> ---
>  README  | 5 +
>  cmd/Kconfig | 9 +
>  net/bootp.c | 7 ++-
>  3 files changed, 20 insertions(+), 1 deletion(-)
>
> diff --git a/README b/README
> index fb331f910d..d8a99281ca 100644
> --- a/README
> +++ b/README
> @@ -1511,10 +1511,15 @@ The following options need to be configured:
> CONFIG_BOOTP_TIMEOFFSET
> CONFIG_BOOTP_VENDOREX
> CONFIG_BOOTP_MAY_FAIL
> +   CONFIG_BOOTP_PREFER_SERVERIP
>
> CONFIG_BOOTP_SERVERIP - TFTP server will be the serverip
> environment variable, not the BOOTP server.
>
> +   CONFIG_BOOTP_PREFER_SERVERIP - TFTP server will be the
> +   serverip environment variable if previously unset, otherwise

I think you mean "previously set" here.

Also, I don't think we are putting descriptions in the README if the
help is already in the Kconfig. Right, Tom?

> +   the DHCP provided serverip is used.
> +
> CONFIG_BOOTP_MAY_FAIL - If the DHCP server is not found
> after the configured retry count, the call will fail
> instead of starting over.  This can be used to fail over
> diff --git a/cmd/Kconfig b/cmd/Kconfig
> index e283cb9a8a..e77a4131b3 100644
> --- a/cmd/Kconfig
> +++ b/cmd/Kconfig
> @@ -1121,6 +1121,15 @@ config BOOTP_HOSTNAME
> help
>   The name may or may not be qualified with the local domain name.
>
> +config BOOTP_PREFER_SERVERIP
> +   bool "Leave serverip variable in place if existing"

I think this would be clearer if it were "serverip variable in the
environment takes precedent over DHCP server IP."

> +   default n
> +   depends on CMD_BOOTP
> +   help
> + By default a BOOTP/DHCP reply will overwrite the tftp target ip

Use the actual variable name here... "serverip"

> + address. With this option enabled, it will leave it alone if

Too many "it"s.

"With this option enabled, the 'serverip' variable in the environment
takes precedence over DHCP server IP and will only be set by the DHCP
server if not already set in the environment."

> + already specified, but populate it if no serverip is specified.
> +
>  config BOOTP_SUBNETMASK
> bool "Request & store 'netmask' from BOOTP/DHCP server"
> default y
> diff --git a/net/bootp.c b/net/bootp.c
> index 9d7cb5d30c..91de4cd426 100644
> --- a/net/bootp.c
> +++ b/net/bootp.c
> @@ -147,9 +147,14 @@ static void store_net_params(struct bootp_hdr *bp)
>  {
>  #if !defined(CONFIG_BOOTP_SERVERIP)
> struct in_addr tmp_ip;
> +   bool overwrite_serverip = true;
> +
> +#if defined(CONFIG_BOOTP_PREFER_SERVERIP)
> +   overwrite_serverip = false;
> +#endif
>
> net_copy_ip(_ip, >bp_siaddr);
> -   if (tmp_ip.s_addr != 0)
> +   if (tmp_ip.s_addr != 0 && (overwrite_serverip || 
> !net_server_ip.s_addr))
> net_copy_ip(_server_ip, >bp_siaddr);
> memcpy(net_server_ethaddr,
>((struct ethernet_hdr *)net_rx_packet)->et_src, 6);
> --
> 2.12.3
>
> ___
> U-Boot mailing list
> U-Boot@lists.denx.de
> https://lists.denx.de/listinfo/u-boot
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH 1/2] net: Add option to prefer bootp/dhcp serverip

2018-06-06 Thread Rick Chen
> From: Alexander Graf [mailto:ag...@suse.de]
> Sent: Wednesday, June 06, 2018 8:32 PM
> To: u-boot@lists.denx.de
> Cc: Rick Jian-Zhi Chen(陳建志); Joe Hershberger; Simon Glass
> Subject: [PATCH 1/2] net: Add option to prefer bootp/dhcp serverip
>
> Currently we can choose between 2 different types of behavior for the serverip
> variable:
>
>   1) Always overwrite it with the DHCP server IP address (default)
>   2) Ignore what the DHCP server says (CONFIG_BOOTP_SERVERIP)
>
> This patch adds a 3rd option:
>
>   3) Use serverip from DHCP if no serverip is given
>  (CONFIG_BOOTP_PREFER_SERVERIP)
>
> With this new option, we can have the default case that a boot file gets 
> loaded
> from the DHCP provided TFTP server work while allowing users to specify their
> own serverip variable to explicitly use a different tftp server.
>
> Signed-off-by: Alexander Graf 
> ---
>  README  | 5 +
>  cmd/Kconfig | 9 +
>  net/bootp.c | 7 ++-
>  3 files changed, 20 insertions(+), 1 deletion(-)
>
> diff --git a/README b/README
> index fb331f910d..d8a99281ca 100644
> --- a/README
> +++ b/README
> @@ -1511,10 +1511,15 @@ The following options need to be configured:
>   CONFIG_BOOTP_TIMEOFFSET
>   CONFIG_BOOTP_VENDOREX
>   CONFIG_BOOTP_MAY_FAIL
> + CONFIG_BOOTP_PREFER_SERVERIP
>
>   CONFIG_BOOTP_SERVERIP - TFTP server will be the serverip
>   environment variable, not the BOOTP server.
>
> + CONFIG_BOOTP_PREFER_SERVERIP - TFTP server will be the
> + serverip environment variable if previously unset, otherwise
> + the DHCP provided serverip is used.
> +
>   CONFIG_BOOTP_MAY_FAIL - If the DHCP server is not found
>   after the configured retry count, the call will fail
>   instead of starting over.  This can be used to fail over diff 
> --git
> a/cmd/Kconfig b/cmd/Kconfig index e283cb9a8a..e77a4131b3 100644
> --- a/cmd/Kconfig
> +++ b/cmd/Kconfig
> @@ -1121,6 +1121,15 @@ config BOOTP_HOSTNAME
>   help
> The name may or may not be qualified with the local domain name.
>
> +config BOOTP_PREFER_SERVERIP
> + bool "Leave serverip variable in place if existing"
> + default n
> + depends on CMD_BOOTP
> + help
> +   By default a BOOTP/DHCP reply will overwrite the tftp target ip
> +   address. With this option enabled, it will leave it alone if
> +   already specified, but populate it if no serverip is specified.
> +
>  config BOOTP_SUBNETMASK
>   bool "Request & store 'netmask' from BOOTP/DHCP server"
>   default y
> diff --git a/net/bootp.c b/net/bootp.c
> index 9d7cb5d30c..91de4cd426 100644
> --- a/net/bootp.c
> +++ b/net/bootp.c
> @@ -147,9 +147,14 @@ static void store_net_params(struct bootp_hdr *bp)
> {  #if !defined(CONFIG_BOOTP_SERVERIP)
>   struct in_addr tmp_ip;
> + bool overwrite_serverip = true;
> +
> +#if defined(CONFIG_BOOTP_PREFER_SERVERIP)
> + overwrite_serverip = false;
> +#endif
>
>   net_copy_ip(_ip, >bp_siaddr);
> - if (tmp_ip.s_addr != 0)
> + if (tmp_ip.s_addr != 0 && (overwrite_serverip ||
> +!net_server_ip.s_addr))
>   net_copy_ip(_server_ip, >bp_siaddr);
>   memcpy(net_server_ethaddr,
>  ((struct ethernet_hdr *)net_rx_packet)->et_src, 6);
> --
> 2.12.3

Hi Alex

I have apply those two patchs and verify
U-Boot-1-2-net-Add-option-to-prefer-bootp-dhcp-serverip.patch
U-Boot-2-2-ax25-Switch-to-CONFIG_BOOTP_PREFER_SERVERIP.patch

But it still fail in dhcp command as below

case 1
serverip is null

RISC-V # set serverip
RISC-V # env print
baudrate=38400
bootcmd=fatload mmc 0:1 0x2000 ae350_64.dtb;fatload mmc 0:1 0x0
bbl-ae350.bin;go 0x0
bootdelay=3
bootfile=pxelinux.0
ethact=mac@e010
fdtcontroladdr=3fedf290
fileaddr=60
filesize=1bb7d34
stderr=serial@f030
stdin=serial@f030
stdout=serial@f030

Environment size: 304/8188 bytes
RISC-V # dhcp 0x60 10.0.4.97:boomimage-310y-ag101p.bin
BOOTP broadcast 1
BOOTP broadcast 2
BOOTP broadcast 3
BOOTP broadcast 4
DHCP client bound to address 10.0.4.191 (4603 ms)
Using mac@e010 device
TFTP from server 255.255.255.255; our IP address is 10.0.4.191;
sending through gateway 10.0.4.254
Filename 'pxelinux.0'.
Load address: 0x60
Loading: *
TFTP error: 'File not found' (1)
Not retrying...

TFTP error: 'File not found' (1)
Not retrying...

case 2
serverip has value

RISC-V # setenv serverip 10.0.4.97 ;

RISC-V # dhcp 0x60 boomimage-310y-ag101p.bin
BOOTP broadcast 1
BOOTP broadcast 2
BOOTP broadcast 3
BOOTP broadcast 4
DHCP client bound to address 10.0.4.191 (4592 ms)
Using mac@e010 device
TFTP from server 10.0.4.97; our IP address is 10.0.4.191
Filename 'pxelinux.0'.
Load address: 0x60
Loading: *
TFTP error: 'File not found' (1)
Not retrying...

TFTP error: 'File not found' (1)
Not retrying...
RISC-V #



Rick
___
U-Boot mailing list