From: Simon Glass <sjg@chromium.org>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: Simon Glass <sjg@chromium.org>, Bin Meng <bmeng.cn@gmail.com>,
Heinrich Schuchardt <xypron.glpk@gmx.de>,
Ilias Apalodimas <ilias.apalodimas@linaro.org>,
Joshua Watt <jpewhacker@gmail.com>,
Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>,
Tobias Waldekranz <tobias@waldekranz.com>
Subject: [PATCH 08/24] part: Add accessors for struct disk_partition uuid
Date: Sun, 13 Aug 2023 08:26:36 -0600 [thread overview]
Message-ID: <20230813142708.361456-9-sjg@chromium.org> (raw)
In-Reply-To: <20230813142708.361456-1-sjg@chromium.org>
This field is only present when a CONFIG is set. To avoid annoying #ifdefs
in the source code, add accessors. Update all code to use it.
Note that the accessor is optional. It can be omitted if it is known that
the option is enabled.
Signed-off-by: Simon Glass <sjg@chromium.org>
---
cmd/gpt.c | 10 ++++------
disk/part.c | 8 ++------
disk/part_dos.c | 17 ++++++++---------
disk/part_efi.c | 31 ++++++++++++++++---------------
fs/fat/fat.c | 4 +---
include/part.h | 27 +++++++++++++++++++++++++++
6 files changed, 58 insertions(+), 39 deletions(-)
diff --git a/cmd/gpt.c b/cmd/gpt.c
index 007a68eaa72a..8969efba8c80 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -211,12 +211,10 @@ static struct disk_part *allocate_disk_part(struct disk_partition *info,
PART_TYPE_LEN);
newpart->gpt_part_info.type[PART_TYPE_LEN - 1] = '\0';
newpart->gpt_part_info.bootable = info->bootable;
-#ifdef CONFIG_PARTITION_UUIDS
- strncpy(newpart->gpt_part_info.uuid, (const char *)info->uuid,
- UUID_STR_LEN);
- /* UUID_STR_LEN is correct, as uuid[]'s length is UUID_STR_LEN+1 chars */
- newpart->gpt_part_info.uuid[UUID_STR_LEN] = '\0';
-#endif
+ if (IS_ENABLED(CONFIG_PARTITION_UUIDS)) {
+ strlcpy(newpart->gpt_part_info.uuid, disk_partition_uuid(info),
+ UUID_STR_LEN + 1);
+ }
newpart->partnum = partnum;
return newpart;
diff --git a/disk/part.c b/disk/part.c
index 9190e8806187..91c6ac42cc83 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -368,10 +368,8 @@ int part_get_info_by_type(struct blk_desc *desc, int part, int part_type,
struct part_driver *drv;
if (blk_enabled()) {
-#if CONFIG_IS_ENABLED(PARTITION_UUIDS)
/* The common case is no UUID support */
- info->uuid[0] = 0;
-#endif
+ disk_partition_clr_uuid(info);
#ifdef CONFIG_PARTITION_TYPE_GUID
info->type_guid[0] = 0;
#endif
@@ -416,9 +414,7 @@ int part_get_info_whole_disk(struct blk_desc *desc,
info->bootable = 0;
strcpy((char *)info->type, BOOT_PART_TYPE);
strcpy((char *)info->name, "Whole Disk");
-#if CONFIG_IS_ENABLED(PARTITION_UUIDS)
- info->uuid[0] = 0;
-#endif
+ disk_partition_clr_uuid(info);
#ifdef CONFIG_PARTITION_TYPE_GUID
info->type_guid[0] = 0;
#endif
diff --git a/disk/part_dos.c b/disk/part_dos.c
index f94d2172d772..f576e9368edb 100644
--- a/disk/part_dos.c
+++ b/disk/part_dos.c
@@ -230,10 +230,8 @@ static int part_get_info_extended(struct blk_desc *desc,
return -1;
}
-#if CONFIG_IS_ENABLED(PARTITION_UUIDS)
- if (!ext_part_sector)
+ if (CONFIG_IS_ENABLED(PARTITION_UUIDS) && !ext_part_sector)
disksig = get_unaligned_le32(&buffer[DOS_PART_DISKSIG_OFFSET]);
-#endif
/* Print all primary/logical partitions */
pt = (dos_partition_t *) (buffer + DOS_PART_TBL_OFFSET);
@@ -255,9 +253,12 @@ static int part_get_info_extended(struct blk_desc *desc,
/* sprintf(info->type, "%d, pt->sys_ind); */
strcpy((char *)info->type, "U-Boot");
info->bootable = get_bootable(pt);
-#if CONFIG_IS_ENABLED(PARTITION_UUIDS)
- sprintf(info->uuid, "%08x-%02x", disksig, part_num);
-#endif
+ if (CONFIG_IS_ENABLED(PARTITION_UUIDS)) {
+ char str[12];
+
+ sprintf(str, "%08x-%02x", disksig, part_num);
+ disk_partition_set_uuid(info, str);
+ }
info->sys_ind = pt->sys_ind;
return 0;
}
@@ -291,9 +292,7 @@ static int part_get_info_extended(struct blk_desc *desc,
info->blksz = DOS_PART_DEFAULT_SECTOR;
info->bootable = 0;
strcpy((char *)info->type, "U-Boot");
-#if CONFIG_IS_ENABLED(PARTITION_UUIDS)
- info->uuid[0] = 0;
-#endif
+ disk_partition_clr_uuid(info);
return 0;
}
diff --git a/disk/part_efi.c b/disk/part_efi.c
index 4ac21868d088..a6f7375cd38a 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -289,10 +289,11 @@ int part_get_info_efi(struct blk_desc *desc, int part,
print_efiname(&gpt_pte[part - 1]));
strcpy((char *)info->type, "U-Boot");
info->bootable = get_bootable(&gpt_pte[part - 1]);
-#if CONFIG_IS_ENABLED(PARTITION_UUIDS)
- uuid_bin_to_str(gpt_pte[part - 1].unique_partition_guid.b, info->uuid,
- UUID_STR_FORMAT_GUID);
-#endif
+ if (CONFIG_IS_ENABLED(PARTITION_UUIDS)) {
+ uuid_bin_to_str(gpt_pte[part - 1].unique_partition_guid.b,
+ (char *)disk_partition_uuid(info),
+ UUID_STR_FORMAT_GUID);
+ }
#ifdef CONFIG_PARTITION_TYPE_GUID
uuid_bin_to_str(gpt_pte[part - 1].partition_type_guid.b,
info->type_guid, UUID_STR_FORMAT_GUID);
@@ -415,10 +416,7 @@ int gpt_fill_pte(struct blk_desc *desc,
le64_to_cpu(gpt_h->last_usable_lba);
int i, k;
size_t efiname_len, dosname_len;
-#if CONFIG_IS_ENABLED(PARTITION_UUIDS)
- char *str_uuid;
unsigned char *bin_uuid;
-#endif
#ifdef CONFIG_PARTITION_TYPE_GUID
char *str_type_guid;
unsigned char *bin_type_guid;
@@ -487,16 +485,19 @@ int gpt_fill_pte(struct blk_desc *desc,
&partition_basic_data_guid, 16);
#endif
-#if CONFIG_IS_ENABLED(PARTITION_UUIDS)
- str_uuid = partitions[i].uuid;
- bin_uuid = gpt_e[i].unique_partition_guid.b;
+ if (CONFIG_IS_ENABLED(PARTITION_UUIDS)) {
+ const char *str_uuid;
+
+ str_uuid = disk_partition_uuid(&partitions[i]);
+ bin_uuid = gpt_e[i].unique_partition_guid.b;
- if (uuid_str_to_bin(str_uuid, bin_uuid, UUID_STR_FORMAT_GUID)) {
- log_debug("Partition no. %d: invalid guid: %s\n",
- i, str_uuid);
- return -EINVAL;
+ if (uuid_str_to_bin(str_uuid, bin_uuid,
+ UUID_STR_FORMAT_GUID)) {
+ log_debug("Partition no. %d: invalid guid: %s\n",
+ i, str_uuid);
+ return -EINVAL;
+ }
}
-#endif
/* partition attributes */
memset(&gpt_e[i].attributes, 0,
diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index d1476aa433d6..8ff1fd0ec835 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -110,9 +110,7 @@ int fat_register_device(struct blk_desc *dev_desc, int part_no)
info.name[0] = 0;
info.type[0] = 0;
info.bootable = 0;
-#if CONFIG_IS_ENABLED(PARTITION_UUIDS)
- info.uuid[0] = 0;
-#endif
+ disk_partition_clr_uuid(&info);
}
return fat_set_blk_dev(dev_desc, &info);
diff --git a/include/part.h b/include/part.h
index dfe1dc08baa4..303ccd036754 100644
--- a/include/part.h
+++ b/include/part.h
@@ -80,6 +80,33 @@ struct disk_partition {
#endif
};
+/* Accessors for struct disk_partition field ->uuid */
+extern char *__invalid_use_of_disk_partition_uuid;
+
+static inline const char *disk_partition_uuid(const struct disk_partition *info)
+{
+#if CONFIG_IS_ENABLED(PARTITION_UUIDS)
+ return info->uuid;
+#else
+ return __invalid_use_of_disk_partition_uuid;
+#endif
+}
+
+static inline void disk_partition_set_uuid(struct disk_partition *info,
+ const char *val)
+{
+#if CONFIG_IS_ENABLED(PARTITION_UUIDS)
+ strlcpy(info->uuid, val, UUID_STR_LEN + 1);
+#endif
+}
+
+static inline void disk_partition_clr_uuid(struct disk_partition *info)
+{
+#if CONFIG_IS_ENABLED(PARTITION_UUIDS)
+ *info->uuid = '\0';
+#endif
+}
+
struct disk_part {
int partnum;
struct disk_partition gpt_part_info;
--
2.41.0.640.ga95def55d0-goog
next prev parent reply other threads:[~2023-08-13 14:28 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-13 14:26 [PATCH 00/24] bootstd: Support ChromiumOS better Simon Glass
2023-08-13 14:26 ` [PATCH 01/24] part: Use desc instead of dev_desc Simon Glass
2023-08-13 14:26 ` [PATCH 02/24] part: amiga: " Simon Glass
2023-08-13 14:26 ` [PATCH 03/24] part: dos: " Simon Glass
2023-08-13 14:26 ` [PATCH 04/24] part: efi: " Simon Glass
2023-08-13 14:26 ` [PATCH 05/24] part: iso: " Simon Glass
2023-08-13 14:26 ` [PATCH 06/24] part: nac: " Simon Glass
2023-08-13 14:26 ` [PATCH 07/24] part: Add comments for static functions Simon Glass
2023-08-13 14:26 ` Simon Glass [this message]
2023-08-13 14:26 ` [PATCH 09/24] part: Add accessors for struct disk_partition type_uuid Simon Glass
2023-08-13 14:26 ` [PATCH 10/24] part: Add an accessor for struct disk_partition sys_ind Simon Glass
2023-08-13 14:26 ` [PATCH 11/24] part: efi: Add debugging for the signature check Simon Glass
2023-08-13 14:26 ` [PATCH 12/24] fs/erofs: Quieten test for filesystem presence Simon Glass
2023-08-14 3:45 ` Gao Xiang
2023-08-13 14:26 ` [PATCH 13/24] dm: core: Correct error handling when event fails Simon Glass
2023-08-13 14:26 ` [PATCH 14/24] uuid: Move function comments to header file Simon Glass
2023-08-13 14:26 ` [PATCH 15/24] sandbox: Add a way to access persistent test files Simon Glass
2023-08-13 14:26 ` [PATCH 16/24] test: Move 1MB.fat32.img and 2MB.ext2.img Simon Glass
2023-08-13 14:26 ` [PATCH 17/24] bootflow: Show an empty filename when there is none Simon Glass
2023-08-13 14:26 ` [PATCH 18/24] bootstd: test: Allow binding and using any mmc device Simon Glass
2023-08-13 14:26 ` [PATCH 19/24] bootstd: Add a test for bootmeth_cros Simon Glass
2023-08-13 14:26 ` [PATCH 20/24] part: Add a fallback for part_get_bootable() Simon Glass
2023-08-13 14:26 ` [PATCH 21/24] bootstd: Support bootmeths which can scan any partition Simon Glass
2023-08-13 14:26 ` [PATCH 22/24] uuid: Add ChromiumOS partition types Simon Glass
2023-08-13 14:26 ` [PATCH 23/24] bootstd: cros: Allow detection of any kernel partition Simon Glass
2023-08-13 14:26 ` [PATCH 24/24] CI: Add ChromiumOS utilities Simon Glass
2023-08-24 17:43 ` [PATCH 00/24] bootstd: Support ChromiumOS better Tom Rini
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=20230813142708.361456-9-sjg@chromium.org \
--to=sjg@chromium.org \
--cc=bmeng.cn@gmail.com \
--cc=ilias.apalodimas@linaro.org \
--cc=jpewhacker@gmail.com \
--cc=stefan.herbrechtsmeier@weidmueller.com \
--cc=tobias@waldekranz.com \
--cc=u-boot@lists.denx.de \
--cc=xypron.glpk@gmx.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