[U-Boot] [PATCH 4/5] Put common autoload code into AutoLoad() function

Wolfgang Denk wd at denx.de
Tue Apr 12 23:58:59 CEST 2011


Dear Simon Glass,

In message <1302642840-6958-4-git-send-email-sjg at chromium.org> you wrote:
> This is a small clean-up patch.
> 
> TEST=Build U-Boot, try bootp and check it auto-loads.
> 
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
>  net/bootp.c |   76 +++++++++++++++++++++++++---------------------------------
>  1 files changed, 33 insertions(+), 43 deletions(-)
> 
> diff --git a/net/bootp.c b/net/bootp.c
> index 1a71786..0ac1429 100644
> --- a/net/bootp.c
> +++ b/net/bootp.c
> @@ -137,6 +137,36 @@ static int truncate_sz (const char *name, int maxlen, int curlen)
>  	return (curlen);
>  }
>  
> +/*
> + * Check if autoload is enabled. If so, use either NFS or TFTP to download
> + * the boot file.
> + */
> +static void AutoLoad(void)

We don't allow for CamelCaps identifiers.


> +	char	*s;
> +
> +	if ((s = getenv("autoload")) != NULL) {
> +		if (*s == 'n') {
> +			/*
> +			 * Just use BOOTP to configure system;
> +			 * Do not use TFTP to load the bootfile.
> +			 */
> +			NetState = NETLOOP_SUCCESS;
> +			return;
> +#if defined(CONFIG_CMD_NFS)
> +		} else if (strcmp(s, "NFS") == 0) {
> +			/*
> +			 * Use NFS to load the bootfile.
> +			 */
> +			NfsStart();
> +			return;
> +#endif
> +		}
> +	}
> +
> +	TftpStart();
> +}
> +
>  #if !defined(CONFIG_CMD_DHCP)
>  
>  static void BootpVendorFieldProcess (u8 * ext)
> @@ -278,6 +308,7 @@ static void BootpVendorProcess (u8 * ext, int size)
>  	if (NetBootFileSize)
>  		debug("NetBootFileSize: %d\n", NetBootFileSize);
>  }
> +
>  /*
>   *	Handle a BOOTP received packet.
>   */
> @@ -285,7 +316,6 @@ static void
>  BootpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
>  {
>  	Bootp_t *bp;
> -	char	*s;
>  
>  	debug("got BOOTP packet (src=%d, dst=%d, len=%d want_len=%zu)\n",
>  		src, dest, len, sizeof (Bootp_t));
> @@ -312,26 +342,7 @@ BootpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
>  
>  	debug("Got good BOOTP\n");
>  
> -	if ((s = getenv("autoload")) != NULL) {
> -		if (*s == 'n') {
> -			/*
> -			 * Just use BOOTP to configure system;
> -			 * Do not use TFTP to load the bootfile.
> -			 */
> -			NetState = NETLOOP_SUCCESS;
> -			return;
> -#if defined(CONFIG_CMD_NFS)
> -		} else if (strcmp(s, "NFS") == 0) {
> -			/*
> -			 * Use NFS to load the bootfile.
> -			 */
> -			NfsStart();
> -			return;
> -#endif
> -		}
> -	}
> -
> -	TftpStart();
> +	AutoLoad();

Note that your change is NOT functionally equivalent - instead of
running the code BEFORE TftpStart(), and eventually short-cutting it
by the "return", you run it AFTER.


Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
The most difficult thing in the world is to know how to  do  a  thing
and to watch someone else doing it wrong, without commenting.
                                                        -- T.H. White


More information about the U-Boot mailing list