Skip to contentSkip to conversation

efi_loader: identify EFI system partition

PATCH Superseded Heinrich Schuchardt 2 participants 13 messages Apr 5, 2020 – Apr 14, 2020

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover efi_loader: identify EFI system partition

For the implementation of capsule updates we need to know where the EFI system partition is located.

With the patches the first available EFI system partition is determined both for MBR and GPT partition tables.

v2:
used BIT() macro to define bit mask

Heinrich Schuchardt (2):
part: detect EFI system partition
efi_loader: identify EFI system partition

 disk/part_dos.c           | 10 ++++++++--
 disk/part_efi.c           | 12 ++++++++----
 include/efi_loader.h      |  7 +++++++
 include/part.h            | 11 ++++++++++-
 lib/efi_loader/efi_disk.c | 20 ++++++++++++++++++++
 5 files changed, 53 insertions(+), 7 deletions(-)

--
2.25.1

#1 lore raw

PATCH v2 1/2 part: detect EFI system partition

Up to now for MBR and GPT partitions the info field 'bootable' was set to 1 if either the partition was an EFI system partition or the bootable flag was set.

Turn info field 'bootable' into a bit mask with separate bits for bootable and EFI system partition.

This will allow us to identify the EFI system partition in the UEFI sub-system.

---
v2:
used BIT() macro to define bit mask

---
 disk/part_dos.c | 10 ++++++++--
 disk/part_efi.c | 12 ++++++++----
 include/part.h  | 11 ++++++++++-
 3 files changed, 26 insertions(+), 7 deletions(-)
disk/part_dos.c +8 -2
index 83ff40d310..0ec7f1628e 100644
@@ -45,9 +45,15 @@ static inline int is_extended(int part_type)
 	    part_type == 0x85);
 }
 
-static inline int is_bootable(dos_partition_t *p)
+static int is_bootable(dos_partition_t *p)
 {
-	return (p->sys_ind == 0xef) || (p->boot_ind == 0x80);
+	int ret = 0;
+
+	if (p->sys_ind == 0xef)
+		ret |= PART_EFI_SYSTEM_PARTITION;
+	if (p->boot_ind == 0x80)
+		ret |= PART_BOOTABLE;
+	return ret;
 }
 
 static void print_one_part(dos_partition_t *p, lbaint_t ext_part_sector,
disk/part_efi.c +8 -4
index b2e157d9c1..19f1f43f4e 100644
@@ -71,11 +71,15 @@ static char *print_efiname(gpt_entry *pte)
 
 static const efi_guid_t system_guid = PARTITION_SYSTEM_GUID;
 
-static inline int is_bootable(gpt_entry *p)
+static int is_bootable(gpt_entry *p)
 {
-	return p->attributes.fields.legacy_bios_bootable ||
-		!memcmp(&(p->partition_type_guid), &system_guid,
-			sizeof(efi_guid_t));
+	int ret = 0;
+
+	if (!memcmp(&p->partition_type_guid, &system_guid, sizeof(efi_guid_t)))
+		ret |=  PART_EFI_SYSTEM_PARTITION;
+	if (p->attributes.fields.legacy_bios_bootable)
+		ret |=  PART_BOOTABLE;
+	return ret;
 }
 
 static int validate_gpt_header(gpt_header *gpt_h, lbaint_t lba,
include/part.h +10 -1
index 0b5cf3d5e8..f3442ef85d 100644
@@ -51,13 +51,22 @@ struct block_drvr {
 #define PART_TYPE_LEN 32
 #define MAX_SEARCH_PARTITIONS 64
 
+#define PART_BOOTABLE			BIT(0)
+#define PART_EFI_SYSTEM_PARTITION	BIT(1)
+
 typedef struct disk_partition {
 	lbaint_t	start;	/* # of first block in partition	*/
 	lbaint_t	size;	/* number of blocks in partition	*/
 	ulong	blksz;		/* block size in bytes			*/
 	uchar	name[PART_NAME_LEN];	/* partition name			*/
 	uchar	type[PART_TYPE_LEN];	/* string type description		*/
-	int	bootable;	/* Active/Bootable flag is set		*/
+	/*
+	 * The bootable is a bitmask with the following fields:
+	 *
+	 * PART_BOOTABLE		the MBR bootable flag is set
+	 * PART_EFI_SYSTEM_PARTITION	the partition is an EFI system partition
+	 */
+	int	bootable;
 #if CONFIG_IS_ENABLED(PARTITION_UUIDS)
 	char	uuid[UUID_STR_LEN + 1];	/* filesystem UUID as string, if exists	*/
 #endif

--
2.25.1

#2 lore raw

PATCH v2 1/2 part: detect EFI system partition

Heinrich,

Quoted 30 lines · Heinrich Schuchardt

Up to now for MBR and GPT partitions the info field 'bootable' was set to 1 if either the partition was an EFI system partition or the bootable flag was set.

Turn info field 'bootable' into a bit mask with separate bits for bootable and EFI system partition.

This will allow us to identify the EFI system partition in the UEFI sub-system.

---
v2:
used BIT() macro to define bit mask

---
 disk/part_dos.c | 10 ++++++++--
 disk/part_efi.c | 12 ++++++++----
 include/part.h  | 11 ++++++++++-
 3 files changed, 26 insertions(+), 7 deletions(-)
disk/part_dos.c +1 -1
index 83ff40d310..0ec7f1628e 100644
@@ -45,9 +45,15 @@ static inline int is_extended(int part_type)
 	    part_type == 0x85);
 }
 
-static inline int is_bootable(dos_partition_t *p)
+static int is_bootable(dos_partition_t *p)

disk/part_dos.c static inline int is_extended(int part_type) · line 57

Quoted 10 lines
disk/part_dos.c +7 -1
 {
-	return (p->sys_ind == 0xef) || (p->boot_ind == 0x80);
+	int ret = 0;
+
+	if (p->sys_ind == 0xef)
+		ret |= PART_EFI_SYSTEM_PARTITION;
+	if (p->boot_ind == 0x80)
+		ret |= PART_BOOTABLE;
+	return ret;
 }

The return value is no longer boolean, so the function's name should be changed to avoid confusion. Say, get_bootable_flags()? Then another function, or inline function should be provided.

bool part_is_bootable(blk_desc *bdev)

for checking if the device is "bootable."

Quoted 13 lines
disk/part_dos.c +0 -0
 static void print_one_part(dos_partition_t *p, lbaint_t ext_part_sector,
disk/part_efi.c +1 -2
index b2e157d9c1..19f1f43f4e 100644
@@ -71,11 +71,15 @@ static char *print_efiname(gpt_entry *pte)
 
 static const efi_guid_t system_guid = PARTITION_SYSTEM_GUID;
 
-static inline int is_bootable(gpt_entry *p)
+static int is_bootable(gpt_entry *p)
 {
-	return p->attributes.fields.legacy_bios_bootable ||

disk/part_efi.c static char *print_efiname(gpt_entry *pte) · line 83

Quoted 10 lines
disk/part_efi.c +7 -2
-		!memcmp(&(p->partition_type_guid), &system_guid,
-			sizeof(efi_guid_t));
+	int ret = 0;
+
+	if (!memcmp(&p->partition_type_guid, &system_guid, sizeof(efi_guid_t)))
+		ret |=  PART_EFI_SYSTEM_PARTITION;
+	if (p->attributes.fields.legacy_bios_bootable)
+		ret |=  PART_BOOTABLE;
+	return ret;
 }

ditto, and again

bool part_is_efi_system()

-Takahiro Akashi

Quoted 32 lines
disk/part_efi.c +0 -0
 static int validate_gpt_header(gpt_header *gpt_h, lbaint_t lba,
include/part.h +10 -2
index 0b5cf3d5e8..f3442ef85d 100644
@@ -51,13 +51,22 @@ struct block_drvr {
 #define PART_TYPE_LEN 32
 #define MAX_SEARCH_PARTITIONS 64
 
+#define PART_BOOTABLE			BIT(0)
+#define PART_EFI_SYSTEM_PARTITION	BIT(1)
+
 typedef struct disk_partition {
 	lbaint_t	start;	/* # of first block in partition	*/
 	lbaint_t	size;	/* number of blocks in partition	*/
 	ulong	blksz;		/* block size in bytes			*/
 	uchar	name[PART_NAME_LEN];	/* partition name			*/
 	uchar	type[PART_TYPE_LEN];	/* string type description		*/
-	int	bootable;	/* Active/Bootable flag is set		*/
+	/*
+	 * The bootable is a bitmask with the following fields:
+	 *
+	 * PART_BOOTABLE		the MBR bootable flag is set
+	 * PART_EFI_SYSTEM_PARTITION	the partition is an EFI system partition
+	 */
+	int	bootable;
 #if CONFIG_IS_ENABLED(PARTITION_UUIDS)
 	char	uuid[UUID_STR_LEN + 1];	/* filesystem UUID as string, if exists	*/
 #endif
--

2.25.1

#3 lore raw

PATCH v2 1/2 part: detect EFI system partition

Am April 14, 2020 5:31:25 AM UTC schrieb AKASHI Takahiro <[email protected]>:

Quoted 51 lines

Heinrich,

Quoted 1 line · Heinrich Schuchardt

Up to now for MBR and GPT partitions the info field 'bootable' was

set to 1

Quoted 1 line

if either the partition was an EFI system partition or the bootable

flag

Quoted 3 lines

was set.

Turn info field 'bootable' into a bit mask with separate bits for

bootable

Quoted 25 lines

and EFI system partition.

This will allow us to identify the EFI system partition in the UEFI sub-system.

---
v2:
used BIT() macro to define bit mask

---
 disk/part_dos.c | 10 ++++++++--
 disk/part_efi.c | 12 ++++++++----
 include/part.h  | 11 ++++++++++-
 3 files changed, 26 insertions(+), 7 deletions(-)
disk/part_dos.c +1 -1
index 83ff40d310..0ec7f1628e 100644
@@ -45,9 +45,15 @@ static inline int is_extended(int part_type)
 	    part_type == 0x85);
 }
 
-static inline int is_bootable(dos_partition_t *p)
+static int is_bootable(dos_partition_t *p)

disk/part_dos.c static inline int is_extended(int part_type) · line 57

Quoted 10 lines
disk/part_dos.c +7 -1
 {
-	return (p->sys_ind == 0xef) || (p->boot_ind == 0x80);
+	int ret = 0;
+
+	if (p->sys_ind == 0xef)
+		ret |= PART_EFI_SYSTEM_PARTITION;
+	if (p->boot_ind == 0x80)
+		ret |= PART_BOOTABLE;
+	return ret;
 }

The return value is no longer boolean, so the function's name should be changed to avoid confusion. Say, get_bootable_flags()? Then another function, or inline function should be provided.

Quoted 4 lines

bool part_is_bootable(blk_desc *bdev)

for checking if the device is "bootable."

Logical operators 'if', '!', '&&', '||' regard any non-zero value as true. So I see no benefit of such a second function.

Best regards

Heinrich

Quoted 66 lines

disk/part_dos.c static inline int is_extended(int part_type) · line 58

Quoted 1 line
disk/part_dos.c +0 -0
 static void print_one_part(dos_partition_t *p, lbaint_t

ext_part_sector,

Quoted 7 lines
disk/part_efi.c +0 -0
index b2e157d9c1..19f1f43f4e 100644
@@ -71,11 +71,15 @@ static char *print_efiname(gpt_entry *pte)
 
 static const efi_guid_t system_guid = PARTITION_SYSTEM_GUID;

disk/part_efi.c static char *print_efiname(gpt_entry *pte) · line 78

Quoted 10 lines
disk/part_efi.c +4 -4
 
-static inline int is_bootable(gpt_entry *p)
+static int is_bootable(gpt_entry *p)
 {
-	return p->attributes.fields.legacy_bios_bootable ||
-		!memcmp(&(p->partition_type_guid), &system_guid,
-			sizeof(efi_guid_t));
+	int ret = 0;
+
+	if (!memcmp(&p->partition_type_guid, &system_guid,

sizeof(efi_guid_t)))

disk/part_efi.c static char *print_efiname(gpt_entry *pte) · line 83

Quoted 5 lines
disk/part_efi.c +4 -0
+		ret |=  PART_EFI_SYSTEM_PARTITION;
+	if (p->attributes.fields.legacy_bios_bootable)
+		ret |=  PART_BOOTABLE;
+	return ret;
 }

ditto, and again

bool part_is_efi_system()

-Takahiro Akashi

Quoted 14 lines
disk/part_efi.c +0 -0
 static int validate_gpt_header(gpt_header *gpt_h, lbaint_t lba,
include/part.h +3 -0
index 0b5cf3d5e8..f3442ef85d 100644
@@ -51,13 +51,22 @@ struct block_drvr {
 #define PART_TYPE_LEN 32
 #define MAX_SEARCH_PARTITIONS 64
 
+#define PART_BOOTABLE			BIT(0)
+#define PART_EFI_SYSTEM_PARTITION	BIT(1)
+
 typedef struct disk_partition {
 	lbaint_t	start;	/* # of first block in partition	*/

include/part.h struct block_drvr { · line 67

Quoted 10 lines
include/part.h +5 -1
 	lbaint_t	size;	/* number of blocks in partition	*/
 	ulong	blksz;		/* block size in bytes			*/
 	uchar	name[PART_NAME_LEN];	/* partition name			*/
 	uchar	type[PART_TYPE_LEN];	/* string type description		*/
-	int	bootable;	/* Active/Bootable flag is set		*/
+	/*
+	 * The bootable is a bitmask with the following fields:
+	 *
+	 * PART_BOOTABLE		the MBR bootable flag is set
+	 * PART_EFI_SYSTEM_PARTITION	the partition is an EFI system

partition

include/part.h struct block_drvr {

Quoted 4 lines
include/part.h +2 -0
+	 */
+	int	bootable;
 #if CONFIG_IS_ENABLED(PARTITION_UUIDS)
 	char	uuid[UUID_STR_LEN + 1];	/* filesystem UUID as string, if

exists */

Quoted 4 lines
include/part.h +0 -1
 #endif
--

2.25.1

#4 lore raw

PATCH v2 2/2 efi_loader: identify EFI system partition

In reply to Heinrich Schuchardt

For capsule updates we need to identify the EFI system partition.

---
v2:
no change

---
 include/efi_loader.h      |  7 +++++++
 lib/efi_loader/efi_disk.c | 20 ++++++++++++++++++++
 2 files changed, 27 insertions(+)
include/efi_loader.h +7 -0
index 3f2792892f..4a45033476 100644
@@ -45,6 +45,13 @@ static inline void *guidcpy(void *dst, const void *src)
 /* Root node */
 extern efi_handle_t efi_root;
 
+/* EFI system partition */
+extern struct efi_system_partition {
+	enum if_type if_type;
+	int devnum;
+	u8 part;
+} efi_system_partition;
+
 int __efi_entry_check(void);
 int __efi_exit_check(void);
 const char *__efi_nesting(void);
lib/efi_loader/efi_disk.c +20 -0
index fc0682bc48..2f752a5e99 100644
@@ -13,6 +13,8 @@
 #include <part.h>
 #include <malloc.h>
 
+struct efi_system_partition efi_system_partition;
+
 const efi_guid_t efi_block_io_guid = EFI_BLOCK_IO_PROTOCOL_GUID;
 
 /**
@@ -372,6 +374,24 @@ static efi_status_t efi_disk_add_dev(
 	diskobj->ops.media = &diskobj->media;
 	if (disk)
 		*disk = diskobj;
+
+	/* Store first EFI system partition */
+	if (part && !efi_system_partition.if_type) {
+		int r;
+		disk_partition_t info;
+
+		r = part_get_info(desc, part, &info);
+		if (r)
+			return EFI_DEVICE_ERROR;
+		if (info.bootable & PART_EFI_SYSTEM_PARTITION) {
+			efi_system_partition.if_type = desc->if_type;
+			efi_system_partition.devnum = desc->devnum;
+			efi_system_partition.part = part;
+			EFI_PRINT("EFI system partition: %s %d:%d\n",
+				  blk_get_if_type_name(desc->if_type),
+				  desc->devnum, part);
+		}
+	}
 	return EFI_SUCCESS;
 }
 

--
2.25.1

#5 lore raw

PATCH v2 2/2 efi_loader: identify EFI system partition

Heinrich,

Quoted 1 line · Heinrich Schuchardt

For capsule updates we need to identify the EFI system partition.

Right, but

Quoted 41 lines

---
v2:
no change

---
 include/efi_loader.h      |  7 +++++++
 lib/efi_loader/efi_disk.c | 20 ++++++++++++++++++++
 2 files changed, 27 insertions(+)
include/efi_loader.h +7 -0
index 3f2792892f..4a45033476 100644
@@ -45,6 +45,13 @@ static inline void *guidcpy(void *dst, const void *src)
 /* Root node */
 extern efi_handle_t efi_root;
 
+/* EFI system partition */
+extern struct efi_system_partition {
+	enum if_type if_type;
+	int devnum;
+	u8 part;
+} efi_system_partition;
+
 int __efi_entry_check(void);
 int __efi_exit_check(void);
 const char *__efi_nesting(void);
lib/efi_loader/efi_disk.c +2 -0
index fc0682bc48..2f752a5e99 100644
@@ -13,6 +13,8 @@
 #include <part.h>
 #include <malloc.h>
 
+struct efi_system_partition efi_system_partition;
+
 const efi_guid_t efi_block_io_guid = EFI_BLOCK_IO_PROTOCOL_GUID;
 
 /**

lib/efi_loader/efi_disk.c static efi_status_t efi_disk_add_dev( · line 378

Quoted 5 lines
lib/efi_loader/efi_disk.c +2 -0
@@ -372,6 +374,24 @@ static efi_status_t efi_disk_add_dev(
 	diskobj->ops.media = &diskobj->media;
 	if (disk)
 		*disk = diskobj;
+
+	/* Store first EFI system partition */

I don't think that the policy, first comes first serves as system partition, is a right decision as
- the order of device probe on U-Boot is indeterministic, and
- there can be several partitions that hold a system partition bit. You may have OS installed on eMMC, but also may have bootable DVD on the system.

-Takahiro Akashi

Quoted 22 lines
lib/efi_loader/efi_disk.c +16 -1
+	if (part && !efi_system_partition.if_type) {
+		int r;
+		disk_partition_t info;
+
+		r = part_get_info(desc, part, &info);
+		if (r)
+			return EFI_DEVICE_ERROR;
+		if (info.bootable & PART_EFI_SYSTEM_PARTITION) {
+			efi_system_partition.if_type = desc->if_type;
+			efi_system_partition.devnum = desc->devnum;
+			efi_system_partition.part = part;
+			EFI_PRINT("EFI system partition: %s %d:%d\n",
+				  blk_get_if_type_name(desc->if_type),
+				  desc->devnum, part);
+		}
+	}
 	return EFI_SUCCESS;
 }
 
--

2.25.1

#6 lore raw

PATCH v2 2/2 efi_loader: identify EFI system partition

Quoted 46 lines · AKASHI Takahiro

Heinrich,

Quoted 1 line · Heinrich Schuchardt

For capsule updates we need to identify the EFI system partition.

Right, but

Quoted 39 lines

---
v2:
no change

---
 include/efi_loader.h      |  7 +++++++
 lib/efi_loader/efi_disk.c | 20 ++++++++++++++++++++
 2 files changed, 27 insertions(+)
include/efi_loader.h +7 -0
index 3f2792892f..4a45033476 100644
@@ -45,6 +45,13 @@ static inline void *guidcpy(void *dst, const void *src)
 /* Root node */
 extern efi_handle_t efi_root;
 
+/* EFI system partition */
+extern struct efi_system_partition {
+	enum if_type if_type;
+	int devnum;
+	u8 part;
+} efi_system_partition;
+
 int __efi_entry_check(void);
 int __efi_exit_check(void);
 const char *__efi_nesting(void);
lib/efi_loader/efi_disk.c +2 -0
index fc0682bc48..2f752a5e99 100644
@@ -13,6 +13,8 @@
 #include <part.h>
 #include <malloc.h>
 
+struct efi_system_partition efi_system_partition;
+
 const efi_guid_t efi_block_io_guid = EFI_BLOCK_IO_PROTOCOL_GUID;
 
Quoted 11 lines

lib/efi_loader/efi_disk.c static efi_status_t efi_disk_add_dev( · line 378

Quoted 7 lines
lib/efi_loader/efi_disk.c +2 -0
 /**
@@ -372,6 +374,24 @@ static efi_status_t efi_disk_add_dev(
 	diskobj->ops.media = &diskobj->media;
 	if (disk)
 		*disk = diskobj;
+
+	/* Store first EFI system partition */

I don't think that the policy, first comes first serves as system partition, is a right decision as
- the order of device probe on U-Boot is indeterministic, and

Indeterministic would mean that on two runs with the same media provided you will get different results. I cannot see any source for such randomness in the U-Boot code. In dm_init_and_scan() the device tree is scanned and drivers and bound in the sequence of occurrence in the device tree.

Quoted 3 lines

- there can be several partitions that hold a system partition bit. You may have OS installed on eMMC, but also may have bootable DVD on the system.

This is a similar logic like finding the relevant boot.scr script to run.

What would be the alternative?

Definition via Kconfig would mean that a Linux distribution like Debian would have to provide a separate U-Boot build for each boot medium that a user might possibly use (eMMC, SD-card, USB, NVME, SCSI).

Best regards

Heinrich

Quoted 25 lines

-Takahiro Akashi

Quoted 22 lines
lib/efi_loader/efi_disk.c +16 -1
+	if (part && !efi_system_partition.if_type) {
+		int r;
+		disk_partition_t info;
+
+		r = part_get_info(desc, part, &info);
+		if (r)
+			return EFI_DEVICE_ERROR;
+		if (info.bootable & PART_EFI_SYSTEM_PARTITION) {
+			efi_system_partition.if_type = desc->if_type;
+			efi_system_partition.devnum = desc->devnum;
+			efi_system_partition.part = part;
+			EFI_PRINT("EFI system partition: %s %d:%d\n",
+				  blk_get_if_type_name(desc->if_type),
+				  desc->devnum, part);
+		}
+	}
 	return EFI_SUCCESS;
 }
 
--

2.25.1

#7 lore raw

PATCH v2 2/2 efi_loader: identify EFI system partition

Quoted 65 lines · Heinrich Schuchardt
Quoted 46 lines · AKASHI Takahiro

Heinrich,

Quoted 1 line · Heinrich Schuchardt

For capsule updates we need to identify the EFI system partition.

Right, but

Quoted 39 lines

---
v2:
no change

---
 include/efi_loader.h      |  7 +++++++
 lib/efi_loader/efi_disk.c | 20 ++++++++++++++++++++
 2 files changed, 27 insertions(+)
include/efi_loader.h +7 -0
index 3f2792892f..4a45033476 100644
@@ -45,6 +45,13 @@ static inline void *guidcpy(void *dst, const void *src)
 /* Root node */
 extern efi_handle_t efi_root;
 
+/* EFI system partition */
+extern struct efi_system_partition {
+	enum if_type if_type;
+	int devnum;
+	u8 part;
+} efi_system_partition;
+
 int __efi_entry_check(void);
 int __efi_exit_check(void);
 const char *__efi_nesting(void);
lib/efi_loader/efi_disk.c +2 -0
index fc0682bc48..2f752a5e99 100644
@@ -13,6 +13,8 @@
 #include <part.h>
 #include <malloc.h>
 
+struct efi_system_partition efi_system_partition;
+
 const efi_guid_t efi_block_io_guid = EFI_BLOCK_IO_PROTOCOL_GUID;
 
Quoted 11 lines

lib/efi_loader/efi_disk.c static efi_status_t efi_disk_add_dev( · line 378

Quoted 7 lines
lib/efi_loader/efi_disk.c +2 -0
 /**
@@ -372,6 +374,24 @@ static efi_status_t efi_disk_add_dev(
 	diskobj->ops.media = &diskobj->media;
 	if (disk)
 		*disk = diskobj;
+
+	/* Store first EFI system partition */

I don't think that the policy, first comes first serves as system partition, is a right decision as
- the order of device probe on U-Boot is indeterministic, and

Indeterministic would mean that on two runs with the same media provided you will get different results. I cannot see any source for such randomness in the U-Boot code. In dm_init_and_scan() the device tree is scanned and drivers and bound in the sequence of occurrence in the device tree.

Quoted 7 lines
Quoted 3 lines

- there can be several partitions that hold a system partition bit. You may have OS installed on eMMC, but also may have bootable DVD on the system.

This is a similar logic like finding the relevant boot.scr script to run.

What would be the alternative?

I think that most UEFI systems have ability for user to specify "boot order."

-Takahiro Akashi

Quoted 35 lines

Definition via Kconfig would mean that a Linux distribution like Debian would have to provide a separate U-Boot build for each boot medium that a user might possibly use (eMMC, SD-card, USB, NVME, SCSI).

Best regards

Heinrich

Quoted 25 lines

-Takahiro Akashi

Quoted 22 lines
lib/efi_loader/efi_disk.c +16 -1
+	if (part && !efi_system_partition.if_type) {
+		int r;
+		disk_partition_t info;
+
+		r = part_get_info(desc, part, &info);
+		if (r)
+			return EFI_DEVICE_ERROR;
+		if (info.bootable & PART_EFI_SYSTEM_PARTITION) {
+			efi_system_partition.if_type = desc->if_type;
+			efi_system_partition.devnum = desc->devnum;
+			efi_system_partition.part = part;
+			EFI_PRINT("EFI system partition: %s %d:%d\n",
+				  blk_get_if_type_name(desc->if_type),
+				  desc->devnum, part);
+		}
+	}
 	return EFI_SUCCESS;
 }
 
--

2.25.1

#8 lore raw

PATCH v2 2/2 efi_loader: identify EFI system partition

Heinrich,

Quoted 70 lines · AKASHI Takahiro
Quoted 69 lines · Heinrich Schuchardt
Quoted 46 lines · AKASHI Takahiro

Heinrich,

Quoted 1 line · Heinrich Schuchardt

For capsule updates we need to identify the EFI system partition.

Right, but

Quoted 39 lines

---
v2:
no change

---
 include/efi_loader.h      |  7 +++++++
 lib/efi_loader/efi_disk.c | 20 ++++++++++++++++++++
 2 files changed, 27 insertions(+)
include/efi_loader.h +7 -0
index 3f2792892f..4a45033476 100644
@@ -45,6 +45,13 @@ static inline void *guidcpy(void *dst, const void *src)
 /* Root node */
 extern efi_handle_t efi_root;
 
+/* EFI system partition */
+extern struct efi_system_partition {
+	enum if_type if_type;
+	int devnum;
+	u8 part;
+} efi_system_partition;
+
 int __efi_entry_check(void);
 int __efi_exit_check(void);
 const char *__efi_nesting(void);
lib/efi_loader/efi_disk.c +2 -0
index fc0682bc48..2f752a5e99 100644
@@ -13,6 +13,8 @@
 #include <part.h>
 #include <malloc.h>
 
+struct efi_system_partition efi_system_partition;
+
 const efi_guid_t efi_block_io_guid = EFI_BLOCK_IO_PROTOCOL_GUID;
 
Quoted 11 lines

lib/efi_loader/efi_disk.c static efi_status_t efi_disk_add_dev( · line 378

Quoted 7 lines
lib/efi_loader/efi_disk.c +2 -0
 /**
@@ -372,6 +374,24 @@ static efi_status_t efi_disk_add_dev(
 	diskobj->ops.media = &diskobj->media;
 	if (disk)
 		*disk = diskobj;
+
+	/* Store first EFI system partition */

I don't think that the policy, first comes first serves as system partition, is a right decision as
- the order of device probe on U-Boot is indeterministic, and

Indeterministic would mean that on two runs with the same media provided you will get different results. I cannot see any source for such randomness in the U-Boot code. In dm_init_and_scan() the device tree is scanned and drivers and bound in the sequence of occurrence in the device tree.

Quoted 3 lines

- there can be several partitions that hold a system partition bit. You may have OS installed on eMMC, but also may have bootable DVD on the system.

Quoted 6 lines
Quoted 3 lines

This is a similar logic like finding the relevant boot.scr script to run.

What would be the alternative?

I think that most UEFI systems have ability for user to specify "boot order."

Any comment?
The discussion and your patch will have some impact on my efi capsule patch.

-Takahiro Akashi

Quoted 36 lines

-Takahiro Akashi

Quoted 35 lines

Definition via Kconfig would mean that a Linux distribution like Debian would have to provide a separate U-Boot build for each boot medium that a user might possibly use (eMMC, SD-card, USB, NVME, SCSI).

Best regards

Heinrich

Quoted 25 lines

-Takahiro Akashi

Quoted 22 lines
lib/efi_loader/efi_disk.c +16 -1
+	if (part && !efi_system_partition.if_type) {
+		int r;
+		disk_partition_t info;
+
+		r = part_get_info(desc, part, &info);
+		if (r)
+			return EFI_DEVICE_ERROR;
+		if (info.bootable & PART_EFI_SYSTEM_PARTITION) {
+			efi_system_partition.if_type = desc->if_type;
+			efi_system_partition.devnum = desc->devnum;
+			efi_system_partition.part = part;
+			EFI_PRINT("EFI system partition: %s %d:%d\n",
+				  blk_get_if_type_name(desc->if_type),
+				  desc->devnum, part);
+		}
+	}
 	return EFI_SUCCESS;
 }
 
--

2.25.1

#9 lore raw

PATCH v2 2/2 efi_loader: identify EFI system partition

Am April 14, 2020 5:20:38 AM UTC schrieb AKASHI Takahiro <[email protected]>:

Quoted 85 lines

Heinrich,

Quoted 5 lines · AKASHI Takahiro
Quoted 4 lines · Heinrich Schuchardt
Quoted 3 lines · AKASHI Takahiro

Heinrich,

On Sun, Apr 05, 2020 at 11:28:18AM +0200, Heinrich Schuchardt

Quoted 1 line · wrote:
Quoted 1 line
Quoted 1 line
Quoted 1 line

For capsule updates we need to identify the EFI system

partition.

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

Right, but

Quoted 9 lines

---
v2:
no change

---
 include/efi_loader.h      |  7 +++++++
 lib/efi_loader/efi_disk.c | 20 ++++++++++++++++++++
 2 files changed, 27 insertions(+)
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

include/efi_loader.h static inline void *guidcpy(void *dst, const

Quoted 5 lines
include/efi_loader.h +0 -0
index 3f2792892f..4a45033476 100644
@@ -45,6 +45,13 @@ static inline void *guidcpy(void *dst, const

void *src)

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines

Review

Quoted 14 lines
include/efi_loader.h +7 -0
 /* Root node */
 extern efi_handle_t efi_root;
 
+/* EFI system partition */
+extern struct efi_system_partition {
+	enum if_type if_type;
+	int devnum;
+	u8 part;
+} efi_system_partition;
+
 int __efi_entry_check(void);
 int __efi_exit_check(void);
 const char *__efi_nesting(void);
(quoted diff) +0 -0

b/lib/efi_loader/efi_disk.c

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

lib/efi_loader/efi_disk.c line 18

Quoted 10 lines

index fc0682bc48..2f752a5e99 100644

lib/efi_loader/efi_disk.c +2 -0
@@ -13,6 +13,8 @@
 #include <part.h>
 #include <malloc.h>
 
+struct efi_system_partition efi_system_partition;
+
 const efi_guid_t efi_block_io_guid =

EFI_BLOCK_IO_PROTOCOL_GUID;

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines

lib/efi_loader/efi_disk.c static efi_status_t efi_disk_add_dev( · line 378

Quoted 8 lines
lib/efi_loader/efi_disk.c +2 -0
 /**
@@ -372,6 +374,24 @@ static efi_status_t efi_disk_add_dev(
 	diskobj->ops.media = &diskobj->media;
 	if (disk)
 		*disk = diskobj;
+
+	/* Store first EFI system partition */

I don't think that the policy, first comes first serves as system partition, is a right decision as
- the order of device probe on U-Boot is indeterministic, and

Quoted 1 line
Quoted 1 line

Indeterministic would mean that on two runs with the same media

provided

Quoted 2 lines
Quoted 2 lines

you will get different results. I cannot see any source for such randomness in the U-Boot code. In dm_init_and_scan() the device

tree is

Quoted 4 lines
Quoted 4 lines

scanned and drivers and bound in the sequence of occurrence in the device tree.

Quoted 1 line

- there can be several partitions that hold a system partition

bit.

Quoted 1 line
Quoted 1 line
Quoted 1 line

You may have OS installed on eMMC, but also may have bootable

DVD

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

on the system.

This is a similar logic like finding the relevant boot.scr script

to run.

Quoted 1 line
Quoted 1 line
Quoted 8 lines
Quoted 4 lines
Quoted 1 line

What would be the alternative?

I think that most UEFI systems have ability for user to specify "boot order."

Any comment?
The discussion and your patch will have some impact on my efi capsule patch.

Concerning capsules the spec says we should use the boot device. So my patch doesn't help you there.

For the storage of variables I still need this patch. I will adjust the commit message.

Best regards

Heinrich

Quoted 41 lines

-Takahiro Akashi

Quoted 3 lines

-Takahiro Akashi

Quoted 2 lines

Definition via Kconfig would mean that a Linux distribution like

Debian

Quoted 1 line
Quoted 1 line

would have to provide a separate U-Boot build for each boot medium

that

Quoted 32 lines
Quoted 32 lines

a user might possibly use (eMMC, SD-card, USB, NVME, SCSI).

Best regards

Heinrich

Quoted 25 lines

-Takahiro Akashi

Quoted 22 lines
lib/efi_loader/efi_disk.c +16 -1
+	if (part && !efi_system_partition.if_type) {
+		int r;
+		disk_partition_t info;
+
+		r = part_get_info(desc, part, &info);
+		if (r)
+			return EFI_DEVICE_ERROR;
+		if (info.bootable & PART_EFI_SYSTEM_PARTITION) {
+			efi_system_partition.if_type = desc->if_type;
+			efi_system_partition.devnum = desc->devnum;
+			efi_system_partition.part = part;
+			EFI_PRINT("EFI system partition: %s %d:%d\n",
+				  blk_get_if_type_name(desc->if_type),
+				  desc->devnum, part);
+		}
+	}
 	return EFI_SUCCESS;
 }
 
--

2.25.1

#10 lore raw

PATCH v2 2/2 efi_loader: identify EFI system partition

Quoted 88 lines · Heinrich Schuchardt

Am April 14, 2020 5:20:38 AM UTC schrieb AKASHI Takahiro <[email protected]>:

Quoted 87 lines

Heinrich,

Quoted 5 lines · AKASHI Takahiro
Quoted 4 lines · Heinrich Schuchardt
Quoted 3 lines · AKASHI Takahiro

Heinrich,

On Sun, Apr 05, 2020 at 11:28:18AM +0200, Heinrich Schuchardt

Quoted 1 line · wrote:
Quoted 1 line
Quoted 1 line
Quoted 1 line

For capsule updates we need to identify the EFI system

partition.

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

Right, but

Quoted 9 lines

---
v2:
no change

---
 include/efi_loader.h      |  7 +++++++
 lib/efi_loader/efi_disk.c | 20 ++++++++++++++++++++
 2 files changed, 27 insertions(+)
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

include/efi_loader.h static inline void *guidcpy(void *dst, const

Quoted 5 lines
include/efi_loader.h +0 -0
index 3f2792892f..4a45033476 100644
@@ -45,6 +45,13 @@ static inline void *guidcpy(void *dst, const

void *src)

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines

Review

Quoted 14 lines
include/efi_loader.h +7 -0
 /* Root node */
 extern efi_handle_t efi_root;
 
+/* EFI system partition */
+extern struct efi_system_partition {
+	enum if_type if_type;
+	int devnum;
+	u8 part;
+} efi_system_partition;
+
 int __efi_entry_check(void);
 int __efi_exit_check(void);
 const char *__efi_nesting(void);
(quoted diff) +0 -0

b/lib/efi_loader/efi_disk.c

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

lib/efi_loader/efi_disk.c line 18

Quoted 10 lines

index fc0682bc48..2f752a5e99 100644

lib/efi_loader/efi_disk.c +2 -0
@@ -13,6 +13,8 @@
 #include <part.h>
 #include <malloc.h>
 
+struct efi_system_partition efi_system_partition;
+
 const efi_guid_t efi_block_io_guid =

EFI_BLOCK_IO_PROTOCOL_GUID;

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines

lib/efi_loader/efi_disk.c static efi_status_t efi_disk_add_dev( · line 378

Quoted 8 lines
lib/efi_loader/efi_disk.c +2 -0
 /**
@@ -372,6 +374,24 @@ static efi_status_t efi_disk_add_dev(
 	diskobj->ops.media = &diskobj->media;
 	if (disk)
 		*disk = diskobj;
+
+	/* Store first EFI system partition */

I don't think that the policy, first comes first serves as system partition, is a right decision as
- the order of device probe on U-Boot is indeterministic, and

Quoted 1 line
Quoted 1 line

Indeterministic would mean that on two runs with the same media

provided

Quoted 2 lines
Quoted 2 lines

you will get different results. I cannot see any source for such randomness in the U-Boot code. In dm_init_and_scan() the device

tree is

Quoted 4 lines
Quoted 4 lines

scanned and drivers and bound in the sequence of occurrence in the device tree.

Quoted 1 line

- there can be several partitions that hold a system partition

bit.

Quoted 1 line
Quoted 1 line
Quoted 1 line

You may have OS installed on eMMC, but also may have bootable

DVD

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

on the system.

This is a similar logic like finding the relevant boot.scr script

to run.

Quoted 3 lines
Quoted 2 lines

What would be the alternative?

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

I think that most UEFI systems have ability for user to specify "boot order."

Any comment?
The discussion and your patch will have some impact on my efi capsule patch.

Concerning capsules the spec says we should use the boot device. So my patch doesn't help you there.

Your commit message says,
"For capsule updates we need to identify the EFI system partition."

and then I made some counter comment.
So now you agreed with my comment, don't you? (I need to confirm this to work on capsule patch.)

Quoted 1 line

For the storage of variables I still need this patch. I will adjust the commit message.

Even in this case, I believe that the first device detected in your logic is not always a "valid" device for your purpose.

-Takahiro Akashi

Quoted 47 lines

Best regards

Heinrich

Quoted 41 lines

-Takahiro Akashi

Quoted 3 lines

-Takahiro Akashi

Quoted 2 lines

Definition via Kconfig would mean that a Linux distribution like

Debian

Quoted 1 line
Quoted 1 line

would have to provide a separate U-Boot build for each boot medium

that

Quoted 32 lines
Quoted 32 lines

a user might possibly use (eMMC, SD-card, USB, NVME, SCSI).

Best regards

Heinrich

Quoted 25 lines

-Takahiro Akashi

Quoted 22 lines
lib/efi_loader/efi_disk.c +16 -1
+	if (part && !efi_system_partition.if_type) {
+		int r;
+		disk_partition_t info;
+
+		r = part_get_info(desc, part, &info);
+		if (r)
+			return EFI_DEVICE_ERROR;
+		if (info.bootable & PART_EFI_SYSTEM_PARTITION) {
+			efi_system_partition.if_type = desc->if_type;
+			efi_system_partition.devnum = desc->devnum;
+			efi_system_partition.part = part;
+			EFI_PRINT("EFI system partition: %s %d:%d\n",
+				  blk_get_if_type_name(desc->if_type),
+				  desc->devnum, part);
+		}
+	}
 	return EFI_SUCCESS;
 }
 
--

2.25.1

#11 lore raw

PATCH v2 2/2 efi_loader: identify EFI system partition

Quoted 96 lines · AKASHI Takahiro
Quoted 95 lines · Heinrich Schuchardt

Am April 14, 2020 5:20:38 AM UTC schrieb AKASHI Takahiro <[email protected]>:

Quoted 93 lines

Heinrich,

Quoted 5 lines · AKASHI Takahiro
Quoted 4 lines · Heinrich Schuchardt
Quoted 3 lines · AKASHI Takahiro

Heinrich,

On Sun, Apr 05, 2020 at 11:28:18AM +0200, Heinrich Schuchardt

Quoted 1 line · wrote:
Quoted 1 line
Quoted 1 line
Quoted 1 line

For capsule updates we need to identify the EFI system

partition.

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

Right, but

Quoted 9 lines

---
v2:
no change

---
 include/efi_loader.h      |  7 +++++++
 lib/efi_loader/efi_disk.c | 20 ++++++++++++++++++++
 2 files changed, 27 insertions(+)
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

include/efi_loader.h static inline void *guidcpy(void *dst, const

Quoted 5 lines
include/efi_loader.h +0 -0
index 3f2792892f..4a45033476 100644
@@ -45,6 +45,13 @@ static inline void *guidcpy(void *dst, const

void *src)

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines

Review

Quoted 14 lines
include/efi_loader.h +7 -0
 /* Root node */
 extern efi_handle_t efi_root;
 
+/* EFI system partition */
+extern struct efi_system_partition {
+	enum if_type if_type;
+	int devnum;
+	u8 part;
+} efi_system_partition;
+
 int __efi_entry_check(void);
 int __efi_exit_check(void);
 const char *__efi_nesting(void);
(quoted diff) +0 -0

b/lib/efi_loader/efi_disk.c

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

lib/efi_loader/efi_disk.c line 18

Quoted 10 lines

index fc0682bc48..2f752a5e99 100644

lib/efi_loader/efi_disk.c +2 -0
@@ -13,6 +13,8 @@
 #include <part.h>
 #include <malloc.h>
 
+struct efi_system_partition efi_system_partition;
+
 const efi_guid_t efi_block_io_guid =

EFI_BLOCK_IO_PROTOCOL_GUID;

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines

lib/efi_loader/efi_disk.c static efi_status_t efi_disk_add_dev( · line 378

Quoted 8 lines
lib/efi_loader/efi_disk.c +2 -0
 /**
@@ -372,6 +374,24 @@ static efi_status_t efi_disk_add_dev(
 	diskobj->ops.media = &diskobj->media;
 	if (disk)
 		*disk = diskobj;
+
+	/* Store first EFI system partition */

I don't think that the policy, first comes first serves as system partition, is a right decision as
- the order of device probe on U-Boot is indeterministic, and

Quoted 1 line
Quoted 1 line

Indeterministic would mean that on two runs with the same media

provided

Quoted 2 lines
Quoted 2 lines

you will get different results. I cannot see any source for such randomness in the U-Boot code. In dm_init_and_scan() the device

tree is

Quoted 4 lines
Quoted 4 lines

scanned and drivers and bound in the sequence of occurrence in the device tree.

Quoted 1 line

- there can be several partitions that hold a system partition

bit.

Quoted 1 line
Quoted 1 line
Quoted 1 line

You may have OS installed on eMMC, but also may have bootable

DVD

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

on the system.

This is a similar logic like finding the relevant boot.scr script

to run.

Quoted 5 lines
Quoted 2 lines

What would be the alternative?

I think that most UEFI systems have ability for user to specify "boot order."

Any comment?
The discussion and your patch will have some impact on my efi capsule patch.

Quoted 8 lines
Quoted 1 line

Concerning capsules the spec says we should use the boot device. So my patch doesn't help you there.

Your commit message says,
"For capsule updates we need to identify the EFI system partition."

and then I made some counter comment.
So now you agreed with my comment, don't you? (I need to confirm this to work on capsule patch.)

You can stick to your original design.

Quoted 5 lines
Quoted 2 lines

For the storage of variables I still need this patch. I will adjust the commit message.

Even in this case, I believe that the first device detected in your logic is not always a "valid" device for your purpose.

Do you have a better suggestion?

Best regards

Heinrich

Quoted 50 lines

-Takahiro Akashi

Quoted 47 lines

Best regards

Heinrich

Quoted 41 lines

-Takahiro Akashi

Quoted 3 lines

-Takahiro Akashi

Quoted 2 lines

Definition via Kconfig would mean that a Linux distribution like

Debian

Quoted 1 line
Quoted 1 line

would have to provide a separate U-Boot build for each boot medium

that

Quoted 32 lines
Quoted 32 lines

a user might possibly use (eMMC, SD-card, USB, NVME, SCSI).

Best regards

Heinrich

Quoted 25 lines

-Takahiro Akashi

Quoted 22 lines
lib/efi_loader/efi_disk.c +16 -1
+	if (part && !efi_system_partition.if_type) {
+		int r;
+		disk_partition_t info;
+
+		r = part_get_info(desc, part, &info);
+		if (r)
+			return EFI_DEVICE_ERROR;
+		if (info.bootable & PART_EFI_SYSTEM_PARTITION) {
+			efi_system_partition.if_type = desc->if_type;
+			efi_system_partition.devnum = desc->devnum;
+			efi_system_partition.part = part;
+			EFI_PRINT("EFI system partition: %s %d:%d\n",
+				  blk_get_if_type_name(desc->if_type),
+				  desc->devnum, part);
+		}
+	}
 	return EFI_SUCCESS;
 }
 
--

2.25.1

#12 lore raw

PATCH v2 2/2 efi_loader: identify EFI system partition

Heinrich,

Quoted 99 lines · Heinrich Schuchardt
Quoted 98 lines · AKASHI Takahiro
Quoted 96 lines · Heinrich Schuchardt

Am April 14, 2020 5:20:38 AM UTC schrieb AKASHI Takahiro <[email protected]>:

Quoted 85 lines

Heinrich,

Quoted 5 lines · AKASHI Takahiro
Quoted 4 lines · Heinrich Schuchardt
Quoted 3 lines · AKASHI Takahiro

Heinrich,

On Sun, Apr 05, 2020 at 11:28:18AM +0200, Heinrich Schuchardt

Quoted 1 line · wrote:
Quoted 1 line
Quoted 1 line
Quoted 1 line

For capsule updates we need to identify the EFI system

partition.

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

Right, but

Quoted 9 lines

---
v2:
no change

---
 include/efi_loader.h      |  7 +++++++
 lib/efi_loader/efi_disk.c | 20 ++++++++++++++++++++
 2 files changed, 27 insertions(+)
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

include/efi_loader.h static inline void *guidcpy(void *dst, const

Quoted 5 lines
include/efi_loader.h +0 -0
index 3f2792892f..4a45033476 100644
@@ -45,6 +45,13 @@ static inline void *guidcpy(void *dst, const

void *src)

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines

Review

Quoted 14 lines
include/efi_loader.h +7 -0
 /* Root node */
 extern efi_handle_t efi_root;
 
+/* EFI system partition */
+extern struct efi_system_partition {
+	enum if_type if_type;
+	int devnum;
+	u8 part;
+} efi_system_partition;
+
 int __efi_entry_check(void);
 int __efi_exit_check(void);
 const char *__efi_nesting(void);
(quoted diff) +0 -0

b/lib/efi_loader/efi_disk.c

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

lib/efi_loader/efi_disk.c line 18

Quoted 10 lines

index fc0682bc48..2f752a5e99 100644

lib/efi_loader/efi_disk.c +2 -0
@@ -13,6 +13,8 @@
 #include <part.h>
 #include <malloc.h>
 
+struct efi_system_partition efi_system_partition;
+
 const efi_guid_t efi_block_io_guid =

EFI_BLOCK_IO_PROTOCOL_GUID;

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines

lib/efi_loader/efi_disk.c static efi_status_t efi_disk_add_dev( · line 378

Quoted 8 lines
lib/efi_loader/efi_disk.c +2 -0
 /**
@@ -372,6 +374,24 @@ static efi_status_t efi_disk_add_dev(
 	diskobj->ops.media = &diskobj->media;
 	if (disk)
 		*disk = diskobj;
+
+	/* Store first EFI system partition */

I don't think that the policy, first comes first serves as system partition, is a right decision as
- the order of device probe on U-Boot is indeterministic, and

Quoted 1 line
Quoted 1 line

Indeterministic would mean that on two runs with the same media

provided

Quoted 2 lines
Quoted 2 lines

you will get different results. I cannot see any source for such randomness in the U-Boot code. In dm_init_and_scan() the device

tree is

Quoted 4 lines
Quoted 4 lines

scanned and drivers and bound in the sequence of occurrence in the device tree.

Quoted 1 line

- there can be several partitions that hold a system partition

bit.

Quoted 1 line
Quoted 1 line
Quoted 1 line

You may have OS installed on eMMC, but also may have bootable

DVD

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

on the system.

This is a similar logic like finding the relevant boot.scr script

to run.

Quoted 1 line
Quoted 1 line
Quoted 8 lines
Quoted 4 lines
Quoted 1 line

What would be the alternative?

I think that most UEFI systems have ability for user to specify "boot order."

Any comment?
The discussion and your patch will have some impact on my efi capsule patch.

Concerning capsules the spec says we should use the boot device. So my patch doesn't help you there.

Quoted 8 lines
Quoted 6 lines

Your commit message says,
"For capsule updates we need to identify the EFI system partition."

and then I made some counter comment.
So now you agreed with my comment, don't you? (I need to confirm this to work on capsule patch.)

You can stick to your original design.

Thanks

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

For the storage of variables I still need this patch. I will adjust the commit message.

Even in this case, I believe that the first device detected in your logic is not always a "valid" device for your purpose.

Do you have a better suggestion?

The root cause would be that there is no notion of "boot device" in U-Boot. So I would suggest
1) we should add Kconfig option to specify it
just as we do for U-Boot environment (variables), and then check if the partition has a system partition bit at boot time.
2) you would follow the similar way as I do in capsule support. or
3) you would first examine what EDK2 does in this respect.

-Takahiro Akashi

Quoted 55 lines

Best regards

Heinrich

Quoted 50 lines

-Takahiro Akashi

Quoted 47 lines

Best regards

Heinrich

Quoted 41 lines

-Takahiro Akashi

Quoted 3 lines

-Takahiro Akashi

Quoted 2 lines

Definition via Kconfig would mean that a Linux distribution like

Debian

Quoted 1 line
Quoted 1 line

would have to provide a separate U-Boot build for each boot medium

that

Quoted 32 lines
Quoted 32 lines

a user might possibly use (eMMC, SD-card, USB, NVME, SCSI).

Best regards

Heinrich

Quoted 25 lines

-Takahiro Akashi

Quoted 22 lines
lib/efi_loader/efi_disk.c +16 -1
+	if (part && !efi_system_partition.if_type) {
+		int r;
+		disk_partition_t info;
+
+		r = part_get_info(desc, part, &info);
+		if (r)
+			return EFI_DEVICE_ERROR;
+		if (info.bootable & PART_EFI_SYSTEM_PARTITION) {
+			efi_system_partition.if_type = desc->if_type;
+			efi_system_partition.devnum = desc->devnum;
+			efi_system_partition.part = part;
+			EFI_PRINT("EFI system partition: %s %d:%d\n",
+				  blk_get_if_type_name(desc->if_type),
+				  desc->devnum, part);
+		}
+	}
 	return EFI_SUCCESS;
 }
 
--

2.25.1