Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Unsorted Block Image commands |
| 3 | * |
| 4 | * Copyright (C) 2008 Samsung Electronics |
| 5 | * Kyungmin Park <kyungmin.park@samsung.com> |
| 6 | * |
Stefan Roese | 62eafb7 | 2009-04-24 20:24:19 +0200 | [diff] [blame] | 7 | * Copyright 2008-2009 Stefan Roese <sr@denx.de>, DENX Software Engineering |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 8 | * |
| 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> |
Simon Glass | 313112a | 2019-08-01 09:46:46 -0600 | [diff] [blame] | 16 | #include <env.h> |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 17 | #include <exports.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 18 | #include <malloc.h> |
Simon Glass | a87fc0a | 2015-09-02 17:24:57 -0600 | [diff] [blame] | 19 | #include <memalign.h> |
Miquel Raynal | 12f1ff1 | 2018-09-29 12:58:29 +0200 | [diff] [blame] | 20 | #include <mtd.h> |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 21 | #include <nand.h> |
| 22 | #include <onenand_uboot.h> |
Simon Glass | d66c5f7 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 23 | #include <dm/devres.h> |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 24 | #include <linux/mtd/mtd.h> |
| 25 | #include <linux/mtd/partitions.h> |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 26 | #include <linux/err.h> |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 27 | #include <ubi_uboot.h> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 28 | #include <linux/errno.h> |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 29 | #include <jffs2/load_kernel.h> |
| 30 | |
Joe Hershberger | 47550fc | 2013-04-08 10:32:49 +0000 | [diff] [blame] | 31 | #undef ubi_msg |
| 32 | #define ubi_msg(fmt, ...) printf("UBI: " fmt "\n", ##__VA_ARGS__) |
| 33 | |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 34 | /* Private own data */ |
| 35 | static struct ubi_device *ubi; |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 36 | |
Stefan Roese | 408c6c4 | 2010-11-01 17:28:22 +0100 | [diff] [blame] | 37 | #ifdef CONFIG_CMD_UBIFS |
Tien Fong Chee | dbc9d85 | 2018-07-06 16:25:12 +0800 | [diff] [blame] | 38 | #include <ubifs_uboot.h> |
Stefan Roese | 408c6c4 | 2010-11-01 17:28:22 +0100 | [diff] [blame] | 39 | #endif |
| 40 | |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 41 | static void display_volume_info(struct ubi_device *ubi) |
| 42 | { |
| 43 | int i; |
| 44 | |
| 45 | for (i = 0; i < (ubi->vtbl_slots + 1); i++) { |
| 46 | if (!ubi->volumes[i]) |
| 47 | continue; /* Empty record */ |
| 48 | ubi_dump_vol_info(ubi->volumes[i]); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | static void display_ubi_info(struct ubi_device *ubi) |
| 53 | { |
| 54 | ubi_msg("MTD device name: \"%s\"", ubi->mtd->name); |
| 55 | ubi_msg("MTD device size: %llu MiB", ubi->flash_size >> 20); |
| 56 | ubi_msg("physical eraseblock size: %d bytes (%d KiB)", |
| 57 | ubi->peb_size, ubi->peb_size >> 10); |
| 58 | ubi_msg("logical eraseblock size: %d bytes", ubi->leb_size); |
| 59 | ubi_msg("number of good PEBs: %d", ubi->good_peb_count); |
| 60 | ubi_msg("number of bad PEBs: %d", ubi->bad_peb_count); |
| 61 | ubi_msg("smallest flash I/O unit: %d", ubi->min_io_size); |
| 62 | ubi_msg("VID header offset: %d (aligned %d)", |
| 63 | ubi->vid_hdr_offset, ubi->vid_hdr_aloffset); |
| 64 | ubi_msg("data offset: %d", ubi->leb_start); |
| 65 | ubi_msg("max. allowed volumes: %d", ubi->vtbl_slots); |
| 66 | ubi_msg("wear-leveling threshold: %d", CONFIG_MTD_UBI_WL_THRESHOLD); |
| 67 | ubi_msg("number of internal volumes: %d", UBI_INT_VOL_COUNT); |
| 68 | ubi_msg("number of user volumes: %d", |
| 69 | ubi->vol_count - UBI_INT_VOL_COUNT); |
| 70 | ubi_msg("available PEBs: %d", ubi->avail_pebs); |
| 71 | ubi_msg("total number of reserved PEBs: %d", ubi->rsvd_pebs); |
| 72 | ubi_msg("number of PEBs reserved for bad PEB handling: %d", |
| 73 | ubi->beb_rsvd_pebs); |
| 74 | ubi_msg("max/mean erase counter: %d/%d", ubi->max_ec, ubi->mean_ec); |
| 75 | } |
| 76 | |
| 77 | static int ubi_info(int layout) |
| 78 | { |
| 79 | if (layout) |
| 80 | display_volume_info(ubi); |
| 81 | else |
| 82 | display_ubi_info(ubi); |
| 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | |
Heiko Schocher | 1762ab1 | 2014-01-25 07:27:11 +0100 | [diff] [blame] | 87 | static int ubi_check_volumename(const struct ubi_volume *vol, char *name) |
| 88 | { |
| 89 | return strcmp(vol->name, name); |
| 90 | } |
| 91 | |
| 92 | static int ubi_check(char *name) |
| 93 | { |
| 94 | int i; |
| 95 | |
| 96 | for (i = 0; i < (ubi->vtbl_slots + 1); i++) { |
| 97 | if (!ubi->volumes[i]) |
| 98 | continue; /* Empty record */ |
| 99 | |
| 100 | if (!ubi_check_volumename(ubi->volumes[i], name)) |
| 101 | return 0; |
| 102 | } |
| 103 | |
Stefan Agner | 6a889f2 | 2015-04-10 11:25:43 +0200 | [diff] [blame] | 104 | return 1; |
Heiko Schocher | 1762ab1 | 2014-01-25 07:27:11 +0100 | [diff] [blame] | 105 | } |
| 106 | |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 107 | static int verify_mkvol_req(const struct ubi_device *ubi, |
| 108 | const struct ubi_mkvol_req *req) |
| 109 | { |
Stefan Roese | 8cfc696 | 2011-03-14 14:34:21 +0100 | [diff] [blame] | 110 | int n, err = EINVAL; |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 111 | |
| 112 | if (req->bytes < 0 || req->alignment < 0 || req->vol_type < 0 || |
| 113 | req->name_len < 0) |
| 114 | goto bad; |
| 115 | |
| 116 | if ((req->vol_id < 0 || req->vol_id >= ubi->vtbl_slots) && |
| 117 | req->vol_id != UBI_VOL_NUM_AUTO) |
| 118 | goto bad; |
| 119 | |
| 120 | if (req->alignment == 0) |
| 121 | goto bad; |
| 122 | |
Stefan Roese | 8cfc696 | 2011-03-14 14:34:21 +0100 | [diff] [blame] | 123 | if (req->bytes == 0) { |
| 124 | printf("No space left in UBI device!\n"); |
| 125 | err = ENOMEM; |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 126 | goto bad; |
Stefan Roese | 8cfc696 | 2011-03-14 14:34:21 +0100 | [diff] [blame] | 127 | } |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 128 | |
| 129 | if (req->vol_type != UBI_DYNAMIC_VOLUME && |
| 130 | req->vol_type != UBI_STATIC_VOLUME) |
| 131 | goto bad; |
| 132 | |
| 133 | if (req->alignment > ubi->leb_size) |
| 134 | goto bad; |
| 135 | |
| 136 | n = req->alignment % ubi->min_io_size; |
| 137 | if (req->alignment != 1 && n) |
| 138 | goto bad; |
| 139 | |
| 140 | if (req->name_len > UBI_VOL_NAME_MAX) { |
Stefan Roese | 8cfc696 | 2011-03-14 14:34:21 +0100 | [diff] [blame] | 141 | printf("Name too long!\n"); |
| 142 | err = ENAMETOOLONG; |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 143 | goto bad; |
| 144 | } |
| 145 | |
| 146 | return 0; |
| 147 | bad: |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 148 | return err; |
| 149 | } |
| 150 | |
Quentin Schulz | a88049b | 2019-09-12 16:41:01 +0200 | [diff] [blame] | 151 | static int ubi_create_vol(char *volume, int64_t size, int dynamic, int vol_id, |
| 152 | bool skipcheck) |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 153 | { |
| 154 | struct ubi_mkvol_req req; |
| 155 | int err; |
| 156 | |
| 157 | if (dynamic) |
| 158 | req.vol_type = UBI_DYNAMIC_VOLUME; |
| 159 | else |
| 160 | req.vol_type = UBI_STATIC_VOLUME; |
| 161 | |
Ladislav Michl | 39370f1 | 2016-09-13 07:14:01 +0200 | [diff] [blame] | 162 | req.vol_id = vol_id; |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 163 | req.alignment = 1; |
| 164 | req.bytes = size; |
| 165 | |
| 166 | strcpy(req.name, volume); |
| 167 | req.name_len = strlen(volume); |
| 168 | req.name[req.name_len] = '\0'; |
Quentin Schulz | a88049b | 2019-09-12 16:41:01 +0200 | [diff] [blame] | 169 | req.flags = 0; |
| 170 | if (skipcheck) |
| 171 | req.flags |= UBI_VOL_SKIP_CRC_CHECK_FLG; |
| 172 | |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 173 | /* It's duplicated at drivers/mtd/ubi/cdev.c */ |
| 174 | err = verify_mkvol_req(ubi, &req); |
| 175 | if (err) { |
| 176 | printf("verify_mkvol_req failed %d\n", err); |
| 177 | return err; |
| 178 | } |
Paul Burton | df68616 | 2013-09-04 15:16:58 +0100 | [diff] [blame] | 179 | printf("Creating %s volume %s of size %lld\n", |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 180 | dynamic ? "dynamic" : "static", volume, size); |
| 181 | /* Call real ubi create volume */ |
| 182 | return ubi_create_volume(ubi, &req); |
| 183 | } |
| 184 | |
Stefan Roese | 8cfc696 | 2011-03-14 14:34:21 +0100 | [diff] [blame] | 185 | static struct ubi_volume *ubi_find_volume(char *volume) |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 186 | { |
Peter Tyser | f2dbedc | 2010-04-04 22:40:50 -0500 | [diff] [blame] | 187 | struct ubi_volume *vol = NULL; |
Stefan Roese | 8cfc696 | 2011-03-14 14:34:21 +0100 | [diff] [blame] | 188 | int i; |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 189 | |
| 190 | for (i = 0; i < ubi->vtbl_slots; i++) { |
| 191 | vol = ubi->volumes[i]; |
Stefan Roese | 8cfc696 | 2011-03-14 14:34:21 +0100 | [diff] [blame] | 192 | if (vol && !strcmp(vol->name, volume)) |
| 193 | return vol; |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 194 | } |
Stefan Roese | 8cfc696 | 2011-03-14 14:34:21 +0100 | [diff] [blame] | 195 | |
| 196 | printf("Volume %s not found!\n", volume); |
| 197 | return NULL; |
| 198 | } |
| 199 | |
| 200 | static int ubi_remove_vol(char *volume) |
| 201 | { |
| 202 | int err, reserved_pebs, i; |
| 203 | struct ubi_volume *vol; |
| 204 | |
| 205 | vol = ubi_find_volume(volume); |
| 206 | if (vol == NULL) |
| 207 | return ENODEV; |
| 208 | |
| 209 | printf("Remove UBI volume %s (id %d)\n", vol->name, vol->vol_id); |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 210 | |
| 211 | if (ubi->ro_mode) { |
| 212 | printf("It's read-only mode\n"); |
Stefan Roese | 8cfc696 | 2011-03-14 14:34:21 +0100 | [diff] [blame] | 213 | err = EROFS; |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 214 | goto out_err; |
| 215 | } |
| 216 | |
Stefan Roese | 8cfc696 | 2011-03-14 14:34:21 +0100 | [diff] [blame] | 217 | err = ubi_change_vtbl_record(ubi, vol->vol_id, NULL); |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 218 | if (err) { |
| 219 | printf("Error changing Vol tabel record err=%x\n", err); |
| 220 | goto out_err; |
| 221 | } |
| 222 | reserved_pebs = vol->reserved_pebs; |
| 223 | for (i = 0; i < vol->reserved_pebs; i++) { |
| 224 | err = ubi_eba_unmap_leb(ubi, vol, i); |
| 225 | if (err) |
| 226 | goto out_err; |
| 227 | } |
| 228 | |
| 229 | kfree(vol->eba_tbl); |
Stefan Roese | 8cfc696 | 2011-03-14 14:34:21 +0100 | [diff] [blame] | 230 | ubi->volumes[vol->vol_id]->eba_tbl = NULL; |
| 231 | ubi->volumes[vol->vol_id] = NULL; |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 232 | |
| 233 | ubi->rsvd_pebs -= reserved_pebs; |
| 234 | ubi->avail_pebs += reserved_pebs; |
| 235 | i = ubi->beb_rsvd_level - ubi->beb_rsvd_pebs; |
| 236 | if (i > 0) { |
| 237 | i = ubi->avail_pebs >= i ? i : ubi->avail_pebs; |
| 238 | ubi->avail_pebs -= i; |
| 239 | ubi->rsvd_pebs += i; |
| 240 | ubi->beb_rsvd_pebs += i; |
| 241 | if (i > 0) |
| 242 | ubi_msg("reserve more %d PEBs", i); |
| 243 | } |
| 244 | ubi->vol_count -= 1; |
| 245 | |
| 246 | return 0; |
| 247 | out_err: |
Heiko Schocher | 94b66de | 2015-10-22 06:19:21 +0200 | [diff] [blame] | 248 | ubi_err(ubi, "cannot remove volume %s, error %d", volume, err); |
Stefan Roese | 8cfc696 | 2011-03-14 14:34:21 +0100 | [diff] [blame] | 249 | if (err < 0) |
| 250 | err = -err; |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 251 | return err; |
| 252 | } |
| 253 | |
Philippe Reynes | 10d5322 | 2020-03-23 19:20:47 +0100 | [diff] [blame] | 254 | static int ubi_rename_vol(char *oldname, char *newname) |
| 255 | { |
| 256 | struct ubi_volume *vol; |
| 257 | struct ubi_rename_entry rename; |
| 258 | struct ubi_volume_desc desc; |
| 259 | struct list_head list; |
| 260 | |
| 261 | vol = ubi_find_volume(oldname); |
| 262 | if (!vol) { |
| 263 | printf("%s: volume %s doesn't exist\n", __func__, oldname); |
| 264 | return ENODEV; |
| 265 | } |
| 266 | |
| 267 | printf("Rename UBI volume %s to %s\n", oldname, newname); |
| 268 | |
| 269 | if (ubi->ro_mode) { |
| 270 | printf("%s: ubi device is in read-only mode\n", __func__); |
| 271 | return EROFS; |
| 272 | } |
| 273 | |
| 274 | rename.new_name_len = strlen(newname); |
| 275 | strcpy(rename.new_name, newname); |
| 276 | rename.remove = 0; |
| 277 | desc.vol = vol; |
| 278 | desc.mode = 0; |
| 279 | rename.desc = &desc; |
| 280 | INIT_LIST_HEAD(&rename.list); |
| 281 | INIT_LIST_HEAD(&list); |
| 282 | list_add(&rename.list, &list); |
| 283 | |
| 284 | return ubi_rename_volumes(ubi, &list); |
| 285 | } |
| 286 | |
Jeroen Hofstee | f384fbf | 2014-06-23 00:22:08 +0200 | [diff] [blame] | 287 | static int ubi_volume_continue_write(char *volume, void *buf, size_t size) |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 288 | { |
Stefan Roese | 8cfc696 | 2011-03-14 14:34:21 +0100 | [diff] [blame] | 289 | int err = 1; |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 290 | struct ubi_volume *vol; |
| 291 | |
Stefan Roese | 8cfc696 | 2011-03-14 14:34:21 +0100 | [diff] [blame] | 292 | vol = ubi_find_volume(volume); |
| 293 | if (vol == NULL) |
| 294 | return ENODEV; |
| 295 | |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 296 | err = ubi_more_update_data(ubi, vol, buf, size); |
| 297 | if (err < 0) { |
Stefan Roese | 8cfc696 | 2011-03-14 14:34:21 +0100 | [diff] [blame] | 298 | printf("Couldnt or partially wrote data\n"); |
| 299 | return -err; |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | if (err) { |
| 303 | size = err; |
| 304 | |
| 305 | err = ubi_check_volume(ubi, vol->vol_id); |
Stefan Roese | 8cfc696 | 2011-03-14 14:34:21 +0100 | [diff] [blame] | 306 | if (err < 0) |
| 307 | return -err; |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 308 | |
| 309 | if (err) { |
Heiko Schocher | 94b66de | 2015-10-22 06:19:21 +0200 | [diff] [blame] | 310 | ubi_warn(ubi, "volume %d on UBI device %d is corrupt", |
| 311 | vol->vol_id, ubi->ubi_num); |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 312 | vol->corrupted = 1; |
| 313 | } |
| 314 | |
| 315 | vol->checked = 1; |
| 316 | ubi_gluebi_updated(vol); |
| 317 | } |
| 318 | |
| 319 | return 0; |
| 320 | } |
| 321 | |
Paul Burton | 6627aa3 | 2013-09-04 15:16:59 +0100 | [diff] [blame] | 322 | int ubi_volume_begin_write(char *volume, void *buf, size_t size, |
| 323 | size_t full_size) |
| 324 | { |
| 325 | int err = 1; |
| 326 | int rsvd_bytes = 0; |
| 327 | struct ubi_volume *vol; |
| 328 | |
| 329 | vol = ubi_find_volume(volume); |
| 330 | if (vol == NULL) |
| 331 | return ENODEV; |
| 332 | |
| 333 | rsvd_bytes = vol->reserved_pebs * (ubi->leb_size - vol->data_pad); |
xypron.glpk@gmx.de | 632a945 | 2017-04-15 16:25:25 +0200 | [diff] [blame] | 334 | if (size > rsvd_bytes) { |
Paul Burton | 6627aa3 | 2013-09-04 15:16:59 +0100 | [diff] [blame] | 335 | printf("size > volume size! Aborting!\n"); |
| 336 | return EINVAL; |
| 337 | } |
| 338 | |
| 339 | err = ubi_start_update(ubi, vol, full_size); |
| 340 | if (err < 0) { |
| 341 | printf("Cannot start volume update\n"); |
| 342 | return -err; |
| 343 | } |
| 344 | |
| 345 | return ubi_volume_continue_write(volume, buf, size); |
| 346 | } |
| 347 | |
| 348 | int ubi_volume_write(char *volume, void *buf, size_t size) |
| 349 | { |
| 350 | return ubi_volume_begin_write(volume, buf, size, size); |
| 351 | } |
| 352 | |
Joe Hershberger | 9219845 | 2013-04-08 10:32:47 +0000 | [diff] [blame] | 353 | int ubi_volume_read(char *volume, char *buf, size_t size) |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 354 | { |
Stefan Roese | 8cfc696 | 2011-03-14 14:34:21 +0100 | [diff] [blame] | 355 | int err, lnum, off, len, tbuf_size; |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 356 | void *tbuf; |
| 357 | unsigned long long tmp; |
Stefan Roese | 8cfc696 | 2011-03-14 14:34:21 +0100 | [diff] [blame] | 358 | struct ubi_volume *vol; |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 359 | loff_t offp = 0; |
Holger Dengler | a14912b | 2017-08-30 18:38:52 +0200 | [diff] [blame] | 360 | size_t len_read; |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 361 | |
Stefan Roese | 8cfc696 | 2011-03-14 14:34:21 +0100 | [diff] [blame] | 362 | vol = ubi_find_volume(volume); |
| 363 | if (vol == NULL) |
| 364 | return ENODEV; |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 365 | |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 366 | if (vol->updating) { |
| 367 | printf("updating"); |
Stefan Roese | 8cfc696 | 2011-03-14 14:34:21 +0100 | [diff] [blame] | 368 | return EBUSY; |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 369 | } |
| 370 | if (vol->upd_marker) { |
| 371 | printf("damaged volume, update marker is set"); |
Stefan Roese | 8cfc696 | 2011-03-14 14:34:21 +0100 | [diff] [blame] | 372 | return EBADF; |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 373 | } |
| 374 | if (offp == vol->used_bytes) |
| 375 | return 0; |
| 376 | |
| 377 | if (size == 0) { |
Stefan Roese | 8cfc696 | 2011-03-14 14:34:21 +0100 | [diff] [blame] | 378 | printf("No size specified -> Using max size (%lld)\n", vol->used_bytes); |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 379 | size = vol->used_bytes; |
| 380 | } |
| 381 | |
Tom Rini | 3aa6e39 | 2018-07-26 11:17:24 -0400 | [diff] [blame] | 382 | printf("Read %zu bytes from volume %s to %p\n", size, volume, buf); |
Stefan Agner | 08d4e0c | 2018-06-25 11:19:12 +0200 | [diff] [blame] | 383 | |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 384 | if (vol->corrupted) |
| 385 | printf("read from corrupted volume %d", vol->vol_id); |
| 386 | if (offp + size > vol->used_bytes) |
Marek Vasut | 40c0c8b | 2011-09-30 12:13:25 +0200 | [diff] [blame] | 387 | size = vol->used_bytes - offp; |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 388 | |
| 389 | tbuf_size = vol->usable_leb_size; |
| 390 | if (size < tbuf_size) |
| 391 | tbuf_size = ALIGN(size, ubi->min_io_size); |
Marcel Ziswiler | abc574b | 2015-08-18 13:06:37 +0200 | [diff] [blame] | 392 | tbuf = malloc_cache_aligned(tbuf_size); |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 393 | if (!tbuf) { |
| 394 | printf("NO MEM\n"); |
Stefan Roese | 8cfc696 | 2011-03-14 14:34:21 +0100 | [diff] [blame] | 395 | return ENOMEM; |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 396 | } |
| 397 | len = size > tbuf_size ? tbuf_size : size; |
| 398 | |
| 399 | tmp = offp; |
| 400 | off = do_div(tmp, vol->usable_leb_size); |
| 401 | lnum = tmp; |
Holger Dengler | a14912b | 2017-08-30 18:38:52 +0200 | [diff] [blame] | 402 | len_read = size; |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 403 | do { |
| 404 | if (off + len >= vol->usable_leb_size) |
| 405 | len = vol->usable_leb_size - off; |
| 406 | |
| 407 | err = ubi_eba_read_leb(ubi, vol, lnum, tbuf, off, len, 0); |
| 408 | if (err) { |
| 409 | printf("read err %x\n", err); |
Stefan Roese | 8cfc696 | 2011-03-14 14:34:21 +0100 | [diff] [blame] | 410 | err = -err; |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 411 | break; |
| 412 | } |
| 413 | off += len; |
| 414 | if (off == vol->usable_leb_size) { |
| 415 | lnum += 1; |
| 416 | off -= vol->usable_leb_size; |
| 417 | } |
| 418 | |
| 419 | size -= len; |
| 420 | offp += len; |
| 421 | |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 422 | memcpy(buf, tbuf, len); |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 423 | |
| 424 | buf += len; |
| 425 | len = size > tbuf_size ? tbuf_size : size; |
| 426 | } while (size); |
| 427 | |
Holger Dengler | a14912b | 2017-08-30 18:38:52 +0200 | [diff] [blame] | 428 | if (!size) |
| 429 | env_set_hex("filesize", len_read); |
| 430 | |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 431 | free(tbuf); |
Stefan Roese | 8cfc696 | 2011-03-14 14:34:21 +0100 | [diff] [blame] | 432 | return err; |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 433 | } |
| 434 | |
Miquel Raynal | 12f1ff1 | 2018-09-29 12:58:29 +0200 | [diff] [blame] | 435 | static int ubi_dev_scan(struct mtd_info *info, const char *vid_header_offset) |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 436 | { |
Simon Kagstrom | 4a8fbfb | 2009-07-07 16:59:46 +0200 | [diff] [blame] | 437 | char ubi_mtd_param_buffer[80]; |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 438 | int err; |
| 439 | |
Miquel Raynal | 12f1ff1 | 2018-09-29 12:58:29 +0200 | [diff] [blame] | 440 | if (!vid_header_offset) |
| 441 | sprintf(ubi_mtd_param_buffer, "%s", info->name); |
| 442 | else |
| 443 | sprintf(ubi_mtd_param_buffer, "%s,%s", info->name, |
| 444 | vid_header_offset); |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 445 | |
Simon Kagstrom | 4a8fbfb | 2009-07-07 16:59:46 +0200 | [diff] [blame] | 446 | err = ubi_mtd_param_parse(ubi_mtd_param_buffer, NULL); |
Miquel Raynal | 12f1ff1 | 2018-09-29 12:58:29 +0200 | [diff] [blame] | 447 | if (err) |
Stefan Roese | 8cfc696 | 2011-03-14 14:34:21 +0100 | [diff] [blame] | 448 | return -err; |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 449 | |
| 450 | err = ubi_init(); |
Miquel Raynal | 12f1ff1 | 2018-09-29 12:58:29 +0200 | [diff] [blame] | 451 | if (err) |
Stefan Roese | 8cfc696 | 2011-03-14 14:34:21 +0100 | [diff] [blame] | 452 | return -err; |
Stefan Roese | 1b20eb8 | 2008-11-27 14:07:09 +0100 | [diff] [blame] | 453 | |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 454 | return 0; |
| 455 | } |
| 456 | |
Stefan Roese | 9ea7786 | 2019-09-17 09:17:53 +0200 | [diff] [blame] | 457 | static int ubi_set_skip_check(char *volume, bool skip_check) |
| 458 | { |
| 459 | struct ubi_vtbl_record vtbl_rec; |
| 460 | struct ubi_volume *vol; |
| 461 | |
| 462 | vol = ubi_find_volume(volume); |
| 463 | if (!vol) |
| 464 | return ENODEV; |
| 465 | |
| 466 | printf("%sing skip_check on volume %s\n", |
| 467 | skip_check ? "Sett" : "Clear", volume); |
| 468 | |
| 469 | vtbl_rec = ubi->vtbl[vol->vol_id]; |
| 470 | if (skip_check) { |
| 471 | vtbl_rec.flags |= UBI_VTBL_SKIP_CRC_CHECK_FLG; |
| 472 | vol->skip_check = 1; |
| 473 | } else { |
| 474 | vtbl_rec.flags &= ~UBI_VTBL_SKIP_CRC_CHECK_FLG; |
| 475 | vol->skip_check = 0; |
| 476 | } |
| 477 | |
| 478 | return ubi_change_vtbl_record(ubi, vol->vol_id, &vtbl_rec); |
| 479 | } |
| 480 | |
Stefan Roese | 3d8686b | 2018-10-31 12:37:20 +0100 | [diff] [blame] | 481 | static int ubi_detach(void) |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 482 | { |
Joe Hershberger | 9219845 | 2013-04-08 10:32:47 +0000 | [diff] [blame] | 483 | #ifdef CONFIG_CMD_UBIFS |
| 484 | /* |
| 485 | * Automatically unmount UBIFS partition when user |
| 486 | * changes the UBI device. Otherwise the following |
| 487 | * UBIFS commands will crash. |
| 488 | */ |
| 489 | if (ubifs_is_mounted()) |
| 490 | cmd_ubifs_umount(); |
| 491 | #endif |
| 492 | |
Joe Hershberger | 9219845 | 2013-04-08 10:32:47 +0000 | [diff] [blame] | 493 | /* |
| 494 | * Call ubi_exit() before re-initializing the UBI subsystem |
| 495 | */ |
Miquel Raynal | 12f1ff1 | 2018-09-29 12:58:29 +0200 | [diff] [blame] | 496 | if (ubi) |
Joe Hershberger | 9219845 | 2013-04-08 10:32:47 +0000 | [diff] [blame] | 497 | ubi_exit(); |
Joe Hershberger | 9219845 | 2013-04-08 10:32:47 +0000 | [diff] [blame] | 498 | |
Miquel Raynal | 12f1ff1 | 2018-09-29 12:58:29 +0200 | [diff] [blame] | 499 | ubi = NULL; |
| 500 | |
Heiko Schocher | 8b4b05f | 2016-06-07 08:55:40 +0200 | [diff] [blame] | 501 | return 0; |
| 502 | } |
| 503 | |
| 504 | int ubi_part(char *part_name, const char *vid_header_offset) |
| 505 | { |
Miquel Raynal | 12f1ff1 | 2018-09-29 12:58:29 +0200 | [diff] [blame] | 506 | struct mtd_info *mtd; |
Heiko Schocher | 8b4b05f | 2016-06-07 08:55:40 +0200 | [diff] [blame] | 507 | int err = 0; |
Heiko Schocher | 8b4b05f | 2016-06-07 08:55:40 +0200 | [diff] [blame] | 508 | |
| 509 | ubi_detach(); |
Miquel Raynal | 12f1ff1 | 2018-09-29 12:58:29 +0200 | [diff] [blame] | 510 | |
| 511 | mtd_probe_devices(); |
| 512 | mtd = get_mtd_device_nm(part_name); |
| 513 | if (IS_ERR(mtd)) { |
Joe Hershberger | 9219845 | 2013-04-08 10:32:47 +0000 | [diff] [blame] | 514 | printf("Partition %s not found!\n", part_name); |
| 515 | return 1; |
| 516 | } |
Miquel Raynal | 12f1ff1 | 2018-09-29 12:58:29 +0200 | [diff] [blame] | 517 | put_mtd_device(mtd); |
Joe Hershberger | 9219845 | 2013-04-08 10:32:47 +0000 | [diff] [blame] | 518 | |
Miquel Raynal | 12f1ff1 | 2018-09-29 12:58:29 +0200 | [diff] [blame] | 519 | err = ubi_dev_scan(mtd, vid_header_offset); |
Joe Hershberger | 9219845 | 2013-04-08 10:32:47 +0000 | [diff] [blame] | 520 | if (err) { |
| 521 | printf("UBI init error %d\n", err); |
Stefan Roese | 8a717d5 | 2018-06-26 08:12:32 +0200 | [diff] [blame] | 522 | printf("Please check, if the correct MTD partition is used (size big enough?)\n"); |
Joe Hershberger | 9219845 | 2013-04-08 10:32:47 +0000 | [diff] [blame] | 523 | return err; |
| 524 | } |
| 525 | |
| 526 | ubi = ubi_devices[0]; |
| 527 | |
| 528 | return 0; |
| 529 | } |
| 530 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 531 | static int do_ubi(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
Joe Hershberger | 9219845 | 2013-04-08 10:32:47 +0000 | [diff] [blame] | 532 | { |
Paul Burton | df68616 | 2013-09-04 15:16:58 +0100 | [diff] [blame] | 533 | int64_t size = 0; |
Joe Hershberger | 9219845 | 2013-04-08 10:32:47 +0000 | [diff] [blame] | 534 | ulong addr = 0; |
Quentin Schulz | a88049b | 2019-09-12 16:41:01 +0200 | [diff] [blame] | 535 | bool skipcheck = false; |
Joe Hershberger | 9219845 | 2013-04-08 10:32:47 +0000 | [diff] [blame] | 536 | |
| 537 | if (argc < 2) |
| 538 | return CMD_RET_USAGE; |
Andreas Huber | 7bf15f8 | 2009-04-02 17:15:34 +0200 | [diff] [blame] | 539 | |
Heinrich Schuchardt | e7bfcff | 2019-01-06 12:26:28 +0100 | [diff] [blame] | 540 | if (strcmp(argv[1], "detach") == 0) |
Heiko Schocher | 8b4b05f | 2016-06-07 08:55:40 +0200 | [diff] [blame] | 541 | return ubi_detach(); |
Heiko Schocher | 8b4b05f | 2016-06-07 08:55:40 +0200 | [diff] [blame] | 542 | |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 543 | if (strcmp(argv[1], "part") == 0) { |
Simon Kagstrom | 4a8fbfb | 2009-07-07 16:59:46 +0200 | [diff] [blame] | 544 | const char *vid_header_offset = NULL; |
Stefan Roese | 62eafb7 | 2009-04-24 20:24:19 +0200 | [diff] [blame] | 545 | |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 546 | /* Print current partition */ |
| 547 | if (argc == 2) { |
Miquel Raynal | 12f1ff1 | 2018-09-29 12:58:29 +0200 | [diff] [blame] | 548 | if (!ubi) { |
| 549 | printf("Error, no UBI device selected!\n"); |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 550 | return 1; |
| 551 | } |
| 552 | |
Miquel Raynal | 12f1ff1 | 2018-09-29 12:58:29 +0200 | [diff] [blame] | 553 | printf("Device %d: %s, MTD partition %s\n", |
| 554 | ubi->ubi_num, ubi->ubi_name, ubi->mtd->name); |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 555 | return 0; |
| 556 | } |
| 557 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 558 | if (argc < 3) |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 559 | return CMD_RET_USAGE; |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 560 | |
Simon Kagstrom | 4a8fbfb | 2009-07-07 16:59:46 +0200 | [diff] [blame] | 561 | if (argc > 3) |
| 562 | vid_header_offset = argv[3]; |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 563 | |
Joe Hershberger | 9219845 | 2013-04-08 10:32:47 +0000 | [diff] [blame] | 564 | return ubi_part(argv[2], vid_header_offset); |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 565 | } |
| 566 | |
Miquel Raynal | 12f1ff1 | 2018-09-29 12:58:29 +0200 | [diff] [blame] | 567 | if ((strcmp(argv[1], "part") != 0) && !ubi) { |
| 568 | printf("Error, no UBI device selected!\n"); |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 569 | return 1; |
| 570 | } |
| 571 | |
| 572 | if (strcmp(argv[1], "info") == 0) { |
| 573 | int layout = 0; |
| 574 | if (argc > 2 && !strncmp(argv[2], "l", 1)) |
| 575 | layout = 1; |
| 576 | return ubi_info(layout); |
| 577 | } |
| 578 | |
Heiko Schocher | 1762ab1 | 2014-01-25 07:27:11 +0100 | [diff] [blame] | 579 | if (strcmp(argv[1], "check") == 0) { |
| 580 | if (argc > 2) |
| 581 | return ubi_check(argv[2]); |
| 582 | |
| 583 | printf("Error, no volume name passed\n"); |
| 584 | return 1; |
| 585 | } |
| 586 | |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 587 | if (strncmp(argv[1], "create", 6) == 0) { |
| 588 | int dynamic = 1; /* default: dynamic volume */ |
Ladislav Michl | 39370f1 | 2016-09-13 07:14:01 +0200 | [diff] [blame] | 589 | int id = UBI_VOL_NUM_AUTO; |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 590 | |
| 591 | /* Use maximum available size */ |
| 592 | size = 0; |
| 593 | |
Quentin Schulz | a88049b | 2019-09-12 16:41:01 +0200 | [diff] [blame] | 594 | /* E.g., create volume with "skipcheck" bit set */ |
| 595 | if (argc == 7) { |
| 596 | skipcheck = strncmp(argv[6], "--skipcheck", 11) == 0; |
| 597 | argc--; |
| 598 | } |
| 599 | |
Ladislav Michl | 39370f1 | 2016-09-13 07:14:01 +0200 | [diff] [blame] | 600 | /* E.g., create volume size type vol_id */ |
| 601 | if (argc == 6) { |
| 602 | id = simple_strtoull(argv[5], NULL, 16); |
| 603 | argc--; |
| 604 | } |
| 605 | |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 606 | /* E.g., create volume size type */ |
| 607 | if (argc == 5) { |
| 608 | if (strncmp(argv[4], "s", 1) == 0) |
| 609 | dynamic = 0; |
| 610 | else if (strncmp(argv[4], "d", 1) != 0) { |
| 611 | printf("Incorrect type\n"); |
| 612 | return 1; |
| 613 | } |
| 614 | argc--; |
| 615 | } |
| 616 | /* E.g., create volume size */ |
| 617 | if (argc == 4) { |
Ladislav Michl | 4fb937b | 2017-01-19 11:45:35 +0100 | [diff] [blame] | 618 | if (argv[3][0] != '-') |
| 619 | size = simple_strtoull(argv[3], NULL, 16); |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 620 | argc--; |
| 621 | } |
| 622 | /* Use maximum available size */ |
Stefan Roese | 8cfc696 | 2011-03-14 14:34:21 +0100 | [diff] [blame] | 623 | if (!size) { |
Paul Burton | df68616 | 2013-09-04 15:16:58 +0100 | [diff] [blame] | 624 | size = (int64_t)ubi->avail_pebs * ubi->leb_size; |
| 625 | printf("No size specified -> Using max size (%lld)\n", size); |
Stefan Roese | 8cfc696 | 2011-03-14 14:34:21 +0100 | [diff] [blame] | 626 | } |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 627 | /* E.g., create volume */ |
Quentin Schulz | a88049b | 2019-09-12 16:41:01 +0200 | [diff] [blame] | 628 | if (argc == 3) { |
| 629 | return ubi_create_vol(argv[2], size, dynamic, id, |
| 630 | skipcheck); |
| 631 | } |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | if (strncmp(argv[1], "remove", 6) == 0) { |
| 635 | /* E.g., remove volume */ |
| 636 | if (argc == 3) |
| 637 | return ubi_remove_vol(argv[2]); |
| 638 | } |
| 639 | |
Philippe Reynes | 10d5322 | 2020-03-23 19:20:47 +0100 | [diff] [blame] | 640 | if (IS_ENABLED(CONFIG_CMD_UBI_RENAME) && !strncmp(argv[1], "rename", 6)) |
| 641 | return ubi_rename_vol(argv[2], argv[3]); |
| 642 | |
Stefan Roese | 9ea7786 | 2019-09-17 09:17:53 +0200 | [diff] [blame] | 643 | if (strncmp(argv[1], "skipcheck", 9) == 0) { |
| 644 | /* E.g., change skip_check flag */ |
| 645 | if (argc == 4) { |
| 646 | skipcheck = strncmp(argv[3], "on", 2) == 0; |
| 647 | return ubi_set_skip_check(argv[2], skipcheck); |
| 648 | } |
| 649 | } |
| 650 | |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 651 | if (strncmp(argv[1], "write", 5) == 0) { |
Joe Hershberger | 9219845 | 2013-04-08 10:32:47 +0000 | [diff] [blame] | 652 | int ret; |
| 653 | |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 654 | if (argc < 5) { |
| 655 | printf("Please see usage\n"); |
| 656 | return 1; |
| 657 | } |
| 658 | |
| 659 | addr = simple_strtoul(argv[2], NULL, 16); |
Stefan Roese | 1b71405 | 2008-11-24 08:31:16 +0100 | [diff] [blame] | 660 | size = simple_strtoul(argv[4], NULL, 16); |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 661 | |
Paul Burton | 6627aa3 | 2013-09-04 15:16:59 +0100 | [diff] [blame] | 662 | if (strlen(argv[1]) == 10 && |
| 663 | strncmp(argv[1] + 5, ".part", 5) == 0) { |
| 664 | if (argc < 6) { |
| 665 | ret = ubi_volume_continue_write(argv[3], |
| 666 | (void *)addr, size); |
| 667 | } else { |
| 668 | size_t full_size; |
| 669 | full_size = simple_strtoul(argv[5], NULL, 16); |
| 670 | ret = ubi_volume_begin_write(argv[3], |
| 671 | (void *)addr, size, full_size); |
| 672 | } |
| 673 | } else { |
| 674 | ret = ubi_volume_write(argv[3], (void *)addr, size); |
| 675 | } |
Joe Hershberger | 9219845 | 2013-04-08 10:32:47 +0000 | [diff] [blame] | 676 | if (!ret) { |
Paul Burton | df68616 | 2013-09-04 15:16:58 +0100 | [diff] [blame] | 677 | printf("%lld bytes written to volume %s\n", size, |
Joe Hershberger | 9219845 | 2013-04-08 10:32:47 +0000 | [diff] [blame] | 678 | argv[3]); |
| 679 | } |
| 680 | |
| 681 | return ret; |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | if (strncmp(argv[1], "read", 4) == 0) { |
| 685 | size = 0; |
| 686 | |
| 687 | /* E.g., read volume size */ |
| 688 | if (argc == 5) { |
Stefan Roese | 1b71405 | 2008-11-24 08:31:16 +0100 | [diff] [blame] | 689 | size = simple_strtoul(argv[4], NULL, 16); |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 690 | argc--; |
| 691 | } |
| 692 | |
| 693 | /* E.g., read volume */ |
| 694 | if (argc == 4) { |
| 695 | addr = simple_strtoul(argv[2], NULL, 16); |
| 696 | argc--; |
| 697 | } |
| 698 | |
Joe Hershberger | 9219845 | 2013-04-08 10:32:47 +0000 | [diff] [blame] | 699 | if (argc == 3) { |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 700 | return ubi_volume_read(argv[3], (char *)addr, size); |
Joe Hershberger | 9219845 | 2013-04-08 10:32:47 +0000 | [diff] [blame] | 701 | } |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | printf("Please see usage\n"); |
Stefan Roese | 8cfc696 | 2011-03-14 14:34:21 +0100 | [diff] [blame] | 705 | return 1; |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 706 | } |
| 707 | |
Frans Meulenbroeks | 7675a09 | 2010-07-31 15:01:53 +0200 | [diff] [blame] | 708 | U_BOOT_CMD( |
Quentin Schulz | a88049b | 2019-09-12 16:41:01 +0200 | [diff] [blame] | 709 | ubi, 7, 1, do_ubi, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 710 | "ubi commands", |
Heiko Schocher | 8b4b05f | 2016-06-07 08:55:40 +0200 | [diff] [blame] | 711 | "detach" |
| 712 | " - detach ubi from a mtd partition\n" |
| 713 | "ubi part [part] [offset]\n" |
Simon Kagstrom | 4a8fbfb | 2009-07-07 16:59:46 +0200 | [diff] [blame] | 714 | " - Show or set current partition (with optional VID" |
| 715 | " header offset)\n" |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 716 | "ubi info [l[ayout]]" |
| 717 | " - Display volume and ubi layout information\n" |
Heiko Schocher | 1762ab1 | 2014-01-25 07:27:11 +0100 | [diff] [blame] | 718 | "ubi check volumename" |
| 719 | " - check if volumename exists\n" |
Quentin Schulz | a88049b | 2019-09-12 16:41:01 +0200 | [diff] [blame] | 720 | "ubi create[vol] volume [size] [type] [id] [--skipcheck]\n" |
Ladislav Michl | 4fb937b | 2017-01-19 11:45:35 +0100 | [diff] [blame] | 721 | " - create volume name with size ('-' for maximum" |
| 722 | " available size)\n" |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 723 | "ubi write[vol] address volume size" |
| 724 | " - Write volume from address with size\n" |
Paul Burton | 6627aa3 | 2013-09-04 15:16:59 +0100 | [diff] [blame] | 725 | "ubi write.part address volume size [fullsize]\n" |
| 726 | " - Write part of a volume from address\n" |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 727 | "ubi read[vol] address volume [size]" |
| 728 | " - Read volume to address with size\n" |
| 729 | "ubi remove[vol] volume" |
| 730 | " - Remove volume\n" |
Philippe Reynes | 10d5322 | 2020-03-23 19:20:47 +0100 | [diff] [blame] | 731 | #if IS_ENABLED(CONFIG_CMD_UBI_RENAME) |
| 732 | "ubi rename oldname newname\n" |
| 733 | #endif |
Stefan Roese | 9ea7786 | 2019-09-17 09:17:53 +0200 | [diff] [blame] | 734 | "ubi skipcheck volume on/off - Set or clear skip_check flag in volume header\n" |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 735 | "[Legends]\n" |
Andrzej Wolski | 7dcc170 | 2009-07-17 22:26:54 +0200 | [diff] [blame] | 736 | " volume: character name\n" |
| 737 | " size: specified in bytes\n" |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 738 | " type: s[tatic] or d[ynamic] (default=dynamic)" |
Kyungmin Park | 3d2c5ff | 2008-11-19 11:47:05 +0100 | [diff] [blame] | 739 | ); |