From patchwork Thu Dec 17 11:27:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 344922 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp1076904jai; Thu, 17 Dec 2020 03:28:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJxHQz6MEsFUnkvIAxbXldHYxopfAvdU6XIKpg03pQa4yEzb1MEW8tSrsmEsZ3ZXtLKWrX/9 X-Received: by 2002:aa7:cd71:: with SMTP id ca17mr26355059edb.25.1608204507940; Thu, 17 Dec 2020 03:28:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608204507; cv=none; d=google.com; s=arc-20160816; b=a4pkS0BvvY9WCAEvA7wwheVatBK1MYxjd1WdUiIv4YjuwzF8X9DMuI8TbW8RDVG50i R25mr6uaBo+oEKwXpl+7hSXztMp/m8K0msrItiddpKLlqxCtWLP5hbHOhB8aE/sVWdbW QI0/fWm2XRLi5xuCH3EYaOa2BPy1Ng4tDR9P5VxC5szxby5Uqz3hq2QYpc7ek9Q6l+e3 bFvZBj5RJmUkNy5mNfovACk2Nyj6PSPOsT18lTqeXnYDdHfqPrFMmG+D9BAJQPBTSBge Ath81GKBdjDalgq+MSuYqf5iX7UGC25ySNVV2PwUPLZA+Zv/unlJHmslWXvyA/OrR5qA olhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:cms-type:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-filter; bh=vvzlqatTFFzXKj1PaWakVqBkiUvGiCiyTy6vU9s2otE=; b=ri9KCcO6E2SSvvUvYVcu0rQrhZyLRKZ8jAVnlr/W3ewBfp/T+WToNqUjB8Dm6xSTRf rr1EVJ0v593nmvENbUmLtc7A6+ozYJhkw10yogLclL6kon9Fw0V7tx/9G1ANT/XFJaCQ 3lGFIzRO6H5m1ofJNhLglmMlSDVu3wcv1shwST11L0TikDZ45Cacy1IiRuR0SKEW1V5s lH3dxkNF8vADg5mQsL4a+5ysUqLkdSEnZA77wy2Mrb7CvDFJSIFwBFwOzewMWxNbj+ue d0Kv0efghQTV2HYCTkqMWpIdpyp/DzGlHb4ky9gSFMmh/l3e097A0iltRSTG/vk8TGYt V9Qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=fwsHLY2x; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id 11si4533378edv.53.2020.12.17.03.28.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Dec 2020 03:28:27 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=fwsHLY2x; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1A50A82BB0; Thu, 17 Dec 2020 12:28:11 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=samsung.com header.i=@samsung.com header.b="fwsHLY2x"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 44B7482BA6; Thu, 17 Dec 2020 12:28:05 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E734882B9F for ; Thu, 17 Dec 2020 12:27:58 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=m.szyprowski@samsung.com Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20201217112748euoutp025d958d7dbcf06ddcc05b7deee84f80cf~RfXGK2JSE2566325663euoutp02E for ; Thu, 17 Dec 2020 11:27:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20201217112748euoutp025d958d7dbcf06ddcc05b7deee84f80cf~RfXGK2JSE2566325663euoutp02E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1608204468; bh=vvzlqatTFFzXKj1PaWakVqBkiUvGiCiyTy6vU9s2otE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fwsHLY2xA4GwEnId92u2T/6yUzVAThBUwdojNcxv2JhcexOxb8kjCJ5qiJ7RCcKL2 aI3PuK365nq9yUE4vbcdoxxRRwN+RxZhtN2rtsr3AQG7iINxbIEhGtd3AcoJr/3x8z jPFIYQ0cOL7MRcKRmKSo4OhYuaZ7Y2tD5TRlU3Vk= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20201217112748eucas1p22e95b6e5621bb71c983eb9c44874c6e8~RfXFt9NCO0440704407eucas1p2p; Thu, 17 Dec 2020 11:27:48 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 42.49.45488.3B04BDF5; Thu, 17 Dec 2020 11:27:47 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20201217112747eucas1p1cddfc0d3b072ceebb6e443c62a5d6d55~RfXFPeAsX3084730847eucas1p1b; Thu, 17 Dec 2020 11:27:47 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20201217112747eusmtrp2adfb0ce58e65640bba84a8165e722714~RfXFO2fHm2732627326eusmtrp2I; Thu, 17 Dec 2020 11:27:47 +0000 (GMT) X-AuditID: cbfec7f5-c5fff7000000b1b0-d6-5fdb40b3464c Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 2B.F0.16282.3B04BDF5; Thu, 17 Dec 2020 11:27:47 +0000 (GMT) Received: from AMDC2765.digital.local (unknown [106.120.51.73]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20201217112747eusmtip2ad0d002e80094662257afcb24bbaa0fd~RfXEzLYcJ2746427464eusmtip2L; Thu, 17 Dec 2020 11:27:47 +0000 (GMT) From: Marek Szyprowski To: u-boot@lists.denx.de Cc: Marek Szyprowski , Lukasz Majewski , Simon Glass , Heinrich Schuchardt , Jaehoon Chung , Bartlomiej Zolnierkiewicz Subject: [PATCH 6/6] cmd: Add MBR partition layout control utility Date: Thu, 17 Dec 2020 12:27:39 +0100 Message-Id: <20201217112739.5045-7-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201217112739.5045-1-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrAIsWRmVeSWpSXmKPExsWy7djPc7qbHW7HG9z6aWWxccZ6Vosbv9pY LZ6/u8xksfbIXXaLb1u2MVq83dvJbnF46gdGB3aP2Q0XWTzmzTrB4vHhY5zH2Ts7GD36tqxi DGCN4rJJSc3JLEst0rdL4Mpoef2RtWCrd8X6CffYGxh3W3UxcnJICJhIHHl2gLGLkYtDSGAF o8SlzjfMEM4XRomdb3+zQDifGSWWPlvJCtMyd/9VNojEckaJOV//MsG1LDl+lwWkik3AUKLr bRcbiC0iICHxq/8q2BJmgX+MEgd/fQQbJSzgJNH4/AUTiM0ioCoxe1cvWJxXwEbi6/MTUOvk JVZvOAB0FAcHp4CtxPL2MpA5EgJTOSR29L5jg6hxkdi1upcdwhaWeHV8C5QtI/F/53wmiIZm RomH59ayQzg9jBKXm2YwQlRZS9w594sNZAOzgKbE+l36EGFHib+behlBwhICfBI33gqChJmB zEnbpjNDhHklOtqEIKrVJGYdXwe39uCFS8wQtodES8NDdkgATWCUaFq5g3UCo/wshGULGBlX MYqnlhbnpqcWG+ellusVJ+YWl+al6yXn525iBCaK0/+Of93BuOLVR71DjEwcjIcYJTiYlUR4 Ew7cjBfiTUmsrEotyo8vKs1JLT7EKM3BoiTOu2vrmnghgfTEktTs1NSC1CKYLBMHp1QD06Jv pQWXvmp65Z67VchlFccds8fMUW+fi6rGrOMr7H+xy+eFzFO5anls5YaojVxz/uzdW3PW5573 zdIfj3snGzBwFe+dcv3nyYlLXzS19EceCIzIY3yS/v2zfFfH29PV09b93+exLHO/zLcKFtMZ gape854osgXJrP/9xzG9+1zLEx3GrAsfdjo942rbVbxnp4j4xRaBxRzFpedrpX9/nLG+Irb3 FXdwyyrZ9IVmT5bu+ONYlBFrk3bouvMGn99XWqbr9r7mPX1v1eLqI1MFN9zK4pS3D2n6fj1/ c/aTlLKfWS27X1XfLV7HVBYRllDgXNb7pi3EeOrXbfvslO6pTD+iJb2ISfbj1JLce1rS2Uos xRmJhlrMRcWJAEpa8qODAwAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrPLMWRmVeSWpSXmKPExsVy+t/xe7qbHW7HG6y5JGWxccZ6Vosbv9pY LZ6/u8xksfbIXXaLb1u2MVq83dvJbnF46gdGB3aP2Q0XWTzmzTrB4vHhY5zH2Ts7GD36tqxi DGCN0rMpyi8tSVXIyC8usVWKNrQw0jO0tNAzMrHUMzQ2j7UyMlXSt7NJSc3JLEst0rdL0Mto ef2RtWCrd8X6CffYGxh3W3UxcnJICJhIzN1/la2LkYtDSGApo8SS64tZIBIyEienNbBC2MIS f651QRV9YpRY/GQrE0iCTcBQoustSIKTQ0RAQuJX/1VGEJtZoIlJYu1/MFtYwEmi8fkLsHoW AVWJ2bt6wYbyCthIfH1+AmqBvMTqDQeYuxg5ODgFbCWWt5eBhIWASj6c3cQ4gZFvASPDKkaR 1NLi3PTcYiO94sTc4tK8dL3k/NxNjMCQ3Xbs55YdjCtffdQ7xMjEwXiIUYKDWUmEN+HAzXgh 3pTEyqrUovz4otKc1OJDjKZAZ0xklhJNzgdGTV5JvKGZgamhiZmlgamlmbGSOK/JkTXxQgLp iSWp2ampBalFMH1MHJxSDUxuLdEXfPXd69Z0SXI4b2P96uhzaHGIzsQNmVpCllXG637r3Nrt 8rNj00Rlr6DsG/sO3TZ4fLij4ipv6CPtrpV2Rf8cWU7OEbT8uSXwSv00M7+D7d9nCJ1eynwl 5bWo7RNOd2b9NVJPkkUDT8euc2JIFuBiedb3ry7oy4/9j2I/Vba7mXy5Z6iR03Iistb8mler l9Hcwzb93y5meq2aZ9Ys9Hqfwt3yIjYrvwV53xd1icTuW8BxKq1k+40dRnv0Xz7VPM/Dwdjw UG6Sgay0zLdDb9YwP4rYdH+VgiqvSYCDaJB8kOfyN/55JgYs74uN89+tK09LSjPWXD513zSD ilNHJ66xW/qYSe5IObeqqhJLcUaioRZzUXEiAMx+30HiAgAA X-CMS-MailID: 20201217112747eucas1p1cddfc0d3b072ceebb6e443c62a5d6d55 X-Msg-Generator: CA X-RootMTR: 20201217112747eucas1p1cddfc0d3b072ceebb6e443c62a5d6d55 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20201217112747eucas1p1cddfc0d3b072ceebb6e443c62a5d6d55 References: <20201217112739.5045-1-m.szyprowski@samsung.com> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Add a 'mbr' command to let user create or verify MBR partition layout based on the provided text description. The partition layout is altearnatively read from 'mbr_parts' environment variable. This can be used in scripts to help system image flashing tools to ensure proper partition layout. The syntax of the text description of the partition list is similar to the one used by the 'gpt' command. Supported parameters are: name (currently ignored), start (partition start offset in bytes), size (in bytes or '-' to expand it to the whole free area), bootable (boolean flag) and id (MBR partition system ID). If one wants to create more than 4 partitions, an 'Extended' primary partition (with 0x05 ID) has to be explicitely provided as a one of the first 4 entries. Here is the example how to create a 6 partitions (3 on the 'extended volume'), some of the predefined sizes: > setenv mbr_parts 'name=boot,start=4M,size=128M,bootable,id=0x0e; name=rootfs,size=3072M,id=0x83; name=system-data,size=512M,id=0x83; name=[ext],size=-,id=0x05; name=user,size=-,id=0x83; name=modules,size=100M,id=0x83; name=ramdisk,size=8M,id=0x83' > mbr write mmc 0 Signed-off-by: Marek Szyprowski --- cmd/Kconfig | 8 ++ cmd/Makefile | 1 + cmd/mbr.c | 308 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 317 insertions(+) create mode 100644 cmd/mbr.c -- 2.17.1 diff --git a/cmd/Kconfig b/cmd/Kconfig index 1595de999b..2c3358e359 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1025,6 +1025,14 @@ config CMD_LSBLK Print list of available block device drivers, and for each, the list of known block devices. +config CMD_MBR + bool "MBR (Master Boot Record) command" + select DOS_PARTITION + select HAVE_BLOCK_DEVICE + help + Enable the 'mbr' command to ready and write MBR (Master Boot Record) + style partition tables. + config CMD_MISC bool "misc" depends on MISC diff --git a/cmd/Makefile b/cmd/Makefile index dd86675bf2..41379d9a0e 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -178,6 +178,7 @@ obj-$(CONFIG_CMD_ZFS) += zfs.o obj-$(CONFIG_CMD_DFU) += dfu.o obj-$(CONFIG_CMD_GPT) += gpt.o +obj-$(CONFIG_CMD_MBR) += mbr.o obj-$(CONFIG_CMD_ETHSW) += ethsw.o obj-$(CONFIG_CMD_AXI) += axi.o obj-$(CONFIG_CMD_PVBLOCK) += pvblock.o diff --git a/cmd/mbr.c b/cmd/mbr.c new file mode 100644 index 0000000000..25a3f694d3 --- /dev/null +++ b/cmd/mbr.c @@ -0,0 +1,308 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * cmd_mbr.c -- MBR (Master Boot Record) handling command + * + * Copyright (C) 2020 Samsung Electronics + * author: Marek Szyprowski + * + * based on the gpt command. + */ + +#include +#include +#include +#include +#include + +/** + * extract_val(): Extract value from a key=value pair list (comma separated). + * Only value for the given key is returend. + * Function allocates memory for the value, remember to free! + * + * @param str - pointer to string with key=values pairs + * @param key - pointer to the key to search for + * + * @return - pointer to allocated string with the value + */ +static char *extract_val(const char *str, const char *key) +{ + char *v, *k; + char *s, *strcopy; + char *new = NULL; + + strcopy = strdup(str); + if (strcopy == NULL) + return NULL; + + s = strcopy; + while (s) { + v = strsep(&s, ","); + if (!v) + break; + k = strsep(&v, "="); + if (!k) + break; + if (strcmp(k, key) == 0) { + new = strdup(v); + break; + } + } + + free(strcopy); + + return new; +} + +/** + * found_key(): Found key without value in parameter list (comma separated). + * + * @param str - pointer to string with key + * @param key - pointer to the key to search for + * + * @return - true on found key + */ +static bool found_key(const char *str, const char *key) +{ + char *k; + char *s, *strcopy; + bool result = false; + + strcopy = strdup(str); + if (!strcopy) + return NULL; + + s = strcopy; + while (s) { + k = strsep(&s, ","); + if (!k) + break; + if (strcmp(k, key) == 0) { + result = true; + break; + } + } + + free(strcopy); + + return result; +} + +static int str_to_partition_info(const char *str_part, unsigned long *disk_uuid, + struct disk_partition **partitions, int *parts_count) +{ + char *tok, *str, *s; + int i; + char *val, *p; + int p_count; + struct disk_partition *parts; + int errno = 0; + uint64_t size_ll, start_ll; + + if (str_part == NULL) + return -1; + + str = strdup(str_part); + if (str == NULL) + return -ENOMEM; + + /* extract disk guid */ + s = str; + val = extract_val(str, "uuid_disk"); + if (val) { + val = strsep(&val, ";"); + p = val; + *disk_uuid = ustrtoull(p, &p, 0); + free(val); + /* Move s to first partition */ + strsep(&s, ";"); + } + if (s == NULL) { + printf("Error: is the partitions string NULL-terminated?\n"); + return -EINVAL; + } + + /* remove the optional semicolon at the end of the string */ + i = strlen(s) - 1; + if (s[i] == ';') + s[i] = '\0'; + + /* calculate expected number of partitions */ + p_count = 1; + p = s; + while (*p) { + if (*p++ == ';') + p_count++; + } + + /* allocate memory for partitions */ + parts = calloc(sizeof(struct disk_partition), p_count); + if (parts == NULL) + return -ENOMEM; + + /* retrieve partitions data from string */ + for (i = 0; i < p_count; i++) { + tok = strsep(&s, ";"); + + if (tok == NULL) + break; + + /* size */ + val = extract_val(tok, "size"); + if (!val) { /* 'size' is mandatory */ + errno = -4; + goto err; + } + p = val; + if ((strcmp(p, "-") == 0)) { + /* auto extend the size */ + parts[i].size = 0; + } else { + size_ll = ustrtoull(p, &p, 0); + parts[i].size = size_ll / 512; + } + free(val); + + /* start address */ + val = extract_val(tok, "start"); + if (val) { /* start address is optional */ + p = val; + start_ll = ustrtoull(p, &p, 0); + parts[i].start = start_ll / 512; + free(val); + } + + /* system id */ + val = extract_val(tok, "id"); + if (!val) { /* '' is mandatory */ + errno = -4; + goto err; + } + p = val; + parts[i].sys_ind = ustrtoul(p, &p, 0); + free(val); + + /* bootable */ + if (found_key(tok, "bootable")) + parts[i].bootable = PART_BOOTABLE; + } + + *parts_count = p_count; + *partitions = parts; + free(str); + + return 0; +err: + free(str); + free(parts); + + return errno; +} + +static int do_write_mbr(struct blk_desc *dev, const char *str) +{ + unsigned long disk_uuid = 0; + struct disk_partition *partitions; + int count; + + if (str_to_partition_info(str, &disk_uuid, &partitions, &count)) { + printf("MBR: failed to setup partitions from \"%s\"\n", str); + return -1; + } + + if (layout_mbr_partitions(partitions, count, dev->lba)) { + printf("MBR: failed to layout partitions on the device\n"); + free(partitions); + return -1; + } + + if (write_mbr_partitions(dev, partitions, count, disk_uuid)) { + printf("MBR: failed to write partitions to the device\n"); + free(partitions); + return -1; + } + + return 0; +} + +static int do_verify_mbr(struct blk_desc *dev, const char *str) +{ + unsigned long disk_uuid = 0; + struct disk_partition *partitions; + int count, i, ret = 1; + + if (str_to_partition_info(str, &disk_uuid, &partitions, &count)) { + printf("MBR: failed to setup partitions from \"%s\"\n", str); + return -1; + } + + for (i = 0; i < count; i++) { + struct disk_partition p; + + if (part_get_info(dev, i+1, &p)) + goto fail; + + if ((partitions[i].size && p.size < partitions[i].size) || + (partitions[i].start && p.start < partitions[i].start) || + (p.sys_ind != partitions[i].sys_ind)) + goto fail; + } + ret = 0; +fail: + free(partitions); + return ret; +} + +static int do_mbr(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) +{ + const char *parts = NULL; + int ret = CMD_RET_SUCCESS; + int dev = 0; + char *ep; + struct blk_desc *blk_dev_desc = NULL; + + if (argc != 4 && argc != 5) + return CMD_RET_USAGE; + + dev = (int)simple_strtoul(argv[3], &ep, 10); + if (!ep || ep[0] != '\0') { + printf("'%s' is not a number\n", argv[3]); + return CMD_RET_USAGE; + } + blk_dev_desc = blk_get_dev(argv[2], dev); + if (!blk_dev_desc) { + printf("%s: %s dev %d NOT available\n", + __func__, argv[2], dev); + return CMD_RET_FAILURE; + } + + if ((strcmp(argv[1], "write") == 0)) { + parts = (argc == 5) ? argv[4] : env_get("mbr_parts"); + printf("MBR: write "); + ret = do_write_mbr(blk_dev_desc, parts); + } else if ((strcmp(argv[1], "verify") == 0)) { + printf("MBR: verify "); + parts = (argc == 5) ? argv[4] : env_get("mbr_parts"); + ret = do_verify_mbr(blk_dev_desc, parts); + } else { + return CMD_RET_USAGE; + } + + if (ret) { + printf("error!\n"); + return CMD_RET_FAILURE; + } + + printf("success!\n"); + return CMD_RET_SUCCESS; +} + +U_BOOT_CMD(mbr, CONFIG_SYS_MAXARGS, 1, do_mbr, + "MBR (Master Boot Record)", + " \n" + " - MBR partition table restoration utility\n" + " Restore or check partition information on a device connected\n" + " to the given block interface\n" + " Example usage:\n" + " mbr write mmc 0 [\"${mbr_parts}\"]\n" + " mbr verify mmc 0 [\"${partitions}\"]\n" +);