[U-Boot] [PATCH v5 4/5] OMAP: networking support for SPL

Joe Hershberger joe.hershberger at gmail.com
Wed Aug 29 23:25:57 CEST 2012


Hi Ilya,

On Tue, Aug 7, 2012 at 3:07 AM, Ilya Yanok
<ilya.yanok at cogentembedded.com> wrote:
> This patch adds support for networking in SPL. Some devices are
> capable of loading SPL via network so it makes sense to load the
> main U-Boot binary via network too. This patch tries to use
> existing network code as much as possible. Unfortunately, it depends
> on environment which in turn depends on other code so SPL size
> is increased significantly. No effort was done to decouple network
> code and environment so far.
>
> Signed-off-by: Ilya Yanok <ilya.yanok at cogentembedded.com>
>
> ---
> Changes in v3:
>  - use BOOTP in SPL regardless of CONFIG_CMD_DHCP
>  - add support for setting different VCI in SPL
>
> Changes in v4:
>  - fix compilation of SPL's libcommon with CONFIG_HUSH_PARSER
>    and CONFIG_BOOTD defined
>  - rename spl_eth.c to spl_net.c
>  - set ethact variable if device name is passed
>
> Changes in v5:
>  - set up guards in cmd_nvedit.c more carefully
>  - now we don't need command.c and only need main.c for
>    show_boot_progress() so defined it to be noop and remove
>    both files from SPL sources
>  - SPL guards in command.c and main.c are no longer needed
>  - add some guards in env_common.c
>  - qsort.c is no longer needed
>  - add guard to hashtable.c to save some space
>  - undefine unneeded CONFIG_CMD_* while building SPL to save space
>
>  arch/arm/cpu/armv7/omap-common/Makefile  |    3 ++
>  arch/arm/cpu/armv7/omap-common/spl.c     |    9 ++++++
>  arch/arm/cpu/armv7/omap-common/spl_net.c |   52 ++++++++++++++++++++++++++++++
>  arch/arm/include/asm/omap_common.h       |    4 +++
>  common/Makefile                          |    4 +++
>  common/cmd_nvedit.c                      |   11 ++++++-
>  common/command.c                         |    2 +-
>  common/env_common.c                      |    7 ++--
>  include/bootstage.h                      |    6 +++-
>  lib/Makefile                             |    9 ++++--
>  lib/hashtable.c                          |    2 ++
>  lib/vsprintf.c                           |    2 +-
>  net/bootp.c                              |   11 ++++++-
>  net/net.c                                |   13 ++++++++
>  net/tftp.c                               |    4 +++
>  spl/Makefile                             |    3 ++
>  16 files changed, 133 insertions(+), 9 deletions(-)
>  create mode 100644 arch/arm/cpu/armv7/omap-common/spl_net.c
>
> diff --git a/arch/arm/cpu/armv7/omap-common/Makefile b/arch/arm/cpu/armv7/omap-common/Makefile
> index d37b22d..f042078 100644
> --- a/arch/arm/cpu/armv7/omap-common/Makefile
> +++ b/arch/arm/cpu/armv7/omap-common/Makefile
> @@ -53,6 +53,9 @@ endif
>  ifdef CONFIG_SPL_YMODEM_SUPPORT
>  COBJS  += spl_ymodem.o
>  endif
> +ifdef CONFIG_SPL_NET_SUPPORT
> +COBJS  += spl_net.o
> +endif

Why not use common pattern of...

COBJS-$(CONFIG_SPL_NET_SUPPORT) += spl_net.o

COBJS   := $(sort $(COBJS-y))

>  endif
>
>  ifndef CONFIG_SPL_BUILD
> diff --git a/arch/arm/cpu/armv7/omap-common/spl.c b/arch/arm/cpu/armv7/omap-common/spl.c
> index f0d766c..53b9261 100644
> --- a/arch/arm/cpu/armv7/omap-common/spl.c
> +++ b/arch/arm/cpu/armv7/omap-common/spl.c
> @@ -178,6 +178,15 @@ void board_init_r(gd_t *id, ulong dummy)
>                 spl_ymodem_load_image();
>                 break;
>  #endif
> +#ifdef CONFIG_SPL_ETH_SUPPORT
> +       case BOOT_DEVICE_CPGMAC:
> +#ifdef CONFIG_SPL_ETH_DEVICE
> +               spl_net_load_image(CONFIG_SPL_ETH_DEVICE);
> +#else
> +               spl_net_load_image(NULL);
> +#endif
> +               break;
> +#endif
>         default:
>                 printf("SPL: Un-supported Boot Device - %d!!!\n", boot_device);
>                 hang();
> diff --git a/arch/arm/cpu/armv7/omap-common/spl_net.c b/arch/arm/cpu/armv7/omap-common/spl_net.c
> new file mode 100644
> index 0000000..cbb3087
> --- /dev/null
> +++ b/arch/arm/cpu/armv7/omap-common/spl_net.c
> @@ -0,0 +1,52 @@
> +/*
> + * (C) Copyright 2000-2004
> + * Wolfgang Denk, DENX Software Engineering, wd at denx.de.
> + *
> + * (C) Copyright 2012
> + * Ilya Yanok <ilya.yanok at gmail.com>
> + *
> + * See file CREDITS for list of people who contributed to this
> + * project.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; either version 2 of
> + * the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc.
> + */
> +#include <common.h>
> +#include <net.h>
> +#include <asm/omap_common.h>

What in here needs this header?

> +
> +DECLARE_GLOBAL_DATA_PTR;
> +
> +void spl_net_load_image(const char *device)
> +{
> +       int rv;
> +
> +       env_init();
> +       env_relocate();
> +       setenv("autoload", "yes");
> +       load_addr = CONFIG_SYS_TEXT_BASE - sizeof(struct image_header);
> +       rv = eth_initialize(gd->bd);
> +       if (rv == 0) {
> +               printf("No Ethernet devices found\n");
> +               hang();
> +       }
> +       if (device)
> +               setenv("ethact", device);
> +       rv = NetLoop(BOOTP);
> +       if (rv < 0) {
> +               printf("Problem booting with BOOTP\n");
> +               hang();
> +       }
> +       spl_parse_image_header((struct image_header *)load_addr);
> +}
> diff --git a/arch/arm/include/asm/omap_common.h b/arch/arm/include/asm/omap_common.h
> index 4e95eee..9b96527 100644
> --- a/arch/arm/include/asm/omap_common.h
> +++ b/arch/arm/include/asm/omap_common.h
> @@ -69,6 +69,7 @@ void preloader_console_init(void);
>  #define BOOT_DEVICE_MMC1       8
>  #define BOOT_DEVICE_MMC2       0
>  #define BOOT_DEVICE_UART       65
> +#define BOOT_DEVICE_CPGMAC     70
>  #define BOOT_DEVICE_MMC2_2      0xFF
>  #endif
>
> @@ -107,6 +108,9 @@ void spl_mmc_load_image(void);
>  /* YMODEM SPL functions */
>  void spl_ymodem_load_image(void);
>
> +/* Ethernet SPL functions */
> +void spl_net_load_image(const char *device);
> +
>  #ifdef CONFIG_SPL_BOARD_INIT
>  void spl_board_init(void);
>  #endif
> diff --git a/common/Makefile b/common/Makefile
> index 483eb4d..0a9f50c 100644
> --- a/common/Makefile
> +++ b/common/Makefile
> @@ -187,6 +187,10 @@ endif
>
>  ifdef CONFIG_SPL_BUILD
>  COBJS-$(CONFIG_SPL_YMODEM_SUPPORT) += xyzModem.o
> +COBJS-$(CONFIG_SPL_NET_SUPPORT) += cmd_nvedit.o
> +COBJS-$(CONFIG_SPL_NET_SUPPORT) += env_common.o
> +COBJS-$(CONFIG_SPL_NET_SUPPORT) += env_nowhere.o
> +COBJS-$(CONFIG_SPL_NET_SUPPORT) += miiphyutil.o
>  endif
>  COBJS-y += console.o
>  COBJS-y += dlmalloc.o
> diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
> index fd05e72..bc735e3 100644
> --- a/common/cmd_nvedit.c
> +++ b/common/cmd_nvedit.c
> @@ -103,6 +103,7 @@ int get_env_id(void)
>         return env_id;
>  }
>
> +#ifndef CONFIG_SPL_BUILD
>  /*
>   * Command interface: print one or all environment variables
>   *
> @@ -196,6 +197,7 @@ static int do_env_grep(cmd_tbl_t *cmdtp, int flag,
>         return rcode;
>  }
>  #endif
> +#endif /* CONFIG_SPL_BUILD */
>
>  /*
>   * Set a new environment variable,
> @@ -394,6 +396,7 @@ int setenv_addr(const char *varname, const void *addr)
>         return setenv(varname, str);
>  }
>
> +#ifndef CONFIG_SPL_BUILD
>  int do_env_set(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
>  {
>         if (argc < 2)
> @@ -493,6 +496,7 @@ int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
>         return setenv(argv[1], buffer);
>  }
>  #endif /* CONFIG_CMD_EDITENV */
> +#endif /* CONFIG_SPL_BUILD */
>
>  /*
>   * Look up variable from environment,
> @@ -578,6 +582,7 @@ ulong getenv_ulong(const char *name, int base, ulong default_val)
>         return str ? simple_strtoul(str, NULL, base) : default_val;
>  }
>
> +#ifndef CONFIG_SPL_BUILD
>  #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
>  int do_env_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
>  {
> @@ -592,6 +597,7 @@ U_BOOT_CMD(
>         ""
>  );
>  #endif
> +#endif /* CONFIG_SPL_BUILD */
>
>
>  /*
> @@ -613,6 +619,7 @@ int envmatch(uchar *s1, int i2)
>         return -1;
>  }
>
> +#ifndef CONFIG_SPL_BUILD
>  static int do_env_default(cmd_tbl_t *cmdtp, int flag,
>                           int argc, char * const argv[])
>  {
> @@ -912,7 +919,8 @@ static cmd_tbl_t cmd_env_sub[] = {
>  #if defined(CONFIG_CMD_RUN)
>         U_BOOT_CMD_MKENT(run, CONFIG_SYS_MAXARGS, 1, do_run, "", ""),
>  #endif
> -#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
> +#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE) && \
> +       !defined(CONFIG_SPL_BUILD)
>         U_BOOT_CMD_MKENT(save, 1, 0, do_env_save, "", ""),
>  #endif
>         U_BOOT_CMD_MKENT(set, CONFIG_SYS_MAXARGS, 0, do_env_set, "", ""),
> @@ -1038,3 +1046,4 @@ U_BOOT_CMD_COMPLETE(
>         var_complete
>  );
>  #endif
> +#endif /* CONFIG_SPL_BUILD */
> diff --git a/common/command.c b/common/command.c
> index aa0fb0a..9827c70 100644
> --- a/common/command.c
> +++ b/common/command.c
> @@ -526,7 +526,7 @@ enum command_ret_t cmd_process(int flag, int argc, char * const argv[],
>         if (argc > cmdtp->maxargs)
>                 rc = CMD_RET_USAGE;
>
> -#if defined(CONFIG_CMD_BOOTD)
> +#ifdef CONFIG_CMD_BOOTD

Unrelated style change.

>         /* avoid "bootd" recursion */
>         else if (cmdtp->cmd == do_bootd) {
>                 if (flag & CMD_FLAG_BOOTD) {
> diff --git a/common/env_common.c b/common/env_common.c
> index d9e990d..fdd40b0 100644
> --- a/common/env_common.c
> +++ b/common/env_common.c
> @@ -199,6 +199,7 @@ void set_default_env(const char *s)
>         gd->flags |= GD_FLG_ENV_READY;
>  }
>
> +#ifndef CONFIG_SPL_BUILD
>  /*
>   * Check if CRC is valid and (if yes) import the environment.
>   * Note that "buf" may or may not be aligned.
> @@ -229,6 +230,7 @@ int env_import(const char *buf, int check)
>
>         return 0;
>  }
> +#endif
>
>  void env_relocate(void)
>  {
> @@ -236,7 +238,8 @@ void env_relocate(void)
>         env_reloc();
>  #endif
>         if (gd->env_valid == 0) {
> -#if defined(CONFIG_ENV_IS_NOWHERE)     /* Environment not changable */
> +#if defined(CONFIG_ENV_IS_NOWHERE) || defined(CONFIG_SPL_BUILD)
> +               /* Environment not changable */
>                 set_default_env(NULL);
>  #else
>                 bootstage_error(BOOTSTAGE_ID_NET_CHECKSUM);
> @@ -247,7 +250,7 @@ void env_relocate(void)
>         }
>  }
>
> -#ifdef CONFIG_AUTO_COMPLETE
> +#if defined(CONFIG_AUTO_COMPLETE) && !defined(CONFIG_SPL_BUILD)
>  int env_complete(char *var, int maxv, char *cmdv[], int bufsz, char *buf)
>  {
>         ENTRY *match;
> diff --git a/include/bootstage.h b/include/bootstage.h
> index a000538..db94a95 100644
> --- a/include/bootstage.h
> +++ b/include/bootstage.h
> @@ -210,6 +210,7 @@ enum bootstage_id {
>   */
>  ulong timer_get_boot_us(void);
>
> +#ifndef CONFIG_SPL_BUILD
>  /*
>   * Board code can implement show_boot_progress() if needed.
>   *
> @@ -217,8 +218,11 @@ ulong timer_get_boot_us(void);
>   *             has occurred.
>   */
>  void show_boot_progress(int val);
> +#else
> +#define show_boot_progress(val) do {} while (0)
> +#endif
>
> -#ifdef CONFIG_BOOTSTAGE
> +#if defined(CONFIG_BOOTSTAGE) && !defined(CONFIG_SPL_BUILD)
>  /* This is the full bootstage implementation */
>
>  /*
> diff --git a/lib/Makefile b/lib/Makefile
> index c60c380..ee10738 100644
> --- a/lib/Makefile
> +++ b/lib/Makefile
> @@ -52,12 +52,17 @@ COBJS-$(CONFIG_SHA1) += sha1.o
>  COBJS-$(CONFIG_SHA256) += sha256.o
>  COBJS-y        += strmhz.o
>  COBJS-$(CONFIG_RBTREE) += rbtree.o
> -else
> -COBJS-$(CONFIG_SPL_SPI_FLASH_SUPPORT) += display_options.o
>  endif
>
>  ifdef CONFIG_SPL_BUILD
>  COBJS-$(CONFIG_SPL_YMODEM_SUPPORT) += crc16.o
> +COBJS-$(CONFIG_SPL_NET_SUPPORT) += crc32.o
> +ifneq ($(CONFIG_SPL_SPI_FLASH_SUPPORT)$(CONFIG_SPL_NET_SUPPORT),)
> +COBJS-y += display_options.o
> +endif
> +COBJS-$(CONFIG_SPL_NET_SUPPORT) += errno.o
> +COBJS-$(CONFIG_SPL_NET_SUPPORT) += hashtable.o
> +COBJS-$(CONFIG_SPL_NET_SUPPORT) += net_utils.o
>  endif
>  COBJS-y += crc32.o
>  COBJS-y += ctype.o
> diff --git a/lib/hashtable.c b/lib/hashtable.c
> index abd61c8..755f8b3 100644
> --- a/lib/hashtable.c
> +++ b/lib/hashtable.c
> @@ -431,6 +431,7 @@ int hdelete_r(const char *key, struct hsearch_data *htab)
>   * hexport()
>   */
>
> +#ifndef CONFIG_SPL_BUILD
>  /*
>   * Export the data stored in the hash table in linearized form.
>   *
> @@ -597,6 +598,7 @@ ssize_t hexport_r(struct hsearch_data *htab, const char sep,
>
>         return size;
>  }
> +#endif
>
>
>  /*
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index e38a4b7..6bb819c 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -784,7 +784,7 @@ void panic(const char *fmt, ...)
>         vprintf(fmt, args);
>         putc('\n');
>         va_end(args);
> -#if defined (CONFIG_PANIC_HANG)
> +#if defined (CONFIG_PANIC_HANG) || defined(CONFIG_SPL_BUILD)
>         hang();
>  #else
>         udelay (100000);        /* allow messages to go out */
> diff --git a/net/bootp.c b/net/bootp.c
> index 35b2e77..e83e35f 100644
> --- a/net/bootp.c
> +++ b/net/bootp.c
> @@ -9,6 +9,10 @@
>   */
>
>  #include <common.h>
> +#ifdef CONFIG_SPL_BUILD
> +#undef CONFIG_CMD_DHCP
> +#undef CONFIG_CMD_SNTP
> +#endif
>  #include <command.h>
>  #include <net.h>
>  #include "bootp.h"
> @@ -535,8 +539,13 @@ static int BootpExtended(u8 *e)
>         *e++ = (576 - 312 + OPT_FIELD_SIZE) & 0xff;
>  #endif
>
> -#ifdef CONFIG_BOOTP_VCI_STRING
> +#if defined(CONFIG_BOOTP_VCI_STRING) || \
> +       (defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_NET_VCI_STRING))
> +#ifndef CONFIG_SPL_BUILD

Don't use negative logic for no reason.

>         put_vci(e, CONFIG_VCI_STRING);
> +#else
> +       put_vci(e, CONFIG_SPL_NET_VCI_STRING);
> +#endif
>  #endif
>
>  #if defined(CONFIG_BOOTP_SUBNETMASK)
> diff --git a/net/net.c b/net/net.c
> index e8ff066..bbd1a6d 100644
> --- a/net/net.c
> +++ b/net/net.c
> @@ -81,6 +81,19 @@
>
>
>  #include <common.h>
> +#ifdef CONFIG_SPL_BUILD
> +/* SPL needs only BOOTP + TFTP so undefine other stuff to save space */
> +#undef CONFIG_CMD_DHCP
> +#undef CONFIG_CMD_CDP
> +#undef CONFIG_CMD_DNS
> +#undef CONFIG_CMD_LINK_LOCAL
> +#undef CONFIG_CMD_NFS
> +#undef CONFIG_CMD_PING
> +#undef CONFIG_CMD_RARP
> +#undef CONFIG_CMD_SNTP
> +#undef CONFIG_CMD_TFTPPUT
> +#undef CONFIG_CMD_TFTPSRV
> +#endif

Is this the best place to do this?  Seems it would be clearer to
modify config_cmd_default.h or add a config_cmd_spl.h that will
undefine them, and include that.

The other files will still be compiled.  Is this enough for them to be
garbage collected?  Guessing it prolly is.

>  #include <command.h>
>  #include <net.h>
>  #if defined(CONFIG_STATUS_LED)
> diff --git a/net/tftp.c b/net/tftp.c
> index b2e08b4..bbf48d9 100644
> --- a/net/tftp.c
> +++ b/net/tftp.c
> @@ -7,6 +7,10 @@
>   */
>
>  #include <common.h>
> +#ifdef CONFIG_SPL_BUILD
> +#undef CONFIG_CMD_TFTPPUT
> +#undef CONFIG_CMD_TFTPSRV
> +#endif

Same here.

>  #include <command.h>
>  #include <net.h>
>  #include "tftp.h"
> diff --git a/spl/Makefile b/spl/Makefile
> index ea7d475..925e84f 100644
> --- a/spl/Makefile
> +++ b/spl/Makefile
> @@ -57,6 +57,9 @@ LIBS-$(CONFIG_SPL_NAND_SUPPORT) += drivers/mtd/nand/libnand.o
>  LIBS-$(CONFIG_SPL_ONENAND_SUPPORT) += drivers/mtd/onenand/libonenand.o
>  LIBS-$(CONFIG_SPL_DMA_SUPPORT) += drivers/dma/libdma.o
>  LIBS-$(CONFIG_SPL_POST_MEM_SUPPORT) += post/drivers/memory.o
> +LIBS-$(CONFIG_SPL_NET_SUPPORT) += net/libnet.o
> +LIBS-$(CONFIG_SPL_ETH_SUPPORT) += drivers/net/libnet.o
> +LIBS-$(CONFIG_SPL_ETH_SUPPORT) += drivers/net/phy/libphy.o
>
>  ifneq ($(CONFIG_AM33XX)$(CONFIG_OMAP34XX)$(CONFIG_OMAP44XX)$(CONFIG_OMAP54XX),)
>  LIBS-y += $(CPUDIR)/omap-common/libomap-common.o
> --
> 1.7.9.5
>
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot


More information about the U-Boot mailing list