From: Marco Felsch <m.felsch@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH v2 3/4] defaultenv-2: add support to automatically create an initial GPT table
Date: Wed, 23 Apr 2025 16:09:12 +0200 [thread overview]
Message-ID: <20250423140913.1530237-3-m.felsch@pengutronix.de> (raw)
In-Reply-To: <20250423140913.1530237-1-m.felsch@pengutronix.de>
This adds the support to automatically create a minimal GPT table.
gpt-add: A script to add a minimal GPT table compatible to i.MX3/5/6/7
devices. The initial GPT only contains a barebox-environment partition.
The script checks for the bootsource to decide the GPT location.
gpt-rm: A script to remove the GPT header and the protective MBR. The
script checks for the bootsource to decide which GPT should be scrubbed.
bbenv-gpt: An initscript which checks for a barebox-environment
partition if booted from MMC. If no parition was found the script
triggers the gpt-add script.
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
v2:
- new
defaultenv/defaultenv-2-base/bin/gpt-add | 40 +++++++++++++++++++++
defaultenv/defaultenv-2-base/bin/gpt-rm | 10 ++++++
defaultenv/defaultenv-2-base/init/bbenv-gpt | 16 +++++++++
3 files changed, 66 insertions(+)
create mode 100644 defaultenv/defaultenv-2-base/bin/gpt-add
create mode 100644 defaultenv/defaultenv-2-base/bin/gpt-rm
create mode 100644 defaultenv/defaultenv-2-base/init/bbenv-gpt
diff --git a/defaultenv/defaultenv-2-base/bin/gpt-add b/defaultenv/defaultenv-2-base/bin/gpt-add
new file mode 100644
index 000000000000..fa61b1929e20
--- /dev/null
+++ b/defaultenv/defaultenv-2-base/bin/gpt-add
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+bootdev="/dev/${bootsource}${bootsource_instance}"
+yesno=""
+
+if [ ${bootsource} != "mmc" ]; then
+ exit 0
+fi
+
+# If successful, there is already a GPT or MBR header
+# TODO: Add hush redirect support to avoid user confusion
+if parted ${bootdev} print; then
+ exit 0
+fi
+
+readline "Create an initial GPT for barebox? [y|N]: " yesno
+
+# No per default
+if [ "${yesno}" == "" ]; then
+ exit 0
+elif [ "${yesno}" == "n" ]; then
+ exit 0
+fi
+
+# Check for other user input than 'y'
+if [ "${yesno}" != "y" ]; then
+ echo "Unkown value, only 'y' and 'n' are supported"
+ exit 1
+fi
+
+# Make a default GPT table, with the GPT partition entrie array starting at 2MiB
+# to have enough space for barebox at the beginning and to overcome legacy
+# platforms like i.MX3/5/6.
+parted ${bootdev} mklabel gpt 2MiB || gpt-rm
+
+# Add a barebox environment partition with the size of 1MiB which should be
+# enough for development.
+parted ${bootdev} mkpart barebox-environment bbenv 3MiB 4MiB || gpt-rm
+
+parted ${bootdev} refresh
diff --git a/defaultenv/defaultenv-2-base/bin/gpt-rm b/defaultenv/defaultenv-2-base/bin/gpt-rm
new file mode 100644
index 000000000000..e45c79395504
--- /dev/null
+++ b/defaultenv/defaultenv-2-base/bin/gpt-rm
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+bootdev="/dev/${bootsource}${bootsource_instance}"
+
+if [ ${bootsource} != "mmc" ]; then
+ exit 0
+fi
+
+# Remove protective MBR and GPT from boot device
+memset -d ${bootdev} 0x100 0x0 0x300
diff --git a/defaultenv/defaultenv-2-base/init/bbenv-gpt b/defaultenv/defaultenv-2-base/init/bbenv-gpt
new file mode 100644
index 000000000000..6756cac9885e
--- /dev/null
+++ b/defaultenv/defaultenv-2-base/init/bbenv-gpt
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+bbenvpart="/dev/${bootsource}${bootsource_instance}.barebox-environment"
+
+if [ ${bootsource} != "mmc" ]; then
+ exit 0
+fi
+
+# TODO:
+# Add command support to search for a given GPT PartUUID on a block device to
+# be partition name independent.
+if [ -e ${bbenvpart} ]; then
+ exit 0
+fi
+
+gpt-add
--
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 ` [PATCH v2 2/4] parted: add support for gpt-location Marco Felsch
2025-04-23 14:09 ` Marco Felsch [this message]
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-3-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