Commit 9ad754fef5053144daed3b007adaf1c9bec654c9

Authored by William Juul
Committed by Scott Wood
1 parent 43ea36fb8f

make nand dump and nand dump.oob work

Signed-off-by: William Juul <william.juul@tandberg.com>
Signed-off-by: Scott Wood <scottwood@freescale.com>

Showing 1 changed file with 27 additions and 19 deletions Side-by-side Diff

... ... @@ -38,37 +38,44 @@
38 38 u8 *part_num, struct part_info **part);
39 39 #endif
40 40  
41   -static int nand_dump_oob(nand_info_t *nand, ulong off)
  41 +static int nand_dump(nand_info_t *nand, ulong off, int only_oob)
42 42 {
43   - return 0;
44   -}
45   -
46   -static int nand_dump(nand_info_t *nand, ulong off)
47   -{
48 43 int i;
49   - u_char *buf, *p;
  44 + u_char *datbuf, *oobbuf, *p;
50 45  
51   - buf = malloc(nand->writesize + nand->oobsize);
52   - if (!buf) {
  46 + datbuf = malloc(nand->writesize + nand->oobsize);
  47 + oobbuf = malloc(nand->oobsize);
  48 + if (!datbuf || !oobbuf) {
53 49 puts("No memory for page buffer\n");
54 50 return 1;
55 51 }
56 52 off &= ~(nand->writesize - 1);
57 53 size_t dummy;
58 54 loff_t addr = (loff_t) off;
59   - i = nand->read(nand, addr, nand->writesize, &dummy, buf);
  55 + struct mtd_oob_ops ops;
  56 + memset(&ops, 0, sizeof(ops));
  57 + ops.datbuf = datbuf;
  58 + ops.oobbuf = oobbuf; /* must exist, but oob data will be appended to ops.datbuf */
  59 + ops.len = nand->writesize;
  60 + ops.ooblen = nand->oobsize;
  61 + ops.mode = MTD_OOB_RAW;
  62 + i = nand->read_oob(nand, addr, &ops);
60 63 if (i < 0) {
61 64 printf("Error (%d) reading page %08lx\n", i, off);
62   - free(buf);
  65 + free(datbuf);
  66 + free(oobbuf);
63 67 return 1;
64 68 }
65 69 printf("Page %08lx dump:\n", off);
66   - i = nand->writesize >> 4; p = buf;
  70 + i = nand->writesize >> 4;
  71 + p = datbuf;
  72 +
67 73 while (i--) {
68   - printf("\t%02x %02x %02x %02x %02x %02x %02x %02x"
69   - " %02x %02x %02x %02x %02x %02x %02x %02x\n",
70   - p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7],
71   - p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]);
  74 + if (!only_oob)
  75 + printf("\t%02x %02x %02x %02x %02x %02x %02x %02x"
  76 + " %02x %02x %02x %02x %02x %02x %02x %02x\n",
  77 + p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7],
  78 + p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]);
72 79 p += 16;
73 80 }
74 81 puts("OOB:\n");
... ... @@ -78,7 +85,8 @@
78 85 p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
79 86 p += 8;
80 87 }
81   - free(buf);
  88 + free(datbuf);
  89 + free(oobbuf);
82 90  
83 91 return 0;
84 92 }
85 93  
... ... @@ -302,9 +310,9 @@
302 310 off = (int)simple_strtoul(argv[2], NULL, 16);
303 311  
304 312 if (s != NULL && strcmp(s, ".oob") == 0)
305   - ret = nand_dump_oob(nand, off);
  313 + ret = nand_dump(nand, off, 1);
306 314 else
307   - ret = nand_dump(nand, off);
  315 + ret = nand_dump(nand, off, 0);
308 316  
309 317 return ret == 0 ? 1 : 0;
310 318