mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH v2 01/19] common: partitions: decouple from EFI GUID definition
Date: Wed,  7 Jun 2023 14:06:56 +0200	[thread overview]
Message-ID: <20230607120714.3083182-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20230607120714.3083182-1-a.fatoum@pengutronix.de>

We have three UUID/GUID definitions in barebox:

 - efi_guid_t: for EFI GUIDs
 - uuid_t:     for RFC 4122/DCE 1.1 (Variant 1) UUIDs
 - guid_t:     Apparently UUIDs stored in little-endian

In preparation for switching efi_guid_t to be a special case of guid_t
like in Linux, let's replace non-EFI uses of efi_guid_t with guid_t.

This allows us to drop the efi.h header outside of EFI code.
This also involves two replacements of efi_char16_t with wchar_t.
This is ok, as we always build with -fshort-wchar.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
  - no change
---
 common/partitions/efi.c    |  4 ++--
 common/partitions/parser.h |  1 +
 include/efi/partition.h    | 27 ++++++++++++++-------------
 lib/Makefile               |  1 +
 lib/uuid.c                 | 15 +++++++++++++++
 5 files changed, 33 insertions(+), 15 deletions(-)
 create mode 100644 lib/uuid.c

diff --git a/common/partitions/efi.c b/common/partitions/efi.c
index 0411a8b2480a..60c981666fc8 100644
--- a/common/partitions/efi.c
+++ b/common/partitions/efi.c
@@ -232,7 +232,7 @@ static int is_gpt_valid(struct block_device *blk, u64 lba,
 static inline int
 is_pte_valid(const gpt_entry *pte, const u64 lastlba)
 {
-	if ((!efi_guidcmp(pte->partition_type_guid, EFI_NULL_GUID)) ||
+	if (guid_is_null(&pte->partition_type_guid) ||
 	    le64_to_cpu(pte->starting_lba) > lastlba	 ||
 	    le64_to_cpu(pte->ending_lba)   > lastlba)
 		return 0;
@@ -287,7 +287,7 @@ compare_gpts(struct device *dev, gpt_header *pgpt, gpt_header *agpt,
 		       (unsigned long long)le64_to_cpu(agpt->last_usable_lba));
 		error_found++;
 	}
-	if (efi_guidcmp(pgpt->disk_guid, agpt->disk_guid)) {
+	if (!guid_equal(&pgpt->disk_guid, &agpt->disk_guid)) {
 		dev_warn(dev, "GPT:disk_guids don't match.\n");
 		error_found++;
 	}
diff --git a/common/partitions/parser.h b/common/partitions/parser.h
index d67f8e1d6a09..f2f692f7903b 100644
--- a/common/partitions/parser.h
+++ b/common/partitions/parser.h
@@ -9,6 +9,7 @@
 
 #include <block.h>
 #include <filetype.h>
+#include <linux/uuid.h>
 #include <linux/list.h>
 
 #define MAX_PARTITION		128
diff --git a/include/efi/partition.h b/include/efi/partition.h
index a9b10c126654..0ca2a72eb9b7 100644
--- a/include/efi/partition.h
+++ b/include/efi/partition.h
@@ -21,7 +21,8 @@
 #ifndef FS_PART_EFI_H_INCLUDED
 #define FS_PART_EFI_H_INCLUDED
 
-#include <efi.h>
+#include <linux/types.h>
+#include <linux/uuid.h>
 
 #define MSDOS_MBR_SIGNATURE 0xaa55
 #define EFI_PMBR_OSTYPE_EFI 0xEF
@@ -33,25 +34,25 @@
 #define GPT_PRIMARY_PARTITION_TABLE_LBA 1
 
 #define PARTITION_SYSTEM_GUID \
-	EFI_GUID( 0xC12A7328, 0xF81F, 0x11d2, \
+	GUID_INIT( 0xC12A7328, 0xF81F, 0x11d2, \
 		0xBA, 0x4B, 0x00, 0xA0, 0xC9, 0x3E, 0xC9, 0x3B)
 #define LEGACY_MBR_PARTITION_GUID \
-	EFI_GUID( 0x024DEE41, 0x33E7, 0x11d3, \
+	GUID_INIT( 0x024DEE41, 0x33E7, 0x11d3, \
 		0x9D, 0x69, 0x00, 0x08, 0xC7, 0x81, 0xF3, 0x9F)
 #define PARTITION_MSFT_RESERVED_GUID \
-	EFI_GUID( 0xE3C9E316, 0x0B5C, 0x4DB8, \
+	GUID_INIT( 0xE3C9E316, 0x0B5C, 0x4DB8, \
 		0x81, 0x7D, 0xF9, 0x2D, 0xF0, 0x02, 0x15, 0xAE)
 #define PARTITION_BASIC_DATA_GUID \
-	EFI_GUID( 0xEBD0A0A2, 0xB9E5, 0x4433, \
+	GUID_INIT( 0xEBD0A0A2, 0xB9E5, 0x4433, \
 		0x87, 0xC0, 0x68, 0xB6, 0xB7, 0x26, 0x99, 0xC7)
 #define PARTITION_LINUX_RAID_GUID \
-	EFI_GUID( 0xa19d880f, 0x05fc, 0x4d3b, \
+	GUID_INIT( 0xa19d880f, 0x05fc, 0x4d3b, \
 		0xa0, 0x06, 0x74, 0x3f, 0x0f, 0x84, 0x91, 0x1e)
 #define PARTITION_LINUX_SWAP_GUID \
-	EFI_GUID( 0x0657fd6d, 0xa4ab, 0x43c4, \
+	GUID_INIT( 0x0657fd6d, 0xa4ab, 0x43c4, \
 		0x84, 0xe5, 0x09, 0x33, 0xc8, 0x4b, 0x4f, 0x4f)
 #define PARTITION_LINUX_LVM_GUID \
-	EFI_GUID( 0xe6d6d379, 0xf507, 0x44c2, \
+	GUID_INIT( 0xe6d6d379, 0xf507, 0x44c2, \
 		0xa2, 0x3c, 0x23, 0x8f, 0x2a, 0x3d, 0xf9, 0x28)
 
 /* based on linux/include/genhd.h */
@@ -79,7 +80,7 @@ typedef struct _gpt_header {
 	__le64 alternate_lba;
 	__le64 first_usable_lba;
 	__le64 last_usable_lba;
-	efi_guid_t disk_guid;
+	guid_t disk_guid;
 	__le64 partition_entry_lba;
 	__le32 num_partition_entries;
 	__le32 sizeof_partition_entry;
@@ -98,14 +99,14 @@ typedef struct _gpt_entry_attributes {
         u64 type_guid_specific:16;
 } __attribute__ ((packed)) gpt_entry_attributes;
 
-#define GPT_PARTNAME_MAX_SIZE	(72 / sizeof (efi_char16_t))
+#define GPT_PARTNAME_MAX_SIZE	(72 / sizeof (wchar_t))
 typedef struct _gpt_entry {
-	efi_guid_t partition_type_guid;
-	efi_guid_t unique_partition_guid;
+	guid_t partition_type_guid;
+	guid_t unique_partition_guid;
 	__le64 starting_lba;
 	__le64 ending_lba;
 	gpt_entry_attributes attributes;
-	efi_char16_t partition_name[GPT_PARTNAME_MAX_SIZE];
+	wchar_t partition_name[GPT_PARTNAME_MAX_SIZE];
 } __attribute__ ((packed)) gpt_entry;
 
 typedef struct _legacy_mbr {
diff --git a/lib/Makefile b/lib/Makefile
index 185e6221fdd2..921e5eedf46e 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -28,6 +28,7 @@ obj-y			+= recursive_action.o
 obj-y			+= make_directory.o
 obj-y			+= math.o
 obj-y			+= math/
+obj-y			+= uuid.o
 obj-$(CONFIG_XXHASH)	+= xxhash.o
 obj-$(CONFIG_BZLIB)	+= decompress_bunzip2.o
 obj-$(CONFIG_ZLIB)	+= decompress_inflate.o zlib_inflate/
diff --git a/lib/uuid.c b/lib/uuid.c
new file mode 100644
index 000000000000..db6464e354b1
--- /dev/null
+++ b/lib/uuid.c
@@ -0,0 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Unified UUID/GUID definition
+ *
+ * Copyright (C) 2009, 2016 Intel Corp.
+ *	Huang Ying <ying.huang@intel.com>
+ */
+
+#include <linux/uuid.h>
+#include <linux/export.h>
+
+const guid_t guid_null;
+EXPORT_SYMBOL(guid_null);
+const uuid_t uuid_null;
+EXPORT_SYMBOL(uuid_null);
-- 
2.39.2




  reply	other threads:[~2023-06-07 12:08 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-07 12:06 [PATCH v2 00/19] state: allow lookup of barebox state partition by Type GUID Ahmad Fatoum
2023-06-07 12:06 ` Ahmad Fatoum [this message]
2023-06-07 12:06 ` [PATCH v2 02/19] efi: define efi_guid_t as 32-bit aligned guid_t Ahmad Fatoum
2023-06-07 12:06 ` [PATCH v2 03/19] cdev: fix for_each_cdev macro Ahmad Fatoum
2023-06-07 12:06 ` [PATCH v2 04/19] of: partition: support of_partition_ensure_probed on parent device Ahmad Fatoum
2023-06-07 12:07 ` [PATCH v2 05/19] state: fix deep probe handling Ahmad Fatoum
2023-06-07 12:07 ` [PATCH v2 06/19] of: of_path: always call of_partition_ensure_probed before resolving Ahmad Fatoum
2023-06-07 12:07 ` [PATCH v2 07/19] driver: add new cdev_is_partition helper Ahmad Fatoum
2023-06-07 12:07 ` [PATCH v2 08/19] commands: stat: remove code duplication for type info Ahmad Fatoum
2023-06-07 12:07 ` [PATCH v2 09/19] cdev: use more descriptive struct cdev::diskuuid/partuuid Ahmad Fatoum
2023-06-07 12:07 ` [PATCH v2 10/19] cdev: record whether partition is parsed from OF Ahmad Fatoum
2023-06-07 12:07 ` [PATCH v2 11/19] cdev: have devfs_add_partition return existing identical partition, not NULL Ahmad Fatoum
2023-06-07 12:07 ` [PATCH v2 12/19] block: parse partition table on block device registration Ahmad Fatoum
2023-06-07 12:07 ` [PATCH v2 13/19] common: partitions: record whether disk is GPT or MBR partitioned Ahmad Fatoum
2023-06-07 12:07 ` [PATCH v2 14/19] block: add cdev_is_block_(device|partition|disk) helpers Ahmad Fatoum
2023-06-07 12:07 ` [PATCH v2 15/19] of: export new of_cdev_find helper Ahmad Fatoum
2023-06-07 12:07 ` [PATCH v2 16/19] state: factor device path lookup into helper function Ahmad Fatoum
2023-06-07 12:07 ` [PATCH v2 17/19] cdev: use cdev::dos_partition_type only if cdev_is_mbr_partitioned Ahmad Fatoum
2023-06-07 12:07 ` [PATCH v2 18/19] common: partitions: efi: record type UUID in cdev Ahmad Fatoum
2023-06-07 12:07 ` [PATCH v2 19/19] state: allow lookup of barebox state partition by Type GUID Ahmad Fatoum
2023-06-08  6:53 ` [PATCH v2 00/19] " 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=20230607120714.3083182-2-a.fatoum@pengutronix.de \
    --to=a.fatoum@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