summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/Makefile10
-rw-r--r--common/cmd_bdinfo.c2
-rw-r--r--common/cmd_cache.c49
-rw-r--r--common/cmd_dfu.c2
-rw-r--r--common/cmd_echo.c28
-rw-r--r--common/cmd_elf.c192
-rw-r--r--common/cmd_ide.c3
-rw-r--r--common/cmd_ini.c275
-rw-r--r--common/cmd_md5sum.c142
-rw-r--r--common/cmd_misc.c27
-rw-r--r--common/cmd_nvedit.c21
-rw-r--r--common/cmd_sha1sum.c142
-rw-r--r--common/cmd_test.c6
-rw-r--r--common/cmd_usb.c16
-rw-r--r--common/env_common.c41
-rw-r--r--common/env_embedded.c40
-rw-r--r--common/fdt_support.c6
-rw-r--r--common/iomux.c2
-rw-r--r--common/main.c5
-rw-r--r--common/serial.c305
-rw-r--r--common/spl/Makefile1
-rw-r--r--common/spl/spl.c12
-rw-r--r--common/spl/spl_net.c52
-rw-r--r--common/stdio.c2
-rw-r--r--common/usb.c108
-rw-r--r--common/usb_hub.c2
-rw-r--r--common/usb_storage.c2
27 files changed, 935 insertions, 558 deletions
diff --git a/common/Makefile b/common/Makefile
index f3fc175..fdfead7 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -32,7 +32,6 @@ COBJS-y += command.o
COBJS-y += exports.o
COBJS-$(CONFIG_SYS_HUSH_PARSER) += hush.o
COBJS-y += s_record.o
-COBJS-$(CONFIG_SERIAL_MULTI) += serial.o
COBJS-y += xyzModem.o
COBJS-y += cmd_disk.o
@@ -108,6 +107,7 @@ COBJS-$(CONFIG_CMD_GPIO) += cmd_gpio.o
COBJS-$(CONFIG_CMD_I2C) += cmd_i2c.o
COBJS-$(CONFIG_CMD_IDE) += cmd_ide.o
COBJS-$(CONFIG_CMD_IMMAP) += cmd_immap.o
+COBJS-$(CONFIG_CMD_INI) += cmd_ini.o
COBJS-$(CONFIG_CMD_IRQ) += cmd_irq.o
COBJS-$(CONFIG_CMD_ITEST) += cmd_itest.o
COBJS-$(CONFIG_CMD_JFFS2) += cmd_jffs2.o
@@ -199,6 +199,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
@@ -228,6 +232,10 @@ $(obj)env_embedded.o: $(src)env_embedded.c $(obj)../tools/envcrc
$(obj)../tools/envcrc:
$(MAKE) -C ../tools
+# SEE README.arm-unaligned-accesses
+$(obj)hush.o: CFLAGS += $(PLATFORM_NO_UNALIGNED)
+$(obj)fdt_support.o: CFLAGS += $(PLATFORM_NO_UNALIGNED)
+
#########################################################################
# defines $(obj).depend target
diff --git a/common/cmd_bdinfo.c b/common/cmd_bdinfo.c
index 23bd8a5..286c8c8 100644
--- a/common/cmd_bdinfo.c
+++ b/common/cmd_bdinfo.c
@@ -51,7 +51,7 @@ static void print_eth(int idx)
}
__maybe_unused
-static void print_lnum(const char *name, u64 value)
+static void print_lnum(const char *name, unsigned long long value)
{
printf("%-12s= 0x%.8llX\n", name, value);
}
diff --git a/common/cmd_cache.c b/common/cmd_cache.c
index 9c228e2..5512f92 100644
--- a/common/cmd_cache.c
+++ b/common/cmd_cache.c
@@ -36,21 +36,24 @@ void __weak invalidate_icache_all(void)
puts("No arch specific invalidate_icache_all available!\n");
}
-int do_icache ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+int do_icache(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
switch (argc) {
case 2: /* on / off */
switch (parse_argv(argv[1])) {
- case 0: icache_disable();
+ case 0:
+ icache_disable();
break;
- case 1: icache_enable ();
+ case 1:
+ icache_enable();
break;
- case 2: invalidate_icache_all();
+ case 2:
+ invalidate_icache_all();
break;
}
- /* FALL TROUGH */
+ break;
case 1: /* get status */
- printf ("Instruction Cache is %s\n",
+ printf("Instruction Cache is %s\n",
icache_status() ? "ON" : "OFF");
return 0;
default:
@@ -65,40 +68,42 @@ void __weak flush_dcache_all(void)
/* please define arch specific flush_dcache_all */
}
-int do_dcache ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+int do_dcache(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
switch (argc) {
- case 2: /* on / off */
+ case 2: /* on / off */
switch (parse_argv(argv[1])) {
- case 0: dcache_disable();
+ case 0:
+ dcache_disable();
break;
- case 1: dcache_enable ();
+ case 1:
+ dcache_enable();
break;
- case 2: flush_dcache_all();
+ case 2:
+ flush_dcache_all();
break;
}
- /* FALL TROUGH */
+ break;
case 1: /* get status */
- printf ("Data (writethrough) Cache is %s\n",
+ printf("Data (writethrough) Cache is %s\n",
dcache_status() ? "ON" : "OFF");
return 0;
default:
return CMD_RET_USAGE;
}
return 0;
-
}
static int parse_argv(const char *s)
{
- if (strcmp(s, "flush") == 0) {
- return (2);
- } else if (strcmp(s, "on") == 0) {
- return (1);
- } else if (strcmp(s, "off") == 0) {
- return (0);
- }
- return (-1);
+ if (strcmp(s, "flush") == 0)
+ return 2;
+ else if (strcmp(s, "on") == 0)
+ return 1;
+ else if (strcmp(s, "off") == 0)
+ return 0;
+
+ return -1;
}
diff --git a/common/cmd_dfu.c b/common/cmd_dfu.c
index 62fb890..01d6b3a 100644
--- a/common/cmd_dfu.c
+++ b/common/cmd_dfu.c
@@ -30,7 +30,7 @@
static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
const char *str_env;
- char s[] = "dfu";
+ char *s = "dfu";
char *env_bkp;
int ret;
diff --git a/common/cmd_echo.c b/common/cmd_echo.c
index 43a6da5..1e499fb 100644
--- a/common/cmd_echo.c
+++ b/common/cmd_echo.c
@@ -30,17 +30,31 @@ int do_echo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
int putnl = 1;
for (i = 1; i < argc; i++) {
- char *p = argv[i], c;
+ char *p = argv[i];
+ char *nls; /* new-line suppression */
if (i > 1)
putc(' ');
- while ((c = *p++) != '\0') {
- if (c == '\\' && *p == 'c') {
- putnl = 0;
- p++;
- } else {
- putc(c);
+
+ nls = strstr(p, "\\c");
+ if (nls) {
+ char *prenls = p;
+
+ putnl = 0;
+ /*
+ * be paranoid and guess that someone might
+ * say \c more than once
+ */
+ while (nls) {
+ *nls = '\0';
+ puts(prenls);
+ *nls = '\\';
+ prenls = nls + 2;
+ nls = strstr(prenls, "\\c");
}
+ puts(prenls);
+ } else {
+ puts(p);
}
}
diff --git a/common/cmd_elf.c b/common/cmd_elf.c
index 8266bba..a667a46 100644
--- a/common/cmd_elf.c
+++ b/common/cmd_elf.c
@@ -24,13 +24,12 @@
DECLARE_GLOBAL_DATA_PTR;
#endif
-int valid_elf_image (unsigned long addr);
static unsigned long load_elf_image_phdr(unsigned long addr);
static unsigned long load_elf_image_shdr(unsigned long addr);
/* Allow ports to override the default behavior */
__attribute__((weak))
-unsigned long do_bootelf_exec (ulong (*entry)(int, char * const[]),
+unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]),
int argc, char * const argv[])
{
unsigned long ret;
@@ -39,26 +38,59 @@ unsigned long do_bootelf_exec (ulong (*entry)(int, char * const[]),
* QNX images require the data cache is disabled.
* Data cache is already flushed, so just turn it off.
*/
- int dcache = dcache_status ();
+ int dcache = dcache_status();
if (dcache)
- dcache_disable ();
+ dcache_disable();
/*
* pass address parameter as argv[0] (aka command name),
* and all remaining args
*/
- ret = entry (argc, argv);
+ ret = entry(argc, argv);
if (dcache)
- dcache_enable ();
+ dcache_enable();
return ret;
}
/* ======================================================================
+ * Determine if a valid ELF image exists at the given memory location.
+ * First looks at the ELF header magic field, the makes sure that it is
+ * executable and makes sure that it is for a PowerPC.
+ * ====================================================================== */
+int valid_elf_image(unsigned long addr)
+{
+ Elf32_Ehdr *ehdr; /* Elf header structure pointer */
+
+ /* -------------------------------------------------- */
+
+ ehdr = (Elf32_Ehdr *) addr;
+
+ if (!IS_ELF(*ehdr)) {
+ printf("## No elf image at address 0x%08lx\n", addr);
+ return 0;
+ }
+
+ if (ehdr->e_type != ET_EXEC) {
+ printf("## Not a 32-bit elf image at address 0x%08lx\n", addr);
+ return 0;
+ }
+
+#if 0
+ if (ehdr->e_machine != EM_PPC) {
+ printf("## Not a PowerPC elf image at address 0x%08lx\n", addr);
+ return 0;
+ }
+#endif
+
+ return 1;
+}
+
+/* ======================================================================
* Interpreter command to boot an arbitrary ELF image from memory.
* ====================================================================== */
-int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+int do_bootelf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
unsigned long addr; /* Address of the ELF image */
unsigned long rc; /* Return value from user code */
@@ -83,7 +115,7 @@ int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
else
addr = load_addr;
- if (!valid_elf_image (addr))
+ if (!valid_elf_image(addr))
return 1;
if (sload && sload[1] == 'p')
@@ -91,17 +123,17 @@ int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
else
addr = load_elf_image_shdr(addr);
- printf ("## Starting application at 0x%08lx ...\n", addr);
+ printf("## Starting application at 0x%08lx ...\n", addr);
/*
* pass address parameter as argv[0] (aka command name),
* and all remaining args
*/
- rc = do_bootelf_exec ((void *)addr, argc - 1, argv + 1);
+ rc = do_bootelf_exec((void *)addr, argc - 1, argv + 1);
if (rc != 0)
rcode = 1;
- printf ("## Application terminated, rc = 0x%lx\n", rc);
+ printf("## Application terminated, rc = 0x%lx\n", rc);
return rcode;
}
@@ -110,10 +142,10 @@ int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
* be either an ELF image or a raw binary. Will attempt to setup the
* bootline and other parameters correctly.
* ====================================================================== */
-int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
unsigned long addr; /* Address of image */
- unsigned long bootaddr; /* Address to put the bootline */
+ unsigned long bootaddr; /* Address to put the bootline */
char *bootline; /* Text of the bootline */
char *tmp; /* Temporary char pointer */
char build_buf[128]; /* Buffer for building the bootline */
@@ -127,16 +159,17 @@ int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
if (argc < 2)
addr = load_addr;
else
- addr = simple_strtoul (argv[1], NULL, 16);
+ addr = simple_strtoul(argv[1], NULL, 16);
#if defined(CONFIG_CMD_NET)
- /* Check to see if we need to tftp the image ourselves before starting */
-
- if ((argc == 2) && (strcmp (argv[1], "tftp") == 0)) {
+ /*
+ * Check to see if we need to tftp the image ourselves before starting
+ */
+ if ((argc == 2) && (strcmp(argv[1], "tftp") == 0)) {
if (NetLoop(TFTPGET) <= 0)
return 1;
- printf("Automatic boot of VxWorks image at address 0x%08lx "
- "...\n", addr);
+ printf("Automatic boot of VxWorks image at address 0x%08lx ...\n",
+ addr);
}
#endif
@@ -155,7 +188,7 @@ int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
eth_getenv_enetaddr("ethaddr", (uchar *)build_buf);
memcpy(tmp, build_buf, 6);
#else
- puts ("## Ethernet MAC address not copied to NV RAM\n");
+ puts("## Ethernet MAC address not copied to NV RAM\n");
#endif
/*
@@ -164,53 +197,52 @@ int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
* PowerPC is LOCAL_MEM_LOCAL_ADRS + BOOT_LINE_OFFSET which
* defaults to 0x4200
*/
-
- if ((tmp = getenv ("bootaddr")) == NULL)
+ tmp = getenv("bootaddr");
+ if (tmp)
bootaddr = CONFIG_SYS_VXWORKS_BOOT_ADDR;
else
- bootaddr = simple_strtoul (tmp, NULL, 16);
+ bootaddr = simple_strtoul(tmp, NULL, 16);
/*
* Check to see if the bootline is defined in the 'bootargs'
* parameter. If it is not defined, we may be able to
* construct the info
*/
-
- if ((bootline = getenv ("bootargs")) != NULL) {
- memcpy ((void *) bootaddr, bootline,
- max (strlen (bootline), 255));
- flush_cache (bootaddr, max (strlen (bootline), 255));
+ bootline = getenv("bootargs");
+ if (bootline) {
+ memcpy((void *) bootaddr, bootline,
+ max(strlen(bootline), 255));
+ flush_cache(bootaddr, max(strlen(bootline), 255));
} else {
-
-
- sprintf (build_buf, CONFIG_SYS_VXWORKS_BOOT_DEVICE);
- if ((tmp = getenv ("bootfile")) != NULL) {
- sprintf (&build_buf[strlen (build_buf)],
+ sprintf(build_buf, CONFIG_SYS_VXWORKS_BOOT_DEVICE);
+ tmp = getenv("bootfile");
+ if (tmp)
+ sprintf(&build_buf[strlen(build_buf)],
"%s:%s ", CONFIG_SYS_VXWORKS_SERVERNAME, tmp);
- } else {
- sprintf (&build_buf[strlen (build_buf)],
+ else
+ sprintf(&build_buf[strlen(build_buf)],
"%s:file ", CONFIG_SYS_VXWORKS_SERVERNAME);
- }
- if ((tmp = getenv ("ipaddr")) != NULL) {
- sprintf (&build_buf[strlen (build_buf)], "e=%s ", tmp);
- }
+ tmp = getenv("ipaddr");
+ if (tmp)
+ sprintf(&build_buf[strlen(build_buf)], "e=%s ", tmp);
- if ((tmp = getenv ("serverip")) != NULL) {
- sprintf (&build_buf[strlen (build_buf)], "h=%s ", tmp);
- }
+ tmp = getenv("serverip");
+ if (tmp)
+ sprintf(&build_buf[strlen(build_buf)], "h=%s ", tmp);
+
+ tmp = getenv("hostname");
+ if (tmp)
+ sprintf(&build_buf[strlen(build_buf)], "tn=%s ", tmp);
- if ((tmp = getenv ("hostname")) != NULL) {
- sprintf (&build_buf[strlen (build_buf)], "tn=%s ", tmp);
- }
#ifdef CONFIG_SYS_VXWORKS_ADD_PARAMS
- sprintf (&build_buf[strlen (build_buf)],
+ sprintf(&build_buf[strlen(build_buf)],
CONFIG_SYS_VXWORKS_ADD_PARAMS);
#endif
- memcpy ((void *) bootaddr, build_buf,
- max (strlen (build_buf), 255));
- flush_cache (bootaddr, max (strlen (build_buf), 255));
+ memcpy((void *) bootaddr, build_buf,
+ max(strlen(build_buf), 255));
+ flush_cache(bootaddr, max(strlen(build_buf), 255));
}
/*
@@ -219,55 +251,21 @@ int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
* binary image
*/
- if (valid_elf_image (addr)) {
- addr = load_elf_image_shdr (addr);
+ if (valid_elf_image(addr)) {
+ addr = load_elf_image_shdr(addr);
} else {
- puts ("## Not an ELF image, assuming binary\n");
+ puts("## Not an ELF image, assuming binary\n");
/* leave addr as load_addr */
}
- printf ("## Using bootline (@ 0x%lx): %s\n", bootaddr,
+ printf("## Using bootline (@ 0x%lx): %s\n", bootaddr,
(char *) bootaddr);
- printf ("## Starting vxWorks at 0x%08lx ...\n", addr);
+ printf("## Starting vxWorks at 0x%08lx ...\n", addr);
dcache_disable();
((void (*)(int)) addr) (0);
- puts ("## vxWorks terminated\n");
- return 1;
-}
-
-/* ======================================================================
- * Determine if a valid ELF image exists at the given memory location.
- * First looks at the ELF header magic field, the makes sure that it is
- * executable and makes sure that it is for a PowerPC.
- * ====================================================================== */
-int valid_elf_image (unsigned long addr)
-{
- Elf32_Ehdr *ehdr; /* Elf header structure pointer */
-
- /* -------------------------------------------------- */
-
- ehdr = (Elf32_Ehdr *) addr;
-
- if (!IS_ELF (*ehdr)) {
- printf ("## No elf image at address 0x%08lx\n", addr);
- return 0;
- }
-
- if (ehdr->e_type != ET_EXEC) {
- printf ("## Not a 32-bit elf image at address 0x%08lx\n", addr);
- return 0;
- }
-
-#if 0
- if (ehdr->e_machine != EM_PPC) {
- printf ("## Not a PowerPC elf image at address 0x%08lx\n",
- addr);
- return 0;
- }
-#endif
-
+ puts("## vxWorks terminated\n");
return 1;
}
@@ -286,14 +284,15 @@ static unsigned long load_elf_image_phdr(unsigned long addr)
/* Load each program header */
for (i = 0; i < ehdr->e_phnum; ++i) {
- void *dst = (void *) phdr->p_paddr;
+ void *dst = (void *)(uintptr_t) phdr->p_paddr;
void *src = (void *) addr + phdr->p_offset;
debug("Loading phdr %i to 0x%p (%i bytes)\n",
i, dst, phdr->p_filesz);
if (phdr->p_filesz)
memcpy(dst, src, phdr->p_filesz);
if (phdr->p_filesz != phdr->p_memsz)
- memset(dst + phdr->p_filesz, 0x00, phdr->p_memsz - phdr->p_filesz);
+ memset(dst + phdr->p_filesz, 0x00,
+ phdr->p_memsz - phdr->p_filesz);
flush_cache((unsigned long)dst, phdr->p_filesz);
++phdr;
}
@@ -315,7 +314,7 @@ static unsigned long load_elf_image_shdr(unsigned long addr)
/* Find the section header string table for output info */
shdr = (Elf32_Shdr *) (addr + ehdr->e_shoff +
- (ehdr->e_shstrndx * sizeof (Elf32_Shdr)));
+ (ehdr->e_shstrndx * sizeof(Elf32_Shdr)));
if (shdr->sh_type == SHT_STRTAB)
strtab = (unsigned char *) (addr + shdr->sh_offset);
@@ -323,7 +322,7 @@ static unsigned long load_elf_image_shdr(unsigned long addr)
/* Load each appropriate section */
for (i = 0; i < ehdr->e_shnum; ++i) {
shdr = (Elf32_Shdr *) (addr + ehdr->e_shoff +
- (i * sizeof (Elf32_Shdr)));
+ (i * sizeof(Elf32_Shdr)));
if (!(shdr->sh_flags & SHF_ALLOC)
|| shdr->sh_addr == 0 || shdr->sh_size == 0) {
@@ -340,14 +339,15 @@ static unsigned long load_elf_image_shdr(unsigned long addr)
}
if (shdr->sh_type == SHT_NOBITS) {
- memset ((void *)shdr->sh_addr, 0, shdr->sh_size);
+ memset((void *)(uintptr_t) shdr->sh_addr, 0,
+ shdr->sh_size);
} else {
image = (unsigned char *) addr + shdr->sh_offset;
- memcpy ((void *) shdr->sh_addr,
+ memcpy((void *)(uintptr_t) shdr->sh_addr,
(const void *) image,
shdr->sh_size);
}
- flush_cache (shdr->sh_addr, shdr->sh_size);
+ flush_cache(shdr->sh_addr, shdr->sh_size);
}
return ehdr->e_entry;
diff --git a/common/cmd_ide.c b/common/cmd_ide.c
index 6e1e568..bae7767 100644
--- a/common/cmd_ide.c
+++ b/common/cmd_ide.c
@@ -668,8 +668,7 @@ static void set_pcmcia_timing(int pmode)
/* We only need to swap data if we are running on a big endian cpu. */
/* But Au1x00 cpu:s already swaps data in big endian mode! */
-#if defined(__LITTLE_ENDIAN) || \
- (defined(CONFIG_SOC_AU1X00) && !defined(CONFIG_GTH2))
+#if defined(__LITTLE_ENDIAN) || defined(CONFIG_SOC_AU1X00)
#define input_swap_data(x,y,z) input_data(x,y,z)
#else
static void input_swap_data(int dev, ulong *sect_buf, int words)
diff --git a/common/cmd_ini.c b/common/cmd_ini.c
new file mode 100644
index 0000000..74481cb
--- /dev/null
+++ b/common/cmd_ini.c
@@ -0,0 +1,275 @@
+/*
+ * inih -- simple .INI file parser
+ *
+ * Copyright (c) 2009, Brush Technology
+ * Copyright (c) 2012:
+ * Joe Hershberger, National Instruments, joe.hershberger@ni.com
+ * All rights reserved.
+ *
+ * The "inih" library is distributed under the following license, which is
+ * derived from and very similar to the 3-clause BSD license:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Brush Technology nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY BRUSH TECHNOLOGY ''AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL BRUSH TECHNOLOGY BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Go to the project home page for more info:
+ * http://code.google.com/p/inih/
+ */
+
+#include <common.h>
+#include <command.h>
+#include <environment.h>
+#include <linux/ctype.h>
+#include <linux/string.h>
+
+#ifdef CONFIG_INI_MAX_LINE
+#define MAX_LINE CONFIG_INI_MAX_LINE
+#else
+#define MAX_LINE 200
+#endif
+
+#ifdef CONFIG_INI_MAX_SECTION
+#define MAX_SECTION CONFIG_INI_MAX_SECTION
+#else
+#define MAX_SECTION 50
+#endif
+
+#ifdef CONFIG_INI_MAX_NAME
+#define MAX_NAME CONFIG_INI_MAX_NAME
+#else
+#define MAX_NAME 50
+#endif
+
+/* Strip whitespace chars off end of given string, in place. Return s. */
+static char *rstrip(char *s)
+{
+ char *p = s + strlen(s);
+
+ while (p > s && isspace(*--p))
+ *p = '\0';
+ return s;
+}
+
+/* Return pointer to first non-whitespace char in given string. */
+static char *lskip(const char *s)
+{
+ while (*s && isspace(*s))
+ s++;
+ return (char *)s;
+}
+
+/* Return pointer to first char c or ';' comment in given string, or pointer to
+ null at end of string if neither found. ';' must be prefixed by a whitespace
+ character to register as a comment. */
+static char *find_char_or_comment(const char *s, char c)
+{
+ int was_whitespace = 0;
+
+ while (*s && *s != c && !(was_whitespace && *s == ';')) {
+ was_whitespace = isspace(*s);
+ s++;
+ }
+ return (char *)s;
+}
+
+/* Version of strncpy that ensures dest (size bytes) is null-terminated. */
+static char *strncpy0(char *dest, const char *src, size_t size)
+{
+ strncpy(dest, src, size);
+ dest[size - 1] = '\0';
+ return dest;
+}
+
+/* Emulate the behavior of fgets but on memory */
+static char *memgets(char *str, int num, char **mem, size_t *memsize)
+{
+ char *end;
+ int len;
+ int newline = 1;
+
+ end = memchr(*mem, '\n', *memsize);
+ if (end == NULL) {
+ if (*memsize == 0)
+ return NULL;
+ end = *mem + *memsize;
+ newline = 0;
+ }
+ len = min((end - *mem) + newline, num);
+ memcpy(str, *mem, len);
+ if (len < num)
+ str[len] = '\0';
+
+ /* prepare the mem vars for the next call */
+ *memsize -= (end - *mem) + newline;
+ *mem += (end - *mem) + newline;
+
+ return str;
+}
+
+/* Parse given INI-style file. May have [section]s, name=value pairs
+ (whitespace stripped), and comments starting with ';' (semicolon). Section
+ is "" if name=value pair parsed before any section heading. name:value
+ pairs are also supported as a concession to Python's ConfigParser.
+
+ For each name=value pair parsed, call handler function with given user
+ pointer as well as section, name, and value (data only valid for duration
+ of handler call). Handler should return nonzero on success, zero on error.
+
+ Returns 0 on success, line number of first error on parse error (doesn't
+ stop on first error).
+*/
+static int ini_parse(char *filestart, size_t filelen,
+ int (*handler)(void *, char *, char *, char *), void *user)
+{
+ /* Uses a fair bit of stack (use heap instead if you need to) */
+ char line[MAX_LINE];
+ char section[MAX_SECTION] = "";
+ char prev_name[MAX_NAME] = "";
+
+ char *curmem = filestart;
+ char *start;
+ char *end;
+ char *name;
+ char *value;
+ size_t memleft = filelen;
+ int lineno = 0;
+ int error = 0;
+
+ /* Scan through file line by line */
+ while (memgets(line, sizeof(line), &curmem, &memleft) != NULL) {
+ lineno++;
+ start = lskip(rstrip(line));
+
+ if (*start == ';' || *start == '#') {
+ /*
+ * Per Python ConfigParser, allow '#' comments at start
+ * of line
+ */
+ }
+#if CONFIG_INI_ALLOW_MULTILINE
+ else if (*prev_name && *start && start > line) {
+ /*
+ * Non-blank line with leading whitespace, treat as
+ * continuation of previous name's value (as per Python
+ * ConfigParser).
+ */
+ if (!handler(user, section, prev_name, start) && !error)
+ error = lineno;
+ }
+#endif
+ else if (*start == '[') {
+ /* A "[section]" line */
+ end = find_char_or_comment(start + 1, ']');
+ if (*end == ']') {
+ *end = '\0';
+ strncpy0(section, start + 1, sizeof(section));
+ *prev_name = '\0';
+ } else if (!error) {
+ /* No ']' found on section line */
+ error = lineno;
+ }
+ } else if (*start && *start != ';') {
+ /* Not a comment, must be a name[=:]value pair */
+ end = find_char_or_comment(start, '=');
+ if (*end != '=')
+ end = find_char_or_comment(start, ':');
+ if (*end == '=' || *end == ':') {
+ *end = '\0';
+ name = rstrip(start);
+ value = lskip(end + 1);
+ end = find_char_or_comment(value, '\0');
+ if (*end == ';')
+ *end = '\0';
+ rstrip(value);
+ /* Strip double-quotes */
+ if (value[0] == '"' &&
+ value[strlen(value)-1] == '"') {
+ value[strlen(value)-1] = '\0';
+ value += 1;
+ }
+
+ /*
+ * Valid name[=:]value pair found, call handler
+ */
+ strncpy0(prev_name, name, sizeof(prev_name));
+ if (!handler(user, section, name, value) &&
+ !error)
+ error = lineno;
+ } else if (!error)
+ /* No '=' or ':' found on name[=:]value line */
+ error = lineno;
+ }
+ }
+
+ return error;
+}
+
+static int ini_handler(void *user, char *section, char *name, char *value)
+{
+ char *requested_section = (char *)user;
+#ifdef CONFIG_INI_CASE_INSENSITIVE
+ int i;
+
+ for (i = 0; i < strlen(requested_section); i++)
+ requested_section[i] = tolower(requested_section[i]);
+ for (i = 0; i < strlen(section); i++)
+ section[i] = tolower(section[i]);
+#endif
+
+ if (!strcmp(section, requested_section)) {
+#ifdef CONFIG_INI_CASE_INSENSITIVE
+ for (i = 0; i < strlen(name); i++)
+ name[i] = tolower(name[i]);
+ for (i = 0; i < strlen(value); i++)
+ value[i] = tolower(value[i]);
+#endif
+ setenv(name, value);
+ printf("ini: Imported %s as %s\n", name, value);
+ }
+
+ /* success */
+ return 1;
+}
+
+static int do_ini(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ const char *section;
+ char *file_address;
+ size_t file_size;
+
+ if (argc == 1)
+ return CMD_RET_USAGE;
+
+ section = argv[1];
+ file_address = (char *)simple_strtoul(
+ argc < 3 ? getenv("loadaddr") : argv[2], NULL, 16);
+ file_size = (size_t)simple_strtoul(
+ argc < 4 ? getenv("filesize") : argv[3], NULL, 16);
+
+ return ini_parse(file_address, file_size, ini_handler, (void *)section);
+}
+
+U_BOOT_CMD(
+ ini, 4, 0, do_ini,
+ "parse an ini file in memory and merge the specified section into the env",
+ "section [[file-address] file-size]"
+);
diff --git a/common/cmd_md5sum.c b/common/cmd_md5sum.c
index b93dd9b..3f81fdf 100644
--- a/common/cmd_md5sum.c
+++ b/common/cmd_md5sum.c
@@ -1,4 +1,7 @@
/*
+ * (C) Copyright 2011
+ * Joe Hershberger, National Instruments, joe.hershberger@ni.com
+ *
* (C) Copyright 2000
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
*
@@ -25,6 +28,125 @@
#include <command.h>
#include <u-boot/md5.h>
+/*
+ * Store the resulting sum to an address or variable
+ */
+static void store_result(const u8 *sum, const char *dest)
+{
+ unsigned int i;
+
+ if (*dest == '*') {
+ u8 *ptr;
+
+ ptr = (u8 *)simple_strtoul(dest + 1, NULL, 16);
+ for (i = 0; i < 16; i++)
+ *ptr++ = sum[i];
+ } else {
+ char str_output[33];
+ char *str_ptr = str_output;
+
+ for (i = 0; i < 16; i++) {
+ sprintf(str_ptr, "%02x", sum[i]);
+ str_ptr += 2;
+ }
+ str_ptr = '\0';
+ setenv(dest, str_output);
+ }
+}
+
+#ifdef CONFIG_MD5SUM_VERIFY
+static int parse_verify_sum(char *verify_str, u8 *vsum)
+{
+ if (*verify_str == '*') {
+ u8 *ptr;
+
+ ptr = (u8 *)simple_strtoul(verify_str + 1, NULL, 16);
+ memcpy(vsum, ptr, 16);
+ } else {
+ unsigned int i;
+ char *vsum_str;
+
+ if (strlen(verify_str) == 32)
+ vsum_str = verify_str;
+ else {
+ vsum_str = getenv(verify_str);
+ if (vsum_str == NULL || strlen(vsum_str) != 32)
+ return 1;
+ }
+
+ for (i = 0; i < 16; i++) {
+ char *nullp = vsum_str + (i + 1) * 2;
+ char end = *nullp;
+
+ *nullp = '\0';
+ *(u8 *)(vsum + i) =
+ simple_strtoul(vsum_str + (i * 2), NULL, 16);
+ *nullp = end;
+ }
+ }
+ return 0;
+}
+
+int do_md5sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ ulong addr, len;
+ unsigned int i;
+ u8 output[16];
+ u8 vsum[16];
+ int verify = 0;
+ int ac;
+ char * const *av;
+
+ if (argc < 3)
+ return CMD_RET_USAGE;
+
+ av = argv + 1;
+ ac = argc - 1;
+ if (strcmp(*av, "-v") == 0) {
+ verify = 1;
+ av++;
+ ac--;
+ if (ac < 3)
+ return CMD_RET_USAGE;
+ }
+
+ addr = simple_strtoul(*av++, NULL, 16);
+ len = simple_strtoul(*av++, NULL, 16);
+
+ md5_wd((unsigned char *) addr, len, output, CHUNKSZ_MD5);
+
+ if (!verify) {
+ printf("md5 for %08lx ... %08lx ==> ", addr, addr + len - 1);
+ for (i = 0; i < 16; i++)
+ printf("%02x", output[i]);
+ printf("\n");
+
+ if (ac > 2)
+ store_result(output, *av);
+ } else {
+ char *verify_str = *av++;
+
+ if (parse_verify_sum(verify_str, vsum)) {
+ printf("ERROR: %s does not contain a valid md5 sum\n",
+ verify_str);
+ return 1;
+ }
+ if (memcmp(output, vsum, 16) != 0) {
+ printf("md5 for %08lx ... %08lx ==> ", addr,
+ addr + len - 1);
+ for (i = 0; i < 16; i++)
+ printf("%02x", output[i]);
+ printf(" != ");
+ for (i = 0; i < 16; i++)
+ printf("%02x", vsum[i]);
+ printf(" ** ERROR **\n");
+ return 1;
+ }
+ }
+
+ return 0;
+}
+#else
static int do_md5sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
unsigned long addr, len;
@@ -43,11 +165,27 @@ static int do_md5sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
printf("%02x", output[i]);
printf("\n");
+ if (argc > 3)
+ store_result(output, argv[3]);
+
return 0;
}
+#endif
+#ifdef CONFIG_MD5SUM_VERIFY
+U_BOOT_CMD(
+ md5sum, 5, 1, do_md5sum,
+ "compute MD5 message digest",
+ "address count [[*]sum]\n"
+ " - compute MD5 message digest [save to sum]\n"
+ "md5sum -v address count [*]sum\n"
+ " - verify md5sum of memory area"
+);
+#else
U_BOOT_CMD(
- md5sum, 3, 1, do_md5sum,
+ md5sum, 4, 1, do_md5sum,
"compute MD5 message digest",
- "address count"
+ "address count [[*]sum]\n"
+ " - compute MD5 message digest [save to sum]"
);
+#endif
diff --git a/common/cmd_misc.c b/common/cmd_misc.c
index 973b1c2..3b47a0c 100644
--- a/common/cmd_misc.c
+++ b/common/cmd_misc.c
@@ -53,3 +53,30 @@ U_BOOT_CMD(
"N\n"
" - delay execution for N seconds (N is _decimal_ !!!)"
);
+
+#ifdef CONFIG_CMD_TIMER
+static int do_timer(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ static ulong start;
+
+ if (argc != 2)
+ return CMD_RET_USAGE;
+
+ if (!strcmp(argv[1], "start"))
+ start = get_timer(0);
+
+ if (!strcmp(argv[1], "get")) {
+ ulong msecs = get_timer(start) * 1000 / CONFIG_SYS_HZ;
+ printf("%ld.%03d\n", msecs / 1000, (int)(msecs % 1000));
+ }
+
+ return 0;
+}
+
+U_BOOT_CMD(
+ timer, 2, 1, do_timer,
+ "access the system timer",
+ "start - Reset the timer reference.\n"
+ "timer get - Print the time since 'start'."
+);
+#endif
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index 3474bc6..1f9c674 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -71,9 +71,6 @@ DECLARE_GLOBAL_DATA_PTR;
SPI_FLASH|NVRAM|MMC|FAT|REMOTE} or CONFIG_ENV_IS_NOWHERE
#endif
-#define XMK_STR(x) #x
-#define MK_STR(x) XMK_STR(x)
-
/*
* Maximum expected input data size for import command
*/
@@ -103,6 +100,7 @@ int get_env_id(void)
return env_id;
}
+#ifndef CONFIG_SPL_BUILD
/*
* Command interface: print one or all environment variables
*
@@ -196,6 +194,7 @@ static int do_env_grep(cmd_tbl_t *cmdtp, int flag,
return rcode;
}
#endif
+#endif /* CONFIG_SPL_BUILD */
/*
* Perform consistency checking before setting, replacing, or deleting an
@@ -213,6 +212,9 @@ int env_check_apply(const char *name, const char *oldval,
{
int console = -1;
+ /* Default value for NULL to protect string-manipulating functions */
+ newval = newval ? : "";
+
/* Check for console redirection */
if (strcmp(name, "stdin") == 0)
console = stdin;
@@ -237,10 +239,8 @@ int env_check_apply(const char *name, const char *oldval,
if (console_assign(console, newval) < 0)
return 1;
-#ifdef CONFIG_SERIAL_MULTI
if (serial_assign(newval) < 0)
return 1;
-#endif
#endif /* CONFIG_CONSOLE_MUX */
}
@@ -254,7 +254,7 @@ int env_check_apply(const char *name, const char *oldval,
if (strcmp(name, "serial#") == 0 ||
(strcmp(name, "ethaddr") == 0
#if defined(CONFIG_OVERWRITE_ETHADDR_ONCE) && defined(CONFIG_ETHADDR)
- && strcmp(oldval, MK_STR(CONFIG_ETHADDR)) != 0
+ && strcmp(oldval, __stringify(CONFIG_ETHADDR)) != 0
#endif /* CONFIG_OVERWRITE_ETHADDR_ONCE && CONFIG_ETHADDR */
)) {
printf("Can't overwrite \"%s\"\n", name);
@@ -437,6 +437,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)
@@ -536,6 +537,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,
@@ -621,6 +623,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[])
{
@@ -635,6 +638,7 @@ U_BOOT_CMD(
""
);
#endif
+#endif /* CONFIG_SPL_BUILD */
/*
@@ -646,6 +650,9 @@ U_BOOT_CMD(
*/
int envmatch(uchar *s1, int i2)
{
+ if (s1 == NULL)
+ return -1;
+
while (*s1 == env_get_char(i2++))
if (*s1++ == '=')
return i2;
@@ -656,6 +663,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[])
{
@@ -1114,3 +1122,4 @@ U_BOOT_CMD_COMPLETE(
var_complete
);
#endif
+#endif /* CONFIG_SPL_BUILD */
diff --git a/common/cmd_sha1sum.c b/common/cmd_sha1sum.c
index 2713a14..8db5456 100644
--- a/common/cmd_sha1sum.c
+++ b/common/cmd_sha1sum.c
@@ -1,4 +1,7 @@
/*
+ * (C) Copyright 2011
+ * Joe Hershberger, National Instruments, joe.hershberger@ni.com
+ *
* (C) Copyright 2000
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
*
@@ -25,6 +28,125 @@
#include <command.h>
#include <sha1.h>
+/*
+ * Store the resulting sum to an address or variable
+ */
+static void store_result(const u8 *sum, const char *dest)
+{
+ unsigned int i;
+
+ if (*dest == '*') {
+ u8 *ptr;
+
+ ptr = (u8 *)simple_strtoul(dest + 1, NULL, 16);
+ for (i = 0; i < 20; i++)
+ *ptr++ = sum[i];
+ } else {
+ char str_output[41];
+ char *str_ptr = str_output;
+
+ for (i = 0; i < 20; i++) {
+ sprintf(str_ptr, "%02x", sum[i]);
+ str_ptr += 2;
+ }
+ str_ptr = '\0';
+ setenv(dest, str_output);
+ }
+}
+
+#ifdef CONFIG_SHA1SUM_VERIFY
+static int parse_verify_sum(char *verify_str, u8 *vsum)
+{
+ if (*verify_str == '*') {
+ u8 *ptr;
+
+ ptr = (u8 *)simple_strtoul(verify_str + 1, NULL, 16);
+ memcpy(vsum, ptr, 20);
+ } else {
+ unsigned int i;
+ char *vsum_str;
+
+ if (strlen(verify_str) == 40)
+ vsum_str = verify_str;
+ else {
+ vsum_str = getenv(verify_str);
+ if (vsum_str == NULL || strlen(vsum_str) != 40)
+ return 1;
+ }
+
+ for (i = 0; i < 20; i++) {
+ char *nullp = vsum_str + (i + 1) * 2;
+ char end = *nullp;
+
+ *nullp = '\0';
+ *(u8 *)(vsum + i) =
+ simple_strtoul(vsum_str + (i * 2), NULL, 16);
+ *nullp = end;
+ }
+ }
+ return 0;
+}
+
+int do_sha1sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ ulong addr, len;
+ unsigned int i;
+ u8 output[20];
+ u8 vsum[20];
+ int verify = 0;
+ int ac;
+ char * const *av;
+
+ if (argc < 3)
+ return CMD_RET_USAGE;
+
+ av = argv + 1;
+ ac = argc - 1;
+ if (strcmp(*av, "-v") == 0) {
+ verify = 1;
+ av++;
+ ac--;
+ if (ac < 3)
+ return CMD_RET_USAGE;
+ }
+
+ addr = simple_strtoul(*av++, NULL, 16);
+ len = simple_strtoul(*av++, NULL, 16);
+
+ sha1_csum_wd((unsigned char *) addr, len, output, CHUNKSZ_SHA1);
+
+ if (!verify) {
+ printf("SHA1 for %08lx ... %08lx ==> ", addr, addr + len - 1);
+ for (i = 0; i < 20; i++)
+ printf("%02x", output[i]);
+ printf("\n");
+
+ if (ac > 2)
+ store_result(output, *av);
+ } else {
+ char *verify_str = *av++;
+
+ if (parse_verify_sum(verify_str, vsum)) {
+ printf("ERROR: %s does not contain a valid SHA1 sum\n",
+ verify_str);
+ return 1;
+ }
+ if (memcmp(output, vsum, 20) != 0) {
+ printf("SHA1 for %08lx ... %08lx ==> ", addr,
+ addr + len - 1);
+ for (i = 0; i < 20; i++)
+ printf("%02x", output[i]);
+ printf(" != ");
+ for (i = 0; i < 20; i++)
+ printf("%02x", vsum[i]);
+ printf(" ** ERROR **\n");
+ return 1;
+ }
+ }
+
+ return 0;
+}
+#else
static int do_sha1sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
unsigned long addr, len;
@@ -43,11 +165,27 @@ static int do_sha1sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
printf("%02x", output[i]);
printf("\n");
+ if (argc > 3)
+ store_result(output, argv[3]);
+
return 0;
}
+#endif
+#ifdef CONFIG_SHA1SUM_VERIFY
+U_BOOT_CMD(
+ sha1sum, 5, 1, do_sha1sum,
+ "compute SHA1 message digest",
+ "address count [[*]sum]\n"
+ " - compute SHA1 message digest [save to sum]\n"
+ "sha1sum -v address count [*]sum\n"
+ " - verify sha1sum of memory area"
+);
+#else
U_BOOT_CMD(
- sha1sum, 3, 1, do_sha1sum,
+ sha1sum, 4, 1, do_sha1sum,
"compute SHA1 message digest",
- "address count"
+ "address count [[*]sum]\n"
+ " - compute SHA1 message digest [save to sum]"
);
+#endif
diff --git a/common/cmd_test.c b/common/cmd_test.c
index fcb5ef2..6da06b9 100644
--- a/common/cmd_test.c
+++ b/common/cmd_test.c
@@ -33,12 +33,12 @@ int do_test(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
if (argc < 3)
return 1;
-#if 0
+#ifdef DEBUG
{
- printf("test:");
+ debug("test(%d):", argc);
left = 1;
while (argv[left])
- printf(" %s", argv[left++]);
+ debug(" '%s'", argv[left++]);
}
#endif
diff --git a/common/cmd_usb.c b/common/cmd_usb.c
index 181e727..c128455 100644
--- a/common/cmd_usb.c
+++ b/common/cmd_usb.c
@@ -381,8 +381,7 @@ int do_usb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
bootstage_mark_name(BOOTSTAGE_ID_USB_START, "usb_start");
usb_stop();
printf("(Re)start USB...\n");
- i = usb_init();
- if (i >= 0) {
+ if (usb_init() >= 0) {
#ifdef CONFIG_USB_STORAGE
/* try to recognize storage devices immediately */
usb_stor_curr_dev = usb_stor_scan(1);
@@ -391,6 +390,9 @@ int do_usb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
/* try to recognize ethernet devices immediately */
usb_ether_curr_dev = usb_host_eth_scan(1);
#endif
+#ifdef CONFIG_USB_KEYBOARD
+ drv_usb_kbd_init();
+#endif
}
return 0;
}
@@ -417,8 +419,14 @@ int do_usb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
return 1;
}
if (strncmp(argv[1], "tree", 4) == 0) {
- printf("\nDevice Tree:\n");
- usb_show_tree(usb_get_dev_index(0));
+ puts("USB device tree:\n");
+ for (i = 0; i < USB_MAX_DEVICE; i++) {
+ dev = usb_get_dev_index(i);
+ if (dev == NULL)
+ break;
+ if (dev->parent == NULL)
+ usb_show_tree(dev);
+ }
return 0;
}
if (strncmp(argv[1], "inf", 3) == 0) {
diff --git a/common/env_common.c b/common/env_common.c
index 3e46c26..61c4be5 100644
--- a/common/env_common.c
+++ b/common/env_common.c
@@ -37,8 +37,6 @@ DECLARE_GLOBAL_DATA_PTR;
/************************************************************************
* Default settings to be used when no valid environment is found
*/
-#define XMK_STR(x) #x
-#define MK_STR(x) XMK_STR(x)
const uchar default_environment[] = {
#ifdef CONFIG_BOOTARGS
@@ -54,40 +52,40 @@ const uchar default_environment[] = {
"nfsboot=" CONFIG_NFSBOOTCOMMAND "\0"
#endif
#if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
- "bootdelay=" MK_STR(CONFIG_BOOTDELAY) "\0"
+ "bootdelay=" __stringify(CONFIG_BOOTDELAY) "\0"
#endif
#if defined(CONFIG_BAUDRATE) && (CONFIG_BAUDRATE >= 0)
- "baudrate=" MK_STR(CONFIG_BAUDRATE) "\0"
+ "baudrate=" __stringify(CONFIG_BAUDRATE) "\0"
#endif
#ifdef CONFIG_LOADS_ECHO
- "loads_echo=" MK_STR(CONFIG_LOADS_ECHO) "\0"
+ "loads_echo=" __stringify(CONFIG_LOADS_ECHO) "\0"
#endif
#ifdef CONFIG_ETHADDR
- "ethaddr=" MK_STR(CONFIG_ETHADDR) "\0"
+ "ethaddr=" __stringify(CONFIG_ETHADDR) "\0"
#endif
#ifdef CONFIG_ETH1ADDR
- "eth1addr=" MK_STR(CONFIG_ETH1ADDR) "\0"
+ "eth1addr=" __stringify(CONFIG_ETH1ADDR) "\0"
#endif
#ifdef CONFIG_ETH2ADDR
- "eth2addr=" MK_STR(CONFIG_ETH2ADDR) "\0"
+ "eth2addr=" __stringify(CONFIG_ETH2ADDR) "\0"
#endif
#ifdef CONFIG_ETH3ADDR
- "eth3addr=" MK_STR(CONFIG_ETH3ADDR) "\0"
+ "eth3addr=" __stringify(CONFIG_ETH3ADDR) "\0"
#endif
#ifdef CONFIG_ETH4ADDR
- "eth4addr=" MK_STR(CONFIG_ETH4ADDR) "\0"
+ "eth4addr=" __stringify(CONFIG_ETH4ADDR) "\0"
#endif
#ifdef CONFIG_ETH5ADDR
- "eth5addr=" MK_STR(CONFIG_ETH5ADDR) "\0"
+ "eth5addr=" __stringify(CONFIG_ETH5ADDR) "\0"
#endif
#ifdef CONFIG_ETHPRIME
"ethprime=" CONFIG_ETHPRIME "\0"
#endif
#ifdef CONFIG_IPADDR
- "ipaddr=" MK_STR(CONFIG_IPADDR) "\0"
+ "ipaddr=" __stringify(CONFIG_IPADDR) "\0"
#endif
#ifdef CONFIG_SERVERIP
- "serverip=" MK_STR(CONFIG_SERVERIP) "\0"
+ "serverip=" __stringify(CONFIG_SERVERIP) "\0"
#endif
#ifdef CONFIG_SYS_AUTOLOAD
"autoload=" CONFIG_SYS_AUTOLOAD "\0"
@@ -99,25 +97,25 @@ const uchar default_environment[] = {
"rootpath=" CONFIG_ROOTPATH "\0"
#endif
#ifdef CONFIG_GATEWAYIP
- "gatewayip=" MK_STR(CONFIG_GATEWAYIP) "\0"
+ "gatewayip=" __stringify(CONFIG_GATEWAYIP) "\0"
#endif
#ifdef CONFIG_NETMASK
- "netmask=" MK_STR(CONFIG_NETMASK) "\0"
+ "netmask=" __stringify(CONFIG_NETMASK) "\0"
#endif
#ifdef CONFIG_HOSTNAME
- "hostname=" MK_STR(CONFIG_HOSTNAME) "\0"
+ "hostname=" __stringify(CONFIG_HOSTNAME) "\0"
#endif
#ifdef CONFIG_BOOTFILE
"bootfile=" CONFIG_BOOTFILE "\0"
#endif
#ifdef CONFIG_LOADADDR
- "loadaddr=" MK_STR(CONFIG_LOADADDR) "\0"
+ "loadaddr=" __stringify(CONFIG_LOADADDR) "\0"
#endif
#ifdef CONFIG_CLOCKS_IN_MHZ
"clocks_in_mhz=1\0"
#endif
#if defined(CONFIG_PCI_BOOTDELAY) && (CONFIG_PCI_BOOTDELAY > 0)
- "pcidelay=" MK_STR(CONFIG_PCI_BOOTDELAY) "\0"
+ "pcidelay=" __stringify(CONFIG_PCI_BOOTDELAY)"\0"
#endif
#ifdef CONFIG_ENV_VARS_UBOOT_CONFIG
"arch=" CONFIG_SYS_ARCH "\0"
@@ -231,6 +229,7 @@ int set_default_vars(int nvars, char * const vars[])
nvars, vars, 1 /* do_apply */);
}
+#ifndef CONFIG_SPL_BUILD
/*
* Check if CRC is valid and (if yes) import the environment.
* Note that "buf" may or may not be aligned.
@@ -262,6 +261,7 @@ int env_import(const char *buf, int check)
return 0;
}
+#endif
void env_relocate(void)
{
@@ -269,7 +269,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);
@@ -280,7 +281,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/common/env_embedded.c b/common/env_embedded.c
index 3872878..8cc08ae 100644
--- a/common/env_embedded.c
+++ b/common/env_embedded.c
@@ -28,6 +28,7 @@
#include <config.h>
#undef __ASSEMBLY__
#include <environment.h>
+#include <linux/stringify.h>
/* Handle HOSTS that have prepended crap on symbol names, not TARGETS. */
#if defined(__APPLE__)
@@ -81,13 +82,6 @@
GEN_SET_VALUE(name, value)
/*
- * Macros to transform values
- * into environment strings.
- */
-#define XMK_STR(x) #x
-#define MK_STR(x) XMK_STR(x)
-
-/*
* Check to see if we are building with a
* computed CRC. Otherwise define it as ~0.
*/
@@ -114,40 +108,40 @@ env_t environment __PPCENV__ = {
"nfsboot=" CONFIG_NFSBOOTCOMMAND "\0"
#endif
#if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
- "bootdelay=" MK_STR(CONFIG_BOOTDELAY) "\0"
+ "bootdelay=" __stringify(CONFIG_BOOTDELAY) "\0"
#endif
#if defined(CONFIG_BAUDRATE) && (CONFIG_BAUDRATE >= 0)
- "baudrate=" MK_STR(CONFIG_BAUDRATE) "\0"
+ "baudrate=" __stringify(CONFIG_BAUDRATE) "\0"
#endif
#ifdef CONFIG_LOADS_ECHO
- "loads_echo=" MK_STR(CONFIG_LOADS_ECHO) "\0"
+ "loads_echo=" __stringify(CONFIG_LOADS_ECHO) "\0"
#endif
#ifdef CONFIG_ETHADDR
- "ethaddr=" MK_STR(CONFIG_ETHADDR) "\0"
+ "ethaddr=" __stringify(CONFIG_ETHADDR) "\0"
#endif
#ifdef CONFIG_ETH1ADDR
- "eth1addr=" MK_STR(CONFIG_ETH1ADDR) "\0"
+ "eth1addr=" __stringify(CONFIG_ETH1ADDR) "\0"
#endif
#ifdef CONFIG_ETH2ADDR
- "eth2addr=" MK_STR(CONFIG_ETH2ADDR) "\0"
+ "eth2addr=" __stringify(CONFIG_ETH2ADDR) "\0"
#endif
#ifdef CONFIG_ETH3ADDR
- "eth3addr=" MK_STR(CONFIG_ETH3ADDR) "\0"
+ "eth3addr=" __stringify(CONFIG_ETH3ADDR) "\0"
#endif
#ifdef CONFIG_ETH4ADDR
- "eth4addr=" MK_STR(CONFIG_ETH4ADDR) "\0"
+ "eth4addr=" __stringify(CONFIG_ETH4ADDR) "\0"
#endif
#ifdef CONFIG_ETH5ADDR
- "eth5addr=" MK_STR(CONFIG_ETH5ADDR) "\0"
+ "eth5addr=" __stringify(CONFIG_ETH5ADDR) "\0"
#endif
#ifdef CONFIG_ETHPRIME
"ethprime=" CONFIG_ETHPRIME "\0"
#endif
#ifdef CONFIG_IPADDR
- "ipaddr=" MK_STR(CONFIG_IPADDR) "\0"
+ "ipaddr=" __stringify(CONFIG_IPADDR) "\0"
#endif
#ifdef CONFIG_SERVERIP
- "serverip=" MK_STR(CONFIG_SERVERIP) "\0"
+ "serverip=" __stringify(CONFIG_SERVERIP) "\0"
#endif
#ifdef CONFIG_SYS_AUTOLOAD
"autoload=" CONFIG_SYS_AUTOLOAD "\0"
@@ -156,19 +150,19 @@ env_t environment __PPCENV__ = {
"rootpath=" CONFIG_ROOTPATH "\0"
#endif
#ifdef CONFIG_GATEWAYIP
- "gatewayip=" MK_STR(CONFIG_GATEWAYIP) "\0"
+ "gatewayip=" __stringify(CONFIG_GATEWAYIP) "\0"
#endif
#ifdef CONFIG_NETMASK
- "netmask=" MK_STR(CONFIG_NETMASK) "\0"
+ "netmask=" __stringify(CONFIG_NETMASK) "\0"
#endif
#ifdef CONFIG_HOSTNAME
- "hostname=" MK_STR(CONFIG_HOSTNAME) "\0"
+ "hostname=" __stringify(CONFIG_HOSTNAME) "\0"
#endif
#ifdef CONFIG_BOOTFILE
"bootfile=" CONFIG_BOOTFILE "\0"
#endif
#ifdef CONFIG_LOADADDR
- "loadaddr=" MK_STR(CONFIG_LOADADDR) "\0"
+ "loadaddr=" __stringify(CONFIG_LOADADDR) "\0"
#endif
#ifdef CONFIG_PREBOOT
"preboot=" CONFIG_PREBOOT "\0"
@@ -177,7 +171,7 @@ env_t environment __PPCENV__ = {
"clocks_in_mhz=" "1" "\0"
#endif
#if defined(CONFIG_PCI_BOOTDELAY) && (CONFIG_PCI_BOOTDELAY > 0)
- "pcidelay=" MK_STR(CONFIG_PCI_BOOTDELAY) "\0"
+ "pcidelay=" __stringify(CONFIG_PCI_BOOTDELAY)"\0"
#endif
#ifdef CONFIG_ENV_VARS_UBOOT_CONFIG
"arch=" CONFIG_SYS_ARCH "\0"
diff --git a/common/fdt_support.c b/common/fdt_support.c
index 593f16c..963ea90 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -94,7 +94,7 @@ int fdt_find_and_setprop(void *fdt, const char *node, const char *prop,
#ifdef CONFIG_OF_STDOUT_VIA_ALIAS
-#ifdef CONFIG_SERIAL_MULTI
+#ifdef CONFIG_CONS_INDEX
static void fdt_fill_multisername(char *sername, size_t maxlen)
{
const char *outname = stdio_devices[stdout]->name;
@@ -106,9 +106,7 @@ static void fdt_fill_multisername(char *sername, size_t maxlen)
if (strcmp(outname + 1, "serial") > 0)
strncpy(sername, outname + 1, maxlen);
}
-#else
-static inline void fdt_fill_multisername(char *sername, size_t maxlen) {}
-#endif /* CONFIG_SERIAL_MULTI */
+#endif
static int fdt_fixup_stdout(void *fdt, int chosenoff)
{
diff --git a/common/iomux.c b/common/iomux.c
index 91d98e9..dbc2312 100644
--- a/common/iomux.c
+++ b/common/iomux.c
@@ -135,7 +135,6 @@ int iomux_doenv(const int console, const char *arg)
*/
if (console_assign(console, start[j]) < 0)
continue;
-#ifdef CONFIG_SERIAL_MULTI
/*
* This was taken from common/cmd_nvedit.c.
* This will never work because serial_assign() returns
@@ -146,7 +145,6 @@ int iomux_doenv(const int console, const char *arg)
*/
if (serial_assign(start[j]) < 0)
continue;
-#endif
cons_set[cs_idx++] = dev;
}
free(console_args);
diff --git a/common/main.c b/common/main.c
index 81984ac..9507cec 100644
--- a/common/main.c
+++ b/common/main.c
@@ -222,7 +222,8 @@ int abortboot(int bootdelay)
#ifdef CONFIG_MENUPROMPT
printf(CONFIG_MENUPROMPT);
#else
- printf("Hit any key to stop autoboot: %2d ", bootdelay);
+ if (bootdelay >= 0)
+ printf("Hit any key to stop autoboot: %2d ", bootdelay);
#endif
#if defined CONFIG_ZERO_BOOTDELAY_CHECK
@@ -382,7 +383,7 @@ void main_loop (void)
debug ("### main_loop: bootcmd=\"%s\"\n", s ? s : "<UNDEFINED>");
- if (bootdelay >= 0 && s && !abortboot (bootdelay)) {
+ if (bootdelay != -1 && s && !abortboot(bootdelay)) {
# ifdef CONFIG_AUTOBOOT_KEYED
int prev = disable_ctrlc(1); /* disable Control C checking */
# endif
diff --git a/common/serial.c b/common/serial.c
deleted file mode 100644
index 75cc1bb..0000000
--- a/common/serial.c
+++ /dev/null
@@ -1,305 +0,0 @@
-/*
- * (C) Copyright 2004
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * 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., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
- */
-
-#include <common.h>
-#include <serial.h>
-#include <stdio_dev.h>
-#include <post.h>
-#include <linux/compiler.h>
-
-DECLARE_GLOBAL_DATA_PTR;
-
-static struct serial_device *serial_devices;
-static struct serial_device *serial_current;
-
-void serial_register(struct serial_device *dev)
-{
-#ifdef CONFIG_NEEDS_MANUAL_RELOC
- dev->init += gd->reloc_off;
- dev->setbrg += gd->reloc_off;
- dev->getc += gd->reloc_off;
- dev->tstc += gd->reloc_off;
- dev->putc += gd->reloc_off;
- dev->puts += gd->reloc_off;
-#endif
-
- dev->next = serial_devices;
- serial_devices = dev;
-}
-
-void serial_initialize(void)
-{
-#if defined(CONFIG_8xx_CONS_SMC1) || defined(CONFIG_8xx_CONS_SMC2)
- serial_register(&serial_smc_device);
-#endif
-#if defined(CONFIG_8xx_CONS_SCC1) || defined(CONFIG_8xx_CONS_SCC2) || \
- defined(CONFIG_8xx_CONS_SCC3) || defined(CONFIG_8xx_CONS_SCC4)
- serial_register(&serial_scc_device);
-#endif
-
-#if defined(CONFIG_SYS_NS16550_SERIAL)
-#if defined(CONFIG_SYS_NS16550_COM1)
- serial_register(&eserial1_device);
-#endif
-#if defined(CONFIG_SYS_NS16550_COM2)
- serial_register(&eserial2_device);
-#endif
-#if defined(CONFIG_SYS_NS16550_COM3)
- serial_register(&eserial3_device);
-#endif
-#if defined(CONFIG_SYS_NS16550_COM4)
- serial_register(&eserial4_device);
-#endif
-#endif /* CONFIG_SYS_NS16550_SERIAL */
-#if defined(CONFIG_FFUART)
- serial_register(&serial_ffuart_device);
-#endif
-#if defined(CONFIG_BTUART)
- serial_register(&serial_btuart_device);
-#endif
-#if defined(CONFIG_STUART)
- serial_register(&serial_stuart_device);
-#endif
-#if defined(CONFIG_S3C2410)
- serial_register(&s3c24xx_serial0_device);
- serial_register(&s3c24xx_serial1_device);
- serial_register(&s3c24xx_serial2_device);
-#endif
-#if defined(CONFIG_S5P)
- serial_register(&s5p_serial0_device);
- serial_register(&s5p_serial1_device);
- serial_register(&s5p_serial2_device);
- serial_register(&s5p_serial3_device);
-#endif
-#if defined(CONFIG_MPC512X)
-#if defined(CONFIG_SYS_PSC1)
- serial_register(&serial1_device);
-#endif
-#if defined(CONFIG_SYS_PSC3)
- serial_register(&serial3_device);
-#endif
-#if defined(CONFIG_SYS_PSC4)
- serial_register(&serial4_device);
-#endif
-#if defined(CONFIG_SYS_PSC6)
- serial_register(&serial6_device);
-#endif
-#endif
-#if defined(CONFIG_SYS_BFIN_UART)
- serial_register_bfin_uart();
-#endif
-#if defined(CONFIG_XILINX_UARTLITE)
-# ifdef XILINX_UARTLITE_BASEADDR
- serial_register(&uartlite_serial0_device);
-# endif /* XILINX_UARTLITE_BASEADDR */
-# ifdef XILINX_UARTLITE_BASEADDR1
- serial_register(&uartlite_serial1_device);
-# endif /* XILINX_UARTLITE_BASEADDR1 */
-# ifdef XILINX_UARTLITE_BASEADDR2
- serial_register(&uartlite_serial2_device);
-# endif /* XILINX_UARTLITE_BASEADDR2 */
-# ifdef XILINX_UARTLITE_BASEADDR3
- serial_register(&uartlite_serial3_device);
-# endif /* XILINX_UARTLITE_BASEADDR3 */
-#endif /* CONFIG_XILINX_UARTLITE */
- serial_assign(default_serial_console()->name);
-}
-
-void serial_stdio_init(void)
-{
- struct stdio_dev dev;
- struct serial_device *s = serial_devices;
-
- while (s) {
- memset(&dev, 0, sizeof(dev));
-
- strcpy(dev.name, s->name);
- dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT;
-
- dev.start = s->init;
- dev.stop = s->uninit;
- dev.putc = s->putc;
- dev.puts = s->puts;
- dev.getc = s->getc;
- dev.tstc = s->tstc;
-
- stdio_register(&dev);
-
- s = s->next;
- }
-}
-
-int serial_assign(const char *name)
-{
- struct serial_device *s;
-
- for (s = serial_devices; s; s = s->next) {
- if (strcmp(s->name, name) == 0) {
- serial_current = s;
- return 0;
- }
- }
-
- return 1;
-}
-
-void serial_reinit_all(void)
-{
- struct serial_device *s;
-
- for (s = serial_devices; s; s = s->next)
- s->init();
-}
-
-static struct serial_device *get_current(void)
-{
- struct serial_device *dev;
-
- if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
- dev = default_serial_console();
-
- /* We must have a console device */
- if (!dev)
- panic("Cannot find console");
- } else
- dev = serial_current;
- return dev;
-}
-
-int serial_init(void)
-{
- return get_current()->init();
-}
-
-void serial_setbrg(void)
-{
- get_current()->setbrg();
-}
-
-int serial_getc(void)
-{
- return get_current()->getc();
-}
-
-int serial_tstc(void)
-{
- return get_current()->tstc();
-}
-
-void serial_putc(const char c)
-{
- get_current()->putc(c);
-}
-
-void serial_puts(const char *s)
-{
- get_current()->puts(s);
-}
-
-#if CONFIG_POST & CONFIG_SYS_POST_UART
-static const int bauds[] = CONFIG_SYS_BAUDRATE_TABLE;
-
-/* Mark weak until post/cpu/.../uart.c migrate over */
-__weak
-int uart_post_test(int flags)
-{
- unsigned char c;
- int ret, saved_baud, b;
- struct serial_device *saved_dev, *s;
- bd_t *bd = gd->bd;
-
- /* Save current serial state */
- ret = 0;
- saved_dev = serial_current;
- saved_baud = bd->bi_baudrate;
-
- for (s = serial_devices; s; s = s->next) {
- /* If this driver doesn't support loop back, skip it */
- if (!s->loop)
- continue;
-
- /* Test the next device */
- serial_current = s;
-
- ret = serial_init();
- if (ret)
- goto done;
-
- /* Consume anything that happens to be queued */
- while (serial_tstc())
- serial_getc();
-
- /* Enable loop back */
- s->loop(1);
-
- /* Test every available baud rate */
- for (b = 0; b < ARRAY_SIZE(bauds); ++b) {
- bd->bi_baudrate = bauds[b];
- serial_setbrg();
-
- /*
- * Stick to printable chars to avoid issues:
- * - terminal corruption
- * - serial program reacting to sequences and sending
- * back random extra data
- * - most serial drivers add in extra chars (like \r\n)
- */
- for (c = 0x20; c < 0x7f; ++c) {
- /* Send it out */
- serial_putc(c);
-
- /* Make sure it's the same one */
- ret = (c != serial_getc());
- if (ret) {
- s->loop(0);
- goto done;
- }
-
- /* Clean up the output in case it was sent */
- serial_putc('\b');
- ret = ('\b' != serial_getc());
- if (ret) {
- s->loop(0);
- goto done;
- }
- }
- }
-
- /* Disable loop back */
- s->loop(0);
-
- /* XXX: There is no serial_uninit() !? */
- if (s->uninit)
- s->uninit();
- }
-
- done:
- /* Restore previous serial state */
- serial_current = saved_dev;
- bd->bi_baudrate = saved_baud;
- serial_reinit_all();
- serial_setbrg();
-
- return ret;
-}
-#endif
diff --git a/common/spl/Makefile b/common/spl/Makefile
index 7cf01ad..5698a23 100644
--- a/common/spl/Makefile
+++ b/common/spl/Makefile
@@ -18,6 +18,7 @@ COBJS-$(CONFIG_SPL_FRAMEWORK) += spl.o
COBJS-$(CONFIG_SPL_NOR_SUPPORT) += spl_nor.o
COBJS-$(CONFIG_SPL_YMODEM_SUPPORT) += spl_ymodem.o
COBJS-$(CONFIG_SPL_NAND_SUPPORT) += spl_nand.o
+COBJS-$(CONFIG_SPL_NET_SUPPORT) += spl_net.o
endif
COBJS := $(sort $(COBJS-y))
diff --git a/common/spl/spl.c b/common/spl/spl.c
index c640f87..0d829c0 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -155,6 +155,8 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
CONFIG_SYS_SPL_MALLOC_SIZE);
#endif
+ timer_init();
+
#ifdef CONFIG_SPL_BOARD_INIT
spl_board_init();
#endif
@@ -194,6 +196,15 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
spl_spi_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:
debug("SPL: Un-supported Boot Device\n");
hang();
@@ -222,7 +233,6 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
void preloader_console_init(void)
{
gd->bd = &bdata;
- gd->flags |= GD_FLG_RELOC;
gd->baudrate = CONFIG_BAUDRATE;
serial_init(); /* serial communications setup */
diff --git a/common/spl/spl_net.c b/common/spl/spl_net.c
new file mode 100644
index 0000000..e1596fe
--- /dev/null
+++ b/common/spl/spl_net.c
@@ -0,0 +1,52 @@
+/*
+ * (C) Copyright 2000-2004
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * (C) Copyright 2012
+ * Ilya Yanok <ilya.yanok@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 <spl.h>
+#include <net.h>
+
+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/common/stdio.c b/common/stdio.c
index 1bf9ba0..605ff3f 100644
--- a/common/stdio.c
+++ b/common/stdio.c
@@ -227,9 +227,7 @@ int stdio_init (void)
drv_logbuff_init ();
#endif
drv_system_init ();
-#ifdef CONFIG_SERIAL_MULTI
serial_stdio_init ();
-#endif
#ifdef CONFIG_USB_TTY
drv_usbtty_init ();
#endif
diff --git a/common/usb.c b/common/usb.c
index 1b40228..1c9763c 100644
--- a/common/usb.c
+++ b/common/usb.c
@@ -72,44 +72,72 @@
static struct usb_device usb_dev[USB_MAX_DEVICE];
static int dev_index;
-static int running;
static int asynch_allowed;
char usb_started; /* flag for the started/stopped USB status */
-/**********************************************************************
- * some forward declerations...
- */
-static void usb_scan_devices(void);
+#ifndef CONFIG_USB_MAX_CONTROLLER_COUNT
+#define CONFIG_USB_MAX_CONTROLLER_COUNT 1
+#endif
/***************************************************************************
* Init USB Device
*/
-
int usb_init(void)
{
- int result;
+ void *ctrl;
+ struct usb_device *dev;
+ int i, start_index = 0;
- running = 0;
dev_index = 0;
asynch_allowed = 1;
usb_hub_reset();
+
+ /* first make all devices unknown */
+ for (i = 0; i < USB_MAX_DEVICE; i++) {
+ memset(&usb_dev[i], 0, sizeof(struct usb_device));
+ usb_dev[i].devnum = -1;
+ }
+
/* init low_level USB */
- printf("USB: ");
- result = usb_lowlevel_init();
- /* if lowlevel init is OK, scan the bus for devices
- * i.e. search HUBs and configure them */
- if (result == 0) {
- printf("scanning bus for devices... ");
- running = 1;
- usb_scan_devices();
+ for (i = 0; i < CONFIG_USB_MAX_CONTROLLER_COUNT; i++) {
+ /* init low_level USB */
+ printf("USB%d: ", i);
+ if (usb_lowlevel_init(i, &ctrl)) {
+ puts("lowlevel init failed\n");
+ continue;
+ }
+ /*
+ * lowlevel init is OK, now scan the bus for devices
+ * i.e. search HUBs and configure them
+ */
+ start_index = dev_index;
+ printf("scanning bus %d for devices... ", i);
+ dev = usb_alloc_new_device(ctrl);
+ /*
+ * device 0 is always present
+ * (root hub, so let it analyze)
+ */
+ if (dev)
+ usb_new_device(dev);
+
+ if (start_index == dev_index)
+ puts("No USB Device found\n");
+ else
+ printf("%d USB Device(s) found\n",
+ dev_index - start_index);
+
usb_started = 1;
- return 0;
- } else {
- printf("Error, couldn't init Lowlevel part\n");
- usb_started = 0;
+ }
+
+ USB_PRINTF("scan end\n");
+ /* if we were not able to find at least one working bus, bail out */
+ if (!usb_started) {
+ puts("USB error: all controllers failed lowlevel init\n");
return -1;
}
+
+ return 0;
}
/******************************************************************************
@@ -117,15 +145,20 @@ int usb_init(void)
*/
int usb_stop(void)
{
- int res = 0;
+ int i;
if (usb_started) {
asynch_allowed = 1;
usb_started = 0;
usb_hub_reset();
- res = usb_lowlevel_stop();
+
+ for (i = 0; i < CONFIG_USB_MAX_CONTROLLER_COUNT; i++) {
+ if (usb_lowlevel_stop(i))
+ printf("failed to stop USB controller %d\n", i);
+ }
}
- return res;
+
+ return 0;
}
/*
@@ -750,11 +783,10 @@ struct usb_device *usb_get_dev_index(int index)
return &usb_dev[index];
}
-
/* returns a pointer of a new device structure or NULL, if
* no device struct is available
*/
-struct usb_device *usb_alloc_new_device(void)
+struct usb_device *usb_alloc_new_device(void *controller)
{
int i;
USB_PRINTF("New Device %d\n", dev_index);
@@ -768,6 +800,7 @@ struct usb_device *usb_alloc_new_device(void)
for (i = 0; i < USB_MAXCHILDREN; i++)
usb_dev[dev_index].children[i] = NULL;
usb_dev[dev_index].parent = NULL;
+ usb_dev[dev_index].controller = controller;
dev_index++;
return &usb_dev[dev_index - 1];
}
@@ -945,29 +978,4 @@ int usb_new_device(struct usb_device *dev)
return 0;
}
-/* build device Tree */
-static void usb_scan_devices(void)
-{
- int i;
- struct usb_device *dev;
-
- /* first make all devices unknown */
- for (i = 0; i < USB_MAX_DEVICE; i++) {
- memset(&usb_dev[i], 0, sizeof(struct usb_device));
- usb_dev[i].devnum = -1;
- }
- dev_index = 0;
- /* device 0 is always present (root hub, so let it analyze) */
- dev = usb_alloc_new_device();
- if (usb_new_device(dev))
- printf("No USB Device found\n");
- else
- printf("%d USB Device(s) found\n", dev_index);
- /* insert "driver" if possible */
-#ifdef CONFIG_USB_KEYBOARD
- drv_usb_kbd_init();
-#endif
- USB_PRINTF("scan end\n");
-}
-
/* EOF */
diff --git a/common/usb_hub.c b/common/usb_hub.c
index 32750e8..e4a1201 100644
--- a/common/usb_hub.c
+++ b/common/usb_hub.c
@@ -244,7 +244,7 @@ void usb_hub_port_connect_change(struct usb_device *dev, int port)
mdelay(200);
/* Allocate a new device struct for it */
- usb = usb_alloc_new_device();
+ usb = usb_alloc_new_device(dev->controller);
if (portstatus & USB_PORT_STAT_HIGH_SPEED)
usb->speed = USB_SPEED_HIGH;
diff --git a/common/usb_storage.c b/common/usb_storage.c
index 4aeed82..950451e 100644
--- a/common/usb_storage.c
+++ b/common/usb_storage.c
@@ -244,7 +244,7 @@ int usb_stor_scan(int mode)
struct usb_device *dev;
if (mode == 1)
- printf(" scanning bus for storage devices... ");
+ printf(" scanning usb for storage devices... ");
usb_disable_asynch(1); /* asynch transfer not allowed */