blob: b3e59b1b003550c0ec92b67186105268ff47f5bc [file] [log] [blame]
Shyam Saini1d43e242019-06-14 13:05:33 +05301/*
2 * i.MX6 nand boot control block(bcb).
3 *
4 * Based on the common/imx-bbu-nand-fcb.c from barebox and imx kobs-ng
5 *
6 * Copyright (C) 2017 Jagan Teki <jagan@amarulasolutions.com>
7 * Copyright (C) 2016 Sergey Kubushyn <ksi@koi8.net>
8 *
9 * SPDX-License-Identifier: GPL-2.0+
10 */
11
12#include <common.h>
Simon Glass336d4612020-02-03 07:36:16 -070013#include <malloc.h>
Shyam Saini1d43e242019-06-14 13:05:33 +053014#include <nand.h>
Simon Glass61b29b82020-02-03 07:36:15 -070015#include <dm/devres.h>
Shyam Saini1d43e242019-06-14 13:05:33 +053016
17#include <asm/io.h>
18#include <jffs2/jffs2.h>
Parthiban Nallathambi6aa87492019-10-18 11:46:19 +020019#include <linux/bch.h>
Shyam Saini1d43e242019-06-14 13:05:33 +053020#include <linux/mtd/mtd.h>
21
Igor Opaniukdad30dd2019-11-03 16:49:44 +010022#include <asm/arch/sys_proto.h>
Shyam Saini1d43e242019-06-14 13:05:33 +053023#include <asm/mach-imx/imx-nandbcb.h>
24#include <asm/mach-imx/imximage.cfg>
25#include <mxs_nand.h>
26#include <linux/mtd/mtd.h>
27#include <nand.h>
28
Miquel Raynaleb446ef2019-10-25 19:39:29 +020029#include "../../../cmd/legacy-mtd-utils.h"
30
Shyam Saini1d43e242019-06-14 13:05:33 +053031#define BF_VAL(v, bf) (((v) & bf##_MASK) >> bf##_OFFSET)
32#define GETBIT(v, n) (((v) >> (n)) & 0x1)
33
Parthiban Nallathambi6aa87492019-10-18 11:46:19 +020034#if defined(CONFIG_MX6UL) || defined(CONFIG_MX6ULL)
35static uint8_t reverse_bit(uint8_t b)
36{
37 b = (b & 0xf0) >> 4 | (b & 0x0f) << 4;
38 b = (b & 0xcc) >> 2 | (b & 0x33) << 2;
39 b = (b & 0xaa) >> 1 | (b & 0x55) << 1;
40
41 return b;
42}
43
44static void encode_bch_ecc(void *buf, struct fcb_block *fcb, int eccbits)
45{
46 int i, j, m = 13;
47 int blocksize = 128;
48 int numblocks = 8;
49 int ecc_buf_size = (m * eccbits + 7) / 8;
50 struct bch_control *bch = init_bch(m, eccbits, 0);
51 u8 *ecc_buf = kzalloc(ecc_buf_size, GFP_KERNEL);
52 u8 *tmp_buf = kzalloc(blocksize * numblocks, GFP_KERNEL);
53 u8 *psrc, *pdst;
54
55 /*
56 * The blocks here are bit aligned. If eccbits is a multiple of 8,
57 * we just can copy bytes. Otherwiese we must move the blocks to
58 * the next free bit position.
59 */
60 WARN_ON(eccbits % 8);
61
62 memcpy(tmp_buf, fcb, sizeof(*fcb));
63
64 for (i = 0; i < numblocks; i++) {
65 memset(ecc_buf, 0, ecc_buf_size);
66 psrc = tmp_buf + i * blocksize;
67 pdst = buf + i * (blocksize + ecc_buf_size);
68
69 /* copy data byte aligned to destination buf */
70 memcpy(pdst, psrc, blocksize);
71
72 /*
73 * imx-kobs use a modified encode_bch which reverse the
74 * bit order of the data before calculating bch.
75 * Do this in the buffer and use the bch lib here.
76 */
77 for (j = 0; j < blocksize; j++)
78 psrc[j] = reverse_bit(psrc[j]);
79
80 encode_bch(bch, psrc, blocksize, ecc_buf);
81
82 /* reverse ecc bit */
83 for (j = 0; j < ecc_buf_size; j++)
84 ecc_buf[j] = reverse_bit(ecc_buf[j]);
85
86 /* Here eccbuf is byte aligned and we can just copy it */
87 memcpy(pdst + blocksize, ecc_buf, ecc_buf_size);
88 }
89
90 kfree(ecc_buf);
91 kfree(tmp_buf);
92 free_bch(bch);
93}
94#else
95
Shyam Saini1d43e242019-06-14 13:05:33 +053096static u8 calculate_parity_13_8(u8 d)
97{
98 u8 p = 0;
99
100 p |= (GETBIT(d, 6) ^ GETBIT(d, 5) ^ GETBIT(d, 3) ^ GETBIT(d, 2)) << 0;
101 p |= (GETBIT(d, 7) ^ GETBIT(d, 5) ^ GETBIT(d, 4) ^ GETBIT(d, 2) ^
102 GETBIT(d, 1)) << 1;
103 p |= (GETBIT(d, 7) ^ GETBIT(d, 6) ^ GETBIT(d, 5) ^ GETBIT(d, 1) ^
104 GETBIT(d, 0)) << 2;
105 p |= (GETBIT(d, 7) ^ GETBIT(d, 4) ^ GETBIT(d, 3) ^ GETBIT(d, 0)) << 3;
106 p |= (GETBIT(d, 6) ^ GETBIT(d, 4) ^ GETBIT(d, 3) ^ GETBIT(d, 2) ^
107 GETBIT(d, 1) ^ GETBIT(d, 0)) << 4;
108
109 return p;
110}
111
112static void encode_hamming_13_8(void *_src, void *_ecc, size_t size)
113{
114 int i;
115 u8 *src = _src;
116 u8 *ecc = _ecc;
117
118 for (i = 0; i < size; i++)
119 ecc[i] = calculate_parity_13_8(src[i]);
120}
Parthiban Nallathambi6aa87492019-10-18 11:46:19 +0200121#endif
Shyam Saini1d43e242019-06-14 13:05:33 +0530122
123static u32 calc_chksum(void *buf, size_t size)
124{
125 u32 chksum = 0;
126 u8 *bp = buf;
127 size_t i;
128
129 for (i = 0; i < size; i++)
130 chksum += bp[i];
131
132 return ~chksum;
133}
134
Igor Opaniuk1b899a82019-11-03 16:49:45 +0100135static void fill_fcb(struct fcb_block *fcb, struct mtd_info *mtd,
136 u32 fw1_start, u32 fw2_start, u32 fw_pages)
Shyam Saini1d43e242019-06-14 13:05:33 +0530137{
138 struct nand_chip *chip = mtd_to_nand(mtd);
139 struct mxs_nand_info *nand_info = nand_get_controller_data(chip);
Igor Opaniukdad30dd2019-11-03 16:49:44 +0100140 struct mxs_nand_layout l;
141
142 mxs_nand_get_layout(mtd, &l);
Shyam Saini1d43e242019-06-14 13:05:33 +0530143
144 fcb->fingerprint = FCB_FINGERPRINT;
145 fcb->version = FCB_VERSION_1;
Igor Opaniukdad30dd2019-11-03 16:49:44 +0100146
Shyam Saini1d43e242019-06-14 13:05:33 +0530147 fcb->pagesize = mtd->writesize;
148 fcb->oob_pagesize = mtd->writesize + mtd->oobsize;
149 fcb->sectors = mtd->erasesize / mtd->writesize;
150
Igor Opaniukdad30dd2019-11-03 16:49:44 +0100151 fcb->meta_size = l.meta_size;
152 fcb->nr_blocks = l.nblocks;
153 fcb->ecc_nr = l.data0_size;
154 fcb->ecc_level = l.ecc0;
155 fcb->ecc_size = l.datan_size;
156 fcb->ecc_type = l.eccn;
Shyam Saini1d43e242019-06-14 13:05:33 +0530157
158 /* Also hardcoded in kobs-ng */
Igor Opaniukdad30dd2019-11-03 16:49:44 +0100159 if (is_mx6()) {
160 fcb->datasetup = 80;
161 fcb->datahold = 60;
162 fcb->addr_setup = 25;
163 fcb->dsample_time = 6;
164 } else if (is_mx7()) {
165 fcb->datasetup = 10;
166 fcb->datahold = 7;
167 fcb->addr_setup = 15;
168 fcb->dsample_time = 6;
169 }
Shyam Saini1d43e242019-06-14 13:05:33 +0530170
171 /* DBBT search area starts at second page on first block */
172 fcb->dbbt_start = 1;
173
174 fcb->bb_byte = nand_info->bch_geometry.block_mark_byte_offset;
175 fcb->bb_start_bit = nand_info->bch_geometry.block_mark_bit_offset;
176
177 fcb->phy_offset = mtd->writesize;
178
179 fcb->nr_blocks = mtd->writesize / fcb->ecc_nr - 1;
180
Igor Opaniukdad30dd2019-11-03 16:49:44 +0100181 fcb->disbbm = 0;
182 fcb->disbbm_search = 0;
183
Igor Opaniuk1b899a82019-11-03 16:49:45 +0100184 fcb->fw1_start = fw1_start; /* Firmware image starts on this sector */
185 fcb->fw2_start = fw2_start; /* Secondary FW Image starting Sector */
186 fcb->fw1_pages = fw_pages; /* Number of sectors in firmware image */
187 fcb->fw2_pages = fw_pages; /* Number of sector in secondary FW image */
188
Shyam Saini1d43e242019-06-14 13:05:33 +0530189 fcb->checksum = calc_chksum((void *)fcb + 4, sizeof(*fcb) - 4);
190}
191
192static int dbbt_fill_data(struct mtd_info *mtd, void *buf, int num_blocks)
193{
194 int n, n_bad_blocks = 0;
195 u32 *bb = buf + 0x8;
196 u32 *n_bad_blocksp = buf + 0x4;
197
198 for (n = 0; n < num_blocks; n++) {
199 loff_t offset = n * mtd->erasesize;
200 if (mtd_block_isbad(mtd, offset)) {
201 n_bad_blocks++;
202 *bb = n;
203 bb++;
204 }
205 }
206
207 *n_bad_blocksp = n_bad_blocks;
208
209 return n_bad_blocks;
210}
211
Igor Opaniuk1b899a82019-11-03 16:49:45 +0100212static int write_fcb_dbbt(struct mtd_info *mtd, struct fcb_block *fcb,
213 struct dbbt_block *dbbt, void *dbbt_data_page,
214 loff_t off)
215{
216 void *fcb_raw_page = 0;
217 int i, ret;
218 size_t dummy;
219
220 /*
221 * We prepare raw page only for i.MX6, for i.MX7 we
222 * leverage BCH hw module instead
223 */
224 if (is_mx6()) {
225 /* write fcb/dbbt */
226 fcb_raw_page = kzalloc(mtd->writesize + mtd->oobsize,
227 GFP_KERNEL);
228 if (!fcb_raw_page) {
229 debug("failed to allocate fcb_raw_page\n");
230 ret = -ENOMEM;
231 return ret;
232 }
233
234#if defined(CONFIG_MX6UL) || defined(CONFIG_MX6ULL)
235 /* 40 bit BCH, for i.MX6UL(L) */
236 encode_bch_ecc(fcb_raw_page + 32, fcb, 40);
237#else
238 memcpy(fcb_raw_page + 12, fcb, sizeof(struct fcb_block));
239 encode_hamming_13_8(fcb_raw_page + 12,
240 fcb_raw_page + 12 + 512, 512);
241#endif
242 /*
243 * Set the first and second byte of OOB data to 0xFF,
244 * not 0x00. These bytes are used as the Manufacturers Bad
245 * Block Marker (MBBM). Since the FCB is mostly written to
246 * the first page in a block, a scan for
247 * factory bad blocks will detect these blocks as bad, e.g.
248 * when function nand_scan_bbt() is executed to build a new
249 * bad block table.
250 */
251 memset(fcb_raw_page + mtd->writesize, 0xFF, 2);
252 }
253 for (i = 0; i < 2; i++) {
254 if (mtd_block_isbad(mtd, off)) {
255 printf("Block %d is bad, skipped\n", i);
256 continue;
257 }
258
259 /*
260 * User BCH ECC hardware module for i.MX7
261 */
262 if (is_mx7()) {
263 u32 off = i * mtd->erasesize;
264 size_t rwsize = sizeof(*fcb);
265
266 printf("Writing %d bytes to 0x%x: ", rwsize, off);
267
268 /* switch nand BCH to FCB compatible settings */
269 mxs_nand_mode_fcb(mtd);
270 ret = nand_write(mtd, off, &rwsize,
271 (unsigned char *)fcb);
272 mxs_nand_mode_normal(mtd);
273
274 printf("%s\n", ret ? "ERROR" : "OK");
275 } else if (is_mx6()) {
276 /* raw write */
277 mtd_oob_ops_t ops = {
278 .datbuf = (u8 *)fcb_raw_page,
279 .oobbuf = ((u8 *)fcb_raw_page) +
280 mtd->writesize,
281 .len = mtd->writesize,
282 .ooblen = mtd->oobsize,
283 .mode = MTD_OPS_RAW
284 };
285
286 ret = mtd_write_oob(mtd, mtd->erasesize * i, &ops);
287 if (ret)
288 goto fcb_raw_page_err;
289 debug("NAND fcb write: 0x%x offset 0x%x written: %s\n",
290 mtd->erasesize * i, ops.len, ret ?
291 "ERROR" : "OK");
292 }
293
294 ret = mtd_write(mtd, mtd->erasesize * i + mtd->writesize,
295 mtd->writesize, &dummy, (void *)dbbt);
296 if (ret)
297 goto fcb_raw_page_err;
298 debug("NAND dbbt write: 0x%x offset, 0x%x bytes written: %s\n",
299 mtd->erasesize * i + mtd->writesize, dummy,
300 ret ? "ERROR" : "OK");
301
302 /* dbbtpages == 0 if no bad blocks */
303 if (dbbt->dbbtpages > 0) {
304 loff_t to = (mtd->erasesize * i + mtd->writesize * 5);
305
306 ret = mtd_write(mtd, to, mtd->writesize, &dummy,
307 dbbt_data_page);
308 if (ret)
309 goto fcb_raw_page_err;
310 }
311 }
312
313fcb_raw_page_err:
314 if (is_mx6())
315 kfree(fcb_raw_page);
316
317 return ret;
318}
319
Shyam Saini1d43e242019-06-14 13:05:33 +0530320static int nandbcb_update(struct mtd_info *mtd, loff_t off, size_t size,
321 size_t maxsize, const u_char *buf)
322{
323 nand_erase_options_t opts;
324 struct fcb_block *fcb;
325 struct dbbt_block *dbbt;
326 loff_t fw1_off;
Igor Opaniuk1b899a82019-11-03 16:49:45 +0100327 void *fwbuf, *dbbt_page, *dbbt_data_page;
328 u32 fw1_start, fw1_pages;
Shyam Saini1d43e242019-06-14 13:05:33 +0530329 int nr_blks, nr_blks_fcb, fw1_blk;
Igor Opaniuk1b899a82019-11-03 16:49:45 +0100330 size_t fwsize;
331 int ret;
Shyam Saini1d43e242019-06-14 13:05:33 +0530332
333 /* erase */
334 memset(&opts, 0, sizeof(opts));
335 opts.offset = off;
336 opts.length = maxsize - 1;
337 ret = nand_erase_opts(mtd, &opts);
338 if (ret) {
339 printf("%s: erase failed (ret = %d)\n", __func__, ret);
340 return ret;
341 }
342
343 /*
344 * Reference documentation from i.MX6DQRM section 8.5.2.2
345 *
346 * Nand Boot Control Block(BCB) contains two data structures,
347 * - Firmware Configuration Block(FCB)
348 * - Discovered Bad Block Table(DBBT)
349 *
350 * FCB contains,
351 * - nand timings
352 * - DBBT search page address,
353 * - start page address of primary firmware
354 * - start page address of secondary firmware
355 *
356 * setup fcb:
357 * - number of blocks = mtd partition size / mtd erasesize
358 * - two firmware blocks, primary and secondary
359 * - first 4 block for FCB/DBBT
360 * - rest split in half for primary and secondary firmware
361 * - same firmware will write two times
362 */
363 nr_blks_fcb = 2;
364 nr_blks = maxsize / mtd->erasesize;
365 fw1_blk = nr_blks_fcb;
366
367 /* write fw */
368 fwsize = ALIGN(size + FLASH_OFFSET_STANDARD + mtd->writesize,
369 mtd->writesize);
370 fwbuf = kzalloc(fwsize, GFP_KERNEL);
371 if (!fwbuf) {
372 debug("failed to allocate fwbuf\n");
373 ret = -ENOMEM;
374 goto err;
375 }
376
377 memcpy(fwbuf + FLASH_OFFSET_STANDARD, buf, size);
378 fw1_off = fw1_blk * mtd->erasesize;
379 ret = nand_write_skip_bad(mtd, fw1_off, &fwsize, NULL, maxsize,
380 (u_char *)fwbuf, WITH_WR_VERIFY);
381 printf("NAND fw write: 0x%llx offset, 0x%x bytes written: %s\n",
382 fw1_off, fwsize, ret ? "ERROR" : "OK");
383 if (ret)
384 goto fwbuf_err;
385
386 /* fill fcb */
387 fcb = kzalloc(sizeof(*fcb), GFP_KERNEL);
388 if (!fcb) {
389 debug("failed to allocate fcb\n");
390 ret = -ENOMEM;
391 goto fwbuf_err;
392 }
393
Igor Opaniuk1b899a82019-11-03 16:49:45 +0100394 fw1_start = (fw1_blk * mtd->erasesize) / mtd->writesize;
395 fw1_pages = size / mtd->writesize + 1;
396 fill_fcb(fcb, mtd, fw1_start, 0, fw1_pages);
Shyam Saini1d43e242019-06-14 13:05:33 +0530397
398 /* fill dbbt */
399 dbbt_page = kzalloc(mtd->writesize, GFP_KERNEL);
400 if (!dbbt_page) {
401 debug("failed to allocate dbbt_page\n");
402 ret = -ENOMEM;
403 goto fcb_err;
404 }
405
406 dbbt_data_page = kzalloc(mtd->writesize, GFP_KERNEL);
407 if (!dbbt_data_page) {
408 debug("failed to allocate dbbt_data_page\n");
409 ret = -ENOMEM;
410 goto dbbt_page_err;
411 }
412
413 dbbt = dbbt_page;
414 dbbt->checksum = 0;
415 dbbt->fingerprint = DBBT_FINGERPRINT2;
416 dbbt->version = DBBT_VERSION_1;
417 ret = dbbt_fill_data(mtd, dbbt_data_page, nr_blks);
418 if (ret < 0)
419 goto dbbt_data_page_err;
420 else if (ret > 0)
421 dbbt->dbbtpages = 1;
422
Igor Opaniuk1b899a82019-11-03 16:49:45 +0100423 /* write fcb and dbbt to nand */
424 ret = write_fcb_dbbt(mtd, fcb, dbbt, dbbt_data_page, off);
425 if (ret < 0)
426 printf("failed to write FCB/DBBT\n");
Shyam Saini1d43e242019-06-14 13:05:33 +0530427
Shyam Saini1d43e242019-06-14 13:05:33 +0530428dbbt_data_page_err:
429 kfree(dbbt_data_page);
430dbbt_page_err:
431 kfree(dbbt_page);
432fcb_err:
433 kfree(fcb);
434fwbuf_err:
435 kfree(fwbuf);
436err:
437 return ret;
438}
439
Igor Opaniukae8a53e2019-11-03 16:49:46 +0100440static int do_nandbcb_bcbonly(int argc, char * const argv[])
441{
442 struct fcb_block *fcb;
443 struct dbbt_block *dbbt;
444 u32 fw_len, fw1_off, fw2_off;
445 struct mtd_info *mtd;
446 void *dbbt_page, *dbbt_data_page;
447 int dev, ret;
448
449 dev = nand_curr_device;
450 if ((dev < 0) || (dev >= CONFIG_SYS_MAX_NAND_DEVICE) ||
451 (!get_nand_dev_by_index(dev))) {
452 puts("No devices available\n");
453 return CMD_RET_FAILURE;
454 }
455
456 mtd = get_nand_dev_by_index(dev);
457
458 if (argc < 3)
459 return CMD_RET_FAILURE;
460
461 fw_len = simple_strtoul(argv[1], NULL, 16);
462 fw1_off = simple_strtoul(argv[2], NULL, 16);
463
464 if (argc > 3)
465 fw2_off = simple_strtoul(argv[3], NULL, 16);
466 else
467 fw2_off = fw1_off;
468
469 /* fill fcb */
470 fcb = kzalloc(sizeof(*fcb), GFP_KERNEL);
471 if (!fcb) {
472 debug("failed to allocate fcb\n");
473 ret = -ENOMEM;
474 return CMD_RET_FAILURE;
475 }
476
477 fill_fcb(fcb, mtd, fw1_off / mtd->writesize,
478 fw2_off / mtd->writesize, fw_len / mtd->writesize);
479
480 /* fill dbbt */
481 dbbt_page = kzalloc(mtd->writesize, GFP_KERNEL);
482 if (!dbbt_page) {
483 debug("failed to allocate dbbt_page\n");
484 ret = -ENOMEM;
485 goto fcb_err;
486 }
487
488 dbbt_data_page = kzalloc(mtd->writesize, GFP_KERNEL);
489 if (!dbbt_data_page) {
490 debug("failed to allocate dbbt_data_page\n");
491 ret = -ENOMEM;
492 goto dbbt_page_err;
493 }
494
495 dbbt = dbbt_page;
496 dbbt->checksum = 0;
497 dbbt->fingerprint = DBBT_FINGERPRINT2;
498 dbbt->version = DBBT_VERSION_1;
499 ret = dbbt_fill_data(mtd, dbbt_data_page, 0);
500 if (ret < 0)
501 goto dbbt_data_page_err;
502 else if (ret > 0)
503 dbbt->dbbtpages = 1;
504
505 /* write fcb and dbbt to nand */
506 ret = write_fcb_dbbt(mtd, fcb, dbbt, dbbt_data_page, 0);
507dbbt_data_page_err:
508 kfree(dbbt_data_page);
509dbbt_page_err:
510 kfree(dbbt_page);
511fcb_err:
512 kfree(fcb);
513
514 if (ret < 0) {
515 printf("failed to write FCB/DBBT\n");
516 return CMD_RET_FAILURE;
517 }
518
519 return CMD_RET_SUCCESS;
520}
521
Shyam Saini1d43e242019-06-14 13:05:33 +0530522static int do_nandbcb_update(int argc, char * const argv[])
523{
524 struct mtd_info *mtd;
525 loff_t addr, offset, size, maxsize;
526 char *endp;
527 u_char *buf;
528 int dev;
529 int ret;
530
531 if (argc != 4)
532 return CMD_RET_USAGE;
533
534 dev = nand_curr_device;
535 if (dev < 0) {
Igor Opaniuk1b899a82019-11-03 16:49:45 +0100536 printf("failed to get nand_curr_device, run nand device\n");
Shyam Saini1d43e242019-06-14 13:05:33 +0530537 return CMD_RET_FAILURE;
538 }
539
540 addr = simple_strtoul(argv[1], &endp, 16);
541 if (*argv[1] == 0 || *endp != 0)
542 return CMD_RET_FAILURE;
543
544 mtd = get_nand_dev_by_index(dev);
545 if (mtd_arg_off_size(argc - 2, argv + 2, &dev, &offset, &size,
546 &maxsize, MTD_DEV_TYPE_NAND, mtd->size))
547 return CMD_RET_FAILURE;
548
549 buf = map_physmem(addr, size, MAP_WRBACK);
550 if (!buf) {
551 puts("failed to map physical memory\n");
552 return CMD_RET_FAILURE;
553 }
554
555 ret = nandbcb_update(mtd, offset, size, maxsize, buf);
556
557 return ret == 0 ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
558}
559
560static int do_nandbcb(cmd_tbl_t *cmdtp, int flag, int argc,
561 char * const argv[])
562{
563 const char *cmd;
564 int ret = 0;
565
566 if (argc < 5)
567 goto usage;
568
569 cmd = argv[1];
570 --argc;
571 ++argv;
572
573 if (strcmp(cmd, "update") == 0) {
574 ret = do_nandbcb_update(argc, argv);
575 goto done;
576 }
577
Igor Opaniukae8a53e2019-11-03 16:49:46 +0100578 if (strcmp(cmd, "bcbonly") == 0) {
579 ret = do_nandbcb_bcbonly(argc, argv);
580 goto done;
581 }
582
Shyam Saini1d43e242019-06-14 13:05:33 +0530583done:
584 if (ret != -1)
585 return ret;
586usage:
587 return CMD_RET_USAGE;
588}
589
Parthiban Nallathambi4ee0ff12019-08-23 18:35:10 +0200590#ifdef CONFIG_SYS_LONGHELP
Shyam Saini1d43e242019-06-14 13:05:33 +0530591static char nandbcb_help_text[] =
592 "update addr off|partition len - update 'len' bytes starting at\n"
Igor Opaniukae8a53e2019-11-03 16:49:46 +0100593 " 'off|part' to memory address 'addr', skipping bad blocks\n"
594 "bcbonly fw-size fw1-off [fw2-off] - write only BCB (FCB and DBBT)\n"
Igor Opaniuk061b63b2019-12-16 14:06:44 +0200595 " where `fw-size` is fw sizes in bytes, `fw1-off`\n"
596 " and `fw2-off` - firmware offsets\n"
597 " FIY, BCB isn't erased automatically, so mtd erase should\n"
598 " be called in advance before writing new BCB:\n"
599 " > mtd erase mx7-bcb";
Parthiban Nallathambi4ee0ff12019-08-23 18:35:10 +0200600#endif
Shyam Saini1d43e242019-06-14 13:05:33 +0530601
602U_BOOT_CMD(nandbcb, 5, 1, do_nandbcb,
Igor Opaniuk061b63b2019-12-16 14:06:44 +0200603 "i.MX6/i.MX7 NAND Boot Control Blocks write",
Shyam Saini1d43e242019-06-14 13:05:33 +0530604 nandbcb_help_text
605);