summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/cmd_bdinfo.c1
-rw-r--r--common/cmd_display.c26
-rw-r--r--common/cmd_elf.c62
-rw-r--r--common/cmd_flash.c12
-rw-r--r--common/cmd_mem.c8
-rw-r--r--common/cmd_mtdparts.c261
-rw-r--r--common/cmd_nand.c339
-rw-r--r--common/cmd_net.c2
-rw-r--r--common/cmd_nvedit.c7
-rw-r--r--common/cmd_otp.c13
-rw-r--r--common/cmd_spi.c40
-rw-r--r--common/cmd_tsi148.c4
-rw-r--r--common/env_common.c7
-rw-r--r--common/env_mmc.c20
-rw-r--r--common/fdt_support.c66
-rw-r--r--common/main.c7
-rw-r--r--common/serial.c1
-rw-r--r--common/usb_storage.c39
18 files changed, 671 insertions, 244 deletions
diff --git a/common/cmd_bdinfo.c b/common/cmd_bdinfo.c
index 6b611b1..1326c8f 100644
--- a/common/cmd_bdinfo.c
+++ b/common/cmd_bdinfo.c
@@ -385,7 +385,6 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
bd_t *bd = gd->bd;
char buf[32];
- print_num ("env_t", (ulong)bd->bi_env);
print_num ("boot_params", (ulong)bd->bi_boot_params);
print_num ("bi_memstart", bd->bi_memstart);
print_num ("bi_memsize", bd->bi_memsize);
diff --git a/common/cmd_display.c b/common/cmd_display.c
index 6c11aa6..d5d5d8c 100644
--- a/common/cmd_display.c
+++ b/common/cmd_display.c
@@ -23,40 +23,32 @@
#include <common.h>
#include <command.h>
+#include <led-display.h>
#undef DEBUG_DISP
-#define DISP_SIZE 8
-#define CWORD_CLEAR 0x80
-#define CLEAR_DELAY (110 * 2)
-
int do_display (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
int i;
- int pos;
/* Clear display */
- *((volatile char*)(CONFIG_SYS_DISP_CWORD)) = CWORD_CLEAR;
- udelay(1000 * CLEAR_DELAY);
+ display_set(DISPLAY_CLEAR | DISPLAY_HOME);
if (argc < 2)
return (0);
- for (pos = 0, i = 1; i < argc && pos < DISP_SIZE; i++) {
- char *p = argv[i], c;
+ for (i = 1; i < argc; i++) {
+ char *p = argv[i];
- if (i > 1) {
- *((volatile uchar *) (CONFIG_SYS_DISP_CHR_RAM + pos++)) = ' ';
-#ifdef DEBUG_DISP
- putc(' ');
-#endif
+ if (i > 1) { /* Insert a space between strings */
+ display_putc(' ');
}
- while ((c = *p++) != '\0' && pos < DISP_SIZE) {
- *((volatile uchar *) (CONFIG_SYS_DISP_CHR_RAM + pos++)) = c;
+ while ((*p)) {
#ifdef DEBUG_DISP
- putc(c);
+ putc(*p);
#endif
+ display_putc(*p++);
}
}
diff --git a/common/cmd_elf.c b/common/cmd_elf.c
index 104d6e6..bf32612 100644
--- a/common/cmd_elf.c
+++ b/common/cmd_elf.c
@@ -25,7 +25,8 @@ DECLARE_GLOBAL_DATA_PTR;
#endif
int valid_elf_image (unsigned long addr);
-unsigned long load_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))
@@ -61,19 +62,34 @@ 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 */
+ char *sload, *saddr;
/* -------------------------------------------------- */
int rcode = 0;
- if (argc < 2)
- addr = load_addr;
+ sload = saddr = NULL;
+ if (argc == 3) {
+ sload = argv[1];
+ saddr = argv[2];
+ } else if (argc == 2) {
+ if (argv[1][0] == '-')
+ sload = argv[1];
+ else
+ saddr = argv[1];
+ }
+
+ if (saddr)
+ addr = simple_strtoul(saddr, NULL, 16);
else
- addr = simple_strtoul (argv[1], NULL, 16);
+ addr = load_addr;
if (!valid_elf_image (addr))
return 1;
- addr = load_elf_image (addr);
+ if (sload && sload[1] == 'p')
+ addr = load_elf_image_phdr(addr);
+ else
+ addr = load_elf_image_shdr(addr);
printf ("## Starting application at 0x%08lx ...\n", addr);
@@ -204,7 +220,7 @@ int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
*/
if (valid_elf_image (addr)) {
- addr = load_elf_image (addr);
+ addr = load_elf_image_shdr (addr);
} else {
puts ("## Not an ELF image, assuming binary\n");
/* leave addr as load_addr */
@@ -258,7 +274,33 @@ int valid_elf_image (unsigned long addr)
* A very simple elf loader, assumes the image is valid, returns the
* entry point address.
* ====================================================================== */
-unsigned long load_elf_image (unsigned long addr)
+static unsigned long load_elf_image_phdr(unsigned long addr)
+{
+ Elf32_Ehdr *ehdr; /* Elf header structure pointer */
+ Elf32_Phdr *phdr; /* Program header structure pointer */
+ int i;
+
+ ehdr = (Elf32_Ehdr *) addr;
+ phdr = (Elf32_Phdr *) (addr + ehdr->e_phoff);
+
+ /* Load each program header */
+ for (i = 0; i < ehdr->e_phnum; ++i) {
+ void *dst = (void *) 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);
+ flush_cache((unsigned long)dst, phdr->p_filesz);
+ ++phdr;
+ }
+
+ return ehdr->e_entry;
+}
+
+static unsigned long load_elf_image_shdr(unsigned long addr)
{
Elf32_Ehdr *ehdr; /* Elf header structure pointer */
Elf32_Shdr *shdr; /* Section header structure pointer */
@@ -312,9 +354,11 @@ unsigned long load_elf_image (unsigned long addr)
/* ====================================================================== */
U_BOOT_CMD(
- bootelf, 2, 0, do_bootelf,
+ bootelf, 3, 0, do_bootelf,
"Boot from an ELF image in memory",
- " [address] - load address of ELF image."
+ "[-p|-s] [address]\n"
+ "\t- load ELF image at [address] via program headers (-p)\n"
+ "\t or via section headers (-s)"
);
U_BOOT_CMD(
diff --git a/common/cmd_flash.c b/common/cmd_flash.c
index 2a02eb9..4493948 100644
--- a/common/cmd_flash.c
+++ b/common/cmd_flash.c
@@ -31,7 +31,7 @@
#include <dataflash.h>
#endif
-#if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_CMD_MTDPARTS)
+#if defined(CONFIG_CMD_MTDPARTS)
#include <jffs2/jffs2.h>
/* partition handling routines */
@@ -327,7 +327,7 @@ int do_flerase (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
flash_info_t *info;
ulong bank, addr_first, addr_last;
int n, sect_first, sect_last;
-#if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_CMD_MTDPARTS)
+#if defined(CONFIG_CMD_MTDPARTS)
struct mtd_device *dev;
struct part_info *part;
u8 dev_type, dev_num, pnum;
@@ -357,7 +357,7 @@ int do_flerase (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
return rcode;
}
-#if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_CMD_MTDPARTS)
+#if defined(CONFIG_CMD_MTDPARTS)
/* erase <part-id> - erase partition */
if ((argc == 2) && (mtd_id_parse(argv[1], NULL, &dev_type, &dev_num) == 0)) {
mtdparts_init();
@@ -463,7 +463,7 @@ int do_protect (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
#if !defined(CONFIG_SYS_NO_FLASH) || defined(CONFIG_HAS_DATAFLASH)
ulong addr_first, addr_last;
#endif
-#if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_CMD_MTDPARTS)
+#if defined(CONFIG_CMD_MTDPARTS)
struct mtd_device *dev;
struct part_info *part;
u8 dev_type, dev_num, pnum;
@@ -553,7 +553,7 @@ int do_protect (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
return rcode;
}
-#if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_CMD_MTDPARTS)
+#if defined(CONFIG_CMD_MTDPARTS)
/* protect on/off <part-id> */
if ((argc == 3) && (mtd_id_parse(argv[2], NULL, &dev_type, &dev_num) == 0)) {
mtdparts_init();
@@ -681,7 +681,7 @@ int flash_sect_protect (int p, ulong addr_first, ulong addr_last)
/**************************************************/
-#if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_CMD_MTDPARTS)
+#if defined(CONFIG_CMD_MTDPARTS)
# define TMP_ERASE "erase <part-id>\n - erase partition\n"
# define TMP_PROT_ON "protect on <part-id>\n - protect partition\n"
# define TMP_PROT_OFF "protect off <part-id>\n - make partition writable\n"
diff --git a/common/cmd_mem.c b/common/cmd_mem.c
index 44834ea..f7a442a 100644
--- a/common/cmd_mem.c
+++ b/common/cmd_mem.c
@@ -337,6 +337,10 @@ int do_mem_cmp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
ngood++;
addr1 += size;
addr2 += size;
+
+ /* reset watchdog from time to time */
+ if ((count % (64 << 10)) == 0)
+ WATCHDOG_RESET();
}
printf("Total of %ld %s%s were the same\n",
@@ -447,6 +451,10 @@ int do_mem_cp ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
*((u_char *)dest) = *((u_char *)addr);
addr += size;
dest += size;
+
+ /* reset watchdog from time to time */
+ if ((count % (64 << 10)) == 0)
+ WATCHDOG_RESET();
}
return 0;
}
diff --git a/common/cmd_mtdparts.c b/common/cmd_mtdparts.c
index ceec5a9..5481c88 100644
--- a/common/cmd_mtdparts.c
+++ b/common/cmd_mtdparts.c
@@ -15,6 +15,9 @@
* Parsing routines are based on driver/mtd/cmdline.c from the linux 2.4
* kernel tree.
*
+ * (C) Copyright 2008
+ * Harald Welte, OpenMoko, Inc., Harald Welte <laforge@openmoko.org>
+ *
* $Id: cmdlinepart.c,v 1.17 2004/11/26 11:18:47 lavinen Exp $
* Copyright 2002 SYSGO Real-Time Solutions GmbH
*
@@ -286,6 +289,29 @@ static void current_save(void)
index_partitions();
}
+
+/**
+ * Produce a mtd_info given a type and num.
+ *
+ * @param type mtd type
+ * @param num mtd number
+ * @param mtd a pointer to an mtd_info instance (output)
+ * @return 0 if device is valid, 1 otherwise
+ */
+static int get_mtd_info(u8 type, u8 num, struct mtd_info **mtd)
+{
+ char mtd_dev[16];
+
+ sprintf(mtd_dev, "%s%d", MTD_DEV_TYPE(type), num);
+ *mtd = get_mtd_device_nm(mtd_dev);
+ if (IS_ERR(*mtd)) {
+ printf("Device %s not found!\n", mtd_dev);
+ return 1;
+ }
+
+ return 0;
+}
+
/**
* Performs sanity check for supplied flash partition.
* Table of existing MTD flash devices is searched and partition device
@@ -297,17 +323,12 @@ static void current_save(void)
*/
static int part_validate_eraseblock(struct mtdids *id, struct part_info *part)
{
- struct mtd_info *mtd;
- char mtd_dev[16];
+ struct mtd_info *mtd = NULL;
int i, j;
ulong start;
- sprintf(mtd_dev, "%s%d", MTD_DEV_TYPE(id->type), id->num);
- mtd = get_mtd_device_nm(mtd_dev);
- if (IS_ERR(mtd)) {
- printf("Partition %s not found on device %s!\n", part->name, mtd_dev);
+ if (get_mtd_info(id->type, id->num, &mtd))
return 1;
- }
part->sector_size = mtd->erasesize;
@@ -684,20 +705,17 @@ static int part_parse(const char *const partdef, const char **ret, struct part_i
/**
* Check device number to be within valid range for given device type.
*
- * @param dev device to validate
+ * @param type mtd type
+ * @param num mtd number
+ * @param size a pointer to the size of the mtd device (output)
* @return 0 if device is valid, 1 otherwise
*/
int mtd_device_validate(u8 type, u8 num, u32 *size)
{
- struct mtd_info *mtd;
- char mtd_dev[16];
+ struct mtd_info *mtd = NULL;
- sprintf(mtd_dev, "%s%d", MTD_DEV_TYPE(type), num);
- mtd = get_mtd_device_nm(mtd_dev);
- if (IS_ERR(mtd)) {
- printf("Device %s not found!\n", mtd_dev);
+ if (get_mtd_info(type, num, &mtd))
return 1;
- }
*size = mtd->size;
@@ -1200,38 +1218,93 @@ static int generate_mtdparts_save(char *buf, u32 buflen)
return ret;
}
+#if defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES)
/**
- * Format and print out a partition list for each device from global device
- * list.
+ * Get the net size (w/o bad blocks) of the given partition.
+ *
+ * @param mtd the mtd info
+ * @param part the partition
+ * @return the calculated net size of this partition
*/
-static void list_partitions(void)
+static uint64_t net_part_size(struct mtd_info *mtd, struct part_info *part)
+{
+ uint64_t i, net_size = 0;
+
+ if (!mtd->block_isbad)
+ return part->size;
+
+ for (i = 0; i < part->size; i += mtd->erasesize) {
+ if (!mtd->block_isbad(mtd, part->offset + i))
+ net_size += mtd->erasesize;
+ }
+
+ return net_size;
+}
+#endif
+
+static void print_partition_table(void)
{
struct list_head *dentry, *pentry;
struct part_info *part;
struct mtd_device *dev;
int part_num;
- debug("\n---list_partitions---\n");
list_for_each(dentry, &devices) {
dev = list_entry(dentry, struct mtd_device, link);
+ /* list partitions for given device */
+ part_num = 0;
+#if defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES)
+ struct mtd_info *mtd;
+
+ if (get_mtd_info(dev->id->type, dev->id->num, &mtd))
+ return;
+
+ printf("\ndevice %s%d <%s>, # parts = %d\n",
+ MTD_DEV_TYPE(dev->id->type), dev->id->num,
+ dev->id->mtd_id, dev->num_parts);
+ printf(" #: name\t\tsize\t\tnet size\toffset\t\tmask_flags\n");
+
+ list_for_each(pentry, &dev->parts) {
+ u32 net_size;
+ char *size_note;
+
+ part = list_entry(pentry, struct part_info, link);
+ net_size = net_part_size(mtd, part);
+ size_note = part->size == net_size ? " " : " (!)";
+ printf("%2d: %-20s0x%08x\t0x%08x%s\t0x%08x\t%d\n",
+ part_num, part->name, part->size,
+ net_size, size_note, part->offset,
+ part->mask_flags);
+#else /* !defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES) */
printf("\ndevice %s%d <%s>, # parts = %d\n",
MTD_DEV_TYPE(dev->id->type), dev->id->num,
dev->id->mtd_id, dev->num_parts);
printf(" #: name\t\tsize\t\toffset\t\tmask_flags\n");
- /* list partitions for given device */
- part_num = 0;
list_for_each(pentry, &dev->parts) {
part = list_entry(pentry, struct part_info, link);
printf("%2d: %-20s0x%08x\t0x%08x\t%d\n",
part_num, part->name, part->size,
part->offset, part->mask_flags);
-
+#endif /* defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES) */
part_num++;
}
}
+
if (list_empty(&devices))
printf("no partitions defined\n");
+}
+
+/**
+ * Format and print out a partition list for each device from global device
+ * list.
+ */
+static void list_partitions(void)
+{
+ struct part_info *part;
+
+ debug("\n---list_partitions---\n");
+ print_partition_table();
/* current_mtd_dev is not NULL only when we have non empty device list */
if (current_mtd_dev) {
@@ -1355,6 +1428,101 @@ static int delete_partition(const char *id)
return 1;
}
+#if defined(CONFIG_CMD_MTDPARTS_SPREAD)
+/**
+ * Increase the size of the given partition so that it's net size is at least
+ * as large as the size member and such that the next partition would start on a
+ * good block if it were adjacent to this partition.
+ *
+ * @param mtd the mtd device
+ * @param part the partition
+ * @param next_offset pointer to the offset of the next partition after this
+ * partition's size has been modified (output)
+ */
+static void spread_partition(struct mtd_info *mtd, struct part_info *part,
+ uint64_t *next_offset)
+{
+ uint64_t net_size, padding_size = 0;
+ int truncated;
+
+ mtd_get_len_incl_bad(mtd, part->offset, part->size, &net_size,
+ &truncated);
+
+ /*
+ * Absorb bad blocks immediately following this
+ * partition also into the partition, such that
+ * the next partition starts with a good block.
+ */
+ if (!truncated) {
+ mtd_get_len_incl_bad(mtd, part->offset + net_size,
+ mtd->erasesize, &padding_size, &truncated);
+ if (truncated)
+ padding_size = 0;
+ else
+ padding_size -= mtd->erasesize;
+ }
+
+ if (truncated) {
+ printf("truncated partition %s to %lld bytes\n", part->name,
+ (uint64_t) net_size + padding_size);
+ }
+
+ part->size = net_size + padding_size;
+ *next_offset = part->offset + part->size;
+}
+
+/**
+ * Adjust all of the partition sizes, such that all partitions are at least
+ * as big as their mtdparts environment variable sizes and they each start
+ * on a good block.
+ *
+ * @return 0 on success, 1 otherwise
+ */
+static int spread_partitions(void)
+{
+ struct list_head *dentry, *pentry;
+ struct mtd_device *dev;
+ struct part_info *part;
+ struct mtd_info *mtd;
+ int part_num;
+ uint64_t cur_offs;
+
+ list_for_each(dentry, &devices) {
+ dev = list_entry(dentry, struct mtd_device, link);
+
+ if (get_mtd_info(dev->id->type, dev->id->num, &mtd))
+ return 1;
+
+ part_num = 0;
+ cur_offs = 0;
+ list_for_each(pentry, &dev->parts) {
+ part = list_entry(pentry, struct part_info, link);
+
+ debug("spread_partitions: device = %s%d, partition %d ="
+ " (%s) 0x%08x@0x%08x\n",
+ MTD_DEV_TYPE(dev->id->type), dev->id->num,
+ part_num, part->name, part->size,
+ part->offset);
+
+ if (cur_offs > part->offset)
+ part->offset = cur_offs;
+
+ spread_partition(mtd, part, &cur_offs);
+
+ part_num++;
+ }
+ }
+
+ index_partitions();
+
+ if (generate_mtdparts_save(last_parts, MTDPARTS_MAXLEN) != 0) {
+ printf("generated mtdparts too long, reseting to null\n");
+ return 1;
+ }
+ return 0;
+}
+#endif /* CONFIG_CMD_MTDPARTS_SPREAD */
+
/**
* Accept character string describing mtd partitions and call device_parse()
* for each entry. Add created devices to the global devices list.
@@ -1782,9 +1950,13 @@ int do_mtdparts(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
}
/* mtdparts add <mtd-dev> <size>[@<offset>] <name> [ro] */
- if (((argc == 5) || (argc == 6)) && (strcmp(argv[1], "add") == 0)) {
+ if (((argc == 5) || (argc == 6)) && (strncmp(argv[1], "add", 3) == 0)) {
#define PART_ADD_DESC_MAXLEN 64
char tmpbuf[PART_ADD_DESC_MAXLEN];
+#if defined(CONFIG_CMD_MTDPARTS_SPREAD)
+ struct mtd_info *mtd;
+ uint64_t next_offset;
+#endif
u8 type, num, len;
struct mtd_device *dev;
struct mtd_device *dev_tmp;
@@ -1819,15 +1991,25 @@ int do_mtdparts(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
debug("+ %s\t%d\t%s\n", MTD_DEV_TYPE(dev->id->type),
dev->id->num, dev->id->mtd_id);
- if ((dev_tmp = device_find(dev->id->type, dev->id->num)) == NULL) {
+ p = list_entry(dev->parts.next, struct part_info, link);
+
+#if defined(CONFIG_CMD_MTDPARTS_SPREAD)
+ if (get_mtd_info(dev->id->type, dev->id->num, &mtd))
+ return 1;
+
+ if (!strcmp(&argv[1][3], ".spread")) {
+ spread_partition(mtd, p, &next_offset);
+ debug("increased %s to %d bytes\n", p->name, p->size);
+ }
+#endif
+
+ dev_tmp = device_find(dev->id->type, dev->id->num);
+ if (dev_tmp == NULL) {
device_add(dev);
- } else {
+ } else if (part_add(dev_tmp, p) != 0) {
/* merge new partition with existing ones*/
- p = list_entry(dev->parts.next, struct part_info, link);
- if (part_add(dev_tmp, p) != 0) {
- device_del(dev);
- return 1;
- }
+ device_del(dev);
+ return 1;
}
if (generate_mtdparts_save(last_parts, MTDPARTS_MAXLEN) != 0) {
@@ -1845,6 +2027,11 @@ int do_mtdparts(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
return delete_partition(argv[2]);
}
+#if defined(CONFIG_CMD_MTDPARTS_SPREAD)
+ if ((argc == 2) && (strcmp(argv[1], "spread") == 0))
+ return spread_partitions();
+#endif /* CONFIG_CMD_MTDPARTS_SPREAD */
+
return cmd_usage(cmdtp);
}
@@ -1867,8 +2054,20 @@ U_BOOT_CMD(
" - delete partition (e.g. part-id = nand0,1)\n"
"mtdparts add <mtd-dev> <size>[@<offset>] [<name>] [ro]\n"
" - add partition\n"
+#if defined(CONFIG_CMD_MTDPARTS_SPREAD)
+ "mtdparts add.spread <mtd-dev> <size>[@<offset>] [<name>] [ro]\n"
+ " - add partition, padding size by skipping bad blocks\n"
+#endif
"mtdparts default\n"
- " - reset partition table to defaults\n\n"
+ " - reset partition table to defaults\n"
+#if defined(CONFIG_CMD_MTDPARTS_SPREAD)
+ "mtdparts spread\n"
+ " - adjust the sizes of the partitions so they are\n"
+ " at least as big as the mtdparts variable specifies\n"
+ " and they each start on a good block\n\n"
+#else
+ "\n"
+#endif /* CONFIG_CMD_MTDPARTS_SPREAD */
"-----\n\n"
"this command uses three environment variables:\n\n"
"'partition' - keeps current partition identifier\n\n"
diff --git a/common/cmd_nand.c b/common/cmd_nand.c
index 3f1d077..8a81237 100644
--- a/common/cmd_nand.c
+++ b/common/cmd_nand.c
@@ -10,6 +10,13 @@
* (C) Copyright 2006-2007 OpenMoko, Inc.
* Added 16-bit nand support
* (C) 2004 Texas Instruments
+ *
+ * Copyright 2010 Freescale Semiconductor
+ * The portions of this file whose copyright is held by Freescale and which
+ * are not considered a derived work of GPL v2-only code may be distributed
+ * and/or modified 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.
*/
#include <common.h>
@@ -30,10 +37,16 @@ int find_dev_and_part(const char *id, struct mtd_device **dev,
u8 *part_num, struct part_info **part);
#endif
-static int nand_dump(nand_info_t *nand, ulong off, int only_oob)
+static int nand_dump(nand_info_t *nand, ulong off, int only_oob, int repeat)
{
int i;
u_char *datbuf, *oobbuf, *p;
+ static loff_t last;
+
+ if (repeat)
+ off = last + nand->writesize;
+
+ last = off;
datbuf = malloc(nand->writesize + nand->oobsize);
oobbuf = malloc(nand->oobsize);
@@ -85,74 +98,132 @@ static int nand_dump(nand_info_t *nand, ulong off, int only_oob)
/* ------------------------------------------------------------------------- */
-static inline int str2long(char *p, ulong *num)
+static int set_dev(int dev)
+{
+ if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE ||
+ !nand_info[dev].name) {
+ puts("No such device\n");
+ return -1;
+ }
+
+ if (nand_curr_device == dev)
+ return 0;
+
+ printf("Device %d: %s", dev, nand_info[dev].name);
+ puts("... is now current device\n");
+ nand_curr_device = dev;
+
+#ifdef CONFIG_SYS_NAND_SELECT_DEVICE
+ board_nand_select_device(nand_info[dev].priv, dev);
+#endif
+
+ return 0;
+}
+
+static inline int str2off(const char *p, loff_t *num)
+{
+ char *endptr;
+
+ *num = simple_strtoull(p, &endptr, 16);
+ return *p != '\0' && *endptr == '\0';
+}
+
+static inline int str2long(const char *p, ulong *num)
{
char *endptr;
*num = simple_strtoul(p, &endptr, 16);
- return (*p != '\0' && *endptr == '\0') ? 1 : 0;
+ return *p != '\0' && *endptr == '\0';
}
-static int
-arg_off_size(int argc, char * const argv[], nand_info_t *nand, ulong *off, size_t *size)
+static int get_part(const char *partname, int *idx, loff_t *off, loff_t *size)
{
- int idx = nand_curr_device;
-#if defined(CONFIG_CMD_MTDPARTS)
+#ifdef CONFIG_CMD_MTDPARTS
struct mtd_device *dev;
struct part_info *part;
u8 pnum;
+ int ret;
- if (argc >= 1 && !(str2long(argv[0], off))) {
- if ((mtdparts_init() == 0) &&
- (find_dev_and_part(argv[0], &dev, &pnum, &part) == 0)) {
- if (dev->id->type != MTD_DEV_TYPE_NAND) {
- puts("not a NAND device\n");
- return -1;
- }
- *off = part->offset;
- if (argc >= 2) {
- if (!(str2long(argv[1], (ulong *)size))) {
- printf("'%s' is not a number\n", argv[1]);
- return -1;
- }
- if (*size > part->size)
- *size = part->size;
- } else {
- *size = part->size;
- }
- idx = dev->id->num;
- *nand = nand_info[idx];
- goto out;
- }
+ ret = mtdparts_init();
+ if (ret)
+ return ret;
+
+ ret = find_dev_and_part(partname, &dev, &pnum, &part);
+ if (ret)
+ return ret;
+
+ if (dev->id->type != MTD_DEV_TYPE_NAND) {
+ puts("not a NAND device\n");
+ return -1;
}
+
+ *off = part->offset;
+ *size = part->size;
+ *idx = dev->id->num;
+
+ ret = set_dev(*idx);
+ if (ret)
+ return ret;
+
+ return 0;
+#else
+ puts("offset is not a number\n");
+ return -1;
#endif
+}
- if (argc >= 1) {
- if (!(str2long(argv[0], off))) {
- printf("'%s' is not a number\n", argv[0]);
- return -1;
- }
- } else {
+static int arg_off(const char *arg, int *idx, loff_t *off, loff_t *maxsize)
+{
+ if (!str2off(arg, off))
+ return get_part(arg, idx, off, maxsize);
+
+ if (*off >= nand_info[*idx].size) {
+ puts("Offset exceeds device limit\n");
+ return -1;
+ }
+
+ *maxsize = nand_info[*idx].size - *off;
+ return 0;
+}
+
+static int arg_off_size(int argc, char *const argv[], int *idx,
+ loff_t *off, loff_t *size)
+{
+ int ret;
+ loff_t maxsize;
+
+ if (argc == 0) {
*off = 0;
+ *size = nand_info[*idx].size;
+ goto print;
}
- if (argc >= 2) {
- if (!(str2long(argv[1], (ulong *)size))) {
- printf("'%s' is not a number\n", argv[1]);
- return -1;
- }
- } else {
- *size = nand->size - *off;
+ ret = arg_off(argv[0], idx, off, &maxsize);
+ if (ret)
+ return ret;
+
+ if (argc == 1) {
+ *size = maxsize;
+ goto print;
}
-#if defined(CONFIG_CMD_MTDPARTS)
-out:
-#endif
- printf("device %d ", idx);
- if (*size == nand->size)
+ if (!str2off(argv[1], size)) {
+ printf("'%s' is not a number\n", argv[1]);
+ return -1;
+ }
+
+ if (*size > maxsize) {
+ puts("Size exceeds partition or device limit\n");
+ return -1;
+ }
+
+print:
+ printf("device %d ", *idx);
+ if (*size == nand_info[*idx].size)
puts("whole chip\n");
else
- printf("offset 0x%lx, size 0x%zx\n", *off, *size);
+ printf("offset 0x%llx, size 0x%llx\n",
+ (unsigned long long)*off, (unsigned long long)*size);
return 0;
}
@@ -200,14 +271,20 @@ static void do_nand_status(nand_info_t *nand)
#ifdef CONFIG_ENV_OFFSET_OOB
unsigned long nand_env_oob_offset;
-int do_nand_env_oob(cmd_tbl_t *cmdtp, nand_info_t *nand,
- int argc, char * const argv[])
+int do_nand_env_oob(cmd_tbl_t *cmdtp, int argc, char *const argv[])
{
int ret;
uint32_t oob_buf[ENV_OFFSET_SIZE/sizeof(uint32_t)];
-
+ nand_info_t *nand = &nand_info[0];
char *cmd = argv[1];
+ if (CONFIG_SYS_MAX_NAND_DEVICE == 0 || !nand->name) {
+ puts("no devices available\n");
+ return 1;
+ }
+
+ set_dev(0);
+
if (!strcmp(cmd, "get")) {
ret = get_nand_env_oob(nand, &nand_env_oob_offset);
if (ret)
@@ -215,16 +292,21 @@ int do_nand_env_oob(cmd_tbl_t *cmdtp, nand_info_t *nand,
printf("0x%08lx\n", nand_env_oob_offset);
} else if (!strcmp(cmd, "set")) {
- ulong addr;
- size_t dummy_size;
+ loff_t addr;
+ loff_t maxsize;
struct mtd_oob_ops ops;
+ int idx = 0;
if (argc < 3)
goto usage;
- if (arg_off_size(argc - 2, argv + 2, nand, &addr,
- &dummy_size) < 0) {
- printf("Offset or partition name expected\n");
+ if (arg_off(argv[2], &idx, &addr, &maxsize)) {
+ puts("Offset or partition name expected\n");
+ return 1;
+ }
+
+ if (idx != 0) {
+ puts("Partition not on first NAND device\n");
return 1;
}
@@ -264,8 +346,8 @@ int do_nand_env_oob(cmd_tbl_t *cmdtp, nand_info_t *nand,
if (addr != nand_env_oob_offset) {
printf("Verification of env offset in OOB failed: "
- "0x%08lx expected but got 0x%08lx\n",
- addr, nand_env_oob_offset);
+ "0x%08llx expected but got 0x%08lx\n",
+ (unsigned long long)addr, nand_env_oob_offset);
return 1;
}
} else {
@@ -293,9 +375,9 @@ static void nand_print_info(int idx)
int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
{
- int i, dev, ret = 0;
- ulong addr, off;
- size_t size;
+ int i, ret = 0;
+ ulong addr;
+ loff_t off, size;
char *cmd, *s;
nand_info_t *nand;
#ifdef CONFIG_SYS_NAND_QUIET
@@ -304,6 +386,8 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
int quiet = 0;
#endif
const char *quiet_str = getenv("quiet");
+ int dev = nand_curr_device;
+ int repeat = flag & CMD_FLAG_REPEAT;
/* at least two arguments please */
if (argc < 2)
@@ -314,6 +398,10 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
cmd = argv[1];
+ /* Only "dump" is repeatable. */
+ if (repeat && strcmp(cmd, "dump"))
+ return 0;
+
if (strcmp(cmd, "info") == 0) {
putc('\n');
@@ -325,68 +413,45 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
}
if (strcmp(cmd, "device") == 0) {
-
if (argc < 3) {
putc('\n');
- if ((nand_curr_device < 0) ||
- (nand_curr_device >= CONFIG_SYS_MAX_NAND_DEVICE))
+ if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE)
puts("no devices available\n");
else
- nand_print_info(nand_curr_device);
+ nand_print_info(dev);
return 0;
}
- dev = (int)simple_strtoul(argv[2], NULL, 10);
- if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE || !nand_info[dev].name) {
- puts("No such device\n");
- return 1;
- }
- printf("Device %d: %s", dev, nand_info[dev].name);
- puts("... is now current device\n");
- nand_curr_device = dev;
-#ifdef CONFIG_SYS_NAND_SELECT_DEVICE
- /*
- * Select the chip in the board/cpu specific driver
- */
- board_nand_select_device(nand_info[dev].priv, dev);
-#endif
+ dev = (int)simple_strtoul(argv[2], NULL, 10);
+ set_dev(dev);
return 0;
}
- if (strcmp(cmd, "bad") != 0 && strcmp(cmd, "erase") != 0 &&
- strncmp(cmd, "dump", 4) != 0 &&
- strncmp(cmd, "read", 4) != 0 && strncmp(cmd, "write", 5) != 0 &&
- strcmp(cmd, "scrub") != 0 && strcmp(cmd, "markbad") != 0 &&
- strcmp(cmd, "biterr") != 0 &&
- strcmp(cmd, "lock") != 0 && strcmp(cmd, "unlock") != 0
-#ifdef CONFIG_ENV_OFFSET_OOB
- && strcmp(cmd, "env.oob") != 0
-#endif
- )
- goto usage;
-
#ifdef CONFIG_ENV_OFFSET_OOB
/* this command operates only on the first nand device */
- if (strcmp(cmd, "env.oob") == 0) {
- return do_nand_env_oob(cmdtp, &nand_info[0],
- argc - 1, argv + 1);
- }
+ if (strcmp(cmd, "env.oob") == 0)
+ return do_nand_env_oob(cmdtp, argc - 1, argv + 1);
#endif
- /* the following commands operate on the current device */
- if (nand_curr_device < 0 || nand_curr_device >= CONFIG_SYS_MAX_NAND_DEVICE ||
- !nand_info[nand_curr_device].name) {
+ /* The following commands operate on the current device, unless
+ * overridden by a partition specifier. Note that if somehow the
+ * current device is invalid, it will have to be changed to a valid
+ * one before these commands can run, even if a partition specifier
+ * for another device is to be used.
+ */
+ if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE ||
+ !nand_info[dev].name) {
puts("\nno devices available\n");
return 1;
}
- nand = &nand_info[nand_curr_device];
+ nand = &nand_info[dev];
if (strcmp(cmd, "bad") == 0) {
- printf("\nDevice %d bad blocks:\n", nand_curr_device);
+ printf("\nDevice %d bad blocks:\n", dev);
for (off = 0; off < nand->size; off += nand->erasesize)
if (nand_block_isbad(nand, off))
- printf(" %08lx\n", off);
+ printf(" %08llx\n", (unsigned long long)off);
return 0;
}
@@ -395,23 +460,52 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
* 0 1 2 3 4
* nand erase [clean] [off size]
*/
- if (strcmp(cmd, "erase") == 0 || strcmp(cmd, "scrub") == 0) {
+ if (strncmp(cmd, "erase", 5) == 0 || strncmp(cmd, "scrub", 5) == 0) {
nand_erase_options_t opts;
/* "clean" at index 2 means request to write cleanmarker */
int clean = argc > 2 && !strcmp("clean", argv[2]);
int o = clean ? 3 : 2;
- int scrub = !strcmp(cmd, "scrub");
+ int scrub = !strncmp(cmd, "scrub", 5);
+ int part = 0;
+ int chip = 0;
+ int spread = 0;
+ int args = 2;
+
+ if (cmd[5] != 0) {
+ if (!strcmp(&cmd[5], ".spread")) {
+ spread = 1;
+ } else if (!strcmp(&cmd[5], ".part")) {
+ part = 1;
+ args = 1;
+ } else if (!strcmp(&cmd[5], ".chip")) {
+ chip = 1;
+ args = 0;
+ } else {
+ goto usage;
+ }
+ }
+
+ /*
+ * Don't allow missing arguments to cause full chip/partition
+ * erases -- easy to do accidentally, e.g. with a misspelled
+ * variable name.
+ */
+ if (argc != o + args)
+ goto usage;
- printf("\nNAND %s: ", scrub ? "scrub" : "erase");
+ printf("\nNAND %s: ", cmd);
/* skip first two or three arguments, look for offset and size */
- if (arg_off_size(argc - o, argv + o, nand, &off, &size) != 0)
+ if (arg_off_size(argc - o, argv + o, &dev, &off, &size) != 0)
return 1;
+ nand = &nand_info[dev];
+
memset(&opts, 0, sizeof(opts));
opts.offset = off;
opts.length = size;
opts.jffs2 = clean;
opts.quiet = quiet;
+ opts.spread = spread;
if (scrub) {
puts("Warning: "
@@ -449,19 +543,14 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
if (argc < 3)
goto usage;
- s = strchr(cmd, '.');
off = (int)simple_strtoul(argv[2], NULL, 16);
-
- if (s != NULL && strcmp(s, ".oob") == 0)
- ret = nand_dump(nand, off, 1);
- else
- ret = nand_dump(nand, off, 0);
+ ret = nand_dump(nand, off, !strcmp(&cmd[4], ".oob"), repeat);
return ret == 0 ? 1 : 0;
-
}
if (strncmp(cmd, "read", 4) == 0 || strncmp(cmd, "write", 5) == 0) {
+ size_t rwsize;
int read;
if (argc < 4)
@@ -471,23 +560,26 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
read = strncmp(cmd, "read", 4) == 0; /* 1 = read, 0 = write */
printf("\nNAND %s: ", read ? "read" : "write");
- if (arg_off_size(argc - 3, argv + 3, nand, &off, &size) != 0)
+ if (arg_off_size(argc - 3, argv + 3, &dev, &off, &size) != 0)
return 1;
+ nand = &nand_info[dev];
+ rwsize = size;
+
s = strchr(cmd, '.');
if (!s || !strcmp(s, ".jffs2") ||
!strcmp(s, ".e") || !strcmp(s, ".i")) {
if (read)
- ret = nand_read_skip_bad(nand, off, &size,
+ ret = nand_read_skip_bad(nand, off, &rwsize,
(u_char *)addr);
else
- ret = nand_write_skip_bad(nand, off, &size,
+ ret = nand_write_skip_bad(nand, off, &rwsize,
(u_char *)addr);
} else if (!strcmp(s, ".oob")) {
/* out-of-band data */
mtd_oob_ops_t ops = {
.oobbuf = (u8 *)addr,
- .ooblen = size,
+ .ooblen = rwsize,
.mode = MTD_OOB_RAW
};
@@ -500,7 +592,7 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
return 1;
}
- printf(" %zu bytes %s: %s\n", size,
+ printf(" %zu bytes %s: %s\n", rwsize,
read ? "read" : "written", ret ? "ERROR" : "OK");
return ret == 0 ? 0 : 1;
@@ -564,7 +656,7 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
if (arg_off_size(argc - 2, argv + 2, nand, &off, &size) < 0)
return 1;
- if (!nand_unlock(nand, off, size)) {
+ if (!nand_unlock(&nand_info[dev], off, size)) {
puts("NAND flash successfully unlocked\n");
} else {
puts("Error unlocking NAND flash, "
@@ -588,11 +680,16 @@ U_BOOT_CMD(
"nand write - addr off|partition size\n"
" read/write 'size' bytes starting at offset 'off'\n"
" to/from memory address 'addr', skipping bad blocks.\n"
- "nand erase [clean] [off size] - erase 'size' bytes from\n"
- " offset 'off' (entire device if not specified)\n"
+ "nand erase[.spread] [clean] [off [size]] - erase 'size' bytes "
+ "from offset 'off'\n"
+ " With '.spread', erase enough for given file size, otherwise,\n"
+ " 'size' includes skipped bad blocks.\n"
+ "nand erase.part [clean] partition - erase entire mtd partition'\n"
+ "nand erase.chip [clean] - erase entire chip'\n"
"nand bad - show bad blocks\n"
"nand dump[.oob] off - dump page\n"
- "nand scrub - really clean NAND erasing bad blocks (UNSAFE)\n"
+ "nand scrub off size | scrub.part partition | scrub.chip\n"
+ " really clean NAND erasing bad blocks (UNSAFE)\n"
"nand markbad off [...] - mark bad block(s) at offset (UNSAFE)\n"
"nand biterr off - make a bit error at offset (UNSAFE)"
#ifdef CONFIG_CMD_NAND_LOCK_UNLOCK
diff --git a/common/cmd_net.c b/common/cmd_net.c
index 3ffb9df..44d17db 100644
--- a/common/cmd_net.c
+++ b/common/cmd_net.c
@@ -54,6 +54,7 @@ U_BOOT_CMD(
"[loadAddress] [[hostIPaddr:]bootfilename]"
);
+#ifdef CONFIG_CMD_RARP
int do_rarpb (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
return netboot_common (RARP, cmdtp, argc, argv);
@@ -64,6 +65,7 @@ U_BOOT_CMD(
"boot image via network using RARP/TFTP protocol",
"[loadAddress] [[hostIPaddr:]bootfilename]"
);
+#endif
#if defined(CONFIG_CMD_DHCP)
int do_dhcp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index c3d63b8..3d30c32 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -837,6 +837,13 @@ static cmd_tbl_t cmd_env_sub[] = {
U_BOOT_CMD_MKENT(set, CONFIG_SYS_MAXARGS, 0, do_env_set, "", ""),
};
+#if !defined(CONFIG_RELOC_FIXUP_WORKS)
+void env_reloc(void)
+{
+ fixup_cmdtable(cmd_env_sub, ARRAY_SIZE(cmd_env_sub));
+}
+#endif
+
static int do_env (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
cmd_tbl_t *cp;
diff --git a/common/cmd_otp.c b/common/cmd_otp.c
index 56f08e0..eb93eb2 100644
--- a/common/cmd_otp.c
+++ b/common/cmd_otp.c
@@ -82,6 +82,7 @@ static void set_otp_timing(bool write)
int do_otp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
+ char *cmd;
uint32_t ret, base_flags;
bool prompt_user, force_read;
uint32_t (*otp_func)(uint32_t page, uint32_t flags, uint64_t *page_content);
@@ -93,21 +94,21 @@ int do_otp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
prompt_user = false;
base_flags = 0;
- if (!strcmp(argv[1], "read"))
+ cmd = argv[1];
+ if (!strcmp(cmd, "read"))
otp_func = bfrom_OtpRead;
- else if (!strcmp(argv[1], "dump")) {
+ else if (!strcmp(cmd, "dump")) {
otp_func = bfrom_OtpRead;
force_read = true;
- } else if (!strcmp(argv[1], "write")) {
+ } else if (!strcmp(cmd, "write")) {
otp_func = bfrom_OtpWrite;
base_flags = OTP_CHECK_FOR_PREV_WRITE;
if (!strcmp(argv[2], "--force")) {
- argv[2] = argv[1];
argv++;
--argc;
} else
prompt_user = false;
- } else if (!strcmp(argv[1], "lock")) {
+ } else if (!strcmp(cmd, "lock")) {
if (argc != 4)
goto usage;
otp_func = bfrom_OtpWrite;
@@ -175,7 +176,7 @@ int do_otp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
}
printf("OTP memory %s: addr 0x%p page 0x%03X count %zu ... ",
- argv[1], addr, page, count);
+ cmd, addr, page, count);
set_otp_timing(otp_func == bfrom_OtpWrite);
if (otp_func == bfrom_OtpWrite && check_voltage()) {
diff --git a/common/cmd_spi.c b/common/cmd_spi.c
index bafa217..8c623c9 100644
--- a/common/cmd_spi.c
+++ b/common/cmd_spi.c
@@ -47,7 +47,9 @@
/*
* Values from last command.
*/
-static unsigned int device;
+static unsigned int bus;
+static unsigned int cs;
+static unsigned int mode;
static int bitlen;
static uchar dout[MAX_SPI_BYTES];
static uchar din[MAX_SPI_BYTES];
@@ -78,8 +80,18 @@ int do_spi (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
if ((flag & CMD_FLAG_REPEAT) == 0)
{
- if (argc >= 2)
- device = simple_strtoul(argv[1], NULL, 10);
+ if (argc >= 2) {
+ mode = CONFIG_DEFAULT_SPI_MODE;
+ bus = simple_strtoul(argv[1], &cp, 10);
+ if (*cp == ':') {
+ cs = simple_strtoul(cp+1, &cp, 10);
+ } else {
+ cs = bus;
+ bus = CONFIG_DEFAULT_SPI_BUS;
+ }
+ if (*cp == '.');
+ mode = simple_strtoul(cp+1, NULL, 10);
+ }
if (argc >= 3)
bitlen = simple_strtoul(argv[2], NULL, 10);
if (argc >= 4) {
@@ -91,7 +103,7 @@ int do_spi (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
if(tmp > 15)
tmp -= ('a' - 'A');
if(tmp > 15) {
- printf("Hex conversion error on %c, giving up.\n", *cp);
+ printf("Hex conversion error on %c\n", *cp);
return 1;
}
if((j % 2) == 0)
@@ -103,24 +115,20 @@ int do_spi (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
}
if ((bitlen < 0) || (bitlen > (MAX_SPI_BYTES * 8))) {
- printf("Invalid bitlen %d, giving up.\n", bitlen);
+ printf("Invalid bitlen %d\n", bitlen);
return 1;
}
- /* FIXME: Make these parameters run-time configurable */
- slave = spi_setup_slave(CONFIG_DEFAULT_SPI_BUS, device, 1000000,
- CONFIG_DEFAULT_SPI_MODE);
+ slave = spi_setup_slave(bus, cs, 1000000, mode);
if (!slave) {
- printf("Invalid device %d, giving up.\n", device);
+ printf("Invalid device %d:%d\n", bus, cs);
return 1;
}
- debug ("spi chipsel = %08X\n", device);
-
spi_claim_bus(slave);
if(spi_xfer(slave, bitlen, dout, din,
SPI_XFER_BEGIN | SPI_XFER_END) != 0) {
- printf("Error with the SPI transaction.\n");
+ printf("Error during SPI transaction\n");
rcode = 1;
} else {
for(j = 0; j < ((bitlen + 7) / 8); j++) {
@@ -138,9 +146,11 @@ int do_spi (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
U_BOOT_CMD(
sspi, 5, 1, do_spi,
- "SPI utility commands",
- "<device> <bit_len> <dout> - Send <bit_len> bits from <dout> out the SPI\n"
- "<device> - Identifies the chip select of the device\n"
+ "SPI utility command",
+ "[<bus>:]<cs>[.<mode>] <bit_len> <dout> - Send and receive bits\n"
+ "<bus> - Identifies the SPI bus\n"
+ "<cs> - Identifies the chip select\n"
+ "<mode> - Identifies the SPI mode to use\n"
"<bit_len> - Number of bits to send (base 10)\n"
"<dout> - Hexadecimal string that gets sent"
);
diff --git a/common/cmd_tsi148.c b/common/cmd_tsi148.c
index 1e83c88..6dc9dab 100644
--- a/common/cmd_tsi148.c
+++ b/common/cmd_tsi148.c
@@ -419,7 +419,7 @@ int do_tsi148(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
if (argc > 5)
vam = simple_strtoul(argv[5], NULL, 16);
if (argc > 6)
- vdw = simple_strtoul(argv[7], NULL, 16);
+ vdw = simple_strtoul(argv[6], NULL, 16);
switch (cmd) {
case 'c':
@@ -465,7 +465,7 @@ int do_tsi148(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
}
U_BOOT_CMD(
- tsi148, 8, 1, do_tsi148,
+ tsi148, 7, 1, do_tsi148,
"initialize and configure Turndra Tsi148\n",
"init\n"
" - initialize tsi148\n"
diff --git a/common/env_common.c b/common/env_common.c
index a415ef8..5acda4d 100644
--- a/common/env_common.c
+++ b/common/env_common.c
@@ -227,13 +227,18 @@ int env_import(const char *buf, int check)
void env_relocate (void)
{
+#if !defined(CONFIG_RELOC_FIXUP_WORKS)
+ extern void env_reloc(void);
+
+ env_reloc();
+#endif
if (gd->env_valid == 0) {
#if defined(CONFIG_ENV_IS_NOWHERE) /* Environment not changable */
set_default_env(NULL);
#else
show_boot_progress (-60);
-#endif
set_default_env("!bad CRC");
+#endif
} else {
env_relocate_spec ();
}
diff --git a/common/env_mmc.c b/common/env_mmc.c
index 14203b6..d443ff5 100644
--- a/common/env_mmc.c
+++ b/common/env_mmc.c
@@ -129,25 +129,27 @@ inline int read_env(struct mmc *mmc, unsigned long size,
void env_relocate_spec(void)
{
#if !defined(ENV_IS_EMBEDDED)
+ char buf[CONFIG_ENV_SIZE];
+
struct mmc *mmc = find_mmc_device(CONFIG_SYS_MMC_ENV_DEV);
- if (init_mmc_for_env(mmc))
+ if (init_mmc_for_env(mmc)) {
+ use_default();
return;
+ }
- if (read_env(mmc, CONFIG_ENV_SIZE, CONFIG_ENV_OFFSET, env_ptr))
- return use_default();
-
- if (crc32(0, env_ptr->data, ENV_SIZE) != env_ptr->crc)
- return use_default();
+ if (read_env(mmc, CONFIG_ENV_SIZE, CONFIG_ENV_OFFSET, buf)) {
+ use_default();
+ return;
+ }
- gd->env_valid = 1;
+ env_import(buf, 1);
#endif
}
#if !defined(ENV_IS_EMBEDDED)
static void use_default()
{
- puts ("*** Warning - bad CRC or MMC, using default environment\n\n");
- set_default_env();
+ set_default_env(NULL);
}
#endif
diff --git a/common/fdt_support.c b/common/fdt_support.c
index 6f32e3f..b8a3dc9 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -620,7 +620,7 @@ int fdt_fixup_nor_flash_size(void *blob)
int off;
int len;
struct fdt_property *prop;
- u32 *reg;
+ u32 *reg, *reg2;
int i;
for (i = 0; i < 2; i++) {
@@ -640,18 +640,21 @@ int fdt_fixup_nor_flash_size(void *blob)
* There might be multiple reg-tuples,
* so loop through them all
*/
- len /= tuple_size;
- reg = (u32 *)&prop->data[0];
- for (idx = 0; idx < len; idx++) {
+ reg = reg2 = (u32 *)&prop->data[0];
+ for (idx = 0; idx < (len / tuple_size); idx++) {
/*
* Update size in reg property
*/
reg[2] = flash_get_bank_size(reg[0],
idx);
- fdt_setprop(blob, off, "reg", reg,
- tuple_size);
- reg += tuple_size;
+
+ /*
+ * Point to next reg tuple
+ */
+ reg += 3;
}
+
+ fdt_setprop(blob, off, "reg", reg2, len);
}
/* Move to next compatible node */
@@ -664,6 +667,16 @@ int fdt_fixup_nor_flash_size(void *blob)
}
#endif
+int fdt_increase_size(void *fdt, int add_len)
+{
+ int newlen;
+
+ newlen = fdt_totalsize(fdt) + add_len;
+
+ /* Open in place with a new len */
+ return fdt_open_into(fdt, fdt, newlen);
+}
+
#ifdef CONFIG_FDT_FIXUP_PARTITIONS
#include <jffs2/load_kernel.h>
#include <mtd_node.h>
@@ -698,16 +711,6 @@ int fdt_del_subnodes(const void *blob, int parent_offset)
return 0;
}
-int fdt_increase_size(void *fdt, int add_len)
-{
- int newlen;
-
- newlen = fdt_totalsize(fdt) + add_len;
-
- /* Open in place with a new len */
- return fdt_open_into(fdt, fdt, newlen);
-}
-
int fdt_del_partitions(void *blob, int parent_offset)
{
const void *prop;
@@ -1186,3 +1189,32 @@ int fdt_alloc_phandle(void *blob)
return phandle + 1;
}
+
+#if defined(CONFIG_VIDEO)
+int fdt_add_edid(void *blob, const char *compat, unsigned char *edid_buf)
+{
+ int noff;
+ int ret;
+
+ noff = fdt_node_offset_by_compatible(blob, -1, compat);
+ if (noff != -FDT_ERR_NOTFOUND) {
+ debug("%s: %s\n", fdt_get_name(blob, noff, 0), compat);
+add_edid:
+ ret = fdt_setprop(blob, noff, "edid", edid_buf, 128);
+ if (ret == -FDT_ERR_NOSPACE) {
+ ret = fdt_increase_size(blob, 512);
+ if (!ret)
+ goto add_edid;
+ else
+ goto err_size;
+ } else if (ret < 0) {
+ printf("Can't add property: %s\n", fdt_strerror(ret));
+ return ret;
+ }
+ }
+ return 0;
+err_size:
+ printf("Can't increase blob size: %s\n", fdt_strerror(ret));
+ return ret;
+}
+#endif
diff --git a/common/main.c b/common/main.c
index 8d548db..d97ccd7 100644
--- a/common/main.c
+++ b/common/main.c
@@ -518,9 +518,6 @@ void reset_cmd_timeout(void)
} while (0)
#define CTL_CH(c) ((c) - 'a' + 1)
-
-#define MAX_CMDBUF_SIZE CONFIG_SYS_CBSIZE
-
#define CTL_BACKSPACE ('\b')
#define DEL ((char)255)
#define DEL7 ((char)127)
@@ -531,7 +528,7 @@ void reset_cmd_timeout(void)
#define getcmd_cbeep() getcmd_putch('\a')
#define HIST_MAX 20
-#define HIST_SIZE MAX_CMDBUF_SIZE
+#define HIST_SIZE CONFIG_SYS_CBSIZE
static int hist_max = 0;
static int hist_add_idx = 0;
@@ -947,7 +944,7 @@ int readline_into_buffer (const char *const prompt, char * buffer)
{
char *p = buffer;
#ifdef CONFIG_CMDLINE_EDITING
- unsigned int len=MAX_CMDBUF_SIZE;
+ unsigned int len = CONFIG_SYS_CBSIZE;
int rc;
static int initted = 0;
diff --git a/common/serial.c b/common/serial.c
index 25b235a..7bebc12 100644
--- a/common/serial.c
+++ b/common/serial.c
@@ -54,6 +54,7 @@ struct serial_device *__default_serial_console (void)
#else
#error "Bad CONFIG_CONS_INDEX."
#endif
+#else
return &serial0_device;
#endif
#elif defined(CONFIG_MPC512X)
diff --git a/common/usb_storage.c b/common/usb_storage.c
index 76949b8..613c4f0 100644
--- a/common/usb_storage.c
+++ b/common/usb_storage.c
@@ -204,6 +204,22 @@ int usb_stor_info(void)
return 1;
}
+static unsigned int usb_get_max_lun(struct us_data *us)
+{
+ int len;
+ unsigned char result;
+ len = usb_control_msg(us->pusb_dev,
+ usb_rcvctrlpipe(us->pusb_dev, 0),
+ US_BBB_GET_MAX_LUN,
+ USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
+ 0, us->ifnum,
+ &result, sizeof(result),
+ USB_CNTL_TIMEOUT * 5);
+ USB_STOR_PRINTF("Get Max LUN -> len = %i, result = %i\n",
+ len, (int) result);
+ return (len > 0) ? result : 0;
+}
+
/*******************************************************************************
* scan the usb and reports device info
* to the user if mode = 1
@@ -241,13 +257,22 @@ int usb_stor_scan(int mode)
break; /* no more devices avaiable */
if (usb_storage_probe(dev, 0, &usb_stor[usb_max_devs])) {
- /* ok, it is a storage devices
- * get info and fill it in
+ /* OK, it's a storage device. Iterate over its LUNs
+ * and populate `usb_dev_desc'.
*/
- if (usb_stor_get_info(dev, &usb_stor[usb_max_devs],
- &usb_dev_desc[usb_max_devs]) == 1)
+ int lun, max_lun, start = usb_max_devs;
+
+ max_lun = usb_get_max_lun(&usb_stor[usb_max_devs]);
+ for (lun = 0;
+ lun <= max_lun && usb_max_devs < USB_MAX_STOR_DEV;
+ lun++) {
+ usb_dev_desc[usb_max_devs].lun = lun;
+ if (usb_stor_get_info(dev, &usb_stor[start],
+ &usb_dev_desc[usb_max_devs]) == 1) {
usb_max_devs++;
}
+ }
+ }
/* if storage device */
if (usb_max_devs == USB_MAX_STOR_DEV) {
printf("max USB Storage Device reached: %d stopping\n",
@@ -882,6 +907,7 @@ static int usb_inquiry(ccb *srb, struct us_data *ss)
do {
memset(&srb->cmd[0], 0, 12);
srb->cmd[0] = SCSI_INQUIRY;
+ srb->cmd[1] = srb->lun << 5;
srb->cmd[4] = 36;
srb->datalen = 36;
srb->cmdlen = 12;
@@ -905,6 +931,7 @@ static int usb_request_sense(ccb *srb, struct us_data *ss)
ptr = (char *)srb->pdata;
memset(&srb->cmd[0], 0, 12);
srb->cmd[0] = SCSI_REQ_SENSE;
+ srb->cmd[1] = srb->lun << 5;
srb->cmd[4] = 18;
srb->datalen = 18;
srb->pdata = &srb->sense_buf[0];
@@ -924,6 +951,7 @@ static int usb_test_unit_ready(ccb *srb, struct us_data *ss)
do {
memset(&srb->cmd[0], 0, 12);
srb->cmd[0] = SCSI_TST_U_RDY;
+ srb->cmd[1] = srb->lun << 5;
srb->datalen = 0;
srb->cmdlen = 12;
if (ss->transport(srb, ss) == USB_STOR_TRANSPORT_GOOD)
@@ -943,6 +971,7 @@ static int usb_read_capacity(ccb *srb, struct us_data *ss)
do {
memset(&srb->cmd[0], 0, 12);
srb->cmd[0] = SCSI_RD_CAPAC;
+ srb->cmd[1] = srb->lun << 5;
srb->datalen = 8;
srb->cmdlen = 12;
if (ss->transport(srb, ss) == USB_STOR_TRANSPORT_GOOD)
@@ -957,6 +986,7 @@ static int usb_read_10(ccb *srb, struct us_data *ss, unsigned long start,
{
memset(&srb->cmd[0], 0, 12);
srb->cmd[0] = SCSI_READ10;
+ srb->cmd[1] = srb->lun << 5;
srb->cmd[2] = ((unsigned char) (start >> 24)) & 0xff;
srb->cmd[3] = ((unsigned char) (start >> 16)) & 0xff;
srb->cmd[4] = ((unsigned char) (start >> 8)) & 0xff;
@@ -973,6 +1003,7 @@ static int usb_write_10(ccb *srb, struct us_data *ss, unsigned long start,
{
memset(&srb->cmd[0], 0, 12);
srb->cmd[0] = SCSI_WRITE10;
+ srb->cmd[1] = srb->lun << 5;
srb->cmd[2] = ((unsigned char) (start >> 24)) & 0xff;
srb->cmd[3] = ((unsigned char) (start >> 16)) & 0xff;
srb->cmd[4] = ((unsigned char) (start >> 8)) & 0xff;