mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-27 07:51:38 +00:00
cmd: nand: Map memory before accessing it
In sandbox, all memory must be mapped before accessing it. Do so for the nand command. Signed-off-by: Sean Anderson <seanga2@gmail.com>
This commit is contained in:
parent
38ef64e6ce
commit
d2e0a9a691
1 changed files with 15 additions and 11 deletions
26
cmd/nand.c
26
cmd/nand.c
|
@ -34,6 +34,7 @@
|
|||
#include <env.h>
|
||||
#include <watchdog.h>
|
||||
#include <malloc.h>
|
||||
#include <mapmem.h>
|
||||
#include <asm/byteorder.h>
|
||||
#include <jffs2/jffs2.h>
|
||||
#include <nand.h>
|
||||
|
@ -432,7 +433,7 @@ static void nand_print_and_set_info(int idx)
|
|||
env_set_hex("nand_erasesize", mtd->erasesize);
|
||||
}
|
||||
|
||||
static int raw_access(struct mtd_info *mtd, ulong addr, loff_t off,
|
||||
static int raw_access(struct mtd_info *mtd, void *buf, loff_t off,
|
||||
ulong count, int read, int no_verify)
|
||||
{
|
||||
int ret = 0;
|
||||
|
@ -440,8 +441,8 @@ static int raw_access(struct mtd_info *mtd, ulong addr, loff_t off,
|
|||
while (count--) {
|
||||
/* Raw access */
|
||||
mtd_oob_ops_t ops = {
|
||||
.datbuf = (u8 *)addr,
|
||||
.oobbuf = ((u8 *)addr) + mtd->writesize,
|
||||
.datbuf = buf,
|
||||
.oobbuf = buf + mtd->writesize,
|
||||
.len = mtd->writesize,
|
||||
.ooblen = mtd->oobsize,
|
||||
.mode = MTD_OPS_RAW
|
||||
|
@ -461,7 +462,7 @@ static int raw_access(struct mtd_info *mtd, ulong addr, loff_t off,
|
|||
break;
|
||||
}
|
||||
|
||||
addr += mtd->writesize + mtd->oobsize;
|
||||
buf += mtd->writesize + mtd->oobsize;
|
||||
off += mtd->writesize;
|
||||
}
|
||||
|
||||
|
@ -675,6 +676,7 @@ static int do_nand(struct cmd_tbl *cmdtp, int flag, int argc,
|
|||
int read;
|
||||
int raw = 0;
|
||||
int no_verify = 0;
|
||||
void *buf;
|
||||
|
||||
if (argc < 4)
|
||||
goto usage;
|
||||
|
@ -730,32 +732,32 @@ static int do_nand(struct cmd_tbl *cmdtp, int flag, int argc,
|
|||
}
|
||||
|
||||
mtd = get_nand_dev_by_index(dev);
|
||||
buf = map_sysmem(addr, maxsize);
|
||||
|
||||
if (!s || !strcmp(s, ".jffs2") ||
|
||||
!strcmp(s, ".e") || !strcmp(s, ".i")) {
|
||||
if (read)
|
||||
ret = nand_read_skip_bad(mtd, off, &rwsize,
|
||||
NULL, maxsize,
|
||||
(u_char *)addr);
|
||||
NULL, maxsize, buf);
|
||||
else
|
||||
ret = nand_write_skip_bad(mtd, off, &rwsize,
|
||||
NULL, maxsize,
|
||||
(u_char *)addr,
|
||||
NULL, maxsize, buf,
|
||||
WITH_WR_VERIFY);
|
||||
#ifdef CONFIG_CMD_NAND_TRIMFFS
|
||||
} else if (!strcmp(s, ".trimffs")) {
|
||||
if (read) {
|
||||
printf("Unknown nand command suffix '%s'\n", s);
|
||||
unmap_sysmem(buf);
|
||||
return 1;
|
||||
}
|
||||
ret = nand_write_skip_bad(mtd, off, &rwsize, NULL,
|
||||
maxsize, (u_char *)addr,
|
||||
maxsize, buf,
|
||||
WITH_DROP_FFS | WITH_WR_VERIFY);
|
||||
#endif
|
||||
} else if (!strcmp(s, ".oob")) {
|
||||
/* out-of-band data */
|
||||
mtd_oob_ops_t ops = {
|
||||
.oobbuf = (u8 *)addr,
|
||||
.oobbuf = buf,
|
||||
.ooblen = rwsize,
|
||||
.mode = MTD_OPS_RAW
|
||||
};
|
||||
|
@ -765,13 +767,15 @@ static int do_nand(struct cmd_tbl *cmdtp, int flag, int argc,
|
|||
else
|
||||
ret = mtd_write_oob(mtd, off, &ops);
|
||||
} else if (raw) {
|
||||
ret = raw_access(mtd, addr, off, pagecount, read,
|
||||
ret = raw_access(mtd, buf, off, pagecount, read,
|
||||
no_verify);
|
||||
} else {
|
||||
printf("Unknown nand command suffix '%s'.\n", s);
|
||||
unmap_sysmem(buf);
|
||||
return 1;
|
||||
}
|
||||
|
||||
unmap_sysmem(buf);
|
||||
printf(" %zu bytes %s: %s\n", rwsize,
|
||||
read ? "read" : "written", ret ? "ERROR" : "OK");
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue