blob: b486ca8fefa0c625fcfbd545a7c407d5426668b2 [file] [log] [blame]
Kyungmin Park694a0b32008-11-19 11:47:05 +01001/*
2 * Unsorted Block Image commands
3 *
4 * Copyright (C) 2008 Samsung Electronics
5 * Kyungmin Park <kyungmin.park@samsung.com>
6 *
Stefan Roese2d579e52009-04-24 20:24:19 +02007 * Copyright 2008-2009 Stefan Roese <sr@denx.de>, DENX Software Engineering
Kyungmin Park694a0b32008-11-19 11:47:05 +01008 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#include <common.h>
15#include <command.h>
16#include <exports.h>
17
18#include <nand.h>
19#include <onenand_uboot.h>
20#include <linux/mtd/mtd.h>
21#include <linux/mtd/partitions.h>
22#include <ubi_uboot.h>
23#include <asm/errno.h>
24#include <jffs2/load_kernel.h>
25
26#define DEV_TYPE_NONE 0
27#define DEV_TYPE_NAND 1
28#define DEV_TYPE_ONENAND 2
Piotr Ziecik25ea6522008-11-17 15:58:00 +010029#define DEV_TYPE_NOR 3
Kyungmin Park694a0b32008-11-19 11:47:05 +010030
31/* Private own data */
32static struct ubi_device *ubi;
Stefan Roesea5c40672008-11-24 08:31:16 +010033static char buffer[80];
Stefan Roese2ee951b2008-11-27 14:07:09 +010034static int ubi_initialized;
Kyungmin Park694a0b32008-11-19 11:47:05 +010035
36struct selected_dev {
Kyungmin Park694a0b32008-11-19 11:47:05 +010037 char part_name[80];
Stefan Roese2d579e52009-04-24 20:24:19 +020038 int selected;
Kyungmin Park694a0b32008-11-19 11:47:05 +010039 int nr;
40 struct mtd_info *mtd_info;
41};
42
43static struct selected_dev ubi_dev;
44
Stefan Roese2f15cfd2010-11-01 17:28:22 +010045#ifdef CONFIG_CMD_UBIFS
46int ubifs_is_mounted(void);
47void cmd_ubifs_umount(void);
48#endif
49
Kyungmin Park694a0b32008-11-19 11:47:05 +010050static void ubi_dump_vol_info(const struct ubi_volume *vol)
51{
52 ubi_msg("volume information dump:");
53 ubi_msg("vol_id %d", vol->vol_id);
54 ubi_msg("reserved_pebs %d", vol->reserved_pebs);
55 ubi_msg("alignment %d", vol->alignment);
56 ubi_msg("data_pad %d", vol->data_pad);
57 ubi_msg("vol_type %d", vol->vol_type);
58 ubi_msg("name_len %d", vol->name_len);
59 ubi_msg("usable_leb_size %d", vol->usable_leb_size);
60 ubi_msg("used_ebs %d", vol->used_ebs);
61 ubi_msg("used_bytes %lld", vol->used_bytes);
62 ubi_msg("last_eb_bytes %d", vol->last_eb_bytes);
63 ubi_msg("corrupted %d", vol->corrupted);
64 ubi_msg("upd_marker %d", vol->upd_marker);
65
66 if (vol->name_len <= UBI_VOL_NAME_MAX &&
67 strnlen(vol->name, vol->name_len + 1) == vol->name_len) {
68 ubi_msg("name %s", vol->name);
69 } else {
70 ubi_msg("the 1st 5 characters of the name: %c%c%c%c%c",
71 vol->name[0], vol->name[1], vol->name[2],
72 vol->name[3], vol->name[4]);
73 }
74 printf("\n");
75}
76
77static void display_volume_info(struct ubi_device *ubi)
78{
79 int i;
80
81 for (i = 0; i < (ubi->vtbl_slots + 1); i++) {
82 if (!ubi->volumes[i])
83 continue; /* Empty record */
84 ubi_dump_vol_info(ubi->volumes[i]);
85 }
86}
87
88static void display_ubi_info(struct ubi_device *ubi)
89{
90 ubi_msg("MTD device name: \"%s\"", ubi->mtd->name);
91 ubi_msg("MTD device size: %llu MiB", ubi->flash_size >> 20);
92 ubi_msg("physical eraseblock size: %d bytes (%d KiB)",
93 ubi->peb_size, ubi->peb_size >> 10);
94 ubi_msg("logical eraseblock size: %d bytes", ubi->leb_size);
95 ubi_msg("number of good PEBs: %d", ubi->good_peb_count);
96 ubi_msg("number of bad PEBs: %d", ubi->bad_peb_count);
97 ubi_msg("smallest flash I/O unit: %d", ubi->min_io_size);
98 ubi_msg("VID header offset: %d (aligned %d)",
99 ubi->vid_hdr_offset, ubi->vid_hdr_aloffset);
100 ubi_msg("data offset: %d", ubi->leb_start);
101 ubi_msg("max. allowed volumes: %d", ubi->vtbl_slots);
102 ubi_msg("wear-leveling threshold: %d", CONFIG_MTD_UBI_WL_THRESHOLD);
103 ubi_msg("number of internal volumes: %d", UBI_INT_VOL_COUNT);
104 ubi_msg("number of user volumes: %d",
105 ubi->vol_count - UBI_INT_VOL_COUNT);
106 ubi_msg("available PEBs: %d", ubi->avail_pebs);
107 ubi_msg("total number of reserved PEBs: %d", ubi->rsvd_pebs);
108 ubi_msg("number of PEBs reserved for bad PEB handling: %d",
109 ubi->beb_rsvd_pebs);
110 ubi_msg("max/mean erase counter: %d/%d", ubi->max_ec, ubi->mean_ec);
111}
112
113static int ubi_info(int layout)
114{
115 if (layout)
116 display_volume_info(ubi);
117 else
118 display_ubi_info(ubi);
119
120 return 0;
121}
122
Kyungmin Park694a0b32008-11-19 11:47:05 +0100123static int verify_mkvol_req(const struct ubi_device *ubi,
124 const struct ubi_mkvol_req *req)
125{
126 int n, err = -EINVAL;
127
128 if (req->bytes < 0 || req->alignment < 0 || req->vol_type < 0 ||
129 req->name_len < 0)
130 goto bad;
131
132 if ((req->vol_id < 0 || req->vol_id >= ubi->vtbl_slots) &&
133 req->vol_id != UBI_VOL_NUM_AUTO)
134 goto bad;
135
136 if (req->alignment == 0)
137 goto bad;
138
139 if (req->bytes == 0)
140 goto bad;
141
142 if (req->vol_type != UBI_DYNAMIC_VOLUME &&
143 req->vol_type != UBI_STATIC_VOLUME)
144 goto bad;
145
146 if (req->alignment > ubi->leb_size)
147 goto bad;
148
149 n = req->alignment % ubi->min_io_size;
150 if (req->alignment != 1 && n)
151 goto bad;
152
153 if (req->name_len > UBI_VOL_NAME_MAX) {
154 err = -ENAMETOOLONG;
155 goto bad;
156 }
157
158 return 0;
159bad:
160 printf("bad volume creation request");
161 return err;
162}
163
164static int ubi_create_vol(char *volume, int size, int dynamic)
165{
166 struct ubi_mkvol_req req;
167 int err;
168
169 if (dynamic)
170 req.vol_type = UBI_DYNAMIC_VOLUME;
171 else
172 req.vol_type = UBI_STATIC_VOLUME;
173
174 req.vol_id = UBI_VOL_NUM_AUTO;
175 req.alignment = 1;
176 req.bytes = size;
177
178 strcpy(req.name, volume);
179 req.name_len = strlen(volume);
180 req.name[req.name_len] = '\0';
181 req.padding1 = 0;
182 /* It's duplicated at drivers/mtd/ubi/cdev.c */
183 err = verify_mkvol_req(ubi, &req);
184 if (err) {
185 printf("verify_mkvol_req failed %d\n", err);
186 return err;
187 }
188 printf("Creating %s volume %s of size %d\n",
189 dynamic ? "dynamic" : "static", volume, size);
190 /* Call real ubi create volume */
191 return ubi_create_volume(ubi, &req);
192}
193
194static int ubi_remove_vol(char *volume)
195{
196 int i, err, reserved_pebs;
197 int found = 0, vol_id = 0;
Peter Tyser3b653fd2010-04-04 22:40:50 -0500198 struct ubi_volume *vol = NULL;
Kyungmin Park694a0b32008-11-19 11:47:05 +0100199
200 for (i = 0; i < ubi->vtbl_slots; i++) {
201 vol = ubi->volumes[i];
202 if (vol && !strcmp(vol->name, volume)) {
203 printf("Volume %s found at valid %d\n", volume, i);
204 vol_id = i;
205 found = 1;
206 break;
207 }
208 }
209 if (!found) {
210 printf("%s volume not found\n", volume);
211 return -ENODEV;
212 }
213 printf("remove UBI volume %s (id %d)\n", vol->name, vol->vol_id);
214
215 if (ubi->ro_mode) {
216 printf("It's read-only mode\n");
217 err = -EROFS;
218 goto out_err;
219 }
220
221 err = ubi_change_vtbl_record(ubi, vol_id, NULL);
222 if (err) {
223 printf("Error changing Vol tabel record err=%x\n", err);
224 goto out_err;
225 }
226 reserved_pebs = vol->reserved_pebs;
227 for (i = 0; i < vol->reserved_pebs; i++) {
228 err = ubi_eba_unmap_leb(ubi, vol, i);
229 if (err)
230 goto out_err;
231 }
232
233 kfree(vol->eba_tbl);
234 ubi->volumes[vol_id]->eba_tbl = NULL;
235 ubi->volumes[vol_id] = NULL;
236
237 ubi->rsvd_pebs -= reserved_pebs;
238 ubi->avail_pebs += reserved_pebs;
239 i = ubi->beb_rsvd_level - ubi->beb_rsvd_pebs;
240 if (i > 0) {
241 i = ubi->avail_pebs >= i ? i : ubi->avail_pebs;
242 ubi->avail_pebs -= i;
243 ubi->rsvd_pebs += i;
244 ubi->beb_rsvd_pebs += i;
245 if (i > 0)
246 ubi_msg("reserve more %d PEBs", i);
247 }
248 ubi->vol_count -= 1;
249
250 return 0;
251out_err:
252 ubi_err("cannot remove volume %d, error %d", vol_id, err);
253 return err;
254}
255
256static int ubi_volume_write(char *volume, void *buf, size_t size)
257{
258 int i = 0, err = -1;
259 int rsvd_bytes = 0;
260 int found = 0;
261 struct ubi_volume *vol;
262
263 for (i = 0; i < ubi->vtbl_slots; i++) {
264 vol = ubi->volumes[i];
265 if (vol && !strcmp(vol->name, volume)) {
266 printf("Volume \"%s\" found at volume id %d\n", volume, i);
267 found = 1;
268 break;
269 }
270 }
271 if (!found) {
272 printf("%s volume not found\n", volume);
273 return 1;
274 }
275 rsvd_bytes = vol->reserved_pebs * (ubi->leb_size - vol->data_pad);
276 if (size < 0 || size > rsvd_bytes) {
277 printf("rsvd_bytes=%d vol->reserved_pebs=%d ubi->leb_size=%d\n",
278 rsvd_bytes, vol->reserved_pebs, ubi->leb_size);
279 printf("vol->data_pad=%d\n", vol->data_pad);
280 printf("Size > volume size !!\n");
281 return 1;
282 }
283
284 err = ubi_start_update(ubi, vol, size);
285 if (err < 0) {
286 printf("Cannot start volume update\n");
287 return err;
288 }
289
290 err = ubi_more_update_data(ubi, vol, buf, size);
291 if (err < 0) {
292 printf("Couldnt or partially wrote data \n");
293 return err;
294 }
295
296 if (err) {
297 size = err;
298
299 err = ubi_check_volume(ubi, vol->vol_id);
300 if ( err < 0 )
301 return err;
302
303 if (err) {
304 ubi_warn("volume %d on UBI device %d is corrupted",
305 vol->vol_id, ubi->ubi_num);
306 vol->corrupted = 1;
307 }
308
309 vol->checked = 1;
310 ubi_gluebi_updated(vol);
311 }
312
313 return 0;
314}
315
316static int ubi_volume_read(char *volume, char *buf, size_t size)
317{
318 int err, lnum, off, len, tbuf_size, i = 0;
319 size_t count_save = size;
320 void *tbuf;
321 unsigned long long tmp;
322 struct ubi_volume *vol = NULL;
323 loff_t offp = 0;
324
325 for (i = 0; i < ubi->vtbl_slots; i++) {
326 vol = ubi->volumes[i];
327 if (vol && !strcmp(vol->name, volume)) {
328 printf("Volume %s found at volume id %d\n",
329 volume, vol->vol_id);
330 break;
331 }
332 }
333 if (i == ubi->vtbl_slots) {
334 printf("%s volume not found\n", volume);
Andreas Huber08503012009-05-19 11:06:30 +0200335 return -ENODEV;
Kyungmin Park694a0b32008-11-19 11:47:05 +0100336 }
337
338 printf("read %i bytes from volume %d to %x(buf address)\n",
339 (int) size, vol->vol_id, (unsigned)buf);
340
341 if (vol->updating) {
342 printf("updating");
343 return -EBUSY;
344 }
345 if (vol->upd_marker) {
346 printf("damaged volume, update marker is set");
347 return -EBADF;
348 }
349 if (offp == vol->used_bytes)
350 return 0;
351
352 if (size == 0) {
353 printf("Read [%lu] bytes\n", (unsigned long) vol->used_bytes);
354 size = vol->used_bytes;
355 }
356
357 if (vol->corrupted)
358 printf("read from corrupted volume %d", vol->vol_id);
359 if (offp + size > vol->used_bytes)
360 count_save = size = vol->used_bytes - offp;
361
362 tbuf_size = vol->usable_leb_size;
363 if (size < tbuf_size)
364 tbuf_size = ALIGN(size, ubi->min_io_size);
365 tbuf = malloc(tbuf_size);
366 if (!tbuf) {
367 printf("NO MEM\n");
368 return -ENOMEM;
369 }
370 len = size > tbuf_size ? tbuf_size : size;
371
372 tmp = offp;
373 off = do_div(tmp, vol->usable_leb_size);
374 lnum = tmp;
Kyungmin Park694a0b32008-11-19 11:47:05 +0100375 do {
376 if (off + len >= vol->usable_leb_size)
377 len = vol->usable_leb_size - off;
378
379 err = ubi_eba_read_leb(ubi, vol, lnum, tbuf, off, len, 0);
380 if (err) {
381 printf("read err %x\n", err);
382 break;
383 }
384 off += len;
385 if (off == vol->usable_leb_size) {
386 lnum += 1;
387 off -= vol->usable_leb_size;
388 }
389
390 size -= len;
391 offp += len;
392
Kyungmin Park694a0b32008-11-19 11:47:05 +0100393 memcpy(buf, tbuf, len);
Kyungmin Park694a0b32008-11-19 11:47:05 +0100394
395 buf += len;
396 len = size > tbuf_size ? tbuf_size : size;
397 } while (size);
398
399 free(tbuf);
400 return err ? err : count_save - size;
401}
402
Simon Kagstrom25c8f402009-07-07 16:59:46 +0200403static int ubi_dev_scan(struct mtd_info *info, char *ubidev,
404 const char *vid_header_offset)
Kyungmin Park694a0b32008-11-19 11:47:05 +0100405{
406 struct mtd_device *dev;
407 struct part_info *part;
408 struct mtd_partition mtd_part;
Simon Kagstrom25c8f402009-07-07 16:59:46 +0200409 char ubi_mtd_param_buffer[80];
Kyungmin Park694a0b32008-11-19 11:47:05 +0100410 u8 pnum;
411 int err;
412
Kyungmin Park694a0b32008-11-19 11:47:05 +0100413 if (find_dev_and_part(ubidev, &dev, &pnum, &part) != 0)
414 return 1;
415
416 sprintf(buffer, "mtd=%d", pnum);
417 memset(&mtd_part, 0, sizeof(mtd_part));
418 mtd_part.name = buffer;
419 mtd_part.size = part->size;
420 mtd_part.offset = part->offset;
421 add_mtd_partitions(info, &mtd_part, 1);
422
Simon Kagstrom25c8f402009-07-07 16:59:46 +0200423 strcpy(ubi_mtd_param_buffer, buffer);
424 if (vid_header_offset)
425 sprintf(ubi_mtd_param_buffer, "mtd=%d,%s", pnum,
426 vid_header_offset);
427 err = ubi_mtd_param_parse(ubi_mtd_param_buffer, NULL);
Kyungmin Park694a0b32008-11-19 11:47:05 +0100428 if (err) {
429 del_mtd_partitions(info);
430 return err;
431 }
432
433 err = ubi_init();
434 if (err) {
435 del_mtd_partitions(info);
436 return err;
437 }
438
Stefan Roese2ee951b2008-11-27 14:07:09 +0100439 ubi_initialized = 1;
440
Kyungmin Park694a0b32008-11-19 11:47:05 +0100441 return 0;
442}
443
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200444static int do_ubi(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
Kyungmin Park694a0b32008-11-19 11:47:05 +0100445{
446 size_t size = 0;
447 ulong addr = 0;
448 int err = 0;
449
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200450 if (argc < 2)
451 return cmd_usage(cmdtp);
Kyungmin Park694a0b32008-11-19 11:47:05 +0100452
Andreas Huberc203ef52009-04-02 17:15:34 +0200453 if (mtdparts_init() != 0) {
454 printf("Error initializing mtdparts!\n");
455 return 1;
456 }
457
Kyungmin Park694a0b32008-11-19 11:47:05 +0100458 if (strcmp(argv[1], "part") == 0) {
Stefan Roese2d579e52009-04-24 20:24:19 +0200459 char mtd_dev[16];
460 struct mtd_device *dev;
461 struct part_info *part;
Simon Kagstrom25c8f402009-07-07 16:59:46 +0200462 const char *vid_header_offset = NULL;
Stefan Roese2d579e52009-04-24 20:24:19 +0200463 u8 pnum;
464
Kyungmin Park694a0b32008-11-19 11:47:05 +0100465 /* Print current partition */
466 if (argc == 2) {
Stefan Roese2d579e52009-04-24 20:24:19 +0200467 if (!ubi_dev.selected) {
Kyungmin Park694a0b32008-11-19 11:47:05 +0100468 printf("Error, no UBI device/partition selected!\n");
469 return 1;
470 }
471
Stefan Roese2d579e52009-04-24 20:24:19 +0200472 printf("Device %d: %s, partition %s\n",
Kyungmin Park694a0b32008-11-19 11:47:05 +0100473 ubi_dev.nr, ubi_dev.mtd_info->name, ubi_dev.part_name);
474 return 0;
475 }
476
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200477 if (argc < 3)
478 return cmd_usage(cmdtp);
Kyungmin Park694a0b32008-11-19 11:47:05 +0100479
Stefan Roese2f15cfd2010-11-01 17:28:22 +0100480#ifdef CONFIG_CMD_UBIFS
481 /*
482 * Automatically unmount UBIFS partition when user
483 * changes the UBI device. Otherwise the following
484 * UBIFS commands will crash.
485 */
486 if (ubifs_is_mounted())
487 cmd_ubifs_umount();
488#endif
489
Kyungmin Park694a0b32008-11-19 11:47:05 +0100490 /* todo: get dev number for NAND... */
491 ubi_dev.nr = 0;
492
493 /*
Stefan Roese2ee951b2008-11-27 14:07:09 +0100494 * Call ubi_exit() before re-initializing the UBI subsystem
495 */
496 if (ubi_initialized) {
497 ubi_exit();
498 del_mtd_partitions(ubi_dev.mtd_info);
499 }
500
501 /*
Stefan Roese2d579e52009-04-24 20:24:19 +0200502 * Search the mtd device number where this partition
503 * is located
Kyungmin Park694a0b32008-11-19 11:47:05 +0100504 */
Stefan Roese2d579e52009-04-24 20:24:19 +0200505 if (find_dev_and_part(argv[2], &dev, &pnum, &part)) {
506 printf("Partition %s not found!\n", argv[2]);
507 return 1;
Kyungmin Park694a0b32008-11-19 11:47:05 +0100508 }
Stefan Roese2d579e52009-04-24 20:24:19 +0200509 sprintf(mtd_dev, "%s%d", MTD_DEV_TYPE(dev->id->type), dev->id->num);
510 ubi_dev.mtd_info = get_mtd_device_nm(mtd_dev);
511 if (IS_ERR(ubi_dev.mtd_info)) {
512 printf("Partition %s not found on device %s!\n", argv[2], mtd_dev);
Kyungmin Park694a0b32008-11-19 11:47:05 +0100513 return 1;
514 }
515
Stefan Roese2d579e52009-04-24 20:24:19 +0200516 ubi_dev.selected = 1;
517
Simon Kagstrom25c8f402009-07-07 16:59:46 +0200518 if (argc > 3)
519 vid_header_offset = argv[3];
Stefan Roese2d579e52009-04-24 20:24:19 +0200520 strcpy(ubi_dev.part_name, argv[2]);
Simon Kagstrom25c8f402009-07-07 16:59:46 +0200521 err = ubi_dev_scan(ubi_dev.mtd_info, ubi_dev.part_name,
522 vid_header_offset);
Kyungmin Park694a0b32008-11-19 11:47:05 +0100523 if (err) {
524 printf("UBI init error %d\n", err);
Stefan Roese2d579e52009-04-24 20:24:19 +0200525 ubi_dev.selected = 0;
Kyungmin Park694a0b32008-11-19 11:47:05 +0100526 return err;
527 }
528
529 ubi = ubi_devices[0];
530
531 return 0;
532 }
533
Stefan Roese2d579e52009-04-24 20:24:19 +0200534 if ((strcmp(argv[1], "part") != 0) && (!ubi_dev.selected)) {
Kyungmin Park694a0b32008-11-19 11:47:05 +0100535 printf("Error, no UBI device/partition selected!\n");
536 return 1;
537 }
538
539 if (strcmp(argv[1], "info") == 0) {
540 int layout = 0;
541 if (argc > 2 && !strncmp(argv[2], "l", 1))
542 layout = 1;
543 return ubi_info(layout);
544 }
545
546 if (strncmp(argv[1], "create", 6) == 0) {
547 int dynamic = 1; /* default: dynamic volume */
548
549 /* Use maximum available size */
550 size = 0;
551
552 /* E.g., create volume size type */
553 if (argc == 5) {
554 if (strncmp(argv[4], "s", 1) == 0)
555 dynamic = 0;
556 else if (strncmp(argv[4], "d", 1) != 0) {
557 printf("Incorrect type\n");
558 return 1;
559 }
560 argc--;
561 }
562 /* E.g., create volume size */
563 if (argc == 4) {
Stefan Roese2d2e0572008-12-02 10:53:47 +0100564 size = simple_strtoul(argv[3], NULL, 16);
Kyungmin Park694a0b32008-11-19 11:47:05 +0100565 argc--;
566 }
567 /* Use maximum available size */
568 if (!size)
569 size = ubi->avail_pebs * ubi->leb_size;
570 /* E.g., create volume */
571 if (argc == 3)
572 return ubi_create_vol(argv[2], size, dynamic);
573 }
574
575 if (strncmp(argv[1], "remove", 6) == 0) {
576 /* E.g., remove volume */
577 if (argc == 3)
578 return ubi_remove_vol(argv[2]);
579 }
580
581 if (strncmp(argv[1], "write", 5) == 0) {
582 if (argc < 5) {
583 printf("Please see usage\n");
584 return 1;
585 }
586
587 addr = simple_strtoul(argv[2], NULL, 16);
Stefan Roesea5c40672008-11-24 08:31:16 +0100588 size = simple_strtoul(argv[4], NULL, 16);
Kyungmin Park694a0b32008-11-19 11:47:05 +0100589
590 return ubi_volume_write(argv[3], (void *)addr, size);
591 }
592
593 if (strncmp(argv[1], "read", 4) == 0) {
594 size = 0;
595
596 /* E.g., read volume size */
597 if (argc == 5) {
Stefan Roesea5c40672008-11-24 08:31:16 +0100598 size = simple_strtoul(argv[4], NULL, 16);
Kyungmin Park694a0b32008-11-19 11:47:05 +0100599 argc--;
600 }
601
602 /* E.g., read volume */
603 if (argc == 4) {
604 addr = simple_strtoul(argv[2], NULL, 16);
605 argc--;
606 }
607
608 if (argc == 3)
609 return ubi_volume_read(argv[3], (char *)addr, size);
610 }
611
612 printf("Please see usage\n");
613 return -1;
614}
615
Frans Meulenbroeks388a29d2010-07-31 15:01:53 +0200616U_BOOT_CMD(
617 ubi, 6, 1, do_ubi,
Peter Tyser2fb26042009-01-27 18:03:12 -0600618 "ubi commands",
Simon Kagstrom25c8f402009-07-07 16:59:46 +0200619 "part [part] [offset]\n"
620 " - Show or set current partition (with optional VID"
621 " header offset)\n"
Kyungmin Park694a0b32008-11-19 11:47:05 +0100622 "ubi info [l[ayout]]"
623 " - Display volume and ubi layout information\n"
624 "ubi create[vol] volume [size] [type]"
625 " - create volume name with size\n"
626 "ubi write[vol] address volume size"
627 " - Write volume from address with size\n"
628 "ubi read[vol] address volume [size]"
629 " - Read volume to address with size\n"
630 "ubi remove[vol] volume"
631 " - Remove volume\n"
632 "[Legends]\n"
Andrzej Wolskif6ca3b72009-07-17 22:26:54 +0200633 " volume: character name\n"
634 " size: specified in bytes\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200635 " type: s[tatic] or d[ynamic] (default=dynamic)"
Kyungmin Park694a0b32008-11-19 11:47:05 +0100636);