Currently gpt_fill_pte() always zeroes the GPT partition entry's
64-bit attributes field, and only ever sets the legacy BIOS bootable
bit.

Add a new CONFIG_PARTITION_ATTR option that, when enabled, adds new
fields to struct disk_partition along with their accessors to support
writing full 64-bit attributes.

Signed-off-by: Sumit Singh Dhami <[email protected]>
---
 disk/Kconfig    |  8 ++++++++
 disk/part_efi.c |  9 +++++++--
 include/part.h  | 30 ++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/disk/Kconfig b/disk/Kconfig
index 672ad46a48f..2a0b6811a3e 100644
--- a/disk/Kconfig
+++ b/disk/Kconfig
@@ -176,4 +176,12 @@ config SPL_PARTITION_TYPE_GUID
          Activate the configuration of GUID type
          for EFI partition
 
+config PARTITION_ATTR
+       bool "Enable support of full GPT partition attributes"
+       depends on EFI_PARTITION
+       help
+         Activate storing and writing the full 64-bit GPT partition
+         attributes field via the 'attrs=' key in the 'gpt write'
+         partitions list, in addition to the legacy bootable bit.
+
 endmenu
diff --git a/disk/part_efi.c b/disk/part_efi.c
index 99f5df1c37d..89cc36d9f0d 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -528,8 +528,13 @@ int gpt_fill_pte(struct blk_desc *desc,
                }
 
                /* partition attributes */
-               memset(&gpt_e[i].attributes, 0,
-                      sizeof(gpt_entry_attributes));
+               if (CONFIG_IS_ENABLED(PARTITION_ATTR) &&
+                   disk_partition_gpt_attr_valid(&partitions[i]))
+                       gpt_e[i].attributes.raw =
+                               disk_partition_gpt_attr(&partitions[i]);
+               else
+                       memset(&gpt_e[i].attributes, 0,
+                              sizeof(gpt_entry_attributes));
 
                if (partitions[i].bootable & PART_BOOTABLE)
                        gpt_e[i].attributes.fields.legacy_bios_bootable = 1;
diff --git a/include/part.h b/include/part.h
index 5d6bc641b5c..e2ff43e92c4 100644
--- a/include/part.h
+++ b/include/part.h
@@ -73,6 +73,10 @@ struct disk_partition {
         */
        int     bootable;
        u16     type_flags;     /* top 16 bits of GPT partition attributes      
*/
+#if CONFIG_IS_ENABLED(PARTITION_ATTR)
+       u64 gpt_attr;           /* raw 64-bit GPT partition attributes, if 
attrs= was given */
+       bool gpt_attr_valid;    /* true if attrs= was present in the partitions 
list */
+#endif
 #if CONFIG_IS_ENABLED(PARTITION_UUIDS)
        char    uuid[UUID_STR_LEN + 1]; /* filesystem UUID as string, if exists 
*/
 #endif
@@ -111,6 +115,32 @@ static inline void disk_partition_clr_uuid(struct 
disk_partition *info)
 #endif
 }
 
+static inline u64 disk_partition_gpt_attr(const struct disk_partition *info)
+{
+#if CONFIG_IS_ENABLED(PARTITION_ATTR)
+       return info->gpt_attr;
+#else
+       return 0;
+#endif
+}
+
+static inline bool disk_partition_gpt_attr_valid(const struct disk_partition 
*info)
+{
+#if CONFIG_IS_ENABLED(PARTITION_ATTR)
+       return info->gpt_attr_valid;
+#else
+       return false;
+#endif
+}
+
+static inline void disk_partition_set_gpt_attr(struct disk_partition *info, 
u64 val)
+{
+#if CONFIG_IS_ENABLED(PARTITION_ATTR)
+       info->gpt_attr = val;
+       info->gpt_attr_valid = true;
+#endif
+}
+
 /* Accessors for struct disk_partition field ->type_guid */
 extern char *__invalid_use_of_disk_partition_type_guid;
 
-- 
2.55.0

Reply via email to