summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/cmd_bdinfo.c10
-rw-r--r--common/cmd_mem.c46
-rw-r--r--common/cmd_nand.c107
-rw-r--r--common/cmd_onenand.c530
-rw-r--r--common/cmd_ubi.c16
-rw-r--r--common/env_sf.c41
-rw-r--r--common/fdt_support.c2
-rw-r--r--common/image.c2
-rw-r--r--common/main.c27
-rw-r--r--common/usb_kbd.c4
10 files changed, 582 insertions, 203 deletions
diff --git a/common/cmd_bdinfo.c b/common/cmd_bdinfo.c
index 6675241..b660d2a 100644
--- a/common/cmd_bdinfo.c
+++ b/common/cmd_bdinfo.c
@@ -328,18 +328,20 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
}
#elif defined(CONFIG_BLACKFIN)
+static void print_str(const char *, const char *);
int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
int i;
bd_t *bd = gd->bd;
+ char buf[32];
printf("U-Boot = %s\n", bd->bi_r_version);
printf("CPU = %s\n", bd->bi_cpu);
printf("Board = %s\n", bd->bi_board_name);
- printf("VCO = %lu MHz\n", bd->bi_vco / 1000000);
- printf("CCLK = %lu MHz\n", bd->bi_cclk / 1000000);
- printf("SCLK = %lu MHz\n", bd->bi_sclk / 1000000);
+ print_str("VCO", strmhz(buf, bd->bi_vco));
+ print_str("CCLK", strmhz(buf, bd->bi_cclk));
+ print_str("SCLK", strmhz(buf, bd->bi_sclk));
print_num("boot_params", (ulong)bd->bi_boot_params);
print_num("memstart", (ulong)bd->bi_memstart);
@@ -430,7 +432,7 @@ static void print_lnum(const char *name, u64 value)
}
#endif
-#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
+#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_BLACKFIN)
static void print_str(const char *name, const char *str)
{
printf ("%-12s= %6s MHz\n", name, str);
diff --git a/common/cmd_mem.c b/common/cmd_mem.c
index d7666c2..c209d62 100644
--- a/common/cmd_mem.c
+++ b/common/cmd_mem.c
@@ -672,6 +672,8 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
ulong val;
ulong readback;
int rcode = 0;
+ int iterations = 1;
+ int iteration_limit;
#if defined(CONFIG_SYS_ALT_MEMTEST)
vu_long len;
@@ -687,7 +689,6 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
vu_long *dummy = 0; /* yes, this is address 0x0, not NULL */
#endif
int j;
- int iterations = 1;
static const ulong bitpattern[] = {
0x00000001, /* single bit */
@@ -704,23 +705,25 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
ulong pattern;
#endif
- if (argc > 1) {
+ if (argc > 1)
start = (ulong *)simple_strtoul(argv[1], NULL, 16);
- } else {
+ else
start = (ulong *)CONFIG_SYS_MEMTEST_START;
- }
- if (argc > 2) {
+ if (argc > 2)
end = (ulong *)simple_strtoul(argv[2], NULL, 16);
- } else {
+ else
end = (ulong *)(CONFIG_SYS_MEMTEST_END);
- }
- if (argc > 3) {
+ if (argc > 3)
pattern = (ulong)simple_strtoul(argv[3], NULL, 16);
- } else {
+ else
pattern = 0;
- }
+
+ if (argc > 4)
+ iteration_limit = (ulong)simple_strtoul(argv[4], NULL, 16);
+ else
+ iteration_limit = 0;
#if defined(CONFIG_SYS_ALT_MEMTEST)
printf ("Testing %08x ... %08x:\n", (uint)start, (uint)end);
@@ -733,8 +736,15 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
return 1;
}
+
+ if (iteration_limit && iterations > iteration_limit) {
+ printf("Tested %d iteration(s) without errors.\n",
+ iterations-1);
+ return 0;
+ }
+
printf("Iteration: %6d\r", iterations);
- PRINTF("Iteration: %6d\n", iterations);
+ PRINTF("\n");
iterations++;
/*
@@ -926,6 +936,13 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
return 1;
}
+ if (iteration_limit && iterations > iteration_limit) {
+ printf("Tested %d iteration(s) without errors.\n",
+ iterations-1);
+ return 0;
+ }
+ ++iterations;
+
printf ("\rPattern %08lX Writing..."
"%12s"
"\b\b\b\b\b\b\b\b\b\b",
@@ -1175,7 +1192,6 @@ int do_unzip ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
unsigned long src, dst;
unsigned long src_len = ~0UL, dst_len = ~0UL;
- int err;
switch (argc) {
case 4:
@@ -1277,9 +1293,9 @@ U_BOOT_CMD(
#endif /* CONFIG_LOOPW */
U_BOOT_CMD(
- mtest, 4, 1, do_mem_mtest,
- "mtest - simple RAM test\n",
- "[start [end [pattern]]]\n"
+ mtest, 5, 1, do_mem_mtest,
+ "mtest - simple RAM test\n",
+ "[start [end [pattern [iterations]]]]\n"
" - simple RAM read/write test\n"
);
diff --git a/common/cmd_nand.c b/common/cmd_nand.c
index 0a366d3..aedf8a6 100644
--- a/common/cmd_nand.c
+++ b/common/cmd_nand.c
@@ -160,10 +160,51 @@ out:
if (*size == nand->size)
puts("whole chip\n");
else
- printf("offset 0x%lx, size 0x%x\n", *off, *size);
+ printf("offset 0x%lx, size 0x%zx\n", *off, *size);
return 0;
}
+#ifdef CONFIG_CMD_NAND_LOCK_UNLOCK
+static void print_status(ulong start, ulong end, ulong erasesize, int status)
+{
+ printf("%08lx - %08lx: %08lx blocks %s%s%s\n",
+ start,
+ end - 1,
+ (end - start) / erasesize,
+ ((status & NAND_LOCK_STATUS_TIGHT) ? "TIGHT " : ""),
+ ((status & NAND_LOCK_STATUS_LOCK) ? "LOCK " : ""),
+ ((status & NAND_LOCK_STATUS_UNLOCK) ? "UNLOCK " : ""));
+}
+
+static void do_nand_status(nand_info_t *nand)
+{
+ ulong block_start = 0;
+ ulong off;
+ int last_status = -1;
+
+ struct nand_chip *nand_chip = nand->priv;
+ /* check the WP bit */
+ nand_chip->cmdfunc(nand, NAND_CMD_STATUS, -1, -1);
+ printf("device is %swrite protected\n",
+ (nand_chip->read_byte(nand) & 0x80 ?
+ "NOT " : ""));
+
+ for (off = 0; off < nand->size; off += nand->erasesize) {
+ int s = nand_get_lock_status(nand, off);
+
+ /* print message only if status has changed */
+ if (s != last_status && off != 0) {
+ print_status(block_start, off, nand->erasesize,
+ last_status);
+ block_start = off;
+ }
+ last_status = s;
+ }
+ /* Print the last block info */
+ print_status(block_start, off, nand->erasesize, last_status);
+}
+#endif
+
int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
{
int i, dev, ret = 0;
@@ -357,7 +398,7 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
return 1;
}
- printf(" %d bytes %s: %s\n", size,
+ printf(" %zu bytes %s: %s\n", size,
read ? "read" : "written", ret ? "ERROR" : "OK");
return ret == 0 ? 0 : 1;
@@ -383,8 +424,9 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
return 1;
}
+#ifdef CONFIG_CMD_NAND_LOCK_UNLOCK
if (strcmp(cmd, "lock") == 0) {
- int tight = 0;
+ int tight = 0;
int status = 0;
if (argc == 3) {
if (!strcmp("tight", argv[2]))
@@ -392,44 +434,8 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
if (!strcmp("status", argv[2]))
status = 1;
}
-/*
- * ! BROKEN !
- *
- * TODO: must be implemented and tested by someone with HW
- */
-#if 0
if (status) {
- ulong block_start = 0;
- ulong off;
- int last_status = -1;
-
- struct nand_chip *nand_chip = nand->priv;
- /* check the WP bit */
- nand_chip->cmdfunc (nand, NAND_CMD_STATUS, -1, -1);
- printf("device is %swrite protected\n",
- (nand_chip->read_byte(nand) & 0x80 ?
- "NOT " : ""));
-
- for (off = 0; off < nand->size; off += nand->writesize) {
- int s = nand_get_lock_status(nand, off);
-
- /* print message only if status has changed
- * or at end of chip
- */
- if (off == nand->size - nand->writesize
- || (s != last_status && off != 0)) {
-
- printf("%08lx - %08lx: %8d pages %s%s%s\n",
- block_start,
- off-1,
- (off-block_start)/nand->writesize,
- ((last_status & NAND_LOCK_STATUS_TIGHT) ? "TIGHT " : ""),
- ((last_status & NAND_LOCK_STATUS_LOCK) ? "LOCK " : ""),
- ((last_status & NAND_LOCK_STATUS_UNLOCK) ? "UNLOCK " : ""));
- }
-
- last_status = s;
- }
+ do_nand_status(nand);
} else {
if (!nand_lock(nand, tight)) {
puts("NAND flash successfully locked\n");
@@ -438,7 +444,6 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
return 1;
}
}
-#endif
return 0;
}
@@ -446,12 +451,6 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
if (arg_off_size(argc - 2, argv + 2, nand, &off, &size) < 0)
return 1;
-/*
- * ! BROKEN !
- *
- * TODO: must be implemented and tested by someone with HW
- */
-#if 0
if (!nand_unlock(nand, off, size)) {
puts("NAND flash successfully unlocked\n");
} else {
@@ -459,9 +458,9 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
"write and erase will probably fail\n");
return 1;
}
-#endif
return 0;
}
+#endif
usage:
printf("Usage:\n%s\n", cmdtp->usage);
@@ -483,9 +482,12 @@ U_BOOT_CMD(nand, 5, 1, do_nand,
"nand scrub - really clean NAND erasing bad blocks (UNSAFE)\n"
"nand markbad off - mark bad block at offset (UNSAFE)\n"
"nand biterr off - make a bit error at offset (UNSAFE)\n"
+#ifdef CONFIG_CMD_NAND_LOCK_UNLOCK
"nand lock [tight] [status]\n"
" bring nand to lock state or display locked pages\n"
- "nand unlock [offset] [size] - unlock section\n");
+ "nand unlock [offset] [size] - unlock section\n"
+#endif
+);
static int nand_load_image(cmd_tbl_t *cmdtp, nand_info_t *nand,
ulong offset, ulong addr, char *cmd)
@@ -854,13 +856,12 @@ int do_nand (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
(u_char *) addr);
}
return ret;
- } else if (cmdtail && !strncmp (cmdtail, ".jffs2", 2))
- cmd |= NANDRW_JFFS2; /* skip bad blocks */
- else if (cmdtail && !strncmp (cmdtail, ".jffs2s", 2)) {
+ } else if (cmdtail && !strncmp (cmdtail, ".jffs2s", 7)) {
cmd |= NANDRW_JFFS2; /* skip bad blocks (on read too) */
if (cmd & NANDRW_READ)
cmd |= NANDRW_JFFS2_SKIP; /* skip bad blocks (on read too) */
- }
+ } else if (cmdtail && !strncmp (cmdtail, ".jffs2", 2))
+ cmd |= NANDRW_JFFS2; /* skip bad blocks */
#ifdef SXNI855T
/* need ".e" same as ".j" for compatibility with older units */
else if (cmdtail && !strcmp (cmdtail, ".e"))
diff --git a/common/cmd_onenand.c b/common/cmd_onenand.c
index 8d87b78..6a2c924 100644
--- a/common/cmd_onenand.c
+++ b/common/cmd_onenand.c
@@ -1,7 +1,7 @@
/*
* U-Boot command for OneNAND support
*
- * Copyright (C) 2005-2007 Samsung Electronics
+ * Copyright (C) 2005-2008 Samsung Electronics
* Kyungmin Park <kyungmin.park@samsung.com>
*
* This program is free software; you can redistribute it and/or modify
@@ -11,6 +11,7 @@
#include <common.h>
#include <command.h>
+#include <malloc.h>
#include <linux/mtd/compat.h>
#include <linux/mtd/mtd.h>
@@ -18,159 +19,468 @@
#include <asm/io.h>
-extern struct mtd_info onenand_mtd;
-extern struct onenand_chip onenand_chip;
+static struct mtd_info *mtd;
+
+static loff_t next_ofs;
+static loff_t skip_ofs;
+
+static inline int str2long(char *p, ulong *num)
+{
+ char *endptr;
+
+ *num = simple_strtoul(p, &endptr, 16);
+ return (*p != '\0' && *endptr == '\0') ? 1 : 0;
+}
+
+static int arg_off_size(int argc, char *argv[], ulong *off, size_t *size)
+{
+ if (argc >= 1) {
+ if (!(str2long(argv[0], off))) {
+ printf("'%s' is not a number\n", argv[0]);
+ return -1;
+ }
+ } else {
+ *off = 0;
+ }
+
+ if (argc >= 2) {
+ if (!(str2long(argv[1], (ulong *)size))) {
+ printf("'%s' is not a number\n", argv[1]);
+ return -1;
+ }
+ } else {
+ *size = mtd->size - *off;
+ }
+
+ if ((*off + *size) > mtd->size) {
+ printf("total chip size (0x%x) exceeded!\n", mtd->size);
+ return -1;
+ }
+
+ if (*size == mtd->size)
+ puts("whole chip\n");
+ else
+ printf("offset 0x%lx, size 0x%x\n", *off, *size);
+
+ return 0;
+}
+
+static int onenand_block_read(loff_t from, size_t len,
+ size_t *retlen, u_char *buf, int oob)
+{
+ struct onenand_chip *this = mtd->priv;
+ int blocks = (int) len >> this->erase_shift;
+ int blocksize = (1 << this->erase_shift);
+ loff_t ofs = from;
+ struct mtd_oob_ops ops = {
+ .retlen = 0,
+ };
+ int ret;
+
+ if (oob)
+ ops.ooblen = blocksize;
+ else
+ ops.len = blocksize;
+
+ while (blocks) {
+ ret = mtd->block_isbad(mtd, ofs);
+ if (ret) {
+ printk("Bad blocks %d at 0x%x\n",
+ (u32)(ofs >> this->erase_shift), (u32)ofs);
+ ofs += blocksize;
+ continue;
+ }
+
+ if (oob)
+ ops.oobbuf = buf;
+ else
+ ops.datbuf = buf;
+
+ ops.retlen = 0;
+ ret = mtd->read_oob(mtd, ofs, &ops);
+ if (ret) {
+ printk("Read failed 0x%x, %d\n", (u32)ofs, ret);
+ ofs += blocksize;
+ continue;
+ }
+ ofs += blocksize;
+ buf += blocksize;
+ blocks--;
+ *retlen += ops.retlen;
+ }
+
+ return 0;
+}
+
+static int onenand_block_write(loff_t to, size_t len,
+ size_t *retlen, const u_char * buf)
+{
+ struct onenand_chip *this = mtd->priv;
+ int blocks = len >> this->erase_shift;
+ int blocksize = (1 << this->erase_shift);
+ loff_t ofs;
+ size_t _retlen = 0;
+ int ret;
+
+ if (to == next_ofs) {
+ next_ofs = to + len;
+ to += skip_ofs;
+ } else {
+ next_ofs = to + len;
+ skip_ofs = 0;
+ }
+ ofs = to;
+
+ while (blocks) {
+ ret = mtd->block_isbad(mtd, ofs);
+ if (ret) {
+ printk("Bad blocks %d at 0x%x\n",
+ (u32)(ofs >> this->erase_shift), (u32)ofs);
+ skip_ofs += blocksize;
+ goto next;
+ }
+
+ ret = mtd->write(mtd, ofs, blocksize, &_retlen, buf);
+ if (ret) {
+ printk("Write failed 0x%x, %d", (u32)ofs, ret);
+ skip_ofs += blocksize;
+ goto next;
+ }
+
+ buf += blocksize;
+ blocks--;
+ *retlen += _retlen;
+next:
+ ofs += blocksize;
+ }
+
+ return 0;
+}
+
+static int onenand_block_erase(u32 start, u32 size, int force)
+{
+ struct onenand_chip *this = mtd->priv;
+ struct erase_info instr = {
+ .callback = NULL,
+ };
+ loff_t ofs;
+ int ret;
+ int blocksize = 1 << this->erase_shift;
+
+ for (ofs = start; ofs < (start + size); ofs += blocksize) {
+ ret = mtd->block_isbad(mtd, ofs);
+ if (ret && !force) {
+ printf("Skip erase bad block %d at 0x%x\n",
+ (u32)(ofs >> this->erase_shift), (u32)ofs);
+ continue;
+ }
+
+ instr.addr = ofs;
+ instr.len = blocksize;
+ instr.priv = force;
+ instr.mtd = mtd;
+ ret = mtd->erase(mtd, &instr);
+ if (ret) {
+ printf("erase failed block %d at 0x%x\n",
+ (u32)(ofs >> this->erase_shift), (u32)ofs);
+ continue;
+ }
+ }
+
+ return 0;
+}
+
+static int onenand_block_test(u32 start, u32 size)
+{
+ struct onenand_chip *this = mtd->priv;
+ struct erase_info instr = {
+ .callback = NULL,
+ .priv = 0,
+ };
+
+ int blocks;
+ loff_t ofs;
+ int blocksize = 1 << this->erase_shift;
+ int start_block, end_block;
+ size_t retlen;
+ u_char *buf;
+ u_char *verify_buf;
+ int ret;
+
+ buf = malloc(blocksize);
+ if (!buf) {
+ printf("Not enough malloc space available!\n");
+ return -1;
+ }
+
+ verify_buf = malloc(blocksize);
+ if (!verify_buf) {
+ printf("Not enough malloc space available!\n");
+ return -1;
+ }
+
+ start_block = start >> this->erase_shift;
+ end_block = (start + size) >> this->erase_shift;
+
+ /* Protect boot-loader from badblock testing */
+ if (start_block < 2)
+ start_block = 2;
+
+ if (end_block > (mtd->size >> this->erase_shift))
+ end_block = mtd->size >> this->erase_shift;
+
+ blocks = start_block;
+ ofs = start;
+ while (blocks < end_block) {
+ printf("\rTesting block %d at 0x%x", (u32)(ofs >> this->erase_shift), (u32)ofs);
+
+ ret = mtd->block_isbad(mtd, ofs);
+ if (ret) {
+ printf("Skip erase bad block %d at 0x%x\n",
+ (u32)(ofs >> this->erase_shift), (u32)ofs);
+ goto next;
+ }
+
+ instr.addr = ofs;
+ instr.len = blocksize;
+ ret = mtd->erase(mtd, &instr);
+ if (ret) {
+ printk("Erase failed 0x%x, %d\n", (u32)ofs, ret);
+ goto next;
+ }
+
+ ret = mtd->write(mtd, ofs, blocksize, &retlen, buf);
+ if (ret) {
+ printk("Write failed 0x%x, %d\n", (u32)ofs, ret);
+ goto next;
+ }
+
+ ret = mtd->read(mtd, ofs, blocksize, &retlen, verify_buf);
+ if (ret) {
+ printk("Read failed 0x%x, %d\n", (u32)ofs, ret);
+ goto next;
+ }
+
+ if (memcmp(buf, verify_buf, blocksize))
+ printk("\nRead/Write test failed at 0x%x\n", (u32)ofs);
+
+next:
+ ofs += blocksize;
+ blocks++;
+ }
+ printf("...Done\n");
+
+ free(buf);
+ free(verify_buf);
+
+ return 0;
+}
+
+static int onenand_dump(struct mtd_info *mtd, ulong off, int only_oob)
+{
+ int i;
+ u_char *datbuf, *oobbuf, *p;
+ struct mtd_oob_ops ops;
+ loff_t addr;
+
+ datbuf = malloc(mtd->writesize + mtd->oobsize);
+ oobbuf = malloc(mtd->oobsize);
+ if (!datbuf || !oobbuf) {
+ puts("No memory for page buffer\n");
+ return 1;
+ }
+ off &= ~(mtd->writesize - 1);
+ addr = (loff_t) off;
+ memset(&ops, 0, sizeof(ops));
+ ops.datbuf = datbuf;
+ ops.oobbuf = oobbuf; /* must exist, but oob data will be appended to ops.datbuf */
+ ops.len = mtd->writesize;
+ ops.ooblen = mtd->oobsize;
+ ops.retlen = 0;
+ i = mtd->read_oob(mtd, addr, &ops);
+ if (i < 0) {
+ printf("Error (%d) reading page %08lx\n", i, off);
+ free(datbuf);
+ free(oobbuf);
+ return 1;
+ }
+ printf("Page %08lx dump:\n", off);
+ i = mtd->writesize >> 4;
+ p = datbuf;
+
+ while (i--) {
+ if (!only_oob)
+ printf("\t%02x %02x %02x %02x %02x %02x %02x %02x"
+ " %02x %02x %02x %02x %02x %02x %02x %02x\n",
+ p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7],
+ p[8], p[9], p[10], p[11], p[12], p[13], p[14],
+ p[15]);
+ p += 16;
+ }
+ puts("OOB:\n");
+ i = mtd->oobsize >> 3;
+ while (i--) {
+ printf("\t%02x %02x %02x %02x %02x %02x %02x %02x\n",
+ p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
+ p += 8;
+ }
+ free(datbuf);
+ free(oobbuf);
+
+ return 0;
+}
int do_onenand(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
{
- int ret = 0;
+ struct onenand_chip *this;
+ int blocksize;
+ ulong addr, ofs;
+ size_t len, retlen = 0;
+ int ret;
+ char *cmd, *s;
+
+ mtd = &onenand_mtd;
+ this = mtd->priv;
+ blocksize = (1 << this->erase_shift);
+
+ cmd = argv[1];
switch (argc) {
case 0:
case 1:
- printf("Usage:\n%s\n", cmdtp->usage);
- return 1;
+ goto usage;
case 2:
- if (strncmp(argv[1], "open", 4) == 0) {
- onenand_init();
+ if (strcmp(cmd, "info") == 0) {
+ printf("%s\n", mtd->name);
+ return 0;
+ }
+
+ if (strcmp(cmd, "bad") == 0) {
+ /* Currently only one OneNAND device is supported */
+ printf("\nDevice %d bad blocks:\n", 0);
+ for (ofs = 0; ofs < mtd->size; ofs += mtd->erasesize) {
+ if (mtd->block_isbad(mtd, ofs))
+ printf(" %08x\n", (u32)ofs);
+ }
+
return 0;
}
- printf("%s\n", onenand_mtd.name);
- return 0;
default:
/* At least 4 args */
- if (strncmp(argv[1], "erase", 5) == 0) {
- struct erase_info instr = {
- .callback = NULL,
- };
- ulong start, end;
- ulong block;
- char *endtail;
-
- if (strncmp(argv[2], "block", 5) == 0) {
- start = simple_strtoul(argv[3], NULL, 10);
- endtail = strchr(argv[3], '-');
- end = simple_strtoul(endtail + 1, NULL, 10);
- } else {
- start = simple_strtoul(argv[2], NULL, 10);
- end = simple_strtoul(argv[3], NULL, 10);
- start >>= onenand_chip.erase_shift;
- end >>= onenand_chip.erase_shift;
- /* Don't include the end block */
- end--;
- }
+ /*
+ * Syntax is:
+ * 0 1 2 3 4
+ * onenand erase [force] [off size]
+ */
+ if ((strcmp(cmd, "erase") == 0) || (strcmp(cmd, "test") == 0)) {
+ int force = argc > 2 && !strcmp("force", argv[2]);
+ int o = force ? 3 : 2;
+ int erase;
- if (!end || end < 0)
- end = start;
+ erase = strcmp(cmd, "erase") == 0; /* 1 = erase, 0 = test */
+ printf("\nOneNAND %s: ", erase ? "erase" : "test");
- printf("Erase block from %lu to %lu\n", start, end);
+ /* skip first two or three arguments, look for offset and size */
+ if (arg_off_size(argc - o, argv + o, &ofs, &len) != 0)
+ return 1;
- for (block = start; block <= end; block++) {
- instr.addr = block << onenand_chip.erase_shift;
- instr.len = 1 << onenand_chip.erase_shift;
- ret = onenand_erase(&onenand_mtd, &instr);
- if (ret) {
- printf("erase failed %lu\n", block);
- break;
- }
- }
+ if (erase)
+ ret = onenand_block_erase(ofs, len, force);
+ else
+ ret = onenand_block_test(ofs, len);
- return 0;
+ printf("%s\n", ret ? "ERROR" : "OK");
+
+ return ret == 0 ? 0 : 1;
}
- if (strncmp(argv[1], "read", 4) == 0) {
- ulong addr = simple_strtoul(argv[2], NULL, 16);
- ulong ofs = simple_strtoul(argv[3], NULL, 16);
- size_t len = simple_strtoul(argv[4], NULL, 16);
- int oob = strncmp(argv[1], "read.oob", 8) ? 0 : 1;
- struct mtd_oob_ops ops;
+ if (strncmp(cmd, "read", 4) == 0 || strncmp(cmd, "write", 5) == 0) {
+ int read;
+ int oob = 0;
- ops.mode = MTD_OOB_PLACE;
+ if (argc < 4)
+ goto usage;
- if (oob) {
- ops.len = 0;
- ops.datbuf = NULL;
- ops.ooblen = len;
- ops.oobbuf = (u_char *) addr;
- } else {
- ops.len = len;
- ops.datbuf = (u_char *) addr;
- ops.ooblen = 0;
- ops.oobbuf = NULL;
- }
- ops.retlen = ops.oobretlen = 0;
+ addr = (ulong)simple_strtoul(argv[2], NULL, 16);
- onenand_mtd.read_oob(&onenand_mtd, ofs, &ops);
- printf("Done\n");
+ read = strncmp(cmd, "read", 4) == 0; /* 1 = read, 0 = write */
+ printf("\nOneNAND %s: ", read ? "read" : "write");
+ if (arg_off_size(argc - 3, argv + 3, &ofs, &len) != 0)
+ return 1;
- return 0;
- }
+ s = strchr(cmd, '.');
+ if ((s != NULL) && (!strcmp(s, ".oob")))
+ oob = 1;
- if (strncmp(argv[1], "write", 5) == 0) {
- ulong addr = simple_strtoul(argv[2], NULL, 16);
- ulong ofs = simple_strtoul(argv[3], NULL, 16);
- size_t len = simple_strtoul(argv[4], NULL, 16);
- size_t retlen = 0;
+ if (read) {
+ ret = onenand_block_read(ofs, len, &retlen,
+ (u8 *)addr, oob);
+ } else {
+ ret = onenand_block_write(ofs, len, &retlen,
+ (u8 *)addr);
+ }
- onenand_write(&onenand_mtd, ofs, len, &retlen,
- (u_char *) addr);
- printf("Done\n");
+ printf(" %d bytes %s: %s\n", retlen,
+ read ? "read" : "written", ret ? "ERROR" : "OK");
- return 0;
+ return ret == 0 ? 0 : 1;
}
- if (strncmp(argv[1], "block", 5) == 0) {
- ulong addr = simple_strtoul(argv[2], NULL, 16);
- ulong block = simple_strtoul(argv[3], NULL, 10);
- ulong page = simple_strtoul(argv[4], NULL, 10);
- size_t len = simple_strtol(argv[5], NULL, 10);
- ulong ofs;
- int oob = strncmp(argv[1], "block.oob", 9) ? 0 : 1;
- struct mtd_oob_ops ops;
-
- ops.mode = MTD_OOB_PLACE;
+ if (strcmp(cmd, "markbad") == 0) {
+ addr = (ulong)simple_strtoul(argv[2], NULL, 16);
+ int ret = mtd->block_markbad(mtd, addr);
+ if (ret == 0) {
+ printf("block 0x%08lx successfully marked as bad\n",
+ (ulong) addr);
+ return 0;
+ } else {
+ printf("block 0x%08lx NOT marked as bad! ERROR %d\n",
+ (ulong) addr, ret);
+ }
+ return 1;
+ }
- ofs = block << onenand_chip.erase_shift;
- if (page)
- ofs += page << onenand_chip.page_shift;
+ if (strncmp(cmd, "dump", 4) == 0) {
+ if (argc < 3)
+ goto usage;
- if (!len) {
- if (oob)
- ops.ooblen = 64;
- else
- ops.len = 512;
- }
+ s = strchr(cmd, '.');
+ ofs = (int)simple_strtoul(argv[2], NULL, 16);
- if (oob) {
- ops.datbuf = NULL;
- ops.oobbuf = (u_char *) addr;
- } else {
- ops.datbuf = (u_char *) addr;
- ops.oobbuf = NULL;
- }
- ops.retlen = ops.oobretlen = 0;
+ if (s != NULL && strcmp(s, ".oob") == 0)
+ ret = onenand_dump(mtd, ofs, 1);
+ else
+ ret = onenand_dump(mtd, ofs, 0);
- onenand_read_oob(&onenand_mtd, ofs, &ops);
- return 0;
+ return ret == 0 ? 1 : 0;
}
break;
}
return 0;
+
+usage:
+ printf("Usage:\n%s\n", cmdtp->usage);
+ return 1;
}
U_BOOT_CMD(
onenand, 6, 1, do_onenand,
"onenand - OneNAND sub-system\n",
- "info - show available OneNAND devices\n"
- "onenand read[.oob] addr ofs len - read data at ofs with len to addr\n"
- "onenand write addr ofs len - write data at ofs with len from addr\n"
- "onenand erase saddr eaddr - erase block start addr to end addr\n"
- "onenand block[.oob] addr block [page] [len] - "
- "read data with (block [, page]) to addr"
+ "info - show available OneNAND devices\n"
+ "onenand bad - show bad blocks\n"
+ "onenand read[.oob] addr off size\n"
+ "onenand write[.oob] addr off size\n"
+ " read/write 'size' bytes starting at offset 'off'\n"
+ " to/from memory address 'addr', skipping bad blocks.\n"
+ "onenand erase [force] [off size] - erase 'size' bytes from\n"
+ "onenand test [off size] - test 'size' bytes from\n"
+ " offset 'off' (entire device if not specified)\n"
+ "onenand dump[.oob] off - dump page\n"
+ "onenand markbad off - mark bad block at offset (UNSAFE)\n"
);
diff --git a/common/cmd_ubi.c b/common/cmd_ubi.c
index 8446765..5c31f7b 100644
--- a/common/cmd_ubi.c
+++ b/common/cmd_ubi.c
@@ -31,6 +31,7 @@
/* Private own data */
static struct ubi_device *ubi;
static char buffer[80];
+static int ubi_initialized;
struct selected_dev {
char dev_name[32]; /* NAND/OneNAND etc */
@@ -428,6 +429,8 @@ static int ubi_dev_scan(struct mtd_info *info, char *ubidev)
return err;
}
+ ubi_initialized = 1;
+
return 0;
}
@@ -464,6 +467,14 @@ static int do_ubi(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
ubi_dev.nr = 0;
/*
+ * Call ubi_exit() before re-initializing the UBI subsystem
+ */
+ if (ubi_initialized) {
+ ubi_exit();
+ del_mtd_partitions(ubi_dev.mtd_info);
+ }
+
+ /*
* Check for nand|onenand selection
*/
#if defined(CONFIG_CMD_NAND)
@@ -497,6 +508,7 @@ static int do_ubi(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
err = ubi_dev_scan(ubi_dev.mtd_info, ubi_dev.part_name);
if (err) {
printf("UBI init error %d\n", err);
+ ubi_dev.type = DEV_TYPE_NONE;
return err;
}
@@ -535,7 +547,7 @@ static int do_ubi(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
}
/* E.g., create volume size */
if (argc == 4) {
- addr = simple_strtoul(argv[3], NULL, 16);
+ size = simple_strtoul(argv[3], NULL, 16);
argc--;
}
/* Use maximum available size */
@@ -589,7 +601,7 @@ static int do_ubi(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
U_BOOT_CMD(ubi, 6, 1, do_ubi,
"ubi - ubi commands\n",
- "part [nand|nor|onenand] [part]"
+ "part [nand|nor|onenand] [part]"
" - Show or set current partition\n"
"ubi info [l[ayout]]"
" - Display volume and ubi layout information\n"
diff --git a/common/env_sf.c b/common/env_sf.c
index 1bbf93f..2f52e25 100644
--- a/common/env_sf.c
+++ b/common/env_sf.c
@@ -27,6 +27,7 @@
*/
#include <common.h>
#include <environment.h>
+#include <malloc.h>
#include <spi_flash.h>
#ifndef CONFIG_ENV_SPI_BUS
@@ -60,13 +61,30 @@ uchar env_get_char_spec(int index)
int saveenv(void)
{
+ u32 saved_size, saved_offset;
+ char *saved_buffer = NULL;
u32 sector = 1;
+ int ret;
if (!env_flash) {
puts("Environment SPI flash not initialized\n");
return 1;
}
+ /* Is the sector larger than the env (i.e. embedded) */
+ if (CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE) {
+ saved_size = CONFIG_ENV_SECT_SIZE - CONFIG_ENV_SIZE;
+ saved_offset = CONFIG_ENV_OFFSET + CONFIG_ENV_SIZE;
+ saved_buffer = malloc(saved_size);
+ if (!saved_buffer) {
+ ret = 1;
+ goto done;
+ }
+ ret = spi_flash_read(env_flash, saved_offset, saved_size, saved_buffer);
+ if (ret)
+ goto done;
+ }
+
if (CONFIG_ENV_SIZE > CONFIG_ENV_SECT_SIZE) {
sector = CONFIG_ENV_SIZE / CONFIG_ENV_SECT_SIZE;
if (CONFIG_ENV_SIZE % CONFIG_ENV_SECT_SIZE)
@@ -74,15 +92,28 @@ int saveenv(void)
}
puts("Erasing SPI flash...");
- if (spi_flash_erase(env_flash, CONFIG_ENV_OFFSET, sector * CONFIG_ENV_SECT_SIZE))
- return 1;
+ ret = spi_flash_erase(env_flash, CONFIG_ENV_OFFSET, sector * CONFIG_ENV_SECT_SIZE);
+ if (ret)
+ goto done;
puts("Writing to SPI flash...");
- if (spi_flash_write(env_flash, CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, env_ptr))
- return 1;
+ ret = spi_flash_write(env_flash, CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, env_ptr);
+ if (ret)
+ goto done;
+
+ if (CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE) {
+ ret = spi_flash_write(env_flash, saved_offset, saved_size, saved_buffer);
+ if (ret)
+ goto done;
+ }
+ ret = 0;
puts("done\n");
- return 0;
+
+ done:
+ if (saved_buffer)
+ free(saved_buffer);
+ return ret;
}
void env_relocate_spec(void)
diff --git a/common/fdt_support.c b/common/fdt_support.c
index 5a83bca..a79bc08 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -610,7 +610,7 @@ int fdt_resize(void *blob)
fdt_size_dt_strings(blob) + sizeof(struct fdt_reserve_entry);
/* Make it so the fdt ends on a page boundary */
- actualsize = ALIGN(actualsize, 0x1000);
+ actualsize = ALIGN(actualsize + ((uint)blob & 0xfff), 0x1000);
actualsize = actualsize - ((uint)blob & 0xfff);
/* Change the fdt header to reflect the correct size */
diff --git a/common/image.c b/common/image.c
index 866edf6..daa68bc 100644
--- a/common/image.c
+++ b/common/image.c
@@ -1071,6 +1071,7 @@ int boot_ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len,
error:
return -1;
}
+#endif /* defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC) */
#ifdef CONFIG_OF_LIBFDT
static void fdt_error (const char *msg)
@@ -1575,6 +1576,7 @@ error:
}
#endif /* CONFIG_OF_LIBFDT */
+#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
/**
* boot_get_cmdline - allocate and initialize kernel cmdline
* @lmb: pointer to lmb handle, will be used for memory mgmt
diff --git a/common/main.c b/common/main.c
index a999a5d..4c4f780 100644
--- a/common/main.c
+++ b/common/main.c
@@ -158,7 +158,19 @@ static __inline__ int abortboot(int bootdelay)
/* In order to keep up with incoming data, check timeout only
* when catch up.
*/
- while (!abort && get_ticks() <= etime) {
+ do {
+ if (tstc()) {
+ if (presskey_len < presskey_max) {
+ presskey [presskey_len ++] = getc();
+ }
+ else {
+ for (i = 0; i < presskey_max - 1; i ++)
+ presskey [i] = presskey [i + 1];
+
+ presskey [i] = getc();
+ }
+ }
+
for (i = 0; i < sizeof(delaykey) / sizeof(delaykey[0]); i ++) {
if (delaykey[i].len > 0 &&
presskey_len >= delaykey[i].len &&
@@ -178,19 +190,8 @@ static __inline__ int abortboot(int bootdelay)
abort = 1;
}
}
+ } while (!abort && get_ticks() <= etime);
- if (tstc()) {
- if (presskey_len < presskey_max) {
- presskey [presskey_len ++] = getc();
- }
- else {
- for (i = 0; i < presskey_max - 1; i ++)
- presskey [i] = presskey [i + 1];
-
- presskey [i] = getc();
- }
- }
- }
# if DEBUG_BOOTKEYS
if (!abort)
puts("key timeout\n");
diff --git a/common/usb_kbd.c b/common/usb_kbd.c
index cf14560..89e6ee7 100644
--- a/common/usb_kbd.c
+++ b/common/usb_kbd.c
@@ -211,7 +211,11 @@ int drv_usb_kbd_init(void)
/* deregistering the keyboard */
int usb_kbd_deregister(void)
{
+#ifdef CONFIG_SYS_DEVICE_DEREGISTER
return device_deregister(DEVNAME);
+#else
+ return 1;
+#endif
}
/**************************************************************************