All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Marco Felsch <m.felsch@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH v2 3/4] defaultenv-2: add support to automatically create an initial GPT table
Date: Thu, 24 Apr 2025 13:51:30 +0200	[thread overview]
Message-ID: <aAolwl3W4ReziQJ2@pengutronix.de> (raw)
In-Reply-To: <20250423140913.1530237-3-m.felsch@pengutronix.de>

On Wed, Apr 23, 2025 at 04:09:12PM +0200, Marco Felsch wrote:
> 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.

Can we have a command for this rather than a script?

We might want to extend this functionality and it looks like the shell
gets to its limits quite fast here.

Sascha

> 
> 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
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



  reply	other threads:[~2025-04-24 16:04 UTC|newest]

Thread overview: 12+ 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-24 12:00   ` Sascha Hauer
2025-04-24 20:34     ` Marco Felsch
2025-04-23 14:09 ` [PATCH v2 3/4] defaultenv-2: add support to automatically create an initial GPT table Marco Felsch
2025-04-24 11:51   ` Sascha Hauer [this message]
2025-04-23 14:09 ` [PATCH v2 4/4] ARM: riotboard: drop static barebox-environment handling Marco Felsch
2025-04-24  8:02   ` Ahmad Fatoum
2025-04-24  8:45     ` Marco Felsch
2025-04-24 17:49     ` Alexander Shiyan
2025-10-27 15:33       ` Ahmad Fatoum
2025-04-24 12:08 ` [PATCH v2 1/4] partitions: efi: add support to specify gpt-location Sascha Hauer

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=aAolwl3W4ReziQJ2@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=m.felsch@pengutronix.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.