public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Joshua Watt <jpewhacker@gmail.com>
To: u-boot@lists.denx.de
Cc: Joshua Watt <JPEWhacker@gmail.com>,
	Simon Glass <sjg@chromium.org>,
	Enric Balletbo i Serra <eballetb@redhat.com>
Subject: [PATCH v2 4/8] cmd: gpt: Add gpt_partition_bootable variable
Date: Wed, 23 Aug 2023 10:47:40 -0600	[thread overview]
Message-ID: <20230823164755.2874792-5-JPEWhacker@gmail.com> (raw)
In-Reply-To: <20230823164755.2874792-1-JPEWhacker@gmail.com>

Adds an additional variable called gpt_partition_bootable that indicates
if the given partition is bootable or not.

Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
---
 cmd/gpt.c                 |  9 +++++++--
 doc/usage/cmd/gpt.rst     |  3 +++
 test/py/tests/test_gpt.py | 33 +++++++++++++++++++++++++++++++++
 3 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/cmd/gpt.c b/cmd/gpt.c
index e6f7b0319a..7a8990e400 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -723,7 +723,7 @@ static int gpt_enumerate(struct blk_desc *desc)
  * gpt_setenv_part_variables() - setup partition environmental variables
  *
  * Setup the gpt_partition_name, gpt_partition_entry, gpt_partition_addr
- * and gpt_partition_size environment variables.
+ * and gpt_partition_size, gpt_partition_bootable environment variables.
  *
  * @pinfo: pointer to disk partition
  * @i: partition entry
@@ -750,6 +750,10 @@ static int gpt_setenv_part_variables(struct disk_partition *pinfo, int i)
 	if (ret)
 		goto fail;
 
+	ret = env_set_ulong("gpt_partition_bootable", !!(pinfo->bootable & PART_BOOTABLE));
+	if (ret)
+		goto fail;
+
 	return 0;
 
 fail:
@@ -1057,7 +1061,8 @@ U_BOOT_CMD(gpt, CONFIG_SYS_MAXARGS, 1, do_gpt,
 	" gpt setenv mmc 0 $name\n"
 	"    - setup environment variables for partition $name:\n"
 	"      gpt_partition_addr, gpt_partition_size,\n"
-	"      gpt_partition_name, gpt_partition_entry\n"
+	"      gpt_partition_name, gpt_partition_entry,\n"
+	"      gpt_partition_bootable\n"
 	" gpt enumerate mmc 0\n"
 	"    - store list of partitions to gpt_partition_list environment variable\n"
 	" gpt guid <interface> <dev>\n"
diff --git a/doc/usage/cmd/gpt.rst b/doc/usage/cmd/gpt.rst
index ea2cf73a60..c9d15b2cba 100644
--- a/doc/usage/cmd/gpt.rst
+++ b/doc/usage/cmd/gpt.rst
@@ -85,6 +85,7 @@ information about a particular partition. The variables are:
 * gpt_partition_size (the size of the partition, in hexadecimal blocks)
 * gpt_partition_name (the name of the partition)
 * gpt_partition_entry (the partition number in the table, e.g. 1, 2, 3, etc.)
+* gpt_partition_bootable (1 if the partition is marked as bootable, 0 if not)
 
 To get the information about the partition named 'rootfs', issue the following
 command:
@@ -99,6 +100,8 @@ command:
     rootfs
     => echo ${gpt_partition_entry}
     2
+    => echo ${gpt_partition_bootable}
+    0
 
 The 'gpt enumerate' command will set the variable 'gpt_partition_list' with the
 list of partition names on the device. For example:
diff --git a/test/py/tests/test_gpt.py b/test/py/tests/test_gpt.py
index 339468bc12..1537ceb8c8 100644
--- a/test/py/tests/test_gpt.py
+++ b/test/py/tests/test_gpt.py
@@ -49,6 +49,7 @@ class GptTestDiskImage(object):
                 u_boot_utils.run_and_log(u_boot_console, cmd)
                 # part1 offset 1MB size 1MB
                 cmd = ('sgdisk', '--new=1:2048:4095', '--change-name=1:part1',
+                    '-A 1:set:2',
                     persistent)
                 # part2 offset 2MB size 1.5MB
                 u_boot_utils.run_and_log(u_boot_console, cmd)
@@ -117,6 +118,38 @@ def test_gpt_guid(state_disk_image, u_boot_console):
     output = u_boot_console.run_command('gpt guid host 0')
     assert '375a56f7-d6c9-4e81-b5f0-09d41ca89efe' in output
 
+@pytest.mark.boardspec('sandbox')
+@pytest.mark.buildconfigspec('cmd_gpt')
+@pytest.mark.requiredtool('sgdisk')
+def test_gpt_setenv(state_disk_image, u_boot_console):
+    """Test the gpt setenv command."""
+    u_boot_console.run_command('host bind 0 ' + state_disk_image.path)
+    output = u_boot_console.run_command('gpt setenv host 0 part1')
+    assert 'success!' in output
+    output = u_boot_console.run_command('echo ${gpt_partition_addr}')
+    assert output.rstrip() == '800'
+    output = u_boot_console.run_command('echo ${gpt_partition_size}')
+    assert output.rstrip() == '800'
+    output = u_boot_console.run_command('echo ${gpt_partition_name}')
+    assert output.rstrip() == 'part1'
+    output = u_boot_console.run_command('echo ${gpt_partition_entry}')
+    assert output.rstrip() == "1"
+    output = u_boot_console.run_command('echo ${gpt_partition_bootable}')
+    assert output.rstrip() == "1"
+
+    output = u_boot_console.run_command('gpt setenv host 0 part2')
+    assert 'success!' in output
+    output = u_boot_console.run_command('echo ${gpt_partition_addr}')
+    assert output.rstrip() == '1000'
+    output = u_boot_console.run_command('echo ${gpt_partition_size}')
+    assert output.rstrip() == 'c00'
+    output = u_boot_console.run_command('echo ${gpt_partition_name}')
+    assert output.rstrip() == 'part2'
+    output = u_boot_console.run_command('echo ${gpt_partition_entry}')
+    assert output.rstrip() == "2"
+    output = u_boot_console.run_command('echo ${gpt_partition_bootable}')
+    assert output.rstrip() == "0"
+
 @pytest.mark.boardspec('sandbox')
 @pytest.mark.buildconfigspec('cmd_gpt')
 @pytest.mark.requiredtool('sgdisk')
-- 
2.33.0


  parent reply	other threads:[~2023-08-23 16:48 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-15 16:26 [PATCH 0/6] cmd: gpt: GPT manipulation improvements Joshua Watt
2023-08-15 16:26 ` [PATCH 1/6] cmd: gpt: Remove confusing help text Joshua Watt
2023-08-18 14:23   ` Tom Rini
2023-08-23 23:57   ` Simon Glass
2023-08-15 16:26 ` [PATCH 2/6] cmd: gpt: Add command to set bootable flags Joshua Watt
2023-08-15 18:39   ` Simon Glass
2023-08-15 16:26 ` [PATCH 3/6] cmd: gpt: Add gpt_partition_bootable variable Joshua Watt
2023-08-15 16:26 ` [PATCH 4/6] cmd: gpt: Preserve type GUID if enabled Joshua Watt
2023-08-15 16:26 ` [PATCH 5/6] cmd: gpt: Preserve bootable flag Joshua Watt
2023-08-15 16:27 ` [PATCH 6/6] cmd: gpt: Add command to swap partition order Joshua Watt
2023-08-23 23:57   ` Simon Glass
2023-08-23 16:47 ` [PATCH v2 0/8] cmd: gpt: GPT manipulation improvements Joshua Watt
2023-08-23 16:47   ` [PATCH v2 1/8] cmd: gpt: Remove confusing help text Joshua Watt
2023-08-23 18:15     ` Tom Rini
2023-08-23 16:47   ` [PATCH v2 2/8] doc: Add gpt command documentation Joshua Watt
2023-08-23 18:15     ` Tom Rini
2023-08-23 23:57     ` Simon Glass
2023-08-23 16:47   ` [PATCH v2 3/8] tests: gpt: Remove test order dependency Joshua Watt
2023-08-23 23:57     ` Simon Glass
2023-08-24  3:29       ` Joshua Watt
2023-08-23 16:47   ` Joshua Watt [this message]
2023-08-23 23:57     ` [PATCH v2 4/8] cmd: gpt: Add gpt_partition_bootable variable Simon Glass
2023-08-23 16:47   ` [PATCH v2 5/8] cmd: gpt: Add command to set bootable flags Joshua Watt
2023-08-23 23:57     ` Simon Glass
2023-08-23 16:47   ` [PATCH v2 6/8] cmd: gpt: Preserve type GUID if enabled Joshua Watt
2023-08-23 23:57     ` Simon Glass
2023-08-23 16:47   ` [PATCH v2 7/8] cmd: gpt: Preserve bootable flag Joshua Watt
2023-08-23 23:57     ` Simon Glass
2023-08-23 16:47   ` [PATCH v2 8/8] cmd: gpt: Add command to swap partition order Joshua Watt
2023-08-25 19:38   ` [PATCH v3 0/8] cmd: gpt: GPT manipulation improvements Joshua Watt
2023-08-25 19:38     ` [PATCH v3 1/8] cmd: gpt: Remove confusing help text Joshua Watt
2023-08-25 19:38     ` [PATCH v3 2/8] doc: Add gpt command documentation Joshua Watt
2023-08-25 23:53       ` Simon Glass
2023-08-28 21:52         ` Joshua Watt
2023-08-26  1:57       ` Heinrich Schuchardt
2023-08-28 19:29         ` Joshua Watt
2023-08-28 20:01           ` Heinrich Schuchardt
2023-08-28 21:01             ` Joshua Watt
2023-08-25 19:38     ` [PATCH v3 3/8] tests: gpt: Remove test order dependency Joshua Watt
2023-08-25 19:38     ` [PATCH v3 4/8] cmd: gpt: Add gpt_partition_bootable variable Joshua Watt
2023-08-25 23:53       ` Simon Glass
2023-08-25 19:38     ` [PATCH v3 5/8] cmd: gpt: Add command to set bootable flags Joshua Watt
2023-08-25 19:38     ` [PATCH v3 6/8] cmd: gpt: Preserve type GUID if enabled Joshua Watt
2023-08-25 23:53       ` Simon Glass
2023-08-26  0:37       ` Heinrich Schuchardt
2023-08-25 19:38     ` [PATCH v3 7/8] cmd: gpt: Preserve bootable flag Joshua Watt
2023-08-25 19:38     ` [PATCH v3 8/8] cmd: gpt: Add command to swap partition order Joshua Watt
2023-08-25 23:53       ` Simon Glass
2023-08-26  1:00       ` Heinrich Schuchardt
2023-08-28 21:56     ` [PATCH v4 0/8] cmd: gpt: GPT manipulation improvements Joshua Watt
2023-08-28 21:56       ` [PATCH v4 1/8] cmd: gpt: Remove confusing help text Joshua Watt
2023-08-28 22:05         ` Heinrich Schuchardt
2023-08-28 21:56       ` [PATCH v4 2/8] doc: Add gpt command documentation Joshua Watt
2023-08-28 22:45         ` Heinrich Schuchardt
2023-08-28 22:59           ` Heinrich Schuchardt
2023-08-29 13:22             ` Joshua Watt
2023-08-28 21:56       ` [PATCH v4 3/8] tests: gpt: Remove test order dependency Joshua Watt
2023-08-28 21:56       ` [PATCH v4 4/8] cmd: gpt: Add gpt_partition_bootable variable Joshua Watt
2023-08-28 21:56       ` [PATCH v4 5/8] cmd: gpt: Add command to set bootable flags Joshua Watt
2023-08-28 22:54         ` Heinrich Schuchardt
2023-08-29 13:24           ` Joshua Watt
2023-08-28 21:56       ` [PATCH v4 6/8] cmd: gpt: Preserve type GUID if enabled Joshua Watt
2023-08-28 21:56       ` [PATCH v4 7/8] cmd: gpt: Preserve bootable flag Joshua Watt
2023-08-28 21:56       ` [PATCH v4 8/8] cmd: gpt: Add command to swap partition order Joshua Watt
2023-08-31 16:51       ` [PATCH v5 0/8] cmd: gpt: GPT manipulation improvements Joshua Watt
2023-08-31 16:51         ` [PATCH v5 1/8] cmd: gpt: Remove confusing help text Joshua Watt
2023-08-31 16:51         ` [PATCH v5 2/8] doc: Add gpt command documentation Joshua Watt
2023-08-31 16:51         ` [PATCH v5 3/8] tests: gpt: Remove test order dependency Joshua Watt
2023-09-12 15:17           ` Tom Rini
2023-08-31 16:51         ` [PATCH v5 4/8] cmd: gpt: Add gpt_partition_bootable variable Joshua Watt
2023-08-31 16:51         ` [PATCH v5 5/8] cmd: gpt: Add command to set bootable flags Joshua Watt
2023-08-31 16:51         ` [PATCH v5 6/8] cmd: gpt: Preserve type GUID if enabled Joshua Watt
2023-08-31 16:51         ` [PATCH v5 7/8] cmd: gpt: Preserve bootable flag Joshua Watt
2023-08-31 16:51         ` [PATCH v5 8/8] cmd: gpt: Add command to swap partition order Joshua Watt

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=20230823164755.2874792-5-JPEWhacker@gmail.com \
    --to=jpewhacker@gmail.com \
    --cc=eballetb@redhat.com \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox