From: Marco Felsch <m.felsch@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH v2 2/4] parted: add support for gpt-location
Date: Wed, 23 Apr 2025 16:09:11 +0200 [thread overview]
Message-ID: <20250423140913.1530237-2-m.felsch@pengutronix.de> (raw)
In-Reply-To: <20250423140913.1530237-1-m.felsch@pengutronix.de>
Add support to place the GPT partition entries to random places instead
of LBA2.
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
v2:
- new
commands/parted.c | 29 +++++++++++++++++++++++++++--
1 file changed, 27 insertions(+), 2 deletions(-)
diff --git a/commands/parted.c b/commands/parted.c
index 90cee1ede10e..895c06524d4c 100644
--- a/commands/parted.c
+++ b/commands/parted.c
@@ -224,6 +224,30 @@ static int do_mklabel(struct block_device *blk, int argc, char *argv[])
return -EINVAL;
}
+ if (argc == 3) {
+ uint64_t mult;
+ int ret;
+
+ if (!strcmp(argv[1], "msdos")) {
+ printf("gpt-location not supported for msdos partitions\n");
+ return -EINVAL;
+ }
+
+ ret = parted_strtoull(argv[2], &gpt_location, &mult);
+ if (ret)
+ return ret;
+
+ if (!mult)
+ mult = gunit;
+
+ gpt_location *= mult;
+
+ /* Ensure alignment */
+ gpt_location = ALIGN(gpt_location, SECTOR_SIZE);
+ /* convert to LBA */
+ gpt_location >>= SECTOR_SHIFT;
+ }
+
pdesc = partition_table_new(blk, argv[1], gpt_location);
if (IS_ERR(pdesc)) {
printf("Error: Cannot create partition table: %pe\n", pdesc);
@@ -236,7 +260,7 @@ static int do_mklabel(struct block_device *blk, int argc, char *argv[])
partition_table_free(gpdesc);
gpdesc = pdesc;
- return 2;
+ return argc > 2 ? 3 : 2;
}
static int do_refresh(struct block_device *blk, int argc, char *argv[])
@@ -352,7 +376,7 @@ BAREBOX_CMD_HELP_TEXT("GNU Parted")
BAREBOX_CMD_HELP_TEXT("")
BAREBOX_CMD_HELP_TEXT("commands:")
BAREBOX_CMD_HELP_OPT ("print", "print partitions")
-BAREBOX_CMD_HELP_OPT ("mklabel <type>", "create a new partition table")
+BAREBOX_CMD_HELP_OPT ("mklabel <type> <gpt-location>", "create a new partition table")
BAREBOX_CMD_HELP_OPT ("rm <num>", "remove a partition")
BAREBOX_CMD_HELP_OPT ("mkpart <name> <fstype> <start> <end>", "create a new partition")
BAREBOX_CMD_HELP_OPT ("unit <unit>", "change display/input units")
@@ -361,6 +385,7 @@ BAREBOX_CMD_HELP_TEXT("")
BAREBOX_CMD_HELP_TEXT("<unit> can be one of \"s\" (sectors), \"B\" (bytes), \"kB\", \"MB\", \"GB\", \"TB\",")
BAREBOX_CMD_HELP_TEXT("\"KiB\", \"MiB\", \"GiB\" or \"TiB\"")
BAREBOX_CMD_HELP_TEXT("<type> must be \"gpt\" or \"msdos\"")
+BAREBOX_CMD_HELP_TEXT("<gpt-location> Location of the GPT table, ignored for MBR. Specified in <unit> size.")
BAREBOX_CMD_HELP_TEXT("<fstype> can be one of \"ext2\", \"ext3\", \"ext4\", \"fat16\", \"fat32\" or \"bbenv\"")
BAREBOX_CMD_HELP_TEXT("<name> for MBR partition tables can be one of \"primary\", \"extended\" or")
BAREBOX_CMD_HELP_TEXT("\"logical\". For GPT this is a name string.")
--
2.39.5
next prev parent reply other threads:[~2025-04-23 17:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-23 14:09 [PATCH v2 1/4] partitions: efi: add support to specify gpt-location Marco Felsch
2025-04-23 14:09 ` Marco Felsch [this message]
2025-04-23 14:09 ` [PATCH v2 3/4] defaultenv-2: add support to automatically create an initial GPT table Marco Felsch
2025-04-23 14:09 ` [PATCH v2 4/4] ARM: riotboard: drop static barebox-environment handling Marco Felsch
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250423140913.1530237-2-m.felsch@pengutronix.de \
--to=m.felsch@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox